Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Hangbin Liu and committed by
Paolo Abeni
87951b56 0599640a

+108 -1
+2 -1
tools/testing/selftests/drivers/net/bonding/Makefile
··· 10 10 mode-2-recovery-updelay.sh \ 11 11 bond_options.sh \ 12 12 bond-eth-type-change.sh \ 13 - bond_macvlan_ipvlan.sh 13 + bond_macvlan_ipvlan.sh \ 14 + bond_passive_lacp.sh 14 15 15 16 TEST_FILES := \ 16 17 lag_lib.sh \
+105
tools/testing/selftests/drivers/net/bonding/bond_passive_lacp.sh
··· 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"
+1
tools/testing/selftests/drivers/net/bonding/config
··· 6 6 CONFIG_IPVLAN=y 7 7 CONFIG_NET_ACT_GACT=y 8 8 CONFIG_NET_CLS_FLOWER=y 9 + CONFIG_NET_CLS_MATCHALL=m 9 10 CONFIG_NET_SCH_INGRESS=y 10 11 CONFIG_NLMON=y 11 12 CONFIG_VETH=y