[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260206030123.5430-3-linus.luessing@c0d3.blue>
Date: Fri, 6 Feb 2026 03:52:08 +0100
From: Linus Lüssing <linus.luessing@...3.blue>
To: bridge@...ts.linux.dev
Cc: netdev@...r.kernel.org,
linux-kernel@...r.kernel.org,
Nikolay Aleksandrov <razor@...ckwall.org>,
Ido Schimmel <idosch@...dia.com>,
Andrew Lunn <andrew+netdev@...n.ch>,
Simon Horman <horms@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Jakub Kicinski <kuba@...nel.org>,
Eric Dumazet <edumazet@...gle.com>,
"David S . Miller" <davem@...emloft.net>,
Kuniyuki Iwashima <kuniyu@...gle.com>,
Stanislav Fomichev <sdf@...ichev.me>,
Xiao Liang <shaw.leon@...il.com>,
Linus Lüssing <linus.luessing@...3.blue>
Subject: [PATCH net-next v2 02/14] net: bridge: mcast: track active state, adding tests
Before making any significant changes to the internals of the Linux
bridge add some tests regarding the multicast activity. This is
also to verify that we have the semantics of the new
*_MCAST_ACTIVE_{V4,V6} netlink attributes as expected.
Signed-off-by: Linus Lüssing <linus.luessing@...3.blue>
---
.../net/forwarding/bridge_mdb_active.sh | 682 ++++++++++++++++++
1 file changed, 682 insertions(+)
create mode 100755 tools/testing/selftests/net/forwarding/bridge_mdb_active.sh
diff --git a/tools/testing/selftests/net/forwarding/bridge_mdb_active.sh b/tools/testing/selftests/net/forwarding/bridge_mdb_active.sh
new file mode 100755
index 000000000000..5b6e14d88bc2
--- /dev/null
+++ b/tools/testing/selftests/net/forwarding/bridge_mdb_active.sh
@@ -0,0 +1,682 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+# +-------+ +---------+
+# | brq0 | | br0 |
+# | + $h1 | | + $swp1 |
+# +----|--+ +----|----+
+# | |
+# \--------------/
+#
+#
+# This script checks if we have the expected mcast_active_v{4,6} state
+# on br0 in a variety of scenarios. This state determines if ultimately
+# multicast snooping is applied to multicast data packets
+# (multicast snooping active) or if they are (by default) flooded instead
+# (multicast snooping inactive).
+#
+# Notably, multicast snooping can be enabled but still be inactive if not all
+# requirements to safely apply multicast snooping to multicast data packets
+# are met.
+#
+# Depending on the test case an IGMP/MLD querier might be on brq0, on br0
+# or neither.
+
+
+ALL_TESTS="
+ test_inactive
+ test_active_other_querier
+ test_active_own_querier
+ test_inactive_brdown
+ test_inactive_nov6
+ test_inactive_snooping_off
+ test_inactive_querier_off
+ test_inactive_other_querier_norespdelay
+ test_inactive_own_querier_norespdelay
+ test_inactive
+ test_vlan_inactive
+ test_vlan_active_other_querier
+ test_vlan_active_own_querier
+ test_vlan_inactive_brdown
+ test_vlan_inactive_nov6
+ test_vlan_inactive_snooping_off
+ test_vlan_inactive_vlans_snooping_off
+ test_vlan_inactive_vlan_snooping_off
+ test_vlan_inactive_other_querier_norespdelay
+ test_vlan_inactive_own_querier_norespdelay
+"
+
+NUM_NETIFS=1
+MCAST_MAX_RESP_IVAL_SEC=1
+MCAST_VLAN_ID=42
+source lib.sh
+
+switch_create()
+{
+ ip link add dev br0 type bridge\
+ vlan_filtering 0 \
+ mcast_query_response_interval $((${MCAST_MAX_RESP_IVAL_SEC}*100))\
+ mcast_snooping 0 \
+ mcast_vlan_snooping 0
+ ip link add dev brq0 type bridge\
+ vlan_filtering 0 \
+ mcast_query_response_interval $((${MCAST_MAX_RESP_IVAL_SEC}*100))\
+ mcast_snooping 0 \
+ mcast_vlan_snooping 0
+
+ echo 1 > /proc/sys/net/ipv6/conf/br0/disable_ipv6
+ echo 1 > /proc/sys/net/ipv6/conf/brq0/disable_ipv6
+
+ ip link set dev $swp1 master br0
+ ip link set dev $h1 master brq0
+
+ ip link set dev $h1 up
+ ip link set dev $swp1 up
+}
+
+switch_destroy()
+{
+ ip link set dev $swp1 down
+ ip link set dev $h1 down
+
+ ip link del dev brq0
+ ip link del dev br0
+}
+
+setup_prepare()
+{
+ h1=${NETIFS[p1]}
+ swp1=${NETIFS[p2]}
+
+ switch_create
+}
+
+cleanup()
+{
+ pre_cleanup
+ switch_destroy
+}
+
+mcast_active_check()
+{
+ local af="$1"
+ local state="$2"
+
+ ip -d -j link show dev br0\
+ | jq -e ".[] | select(.linkinfo.info_data.mcast_active_$af == $state)"\
+ &> /dev/null
+
+ check_err $? "Mcast active check failed"
+}
+
+mcast_vlan_active_check()
+{
+ local af="$1"
+ local state="$2"
+ local vid="${MCAST_VLAN_ID}"
+ local ret
+
+ bridge -j vlan global show dev br0\
+ | jq -e ".[].vlans.[] | select(.vlan == $vid and .mcast_active_$af == 1)"\
+ &> /dev/null
+ ret="$?"
+
+ if [ $ret -eq 0 -a $state -eq 0 ] || [ $ret -ne 0 -a $state -eq 1 ]; then
+ check_err 1 "Mcast VLAN active check failed"
+ fi
+}
+
+mcast_assert_active_v4()
+{
+ mcast_active_check "v4" "1"
+}
+
+mcast_assert_active_v6()
+{
+ mcast_active_check "v6" "1"
+}
+
+mcast_assert_inactive_v4()
+{
+ mcast_active_check "v4" "0"
+}
+
+mcast_assert_inactive_v6()
+{
+ mcast_active_check "v6" "0"
+}
+
+mcast_vlan_assert_active_v4()
+{
+ mcast_vlan_active_check "v4" "1"
+}
+
+mcast_vlan_assert_active_v6()
+{
+ mcast_vlan_active_check "v6" "1"
+}
+
+mcast_vlan_assert_inactive_v4()
+{
+ mcast_vlan_active_check "v4" "0"
+}
+
+mcast_vlan_assert_inactive_v6()
+{
+ mcast_vlan_active_check "v6" "0"
+}
+
+
+test_inactive_nolog()
+{
+ ip link set dev br0 down
+ ip link set dev brq0 down
+ ip link set dev br0 type bridge mcast_snooping 0
+ ip link set dev brq0 type bridge mcast_snooping 0
+ ip link set dev br0 type bridge mcast_querier 0
+ ip link set dev brq0 type bridge mcast_querier 0
+ ip link set dev br0 type bridge mcast_vlan_snooping 0
+ ip link set dev br0 type bridge vlan_filtering 0
+
+ echo 1 > /proc/sys/net/ipv6/conf/br0/disable_ipv6
+ echo 1 > /proc/sys/net/ipv6/conf/brq0/disable_ipv6
+
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+}
+
+test_inactive()
+{
+ RET=0
+
+ test_inactive_nolog
+ log_test "Mcast inactive test"
+}
+
+wait_lladdr_dad() {
+ local check_tentative
+
+ check_tentative="map(select(.scope == \"link\" and ((.tentative == true) | not))) | .[]"
+
+ ip -6 -j a s dev "$1"\
+ | jq -e ".[].addr_info | ${check_tentative}" &> /dev/null
+}
+
+test_active_setup_bridge()
+{
+ [ -n "$1" ] && echo 0 > /proc/sys/net/ipv6/conf/br0/disable_ipv6
+ [ -n "$2" ] && echo 0 > /proc/sys/net/ipv6/conf/brq0/disable_ipv6
+
+ [ -n "$3" ] && ip link set dev br0 up
+ [ -n "$4" ] && ip link set dev brq0 up
+ [ -n "$5" ] && slowwait 3 wait_lladdr_dad br0
+ [ -n "$6" ] && slowwait 3 wait_lladdr_dad brq0
+}
+
+test_active_setup_config()
+{
+ [ -n "$1" ] && ip link set dev br0 type bridge mcast_snooping 1
+ [ -n "$2" ] && ip link set dev brq0 type bridge mcast_snooping 1
+ [ -n "$3" ] && ip link set dev br0 type bridge mcast_querier 1
+ [ -n "$4" ] && ip link set dev brq0 type bridge mcast_querier 1
+}
+
+test_active_setup_wait()
+{
+ sleep $((${MCAST_MAX_RESP_IVAL_SEC} * 2))
+}
+
+test_active_setup_reset_own_querier()
+{
+ ip link set dev br0 type bridge mcast_querier 0
+ ip link set dev br0 type bridge mcast_querier 1
+
+ test_active_setup_wait
+}
+
+test_vlan_active_setup_config()
+{
+ [ -n "$1" ] && ip link set dev br0 type bridge vlan_filtering 1
+ [ -n "$2" ] && ip link set dev brq0 type bridge vlan_filtering 1
+ [ -n "$3" ] && ip link set dev br0 type bridge mcast_vlan_snooping 1
+ [ -n "$4" ] && ip link set dev brq0 type bridge mcast_vlan_snooping 1
+}
+
+test_vlan_active_setup_add_vlan()
+{
+ bridge vlan add vid ${MCAST_VLAN_ID} dev $swp1
+ bridge vlan add vid ${MCAST_VLAN_ID} dev $h1
+ bridge vlan global set vid ${MCAST_VLAN_ID} dev br0\
+ mcast_query_response_interval $((${MCAST_MAX_RESP_IVAL_SEC}*100))
+ bridge vlan global set vid ${MCAST_VLAN_ID} dev brq0\
+ mcast_query_response_interval $((${MCAST_MAX_RESP_IVAL_SEC}*100))
+ bridge vlan global set vid ${MCAST_VLAN_ID} dev br0 mcast_snooping 0
+ bridge vlan global set vid ${MCAST_VLAN_ID} dev brq0 mcast_snooping 0
+ bridge vlan global set vid ${MCAST_VLAN_ID} dev br0 mcast_querier 0
+ bridge vlan global set vid ${MCAST_VLAN_ID} dev brq0 mcast_querier 0
+}
+
+test_vlan_active_setup_config_vlan()
+{
+ [ -n "$1" ] && bridge vlan global set vid ${MCAST_VLAN_ID} dev br0 mcast_snooping 1
+ [ -n "$2" ] && bridge vlan global set vid ${MCAST_VLAN_ID} dev brq0 mcast_snooping 1
+ [ -n "$3" ] && bridge vlan global set vid ${MCAST_VLAN_ID} dev br0 mcast_querier 1
+ [ -n "$4" ] && bridge vlan global set vid ${MCAST_VLAN_ID} dev brq0 mcast_querier 1
+}
+
+test_vlan_teardown()
+{
+ bridge vlan del vid ${MCAST_VLAN_ID} dev $swp1
+ bridge vlan del vid ${MCAST_VLAN_ID} dev $h1
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+ mcast_vlan_assert_inactive_v4
+ mcast_vlan_assert_inactive_v6
+}
+
+test_vlan_active_setup_reset_own_querier()
+{
+ bridge vlan global set vid ${MCAST_VLAN_ID} dev br0 mcast_querier 0
+ bridge vlan global set vid ${MCAST_VLAN_ID} dev br0 mcast_querier 1
+
+ test_active_setup_wait
+}
+
+test_active_other_querier_nolog()
+{
+ test_active_setup_bridge "1" "2" "3" "4" "5" "6"
+ test_active_setup_config "1" "2" "" "4"
+ test_active_setup_wait
+
+ mcast_assert_active_v4
+ mcast_assert_active_v6
+}
+
+test_active_other_querier()
+{
+ RET=0
+
+ test_active_other_querier_nolog
+ test_inactive_nolog
+ log_test "Mcast active with other querier test"
+}
+
+test_active_own_querier_nolog()
+{
+ test_active_setup_bridge "1" "2" "3" "4" "5" "6"
+ test_active_setup_config "1" "2" "3" ""
+ test_active_setup_wait
+
+ mcast_assert_active_v4
+ mcast_assert_active_v6
+}
+
+test_active_own_querier()
+{
+ RET=0
+
+ test_active_own_querier_nolog
+ test_inactive_nolog
+ log_test "Mcast active with own querier test"
+}
+
+test_active_final()
+{
+ mcast_assert_active_v4
+ mcast_assert_active_v6
+
+ test_inactive_nolog
+}
+
+test_inactive_brdown()
+{
+ RET=0
+
+ test_active_setup_bridge "1" "2" "" "4" "" "6"
+ test_active_setup_config "1" "2" "3" ""
+ test_active_setup_wait
+
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+
+ test_active_setup_bridge "" "" "3" "" "" ""
+ mcast_assert_active_v4
+ mcast_assert_inactive_v6
+
+ test_active_setup_bridge "" "" "" "" "5" ""
+ test_active_setup_reset_own_querier
+ test_active_final
+
+ log_test "Mcast inactive, bridge down test"
+}
+
+test_inactive_nov6()
+{
+ RET=0
+
+ test_active_setup_bridge "" "2" "3" "4" "5" "6"
+ test_active_setup_config "1" "2" "3" ""
+ test_active_setup_wait
+
+ mcast_assert_active_v4
+ mcast_assert_inactive_v6
+
+ test_active_setup_bridge "1" "" "" "" "5" ""
+ test_active_setup_reset_own_querier
+ test_active_final
+
+ log_test "Mcast inactive, own querier, no IPv6 address test"
+}
+
+test_inactive_snooping_off()
+{
+ RET=0
+
+ test_active_setup_bridge "1" "2" "3" "4" "5" "6"
+ test_active_setup_config "" "2" "3" ""
+ test_active_setup_wait
+
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+
+ test_active_setup_config "1" "" "" ""
+ test_active_setup_reset_own_querier
+ test_active_final
+
+ log_test "Mcast inactive, snooping disabled test"
+}
+
+test_inactive_querier_off()
+{
+ RET=0
+
+ test_active_setup_bridge "1" "2" "3" "4" "5" "6"
+ test_active_setup_config "1" "2" "" ""
+ test_active_setup_wait
+
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+
+ test_active_setup_config "" "" "3" ""
+ test_active_setup_wait
+ test_active_final
+
+ log_test "Mcast inactive, no querier test"
+}
+
+test_inactive_other_querier_norespdelay()
+{
+ RET=0
+
+ test_active_setup_bridge "1" "2" "3" "4" "5" "6"
+ test_active_setup_config "1" "2" "3" ""
+ #test_active_setup_wait
+
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+
+ test_active_setup_wait
+ test_active_final
+
+ log_test "Mcast inactive, other querier, no response delay test"
+}
+
+test_inactive_own_querier_norespdelay()
+{
+ RET=0
+
+ test_active_setup_bridge "1" "2" "3" "4" "5" "6"
+ test_active_setup_config "1" "2" "" "4"
+ #test_active_setup_wait
+
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+
+ test_active_setup_wait
+ test_active_final
+
+ log_test "Mcast inactive, own querier, no response delay test"
+}
+
+test_vlan_inactive()
+{
+ RET=0
+
+ test_inactive_nolog
+ mcast_vlan_assert_inactive_v4
+ mcast_vlan_assert_inactive_v6
+
+ ip link set dev br0 type bridge vlan_filtering 1
+ ip link set dev br0 type bridge mcast_vlan_snooping 1
+ mcast_vlan_assert_inactive_v4
+ mcast_vlan_assert_inactive_v6
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+
+ ip link set dev br0 type bridge mcast_vlan_snooping 0
+ ip link set dev br0 type bridge vlan_filtering 0
+ test_active_own_querier_nolog
+ ip link set dev br0 type bridge vlan_filtering 1
+ mcast_assert_active_v4
+ mcast_assert_active_v6
+
+ ip link set dev br0 type bridge mcast_vlan_snooping 1
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+
+ test_inactive_nolog
+ log_test "Mcast VLAN inactive test"
+}
+
+test_vlan_active_final()
+{
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+ mcast_vlan_assert_active_v4
+ mcast_vlan_assert_active_v6
+
+ test_vlan_teardown
+ test_inactive_nolog
+}
+
+test_vlan_active_other_querier()
+{
+ RET=0
+
+ test_active_setup_bridge "1" "2" "3" "4" "5" "6"
+ test_active_setup_config "1" "2" "" ""
+ test_vlan_active_setup_config "1" "2" "3" "4"
+ test_vlan_active_setup_add_vlan
+ test_vlan_active_setup_config_vlan "1" "2" "" "4"
+ test_active_setup_wait
+ test_vlan_active_final
+
+ log_test "Mcast VLAN active, other querier test"
+}
+
+test_vlan_active_own_querier()
+{
+ RET=0
+
+ test_active_setup_bridge "1" "2" "3" "4" "5" "6"
+ test_active_setup_config "1" "2" "" ""
+ test_vlan_active_setup_config "1" "2" "3" "4"
+ test_vlan_active_setup_add_vlan
+ test_vlan_active_setup_config_vlan "1" "2" "3" ""
+ test_active_setup_wait
+ test_vlan_active_final
+
+ log_test "Mcast VLAN active, own querier test"
+}
+
+test_vlan_inactive_brdown()
+{
+ RET=0
+
+ test_active_setup_bridge "1" "2" "" "4" "" "6"
+ test_active_setup_config "1" "2" "" ""
+ test_vlan_active_setup_config "1" "2" "3" "4"
+ test_vlan_active_setup_add_vlan
+ test_vlan_active_setup_config_vlan "1" "2" "3" ""
+ test_active_setup_wait
+
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+ mcast_vlan_assert_inactive_v4
+ mcast_vlan_assert_inactive_v6
+
+ test_active_setup_bridge "" "" "3" "" "" ""
+ mcast_vlan_assert_active_v4
+ mcast_assert_inactive_v6
+
+ test_active_setup_bridge "" "" "" "" "5" ""
+ test_vlan_active_setup_reset_own_querier
+ test_vlan_active_final
+
+ log_test "Mcast VLAN inactive, bridge down test"
+}
+
+test_vlan_inactive_nov6()
+{
+ RET=0
+
+ test_active_setup_bridge "" "2" "3" "4" "5" "6"
+ test_active_setup_config "1" "2" "" ""
+ test_vlan_active_setup_config "1" "2" "3" "4"
+ test_vlan_active_setup_add_vlan
+ test_vlan_active_setup_config_vlan "1" "2" "3" ""
+ test_active_setup_wait
+
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+ mcast_vlan_assert_active_v4
+ mcast_vlan_assert_inactive_v6
+
+ test_active_setup_bridge "1" "" "" "" "5" ""
+ test_vlan_active_setup_reset_own_querier
+ test_vlan_active_final
+
+ log_test "Mcast VLAN inactive, own querier, no IPv6 address test"
+}
+
+test_vlan_inactive_snooping_off()
+{
+ RET=0
+
+ test_active_setup_bridge "1" "2" "3" "4" "5" "6"
+ test_active_setup_config "" "2" "" ""
+ test_vlan_active_setup_config "1" "2" "3" "4"
+ test_vlan_active_setup_add_vlan
+ test_vlan_active_setup_config_vlan "1" "2" "3" ""
+ test_active_setup_wait
+
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+ mcast_vlan_assert_inactive_v4
+ mcast_vlan_assert_inactive_v6
+
+ test_active_setup_config "1" "" "" ""
+ test_vlan_active_setup_reset_own_querier
+ test_vlan_active_final
+
+ log_test "Mcast VLAN inactive, snooping disabled test"
+}
+
+test_vlan_inactive_vlans_snooping_off()
+{
+ RET=0
+
+ test_active_setup_bridge "1" "2" "3" "4" "5" "6"
+ test_active_setup_config "1" "2" "" ""
+ test_vlan_active_setup_config "1" "2" "" "4"
+ test_vlan_active_setup_add_vlan
+ test_vlan_active_setup_config_vlan "1" "2" "3" ""
+ test_active_setup_wait
+
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+ mcast_vlan_assert_inactive_v4
+ mcast_vlan_assert_inactive_v6
+
+ test_vlan_active_setup_config "" "" "3" ""
+ test_vlan_active_setup_reset_own_querier
+ test_vlan_active_final
+
+ log_test "Mcast VLAN inactive, snooping for VLANs disabled test"
+}
+
+test_vlan_inactive_vlan_snooping_off()
+{
+ RET=0
+
+ test_active_setup_bridge "1" "2" "3" "4" "5" "6"
+ test_active_setup_config "1" "2" "" ""
+ test_vlan_active_setup_config "1" "2" "3" "4"
+ test_vlan_active_setup_add_vlan
+ test_vlan_active_setup_config_vlan "" "2" "3" ""
+ test_active_setup_wait
+
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+ mcast_vlan_assert_inactive_v4
+ mcast_vlan_assert_inactive_v6
+
+ test_vlan_active_setup_config_vlan "1" "" "" ""
+ test_vlan_active_setup_reset_own_querier
+ test_vlan_active_final
+
+ log_test "Mcast VLAN inactive, snooping for this VLAN disabled test"
+}
+
+test_vlan_inactive_other_querier_norespdelay()
+{
+ RET=0
+
+ test_active_setup_bridge "1" "2" "3" "4" "5" "6"
+ test_active_setup_config "1" "2" "" ""
+ test_vlan_active_setup_config "1" "2" "3" "4"
+ test_vlan_active_setup_add_vlan
+ test_vlan_active_setup_config_vlan "1" "2" "" "4"
+ #test_active_setup_wait
+
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+ mcast_vlan_assert_inactive_v4
+ mcast_vlan_assert_inactive_v6
+
+ test_active_setup_wait
+ test_vlan_active_final
+
+ log_test "Mcast VLAN inactive, other querier, no response delay test"
+}
+
+test_vlan_inactive_own_querier_norespdelay()
+{
+ RET=0
+
+ test_active_setup_bridge "1" "2" "3" "4" "5" "6"
+ test_active_setup_config "1" "2" "" ""
+ test_vlan_active_setup_config "1" "2" "3" "4"
+ test_vlan_active_setup_add_vlan
+ test_vlan_active_setup_config_vlan "1" "2" "3" ""
+ #test_active_setup_wait
+
+ mcast_assert_inactive_v4
+ mcast_assert_inactive_v6
+ mcast_vlan_assert_inactive_v4
+ mcast_vlan_assert_inactive_v6
+
+ test_active_setup_wait
+ test_vlan_active_final
+
+ log_test "Mcast VLAN inactive, own querier, no response delay test"
+}
+
+trap cleanup EXIT
+
+setup_prepare
+setup_wait
+
+tests_run
+
+exit $EXIT_STATUS
--
2.51.0
Powered by blists - more mailing lists