diff mbox series

[net,10/12] net: link_watch: fix detection of urgent events

Message ID 5a58a1a6425c565bb0ba7f46461fdd23cedb6b72.1600770261.git.sd@queasysnail.net
State New
Headers show
Series net: iflink and link-netnsid fixes | expand

Commit Message

Sabrina Dubroca Oct. 1, 2020, 7:59 a.m. UTC
linkwatch_urgent_event can miss urgent events when the device and its
link have the same ifindex, which can happen when those devices are in
different network namespaces.

With this setup, the vlan0 device can remain in LOWERLAYERDOWN state
for a full second (the linkwatch delay for non-urgent events), while
the vlan1 device will come up immediately:

    ip netns add a
    ip netns add b
    ip -net a link add dummy0 type dummy
    ip -net a link add link dummy0 vlan0 netns b type vlan id 1
    ip -net a link add link dummy0 vlan1 netns b type vlan id 2

    ip -net a link set dummy0 up
    ip -net b link set vlan1 down ; ip -net b link set vlan0 down
    sleep 2
    ip -net b link set vlan1 up   ; ip -net b link set vlan0 up

Fixes: d8a5ec672768 ("[NET]: netlink support for moving devices between network namespaces.")
Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
---
 net/core/link_watch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/net/core/link_watch.c b/net/core/link_watch.c
index 6932ad51aa4a..8a5d0ab820f9 100644
--- a/net/core/link_watch.c
+++ b/net/core/link_watch.c
@@ -92,7 +92,7 @@  static bool linkwatch_urgent_event(struct net_device *dev)
 	if (!netif_running(dev))
 		return false;
 
-	if (dev->ifindex != dev_get_iflink(dev))
+	if (dev->netdev_ops && dev->netdev_ops->ndo_get_iflink)
 		return true;
 
 	if (netif_is_lag_port(dev) || netif_is_lag_master(dev))