Skip to content

Commit 2f15cac

Browse files
author
Hangbin Liu
committed
selftests: bonding: add test for passive LACP mode
JIRA: https://issues.redhat.com/browse/RHEL-100461 Upstream Status: net.git commit 87951b5 commit 87951b5 Author: Hangbin Liu <liuhangbin@gmail.com> Date: Fri Aug 15 06:20:00 2025 +0000 selftests: bonding: add test for passive LACP mode Add a selftest to verify bonding behavior when `lacp_active` is set to `off`. The test checks the following: - The passive LACP bond should not send LACPDUs before receiving a partner's LACPDU. - The transmitted LACPDUs must not include the active flag. - After transitioning to EXPIRED and DEFAULTED states, the passive side should still not initiate LACPDUs. Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> Link: https://patch.msgid.link/20250815062000.22220-4-liuhangbin@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Hangbin Liu <haliu@redhat.com>
1 parent 74479c7 commit 2f15cac

File tree

3 files changed

+108
-1
lines changed

3 files changed

+108
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ TEST_PROGS := \
1010
mode-2-recovery-updelay.sh \
1111
bond_options.sh \
1212
bond-eth-type-change.sh \
13-
bond_macvlan_ipvlan.sh
13+
bond_macvlan_ipvlan.sh \
14+
bond_passive_lacp.sh
1415

1516
TEST_FILES := \
1617
lag_lib.sh \
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
#
4+
# Test if a bond interface works with lacp_active=off.
5+
6+
# shellcheck disable=SC2034
7+
REQUIRE_MZ=no
8+
NUM_NETIFS=0
9+
lib_dir=$(dirname "$0")
10+
# shellcheck disable=SC1091
11+
source "$lib_dir"/../../../net/forwarding/lib.sh
12+
13+
# shellcheck disable=SC2317
14+
check_port_state()
15+
{
16+
local netns=$1
17+
local port=$2
18+
local state=$3
19+
20+
ip -n "${netns}" -d -j link show "$port" | \
21+
jq -e ".[].linkinfo.info_slave_data.ad_actor_oper_port_state_str | index(\"${state}\") != null" > /dev/null
22+
}
23+
24+
check_pkt_count()
25+
{
26+
RET=0
27+
local ns="$1"
28+
local iface="$2"
29+
30+
# wait 65s, one per 30s
31+
slowwait_for_counter 65 2 tc_rule_handle_stats_get \
32+
"dev ${iface} egress" 101 ".packets" "-n ${ns}" &> /dev/null
33+
}
34+
35+
setup() {
36+
setup_ns c_ns s_ns
37+
38+
# shellcheck disable=SC2154
39+
ip -n "${c_ns}" link add eth0 type veth peer name eth0 netns "${s_ns}"
40+
ip -n "${c_ns}" link add eth1 type veth peer name eth1 netns "${s_ns}"
41+
42+
# Add tc filter to count the pkts
43+
tc -n "${c_ns}" qdisc add dev eth0 clsact
44+
tc -n "${c_ns}" filter add dev eth0 egress handle 101 protocol 0x8809 matchall action pass
45+
tc -n "${s_ns}" qdisc add dev eth1 clsact
46+
tc -n "${s_ns}" filter add dev eth1 egress handle 101 protocol 0x8809 matchall action pass
47+
48+
ip -n "${s_ns}" link add bond0 type bond mode 802.3ad lacp_active on lacp_rate fast
49+
ip -n "${s_ns}" link set eth0 master bond0
50+
ip -n "${s_ns}" link set eth1 master bond0
51+
52+
ip -n "${c_ns}" link add bond0 type bond mode 802.3ad lacp_active off lacp_rate fast
53+
ip -n "${c_ns}" link set eth0 master bond0
54+
ip -n "${c_ns}" link set eth1 master bond0
55+
56+
}
57+
58+
trap cleanup_all_ns EXIT
59+
setup
60+
61+
# The bond will send 2 lacpdu pkts during init time, let's wait at least 2s
62+
# after interface up
63+
ip -n "${c_ns}" link set bond0 up
64+
sleep 2
65+
66+
# 1. The passive side shouldn't send LACPDU.
67+
check_pkt_count "${c_ns}" "eth0" && RET=1
68+
log_test "802.3ad lacp_active off" "init port"
69+
70+
ip -n "${s_ns}" link set bond0 up
71+
# 2. The passive side should not have the 'active' flag.
72+
RET=0
73+
slowwait 2 check_port_state "${c_ns}" "eth0" "active" && RET=1
74+
log_test "802.3ad lacp_active off" "port state active"
75+
76+
# 3. The active side should have the 'active' flag.
77+
RET=0
78+
slowwait 2 check_port_state "${s_ns}" "eth0" "active" || RET=1
79+
log_test "802.3ad lacp_active on" "port state active"
80+
81+
# 4. Make sure the connection is not expired.
82+
RET=0
83+
slowwait 5 check_port_state "${s_ns}" "eth0" "distributing"
84+
slowwait 10 check_port_state "${s_ns}" "eth0" "expired" && RET=1
85+
log_test "bond 802.3ad lacp_active off" "port connection"
86+
87+
# After testing, disconnect one port on each side to check the state.
88+
ip -n "${s_ns}" link set eth0 nomaster
89+
ip -n "${s_ns}" link set eth0 up
90+
ip -n "${c_ns}" link set eth1 nomaster
91+
ip -n "${c_ns}" link set eth1 up
92+
# Due to Periodic Machine and Rx Machine state change, the bond will still
93+
# send lacpdu pkts in a few seconds. sleep at lease 5s to make sure
94+
# negotiation finished
95+
sleep 5
96+
97+
# 5. The active side should keep sending LACPDU.
98+
check_pkt_count "${s_ns}" "eth1" || RET=1
99+
log_test "bond 802.3ad lacp_active on" "port pkt after disconnect"
100+
101+
# 6. The passive side shouldn't send LACPDU anymore.
102+
check_pkt_count "${c_ns}" "eth0" && RET=1
103+
log_test "bond 802.3ad lacp_active off" "port pkt after disconnect"
104+
105+
exit "$EXIT_STATUS"

tools/testing/selftests/drivers/net/bonding/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CONFIG_MACVLAN=y
66
CONFIG_IPVLAN=y
77
CONFIG_NET_ACT_GACT=y
88
CONFIG_NET_CLS_FLOWER=y
9+
CONFIG_NET_CLS_MATCHALL=m
910
CONFIG_NET_SCH_INGRESS=y
1011
CONFIG_NLMON=y
1112
CONFIG_VETH=y

0 commit comments

Comments
 (0)