From: Hangbin Liu <liuhangbin@gmail.com>
To: Yuyang Huang <yuyanghuang@google.com>
Cc: "David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Simon Horman" <horms@kernel.org>,
"David Ahern" <dsahern@kernel.org>,
roopa@cumulusnetworks.com, jiri@resnulli.us,
stephen@networkplumber.org, netdev@vger.kernel.org,
"Maciej Żenczykowski" <maze@google.com>,
"Lorenzo Colitti" <lorenzo@google.com>,
"Patrick Ruddy" <pruddy@vyatta.att-mail.com>
Subject: Re: [PATCH net-next] netlink: add igmp join/leave notifications
Date: Tue, 12 Nov 2024 09:54:04 +0000 [thread overview]
Message-ID: <ZzMlvCA4e3YhYTPn@fedora> (raw)
In-Reply-To: <20241110081953.121682-1-yuyanghuang@google.com>
Hi Yuyang,
Would you mind also update iproute2 for testing?
On Sun, Nov 10, 2024 at 05:19:53PM +0900, Yuyang Huang wrote:
> This change introduces netlink notifications for multicast address
> changes, enabling components like the Android Packet Filter to implement
> IGMP offload solutions.
>
> The following features are included:
> * Addition and deletion of multicast addresses are reported using
> RTM_NEWMULTICAST and RTM_DELMULTICAST messages with AF_INET.
> * A new notification group, RTNLGRP_IPV4_MCADDR, is introduced for
> receiving these events.
>
> This enhancement allows user-space components to efficiently track
> multicast group memberships and program hardware offload filters
> accordingly.
>
> Cc: Maciej Żenczykowski <maze@google.com>
> Cc: Lorenzo Colitti <lorenzo@google.com>
> Co-developed-by: Patrick Ruddy <pruddy@vyatta.att-mail.com>
> Signed-off-by: Patrick Ruddy <pruddy@vyatta.att-mail.com>
> Link: https://lore.kernel.org/r/20180906091056.21109-1-pruddy@vyatta.att-mail.com
> Signed-off-by: Yuyang Huang <yuyanghuang@google.com>
> ---
> include/uapi/linux/rtnetlink.h | 6 ++++
> net/ipv4/igmp.c | 58 ++++++++++++++++++++++++++++++++++
> 2 files changed, 64 insertions(+)
>
> diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
> index 3b687d20c9ed..354a923f129d 100644
> --- a/include/uapi/linux/rtnetlink.h
> +++ b/include/uapi/linux/rtnetlink.h
> @@ -93,6 +93,10 @@ enum {
> RTM_NEWPREFIX = 52,
> #define RTM_NEWPREFIX RTM_NEWPREFIX
>
> + RTM_NEWMULTICAST,
> +#define RTM_NEWMULTICAST RTM_NEWMULTICAST
> + RTM_DELMULTICAST,
> +#define RTM_DELMULTICAST RTM_DELMULTICAST
> RTM_GETMULTICAST = 58,
> #define RTM_GETMULTICAST RTM_GETMULTICAST
>
> @@ -774,6 +778,8 @@ enum rtnetlink_groups {
> #define RTNLGRP_TUNNEL RTNLGRP_TUNNEL
> RTNLGRP_STATS,
> #define RTNLGRP_STATS RTNLGRP_STATS
> + RTNLGRP_IPV4_MCADDR,
> +#define RTNLGRP_IPV4_MCADDR RTNLGRP_IPV4_MCADDR
> __RTNLGRP_MAX
> };
> #define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
> diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
> index 9bf09de6a2e7..34575f5392a8 100644
> --- a/net/ipv4/igmp.c
> +++ b/net/ipv4/igmp.c
> @@ -88,6 +88,7 @@
> #include <linux/byteorder/generic.h>
>
> #include <net/net_namespace.h>
> +#include <net/netlink.h>
> #include <net/arp.h>
> #include <net/ip.h>
> #include <net/protocol.h>
> @@ -1430,6 +1431,60 @@ static void ip_mc_hash_remove(struct in_device *in_dev,
> *mc_hash = im->next_hash;
> }
>
> +static int inet_fill_ifmcaddr(struct sk_buff *skb, struct net_device *dev,
> + __be32 addr, int event)
> +{
> + struct nlmsghdr *nlh;
> + struct ifaddrmsg *ifm;
> +
> + nlh = nlmsg_put(skb, 0, 0, event, sizeof(struct ifaddrmsg), 0);
> + if (!nlh)
> + return -EMSGSIZE;
> +
> + ifm = nlmsg_data(nlh);
> + ifm->ifa_family = AF_INET;
> + ifm->ifa_prefixlen = 32;
> + ifm->ifa_flags = IFA_F_PERMANENT;
> + ifm->ifa_scope = RT_SCOPE_LINK;
> + ifm->ifa_index = dev->ifindex;
> +
> + if (nla_put_in_addr(skb, IFA_MULTICAST, addr) < 0) {
> + nlmsg_cancel(skb, nlh);
> + return -EMSGSIZE;
> + }
> +
> + nlmsg_end(skb, nlh);
> + return 0;
> +}
> +
> +static inline int inet_ifmcaddr_msgsize(void)
> +{
> + return NLMSG_ALIGN(sizeof(struct ifaddrmsg))
> + + nla_total_size(sizeof(__be32));
> +}
> +
> +static void inet_ifmcaddr_notify(struct net_device *dev, __be32 addr, int event)
> +{
> + struct net *net = dev_net(dev);
> + struct sk_buff *skb;
> + int err = -ENOBUFS;
> +
> + skb = nlmsg_new(inet_ifmcaddr_msgsize(), GFP_ATOMIC);
> + if (!skb)
> + goto error;
> +
> + err = inet_fill_ifmcaddr(skb, dev, addr, event);
> + if (err < 0) {
> + WARN_ON(err == -EMSGSIZE);
> + kfree_skb(skb);
> + goto error;
> + }
> +
> + rtnl_notify(skb, net, 0, RTNLGRP_IPV4_MCADDR, NULL, GFP_ATOMIC);
> + return;
> +error:
> + rtnl_set_sk_err(net, RTNLGRP_IPV4_MCADDR, err);
> +}
>
> /*
> * A socket has joined a multicast group on device dev.
> @@ -1476,6 +1531,7 @@ static void ____ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
> igmpv3_del_delrec(in_dev, im);
> #endif
> igmp_group_added(im);
> + inet_ifmcaddr_notify(in_dev->dev, addr, RTM_NEWMULTICAST);
> if (!in_dev->dead)
> ip_rt_multicast_event(in_dev);
> out:
> @@ -1689,6 +1745,8 @@ void __ip_mc_dec_group(struct in_device *in_dev, __be32 addr, gfp_t gfp)
> *ip = i->next_rcu;
> in_dev->mc_count--;
> __igmp_group_dropped(i, gfp);
> + inet_ifmcaddr_notify(in_dev->dev, addr,
> + RTM_DELMULTICAST);
> ip_mc_clear_src(i);
>
> if (!in_dev->dead)
> --
> 2.47.0.277.g8800431eea-goog
>
next prev parent reply other threads:[~2024-11-12 9:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-10 8:19 [PATCH net-next] netlink: add igmp join/leave notifications Yuyang Huang
2024-11-12 9:54 ` Hangbin Liu [this message]
2024-11-12 10:10 ` Yuyang Huang
2024-11-12 11:34 ` Hangbin Liu
2024-11-12 19:34 ` Andrew Lunn
2024-11-13 0:56 ` Yuyang Huang
2024-11-13 1:17 ` Andrew Lunn
2024-11-13 4:26 ` Yuyang Huang
[not found] ` <9fa93b71-cd81-44ce-b7cc-24b12be8cb24@lunn.ch>
2024-11-14 5:58 ` Yuyang Huang
2024-11-14 13:25 ` Andrew Lunn
2024-11-14 14:19 ` Yuyang Huang
2024-11-12 13:45 ` Nicolas Dichtel
2024-11-12 14:06 ` Yuyang Huang
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=ZzMlvCA4e3YhYTPn@fedora \
--to=liuhangbin@gmail.com \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=lorenzo@google.com \
--cc=maze@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=pruddy@vyatta.att-mail.com \
--cc=roopa@cumulusnetworks.com \
--cc=stephen@networkplumber.org \
--cc=yuyanghuang@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).