rtnetlink: dump link-layer multicast addresses
Subsystems (5)
v4 cover rtnetlink: dump link-layer multicast addresses
"ip maddr show" prints three kinds of entries: link-layer, IPv4 and IPv6. The IPv4 and IPv6 ones can be read over netlink today: IPv6 has had RTM_GETMULTICAST for a long time and IPv4 got it in eb4e17a1d915 ("netlink: support dumping IPv4 multicast addresses"), with IFA_MC_USERS added later so the user count no longer has to come from procfs.
The link-layer list is the missing piece. dev->mc, the addresses programmed into the device filter, is only exported via /proc/net/dev_mcast, so iproute2 still carries a procfs parser just for that. This series closes the gap so that "ip maddr show" can be served from rtnetlink alone.
Patch 1 fixes the type of target-netnsid in the rt-addr spec. Patch 2 handles RTM_GETMULTICAST dumps with ifa_family set to AF_PACKET and walks dev->mc under netif_addr_lock_bh(), no RTNL. The reply reuses the ifaddrmsg format of the IPv4 and IPv6 dumps: IFA_MULTICAST carries the raw link-layer address, IFA_MC_USERS the reference count, and a new IFA_F_GLOBAL flag in IFA_FLAGS marks entries added explicitly, which is the "static" column /proc/net/dev_mcast has and "ip maddr" prints. A non-zero ifa_index limits the dump to one device and IFA_TARGET_NETNSID selects another netns, like the IPv4 and IPv6 dumps.
Patch 3 updates the rt-addr spec and patch 4 adds a selftest that checks the filter, the user count, the global flag and target-netnsid.
Nothing changes for other families. AF_PACKET dumps returned -EOPNOTSUPP before, so iproute2 can keep the procfs fallback for older kernels. I have the iproute2 side ready and will post it once this is in; with it, "ip maddr show" does not open /proc/net at all.
Changes in v4:
- Reset the resume offset when the device the dump stopped at is gone
- Use a tracked netns reference (put_net_track)
- Say ifa-family must be set in the spec doc, drop the AF_UNSPEC remark
- Close the netlink socket and guard the checks in the selftest
- Drop the Fixes tag
Changes in v3:
- Report the static bit as a new IFA_F_GLOBAL flag in IFA_FLAGS instead of IFA_F_PERMANENT
- Support IFA_TARGET_NETNSID and test it
- Describe global_use accurately, it is also set by dev_mc_add_excl()
- Fix the target-netnsid type in the rt-addr spec, as its own patch
Changes in v2:
- Always validate the request header, not only with strict checking
- Use a single "with" statement in the selftest (ruff)
Yuyang Huang (4):
netlink: specs: rt-addr: fix the type of target-netnsid
rtnetlink: add AF_PACKET multicast dumps
netlink: specs: rt-addr: document AF_PACKET multicast dumps
selftests: net: test AF_PACKET multicast dumps
Documentation/netlink/specs/rt-addr.yaml | 17 ++- include/uapi/linux/if_addr.h | 1 + net/core/rtnetlink.c | 174 +++++++++++++++++++++++ tools/testing/selftests/net/rtnetlink.py | 75 +++++++++- 4 files changed, 261 insertions(+), 6 deletions(-)
Signature · 1 line
2.43.0
PATCH v4 1/4 netlink: specs: rt-addr: fix the type of target-netnsid
The kernel parses IFA_TARGET_NETNSID as NLA_S32 and rt-link.yaml declares its target-netnsid as s32, but rt-addr.yaml has it as binary.
--- Documentation/netlink/specs/rt-addr.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/netlink/specs/rt-addr.yaml +1 -1
@@ -119,7 +119,7 @@ attribute-sets: type: u32 - name: target-netnsid - type: binary + type: s32 - name: proto type: u8
Signature · 1 line
2.43.0
Re: [PATCH net-next v4 1/4] netlink: specs: rt-addr: fix the type of target-netnsid
Le 11/09/2026 à 12:51, Yuyang Huang a écrit :
Quoted 4 lines
The kernel parses
IFA_TARGET_NETNSIDasNLA_S32andrt-link.yamldeclares its target-netnsid as s32, butrt-addr.yamlhas it as binary.Signed-off-by Yuyang Huang <[email protected]>
PATCH v4 2/4 rtnetlink: add AF_PACKET multicast dumps
In reply to Yuyang HuangRTM_GETMULTICAST dumps IPv4 and IPv6 multicast group memberships, but the device multicast list (dev->mc) is only available through /proc/net/dev_mcast, so "ip maddr show" still has to parse procfs for its link-layer entries.
Handle RTM_GETMULTICAST dumps with ifa_family set to AF_PACKET and report every entry of dev->mc in the existing ifaddrmsg format:
- IFA_MULTICAST carries the raw link-layer address
- IFA_MC_USERS carries the entry reference count
- IFA_F_GLOBAL in IFA_FLAGS reports netdev_hw_addr::global_use, set by dev_mc_add_global() (SIOCADDMULTI) and dev_mc_add_excl() ("bridge fdb add ... self"), i.e. entries added explicitly rather than by a protocol join. This is the static column of /proc/net/dev_mcast
- ifa_scope is RT_SCOPE_LINK
This covers every column of /proc/net/dev_mcast. AF_PACKET is the family iproute2 already uses for link-layer addresses ("ip -0").
The default FDB dump also walks dev->mc, but only for Ethernet devices without an ndo_fdb_dump of their own, so bridge, vxlan or macvlan devices never show their multicast filter there, and it has no users count or global_use bit. Extending it would change "bridge fdb show" output and add NDA_* attributes.
There are no legacy users of AF_PACKET requests, so they are always
validated: prefixlen, flags and scope must be zero and a non-zero ifa_index restricts the dump to that device. IFA_TARGET_NETNSID selects another netns like the IPv4 and IPv6 dumps and is the only attribute accepted. The dump runs under RCU and netif_addr_lock_bh() and does not need RTNL.
--- include/uapi/linux/if_addr.h | 1 + net/core/rtnetlink.c | 174 +++++++++++++++++++++++++++++++++++ 2 files changed, 175 insertions(+)
include/uapi/linux/if_addr.h +1 -0
@@ -57,6 +57,7 @@ enum {#define IFA_F_NOPREFIXROUTE 0x200#define IFA_F_MCAUTOJOIN 0x400#define IFA_F_STABLE_PRIVACY 0x800 +#define IFA_F_GLOBAL 0x1000struct ifa_cacheinfo {__u32 ifa_prefered;
net/core/rtnetlink.c +174 -0
186 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH net-next v4 2/4] rtnetlink: add AF_PACKET multicast dumps
Le 11/09/2026 à 12:51, Yuyang Huang a écrit :
Quoted 26 lines
RTM_GETMULTICASTdumps IPv4 and IPv6 multicast group memberships, but the device multicast list (dev->mc) is only available through/proc/net/dev_mcast, so "ip maddr show" still has to parse procfs for its link-layer entries.Handle
RTM_GETMULTICASTdumps withifa_familyset toAF_PACKETand report every entry ofdev->mcin the existing ifaddrmsg format:-
IFA_MULTICASTcarries the raw link-layer address
-IFA_MC_USERScarries the entry reference count
-IFA_F_GLOBALinIFA_FLAGSreportsnetdev_hw_addr::global_use, set bydev_mc_add_global()(SIOCADDMULTI) anddev_mc_add_excl()("bridge fdb add ... self"), i.e. entries added explicitly rather than by a protocol join. This is the static column of/proc/net/dev_mcast
-ifa_scopeisRT_SCOPE_LINKThis covers every column of
/proc/net/dev_mcast.AF_PACKETis the family iproute2 already uses for link-layer addresses ("ip -0").The default FDB dump also walks
dev->mc, but only for Ethernet devices without anndo_fdb_dumpof their own, so bridge, vxlan or macvlan devices never show their multicast filter there, and it has no users count orglobal_usebit. Extending it would change "bridge fdb show" output and add NDA_* attributes.
Quoted 8 lines
There are no legacy users of
AF_PACKETrequests, so they are always
validated: prefixlen, flags and scope must be zero and a non-zeroifa_indexrestricts the dump to that device.IFA_TARGET_NETNSIDselects another netns like the IPv4 and IPv6 dumps and is the only attribute accepted. The dump runs under RCU andnetif_addr_lock_bh()and does not need RTNL.Signed-off-by Yuyang Huang <[email protected]>
PATCH v4 3/4 netlink: specs: rt-addr: document AF_PACKET multicast dumps
In reply to Yuyang HuangAdd the global flag, list the attributes the AF_PACKET dump uses and describe how ifa-family selects IPv4, IPv6 or link-layer output for RTM_GETMULTICAST.
--- Documentation/netlink/specs/rt-addr.yaml | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
Documentation/netlink/specs/rt-addr.yaml +13 -2
@@ -77,6 +77,8 @@ definitions: name: mcautojoin - name: stable-privacy + - + name: global attribute-sets: -
@@ -168,7 +170,13 @@ operations: attributes: *ifaddr-all - name: getmulticast - doc: Get / dump IPv4/IPv6 multicast addresses. + doc: | + Get / dump multicast addresses. ifa-family must select the address + family: AF_INET or AF_INET6 for the IP multicast groups joined on + a device, AF_PACKET for the link-layer multicast addresses in the + device filter. Link-layer entries added explicitly, e.g. with + SIOCADDMULTI or "bridge fdb add ... self", rather than by a + protocol join are reported with the global flag set. attribute-set: addr-attrs fixed-header: ifaddrmsg do:
@@ -181,10 +189,13 @@ operations: - multicast - mc-users - cacheinfo + - flags + - target-netnsid dump: request: value: 58 - attributes: [] + attributes: + - target-netnsid reply: value: 58 attributes: *mcaddr-attrs
Signature · 1 line
2.43.0
Re: [PATCH net-next v4 3/4] netlink: specs: rt-addr: document AF_PACKET multicast dumps
Le 11/09/2026 à 12:51, Yuyang Huang a écrit :
Quoted 5 lines
Add the global flag, list the attributes the
AF_PACKETdump uses and describe how ifa-family selects IPv4, IPv6 or link-layer output forRTM_GETMULTICAST.Signed-off-by Yuyang Huang <[email protected]>
PATCH v4 4/4 selftests: net: test AF_PACKET multicast dumps
In reply to Yuyang HuangDump the link-layer multicast addresses of a dummy device and verify that ifa_index restricts the dump to that device, that the all-hosts address joined on link up is listed without IFA_F_GLOBAL, that an address added with SIOCADDMULTI is listed with IFA_F_GLOBAL and IFA_MC_USERS, and that IFA_TARGET_NETNSID dumps another netns. Skip when the kernel does not support AF_PACKET dumps.
--- tools/testing/selftests/net/rtnetlink.py | 75 +++++++++++++++++++++++- 1 file changed, 72 insertions(+), 3 deletions(-)
tools/testing/selftests/net/rtnetlink.py +72 -3
@@ -1,17 +1,21 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0 +import errno import socket import struct import time from lib.py import bkg, ip, ksft_exit, ksft_run, ksft_eq, ksft_ge, ksft_true, KsftSkipEx -from lib.py import ksft_not_in, ksft_not_none -from lib.py import CmdExitFailure, NetNS, NetNSEnter, RtnlAddrFamily, RtnlRouteFamily +from lib.py import ksft_in, ksft_not_in, ksft_not_none +from lib.py import CmdExitFailure, NetNS, NetNSEnter, NlError, RtnlAddrFamily, RtnlRouteFamily from lib.py import defer IPV4_ALL_HOSTS_MULTICAST = b'\xe0\x00\x00\x01' IPV4_TEST_MULTICAST = b'\xef\x01\x01\x01' IPV6_TEST_MULTICAST = bytes.fromhex('ff020000000000000000000000000123') +ETH_ALL_HOSTS_MULTICAST = bytes.fromhex('01005e000001') +ETH_TEST_MULTICAST_STR = '01:00:5e:01:01:01' +ETH_TEST_MULTICAST = bytes.fromhex(ETH_TEST_MULTICAST_STR.replace(':', '')) def _users_for(rtnl: RtnlAddrFamily, family: int, grp: bytes, ifindex: int):
@@ -105,6 +109,70 @@ def dump_mcaddr6_check() -> None: s2.close() +def dump_mcaddr_l2_check() -> None: + """ + Verify link-layer multicast addresses in an AF_PACKET RTM_GETMULTICAST + dump: the ifa-index filter, mc-users, the global flag and + target-netnsid. + """ + + with NetNS() as ns, NetNSEnter(str(ns)): + for ifname in ("dummy1", "dummy2"): + ip(f"link add name {ifname} type dummy") + ip(f"link set {ifname} up") + dev_idx = socket.if_nametoindex("dummy1") + ip(f"maddr add {ETH_TEST_MULTICAST_STR} dev dummy1") + + rtnl = RtnlAddrFamily() + defer(rtnl.close) + try: + addresses = rtnl.getmulticast( + {"ifa-family": socket.AF_PACKET, "ifa-index": dev_idx}, + dump=True) + except NlError as e: + if e.error == errno.EOPNOTSUPP: + raise KsftSkipEx( + "kernel does not support AF_PACKET multicast dump") + raise + + # dummy2 has entries as well, only dummy1 may be listed + ksft_eq({addr['ifa-index'] for addr in addresses}, {dev_idx}, + "AF_PACKET multicast dump ignored ifa-index filter") + + entries = {addr['multicast']: addr for addr in addresses} + + # Bringing an Ethernet device up joins 224.0.0.1, which maps + # to 01:00:5e:00:00:01 in the device multicast list. + all_hosts = entries.get(ETH_ALL_HOSTS_MULTICAST) + ksft_not_none(all_hosts, + "dummy1 does not have the all-hosts link-layer address") + if all_hosts is not None: + ksft_not_in('global', all_hosts['flags'], + "protocol entry is global") + + static = entries.get(ETH_TEST_MULTICAST) + ksft_not_none(static, "dummy1 does not have the SIOCADDMULTI address") + if static is not None: + ksft_eq(static['mc-users'], 1, + "unexpected mc-users for the SIOCADDMULTI address") + ksft_in('global', static['flags'], + "SIOCADDMULTI entry is not global") + + # target-netnsid dumps another netns, ifa-index is relative to it + with NetNS() as peer: + ip(f"netns set {peer} 5") + ip("link add name dummy3 type dummy", ns=peer) + ip("link set dummy3 up", ns=peer) + peer_idx = ip("link show dummy3", json=True, ns=peer)[0]['ifindex'] + + addresses = rtnl.getmulticast( + {"ifa-family": socket.AF_PACKET, "target-netnsid": 5}, + dump=True) + ksft_eq({(addr['ifa-index'], addr['target-netnsid']) + for addr in addresses}, {(peer_idx, 5)}, + "target-netnsid did not dump the peer netns") + + def ipv4_devconf_notify() -> None: """ Configure an interface and set ipv4-devconf values through netlink
@@ -315,7 +383,8 @@ def ipv6_route_del_reason_absent() -> None: def main() -> None: - ksft_run([dump_mcaddr_check, dump_mcaddr6_check, ipv4_devconf_notify, + ksft_run([dump_mcaddr_check, dump_mcaddr6_check, dump_mcaddr_l2_check, + ipv4_devconf_notify, ipv6_route_del_reason_expired, ipv6_route_del_reason_ra_withdrawn, ipv6_route_del_reason_absent])
Signature · 1 line
2.43.0
Jakub Kicinski
maintainerQuoted 1 line · On Fri, 11 Sep 2026 19:50:59 +0900 Yuyang Huang wrote:
Subject: [PATCH net-next v4 0/4] rtnetlink: dump link-layer multicast addresses
The new test seems to be failing:
# 0.14 [+0.05] # Check| At /srv/vmksft/testing/wt-1/tools/testing/selftests/net/./rtnetlink.py, line 171, in dump_mcaddr_l2_check:
# 0.15 [+0.01] # Check| ksft_eq({(addr['ifa-index'], addr['target-netnsid'])
# 0.15 [+0.00] # Check failed {(9, 5), (8, 5), (11, 5)} != {(11, 5)} target-netnsid did not dump the peer netns # 0.17 [+0.01] not ok 3 rtnetlink.dump_mcaddr_l2_check
Please wait a couple of days with the repost.
Quoted 4 lines · Jakub Kicinski
Quoted 1 line · On Fri, 11 Sep 2026 19:50:59 +0900 Yuyang Huang wrote:
Subject: [PATCH net-next v4 0/4] rtnetlink: dump link-layer multicast addresses
Quoted 8 lines
The new test seems to be failing:
# 0.14 [+0.05] # Check| At
/srv/vmksft/testing/wt-1/tools/testing/selftests/net/./rtnetlink.py, line 171, indump_mcaddr_l2_check:
# 0.15 [+0.01] # Check| ksft_eq({(addr['ifa-index'], addr['target-netnsid'])
# 0.15 [+0.00] # Check failed {(9, 5), (8, 5), (11, 5)} != {(11, 5)} target-netnsid did not dump the peer netns # 0.17 [+0.01] not ok 3 rtnetlink.dump_mcaddr_l2_checkPlease wait a couple of days with the repost.
It looks like the test is flaky, I think I got a fix working locally, will wait a couple of days and then repost again.