The test that nla_put_iflink() uses to detect whether a device has a lower link doesn't work with network namespaces, as a device can have the same ifindex as its parent:
ip netns add main ip netns add peer ip -net main link add dummy0 type dummy ip -net main link add link dummy0 macvlan0 netns peer type macvlan ip -net main link show type dummy # 9: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop ... ip -net peer link show type macvlan # 9: macvlan0@if9: <BROADCAST,MULTICAST> mtu 1500 qdisc noop ... Instead of calling dev_get_iflink(), we can use the existence of the ndo_get_iflink operation (which dev_get_iflink would call) to check if a device has a lower link. I previously tried to fix this with commit feadc4b6cf42 ("rtnetlink: always put IFLA_LINK for links with a link-netnsid") but didn't get to the root of the problem. Fixes: d8a5ec672768 ("[NET]: netlink support for moving devices between network namespaces.") Signed-off-by: Sabrina Dubroca <s...@queasysnail.net> --- net/core/rtnetlink.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index c35b3f02b4f9..a8459fb59ccd 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1549,12 +1549,13 @@ static int put_master_ifindex(struct sk_buff *skb, struct net_device *dev) static int nla_put_iflink(struct sk_buff *skb, const struct net_device *dev) { - int ifindex = dev_get_iflink(dev); + if (dev->netdev_ops && dev->netdev_ops->ndo_get_iflink) { + int ifindex = dev->netdev_ops->ndo_get_iflink(dev); - if (dev->ifindex == ifindex) - return 0; + return nla_put_u32(skb, IFLA_LINK, ifindex); + } - return nla_put_u32(skb, IFLA_LINK, ifindex); + return 0; } static noinline_for_stack int nla_put_ifalias(struct sk_buff *skb, -- 2.28.0