rtnetlink: dump link-layer multicast addresses
Subsystems (7)
v9 cover rtnetlink: dump link-layer multicast addresses
"ip maddr show" prints link-layer, IPv4 and IPv6 entries. The IPv4 and IPv6 ones come over netlink today, with IFA_MC_USERS for the user count. The link-layer list, dev->mc, is only exported via /proc/net/dev_mcast, so iproute2 and other users still parse procfs for it.
This series adds the AF_PACKET family to RTM_GETMULTICAST so that the link-layer multicast addresses are reported the same way. Patch 4 dumps dev->mc in the ifaddrmsg format of the IPv4 and IPv6 dumps: IFA_MULTICAST carries the address, IFA_MC_USERS the reference count and a new IFA_F_GLOBAL flag marks entries added explicitly, the "static" column of /proc/net/dev_mcast. ifa_index limits the dump to one device and IFA_TARGET_NETNSID selects another netns. Patches 2 and 3 add a generation counter for dev->mc changes so a multi-part dump reports NLM_F_DUMP_INTR like the IPv4 and IPv6 ones. Patches 1 and 5 update the rt-addr spec and patch 6 adds a selftest.
AF_PACKET dumps returned -EOPNOTSUPP before, so iproute2 can keep the procfs fallback for older kernels. The iproute2 side is ready and will be posted once this is in.
Changes in v9:
- Change the count of a netdev_hw_addr_list through helpers only and rename it to _count, as its own patch
- Use the count helpers in __hw_addr_splice() too
- Note in the spec doc that the header checks are unconditional for AF_PACKET only
Changes in v8:
- Set the owner of every list a device has, not only dev->mc, and check for dev->mc in one place when bumping the counter
- Add __hw_addr_count_inc/dec/reset() so a change of list->count and the counter bump stay together
Changes in v7:
- Add a per netns generation counter bumped on dev->mc changes and fold it into cb->seq, dev_base_seq alone did not cover the dumped entries
- Sample cb->seq under the address lock of each device and again when a dump round ends, so the NLMSG_DONE check sees a change too
Changes in v6:
- Move the dump to net/core/dev_addr_lists.c next to the dev->mc helpers
- Stamp cb->seq from dev_base_seq and check dump consistency
- Let an unexpected dump error propagate instead of skipping
- Check for an address only present in the peer netns in the target-netnsid selftest, the peer and local ifindex can be equal
- Document the ifa-index filter and the zero header fields in the spec
Changes in v5:
- Filter the target-netnsid selftest dump by ifa-index, a new netns also contains the fallback tunnel devices
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 (6):
netlink: specs: rt-addr: fix the type of target-netnsid
net: change netdev_hw_addr_list count through helpers
net: add a generation counter for dev->mc changes
net: 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 | 20 +- .../net/ethernet/cavium/octeon/octeon_mgmt.c | 4 +- .../net/wireless/microchip/wilc1000/netdev.c | 8 +- include/linux/netdevice.h | 11 +- include/net/net_namespace.h | 1 + include/uapi/linux/if_addr.h | 1 + net/core/dev_addr_lists.c | 259 +++++++++++++++++- net/core/dev_addr_lists_test.c | 18 +- net/core/rtnetlink.c | 2 + net/mac80211/driver-ops.h | 2 +- tools/testing/selftests/net/rtnetlink.py | 73 ++++- 11 files changed, 364 insertions(+), 35 deletions(-)
Signature · 1 line
2.43.0
PATCH v9 1/6 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
[email protected]
AI reviewRe: [PATCH net-next v9 1/6] netlink: specs: rt-addr: fix the type of target-netnsid
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit "netlink: specs: rt-addr: fix the type of target- netnsid" fixes a bug in one specific earlier commit, but its message…
Pre-existing issues:
- [Low] This problem wasn't introduced by this patch, but after this commit rt-addr.yaml still lists target-netnsid in no operation's…
--
netlink: specs: rt-addr: fix the type of target-netnsid
This commit changes the type of the target-netnsid attribute in the rt-addr netlink spec from binary to s32. That matches the NLA_S32 policy the kernel uses for IFA_TARGET_NETNSID and the type rt-link.yaml already declares.
Documentation/netlink/specs/rt-addr.yaml attribute-sets: · line 122
Quoted 10 lines
Documentation/netlink/specs/rt-addr.yaml +1
-1@@ -119,7 +119,7 @@ attribute-sets: type: u32 - name: target-netnsid - type: binary + type: s32
[Severity: Low]
Should this patch carry a Fixes: tag?
The binary type for target-netnsid has been there since the spec was first added, when the file was still named rt_addr.yaml. Commit 0c8e30252d9f later renamed the attribute but did not change its type.
The kernel has always treated this attribute as s32. In net/ipv4/devinet.c and net/ipv6/addrconf.c the policy entry is:
[IFA_TARGET_NETNSID] = { .type = NLA_S32 },The value is written with nla_put_s32() and read with nla_get_s32().
Perhaps:
[Severity: Low]
This is a pre-existing issue and was not introduced by this patch. Even with the type corrected, no operation in rt-addr.yaml lists target-netnsid. The getaddr dump in particular leaves it out:
name: getaddr
doc: Dump address information.
attribute-set: addr-attrs
dump:
request:
value: 22
attributes: []
reply:
value: 20
attributes: *ifaddr-allThe kernel accepts IFA_TARGET_NETNSID in RTM_GETADDR dump requests:
net/ipv4/devinet.c:inet_valid_dump_ifaddr_req() {
...
if (i == IFA_TARGET_NETNSID) {
struct net *net;
fillargs->netnsid = nla_get_s32(tb[i]);
...
}inet6_rtm_valid_getaddr_req() and inet6_rtm_getaddr() in net/ipv6/addrconf.c accept it too.
The kernel also puts it in replies, from inet_fill_ifaddr() and inet6_fill_ifaddr():
if (args->netnsid >= 0 && nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid))
Could getaddr's request and reply attribute lists include target-netnsid? Without it, YNL-generated code cannot dump addresses from another netns through getaddr.
A later commit in this series, "netlink: specs: rt-addr: document AF_PACKET multicast dumps", adds target-netnsid to the getmulticast request and reply lists. getaddr is still unchanged at the end of the series.
Quoted 3 lines
Documentation/netlink/specs/rt-addr.yaml +0
-0- name: proto type: u8
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260930112842.21323-1-sigefriedhyy%40gmail.com
Re: [PATCH net-next v9 1/6] netlink: specs: rt-addr: fix the type of target-netnsid
Quoted 2 lines
- [Low] The commit "netlink: specs: rt-addr: fix the type of target- netnsid" fixes a bug in one specific earlier commit, but its message…
The Fixes tag was dropped in v4 on purpose, this is a spec fix for net-next, not stable material.
Quoted 2 lines
- [Low] This problem wasn't introduced by this patch, but after this commit
rt-addr.yamlstill lists target-netnsid in no operation's…
Pre-existing and unrelated to multicast dumps, can be fixed separately.
PATCH v9 2/6 net: change netdev_hw_addr_list count through helpers
In reply to Yuyang HuangThe count of a netdev_hw_addr_list is changed in several places of dev_addr_lists.c and a few drivers read it directly. The next patch needs to account every change of the count of dev->mc.
Add __hw_addr_count_add(), __hw_addr_count_inc(), __hw_addr_count_dec() and __hw_addr_count_reset(), use them for every change of the count and rename the field to _count so that a direct write stands out. Readers keep using netdev_hw_addr_list_count() and the netdev_uc_count() and netdev_mc_count() helpers, the few that read the field directly are converted. No functional change.
--- .../net/ethernet/cavium/octeon/octeon_mgmt.c | 4 +- .../net/wireless/microchip/wilc1000/netdev.c | 8 ++-- include/linux/netdevice.h | 5 ++- net/core/dev_addr_lists.c | 44 ++++++++++++++----- net/core/dev_addr_lists_test.c | 18 ++++---- net/mac80211/driver-ops.h | 2 +- 6 files changed, 51 insertions(+), 30 deletions(-)
drivers/net/ethernet/cavium/octeon/octeon_mgmt.c +2 -2
@@ -573,14 +573,14 @@ static void octeon_mgmt_set_rx_filtering(struct net_device *netdev)memset (&cam_state,0 ,sizeof (cam_state)); -if ((netdev->flags &IFF_PROMISC ) || netdev->uc.count >7 ) { +if ((netdev->flags &IFF_PROMISC ) ||netdev_uc_count (netdev) >7 ) { cam_mode =0 ; available_cam_entries =8 ; }else {/* One CAM entry for the primary address, leaves seven * for the secondary addresses. */ - available_cam_entries =7 - netdev->uc.count; + available_cam_entries =7 -netdev_uc_count (netdev); }if (netdev->flags &IFF_MULTICAST ) {
drivers/net/wireless/microchip/wilc1000/netdev.c +4 -4
@@ -704,17 +704,17 @@ static void wilc_set_multicast_list(struct net_device *dev)return ;if (dev->flags &IFF_ALLMULTI || - dev->mc.count >WILC_MULTICAST_TABLE_SIZE ) { +netdev_mc_count (dev) >WILC_MULTICAST_TABLE_SIZE ) {wilc_setup_multicast_filter (vif,0 ,0 ,NULL );return ; } -if (dev->mc.count ==0 ) { +if (netdev_mc_empty (dev)) {wilc_setup_multicast_filter (vif,1 ,0 ,NULL );return ; } - mc_list =kmalloc_array (dev->mc.count,ETH_ALEN ,GFP_ATOMIC ); + mc_list =kmalloc_array (netdev_mc_count (dev),ETH_ALEN ,GFP_ATOMIC );if (!mc_list)return ;
@@ -727,7 +727,7 @@ static void wilc_set_multicast_list(struct net_device *dev) cur_mc +=ETH_ALEN ; } -if (wilc_setup_multicast_filter (vif,1 , dev->mc.count, mc_list)) +if (wilc_setup_multicast_filter (vif,1 ,netdev_mc_count (dev), mc_list))kfree (mc_list); }
include/linux/netdevice.h +3 -2
@@ -252,13 +252,14 @@ struct netdev_hw_addr {struct netdev_hw_addr_list {struct list_head list; -int count; +/* Only changed through the __hw_addr_count_* helpers */ +int _count;/* Auxiliary tree for faster lookup on addition and deletion */ struct rb_root tree; }; -#define netdev_hw_addr_list_count (l) ((l)->count) +#define netdev_hw_addr_list_count (l) ((l)->_count)#define netdev_hw_addr_list_empty (l) (netdev_hw_addr_list_count(l) == 0)#define netdev_hw_addr_list_for_each (ha, l) \ list_for_each_entry(ha, &(l)->list, list)
net/core/dev_addr_lists.c +32 -12
113 lines not on this page · raw message
net/core/dev_addr_lists_test.c +9 -9
@@ -291,7 +291,7 @@ static void dev_addr_test_snapshot_sync(struct kunit *test)netif_addr_unlock_bh (netdev);/* Real entry should now reflect the sync: sync_cnt=1, refcount=2 */ -KUNIT_EXPECT_EQ (test,1 , netdev->uc.count); +KUNIT_EXPECT_EQ (test,1 ,netdev_uc_count (netdev)); ha = list_first_entry(&netdev->uc.list, struct netdev_hw_addr, list);KUNIT_EXPECT_MEMEQ (test, ha->addr, addr,ETH_ALEN );KUNIT_EXPECT_EQ (test,1 , ha->sync_cnt);
@@ -303,7 +303,7 @@ static void dev_addr_test_snapshot_sync(struct kunit *test) dev_addr_test_unsync);KUNIT_EXPECT_EQ (test,0 , datp->addr_synced);KUNIT_EXPECT_EQ (test,0 , datp->addr_unsynced); -KUNIT_EXPECT_EQ (test,1 , netdev->uc.count); +KUNIT_EXPECT_EQ (test,1 ,netdev_uc_count (netdev));__hw_addr_flush (&cache);rtnl_unlock ();
@@ -351,7 +351,7 @@ static void dev_addr_test_snapshot_remove_during_sync(struct kunit *test)/* Concurrent removal: user deletes ADDR_A while driver was working */ memset (addr,ADDR_A ,sizeof (addr));KUNIT_EXPECT_EQ (test,0 ,dev_uc_del (netdev, addr)); -KUNIT_EXPECT_EQ (test,0 , netdev->uc.count); +KUNIT_EXPECT_EQ (test,0 ,netdev_uc_count (netdev));/* Reconcile: ADDR_A gone from real list but driver synced it, * so it gets re-inserted as stale (sync_cnt=1, refcount=1).
@@ -361,7 +361,7 @@ static void dev_addr_test_snapshot_remove_during_sync(struct kunit *test) &cache);netif_addr_unlock_bh (netdev); -KUNIT_EXPECT_EQ (test,1 , netdev->uc.count); +KUNIT_EXPECT_EQ (test,1 ,netdev_uc_count (netdev)); ha = list_first_entry(&netdev->uc.list, struct netdev_hw_addr, list);KUNIT_EXPECT_MEMEQ (test, ha->addr, addr,ETH_ALEN );KUNIT_EXPECT_EQ (test,1 , ha->sync_cnt);
@@ -373,7 +373,7 @@ static void dev_addr_test_snapshot_remove_during_sync(struct kunit *test) dev_addr_test_unsync);KUNIT_EXPECT_EQ (test,0 , datp->addr_synced);KUNIT_EXPECT_EQ (test,1 <<ADDR_A , datp->addr_unsynced); -KUNIT_EXPECT_EQ (test,0 , netdev->uc.count); +KUNIT_EXPECT_EQ (test,0 ,netdev_uc_count (netdev));__hw_addr_flush (&cache);rtnl_unlock ();
@@ -433,7 +433,7 @@ static void dev_addr_test_snapshot_readd_during_unsync(struct kunit *test)* stale entry and bumps refcount from 1 -> 2. sync_cnt stays 1. */ KUNIT_EXPECT_EQ (test,0 ,dev_uc_add (netdev, addr)); -KUNIT_EXPECT_EQ (test,1 , netdev->uc.count); +KUNIT_EXPECT_EQ (test,1 ,netdev_uc_count (netdev));/* Reconcile: ref sync_cnt=1 matches real sync_cnt=1, delta=-1 * applied. Result: sync_cnt=0, refcount=1 (fresh).
@@ -444,7 +444,7 @@ static void dev_addr_test_snapshot_readd_during_unsync(struct kunit *test)netif_addr_unlock_bh (netdev);/* Entry survives as fresh: needs re-sync to HW */ -KUNIT_EXPECT_EQ (test,1 , netdev->uc.count); +KUNIT_EXPECT_EQ (test,1 ,netdev_uc_count (netdev)); ha = list_first_entry(&netdev->uc.list, struct netdev_hw_addr, list);KUNIT_EXPECT_MEMEQ (test, ha->addr, addr,ETH_ALEN );KUNIT_EXPECT_EQ (test,0 , ha->sync_cnt);
@@ -528,7 +528,7 @@ static void dev_addr_test_snapshot_add_and_remove(struct kunit *test)* ADDR_B: refcount went from 2->1 via dev_uc_del (still present, stale) * ADDR_C: sync propagated (sync_cnt=1, refcount=2) */ -KUNIT_EXPECT_EQ (test,3 , netdev->uc.count); +KUNIT_EXPECT_EQ (test,3 ,netdev_uc_count (netdev));netdev_hw_addr_list_for_each (ha, &netdev->uc) {u8 id = ha->addr[0 ];
@@ -553,7 +553,7 @@ static void dev_addr_test_snapshot_add_and_remove(struct kunit *test) dev_addr_test_unsync);KUNIT_EXPECT_EQ (test,0 , datp->addr_synced);KUNIT_EXPECT_EQ (test,1 <<ADDR_B , datp->addr_unsynced); -KUNIT_EXPECT_EQ (test,2 , netdev->uc.count); +KUNIT_EXPECT_EQ (test,2 ,netdev_uc_count (netdev));__hw_addr_flush (&cache);rtnl_unlock ();
net/mac80211/driver-ops.h +1 -1
@@ -187,7 +187,7 @@ static inline u64 drv_prepare_multicast(struct ieee80211_local *local, {u64 ret =0 ; -trace_drv_prepare_multicast (local, mc_list->count); +trace_drv_prepare_multicast (local,netdev_hw_addr_list_count (mc_list));if (local->ops->prepare_multicast) ret = local->ops->prepare_multicast (&local->hw, mc_list);
Signature · 1 line
2.43.0
Re: [PATCH net-next v9 2/6] net: change netdev_hw_addr_list count through helpers
Le 30/09/2026 à 13:28, Yuyang Huang a écrit :
Quoted 4 lines
The count of a
netdev_hw_addr_listis changed in several places ofdev_addr_lists.cand a few drivers read it directly. The next patch needs to account every change of the count ofdev->mc.
Quoted 8 lines
Add
__hw_addr_count_add(),__hw_addr_count_inc(),__hw_addr_count_dec()and__hw_addr_count_reset(), use them for every change of the count and rename the field to_countso that a direct write stands out. Readers keep usingnetdev_hw_addr_list_count()and thenetdev_uc_count()andnetdev_mc_count()helpers, the few that read the field directly are converted. No functional change.Signed-off-by Yuyang Huang <[email protected]>
If you respin a version, you can use netdev_hw_addr_list_count() in __hw_addr_list_snapshot() also.
Thanks,
Nicolas
Re: [PATCH net-next v9 2/6] net: change netdev_hw_addr_list count through helpers
Quoted 2 lines
If you respin a version, you can use
netdev_hw_addr_list_count()in__hw_addr_list_snapshot()also.
Thanks, will do if there is a v10.
Quoted 21 lines · Nicolas Dichtel
Quoted 4 lines · Yuyang Huang
The count of a
netdev_hw_addr_listis changed in several places ofdev_addr_lists.cand a few drivers read it directly. The next patch needs to account every change of the count ofdev->mc.Quoted 8 lines
Add
__hw_addr_count_add(),__hw_addr_count_inc(),__hw_addr_count_dec()and__hw_addr_count_reset(), use them for every change of the count and rename the field to_countso that a direct write stands out. Readers keep usingnetdev_hw_addr_list_count()and thenetdev_uc_count()andnetdev_mc_count()helpers, the few that read the field directly are converted. No functional change.Signed-off-by Yuyang Huang <[email protected]>Reviewed-by Nicolas Dichtel <[email protected]>If you respin a version, you can use
netdev_hw_addr_list_count()in__hw_addr_list_snapshot()also.Thanks,
Nicolas
Re: [PATCH net-next v9 2/6] net: change netdev_hw_addr_list count through helpers
Le 30/09/2026 à 15:43, Yuyang Huang a écrit :
Quoted 4 lines
Quoted 2 lines
If you respin a version, you can use
netdev_hw_addr_list_count()in__hw_addr_list_snapshot()also.Thanks, will do if there is a v10.
Thanks. FYI, please don't top post:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst#n336
Re: [PATCH net-next v9 2/6] net: change netdev_hw_addr_list count through helpers
Quoted 2 lines
Thanks. FYI, please don't top post:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst#n336
Thanks for the reminder, will be more careful next time.
[email protected]
AI reviewRe: [PATCH net-next v9 2/6] net: change netdev_hw_addr_list count through helpers
In reply to Yuyang HuangThank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] In the commit "net: change netdev_hw_addr_list count through helpers", a new comment on struct netdev_hw_addr_list::_count in…
--
net: change netdev_hw_addr_list count through helpers
This patch adds __hw_addr_count_add(), __hw_addr_count_inc(), __hw_addr_count_dec() and __hw_addr_count_reset() to net/core/dev_addr_lists.c and uses them for changes to the list count. It also renames netdev_hw_addr_list.count to _count so that direct writes stand out. Drivers, mac80211 and the kunit tests that read the field directly now use the count helpers. This prepares for a later patch that accounts every change to dev->mc.
Quoted 11 lines
include/linux/netdevice.h +2
-1@@ -252,13 +252,14 @@ struct netdev_hw_addr {struct netdev_hw_addr_list {struct list_head list; -int count; +/* Only changed through the __hw_addr_count_* helpers */ +int _count;
[ ... ]
Quoted 4 lines
net/core/dev_addr_lists.c +0
-0
[ ... ]
Quoted 1 line
net/core/dev_addr_lists.c +0
-0@@ -492,14 +512,14 @@ void __hw_addr_flush(struct netdev_hw_addr_list *list)
[ ... ]
net/core/dev_addr_lists.c void __hw_addr_flush(struct netdev_hw_addr_list *list) · line 522
Quoted 5 lines
void
__hw_addr_init(struct netdev_hw_addr_list *list){net/core/dev_addr_lists.c +1
-1INIT_LIST_HEAD (&list->list); - list->count =0 ; + list->_count =0 ;
[Severity: Low]
This isn't a bug, but the new comment in struct netdev_hw_addr_list says _count is "Only changed through the __hw_addr_count_* helpers". However, __hw_addr_init() still writes it directly, and the write is still there at the end of the series.
Could the comment name initialization as an exception? For example:
/* Only changed through the __hw_addr_count_* helpers after
* __hw_addr_init()
*/This has no functional effect on the later dev->mc generation counter patch. dev_mc_init() calls __hw_addr_init() only from alloc_netdev_mqs(), on a freshly zeroed device, and dev->mc.owner is set only after that call. Also, by the end of the series __hw_addr_init() sets list->owner = NULL. So __hw_addr_changed() would do nothing here even if a helper were used.
A related point: the commit message says readers keep using netdev_hw_addr_list_count(), but two places in this file still read the raw field:
__hw_addr_splice():
__hw_addr_count_add(dst, src->_count);
__hw_addr_list_snapshot():
if (cache->_count) {Should these use netdev_hw_addr_list_count() too, so they follow the reader convention in the commit message?
Quoted 3 lines
list->tree=RB_ROOT;
}
EXPORT_SYMBOL(__hw_addr_init);
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260930112842.21323-1-sigefriedhyy%40gmail.com
Re: [PATCH net-next v9 2/6] net: change netdev_hw_addr_list count through helpers
Quoted 2 lines
- [Low] In the commit "net: change
netdev_hw_addr_listcount through helpers", a new comment on structnetdev_hw_addr_list::_countin…
Agreed, but they are nit, will fold them into v10 if another version is needed.
PATCH v9 3/6 net: add a generation counter for dev->mc changes
In reply to Yuyang HuangA multi-part RTM_GETMULTICAST dump of dev->mc resumes by position, so entries added or removed between two dump rounds can be skipped or repeated. The IPv4 and IPv6 dumps report that with NLM_F_DUMP_INTR by stamping cb->seq from a per netns generation counter combined with dev_base_seq, see inet_base_seq().
Add the equivalent for the device multicast lists: a per netns counter bumped whenever an entry is added to or removed from any dev->mc. The list helpers do not know which device a list belongs to, so give netdev_hw_addr_list an owner, set for the lists of a device and NULL for snapshots and other standalone lists, and bump the counter of dev_net(owner) from the count helpers when the list is dev->mc. That covers the dev_mc_* helpers, both lists of a sync, the hardware sync helpers drivers call from their rx mode callbacks or their own workers and the reconciliation after an asynchronous rx mode update. It is atomic since the writers only hold the address lock of their own device.
Used by the following patch for the AF_PACKET multicast dump.
--- include/linux/netdevice.h | 5 +++++ include/net/net_namespace.h | 1 + net/core/dev_addr_lists.c | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+)
include/linux/netdevice.h +5 -0
@@ -257,6 +257,11 @@ struct netdev_hw_addr_list {/* Auxiliary tree for faster lookup on addition and deletion */ struct rb_root tree; + +/* The device a list belongs to, NULL for snapshots and other +* standalone lists +*/ +struct net_device *owner; };#define netdev_hw_addr_list_count (l) ((l)->_count)
include/net/net_namespace.h +1 -0
@@ -71,6 +71,7 @@ struct net {spinlock_t rules_mod_lock;unsigned int dev_base_seq;/* protected by rtnl_mutex */ +atomic_t dev_mc_genid;/* bumped on dev->mc changes */ u32 ifindex;spinlock_t nsid_lock;
net/core/dev_addr_lists.c +20 -0
@@ -16,9 +16,21 @@#include "dev.h" +/* Only dev->mc is tracked, RTM_GETMULTICAST dumps use the netns generation +* counter to detect changes between dump rounds. +*/ +static void __hw_addr_changed (struct netdev_hw_addr_list *list) +{ +struct net_device *dev = list->owner; + +if (dev && list == &dev->mc) +atomic_inc (&dev_net (dev)->dev_mc_genid); +} +static void __hw_addr_count_add (struct netdev_hw_addr_list *list,int value) { list->_count += value; +__hw_addr_changed (list); }static void __hw_addr_count_inc (struct netdev_hw_addr_list *list)
@@ -33,7 +45,10 @@ static void __hw_addr_count_dec(struct netdev_hw_addr_list *list)static void __hw_addr_count_reset (struct netdev_hw_addr_list *list) { +if (!list->_count) +return ; list->_count =0 ; +__hw_addr_changed (list); }/*
@@ -521,6 +536,7 @@ void __hw_addr_init(struct netdev_hw_addr_list *list)INIT_LIST_HEAD (&list->list); list->_count =0 ; list->tree =RB_ROOT ; + list->owner =NULL ; }EXPORT_SYMBOL (__hw_addr_init);
@@ -705,6 +721,7 @@ int dev_addr_init(struct net_device *dev)/* rtnl_mutex must be held here */ __hw_addr_init (&dev->dev_addrs); + dev->dev_addrs.owner = dev;memset (addr,0 ,sizeof (addr)); err =__hw_addr_add (&dev->dev_addrs, addr,sizeof (addr),NETDEV_HW_ADDR_T_LAN );
@@ -982,6 +999,7 @@ EXPORT_SYMBOL(dev_uc_flush);void dev_uc_init (struct net_device *dev) {__hw_addr_init (&dev->uc); + dev->uc.owner = dev; }EXPORT_SYMBOL (dev_uc_init);
@@ -1197,6 +1215,7 @@ EXPORT_SYMBOL(dev_mc_flush);void dev_mc_init (struct net_device *dev) {__hw_addr_init (&dev->mc); + dev->mc.owner = dev; }EXPORT_SYMBOL (dev_mc_init);
@@ -1368,6 +1387,7 @@ static void netif_rx_mode_retry(struct timer_list *t)void netif_rx_mode_init (struct net_device *dev) {__hw_addr_init (&dev->rx_mode_addr_cache); + dev->rx_mode_addr_cache.owner = dev;timer_setup (&dev->rx_mode_retry_timer, netif_rx_mode_retry,0 ); }
Signature · 1 line
2.43.0
Re: [PATCH net-next v9 3/6] net: add a generation counter for dev->mc changes
Le 30/09/2026 à 13:28, Yuyang Huang a écrit :
Quoted 18 lines
A multi-part
RTM_GETMULTICASTdump ofdev->mcresumes by position, so entries added or removed between two dump rounds can be skipped or repeated. The IPv4 and IPv6 dumps report that withNLM_F_DUMP_INTRby stampingcb->seqfrom a per netns generation counter combined withdev_base_seq, seeinet_base_seq().Add the equivalent for the device multicast lists: a per netns counter bumped whenever an entry is added to or removed from any
dev->mc. The list helpers do not know which device a list belongs to, so givenetdev_hw_addr_listan owner, set for the lists of a device and NULL for snapshots and other standalone lists, and bump the counter ofdev_net(owner)from the count helpers when the list isdev->mc. That covers the dev_mc_* helpers, both lists of a sync, the hardware sync helpers drivers call from their rx mode callbacks or their own workers and the reconciliation after an asynchronous rx mode update. It is atomic since the writers only hold the address lock of their own device.
Quoted 3 lines
Used by the following patch for the
AF_PACKETmulticast dump.Signed-off-by Yuyang Huang <[email protected]>
Jakub Kicinski
maintainerRe: [PATCH net-next v9 3/6] net: add a generation counter for dev->mc changes
In reply to Yuyang Huangnet/core/dev_addr_lists.c static void netif_rx_mode_retry(struct timer_list *t) · line 1390
Quoted 4 lines · On Wed, 30 Sep 2026 20:28:39 +0900 Yuyang Huang wrote:
void
netif_rx_mode_init(struct net_device *dev)
{net/core/dev_addr_lists.c +1
-0__hw_addr_init (&dev->rx_mode_addr_cache); + dev->rx_mode_addr_cache.owner = dev;
There's no need to set this?
Quoted 1 line
timer_setup(&dev->rx_mode_retry_timer, netif_rx_mode_retry, 0);
Re: [PATCH net-next v9 3/6] net: add a generation counter for dev->mc changes
Quoted 3 lines
Quoted 1 line
+
dev->rx_mode_addr_cache.owner= dev;There's no need to set this?
No, only dev->mc is looked at. It was set for all the lists of a device after Nicolas's comment on v7:
``` There are several lists owned by a device (dev->dev_addrs, dev->uc, dev->mc, dev->rx_mode_addr_cache), the name 'owner' does not reflect that it is set only when the list is dev->mc. I wonder if the name should be changed or if __hw_addr_init() should be updated to always set owner when the list is owned by a device. ```
v10 takes the other option: the field becomes mc_dev, set for dev->mc only.
PATCH v9 4/6 net: 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 next to the dev->mc helpers in dev_addr_lists.c 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.
Requests are always validated, there are no legacy users: prefixlen, flags and scope must be zero, ifa_index selects one device and IFA_TARGET_NETNSID is the only attribute accepted. The dump runs under RCU and netif_addr_lock_bh() without RTNL. cb->seq is sampled from the dev->mc generation counter and dev_base_seq under the address lock of each device and again when a round ends, so a change since the previous device or dump round sets NLM_F_DUMP_INTR, also when the last round dumps nothing because the device it stopped at is gone.
--- include/linux/netdevice.h | 1 + include/uapi/linux/if_addr.h | 1 + net/core/dev_addr_lists.c | 195 +++++++++++++++++++++++++++++++++++ net/core/rtnetlink.c | 2 + 4 files changed, 199 insertions(+)
include/linux/netdevice.h +1 -0
@@ -5168,6 +5168,7 @@ int dev_mc_sync_multiple(struct net_device *to, struct net_device *from);void dev_mc_unsync (struct net_device *to,struct net_device *from);void dev_mc_flush (struct net_device *dev);void dev_mc_init (struct net_device *dev); +int dev_mc_dump (struct sk_buff *skb,struct netlink_callback *cb);/** * __dev_mc_sync - Synchronize device's multicast list
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/dev_addr_lists.c +195 -0
209 lines not on this page · raw message
net/core/rtnetlink.c +2 -0
@@ -7278,6 +7278,8 @@ static const struct rtnl_msg_handler rtnetlink_rtnl_msg_handlers[] __initconst = {.msgtype = RTM_SETSTATS, .doit = rtnl_stats_set}, {.msgtype = RTM_NEWLINKPROP, .doit = rtnl_newlinkprop}, {.msgtype = RTM_DELLINKPROP, .doit = rtnl_dellinkprop}, + {.protocol = PF_PACKET, .msgtype = RTM_GETMULTICAST, + .dumpit = dev_mc_dump, .flags = RTNL_FLAG_DUMP_UNLOCKED}, {.protocol = PF_BRIDGE, .msgtype = RTM_GETLINK, .dumpit = rtnl_bridge_getlink}, {.protocol = PF_BRIDGE, .msgtype = RTM_DELLINK,
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH net-next v9 4/6] net: add AF_PACKET multicast dumps
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 3
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] Concurrent device removal can end an unfiltered AF_PACKET RTM_GETMULTICAST dump early without setting NLM_F_DUMP_INTR.
- [Low] The commit message gives a false reason for not extending the FDB dump.
- [Low] At this commit, Documentation/netlink/specs/rt-addr.yaml does not describe the new AF_PACKET multicast dump: - The ifa-flags enum stops…
- [Low] dev_mc_genid is only bumped through the __hw_addr_count_* helpers, i.e. when a dev->mc entry is added or removed.
--
net: add AF_PACKET multicast dumps
This adds an unlocked RTM_GETMULTICAST dump handler for ifa_family AF_PACKET. For each device it reports every dev->mc entry in the ifaddrmsg format, with IFA_MULTICAST, IFA_MC_USERS and a new IFA_F_GLOBAL flag. Dump consistency comes from sampling dev_mc_genid plus dev_base_seq into cb->seq, so NLM_F_DUMP_INTR gets set when either changes.
Quoted 4 lines
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.
[Severity: Low]
Is this accurate for bridge and macvlan?
macvlan uses the default helper directly:
drivers/net/macvlan.c:
.ndo_fdb_dump = ndo_dflt_fdb_dump,
br_fdb_dump() also falls back to it for unfiltered dumps:
net/bridge/br_fdb.c:br_fdb_dump() {
...
if (!filter_dev) {
err = ndo_dflt_fdb_dump(skb, cb, dev, NULL, idx);
...
}rtnl_fdb_dump() calls a device's own ndo_fdb_dump with filter_dev == NULL. ndo_dflt_fdb_dump() then walks both dev->uc and dev->mc for ARPHRD_ETHER devices.
So "bridge fdb show" seems to already list dev->mc for bridge masters and macvlan devices. Only vxlan fits the description.
The other reasons (no users count, no global_use bit, changing the "bridge fdb show" output) may still hold. Could this paragraph be corrected?
Quoted 4 lines
net/core/dev_addr_lists.c +0
-0
[ ... ]
Quoted 9 lines
net/core/dev_addr_lists.c +5
-0@@ -1219,6 +1223,197 @@ void dev_mc_init(struct net_device *dev) }EXPORT_SYMBOL (dev_mc_init); +static int dev_mc_fill_addr (struct sk_buff *skb,const struct net_device *dev, +const struct netdev_hw_addr *ha,u32 portid, +u32 seq,unsigned int flags,int netnsid) +{ +u32 ifa_flags = ha->global_use ?IFA_F_GLOBAL :0 ;
[ ... ]
net/core/dev_addr_lists.c void dev_mc_init(struct net_device *dev) · line 1251
Quoted 5 lines
net/core/dev_addr_lists.c +5
-0+if ((netnsid >=0 && +nla_put_s32 (skb,IFA_TARGET_NETNSID , netnsid)) || +nla_put (skb,IFA_MULTICAST , dev->addr_len, ha->addr) || +nla_put_u32 (skb,IFA_MC_USERS , ha->refcount) || +nla_put_u32 (skb,IFA_FLAGS , ifa_flags)) {
[Severity: Low]
At this commit, Documentation/netlink/specs/rt-addr.yaml doesn't yet describe this dump:
- the ifa-flags enum ends at stable-privacy, so bit 12 (IFA_F_GLOBAL), emitted here in IFA_FLAGS, has no name
- the getmulticast op doc still says "Get / dump IPv4/IPv6 multicast addresses."
- the reply attributes do not include flags or target-netnsid, and the dump request declares no attributes even though target-netnsid is accepted
The next patch in the series, "netlink: specs: rt-addr: document AF_PACKET multicast dumps", fixes all of this. It adds global after stable-privacy, adds flags and target-netnsid to the reply and target-netnsid to the request, and rewrites the op doc. Nothing is left over at the end of the series.
Would it make sense to fold the spec update into this patch, so the spec and the kernel match at every commit?
Quoted 6 lines
net/core/dev_addr_lists.c +6
-0+ nla_put_u32(skb, IFA_FLAGS, ifa_flags)) { +nlmsg_cancel (skb, nlh); +return -EMSGSIZE ; + } + +nlmsg_end (skb, nlh);
net/core/dev_addr_lists.c void dev_mc_init(struct net_device *dev) · line 1266
Quoted 10 lines
net/core/dev_addr_lists.c +10
-0+return 0 ; +} + +/* Combine dev_mc_genid and dev_base_seq to detect changes, like +* inet_base_seq(). +*/ +static u32 dev_mc_base_seq (const struct net *net) +{ +u32 res =atomic_read (&net->dev_mc_genid) + +READ_ONCE (net->dev_base_seq);
[Severity: Low]
This isn't a bug, but dev_mc_genid is only bumped from the __hw_addr_count_* helpers, i.e. when a dev->mc entry is added or removed. In-place updates to the two fields exported here don't bump it:
net/core/dev_addr_lists.c:__hw_addr_add_ex() {
...
if (global) {
/* check if addr is already used as global */
if (ha->global_use)
return 0;
else
ha->global_use = true;
}
...
ha->refcount++;
return 0;
...
}net/core/dev_addr_lists.c:__hw_addr_del_entry() {
...
if (global)
ha->global_use = false;
...
if (--ha->refcount)
return 0;
...
}The dump resumes by list position, and these updates never add, remove or reorder entries. So nothing is skipped or repeated, which matches the IPv4 dev_addr_genid convention.
However, the struct net comment ("bumped on dev->mc changes") and the commit message ("so a change since the previous device or dump round sets NLM_F_DUMP_INTR") describe more than that. Could they say membership changes instead?
[ ... ]
Quoted 7 lines
net/core/dev_addr_lists.c +7
-0+ s_ifindex = ctx->ifindex; +for_each_netdev_dump (filter.tgt_net, dev, ctx->ifindex) { +/* The device the dump stopped at is gone, do not skip +* entries of the next one. +*/ +if (dev->ifindex != s_ifindex) + ctx->addr_idx =0 ;
net/core/dev_addr_lists.c void dev_mc_init(struct net_device *dev) · line 1410
Quoted 10 lines
net/core/dev_addr_lists.c +10
-0+ err =dev_mc_dump_dev (dev, skb, cb, &ctx->addr_idx, flags, + filter.netnsid); +if (err <0 ) +break ; + } +out: +/* A round that dumps no device, e.g. the one it stopped at is gone, +* still needs the NLMSG_DONE check to see the change. +*/ + cb->seq =dev_mc_base_seq (filter.tgt_net);
[Severity: Medium]
Can a concurrent unregister still end this dump early without NLM_F_DUMP_INTR?
unlist_netdevice() removes the device from the xarray before it bumps dev_base_seq:
net/core/dev.c:unlist_netdevice() {
...
xa_erase(&net->dev_by_index, dev->ifindex);
netdev_for_each_altname(dev, name_node)
netdev_name_node_del(name_node);
/* Unlink dev from the device chain */
list_del_rcu(&dev->dev_list);
netdev_name_node_del(dev->name_node);
hlist_del_rcu(&dev->index_hlist);
dev_base_seq_inc(dev_net(dev));
}The handler is registered with RTNL_FLAG_DUMP_UNLOCKED. So the next dump round can run while the RTNL holder is preempted between xa_erase() and dev_base_seq_inc().
Take a round that returns -EMSGSIZE partway through device D. That leaves ctx->ifindex == D->ifindex, ctx->addr_idx == k, and cb->prev_seq == cb->seq == G.
D, which is down, is then unregistered or moved to another netns. dev->mc isn't flushed until later in unregister_netdevice_many_notify(), so dev_mc_genid doesn't change either.
In the next round, for_each_netdev_dump() no longer finds D. The dev_mc_dump_dev() calls on later devices and the sample at out: both read G again. netlink_dump_done()->nl_dump_check_consistent() then sees seq == prev_seq, and NLMSG_DONE is sent without NLM_F_DUMP_INTR.
Userspace would get entries 0..k-1 of D and no sign that the rest are missing. The unlocked IPv4 and IPv6 dumps rely on the same dev_base_seq ordering, but this path is new in this patch.
The commit message says this case is covered ("also when the last round dumps nothing because the device it stopped at is gone"). Does that fully hold with this ordering?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260930112842.21323-1-sigefriedhyy%40gmail.com
Re: [PATCH net-next v9 4/6] net: add AF_PACKET multicast dumps
Quoted 2 lines
- [Medium] Concurrent device removal can end an unfiltered
AF_PACKETRTM_GETMULTICASTdump early without settingNLM_F_DUMP_INTR.
This window is in unlist_netdevice(), the device leaves the index before dev_base_seq is bumped. Moreover, it seems it affects the IPv4 and IPv6 address
dumps the same way. If it should be fixed, it seems it needs to be fixed seapartely, not a new issue introduced in this patchset.
Quoted 4 lines
- [Low] The commit message gives a false reason for not extending the FDB dump.
- [Low]dev_mc_genidis only bumped through the __hw_addr_count_* helpers, i.e. when adev->mcentry is added or removed.
Agreed on both, but they are nits, will adjust if there is a v10.
Quoted 2 lines
- [Low] At this commit,
Documentation/netlink/specs/rt-addr.yamldoes not describe the newAF_PACKETmulticast dump: - The ifa-flags enum stops…
The spec update is the next patch.
Jakub Kicinski
maintainerRe: [PATCH net-next v9 4/6] net: add AF_PACKET multicast dumps
In reply to Yuyang Huangnet/core/dev_addr_lists.c void dev_mc_init(struct net_device *dev) · line 1294
Quoted 10 lines · On Wed, 30 Sep 2026 20:28:40 +0900 Yuyang Huang wrote:
net/core/dev_addr_lists.c +10
-0+netdev_for_each_mc_addr (ha, dev) { +if (addr_idx < *s_addr_idx) { + addr_idx++; +continue ; + } + err =dev_mc_fill_addr (skb, dev, ha,NETLINK_CB (cb->skb).portid, + cb->nlh->nlmsg_seq, flags, netnsid); +if (err <0 ) +break ; +nl_dump_check_consistent (cb,nlmsg_hdr (skb));
Why are you checking this on every iteration?
Review
Quoted 2 lines
(quoted diff) +2
-0+ addr_idx++; + }
The changes still lack polish IMO.
Re: [PATCH net-next v9 4/6] net: add AF_PACKET multicast dumps
Quoted 7 lines
Quoted 5 lines
+ err = dev_mc_fill_addr(skb, dev, ha, NETLINK_CB(cb->skb).portid,
+cb->nlh->nlmsg_seq, flags, netnsid);
+ if (err < 0)
+ break;
+nl_dump_check_consistent(cb, nlmsg_hdr(skb));Why are you checking this on every iteration?
Right, we don't need to check it on every iteration, I will fix it in v10.
Quoted 1 line
The changes still lack polish IMO.
I will go over the series again for v10. If you have something specific in mind, a pointer would help.
PATCH v9 5/6 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 | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
Documentation/netlink/specs/rt-addr.yaml +16 -2
@@ -77,6 +77,8 @@ definitions: name: mcautojoin - name: stable-privacy + - + name: global attribute-sets: -
@@ -168,7 +170,16 @@ 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. For AF_PACKET + a non-zero ifa-index restricts the dump to that device and + ifa-prefixlen, ifa-flags and ifa-scope must be zero, AF_INET and + AF_INET6 apply this with NETLINK_GET_STRICT_CHK only. attribute-set: addr-attrs fixed-header: ifaddrmsg do:
@@ -181,10 +192,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
[email protected]
AI reviewRe: [PATCH net-next v9 5/6] netlink: specs: rt-addr: document AF_PACKET multicast dumps
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The patch adds target-netnsid to the getmulticast dump request with no condition, and writes doc text on which request semantics…
Pre-existing issues:
- [Low] In Documentation/netlink/specs/rt-addr.yaml, the getmulticast operation still has a do section, and its doc still starts with "Get…
--
netlink: specs: rt-addr: document AF_PACKET multicast dumps
This updates the rt-addr spec to cover AF_PACKET RTM_GETMULTICAST dumps. It adds a global ifa-flags value and expands the getmulticast doc. It also adds flags and target-netnsid to the multicast reply attributes and lists target-netnsid as a dump request attribute.
Quoted 4 lines
Documentation/netlink/specs/rt-addr.yaml +0
-0
[ ... ]
Quoted 19 lines
Documentation/netlink/specs/rt-addr.yaml +10
-1@@ -168,7 +170,16 @@ 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. For AF_PACKET + a non-zero ifa-index restricts the dump to that device and + ifa-prefixlen, ifa-flags and ifa-scope must be zero, AF_INET and + AF_INET6 apply this with NETLINK_GET_STRICT_CHK only. attribute-set: addr-attrs fixed-header: ifaddrmsg do:
Documentation/netlink/specs/rt-addr.yaml operations: · line 196
Quoted 5 lines
Documentation/netlink/specs/rt-addr.yaml +2
-0@@ -181,10 +192,13 @@ operations: - multicast - mc-users - cacheinfo + - flags + - target-netnsid
[Severity: Low]
This is a pre-existing issue, but does any family actually implement the do side of getmulticast?
The do block and the "Get / dump" wording were already in the spec before this patch. Every RTM_GETMULTICAST registration is dump-only:
net/core/rtnetlink.c:
{.protocol = PF_PACKET, .msgtype = RTM_GETMULTICAST,
.dumpit = dev_mc_dump, .flags = RTNL_FLAG_DUMP_UNLOCKED},
net/ipv4/devinet.c:
{.owner = THIS_MODULE, .protocol = PF_INET, .msgtype = RTM_GETMULTICAST,
.dumpit = inet_dump_ifmcaddr, .flags = RTNL_FLAG_DUMP_UNLOCKED},
net/ipv6/addrconf.c:
{.owner = THIS_MODULE, .protocol = PF_INET6, .msgtype = RTM_GETMULTICAST,
.dumpit = inet6_dump_ifmcaddr,
.flags = RTNL_FLAG_DUMP_UNLOCKED},
If NLM_F_DUMP is not set, rtnetlink_rcv_msg() finds no doit for the family or for PF_UNSPEC and returns -EOPNOTSUPP. A spec-driven do getmulticast (ynl --do, or the generated C do helper) will therefore always fail.
The rewritten doc still begins with "Get / dump". The &mcaddr-attrs anchor is defined under do.reply, so the patch also adds flags and target-netnsid to the reply of an operation that cannot succeed.
Since this doc is being rewritten anyway, could the do block be dropped, the attribute list moved under dump.reply, and "Get" removed from the doc?
Documentation/netlink/specs/rt-addr.yaml operations: · line 201
Quoted 6 lines
Documentation/netlink/specs/rt-addr.yaml +2
-1dump: request: value: 58 - attributes: [] + attributes: + - target-netnsid
[Severity: Low]
Do all three families honour target-netnsid here? The new doc says:
For AF_PACKET
a non-zero ifa-index restricts the dump to that device and ifa-prefixlen, ifa-flags and ifa-scope must be zero, AF_INET and AF_INET6 apply this with NETLINK_GET_STRICT_CHK only.
That caveat covers the ifa-index filter and the zero header checks. However, target-netnsid is listed as a request attribute with no condition.
For AF_INET, inet_dump_addr() parses IFA_TARGET_NETNSID only through inet_valid_dump_ifaddr_req(), and only when strict checking is on:
net/ipv4/devinet.c:inet_dump_addr() {
...
if (cb->strict_check) {
err = inet_valid_dump_ifaddr_req(nlh, &fillargs, &tgt_net,
skb->sk, cb);
...
}inet6_dump_addr() in net/ipv6/addrconf.c does the same with inet6_valid_dump_ifaddr_req(). On the AF_PACKET side, dev_mc_valid_dump_req() parses it unconditionally.
As a result, a non-strict AF_INET or AF_INET6 RTM_GETMULTICAST dump that carries IFA_TARGET_NETNSID ignores the attribute without any error and dumps the caller's own netns. AF_PACKET honours it.
The C YNL library in tools/net/ynl/lib/ynl.c sets only NETLINK_CAP_ACK and NETLINK_EXT_ACK and never NETLINK_GET_STRICT_CHK, so spec-driven C clients will hit this. The Python YNL library does set it.
Could the doc also say that AF_INET and AF_INET6 honour target-netnsid only with NETLINK_GET_STRICT_CHK?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260930112842.21323-1-sigefriedhyy%40gmail.com
Re: [PATCH net-next v9 5/6] netlink: specs: rt-addr: document AF_PACKET multicast dumps
Quoted 2 lines
- [Low] The patch adds
target-netnsidto the getmulticast dump request with no condition, and writes doc text on which request semantics…
Fair, will mention target-netnsid in that sentence if there is a v10.
Quoted 2 lines
- [Low] In
Documentation/netlink/specs/rt-addr.yaml, the getmulticast operation still has adosection, and its doc still starts with "Get…
Pre-existing issue.
PATCH v9 6/6 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.
--- tools/testing/selftests/net/rtnetlink.py | 73 +++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-)
tools/testing/selftests/net/rtnetlink.py +71 -2
@@ -5,13 +5,18 @@ 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 ksft_in, ksft_not_in, ksft_not_none from lib.py import CmdExitFailure, NetNS, NetNSEnter, 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(':', '')) +ETH_PEER_MULTICAST_STR = '01:00:5e:02:02:02' +ETH_PEER_MULTICAST = bytes.fromhex(ETH_PEER_MULTICAST_STR.replace(':', '')) def _users_for(rtnl: RtnlAddrFamily, family: int, grp: bytes, ifindex: int):
@@ -105,6 +110,69 @@ 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) + addresses = rtnl.getmulticast( + {"ifa-family": socket.AF_PACKET, "ifa-index": dev_idx}, + dump=True) + + # 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) + ip(f"maddr add {ETH_PEER_MULTICAST_STR} dev dummy3", 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, + "ifa-index": peer_idx}, 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") + # dummy1 in this netns can have the same ifindex as dummy3 + ksft_in(ETH_PEER_MULTICAST, + {addr['multicast'] for addr in addresses}, + "target-netnsid did not dump the peer device") + + def ipv4_devconf_notify() -> None: """ Configure an interface and set ipv4-devconf values through netlink
@@ -424,7 +492,8 @@ def ipv6_verify_inter_scope_addr_order() -> 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