Bridge devices try to detect if devices have a lower link when dumping
information about their ports, but that detection doesn't work when
the device and its link have the same ifindex:

For a bridge with the following ports:

    20: veth1@if20: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master bridge0 ...
    22: veth2@if21: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master bridge0 ...

We get this output with the "bridge link" command:

    20: veth1: <BROADCAST,MULTICAST> mtu 1500 master bridge0 ...
    22: veth2@if21: <BROADCAST,MULTICAST> mtu 1500 master bridge0 ...

veth1 should also have "@if20" in bridge link.

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.

Fixes: d8a5ec672768 ("[NET]: netlink support for moving devices between network 
namespaces.")
Signed-off-by: Sabrina Dubroca <s...@queasysnail.net>
---
 net/bridge/br_netlink.c | 2 +-
 net/core/rtnetlink.c    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
index 147d52596e17..6af5d62ddf7b 100644
--- a/net/bridge/br_netlink.c
+++ b/net/bridge/br_netlink.c
@@ -410,7 +410,7 @@ static int br_fill_ifinfo(struct sk_buff *skb,
            nla_put_u8(skb, IFLA_OPERSTATE, operstate) ||
            (dev->addr_len &&
             nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) ||
-           (dev->ifindex != dev_get_iflink(dev) &&
+           (dev->netdev_ops && dev->netdev_ops->ndo_get_iflink &&
             nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev))))
                goto nla_put_failure;
 
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index a8459fb59ccd..3d8051158890 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -4625,7 +4625,7 @@ int ndo_dflt_bridge_getlink(struct sk_buff *skb, u32 pid, 
u32 seq,
             nla_put_u32(skb, IFLA_MASTER, br_dev->ifindex)) ||
            (dev->addr_len &&
             nla_put(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr)) ||
-           (dev->ifindex != dev_get_iflink(dev) &&
+           (dev->netdev_ops && dev->netdev_ops->ndo_get_iflink &&
             nla_put_u32(skb, IFLA_LINK, dev_get_iflink(dev))))
                goto nla_put_failure;
 
-- 
2.28.0

Reply via email to