Skip to contentSkip to conversation

ipmaddr: use RTM_GETMULTICAST to list multicast addresses

PATCH Applied Yuyang Huang 2 participants 2 messages Jul 18 – Jul 22

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ipmaddr: use RTM_GETMULTICAST to list multicast addresses

Replace /proc/net/igmp and /proc/net/igmp6 parsing in "ip maddr show" with RTM_GETMULTICAST dumps. The kernel dumps IPv6 multicast addresses via netlink since the beginning, IPv4 since v6.15 (eb4e17a1d915), and reports the group users count via IFA_MC_USERS since kernel commits 7cb8198761e6 and e1d0f3f08391.

The netlink result is only used when it carries the same information as procfs: if the dump fails (e.g. no IPv4 dump support) or any entry lacks IFA_MC_USERS, the result is discarded and the procfs parsers run as before, so output is unchanged on older kernels.

Link-layer multicast addresses are still read from /proc/net/dev_mcast as there is no netlink API for them.

When a device is given, its ifindex is passed in the dump request so strict-check kernels filter the dump server side; received entries are checked against the ifindex again for kernels that ignore the request field. An unknown device keeps printing an empty list.

---
Changes in v2:
- accept_maddr(): only accept RTM_NEWMULTICAST; the kernel never sends RTM_GETMULTICAST in dump replies

Changes in v3:
- accept_maddr(): match RTM_GETMULTICAST again, reverting the v2 change; dump replies do carry RTM_GETMULTICAST (RTM_NEWMULTICAST is only used for notifications), confirmed by testing on a live kernel

 include/libnetlink.h |   3 ++
 ip/ipmaddr.c         | 109 +++++++++++++++++++++++++++++++++++++++++--
 lib/libnetlink.c     |  26 +++++++++++
 3 files changed, 134 insertions(+), 4 deletions(-)
include/libnetlink.h +3 -0
index e91505d9..518b8714 100644
@@ -62,6 +62,9 @@ typedef int (*req_filter_fn_t)(struct nlmsghdr *nlh, int reqlen);
 int rtnl_addrdump_req(struct rtnl_handle *rth, int family,
 		      req_filter_fn_t filter_fn)
 	__attribute__((warn_unused_result));
+int rtnl_mcaddrdump_req(struct rtnl_handle *rth, int family,
+			req_filter_fn_t filter_fn)
+	__attribute__((warn_unused_result));
 int rtnl_addrlbldump_req(struct rtnl_handle *rth, int family)
 	__attribute__((warn_unused_result));
 int rtnl_routedump_req(struct rtnl_handle *rth, int family,
ip/ipmaddr.c +105 -4

129 lines not on this page · raw message

lib/libnetlink.c +26 -0
index 8905e297..edf3a8ba 100644
@@ -336,6 +336,32 @@ int rtnl_addrdump_req(struct rtnl_handle *rth, int family,
 	return send(rth->fd, &req, sizeof(req), 0);
 }
 
+int rtnl_mcaddrdump_req(struct rtnl_handle *rth, int family,
+			req_filter_fn_t filter_fn)
+{
+	struct {
+		struct nlmsghdr nlh;
+		struct ifaddrmsg ifm;
+		char buf[128];
+	} req = {
+		.nlh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)),
+		.nlh.nlmsg_type = RTM_GETMULTICAST,
+		.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST,
+		.nlh.nlmsg_seq = rth->dump = ++rth->seq,
+		.ifm.ifa_family = family,
+	};
+
+	if (filter_fn) {
+		int err;
+
+		err = filter_fn(&req.nlh, sizeof(req));
+		if (err)
+			return err;
+	}
+
+	return send(rth->fd, &req, sizeof(req), 0);
+}
+
 int rtnl_addrlbldump_req(struct rtnl_handle *rth, int family)
 {
 	struct {
Signature · 1 line
2.43.0
#1 lore raw
This patch was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:

Hello:

This patch was applied to iproute2/iproute2-next.git (main) by David Ahern <[email protected]>:

Quoted 6 lines · On Sat, 18 Jul 2026 15:48:00 +0900 you wrote:

Replace /proc/net/igmp and /proc/net/igmp6 parsing in "ip maddr show" with RTM_GETMULTICAST dumps. The kernel dumps IPv6 multicast addresses via netlink since the beginning, IPv4 since v6.15 (eb4e17a1d915), and reports the group users count via IFA_MC_USERS since kernel commits 7cb8198761e6 and e1d0f3f08391.

Quoted 6 lines

The netlink result is only used when it carries the same information as procfs: if the dump fails (e.g. no IPv4 dump support) or any entry lacks IFA_MC_USERS, the result is discarded and the procfs parsers run as before, so output is unchanged on older kernels.

[...]

Here is the summary with links:
- [iproute2-next,v3] ipmaddr: use RTM_GETMULTICAST to list multicast addresses

    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=b8cdda55904b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html