From: Ramses de Norre <rams…@well-founded.dev> Add a test for the two ways the ARP monitor can start after the slaves were enslaved: bringing the bond up after enslaving into it while it is down, and setting arp_interval on a running bond that uses miimon. In both cases the test waits longer than the arp_missed_max window before the monitor starts, and checks that the primary stays active and that no slave gets a link failure. Without the previous patch, both cases fail: the first monitor run takes both slaves down and the bond comes back on eth1, where it stays with primary_reselect=failure. Signed-off-by: Ramses de Norre <rams…@well-founded.dev> --- .../testing/selftests/drivers/net/bonding/Makefile | 1 + .../drivers/net/bonding/bond_arp_monitor_start.sh | 154 +++++++++++++++++++++ 2 files changed, 155 insertions(+) diff --git a/tools/testing/selftests/drivers/net/bonding/Makefile b/tools/testing/selftests/drivers/net/bonding/Makefile index 46d9fede59185..12276c942506e 100644 --- a/tools/testing/selftests/drivers/net/bonding/Makefile +++ b/tools/testing/selftests/drivers/net/bonding/Makefile @@ -6,6 +6,7 @@ TEST_PROGS := \ bond-break-lacpdu-tx.sh \ bond-eth-type-change.sh \ bond-lladdr-target.sh \ + bond_arp_monitor_start.sh \ bond_ipsec_offload.sh \ bond_lacp_independent_control.sh \ bond_lacp_prio.sh \ diff --git a/tools/testing/selftests/drivers/net/bonding/bond_arp_monitor_start.sh b/tools/testing/selftests/drivers/net/bonding/bond_arp_monitor_start.sh new file mode 100755 index 0000000000000..a718292172244 --- /dev/null +++ b/tools/testing/selftests/drivers/net/bonding/bond_arp_monitor_start.sh @@ -0,0 +1,154 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Check that the ARP monitor does not take UP slaves down when it starts +# after the slaves were enslaved. That happens when the slaves are enslaved +# while the bond is down, or when arp_interval is set on a running bond +# that used miimon. The monitor must give the slaves a full arp_missed_max +# window from when it starts, not from when they were enslaved. +# +# +------------------------+ +# | bond0 192.0.2.1/24 | h_ns +# | eth0 eth1 | +# +---+-------------+------+ +# | | +# +---+-------------+------+ +# | sw0 sw1 | sw_ns +# | br0 192.0.2.254/24 | +# +------------------------+ + +# shellcheck disable=SC2034,SC2329 +ALL_TESTS=" + arp_monitor_start_on_open + arp_monitor_start_on_interval_set +" +REQUIRE_MZ=no +NUM_NETIFS=0 +lib_dir=$(dirname "$0") +# shellcheck disable=SC1091 +source "$lib_dir"/../../../net/forwarding/lib.sh + +require_command jq + +# Assigned by setup_ns. +h_ns="" +sw_ns="" + +ARP_INTERVAL=100 +# Longer than the arp_missed_max window of the slaves, so that their +# enslave time seeds are stale when the monitor starts. +ENSLAVE_WAIT=1 +# Let the monitor run several times before checking the slaves. +MONITOR_WAIT=1 + +setup_prepare() +{ + setup_ns h_ns sw_ns + defer cleanup_ns "$h_ns" "$sw_ns" + + ip -n "$sw_ns" link add br0 type bridge + ip -n "$sw_ns" link set br0 up + ip -n "$sw_ns" addr add 192.0.2.254/24 dev br0 + + for i in 0 1; do + ip -n "$h_ns" link add "eth$i" type veth \ + peer name "sw$i" netns "$sw_ns" + ip -n "$sw_ns" link set "sw$i" master br0 + ip -n "$sw_ns" link set "sw$i" up + done +} + +bond_create() +{ + ip -n "$h_ns" link add bond0 type bond mode active-backup \ + primary eth0 primary_reselect failure \ + arp_ip_target 192.0.2.254 "$@" + defer ip -n "$h_ns" link del bond0 + ip -n "$h_ns" addr add 192.0.2.1/24 dev bond0 +} + +bond_enslave() +{ + ip -n "$h_ns" link set eth0 master bond0 + ip -n "$h_ns" link set eth1 master bond0 +} + +active_slave_get() +{ + ip -n "$h_ns" -d -j link show bond0 | \ + jq -r '.[].linkinfo.info_data.active_slave' +} + +link_failures_get() +{ + local dev=$1; shift + + ip -n "$h_ns" -d -j link show "$dev" | \ + jq '.[].linkinfo.info_slave_data.link_failure_count' +} + +active_slave_is() +{ + [[ $(active_slave_get) == "$1" ]] +} + +slaves_check() +{ + local dev + + slowwait 5 active_slave_is eth0 + check_err $? "eth0 did not become the active slave" + + sleep "$MONITOR_WAIT" + + active_slave_is eth0 + check_err $? "eth0 is no longer the active slave" + for dev in eth0 eth1; do + [[ $(link_failures_get "$dev") == 0 ]] + check_err $? "$dev went down when the ARP monitor started" + done +} + +arp_monitor_start_on_open() +{ + RET=0 + + bond_create arp_interval "$ARP_INTERVAL" arp_validate all + bond_enslave + sleep "$ENSLAVE_WAIT" + ip -n "$h_ns" link set bond0 up + + slaves_check + + log_test "ARP monitor started by bringing the bond up" +} + +arp_monitor_start_on_interval_set() +{ + RET=0 + + bond_create miimon 100 + ip -n "$h_ns" link set bond0 up + bond_enslave + slowwait 5 active_slave_is eth0 + check_err $? "eth0 did not become the active slave with miimon" + sleep "$ENSLAVE_WAIT" + # arp_validate cannot be set while miimon is in use. bond_changelink() + # sets arp_interval first, which turns miimon off. + ip -n "$h_ns" link set bond0 type bond arp_interval "$ARP_INTERVAL" \ + arp_validate all + check_err $? "Failed to switch to the ARP monitor" + + slaves_check + + log_test "ARP monitor started by setting arp_interval" +} + +trap cleanup EXIT + +setup_prepare +setup_wait + +tests_run + +exit "$EXIT_STATUS"
-- 2.56.1