net: netdevsim: fix inconsistent carrier state after link/unlink
Subsystems (4)
v3 cover net: netdevsim: fix inconsistent carrier state after link/unlink
This series fixes netdevsim's inconsistent behavior between carrier and link/unlink state.
More specifically, this fixes a bug that the carrier goes DOWN although two netdevsim were peered, depending on the order of peering and ifup. Especially in a NetworkManager-enabled environment, netdevsim test fails because of this.
The first patch fixes the bug itself in netdevsim/bus.c by adding netif_carrier_on() into a proper function. The second patch adds a regression test for this bug.
Changelog
=========
v2 -> v3:
- Rebase to the latest net/main
- patch 1:
- Add Reviewed-by tag from Breno Leitao
- Address the review comments from Jakub Kicinski regarding the condition to call netif_carrier_on()
- patch 2:
- Solve the shellcheck warning in the test
- Line too long error is left as is for consistency with other test cases
- v2: https://lore.kernel.org/netdev/[email protected]/
v1 -> v2:
- Rebase to the latest net/main
- Separate TFO tests from this series
- Separate netdevsim test improvement from this series
- v1: https://lore.kernel.org/netdev/[email protected]/
Yohei Kojima (2):
net: netdevsim: fix inconsistent carrier state after link/unlink
selftests: netdevsim: add carrier state consistency test
drivers/net/netdevsim/bus.c | 8 +++ .../selftests/drivers/net/netdevsim/peer.sh | 59 +++++++++++++++++++ 2 files changed, 67 insertions(+)
Signature · 1 line
2.51.2
PATCH v3 1/2 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.
--- drivers/net/netdevsim/bus.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/net/netdevsim/bus.c +8 -0
@@ -332,6 +332,11 @@ static ssize_t link_device_store(const struct bus_type *bus, const char *buf, sircu_assign_pointer (nsim_a->peer, nsim_b);rcu_assign_pointer (nsim_b->peer, nsim_a); +if (netif_running (dev_a) &&netif_running (dev_b)) { +netif_carrier_on (dev_a); +netif_carrier_on (dev_b); + } + out_err:put_net (ns_b);put_net (ns_a);
@@ -381,6 +386,9 @@ static ssize_t unlink_device_store(const struct bus_type *bus, const char *buf,if (!peer) goto out_put_netns; +netif_carrier_off (dev); +netif_carrier_off (peer->netdev); + err =0 ;RCU_INIT_POINTER (nsim->peer,NULL );RCU_INIT_POINTER (peer->peer,NULL );
Signature · 1 line
2.51.2
PATCH v3 2/2 selftests: netdevsim: add carrier state consistency test
In reply to Yohei KojimaThis commit adds a test case for netdevsim carrier state consistency. Specifically, the added test verifies the carrier state during the following operations:
1. Unlink two netdevsims
2. ifdown one netdevsim, then ifup again
3. Link the netdevsims again
4. ifdown one netdevsim, then ifup again
These steps verifies that the carrier is UP iff two netdevsims are linked and ifuped.
--- .../selftests/drivers/net/netdevsim/peer.sh | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+)
tools/testing/selftests/drivers/net/netdevsim/peer.sh +59 -0
@@ -52,6 +52,39 @@ cleanup_ns() ip netns del nssv } +is_carrier_up() +{ + local netns="$1" + local nsim_dev="$2" + + test "$(ip netns exec "$netns" \ + cat /sys/class/net/"$nsim_dev"/carrier 2>/dev/null)" -eq 1 +} + +assert_carrier_up() +{ + local netns="$1" + local nsim_dev="$2" + + if ! is_carrier_up "$netns" "$nsim_dev"; then + echo "$nsim_dev's carrier should be UP, but it isn't" + cleanup_ns + exit 1 + fi +} + +assert_carrier_down() +{ + local netns="$1" + local nsim_dev="$2" + + if is_carrier_up "$netns" "$nsim_dev"; then + echo "$nsim_dev's carrier should be DOWN, but it isn't" + cleanup_ns + exit 1 + fi +} + ### ### Code start ###
@@ -113,6 +146,32 @@ if [ $? -eq 0 ]; then exit 1 fi +# netdevsim carrier state consistency checking +assert_carrier_up nssv "$NSIM_DEV_1_NAME" +assert_carrier_up nscl "$NSIM_DEV_2_NAME" + +echo "$NSIM_DEV_1_FD:$NSIM_DEV_1_IFIDX" > "$NSIM_DEV_SYS_UNLINK" + +assert_carrier_down nssv "$NSIM_DEV_1_NAME" +assert_carrier_down nscl "$NSIM_DEV_2_NAME" + +ip netns exec nssv ip link set dev "$NSIM_DEV_1_NAME" down +ip netns exec nssv ip link set dev "$NSIM_DEV_1_NAME" up + +assert_carrier_down nssv "$NSIM_DEV_1_NAME" +assert_carrier_down nscl "$NSIM_DEV_2_NAME" + +echo "$NSIM_DEV_1_FD:$NSIM_DEV_1_IFIDX $NSIM_DEV_2_FD:$NSIM_DEV_2_IFIDX" > $NSIM_DEV_SYS_LINK + +assert_carrier_up nssv "$NSIM_DEV_1_NAME" +assert_carrier_up nscl "$NSIM_DEV_2_NAME" + +ip netns exec nssv ip link set dev "$NSIM_DEV_1_NAME" down +ip netns exec nssv ip link set dev "$NSIM_DEV_1_NAME" up + +assert_carrier_up nssv "$NSIM_DEV_1_NAME" +assert_carrier_up nscl "$NSIM_DEV_2_NAME" + # send/recv packets tmp_file=$(mktemp)
Signature · 1 line
2.51.2
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Tue, 6 Jan 2026 00:17:31 +0900 you wrote:
This series fixes netdevsim's inconsistent behavior between carrier and link/unlink state.
More specifically, this fixes a bug that the carrier goes DOWN although two netdevsim were peered, depending on the order of peering and ifup. Especially in a NetworkManager-enabled environment, netdevsim test fails because of this.
[...]
Here is the summary with links:
- [net,v3,1/2] net: netdevsim: fix inconsistent carrier state after link/unlink
https://git.kernel.org/netdev/net/c/d83dddffe190 - [net,v3,2/2] selftests: netdevsim: add carrier state consistency test https://git.kernel.org/netdev/net/c/75df712cddfd
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html