diff options
author | Jiri Pirko <jiri@nvidia.com> | 2023-12-16 13:29:59 +0100 |
---|---|---|
committer | Paolo Abeni <pabeni@redhat.com> | 2023-12-19 15:31:40 +0100 |
commit | 971b4ad88293bef00160e1d38659077fe3a93af6 (patch) | |
tree | b7a311c9a7b2d6b4b0aa694185eb46069ddabaad /include/net/genetlink.h | |
parent | netlink: introduce typedef for filter function (diff) | |
download | linux-971b4ad88293bef00160e1d38659077fe3a93af6.tar.xz linux-971b4ad88293bef00160e1d38659077fe3a93af6.zip |
genetlink: introduce helpers to do filtered multicast
Currently it is possible for netlink kernel user to pass custom
filter function to broadcast send function netlink_broadcast_filtered().
However, this is not exposed to multicast send and to generic
netlink users.
Extend the api and introduce a netlink helper nlmsg_multicast_filtered()
and a generic netlink helper genlmsg_multicast_netns_filtered()
to allow generic netlink families to specify filter function
while sending multicast messages.
Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Diffstat (limited to 'include/net/genetlink.h')
-rw-r--r-- | include/net/genetlink.h | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/include/net/genetlink.h b/include/net/genetlink.h index 6bc37f392a9a..85c63d4f16dd 100644 --- a/include/net/genetlink.h +++ b/include/net/genetlink.h @@ -449,6 +449,35 @@ static inline void genlmsg_cancel(struct sk_buff *skb, void *hdr) } /** + * genlmsg_multicast_netns_filtered - multicast a netlink message + * to a specific netns with filter + * function + * @family: the generic netlink family + * @net: the net namespace + * @skb: netlink message as socket buffer + * @portid: own netlink portid to avoid sending to yourself + * @group: offset of multicast group in groups array + * @flags: allocation flags + * @filter: filter function + * @filter_data: filter function private data + * + * Return: 0 on success, negative error code for failure. + */ +static inline int +genlmsg_multicast_netns_filtered(const struct genl_family *family, + struct net *net, struct sk_buff *skb, + u32 portid, unsigned int group, gfp_t flags, + netlink_filter_fn filter, + void *filter_data) +{ + if (WARN_ON_ONCE(group >= family->n_mcgrps)) + return -EINVAL; + group = family->mcgrp_offset + group; + return nlmsg_multicast_filtered(net->genl_sock, skb, portid, group, + flags, filter, filter_data); +} + +/** * genlmsg_multicast_netns - multicast a netlink message to a specific netns * @family: the generic netlink family * @net: the net namespace @@ -461,10 +490,8 @@ static inline int genlmsg_multicast_netns(const struct genl_family *family, struct net *net, struct sk_buff *skb, u32 portid, unsigned int group, gfp_t flags) { - if (WARN_ON_ONCE(group >= family->n_mcgrps)) - return -EINVAL; - group = family->mcgrp_offset + group; - return nlmsg_multicast(net->genl_sock, skb, portid, group, flags); + return genlmsg_multicast_netns_filtered(family, net, skb, portid, + group, flags, NULL, NULL); } /** |