netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] bonding: fix multicast MAC address synchronization
@ 2025-05-23  2:23 Hangbin Liu
  2025-05-23 21:03 ` Jay Vosburgh
  0 siblings, 1 reply; 5+ messages in thread
From: Hangbin Liu @ 2025-05-23  2:23 UTC (permalink / raw)
  To: netdev
  Cc: Jay Vosburgh, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Nikolay Aleksandrov, Simon Horman,
	linux-kernel, Hangbin Liu, Liang Li

There is a corner case where the NS (Neighbor Solicitation) target is set to
an invalid or unreachable address. In such cases, all the slave links are
marked as down and set to backup. This causes the bond to add multicast MAC
addresses to all slaves.

However, bond_ab_arp_probe() later tries to activate a carrier on slave and
sets it as active. If we subsequently change or clear the NS targets, the
call to bond_slave_ns_maddrs_del() on this interface will fail because it
is still marked active, and the multicast MAC address will remain.

To fix this issue, move the NS multicast address add/remove logic into
bond_set_slave_state() to ensure multicast MAC addresses are updated
synchronously whenever the slave state changes.

Note: The call to bond_slave_ns_maddrs_del() in __bond_release_one() is
kept, as it is still required to clean up multicast MAC addresses when
a slave is removed.

Fixes: 8eb36164d1a6 ("bonding: add ns target multicast address to slave device")
Reported-by: Liang Li <liali@redhat.com>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 drivers/net/bonding/bond_main.c | 9 ---------
 include/net/bonding.h           | 7 +++++++
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
index 8ea183da8d53..6dde6f870ee2 100644
--- a/drivers/net/bonding/bond_main.c
+++ b/drivers/net/bonding/bond_main.c
@@ -1004,8 +1004,6 @@ static void bond_hw_addr_swap(struct bonding *bond, struct slave *new_active,
 
 		if (bond->dev->flags & IFF_UP)
 			bond_hw_addr_flush(bond->dev, old_active->dev);
-
-		bond_slave_ns_maddrs_add(bond, old_active);
 	}
 
 	if (new_active) {
@@ -1022,8 +1020,6 @@ static void bond_hw_addr_swap(struct bonding *bond, struct slave *new_active,
 			dev_mc_sync(new_active->dev, bond->dev);
 			netif_addr_unlock_bh(bond->dev);
 		}
-
-		bond_slave_ns_maddrs_del(bond, new_active);
 	}
 }
 
@@ -2350,11 +2346,6 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
 	bond_compute_features(bond);
 	bond_set_carrier(bond);
 
-	/* Needs to be called before bond_select_active_slave(), which will
-	 * remove the maddrs if the slave is selected as active slave.
-	 */
-	bond_slave_ns_maddrs_add(bond, new_slave);
-
 	if (bond_uses_primary(bond)) {
 		block_netpoll_tx();
 		bond_select_active_slave(bond);
diff --git a/include/net/bonding.h b/include/net/bonding.h
index 95f67b308c19..0041f7a2bd18 100644
--- a/include/net/bonding.h
+++ b/include/net/bonding.h
@@ -385,7 +385,14 @@ static inline void bond_set_slave_state(struct slave *slave,
 	if (slave->backup == slave_state)
 		return;
 
+	if (slave_state == BOND_STATE_ACTIVE)
+		bond_slave_ns_maddrs_del(slave->bond, slave);
+
 	slave->backup = slave_state;
+
+	if (slave_state == BOND_STATE_BACKUP)
+		bond_slave_ns_maddrs_add(slave->bond, slave);
+
 	if (notify) {
 		bond_lower_state_changed(slave);
 		bond_queue_slave_event(slave);
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-07-03  6:26 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-23  2:23 [PATCH net] bonding: fix multicast MAC address synchronization Hangbin Liu
2025-05-23 21:03 ` Jay Vosburgh
2025-05-26  8:51   ` Hangbin Liu
2025-06-24  1:42     ` Hangbin Liu
2025-07-03  6:26     ` Hangbin Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).