Skip to content

Commit d83dddf

Browse files
y-kojkuba-moo
authored andcommitted
net: netdevsim: fix inconsistent carrier state after link/unlink
This patch fixes the edge case behavior on ifup/ifdown and linking/unlinking two netdevsim interfaces: 1. unlink two interfaces netdevsim1 and netdevsim2 2. ifdown netdevsim1 3. ifup netdevsim1 4. link two interfaces netdevsim1 and netdevsim2 5. (Now two interfaces are linked in terms of netdevsim peer, but carrier state of the two interfaces remains DOWN.) This inconsistent behavior is caused by the current implementation, which only cares about the "link, then ifup" order, not "ifup, then link" order. This patch fixes the inconsistency by calling netif_carrier_on() when two netdevsim interfaces are linked. This patch fixes buggy behavior on NetworkManager-based systems which causes the netdevsim test to fail with the following error: # timeout set to 600 # selftests: drivers/net/netdevsim: peer.sh # 2025/12/25 00:54:03 socat[9115] W address is opened in read-write mode but only supports read-only # 2025/12/25 00:56:17 socat[9115] W connect(7, AF=2 192.168.1.1:1234, 16): Connection timed out # 2025/12/25 00:56:17 socat[9115] E TCP:192.168.1.1:1234: Connection timed out # expected 3 bytes, got 0 # 2025/12/25 00:56:17 socat[9109] W exiting on signal 15 not ok 13 selftests: drivers/net/netdevsim: peer.sh # exit=1 This patch also solves timeout on TCP Fast Open (TFO) test in NetworkManager-based systems because it also depends on netdevsim's carrier consistency. Fixes: 1a8fed5 ("netdevsim: set the carrier when the device goes up") Signed-off-by: Yohei Kojima <yk@y-koj.net> Reviewed-by: Breno Leitao <leitao@debian.org> Link: https://patch.msgid.link/602c9e1ba5bb2ee1997bb38b1d866c9c3b807ae9.1767624906.git.yk@y-koj.net Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 353cfc0 commit d83dddf

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

  • drivers/net/netdevsim

drivers/net/netdevsim/bus.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ static ssize_t link_device_store(const struct bus_type *bus, const char *buf, si
332332
rcu_assign_pointer(nsim_a->peer, nsim_b);
333333
rcu_assign_pointer(nsim_b->peer, nsim_a);
334334

335+
if (netif_running(dev_a) && netif_running(dev_b)) {
336+
netif_carrier_on(dev_a);
337+
netif_carrier_on(dev_b);
338+
}
339+
335340
out_err:
336341
put_net(ns_b);
337342
put_net(ns_a);
@@ -381,6 +386,9 @@ static ssize_t unlink_device_store(const struct bus_type *bus, const char *buf,
381386
if (!peer)
382387
goto out_put_netns;
383388

389+
netif_carrier_off(dev);
390+
netif_carrier_off(peer->netdev);
391+
384392
err = 0;
385393
RCU_INIT_POINTER(nsim->peer, NULL);
386394
RCU_INIT_POINTER(peer->peer, NULL);

0 commit comments

Comments
 (0)