From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net,
edumazet@google.com, jacob.e.keller@intel.com, jhs@mojatatu.com,
johannes@sipsolutions.net, andriy.shevchenko@linux.intel.com,
amritha.nambiar@intel.com, sdf@google.com, horms@kernel.org
Subject: [patch net-next v3 9/9] devlink: extend multicast filtering by port index
Date: Mon, 20 Nov 2023 09:46:57 +0100 [thread overview]
Message-ID: <20231120084657.458076-10-jiri@resnulli.us> (raw)
In-Reply-To: <20231120084657.458076-1-jiri@resnulli.us>
From: Jiri Pirko <jiri@nvidia.com>
Expose the previously introduced notification multicast messages
filtering infrastructure and allow the user to select messages using
port index.
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
Documentation/netlink/specs/devlink.yaml | 1 +
net/devlink/devl_internal.h | 9 +++++++++
net/devlink/health.c | 6 +++++-
net/devlink/netlink.c | 10 +++++++++-
net/devlink/netlink_gen.c | 5 +++--
net/devlink/port.c | 5 ++++-
tools/net/ynl/generated/devlink-user.c | 2 ++
tools/net/ynl/generated/devlink-user.h | 9 +++++++++
8 files changed, 42 insertions(+), 5 deletions(-)
diff --git a/Documentation/netlink/specs/devlink.yaml b/Documentation/netlink/specs/devlink.yaml
index cc4991cbce83..49d4fbf3fe44 100644
--- a/Documentation/netlink/specs/devlink.yaml
+++ b/Documentation/netlink/specs/devlink.yaml
@@ -2065,3 +2065,4 @@ operations:
attributes:
- bus-name
- dev-name
+ - port-index
diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
index 0ee0bcdd4a7d..3ed7808013f1 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h
@@ -181,6 +181,8 @@ static inline bool devlink_nl_notify_need(struct devlink *devlink)
struct devlink_obj_desc {
const char *bus_name;
const char *dev_name;
+ unsigned int port_index;
+ bool port_index_valid;
long data[];
};
@@ -192,6 +194,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,
diff --git a/net/devlink/health.c b/net/devlink/health.c
index 2f06e4ddbf3b..0e96d26203f1 100644
--- a/net/devlink/health.c
+++ b/net/devlink/health.c
@@ -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;
@@ -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
diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c
index 738e2f340ab9..6c033d1f7e64 100644
--- a/net/devlink/netlink.c
+++ b/net/devlink/netlink.c
@@ -46,11 +46,16 @@ 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;
+ }
+
/* Free the existing filter if any. */
kfree(sk->sk_user_data);
/* 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;
}
@@ -68,6 +73,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;
}
diff --git a/net/devlink/netlink_gen.c b/net/devlink/netlink_gen.c
index f207f3fc7e20..b3f37e3c1b64 100644
--- a/net/devlink/netlink_gen.c
+++ b/net/devlink/netlink_gen.c
@@ -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 */
@@ -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,
},
};
diff --git a/net/devlink/port.c b/net/devlink/port.c
index 758df3000a1b..62e54e152ecf 100644
--- a/net/devlink/port.c
+++ b/net/devlink/port.c
@@ -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;
@@ -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,
diff --git a/tools/net/ynl/generated/devlink-user.c b/tools/net/ynl/generated/devlink-user.c
index cd5f70eadf5b..86392da0b52c 100644
--- a/tools/net/ynl/generated/devlink-user.c
+++ b/tools/net/ynl/generated/devlink-user.c
@@ -6853,6 +6853,8 @@ int devlink_notify_filter_set(struct ynl_sock *ys,
mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, req->bus_name);
if (req->_present.dev_name_len)
mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, req->dev_name);
+ if (req->_present.port_index)
+ mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_INDEX, req->port_index);
err = ynl_exec(ys, nlh, NULL);
if (err < 0)
diff --git a/tools/net/ynl/generated/devlink-user.h b/tools/net/ynl/generated/devlink-user.h
index e5d79b824a67..b96837663e6e 100644
--- a/tools/net/ynl/generated/devlink-user.h
+++ b/tools/net/ynl/generated/devlink-user.h
@@ -5258,10 +5258,12 @@ struct devlink_notify_filter_set_req {
struct {
__u32 bus_name_len;
__u32 dev_name_len;
+ __u32 port_index:1;
} _present;
char *bus_name;
char *dev_name;
+ __u32 port_index;
};
static inline struct devlink_notify_filter_set_req *
@@ -5292,6 +5294,13 @@ devlink_notify_filter_set_req_set_dev_name(struct devlink_notify_filter_set_req
memcpy(req->dev_name, dev_name, req->_present.dev_name_len);
req->dev_name[req->_present.dev_name_len] = 0;
}
+static inline void
+devlink_notify_filter_set_req_set_port_index(struct devlink_notify_filter_set_req *req,
+ __u32 port_index)
+{
+ req->_present.port_index = 1;
+ req->port_index = port_index;
+}
/*
* Set notification messages socket filter.
--
2.41.0
next prev parent reply other threads:[~2023-11-20 8:47 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-20 8:46 [patch net-next v3 0/9] devlink: introduce notifications filtering Jiri Pirko
2023-11-20 8:46 ` [patch net-next v3 1/9] devlink: use devl_is_registered() helper instead xa_get_mark() Jiri Pirko
2023-11-20 8:46 ` [patch net-next v3 2/9] devlink: introduce __devl_is_registered() helper and use it instead of xa_get_mark() Jiri Pirko
2023-11-20 8:46 ` [patch net-next v3 3/9] devlink: send notifications only if there are listeners Jiri Pirko
2023-11-20 8:46 ` [patch net-next v3 4/9] devlink: introduce a helper for netlink multicast send Jiri Pirko
2023-11-20 8:46 ` [patch net-next v3 5/9] genetlink: implement release callback and free sk_user_data there Jiri Pirko
2023-11-21 2:50 ` Jakub Kicinski
2023-11-21 7:36 ` Jiri Pirko
2023-11-21 13:12 ` Jiri Pirko
2023-11-21 17:55 ` Jakub Kicinski
2023-11-22 9:29 ` Jiri Pirko
2023-11-22 17:08 ` Jakub Kicinski
2023-11-22 18:20 ` Jiri Pirko
2023-11-22 19:50 ` Jakub Kicinski
2023-11-23 6:37 ` Jiri Pirko
2023-11-23 10:32 ` Jiri Pirko
2023-11-23 16:24 ` Jakub Kicinski
2023-11-23 16:53 ` Jiri Pirko
2023-11-20 8:46 ` [patch net-next v3 6/9] netlink: introduce typedef for filter function Jiri Pirko
2023-11-20 8:46 ` [patch net-next v3 7/9] genetlink: introduce helpers to do filtered multicast Jiri Pirko
2023-11-20 8:46 ` [patch net-next v3 8/9] devlink: add a command to set notification filter and use it for multicasts Jiri Pirko
2023-11-21 2:51 ` Jakub Kicinski
2023-11-21 7:35 ` Jiri Pirko
2023-11-20 8:46 ` Jiri Pirko [this message]
2023-11-21 2:29 ` [patch net-next v3 0/9] devlink: introduce notifications filtering Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231120084657.458076-10-jiri@resnulli.us \
--to=jiri@resnulli.us \
--cc=amritha.nambiar@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=jhs@mojatatu.com \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sdf@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).