~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/testing/selftests/drivers/net/bonding/lag_lib.sh

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 
  4 NAMESPACES=""
  5 
  6 # Test that a link aggregation device (bonding, team) removes the hardware
  7 # addresses that it adds on its underlying devices.
  8 test_LAG_cleanup()
  9 {
 10         local driver=$1
 11         local mode=$2
 12         local ucaddr="02:00:00:12:34:56"
 13         local addr6="fe80::78:9abc/64"
 14         local mcaddr="33:33:ff:78:9a:bc"
 15         local name
 16 
 17         ip link add dummy1 type dummy
 18         ip link add dummy2 type dummy
 19         if [ "$driver" = "bonding" ]; then
 20                 name="bond1"
 21                 ip link add "$name" up type bond mode "$mode"
 22                 ip link set dev dummy1 master "$name"
 23                 ip link set dev dummy2 master "$name"
 24         elif [ "$driver" = "team" ]; then
 25                 name="team0"
 26                 teamd -d -c '
 27                         {
 28                                 "device": "'"$name"'",
 29                                 "runner": {
 30                                         "name": "'"$mode"'"
 31                                 },
 32                                 "ports": {
 33                                         "dummy1":
 34                                                 {},
 35                                         "dummy2":
 36                                                 {}
 37                                 }
 38                         }
 39                 '
 40                 ip link set dev "$name" up
 41         else
 42                 check_err 1
 43                 log_test test_LAG_cleanup ": unknown driver \"$driver\""
 44                 return
 45         fi
 46 
 47         # Used to test dev->uc handling
 48         ip link add mv0 link "$name" up address "$ucaddr" type macvlan
 49         # Used to test dev->mc handling
 50         ip address add "$addr6" dev "$name"
 51 
 52         # Check that addresses were added as expected
 53         (grep_bridge_fdb "$ucaddr" bridge fdb show dev dummy1 ||
 54                 grep_bridge_fdb "$ucaddr" bridge fdb show dev dummy2) >/dev/null
 55         check_err $? "macvlan unicast address not found on a slave"
 56 
 57         # mcaddr is added asynchronously by addrconf_dad_work(), use busywait
 58         (busywait 10000 grep_bridge_fdb "$mcaddr" bridge fdb show dev dummy1 ||
 59                 grep_bridge_fdb "$mcaddr" bridge fdb show dev dummy2) >/dev/null
 60         check_err $? "IPv6 solicited-node multicast mac address not found on a slave"
 61 
 62         ip link set dev "$name" down
 63         ip link del "$name"
 64 
 65         not grep_bridge_fdb "$ucaddr" bridge fdb show >/dev/null
 66         check_err $? "macvlan unicast address still present on a slave"
 67 
 68         not grep_bridge_fdb "$mcaddr" bridge fdb show >/dev/null
 69         check_err $? "IPv6 solicited-node multicast mac address still present on a slave"
 70 
 71         cleanup
 72 
 73         log_test "$driver cleanup mode $mode"
 74 }
 75 
 76 # Build a generic 2 node net namespace with 2 connections
 77 # between the namespaces
 78 #
 79 #  +-----------+       +-----------+
 80 #  | node1     |       | node2     |
 81 #  |           |       |           |
 82 #  |           |       |           |
 83 #  |      eth0 +-------+ eth0      |
 84 #  |           |       |           |
 85 #  |      eth1 +-------+ eth1      |
 86 #  |           |       |           |
 87 #  +-----------+       +-----------+
 88 lag_setup2x2()
 89 {
 90         local state=${1:-down}
 91         local namespaces="lag_node1 lag_node2"
 92 
 93         # create namespaces
 94         for n in ${namespaces}; do
 95                 ip netns add ${n}
 96         done
 97 
 98         # wire up namespaces
 99         ip link add name lag1 type veth peer name lag1-end
100         ip link set dev lag1 netns lag_node1 $state name eth0
101         ip link set dev lag1-end netns lag_node2 $state name eth0
102 
103         ip link add name lag1 type veth peer name lag1-end
104         ip link set dev lag1 netns lag_node1 $state name eth1
105         ip link set dev lag1-end netns lag_node2 $state name eth1
106 
107         NAMESPACES="${namespaces}"
108 }
109 
110 # cleanup all lag related namespaces
111 lag_cleanup()
112 {
113         for n in ${NAMESPACES}; do
114                 ip netns delete ${n} >/dev/null 2>&1 || true
115         done
116 }
117 
118 SWITCH="lag_node1"
119 CLIENT="lag_node2"
120 CLIENTIP="172.20.2.1"
121 SWITCHIP="172.20.2.2"
122 
123 lag_setup_network()
124 {
125         lag_setup2x2 "down"
126 
127         # create switch
128         ip netns exec ${SWITCH} ip link add br0 up type bridge
129         ip netns exec ${SWITCH} ip link set eth0 master br0 up
130         ip netns exec ${SWITCH} ip link set eth1 master br0 up
131         ip netns exec ${SWITCH} ip addr add ${SWITCHIP}/24 dev br0
132 }
133 
134 lag_reset_network()
135 {
136         ip netns exec ${CLIENT} ip link del bond0
137         ip netns exec ${SWITCH} ip link set eth0 up
138         ip netns exec ${SWITCH} ip link set eth1 up
139 }
140 
141 create_bond()
142 {
143         # create client
144         ip netns exec ${CLIENT} ip link set eth0 down
145         ip netns exec ${CLIENT} ip link set eth1 down
146 
147         ip netns exec ${CLIENT} ip link add bond0 type bond $@
148         ip netns exec ${CLIENT} ip link set eth0 master bond0
149         ip netns exec ${CLIENT} ip link set eth1 master bond0
150         ip netns exec ${CLIENT} ip link set bond0 up
151         ip netns exec ${CLIENT} ip addr add ${CLIENTIP}/24 dev bond0
152 }
153 
154 test_bond_recovery()
155 {
156         RET=0
157 
158         create_bond $@
159 
160         # verify connectivity
161         slowwait 2 ip netns exec ${CLIENT} ping ${SWITCHIP} -c 2 -W 0.1 &> /dev/null
162         check_err $? "No connectivity"
163 
164         # force the links of the bond down
165         ip netns exec ${SWITCH} ip link set eth0 down
166         sleep 2
167         ip netns exec ${SWITCH} ip link set eth0 up
168         ip netns exec ${SWITCH} ip link set eth1 down
169 
170         # re-verify connectivity
171         slowwait 2 ip netns exec ${CLIENT} ping ${SWITCHIP} -c 2 -W 0.1 &> /dev/null
172 
173         local rc=$?
174         check_err $rc "Bond failed to recover"
175         log_test "$1 ($2) bond recovery"
176         lag_reset_network
177 }

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php