mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ramses de Norre via B4 Relay <devnull+ramses.well-founded.dev@kernel.org>
To: Jay Vosburgh <jv@jvosburgh.net>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	 "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>, Jiri Bohac <jbohac@suse.cz>,
	 Eric Dumazet <edumazet@kernel.org>,
	Willem de Bruijn <willemb@google.com>,
	 Simon Horman <horms@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	 linux-kselftest@vger.kernel.org,
	Nikolay Aleksandrov <razor@blackwall.org>,
	 Hangbin Liu <hangbin.liu@linux.dev>,
	Shuah Khan <shuah@kernel.org>,
	 Ramses de Norre <ramses@well-founded.dev>
Subject: [PATCH net-next v2 2/2] selftests: bonding: test that the ARP monitor keeps UP slaves when it starts
Date: Thu, 03 Dec 2026 17:27:43 +0200	[thread overview]
Message-ID: <20261203-bonding-arp-reseed-v2-2-de49c2a3bb1e@well-founded.dev> (raw)
In-Reply-To: <20261203-bonding-arp-reseed-v2-0-de49c2a3bb1e@well-founded.dev>

From: Ramses de Norre <ramses@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 <ramses@well-founded.dev>
---
 .../testing/selftests/drivers/net/bonding/Makefile |   1 +
 .../drivers/net/bonding/bond_arp_monitor_start.sh  | 151 +++++++++++++++++++++
 2 files changed, 152 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..248d7279a3ced
--- /dev/null
+++ b/tools/testing/selftests/drivers/net/bonding/bond_arp_monitor_start.sh
@@ -0,0 +1,151 @@
+#!/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
+"
+lib_dir=$(dirname "$0")
+# shellcheck disable=SC1091
+source "$lib_dir"/../../../net/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"
+	# bond_changelink() rejects arp_validate and miimon in one request,
+	# so arp_validate is set here and not in bond_create.
+	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 defer_scopes_cleanup EXIT
+
+setup_prepare
+
+tests_run
+
+exit "$EXIT_STATUS"

-- 
2.56.1



      parent reply	other threads:[~2026-12-03 15:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03 15:27 [PATCH net-next v2 0/2] bonding: reseed the ARP monitor " Ramses de Norre via B4 Relay
2026-12-03 15:27 ` [PATCH net-next v2 1/2] " Ramses de Norre via B4 Relay
2026-12-04 16:19   ` netdev-bot+sashiko
2026-12-06 10:25     ` Ramses
2026-12-03 15:27 ` Ramses de Norre via B4 Relay [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261203-bonding-arp-reseed-v2-2-de49c2a3bb1e@well-founded.dev \
    --to=devnull+ramses.well-founded.dev@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hangbin.liu@linux.dev \
    --cc=horms@kernel.org \
    --cc=jbohac@suse.cz \
    --cc=jv@jvosburgh.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=ramses@well-founded.dev \
    --cc=razor@blackwall.org \
    --cc=shuah@kernel.org \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®