rtnetlink: dump link-layer multicast addresses
Subsystems (7)
v11 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 v11:
- Sample cb->seq before each round and again after it, and skip the check in a round without a message, so a change after the walk or before an empty round sets NLM_F_DUMP_INTR
Changes in v10:
- Rename the list owner to mc_dev and set it for dev->mc only
- Sample cb->seq once after the walk and check it once per round, like rtnl_dump_ifinfo()
- Read the count through netdev_hw_addr_list_count() in the helpers file, note the init exception in the _count comment
- Fix the FDB remark in the dump message, bridge and macvlan use the default FDB dump
- Say in the spec doc that AF_INET and AF_INET6 honour target-netnsid with NETLINK_GET_STRICT_CHK only
- Drop the Reviewed-by tags of patches 3 and 4 after the rework
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 | 21 +- .../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 | 251 +++++++++++++++++- 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, 357 insertions(+), 35 deletions(-)
Signature · 1 line
2.43.0
PATCH v11 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 v11 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 fixes a real type mismatch in
Documentation/netlink/specs/rt-addr.yaml.
Pre-existing issues:
- [Low] This problem wasn't introduced by this patch, but the getaddr operation in Documentation/netlink/specs/rt-addr.yaml still doesn't…
- [Low] This problem wasn't introduced by this patch, but Documentation/netlink/specs/ovs_vport.yaml has the same kind of…
--
netlink: specs: rt-addr: fix the type of target-netnsid
This patch changes the type of target-netnsid in the rt-addr YNL spec from binary to s32. That matches the NLA_S32 policy the kernel uses for IFA_TARGET_NETNSID and the s32 type rt-link.yaml already uses.
Quoted 6 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]>Reviewed-by Nicolas Dichtel <[email protected]>Reviewed-by Aleksandr Loktionov <[email protected]>
[Severity: Low]
Should this have a Fixes: tag? The type: binary line comes from the commit that first added the spec. The later rename commit only changed the attribute name:
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]
This is a pre-existing issue and was not introduced by this patch. The getaddr operation in this spec still doesn't list target-netnsid anywhere:
name: getaddr
doc: Dump address information.
attribute-set: addr-attrs
dump:
request:
value: 22
attributes: []
reply:
value: 20
attributes: *ifaddr-allHere *ifaddr-all contains only address, label, local and cacheinfo.
The kernel accepts the attribute in RTM_GETADDR dump requests. This is from net/ipv4/devinet.c:inet_valid_dump_ifaddr_req():
if (i == IFA_TARGET_NETNSID) {
struct net *net;
fillargs->netnsid = nla_get_s32(tb[i]);The IPv6 dump request handling in net/ipv6/addrconf.c does the same. The kernel also puts the attribute in replies, from inet_fill_ifaddr() and inet6_fill_ifaddr():
if (args->netnsid >= 0 && nla_put_s32(skb, IFA_TARGET_NETNSID, args->netnsid))
The spec also has no do block for getaddr. IPv6 registers RTM_GETADDR with .doit = inet6_rtm_getaddr, and inet6_rtm_valid_getaddr_req() accepts IFA_TARGET_NETNSID, IFA_ADDRESS and IFA_LOCAL.
Could target-netnsid be added to the getaddr request and reply lists, along with a do block? Right now, generated per-op C code can't set or parse the attribute whose type this patch fixes. The Python YNL tools still work because they encode and decode against the whole attribute set.
A later patch in this series fixes the getmulticast case: "netlink: specs:
rt-addr: document AF_PACKET multicast dumps" adds target-netnsid to the getmulticast dump request and to &mcaddr-attrs. getaddr is still unchanged at the end of the series.
Documentation/netlink/specs/rt-addr.yaml attribute-sets: · line 125
Quoted 3 lines
Documentation/netlink/specs/rt-addr.yaml +0
-0- name: proto type: u8
[Severity: Low]
This isn't a bug introduced by this patch, but Documentation/netlink/specs/ovs_vport.yaml seems to have the same kind of netnsid type mismatch. Should it be s32 as well? That spec declares the attribute as unsigned:
name: netnsid
type: u32But vport_policy in net/openvswitch/datapath.c uses a signed type:
[OVS_VPORT_ATTR_NETNSID] = { .type = NLA_S32 },ovs_vport_cmd_fill_info() sends the value with nla_put_s32(). The value comes from peernet2id_alloc(), which can return NETNSA_NSID_NOT_ASSIGNED (-1). A YNL client using the ovs_vport spec would decode -1 as 4294967295.
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261012011707.3378-1-sigefriedhyy%40gmail.com
Re: [PATCH net-next v11 1/6] netlink: specs: rt-addr: fix the type of target-netnsid
Quoted 1 line
Should this have a Fixes: tag?
Already discussed in previous thread.
PATCH v11 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 | 7 ++- net/core/dev_addr_lists.c | 44 ++++++++++++++----- net/core/dev_addr_lists_test.c | 18 ++++---- net/mac80211/driver-ops.h | 2 +- 6 files changed, 53 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 +5 -2
@@ -252,13 +252,16 @@ struct netdev_hw_addr {struct netdev_hw_addr_list {struct list_head list; -int count; +/* Only changed through the __hw_addr_count_* helpers after +* __hw_addr_init() +*/ +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
PATCH v11 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 mc_dev pointer, set for dev->mc only, and bump the counter of dev_net(mc_dev) from the count helpers. 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 | 3 +++ include/net/net_namespace.h | 1 + net/core/dev_addr_lists.c | 15 +++++++++++++++ 3 files changed, 19 insertions(+)
include/linux/netdevice.h +3 -0
@@ -259,6 +259,9 @@ struct netdev_hw_addr_list {/* Auxiliary tree for faster lookup on addition and deletion */ struct rb_root tree; + +/* Set for dev->mc only, the device the list belongs to */ +struct net_device *mc_dev; };#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;/* dev->mc membership changes */ u32 ifindex;spinlock_t nsid_lock;
net/core/dev_addr_lists.c +15 -0
@@ -16,9 +16,19 @@#include "dev.h" +/* RTM_GETMULTICAST dumps use the netns generation counter to detect +* changes of dev->mc between dump rounds. +*/ +static void __hw_addr_changed (struct netdev_hw_addr_list *list) +{ +if (list->mc_dev) +atomic_inc (&dev_net (list->mc_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 +43,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 +534,7 @@ void __hw_addr_init(struct netdev_hw_addr_list *list)INIT_LIST_HEAD (&list->list); list->_count =0 ; list->tree =RB_ROOT ; + list->mc_dev =NULL ; }EXPORT_SYMBOL (__hw_addr_init);
@@ -1197,6 +1211,7 @@ EXPORT_SYMBOL(dev_mc_flush);void dev_mc_init (struct net_device *dev) {__hw_addr_init (&dev->mc); + dev->mc.mc_dev = dev; }EXPORT_SYMBOL (dev_mc_init);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH net-next v11 3/6] net: add a generation counter for dev->mc changes
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 message misdescribes the precedent it copies.
- [Low] The patch adds an 8-byte 'struct net_device *mc_dev' to every struct netdev_hw_addr_list (include/linux/netdevice.h:253), but only…
- [Low] __hw_addr_changed() (net/core/dev_addr_lists.c:22-26) reads the device netns with plain dev_net(list->mc_dev).
--
net: add a generation counter for dev->mc changes
This adds a per netns atomic counter, dev_mc_genid. It is bumped whenever an entry is added to or removed from any dev->mc list. To find the netns from the list helpers, a new mc_dev back pointer is added to struct netdev_hw_addr_list and set only for dev->mc. The counter is meant for the AF_PACKET multicast dump in the following patch.
Quoted 3 lines
The IPv4 and IPv6 dumps report that with
NLM_F_DUMP_INTRby stampingcb->seqfrom a per netns generation counter combined withdev_base_seq, seeinet_base_seq().
[Severity: Low]
Is this accurate for the multicast dumps?
inet_base_seq() reads net->ipv4.dev_addr_genid, and inet6_base_seq() reads net->ipv6.dev_addr_genid. inet_dump_addr() and inet6_dump_addr() also use these for RTM_GETMULTICAST and MULTICAST_ADDR.
The only writers of dev_addr_genid are the unicast ifaddr and netdev event
paths: fib_inetaddr_event() and fib_netdev_event() for IPv4, and __ipv6_ifa_notify() for IPv6. Neither net/ipv4/igmp.c nor net/ipv6/mcast.c touches it.
Doesn't that mean the IPv4 and IPv6 multicast dumps also miss group joins and leaves between dump rounds? If so, they share the gap this patch closes for dev->mc rather than being a working precedent. Could the commit message be reworded to say that?
include/linux/netdevice.h struct netdev_hw_addr_list { · line 265
Quoted 12 lines
include/linux/netdevice.h +3
-0@@ -259,6 +259,9 @@ struct netdev_hw_addr_list {/* Auxiliary tree for faster lookup on addition and deletion */ struct rb_root tree; + +/* Set for dev->mc only, the device the list belongs to */ +struct net_device *mc_dev; };
[Severity: Low]
This isn't a functional bug, but the pointer makes every netdev_hw_addr_list bigger, and only dev_mc_init() ever sets it. On 64-bit the struct goes from 32 to 40 bytes.
Some examples of the cost:
- struct net_device embeds four of these lists (uc, mc, dev_addrs, rx_mode_addr_cache), so it grows by 32 bytes.
- vlan_mcast_list[MAX_VLAN_ID] in drivers/net/ethernet/ti/icssg/icssg_prueth.h grows by about 2 KiB per emac.
- netif_rx_mode_run() has four on-stack snapshot lists, so its frame grows by 32 bytes.
- Other users, such as the mac80211 mc_list, carry a pointer that is always NULL.
There is a 4-byte hole after _count. Would a bool or 1-bit flag there, combined with container_of(list, struct net_device, mc), work instead? It would give the same information without growing the struct.
[ ... ]
Quoted 5 lines
net/core/dev_addr_lists.c +0
-0
net/core/dev_addr_lists.c line 25
Quoted 10 lines
net/core/dev_addr_lists.c +7
-0@@ -16,9 +16,19 @@#include "dev.h" +/* RTM_GETMULTICAST dumps use the netns generation counter to detect +* changes of dev->mc between dump rounds. +*/ +static void __hw_addr_changed (struct netdev_hw_addr_list *list) +{ +if (list->mc_dev) +atomic_inc (&dev_net (list->mc_dev)->dev_mc_genid);
[Severity: Low]
Can this dev_net() read race with a netns move of mc_dev?
dev_net() becomes read_pnet(), which is rcu_dereference_protected(pnet->net, true), a plain load. Some callers here hold only addr_list_lock. They don't hold RTNL or the device instance lock. Meanwhile __dev_change_net_namespace() writes nd_net under RTNL and netdev_lock(dev):
net/core/dev.c:__dev_change_net_namespace() {
...
netdev_lock(dev);
dev_net_set(dev, net);
netdev_unlock(dev);
...
}One path that isn't serialized against this goes through net_failover. That driver is not ops-locked and has no ndo_change_rx_flags, so it uses the legacy synchronous rx mode path. An IPv6 multicast join on the failover master runs with only idev->mc_lock held:
__ipv6_dev_mc_inc()
igmp6_group_added()
dev_mc_add(failover)
__dev_set_rx_mode(failover)
net_failover_set_rx_mode()
dev_mc_sync_multiple(primary_dev, dev)
__hw_addr_add_ex(&primary_dev->mc, ...)
__hw_addr_count_inc()
__hw_addr_changed()
dev_net(primary_dev)When the primary slave moves to another netns, net_failover_slave_unregister() clears the pointer without waiting for a grace period:
RCU_INIT_POINTER(nfo_info->primary_dev, NULL);
An rx mode call already in flight can then still be reading dev_net(primary_dev) when dev_net_set() runs. KCSAN would likely report this.
The BH-disabled addr_list_lock already provides an RCU read side here. Would dev_net_rcu() be the better accessor? The worst outcome is one increment landing on the old netns counter, and the move also bumps dev_base_seq in the new netns.
Quoted 7 lines
net/core/dev_addr_lists.c +3
-0+} +static void __hw_addr_count_add (struct netdev_hw_addr_list *list,int value) { list->_count += value; +__hw_addr_changed (list); }
[ ... ]
Quoted 7 lines
net/core/dev_addr_lists.c +1
-0@@ -1197,6 +1211,7 @@ EXPORT_SYMBOL(dev_mc_flush);void dev_mc_init (struct net_device *dev) {__hw_addr_init (&dev->mc); + dev->mc.mc_dev = dev; }EXPORT_SYMBOL (dev_mc_init);
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261012011707.3378-1-sigefriedhyy%40gmail.com
Re: [PATCH net-next v11 3/6] net: add a generation counter for dev->mc changes
Quoted 1 line
- [Low] The commit message misdescribes the precedent it copies.
Looks like a nit, will adjust it if need new revision.
Quoted 2 lines
- [Low] The patch adds an 8-byte 'struct
net_device*mc_dev' to every structnetdev_hw_addr_list(include/linux/netdevice.h:253), but only…
It seems to me this issue by itself doesn't deserve a revision. Will fix it if new revision is required.
Quoted 2 lines
- [Low]
__hw_addr_changed()(net/core/dev_addr_lists.c:22-26) reads the device netns with plaindev_net(list->mc_dev).
This was raised on earlier versions. Every dev->mc writer already reads dev_net() under only the address lock, so this adds no new race.
Paolo Abeni
maintainerRe: [PATCH net-next v11 3/6] net: add a generation counter for dev->mc changes
Quoted 9 lines · Yuyang Huang
Quoted 1 line
- [Low] The commit message misdescribes the precedent it copies.
Looks like a nit, will adjust it if need new revision.
Quoted 2 lines
- [Low] The patch adds an 8-byte 'struct
net_device*mc_dev' to every structnetdev_hw_addr_list(include/linux/netdevice.h:253), but only…It seems to me this issue by itself doesn't deserve a revision. Will fix it if new revision is required.
I agree this is not a blocker, but I think it would be nice if you could follow-up on this one.
The solution proposed by the LLM LGTM.
Quoted 6 lines
Quoted 3 lines
- [Low]
__hw_addr_changed()(net/core/dev_addr_lists.c:22-26) reads the device netns with plaindev_net(list->mc_dev).This was raised on earlier versions. Every
dev->mcwriter already readsdev_net()under only the address lock, so this adds no new race.
Same here.
Also, still speaking of possible follow-up, I think it would be nice if you could change the addr list lifecycle to RCU (no idea of how much complex would be that).
Thanks,
Paolo
Re: [PATCH net-next v11 3/6] net: add a generation counter for dev->mc changes
Quoted 4 lines · Paolo Abeni
I agree this is not a blocker, but I think it would be nice if you could follow-up on this one.
Quoted 8 lines
The solution proposed by the LLM LGTM.
Same here.
Also, still speaking of possible follow-up, I think it would be nice if you could change the addr list lifecycle to RCU (no idea of how much complex would be that).
Thanks for the review. Since we're already at v12 I'd rather not respin just for these, but I agree both are worth fixing, so I'll handle them as follow ups.
The first one is a simple fix, so if v13 ends up being needed for other reasons I'll fold it in there, otherwise I'll send it as a separate patch.
The RCU conversion needs more thought and will probably cause quite a bit of churn, so I'll try it if there's a v13, and if it gets too messy. I'll post it separately later.
Thanks,
Yuyang
Paolo Abeni
maintainerRe: [PATCH net-next v11 3/6] net: add a generation counter for dev->mc changes
Quoted 18 lines · Yuyang Huang
Quoted 4 lines · Paolo Abeni
I agree this is not a blocker, but I think it would be nice if you could follow-up on this one.
Quoted 8 lines
The solution proposed by the LLM LGTM.
Same here.
Also, still speaking of possible follow-up, I think it would be nice if you could change the addr list lifecycle to RCU (no idea of how much complex would be that).
Thanks for the review. Since we're already at v12 I'd rather not respin just for these, but I agree both are worth fixing, so I'll handle them as follow ups.
Quoted 7 lines
The first one is a simple fix, so if v13 ends up being needed for other reasons I'll fold it in there, otherwise I'll send it as a separate patch.
The RCU conversion needs more thought and will probably cause quite a bit of churn, so I'll try it if there's a v13, and if it gets too messy. I'll post it separately later.
To clarify: every I mentioned in my previous email was about possible follow-ups - not to be included here.
My understanding is that there is sort of a pending/implicit question from Jakub on v9: why are you doing this? is does it solve some specific scaling problem or is 'nl is nicer" thing?
/P
Re: [PATCH net-next v11 3/6] net: add a generation counter for dev->mc changes
Quoted 2 lines
To clarify: every I mentioned in my previous email was about possible follow-ups - not to be included here.
Understood, I will send them as separate patches.
Quoted 3 lines
My understanding is that there is sort of a pending/implicit question from Jakub on v9: why are you doing this? is does it solve some specific scaling problem or is 'nl is nicer" thing?
I think the motivation question was on the v5 thread, and I replied there as well.
My original motivation is to simplify some userspace hardware offload code I am working on, and to finish moving "ip maddr" to netlink.
RTM_GETMULTICAST already reports IPv4 and IPv6 group memberships with IFA_MC_USERS. dev->mc is the only part of the multicast state still available only from /proc/net/dev_mcast, so every consumer that needs the full picture keeps two paths: netlink for L3 and procfs text parsing for L2. The offload code above is one such consumer. iproute2 is another: "ip maddr show" already gets IPv4/IPv6 over netlink but still parses procfs for its link-layer entries. The iproute2 change to drop that is ready to follow this series.
Also, compared to procfs, the dump provides a nicer API: it supports per-device filtering, other netns through IFA_TARGET_NETNSID, and reports concurrent changes with NLM_F_DUMP_INTR.
Thanks,
Yuyang
Paolo Abeni
maintainerRe: [PATCH net-next v11 3/6] net: add a generation counter for dev->mc changes
Quoted 11 lines · Yuyang Huang
Quoted 2 lines
To clarify: every I mentioned in my previous email was about possible follow-ups - not to be included here.
Understood, I will send them as separate patches.
Quoted 3 lines
My understanding is that there is sort of a pending/implicit question from Jakub on v9: why are you doing this? is does it solve some specific scaling problem or is 'nl is nicer" thing?
I think the motivation question was on the v5 thread, and I replied there as well.
FTR (and just in case it's not obvious enough :-P) the ML traffic is quite overwhelming. I unable to read some of the email/patches I don't end-up processing, and even when I actually processed the relevant email, I could end-up forgetting a specific contents of one given email, some 10-100K emails later...
TL;DR: please include the relevant information in later revisions, at least as a reference link.
Quoted 11 lines
My original motivation is to simplify some userspace hardware offload code I am working on, and to finish moving "ip maddr" to netlink.
RTM_GETMULTICASTalready reports IPv4 and IPv6 group memberships withIFA_MC_USERS.dev->mcis the only part of the multicast state still available only from/proc/net/dev_mcast, so every consumer that needs the full picture keeps two paths: netlink for L3 and procfs text parsing for L2. The offload code above is one such consumer. iproute2 is another: "ip maddr show" already gets IPv4/IPv6 over netlink but still parses procfs for its link-layer entries. The iproute2 change to drop that is ready to follow this series.
I agree that the unified interface makes sense.
/P
Re: [PATCH net-next v11 3/6] net: add a generation counter for dev->mc changes
Quoted 2 lines
TL;DR: please include the relevant information in later revisions, at least as a reference link.
Understood, thanks for mentioning the background, next time I will make sure to include all relevant information in the cover-letter.
Thanks,
Yuyang
PATCH v11 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 and only if the driver uses it, vxlan for example does not, 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 set from the dev->mc generation counter and dev_base_seq before each round and checked after it, so an entry added or removed since the previous round sets NLM_F_DUMP_INTR. A round without a message skips the check and cb->seq is set once more after the round, so the NLMSG_DONE check reports a change made during the last round or before an empty one.
--- include/linux/netdevice.h | 1 + include/uapi/linux/if_addr.h | 1 + net/core/dev_addr_lists.c | 192 +++++++++++++++++++++++++++++++++++ net/core/rtnetlink.c | 2 + 4 files changed, 196 insertions(+)
include/linux/netdevice.h +1 -0
@@ -5171,6 +5171,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 +192 -0
206 lines not on this page · raw message
net/core/rtnetlink.c +2 -0
@@ -7282,6 +7282,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 v11 4/6] net: add AF_PACKET multicast dumps
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
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] dev_mc_dump() is registered with RTNL_FLAG_DUMP_UNLOCKED.
- [Low] Under this patch alone, the uAPI and the YAML spec disagree.
--
net: add AF_PACKET multicast dumps
This adds an RTM_GETMULTICAST dump handler for ifa_family AF_PACKET. The handler reports every entry of dev->mc in the ifaddrmsg format, using IFA_MULTICAST, IFA_MC_USERS and a new IFA_F_GLOBAL bit in IFA_FLAGS. The dump runs without RTNL, under RCU and netif_addr_lock_bh(), and uses dev_mc_genid plus dev_base_seq to set NLM_F_DUMP_INTR.
include/uapi/linux/if_addr.h enum { · line 60
Quoted 9 lines
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 0x1000
[Severity: Low]
This isn't a bug, but with only this patch applied, the uAPI and Documentation/netlink/specs/rt-addr.yaml don't match.
The ifa-flags enum in the spec still ends at stable-privacy and has no entry for IFA_F_GLOBAL.
The getmulticast reply in the spec lists only multicast, mc-users and cacheinfo. dev_mc_fill_addr() now also emits IFA_FLAGS and IFA_TARGET_NETNSID.
The dump request attributes in the spec are still empty. The op doc still covers only IPv4/IPv6.
The next patch in the series, "netlink: specs: rt-addr: document AF_PACKET multicast dumps", adds the global flag, the flags and target-netnsid attributes and the AF_PACKET doc. After it, the series is consistent.
Could the spec update be folded into this patch, so the uAPI and the spec land together?
Quoted 4 lines
net/core/dev_addr_lists.c +0
-0
[ ... ]
Quoted 8 lines
net/core/dev_addr_lists.c +4
-0@@ -1215,6 +1219,194 @@ 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) +{
[ ... ]
net/core/dev_addr_lists.c void dev_mc_init(struct net_device *dev) · line 1243
Quoted 3 lines
net/core/dev_addr_lists.c +3
-0+ if ((netnsid >= 0 && + nla_put_s32(skb, IFA_TARGET_NETNSID, netnsid)) || + nla_put(skb, IFA_MULTICAST, dev->addr_len, ha->addr) ||
[Severity: Medium]
Is it safe to take the IFA_MULTICAST length from the live dev->addr_len here?
dev_mc_dump() is registered with RTNL_FLAG_DUMP_UNLOCKED. While it calls this function it holds only RCU and addr_list_lock. Code that writes addr_len at runtime holds RTNL but not addr_list_lock. One example is TUNSETLINK in __tun_chr_ioctl():
drivers/net/tun.c:__tun_chr_ioctl() {
...
tun->dev->type = (int) arg;
tun->dev->addr_len = tun_get_addr_len(tun->dev->type);
...
}Nothing flushes dev->mc when the type changes. Entries added through SIOCADDMULTI and dev_mc_add_global() remain after the change, because that path doesn't require IFF_UP.
Those entries were created by __hw_addr_create(), which initializes only as many bytes as the address length at creation time:
net/core/dev_addr_lists.c:__hw_addr_create() {
...
ha = kmalloc(alloc_size, GFP_ATOMIC);
if (!ha)
return NULL;
memcpy(ha->addr, addr, addr_len);
...
}Suppose a TAP device is switched from ARPHRD_ETHER (addr_len 6) to ARPHRD_IP6GRE (addr_len 16). Would this dump then copy the uninitialized bytes in ha->addr[6..15] to userspace?
There are two related points.
First, if TUNSETLINK runs during a dump, its plain write to dev->addr_len races with the read here.
Second, in a dump that takes several rounds, entries from the same device can be emitted with different lengths. A type change doesn't touch dev_mc_genid or dev_base_seq, so NLM_F_DUMP_INTR isn't set in that case.
dev_mc_seq_show() for /proc/net/dev_mcast already reads dev->addr_len the same way. This patch adds a second path to existing behavior rather than a new exposure, but the new uAPI picks up the same problem.
Quoted 5 lines
net/core/dev_addr_lists.c +5
-0+ nla_put_u32(skb, IFA_MC_USERS, ha->refcount) || + nla_put_u32(skb, IFA_FLAGS, ha->global_use ? IFA_F_GLOBAL : 0)) { +nlmsg_cancel (skb, nlh); +return -EMSGSIZE ; + }
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261012011707.3378-1-sigefriedhyy%40gmail.com
Re: [PATCH net-next v11 4/6] net: add AF_PACKET multicast dumps
Quoted 1 line
- [Medium]
dev_mc_dump()is registered withRTNL_FLAG_DUMP_UNLOCKED.
This was raised on v9 too, already replied in a previous thread.
PATCH v11 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 | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-)
Documentation/netlink/specs/rt-addr.yaml +17 -2
@@ -77,6 +77,8 @@ definitions: name: mcautojoin - name: stable-privacy + - + name: global attribute-sets: -
@@ -168,7 +170,17 @@ 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 and target-netnsid with NETLINK_GET_STRICT_CHK + only. attribute-set: addr-attrs fixed-header: ifaddrmsg do:
@@ -181,10 +193,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
PATCH v11 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
RE: [PATCH net-next v11 6/6] selftests: net: test AF_PACKET multicast dumps
Quoted 69 lines
-----Original Message-----
From: Yuyang Huang <[email protected]> On Behalf Of Yuyang Huang
Sent: Monday, October 12, 2026 3:17 AM
To: Yuyang Huang <[email protected]>
Cc: Ajay Singh <[email protected]>; Loktionov, Aleksandr <[email protected]>; Andrew Lunn <[email protected]>; Claudiu Beznea <[email protected]>; David S. Miller <[email protected]>; David Ahern <[email protected]>; Donald Hunter <[email protected]>; Eric Dumazet <[email protected]>; Ido Schimmel <[email protected]>; Keller, Jacob E <[email protected]>; Jakub Kicinski <[email protected]>; Johannes Berg <[email protected]>; Kees Cook <[email protected]>; Kory Maincent <[email protected]>; Kuniyuki Iwashima <[email protected]>; Nicolas Dichtel <[email protected]>; Nikolaos Gkarlis <[email protected]>; Paolo Abeni <[email protected]>; Sabrina Dubroca <[email protected]>; Shuah Khan <[email protected]>; Simon Horman <[email protected]>; Stanislav Fomichev <[email protected]>; Vadim Fedorenko <[email protected]>; Willem de Bruijn <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: [PATCH net-next v11 6/6] selftests: net: testAF_PACKETmulticast dumpsDump the link-layer multicast addresses of a dummy device and verify that
ifa_indexrestricts the dump to that device, that the all-hosts address joined on link up is listed withoutIFA_F_GLOBAL, that an address added with SIOCADDMULTI is listed withIFA_F_GLOBALandIFA_MC_USERS, and thatIFA_TARGET_NETNSIDdumps another netns.Signed-off-by Yuyang Huang <[email protected]>Reviewed-by Nicolas Dichtel <[email protected]>--- tools/testing/selftests/net/rtnetlink.py | 73 +++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-)tools/testing/selftests/net/rtnetlink.py +0
-0@@ -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 -fromlib.pyimportksft_not_in,ksft_not_none+fromlib.pyimportksft_in,ksft_not_in,ksft_not_none
fromlib.pyimport CmdExitFailure, NetNS, NetNSEnter, RtnlAddrFamily,
RtnlRouteFamily fromlib.pyimport defer
IPV4_ALL_HOSTS_MULTICAST= b'\xe0\x00\x00\x01'IPV4_TEST_MULTICAST= b'\xef\x01\x01\x01'IPV6_TEST_MULTICAST=bytes.fromhex('ff020000000000000000000000000123')tools/testing/selftests/net/rtnetlink.py +6
-0+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):
tools/testing/selftests/net/rtnetlink.py +0
-0@@ -105,6 +110,69 @@ def dump_mcaddr6_check() -> None: s2.close()
...
Quoted 5 lines
ipv6_route_del_reason_expired,ipv6_route_del_reason_ra_withdrawn,ipv6_route_del_reason_absent,
--
2.43.0
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Paolo Abeni <[email protected]>:
Quoted 16 lines · On Mon, 12 Oct 2026 10:17:01 +0900 you wrote:
"ip maddr show" prints link-layer, IPv4 and IPv6 entries. The IPv4 and IPv6 ones come over netlink today, with
IFA_MC_USERSfor 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_PACKETfamily toRTM_GETMULTICASTso that the link-layer multicast addresses are reported the same way. Patch 4 dumpsdev->mcin the ifaddrmsg format of the IPv4 and IPv6 dumps:IFA_MULTICASTcarries the address,IFA_MC_USERSthe reference count and a newIFA_F_GLOBALflag marks entries added explicitly, the "static" column of/proc/net/dev_mcast.ifa_indexlimits the dump to one device andIFA_TARGET_NETNSIDselects another netns. Patches 2 and 3 add a generation counter fordev->mcchanges so a multi-part dump reportsNLM_F_DUMP_INTRlike the IPv4 and IPv6 ones. Patches 1 and 5 update the rt-addr spec and patch 6 adds a selftest.
Quoted 1 line
[...]
Here is the summary with links:
- [net-next,v11,1/6] netlink: specs: rt-addr: fix the type of target-netnsid
https://git.kernel.org/netdev/net-next/c/bc6728374478 - [net-next,v11,2/6] net: change netdev_hw_addr_list count through helpers https://git.kernel.org/netdev/net-next/c/778a262a6c69 - [net-next,v11,3/6] net: add a generation counter for dev->mc changes https://git.kernel.org/netdev/net-next/c/646cb8868bd2 - [net-next,v11,4/6] net: add AF_PACKET multicast dumps https://git.kernel.org/netdev/net-next/c/ebff14be20c3 - [net-next,v11,5/6] netlink: specs: rt-addr: document AF_PACKET multicast dumps https://git.kernel.org/netdev/net-next/c/48191155c538 - [net-next,v11,6/6] selftests: net: test AF_PACKET multicast dumps https://git.kernel.org/netdev/net-next/c/0e87a4a83e13
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html