Skip to content

Commit 222c94e

Browse files
NikAleksandrovdavem330
authored andcommitted
selftests: bonding: add tests for ether type changes
Add new network selftests for the bonding device which exercise the ether type changing call paths. They also test for the recent syzbot bug[1] which causes a warning and results in wrong device flags (IFF_SLAVE missing). The test adds three bond devices and a nlmon device, enslaves one of the bond devices to the other and then uses the nlmon device for successful and unsuccesful enslaves both of which change the bond ether type. Thus we can test for both MASTER and SLAVE flags at the same time. If the flags are properly restored we get: TEST: Change ether type of an enslaved bond device with unsuccessful enslave [ OK ] TEST: Change ether type of an enslaved bond device with successful enslave [ OK ] [1] https://syzkaller.appspot.com/bug?id=391c7b1f6522182899efba27d891f1743e8eb3ef Signed-off-by: Nikolay Aleksandrov <razor@blackwall.org> Reviewed-by: Michal Kubiak <michal.kubiak@intel.com> Acked-by: Jonathan Toppins <jtoppins@redhat.com> Acked-by: Jay Vosburgh <jay.vosburgh@canonical.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e667d46 commit 222c94e

File tree

2 files changed

+87
-1
lines changed

2 files changed

+87
-1
lines changed

tools/testing/selftests/drivers/net/bonding/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ TEST_PROGS := \
88
dev_addr_lists.sh \
99
mode-1-recovery-updelay.sh \
1010
mode-2-recovery-updelay.sh \
11-
option_prio.sh
11+
option_prio.sh \
12+
bond-eth-type-change.sh
1213

1314
TEST_FILES := \
1415
lag_lib.sh \
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# Test bond device ether type changing
5+
#
6+
7+
ALL_TESTS="
8+
bond_test_unsuccessful_enslave_type_change
9+
bond_test_successful_enslave_type_change
10+
"
11+
REQUIRE_MZ=no
12+
NUM_NETIFS=0
13+
lib_dir=$(dirname "$0")
14+
source "$lib_dir"/net_forwarding_lib.sh
15+
16+
bond_check_flags()
17+
{
18+
local bonddev=$1
19+
20+
ip -d l sh dev "$bonddev" | grep -q "MASTER"
21+
check_err $? "MASTER flag is missing from the bond device"
22+
23+
ip -d l sh dev "$bonddev" | grep -q "SLAVE"
24+
check_err $? "SLAVE flag is missing from the bond device"
25+
}
26+
27+
# test enslaved bond dev type change from ARPHRD_ETHER and back
28+
# this allows us to test both MASTER and SLAVE flags at once
29+
bond_test_enslave_type_change()
30+
{
31+
local test_success=$1
32+
local devbond0="test-bond0"
33+
local devbond1="test-bond1"
34+
local devbond2="test-bond2"
35+
local nonethdev="test-noneth0"
36+
37+
# create a non-ARPHRD_ETHER device for testing (e.g. nlmon type)
38+
ip link add name "$nonethdev" type nlmon
39+
check_err $? "could not create a non-ARPHRD_ETHER device (nlmon)"
40+
ip link add name "$devbond0" type bond
41+
if [ $test_success -eq 1 ]; then
42+
# we need devbond0 in active-backup mode to successfully enslave nonethdev
43+
ip link set dev "$devbond0" type bond mode active-backup
44+
check_err $? "could not change bond mode to active-backup"
45+
fi
46+
ip link add name "$devbond1" type bond
47+
ip link add name "$devbond2" type bond
48+
ip link set dev "$devbond0" master "$devbond1"
49+
check_err $? "could not enslave $devbond0 to $devbond1"
50+
# change bond type to non-ARPHRD_ETHER
51+
ip link set dev "$nonethdev" master "$devbond0" 1>/dev/null 2>/dev/null
52+
ip link set dev "$nonethdev" nomaster 1>/dev/null 2>/dev/null
53+
# restore ARPHRD_ETHER type by enslaving such device
54+
ip link set dev "$devbond2" master "$devbond0"
55+
check_err $? "could not enslave $devbond2 to $devbond0"
56+
ip link set dev "$devbond1" nomaster
57+
58+
bond_check_flags "$devbond0"
59+
60+
# clean up
61+
ip link del dev "$devbond0"
62+
ip link del dev "$devbond1"
63+
ip link del dev "$devbond2"
64+
ip link del dev "$nonethdev"
65+
}
66+
67+
bond_test_unsuccessful_enslave_type_change()
68+
{
69+
RET=0
70+
71+
bond_test_enslave_type_change 0
72+
log_test "Change ether type of an enslaved bond device with unsuccessful enslave"
73+
}
74+
75+
bond_test_successful_enslave_type_change()
76+
{
77+
RET=0
78+
79+
bond_test_enslave_type_change 1
80+
log_test "Change ether type of an enslaved bond device with successful enslave"
81+
}
82+
83+
tests_run
84+
85+
exit "$EXIT_STATUS"

0 commit comments

Comments
 (0)