Unsync addresses from ports when stopping aggregated devices
Subsystems (5)
v3 cover Unsync addresses from ports when stopping aggregated devices
This series fixes similar problems in the bonding and team drivers.
Because of missing dev_{uc,mc}_unsync() calls, addresses added to underlying devices may be leftover after the aggregated device is deleted. Add the missing calls and a few related tests.
v2:
* fix selftest installation, see patch 3
v3:
* Split lacpdu_multicast changes to their own patch, #1
* In ndo_{add,del}_slave methods, only perform address list changes when the aggregated device is up (patches 2 & 3)
* Add selftest function related to the above change (patch 4)
Benjamin Poirier (4):
net: bonding: Share lacpdu_mcast_addr definition
net: bonding: Unsync device addresses on ndo_stop
net: team: Unsync device addresses on ndo_stop
net: Add tests for bonding and team address list management
MAINTAINERS | 1 + drivers/net/bonding/bond_3ad.c | 5 +- drivers/net/bonding/bond_main.c | 57 +++++---- drivers/net/team/team.c | 24 +++- include/net/bond_3ad.h | 2 - include/net/bonding.h | 3 + tools/testing/selftests/Makefile | 1 + .../selftests/drivers/net/bonding/Makefile | 5 +- .../selftests/drivers/net/bonding/config | 1 + .../drivers/net/bonding/dev_addr_lists.sh | 109 ++++++++++++++++++ .../selftests/drivers/net/bonding/lag_lib.sh | 61 ++++++++++ .../selftests/drivers/net/team/Makefile | 6 + .../testing/selftests/drivers/net/team/config | 3 + .../drivers/net/team/dev_addr_lists.sh | 51 ++++++++ 14 files changed, 297 insertions(+), 32 deletions(-) create mode 100755 tools/testing/selftests/drivers/net/bonding/dev_addr_lists.sh create mode 100644 tools/testing/selftests/drivers/net/bonding/lag_lib.sh create mode 100644 tools/testing/selftests/drivers/net/team/Makefile create mode 100644 tools/testing/selftests/drivers/net/team/config create mode 100755 tools/testing/selftests/drivers/net/team/dev_addr_lists.sh
Signature · 1 line
2.37.2
PATCH v3 1/4 net: bonding: Share lacpdu_mcast_addr definition
There are already a few definitions of arrays containing MULTICAST_LACPDU_ADDR and the next patch will add one more use. These all contain the same constant data so define one common instance for all bonding code.
--- drivers/net/bonding/bond_3ad.c | 5 +++-- drivers/net/bonding/bond_main.c | 16 ++++------------ include/net/bond_3ad.h | 2 -- include/net/bonding.h | 3 +++ 4 files changed, 10 insertions(+), 16 deletions(-)
drivers/net/bonding/bond_3ad.c +3 -2
@@ -88,8 +88,9 @@ static const u8 null_mac_addr[ETH_ALEN + 2] __long_aligned = {static const u16 ad_ticks_per_sec =1000 /AD_TIMER_INTERVAL ;static const int ad_delta_in_ticks = (AD_TIMER_INTERVAL *HZ ) /1000 ; -static const u8 lacpdu_mcast_addr[ETH_ALEN + 2] __long_aligned = -MULTICAST_LACPDU_ADDR ; +const u8 lacpdu_mcast_addr[ETH_ALEN + 2] __long_aligned = { +0x01 ,0x80 ,0xC2 ,0x00 ,0x00 ,0x02 +};/* ================= main 802.3ad protocol functions ================== */ static int ad_lacpdu_send (struct port *port);
drivers/net/bonding/bond_main.c +4 -12
@@ -865,12 +865,8 @@ static void bond_hw_addr_flush(struct net_device *bond_dev,dev_uc_unsync (slave_dev, bond_dev);dev_mc_unsync (slave_dev, bond_dev); -if (BOND_MODE (bond) ==BOND_MODE_8023AD ) { -/* del lacpdu mc addr from mc list */ -u8 lacpdu_multicast[ETH_ALEN ] =MULTICAST_LACPDU_ADDR ; - -dev_mc_del (slave_dev, lacpdu_multicast); - } +if (BOND_MODE (bond) ==BOND_MODE_8023AD ) +dev_mc_del (slave_dev, lacpdu_mcast_addr); }/*--------------------------- Active slave change ---------------------------*/
@@ -2171,12 +2167,8 @@ int bond_enslave(struct net_device *bond_dev, struct net_device *slave_dev,dev_uc_sync_multiple (slave_dev, bond_dev);netif_addr_unlock_bh (bond_dev); -if (BOND_MODE (bond) ==BOND_MODE_8023AD ) { -/* add lacpdu mc addr to mc list */ -u8 lacpdu_multicast[ETH_ALEN ] =MULTICAST_LACPDU_ADDR ; - -dev_mc_add (slave_dev, lacpdu_multicast); - } +if (BOND_MODE (bond) ==BOND_MODE_8023AD ) +dev_mc_add (slave_dev, lacpdu_mcast_addr); } bond->slave_cnt++;
include/net/bond_3ad.h +0 -2
@@ -15,8 +15,6 @@#define PKT_TYPE_LACPDU cpu_to_be16(ETH_P_SLOW)#define AD_TIMER_INTERVAL 100/*msec*/ -#define MULTICAST_LACPDU_ADDR {0x01, 0x80, 0xC2, 0x00, 0x00, 0x02} -#define AD_LACP_SLOW 0#define AD_LACP_FAST 1
include/net/bonding.h +3 -0
@@ -786,6 +786,9 @@ extern struct rtnl_link_ops bond_link_ops;/* exported from bond_sysfs_slave.c */ extern const struct sysfs_ops slave_sysfs_ops; +/* exported from bond_3ad.c */ +extern const u8 lacpdu_mcast_addr[]; +static inline netdev_tx_t bond_tx_drop (struct net_device *dev,struct sk_buff *skb) {dev_core_stats_tx_dropped_inc (dev);
Signature · 1 line
2.37.2
PATCH v3 2/4 net: bonding: Unsync device addresses on ndo_stop
In reply to Benjamin PoirierNetdev 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.
--- drivers/net/bonding/bond_main.c | 47 ++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 12 deletions(-)
drivers/net/bonding/bond_main.c +35 -12
@@ -886,7 +886,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) {
@@ -897,10 +898,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); + } } }
@@ -2162,13 +2165,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++;
@@ -2439,7 +2444,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);
@@ -4213,6 +4219,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))
@@ -4224,6 +4233,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 ;
@@ -4231,6 +4241,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 ; }
Signature · 1 line
2.37.2
PATCH v3 3/4 net: team: Unsync device addresses on ndo_stop
In reply to Benjamin PoirierNetdev 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 team 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 team ports after a team device has been deleted; see test_LAG_cleanup() in the last patch in this series.
Add unsync calls at their expected location, team_close().
v3:
* When adding or deleting a port, only sync/unsync addresses if the team device is up. In other cases, it is taken care of at the right time by ndo_open/ndo_set_rx_mode/ndo_stop.
--- drivers/net/team/team.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-)
drivers/net/team/team.c +18 -6
@@ -1275,10 +1275,12 @@ static int team_port_add(struct team *team, struct net_device *port_dev, } } -netif_addr_lock_bh (dev); -dev_uc_sync_multiple (port_dev, dev); -dev_mc_sync_multiple (port_dev, dev); -netif_addr_unlock_bh (dev); +if (dev->flags &IFF_UP ) { +netif_addr_lock_bh (dev); +dev_uc_sync_multiple (port_dev, dev); +dev_mc_sync_multiple (port_dev, dev); +netif_addr_unlock_bh (dev); + } port->index =-1 ;list_add_tail_rcu (&port->list, &team->port_list);
@@ -1349,8 +1351,10 @@ static int team_port_del(struct team *team, struct net_device *port_dev)netdev_rx_handler_unregister (port_dev);team_port_disable_netpoll (port);vlan_vids_del_by_dev (port_dev, dev); -dev_uc_unsync (port_dev, dev); -dev_mc_unsync (port_dev, dev); +if (dev->flags &IFF_UP ) { +dev_uc_unsync (port_dev, dev); +dev_mc_unsync (port_dev, dev); + }dev_close (port_dev);team_port_leave (team, port);
@@ -1700,6 +1704,14 @@ static int team_open(struct net_device *dev)static int team_close (struct net_device *dev) { +struct team *team =netdev_priv (dev); +struct team_port *port; + +list_for_each_entry (port, &team->port_list, list) { +dev_uc_unsync (port->dev, dev); +dev_mc_unsync (port->dev, dev); + } +return 0 ; }
Signature · 1 line
2.37.2
PATCH v3 4/4 net: Add tests for bonding and team address list management
In reply to Benjamin PoirierTest that the bonding and team drivers clean up an underlying device's address lists (dev->uc, dev->mc) when the aggregated device is deleted.
Test addition and removal of the LACPDU multicast address on underlying devices by the bonding driver.
v2:
* add lag_lib.sh to TEST_FILES
v3:
* extend bond_listen_lacpdu_multicast test to init_state up and down cases
* remove some superfluous shell syntax and 'set dev ... up' commands
--- MAINTAINERS | 1 + tools/testing/selftests/Makefile | 1 + .../selftests/drivers/net/bonding/Makefile | 5 +- .../selftests/drivers/net/bonding/config | 1 + .../drivers/net/bonding/dev_addr_lists.sh | 109 ++++++++++++++++++ .../selftests/drivers/net/bonding/lag_lib.sh | 61 ++++++++++ .../selftests/drivers/net/team/Makefile | 6 + .../testing/selftests/drivers/net/team/config | 3 + .../drivers/net/team/dev_addr_lists.sh | 51 ++++++++ 9 files changed, 237 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/drivers/net/bonding/dev_addr_lists.sh create mode 100644 tools/testing/selftests/drivers/net/bonding/lag_lib.sh create mode 100644 tools/testing/selftests/drivers/net/team/Makefile create mode 100644 tools/testing/selftests/drivers/net/team/config create mode 100755 tools/testing/selftests/drivers/net/team/dev_addr_lists.sh
MAINTAINERS +1 -0
@@ -19937,6 +19937,7 @@ S: Supported F: drivers/net/team/ F: include/linux/if_team.h F: include/uapi/linux/if_team.h +F: tools/testing/selftests/net/team/ TECHNOLOGIC SYSTEMS TS-5500 PLATFORM SUPPORT M: "Savoir-faire Linux Inc." <[email protected]>
tools/testing/selftests/Makefile +1 -0
@@ -13,6 +13,7 @@ TARGETS += damon TARGETS += drivers/dma-buf TARGETS += drivers/s390x/uvdevice TARGETS += drivers/net/bonding +TARGETS += drivers/net/team TARGETS += efivarfs TARGETS += exec TARGETS += filesystems
tools/testing/selftests/drivers/net/bonding/Makefile +4 -1
@@ -1,6 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 # Makefile for net selftests -TEST_PROGS := bond-break-lacpdu-tx.sh +TEST_PROGS := bond-break-lacpdu-tx.sh \ + dev_addr_lists.sh + +TEST_FILES := lag_lib.sh include ../../../lib.mk
tools/testing/selftests/drivers/net/bonding/config +1 -0
@@ -1 +1,2 @@ CONFIG_BONDING=y +CONFIG_MACVLAN=y
tools/testing/selftests/drivers/net/bonding/dev_addr_lists.sh new file +109 -0
109 lines not on this page · raw message
tools/testing/selftests/drivers/net/bonding/lag_lib.sh new file +61 -0
61 lines not on this page · raw message
tools/testing/selftests/drivers/net/team/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +# Makefile for net selftests + +TEST_PROGS := dev_addr_lists.sh + +include ../../../lib.mk
tools/testing/selftests/drivers/net/team/config new file +3 -0
@@ -0,0 +1,3 @@ +CONFIG_NET_TEAM=y +CONFIG_NET_TEAM_MODE_LOADBALANCE=y +CONFIG_MACVLAN=y
tools/testing/selftests/drivers/net/team/dev_addr_lists.sh new file +51 -0
51 lines not on this page · raw message
Signature · 1 line
2.37.2
Quoted 5 lines · Benjamin Poirier
This series fixes similar problems in the bonding and team drivers.
Because of missing dev_{uc,mc}_unsync() calls, addresses added to underlying devices may be leftover after the aggregated device is deleted. Add the missing calls and a few related tests.
I'm not seeing any gaps in the logic; so, for the bonding parts
of the series
-J
Quoted 30 lines
v2:
* fix selftest installation, see patch 3v3:
* Splitlacpdu_multicastchanges to their own patch, #1
* In ndo_{add,del}_slave methods, only perform address list changes when the aggregated device is up (patches 2 & 3)
* Add selftest function related to the above change (patch 4)Benjamin Poirier (4):
net: bonding: Sharelacpdu_mcast_addrdefinition
net: bonding: Unsync device addresses onndo_stop
net: team: Unsync device addresses onndo_stop
net: Add tests for bonding and team address list managementMAINTAINERS | 1 + drivers/net/bonding/bond_3ad.c | 5 +- drivers/net/bonding/bond_main.c | 57 +++++---- drivers/net/team/team.c | 24 +++- include/net/bond_3ad.h | 2 - include/net/bonding.h | 3 + tools/testing/selftests/Makefile | 1 + .../selftests/drivers/net/bonding/Makefile | 5 +- .../selftests/drivers/net/bonding/config | 1 + .../drivers/net/bonding/dev_addr_lists.sh | 109 ++++++++++++++++++ .../selftests/drivers/net/bonding/lag_lib.sh | 61 ++++++++++ .../selftests/drivers/net/team/Makefile | 6 + .../testing/selftests/drivers/net/team/config | 3 + .../drivers/net/team/dev_addr_lists.sh | 51 ++++++++ 14 files changed, 297 insertions(+), 32 deletions(-)
Quoted 9 lines
create mode 100755
tools/testing/selftests/drivers/net/bonding/dev_addr_lists.shcreate mode 100644tools/testing/selftests/drivers/net/bonding/lag_lib.shcreate mode 100644tools/testing/selftests/drivers/net/team/Makefilecreate mode 100644tools/testing/selftests/drivers/net/team/configcreate mode 100755tools/testing/selftests/drivers/net/team/dev_addr_lists.shSignature · 1 line
2.37.2
---
-Jay Vosburgh, [email protected]
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:
Hello:
This series was applied to netdev/net.git (master) by David S. Miller <[email protected]>:
Quoted 10 lines · On Wed, 7 Sep 2022 16:56:38 +0900 you wrote:
This series fixes similar problems in the bonding and team drivers.
Because of missing dev_{uc,mc}_unsync() calls, addresses added to underlying devices may be leftover after the aggregated device is deleted. Add the missing calls and a few related tests.
v2:
* fix selftest installation, see patch 3[...]
Here is the summary with links:
- [net,v3,1/4] net: bonding: Share lacpdu_mcast_addr definition
https://git.kernel.org/netdev/net/c/1d9a143ee340 - [net,v3,2/4] net: bonding: Unsync device addresses on ndo_stop https://git.kernel.org/netdev/net/c/86247aba599e - [net,v3,3/4] net: team: Unsync device addresses on ndo_stop https://git.kernel.org/netdev/net/c/bd60234222b2 - [net,v3,4/4] net: Add tests for bonding and team address list management https://git.kernel.org/netdev/net/c/bbb774d921e2
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html