Skip to contentSkip to conversation

netlink: support dumping IPv4 multicast addresses

PATCH Superseded Yuyang Huang 2 participants 3 messages Dec 18, 2024 – Dec 19, 2024

Subsystems (3)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 netlink: support dumping IPv4 multicast addresses

Extended RTM_GETMULTICAST to support dumping joined IPv4 multicast addresses, in addition to the existing IPv6 functionality. This allows userspace applications to retrieve both IPv4 and IPv6 multicast addresses through similar netlink command and then monitor future changes by registering to RTNLGRP_IPV4_MCADDR and RTNLGRP_IPV6_MCADDR.

Cc Maciej Żenczykowski <[email protected]>
Cc Lorenzo Colitti <[email protected]>

---

Changelog since v1:
- Minor style fixes.
- Use for_each_pmc_rcu() instead of for_each_pmc_rtnl().

 include/linux/igmp.h |  7 +++++
 net/ipv4/devinet.c   | 61 ++++++++++++++++++++++++++++++++++++--------
 net/ipv4/igmp.c      | 14 ++++------
 3 files changed, 63 insertions(+), 19 deletions(-)
include/linux/igmp.h +7 -0
index 073b30a9b850..221768b47e80 100644
@@ -142,4 +142,11 @@ extern void __ip_mc_inc_group(struct in_device *in_dev, __be32 addr,
 extern void ip_mc_inc_group(struct in_device *in_dev, __be32 addr);
 int ip_mc_check_igmp(struct sk_buff *skb);
 
+#define for_each_pmc_rcu(in_dev, pmc)				\
+	for (pmc = rcu_dereference(in_dev->mc_list);		\
+	     pmc != NULL;					\
+	     pmc = rcu_dereference(pmc->next_rcu))
+
+int inet_fill_ifmcaddr(struct sk_buff *skb, struct net_device *dev,
+		       const struct ip_mc_list *im, int event, int flags);
 #endif
net/ipv4/devinet.c +51 -10

105 lines not on this page · raw message

net/ipv4/igmp.c +5 -9
index 8a370ef37d3f..a262614c29ee 100644
@@ -174,11 +174,6 @@ static void ip_ma_put(struct ip_mc_list *im)
 	}
 }
 
-#define for_each_pmc_rcu(in_dev, pmc)				\
-	for (pmc = rcu_dereference(in_dev->mc_list);		\
-	     pmc != NULL;					\
-	     pmc = rcu_dereference(pmc->next_rcu))
-
 #define for_each_pmc_rtnl(in_dev, pmc)				\
 	for (pmc = rtnl_dereference(in_dev->mc_list);		\
 	     pmc != NULL;					\
@@ -1432,14 +1427,14 @@ 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,
-			      const struct ip_mc_list *im, int event)
+int inet_fill_ifmcaddr(struct sk_buff *skb, struct net_device *dev,
+		       const struct ip_mc_list *im, int event, int flags)
 {
 	struct ifa_cacheinfo ci;
 	struct ifaddrmsg *ifm;
 	struct nlmsghdr *nlh;
 
-	nlh = nlmsg_put(skb, 0, 0, event, sizeof(struct ifaddrmsg), 0);
+	nlh = nlmsg_put(skb, 0, 0, event, sizeof(struct ifaddrmsg), flags);
 	if (!nlh)
 		return -EMSGSIZE;
 
@@ -1464,6 +1459,7 @@ static int inet_fill_ifmcaddr(struct sk_buff *skb, struct net_device *dev,
 	nlmsg_end(skb, nlh);
 	return 0;
 }
+EXPORT_SYMBOL(inet_fill_ifmcaddr);
 
 static void inet_ifmcaddr_notify(struct net_device *dev,
 				 const struct ip_mc_list *im, int event)
@@ -1477,7 +1473,7 @@ static void inet_ifmcaddr_notify(struct net_device *dev,
 	if (!skb)
 		goto error;
 
-	err = inet_fill_ifmcaddr(skb, dev, im, event);
+	err = inet_fill_ifmcaddr(skb, dev, im, event, 0);
 	if (err < 0) {
 		WARN_ON_ONCE(err == -EMSGSIZE);
 		nlmsg_free(skb);
Signature · 1 line
2.47.1.613.gc27f4b7a9f-goog
Reviewed-by on v2 1/1
#1 lore raw
Quoted 11 lines · Yuyang Huang

Extended RTM_GETMULTICAST to support dumping joined IPv4 multicast addresses, in addition to the existing IPv6 functionality. This allows userspace applications to retrieve both IPv4 and IPv6 multicast addresses through similar netlink command and then monitor future changes by registering to RTNLGRP_IPV4_MCADDR and RTNLGRP_IPV6_MCADDR.

Cc Maciej Żenczykowski <[email protected]>
Cc Lorenzo Colitti <[email protected]>

---

#2 lore raw

Per review feedback in a separate patch:

Quoted 1 line

+EXPORT_SYMBOL(inet_fill_ifmcaddr);

This EXPORT_SYMBOL should be removed.

Thanks,
Yuyang

Quoted 15 lines · Eric Dumazet
Quoted 11 lines · Yuyang Huang

Extended RTM_GETMULTICAST to support dumping joined IPv4 multicast addresses, in addition to the existing IPv6 functionality. This allows userspace applications to retrieve both IPv4 and IPv6 multicast addresses through similar netlink command and then monitor future changes by registering to RTNLGRP_IPV4_MCADDR and RTNLGRP_IPV6_MCADDR.

Cc Maciej Żenczykowski <[email protected]>
Cc Lorenzo Colitti <[email protected]>

---