]> git.itanic.dy.fi Git - linux-stable/commitdiff
net: bonding: Unsync device addresses on ndo_stop
authorBenjamin Poirier <bpoirier@nvidia.com>
Wed, 7 Sep 2022 07:56:40 +0000 (16:56 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 28 Sep 2022 09:10:31 +0000 (11:10 +0200)
[ Upstream commit 86247aba599e5b07d7e828e6edaaebb0ef2b1158 ]

Netdev drivers are expected to call dev_{uc,mc}_sync() in their
ndo_set_rx_mode method and dev_{uc,mc}_unsync() in their ndo_stop method.
This is mentioned in the kerneldoc for those dev_* functions.

The bonding driver calls dev_{uc,mc}_unsync() during ndo_uninit instead of
ndo_stop. This is ineffective because address lists (dev->{uc,mc}) have
already been emptied in unregister_netdevice_many() before ndo_uninit is
called. This mistake can result in addresses being leftover on former bond
slaves after a bond has been deleted; see test_LAG_cleanup() in the last
patch in this series.

Add unsync calls, via bond_hw_addr_flush(), at their expected location,
bond_close().
Add dev_mc_add() call to bond_open() to match the above change.

v3:
* When adding or deleting a slave, only sync/unsync, add/del addresses if
  the bond is up. In other cases, it is taken care of at the right time by
  ndo_open/ndo_set_rx_mode/ndo_stop.

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Benjamin Poirier <bpoirier@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/net/bonding/bond_main.c

index be1fd4ef45313beb5af0b38aa5b44b3da96c4190..f38a6ce5749bb49f7e3a01d8d3628ca625ad82bc 100644 (file)
@@ -848,7 +848,8 @@ static void bond_hw_addr_swap(struct bonding *bond, struct slave *new_active,
                if (bond->dev->flags & IFF_ALLMULTI)
                        dev_set_allmulti(old_active->dev, -1);
 
-               bond_hw_addr_flush(bond->dev, old_active->dev);
+               if (bond->dev->flags & IFF_UP)
+                       bond_hw_addr_flush(bond->dev, old_active->dev);
        }
 
        if (new_active) {
@@ -859,10 +860,12 @@ static void bond_hw_addr_swap(struct bonding *bond, struct slave *new_active,
                if (bond->dev->flags & IFF_ALLMULTI)
                        dev_set_allmulti(new_active->dev, 1);
 
-               netif_addr_lock_bh(bond->dev);
-               dev_uc_sync(new_active->dev, bond->dev);
-               dev_mc_sync(new_active->dev, bond->dev);
-               netif_addr_unlock_bh(bond->dev);
+               if (bond->dev->flags & IFF_UP) {
+                       netif_addr_lock_bh(bond->dev);
+                       dev_uc_sync(new_active->dev, bond->dev);
+                       dev_mc_sync(new_active->dev, bond->dev);
+                       netif_addr_unlock_bh(bond->dev);
+               }
        }
 }
 
@@ -2069,13 +2072,15 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,
                        }
                }
 
-               netif_addr_lock_bh(bond_dev);
-               dev_mc_sync_multiple(slave_dev, bond_dev);
-               dev_uc_sync_multiple(slave_dev, bond_dev);
-               netif_addr_unlock_bh(bond_dev);
+               if (bond_dev->flags & IFF_UP) {
+                       netif_addr_lock_bh(bond_dev);
+                       dev_mc_sync_multiple(slave_dev, bond_dev);
+                       dev_uc_sync_multiple(slave_dev, bond_dev);
+                       netif_addr_unlock_bh(bond_dev);
 
-               if (BOND_MODE(bond) == BOND_MODE_8023AD)
-                       dev_mc_add(slave_dev, lacpdu_mcast_addr);
+                       if (BOND_MODE(bond) == BOND_MODE_8023AD)
+                               dev_mc_add(slave_dev, lacpdu_mcast_addr);
+               }
        }
 
        bond->slave_cnt++;
@@ -2302,7 +2307,8 @@ static int __bond_release_one(struct net_device *bond_dev,
                if (old_flags & IFF_ALLMULTI)
                        dev_set_allmulti(slave_dev, -1);
 
-               bond_hw_addr_flush(bond_dev, slave_dev);
+               if (old_flags & IFF_UP)
+                       bond_hw_addr_flush(bond_dev, slave_dev);
        }
 
        slave_disable_netpoll(slave);
@@ -3764,6 +3770,9 @@ static int bond_open(struct net_device *bond_dev)
                /* register to receive LACPDUs */
                bond->recv_probe = bond_3ad_lacpdu_recv;
                bond_3ad_initiate_agg_selection(bond, 1);
+
+               bond_for_each_slave(bond, slave, iter)
+                       dev_mc_add(slave->dev, lacpdu_mcast_addr);
        }
 
        if (bond_mode_can_use_xmit_hash(bond))
@@ -3775,6 +3784,7 @@ static int bond_open(struct net_device *bond_dev)
 static int bond_close(struct net_device *bond_dev)
 {
        struct bonding *bond = netdev_priv(bond_dev);
+       struct slave *slave;
 
        bond_work_cancel_all(bond);
        bond->send_peer_notif = 0;
@@ -3782,6 +3792,19 @@ static int bond_close(struct net_device *bond_dev)
                bond_alb_deinitialize(bond);
        bond->recv_probe = NULL;
 
+       if (bond_uses_primary(bond)) {
+               rcu_read_lock();
+               slave = rcu_dereference(bond->curr_active_slave);
+               if (slave)
+                       bond_hw_addr_flush(bond_dev, slave->dev);
+               rcu_read_unlock();
+       } else {
+               struct list_head *iter;
+
+               bond_for_each_slave(bond, slave, iter)
+                       bond_hw_addr_flush(bond_dev, slave->dev);
+       }
+
        return 0;
 }