* [PATCH net-next v6 1/4] netlink: specs: rt-addr: fix the type of target-netnsid
2026-09-21 23:59 [PATCH net-next v6 0/4] rtnetlink: dump link-layer multicast addresses Yuyang Huang
@ 2026-09-21 23:59 ` Yuyang Huang
2026-09-21 23:59 ` [PATCH net-next v6 2/4] net: add AF_PACKET multicast dumps Yuyang Huang
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Yuyang Huang @ 2026-09-21 23:59 UTC (permalink / raw)
To: Yuyang Huang
Cc: Andrew Lunn, David S. Miller, David Ahern, Donald Hunter,
Eric Dumazet, Ido Schimmel, Jacob Keller, Jakub Kicinski,
Kuniyuki Iwashima, Nicolas Dichtel, Nikolaos Gkarlis,
Paolo Abeni, Sabrina Dubroca, Shuah Khan, Simon Horman,
Stanislav Fomichev, linux-kernel, linux-kselftest, netdev
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.
Signed-off-by: Yuyang Huang <sigefriedhyy@gmail.com>
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
Documentation/netlink/specs/rt-addr.yaml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Documentation/netlink/specs/rt-addr.yaml b/Documentation/netlink/specs/rt-addr.yaml
index 0ecbd24c890c..17ead2203451 100644
--- a/Documentation/netlink/specs/rt-addr.yaml
+++ b/Documentation/netlink/specs/rt-addr.yaml
@@ -119,7 +119,7 @@ attribute-sets:
type: u32
-
name: target-netnsid
- type: binary
+ type: s32
-
name: proto
type: u8
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH net-next v6 2/4] net: add AF_PACKET multicast dumps
2026-09-21 23:59 [PATCH net-next v6 0/4] rtnetlink: dump link-layer multicast addresses Yuyang Huang
2026-09-21 23:59 ` [PATCH net-next v6 1/4] netlink: specs: rt-addr: fix the type of target-netnsid Yuyang Huang
@ 2026-09-21 23:59 ` Yuyang Huang
2026-09-22 7:20 ` Nicolas Dichtel
2026-09-21 23:59 ` [PATCH net-next v6 3/4] netlink: specs: rt-addr: document " Yuyang Huang
2026-09-21 23:59 ` [PATCH net-next v6 4/4] selftests: net: test " Yuyang Huang
3 siblings, 1 reply; 7+ messages in thread
From: Yuyang Huang @ 2026-09-21 23:59 UTC (permalink / raw)
To: Yuyang Huang
Cc: Andrew Lunn, David S. Miller, David Ahern, Donald Hunter,
Eric Dumazet, Ido Schimmel, Jacob Keller, Jakub Kicinski,
Kuniyuki Iwashima, Nicolas Dichtel, Nikolaos Gkarlis,
Paolo Abeni, Sabrina Dubroca, Shuah Khan, Simon Horman,
Stanislav Fomichev, linux-kernel, linux-kselftest, netdev
RTM_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, and stamps cb->seq from
dev_base_seq so a device added or removed between dump rounds sets
NLM_F_DUMP_INTR.
Signed-off-by: Yuyang Huang <sigefriedhyy@gmail.com>
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
include/linux/netdevice.h | 1 +
include/uapi/linux/if_addr.h | 1 +
net/core/dev_addr_lists.c | 177 +++++++++++++++++++++++++++++++++++
net/core/rtnetlink.c | 2 +
4 files changed, 181 insertions(+)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 1f0710eef185..d469aba057c7 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -5169,6 +5169,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
diff --git a/include/uapi/linux/if_addr.h b/include/uapi/linux/if_addr.h
index 7fb630b7fe31..0a1ad9ebb47b 100644
--- a/include/uapi/linux/if_addr.h
+++ b/include/uapi/linux/if_addr.h
@@ -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
struct ifa_cacheinfo {
__u32 ifa_prefered;
diff --git a/net/core/dev_addr_lists.c b/net/core/dev_addr_lists.c
index 08528ca0a8b3..b69565f8ff05 100644
--- a/net/core/dev_addr_lists.c
+++ b/net/core/dev_addr_lists.c
@@ -10,8 +10,12 @@
#include <linux/netdevice.h>
#include <linux/rtnetlink.h>
#include <linux/export.h>
+#include <linux/if_addr.h>
#include <linux/list.h>
#include <linux/spinlock.h>
+#include <net/netlink.h>
+#include <net/rtnetlink.h>
+#include <net/sock.h>
#include <kunit/visibility.h>
#include "dev.h"
@@ -1180,6 +1184,179 @@ 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;
+ struct ifaddrmsg *ifm;
+ struct nlmsghdr *nlh;
+
+ nlh = nlmsg_put(skb, portid, seq, RTM_GETMULTICAST, sizeof(*ifm),
+ flags);
+ if (!nlh)
+ return -EMSGSIZE;
+
+ ifm = nlmsg_data(nlh);
+ ifm->ifa_family = AF_PACKET;
+ ifm->ifa_prefixlen = 0;
+ /* ifm->ifa_flags holds 8 bits, the full value is in IFA_FLAGS */
+ ifm->ifa_flags = (__u8)ifa_flags;
+ ifm->ifa_scope = RT_SCOPE_LINK;
+ ifm->ifa_index = dev->ifindex;
+
+ 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)) {
+ nlmsg_cancel(skb, nlh);
+ return -EMSGSIZE;
+ }
+
+ nlmsg_end(skb, nlh);
+ return 0;
+}
+
+static int dev_mc_dump_dev(struct net_device *dev, struct sk_buff *skb,
+ struct netlink_callback *cb, int *s_addr_idx,
+ unsigned int flags, int netnsid)
+{
+ struct netdev_hw_addr *ha;
+ int addr_idx = 0;
+ int err = 0;
+
+ netif_addr_lock_bh(dev);
+ 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));
+ addr_idx++;
+ }
+ netif_addr_unlock_bh(dev);
+
+ *s_addr_idx = err < 0 ? addr_idx : 0;
+
+ return err;
+}
+
+struct dev_mc_dump_filter {
+ struct net *tgt_net;
+ netns_tracker ns_tracker;
+ int netnsid;
+ int ifindex;
+};
+
+static const struct nla_policy dev_mc_dump_policy[IFA_MAX + 1] = {
+ [IFA_TARGET_NETNSID] = { .type = NLA_S32 },
+};
+
+static int dev_mc_valid_dump_req(const struct nlmsghdr *nlh, struct sock *sk,
+ struct dev_mc_dump_filter *filter,
+ struct netlink_ext_ack *extack)
+{
+ struct nlattr *tb[IFA_MAX + 1];
+ struct ifaddrmsg *ifm;
+ int err;
+
+ ifm = nlmsg_payload(nlh, sizeof(*ifm));
+ if (!ifm) {
+ NL_SET_ERR_MSG(extack,
+ "Invalid header for multicast dump request");
+ return -EINVAL;
+ }
+
+ if (ifm->ifa_prefixlen || ifm->ifa_flags || ifm->ifa_scope) {
+ NL_SET_ERR_MSG(extack,
+ "Invalid values in multicast dump header");
+ return -EINVAL;
+ }
+
+ err = nlmsg_parse(nlh, sizeof(*ifm), tb, IFA_MAX,
+ dev_mc_dump_policy, extack);
+ if (err < 0)
+ return err;
+
+ if (tb[IFA_TARGET_NETNSID]) {
+ struct net *net;
+
+ filter->netnsid = nla_get_s32(tb[IFA_TARGET_NETNSID]);
+ net = rtnl_get_net_ns_capable(sk, filter->netnsid);
+ if (IS_ERR(net)) {
+ NL_SET_ERR_MSG(extack,
+ "Invalid target network namespace id");
+ return PTR_ERR(net);
+ }
+ netns_tracker_alloc(net, &filter->ns_tracker, GFP_KERNEL);
+ filter->tgt_net = net;
+ }
+
+ filter->ifindex = ifm->ifa_index;
+
+ return 0;
+}
+
+int dev_mc_dump(struct sk_buff *skb, struct netlink_callback *cb)
+{
+ struct dev_mc_dump_filter filter = {
+ .tgt_net = sock_net(skb->sk),
+ .netnsid = -1,
+ };
+ unsigned int flags = NLM_F_MULTI;
+ struct {
+ unsigned long ifindex;
+ int addr_idx;
+ } *ctx = (void *)cb->ctx;
+ unsigned long s_ifindex;
+ struct net_device *dev;
+ int err;
+
+ err = dev_mc_valid_dump_req(cb->nlh, skb->sk, &filter, cb->extack);
+ if (err < 0)
+ return err;
+
+ cb->seq = READ_ONCE(filter.tgt_net->dev_base_seq);
+
+ rcu_read_lock();
+
+ if (filter.ifindex) {
+ cb->answer_flags |= NLM_F_DUMP_FILTERED;
+ flags |= NLM_F_DUMP_FILTERED;
+ dev = dev_get_by_index_rcu(filter.tgt_net, filter.ifindex);
+ if (!dev) {
+ err = -ENODEV;
+ goto out;
+ }
+ err = dev_mc_dump_dev(dev, skb, cb, &ctx->addr_idx, flags,
+ filter.netnsid);
+ goto out;
+ }
+
+ 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;
+ err = dev_mc_dump_dev(dev, skb, cb, &ctx->addr_idx, flags,
+ filter.netnsid);
+ if (err < 0)
+ break;
+ }
+out:
+ rcu_read_unlock();
+ if (filter.netnsid >= 0)
+ put_net_track(filter.tgt_net, &filter.ns_tracker);
+ return err;
+}
+
static int netif_addr_lists_snapshot(struct net_device *dev,
struct netdev_hw_addr_list *uc_snap,
struct netdev_hw_addr_list *mc_snap,
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index e3444fd24061..204dc9040e3c 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -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,
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH net-next v6 2/4] net: add AF_PACKET multicast dumps
2026-09-21 23:59 ` [PATCH net-next v6 2/4] net: add AF_PACKET multicast dumps Yuyang Huang
@ 2026-09-22 7:20 ` Nicolas Dichtel
2026-09-22 8:44 ` Yuyang Huang
0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Dichtel @ 2026-09-22 7:20 UTC (permalink / raw)
To: Yuyang Huang
Cc: Andrew Lunn, David S. Miller, David Ahern, Donald Hunter,
Eric Dumazet, Ido Schimmel, Jacob Keller, Jakub Kicinski,
Kuniyuki Iwashima, Nikolaos Gkarlis, Paolo Abeni,
Sabrina Dubroca, Shuah Khan, Simon Horman, Stanislav Fomichev,
linux-kernel, linux-kselftest, netdev
Le 22/09/2026 à 01:59, Yuyang Huang a écrit :
> RTM_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, and stamps cb->seq from
> dev_base_seq so a device added or removed between dump rounds sets
> NLM_F_DUMP_INTR.
>
> Signed-off-by: Yuyang Huang <sigefriedhyy@gmail.com>
> Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> ---
[snip]
> +static int dev_mc_dump_dev(struct net_device *dev, struct sk_buff *skb,
> + struct netlink_callback *cb, int *s_addr_idx,
> + unsigned int flags, int netnsid)
> +{
> + struct netdev_hw_addr *ha;
> + int addr_idx = 0;
> + int err = 0;
> +
> + netif_addr_lock_bh(dev);
> + 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));
> + addr_idx++;
> + }
> + netif_addr_unlock_bh(dev);
> +
> + *s_addr_idx = err < 0 ? addr_idx : 0;
> +
> + return err;
> +}
[snip]
> +int dev_mc_dump(struct sk_buff *skb, struct netlink_callback *cb)
> +{
> + struct dev_mc_dump_filter filter = {
> + .tgt_net = sock_net(skb->sk),
> + .netnsid = -1,
> + };
> + unsigned int flags = NLM_F_MULTI;
> + struct {
> + unsigned long ifindex;
> + int addr_idx;
> + } *ctx = (void *)cb->ctx;
> + unsigned long s_ifindex;
> + struct net_device *dev;
> + int err;
> +
> + err = dev_mc_valid_dump_req(cb->nlh, skb->sk, &filter, cb->extack);
> + if (err < 0)
> + return err;
> +
> + cb->seq = READ_ONCE(filter.tgt_net->dev_base_seq);
dev_base_seq only indicates whether the netdevice list has changed, not whether
the addr list has changed. It's only a partial consistency check.
See inet_base_seq()/inet6_base_seq().
I don't see an equivalent of dev_addr_genid for the L2 mcaddr list; it should
probably be added.
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH net-next v6 2/4] net: add AF_PACKET multicast dumps
2026-09-22 7:20 ` Nicolas Dichtel
@ 2026-09-22 8:44 ` Yuyang Huang
0 siblings, 0 replies; 7+ messages in thread
From: Yuyang Huang @ 2026-09-22 8:44 UTC (permalink / raw)
To: nicolas.dichtel
Cc: Andrew Lunn, David S. Miller, David Ahern, Donald Hunter,
Eric Dumazet, Ido Schimmel, Jacob Keller, Jakub Kicinski,
Kuniyuki Iwashima, Nikolaos Gkarlis, Paolo Abeni,
Sabrina Dubroca, Shuah Khan, Simon Horman, Stanislav Fomichev,
linux-kernel, linux-kselftest, netdev
On Tue, Sep 22, 2026 at 4:20 PM Nicolas Dichtel
<nicolas.dichtel@6wind.com> wrote:
> dev_base_seq only indicates whether the netdevice list has changed, not whether
> the addr list has changed. It's only a partial consistency check.
> See inet_base_seq()/inet6_base_seq().
>
> I don't see an equivalent of dev_addr_genid for the L2 mcaddr list; it should
> probably be added.
Thanks for the suggestion, I will fix this issue in v7: I think I need
to add a per netns counter bumped on dev->mc changes and combine it
with dev_base_seq like inet_base_seq() does.
Thanks,
Yuyang
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net-next v6 3/4] netlink: specs: rt-addr: document AF_PACKET multicast dumps
2026-09-21 23:59 [PATCH net-next v6 0/4] rtnetlink: dump link-layer multicast addresses Yuyang Huang
2026-09-21 23:59 ` [PATCH net-next v6 1/4] netlink: specs: rt-addr: fix the type of target-netnsid Yuyang Huang
2026-09-21 23:59 ` [PATCH net-next v6 2/4] net: add AF_PACKET multicast dumps Yuyang Huang
@ 2026-09-21 23:59 ` Yuyang Huang
2026-09-21 23:59 ` [PATCH net-next v6 4/4] selftests: net: test " Yuyang Huang
3 siblings, 0 replies; 7+ messages in thread
From: Yuyang Huang @ 2026-09-21 23:59 UTC (permalink / raw)
To: Yuyang Huang
Cc: Andrew Lunn, David S. Miller, David Ahern, Donald Hunter,
Eric Dumazet, Ido Schimmel, Jacob Keller, Jakub Kicinski,
Kuniyuki Iwashima, Nicolas Dichtel, Nikolaos Gkarlis,
Paolo Abeni, Sabrina Dubroca, Shuah Khan, Simon Horman,
Stanislav Fomichev, linux-kernel, linux-kselftest, netdev
Add 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.
Signed-off-by: Yuyang Huang <sigefriedhyy@gmail.com>
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
Documentation/netlink/specs/rt-addr.yaml | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/Documentation/netlink/specs/rt-addr.yaml b/Documentation/netlink/specs/rt-addr.yaml
index 17ead2203451..dc5c0ce259ba 100644
--- a/Documentation/netlink/specs/rt-addr.yaml
+++ b/Documentation/netlink/specs/rt-addr.yaml
@@ -77,6 +77,8 @@ definitions:
name: mcautojoin
-
name: stable-privacy
+ -
+ name: global
attribute-sets:
-
@@ -168,7 +170,15 @@ 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. A non-zero
+ ifa-index restricts the dump to that device, ifa-prefixlen,
+ ifa-flags and ifa-scope must be zero.
attribute-set: addr-attrs
fixed-header: ifaddrmsg
do:
@@ -181,10 +191,13 @@ operations:
- multicast
- mc-users
- cacheinfo
+ - flags
+ - target-netnsid
dump:
request:
value: 58
- attributes: []
+ attributes:
+ - target-netnsid
reply:
value: 58
attributes: *mcaddr-attrs
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH net-next v6 4/4] selftests: net: test AF_PACKET multicast dumps
2026-09-21 23:59 [PATCH net-next v6 0/4] rtnetlink: dump link-layer multicast addresses Yuyang Huang
` (2 preceding siblings ...)
2026-09-21 23:59 ` [PATCH net-next v6 3/4] netlink: specs: rt-addr: document " Yuyang Huang
@ 2026-09-21 23:59 ` Yuyang Huang
3 siblings, 0 replies; 7+ messages in thread
From: Yuyang Huang @ 2026-09-21 23:59 UTC (permalink / raw)
To: Yuyang Huang
Cc: Andrew Lunn, David S. Miller, David Ahern, Donald Hunter,
Eric Dumazet, Ido Schimmel, Jacob Keller, Jakub Kicinski,
Kuniyuki Iwashima, Nicolas Dichtel, Nikolaos Gkarlis,
Paolo Abeni, Sabrina Dubroca, Shuah Khan, Simon Horman,
Stanislav Fomichev, linux-kernel, linux-kselftest, netdev
Dump 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.
Signed-off-by: Yuyang Huang <sigefriedhyy@gmail.com>
Reviewed-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
tools/testing/selftests/net/rtnetlink.py | 73 +++++++++++++++++++++++-
1 file changed, 71 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/net/rtnetlink.py b/tools/testing/selftests/net/rtnetlink.py
index dc8c77db4897..5534ade056a5 100755
--- a/tools/testing/selftests/net/rtnetlink.py
+++ b/tools/testing/selftests/net/rtnetlink.py
@@ -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,
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread