[PATCH net-next v3 1/2] bonding: reseed the ARP monitor when it starts

From: Ramses de Norre via B4 Relay

Date: Sun Dec 06 2026 - 05:24:45 EST


From: Ramses de Norre <ramses@xxxxxxxxxxxxxxxx>

The ARP monitor timestamps are seeded at enslave time. When the monitor
starts later, on bond up or when arp_interval replaces miimon, those
seeds can be arbitrarily old. The first monitor run then takes the UP
slaves down before a single probe went out. With
primary_reselect=failure the bond can stay on the backup.

systemd-networkd hits this with ActivationPolicy=manual.

Reseed the slaves when the monitor starts. Only a slave that is UP and
running gets fresh timestamps. The timestamps of the others only move
back, so an active slave that is not UP cannot look like it got a reply.

Link: https://lore.kernel.org/netdev/20261030-bonding-last-rx-v5-0-0b9b653f2f94@xxxxxxxxxxxxxxxx/
Signed-off-by: Ramses de Norre <ramses@xxxxxxxxxxxxxxxx>
Reviewed-by: Hangbin Liu <liuhangbin@xxxxxxxxxx>
---
drivers/net/bonding/bond_main.c | 83 ++++++++++++++++++++++++++++----------
drivers/net/bonding/bond_options.c | 6 ++-
include/net/bonding.h | 1 +
3 files changed, 68 insertions(+), 22 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 754048ef4835d..4c1605f60ea9f 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1888,6 +1888,65 @@ void bond_xdp_set_features(struct net_device *bond_dev)
xdp_set_features_flag(bond_dev, val);
}

+/* Too old for the up test in the ARP monitors. */
+static unsigned long bond_arp_down_seed(struct bonding *bond)
+{
+ return jiffies - (2 * msecs_to_jiffies(bond->params.arp_interval) + 1);
+}
+
+/* Keep a slave that is not UP down until it receives traffic. Give a slave
+ * that is UP a full arp_missed_max window.
+ */
+static void bond_arp_seed_slave(struct bonding *bond, struct slave *slave)
+{
+ unsigned long seed;
+ int i;
+
+ if (slave->link == BOND_LINK_UP) {
+ slave->last_link_up = jiffies;
+ seed = slave->last_link_up;
+ } else {
+ seed = bond_arp_down_seed(bond);
+ }
+
+ WRITE_ONCE(slave->last_rx, seed);
+ for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
+ WRITE_ONCE(slave->target_last_arp_rx[i], seed);
+ WRITE_ONCE(slave->last_tx, seed);
+}
+
+static void bond_arp_age(unsigned long *ts, unsigned long seed)
+{
+ if (time_after(READ_ONCE(*ts), seed))
+ WRITE_ONCE(*ts, seed);
+}
+
+/* Only a slave that is UP and running gets a fresh seed. The timestamps of
+ * the others only move back, see bond_arp_rcv(). recv_probe may already be
+ * set, a racing receive is harmless.
+ */
+void bond_arp_reseed_slaves(struct bonding *bond)
+{
+ unsigned long seed = bond_arp_down_seed(bond);
+ struct list_head *iter;
+ struct slave *slave;
+ int i;
+
+ ASSERT_RTNL();
+
+ bond_for_each_slave(bond, slave, iter) {
+ if (slave->link == BOND_LINK_UP && bond_slave_is_up(slave)) {
+ bond_arp_seed_slave(bond, slave);
+ continue;
+ }
+
+ bond_arp_age(&slave->last_rx, seed);
+ for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
+ bond_arp_age(&slave->target_last_arp_rx[i], seed);
+ bond_arp_age(&slave->last_tx, seed);
+ }
+}
+
/* enslave device <slave> to bond device <master> */
int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
struct netlink_ext_ack *extack)
@@ -1896,7 +1955,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
const struct net_device_ops *slave_ops = slave_dev->netdev_ops;
struct slave *new_slave = NULL, *prev_slave;
struct sockaddr_storage ss;
- int res = 0, i;
+ int res = 0;

if (slave_dev->type == ARPHRD_CAN ||
slave_dev->type == ARPHRD_IEEE802154 ||
@@ -2158,26 +2217,7 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
BOND_SLAVE_NOTIFY_NOW);
}

- /* The ARP monitor's up test includes arp_interval/2 of slack, see
- * bond_time_in_interval(). Seed a slave that starts DOWN outside
- * that window, so it stays DOWN until it receives traffic.
- */
- if (new_slave->link == BOND_LINK_DOWN) {
- new_slave->last_rx = jiffies -
- (2 * msecs_to_jiffies(bond->params.arp_interval) + 1);
- } else {
- /* Give a slave that starts UP a full arp_missed_max window.
- * Not seeding it later than last_link_up keeps bond_arp_rcv()
- * from trusting ARPs on backup slaves before the active one
- * got a reply.
- */
- new_slave->last_link_up = jiffies;
- new_slave->last_rx = new_slave->last_link_up;
- }
- for (i = 0; i < BOND_MAX_ARP_TARGETS; i++)
- new_slave->target_last_arp_rx[i] = new_slave->last_rx;
-
- new_slave->last_tx = new_slave->last_rx;
+ bond_arp_seed_slave(bond, new_slave);

slave_dbg(bond_dev, slave_dev, "Initial state of slave is BOND_LINK_%s\n",
new_slave->link == BOND_LINK_DOWN ? "DOWN" :
@@ -4415,6 +4455,7 @@ static int bond_open(struct net_device *bond_dev)
queue_delayed_work(bond->wq, &bond->mii_work, 0);

if (bond->params.arp_interval) { /* arp interval, in milliseconds. */
+ bond_arp_reseed_slaves(bond);
queue_delayed_work(bond->wq, &bond->arp_work, 0);
WRITE_ONCE(bond->recv_probe, bond_rcv_validate);
}
diff --git a/drivers/net/bonding/bond_options.c b/drivers/net/bonding/bond_options.c
index 9efadeff6a223..1f40adc0b7fb1 100644
--- a/drivers/net/bonding/bond_options.c
+++ b/drivers/net/bonding/bond_options.c
@@ -1128,6 +1128,8 @@ static int bond_option_use_carrier_set(struct bonding *bond,
static int bond_option_arp_interval_set(struct bonding *bond,
const struct bond_opt_value *newval)
{
+ bool start = !bond->params.arp_interval && newval->value;
+
netdev_dbg(bond->dev, "Setting ARP monitoring interval to %llu\n",
newval->value);
WRITE_ONCE(bond->params.arp_interval, newval->value);
@@ -1150,9 +1152,11 @@ static int bond_option_arp_interval_set(struct bonding *bond,
WRITE_ONCE(bond->recv_probe, NULL);
cancel_delayed_work_sync(&bond->arp_work);
} else {
+ cancel_delayed_work_sync(&bond->mii_work);
+ if (start)
+ bond_arp_reseed_slaves(bond);
/* arp_validate can be set only in active-backup mode */
WRITE_ONCE(bond->recv_probe, bond_rcv_validate);
- cancel_delayed_work_sync(&bond->mii_work);
queue_delayed_work(bond->wq, &bond->arp_work, 0);
}
}
diff --git a/include/net/bonding.h b/include/net/bonding.h
index 5980df71a358e..fbd49a52b7378 100644
--- a/include/net/bonding.h
+++ b/include/net/bonding.h
@@ -708,6 +708,7 @@ int bond_release(struct net_device *bond_dev, struct net_device *slave_dev);
u32 bond_xmit_hash(struct bonding *bond, struct sk_buff *skb);
int bond_set_carrier(struct bonding *bond);
void bond_select_active_slave(struct bonding *bond);
+void bond_arp_reseed_slaves(struct bonding *bond);
void bond_change_active_slave(struct bonding *bond, struct slave *new_active);
void bond_create_debugfs(void);
void bond_destroy_debugfs(void);

--
2.56.1