Skip to content

Commit 444be06

Browse files
idoschdavem330
authored andcommitted
drop_monitor: Add a command to query current configuration
Users should be able to query the current configuration of drop monitor before they start using it. Add a command to query the existing configuration which currently consists of alert mode and packet truncation length. Signed-off-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5798661 commit 444be06

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

‎include/uapi/linux/net_dropmon.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ enum {
5454
NET_DM_CMD_START,
5555
NET_DM_CMD_STOP,
5656
NET_DM_CMD_PACKET_ALERT,
57+
NET_DM_CMD_CONFIG_GET,
58+
NET_DM_CMD_CONFIG_NEW,
5759
_NET_DM_CMD_MAX,
5860
};
5961

‎net/core/drop_monitor.c‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,50 @@ static int net_dm_cmd_trace(struct sk_buff *skb,
676676
return -EOPNOTSUPP;
677677
}
678678

679+
static int net_dm_config_fill(struct sk_buff *msg, struct genl_info *info)
680+
{
681+
void *hdr;
682+
683+
hdr = genlmsg_put(msg, info->snd_portid, info->snd_seq,
684+
&net_drop_monitor_family, 0, NET_DM_CMD_CONFIG_NEW);
685+
if (!hdr)
686+
return -EMSGSIZE;
687+
688+
if (nla_put_u8(msg, NET_DM_ATTR_ALERT_MODE, net_dm_alert_mode))
689+
goto nla_put_failure;
690+
691+
if (nla_put_u32(msg, NET_DM_ATTR_TRUNC_LEN, net_dm_trunc_len))
692+
goto nla_put_failure;
693+
694+
genlmsg_end(msg, hdr);
695+
696+
return 0;
697+
698+
nla_put_failure:
699+
genlmsg_cancel(msg, hdr);
700+
return -EMSGSIZE;
701+
}
702+
703+
static int net_dm_cmd_config_get(struct sk_buff *skb, struct genl_info *info)
704+
{
705+
struct sk_buff *msg;
706+
int rc;
707+
708+
msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
709+
if (!msg)
710+
return -ENOMEM;
711+
712+
rc = net_dm_config_fill(msg, info);
713+
if (rc)
714+
goto free_msg;
715+
716+
return genlmsg_reply(msg, info);
717+
718+
free_msg:
719+
nlmsg_free(msg);
720+
return rc;
721+
}
722+
679723
static int dropmon_net_event(struct notifier_block *ev_block,
680724
unsigned long event, void *ptr)
681725
{
@@ -738,6 +782,10 @@ static const struct genl_ops dropmon_ops[] = {
738782
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
739783
.doit = net_dm_cmd_trace,
740784
},
785+
{
786+
.cmd = NET_DM_CMD_CONFIG_GET,
787+
.doit = net_dm_cmd_config_get,
788+
},
741789
};
742790

743791
static int net_dm_nl_pre_doit(const struct genl_ops *ops,

0 commit comments

Comments
 (0)