Skip to content

Commit

Permalink
devlink: extend multicast filtering by port index
Browse files Browse the repository at this point in the history
Expose the previously introduced notification multicast messages
filtering infrastructure and allow the user to select messages using
port index.

Signed-off-by: Jiri Pirko <[email protected]>
Signed-off-by: Paolo Abeni <[email protected]>
  • Loading branch information
Jiri Pirko authored and Paolo Abeni committed Dec 19, 2023
1 parent 13b127d commit ded6f77
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions Documentation/netlink/specs/devlink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2264,3 +2264,4 @@ operations:
attributes:
- bus-name
- dev-name
- port-index
9 changes: 9 additions & 0 deletions net/devlink/devl_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ struct devlink_obj_desc {
struct rcu_head rcu;
const char *bus_name;
const char *dev_name;
unsigned int port_index;
bool port_index_valid;
long data[];
};

Expand All @@ -206,6 +208,13 @@ static inline void devlink_nl_obj_desc_init(struct devlink_obj_desc *desc,
desc->dev_name = dev_name(devlink->dev);
}

static inline void devlink_nl_obj_desc_port_set(struct devlink_obj_desc *desc,
struct devlink_port *devlink_port)
{
desc->port_index = devlink_port->index;
desc->port_index_valid = true;
}

int devlink_nl_notify_filter(struct sock *dsk, struct sk_buff *skb, void *data);

static inline void devlink_nl_notify_send_desc(struct devlink *devlink,
Expand Down
6 changes: 5 additions & 1 deletion net/devlink/health.c
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ static void devlink_recover_notify(struct devlink_health_reporter *reporter,
enum devlink_command cmd)
{
struct devlink *devlink = reporter->devlink;
struct devlink_obj_desc desc;
struct sk_buff *msg;
int err;

Expand All @@ -509,7 +510,10 @@ static void devlink_recover_notify(struct devlink_health_reporter *reporter,
return;
}

devlink_nl_notify_send(devlink, msg);
devlink_nl_obj_desc_init(&desc, devlink);
if (reporter->devlink_port)
devlink_nl_obj_desc_port_set(&desc, reporter->devlink_port);
devlink_nl_notify_send_desc(devlink, msg, &desc);
}

void
Expand Down
10 changes: 9 additions & 1 deletion net/devlink/netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ int devlink_nl_notify_filter_set_doit(struct sk_buff *skb,
flt->dev_name = pos;
}

if (attrs[DEVLINK_ATTR_PORT_INDEX]) {
flt->port_index = nla_get_u32(attrs[DEVLINK_ATTR_PORT_INDEX]);
flt->port_index_valid = true;
}

/* Don't attach empty filter. */
if (!flt->bus_name && !flt->dev_name) {
if (!flt->bus_name && !flt->dev_name && !flt->port_index_valid) {
kfree(flt);
flt = NULL;
}
Expand All @@ -101,6 +106,9 @@ static bool devlink_obj_desc_match(const struct devlink_obj_desc *desc,
if (desc->dev_name && flt->dev_name &&
strcmp(desc->dev_name, flt->dev_name))
return false;
if (desc->port_index_valid && flt->port_index_valid &&
desc->port_index != flt->port_index)
return false;
return true;
}

Expand Down
5 changes: 3 additions & 2 deletions net/devlink/netlink_gen.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,10 @@ static const struct nla_policy devlink_selftests_run_nl_policy[DEVLINK_ATTR_SELF
};

/* DEVLINK_CMD_NOTIFY_FILTER_SET - do */
static const struct nla_policy devlink_notify_filter_set_nl_policy[DEVLINK_ATTR_DEV_NAME + 1] = {
static const struct nla_policy devlink_notify_filter_set_nl_policy[DEVLINK_ATTR_PORT_INDEX + 1] = {
[DEVLINK_ATTR_BUS_NAME] = { .type = NLA_NUL_STRING, },
[DEVLINK_ATTR_DEV_NAME] = { .type = NLA_NUL_STRING, },
[DEVLINK_ATTR_PORT_INDEX] = { .type = NLA_U32, },
};

/* Ops table for devlink */
Expand Down Expand Up @@ -1243,7 +1244,7 @@ const struct genl_split_ops devlink_nl_ops[74] = {
.cmd = DEVLINK_CMD_NOTIFY_FILTER_SET,
.doit = devlink_nl_notify_filter_set_doit,
.policy = devlink_notify_filter_set_nl_policy,
.maxattr = DEVLINK_ATTR_DEV_NAME,
.maxattr = DEVLINK_ATTR_PORT_INDEX,
.flags = GENL_CMD_CAP_DO,
},
};
5 changes: 4 additions & 1 deletion net/devlink/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ static void devlink_port_notify(struct devlink_port *devlink_port,
enum devlink_command cmd)
{
struct devlink *devlink = devlink_port->devlink;
struct devlink_obj_desc desc;
struct sk_buff *msg;
int err;

Expand All @@ -525,7 +526,9 @@ static void devlink_port_notify(struct devlink_port *devlink_port,
return;
}

devlink_nl_notify_send(devlink, msg);
devlink_nl_obj_desc_init(&desc, devlink);
devlink_nl_obj_desc_port_set(&desc, devlink_port);
devlink_nl_notify_send_desc(devlink, msg, &desc);
}

static void devlink_ports_notify(struct devlink *devlink,
Expand Down

0 comments on commit ded6f77

Please sign in to comment.