xref: /openbmc/linux/tools/testing/selftests/net/test_bridge_neigh_suppress.sh (revision e0d77d0f38aa60ca61b3ce6e60d64fad2aa0853d)
17648ac72SIdo Schimmel#!/bin/bash
27648ac72SIdo Schimmel# SPDX-License-Identifier: GPL-2.0
37648ac72SIdo Schimmel#
47648ac72SIdo Schimmel# This test is for checking bridge neighbor suppression functionality. The
57648ac72SIdo Schimmel# topology consists of two bridges (VTEPs) connected using VXLAN. A single
67648ac72SIdo Schimmel# host is connected to each bridge over multiple VLANs. The test checks that
77648ac72SIdo Schimmel# ARP/NS messages from the first host are suppressed on the VXLAN port when
87648ac72SIdo Schimmel# should.
97648ac72SIdo Schimmel#
107648ac72SIdo Schimmel# +-----------------------+              +------------------------+
117648ac72SIdo Schimmel# | h1                    |              | h2                     |
127648ac72SIdo Schimmel# |                       |              |                        |
137648ac72SIdo Schimmel# | + eth0.10             |              | + eth0.10              |
147648ac72SIdo Schimmel# | | 192.0.2.1/28        |              | | 192.0.2.2/28         |
157648ac72SIdo Schimmel# | | 2001:db8:1::1/64    |              | | 2001:db8:1::2/64     |
167648ac72SIdo Schimmel# | |                     |              | |                      |
177648ac72SIdo Schimmel# | |  + eth0.20          |              | |  + eth0.20           |
187648ac72SIdo Schimmel# | \  | 192.0.2.17/28    |              | \  | 192.0.2.18/28     |
197648ac72SIdo Schimmel# |  \ | 2001:db8:2::1/64 |              |  \ | 2001:db8:2::2/64  |
207648ac72SIdo Schimmel# |   \|                  |              |   \|                   |
217648ac72SIdo Schimmel# |    + eth0             |              |    + eth0              |
227648ac72SIdo Schimmel# +----|------------------+              +----|-------------------+
237648ac72SIdo Schimmel#      |                                      |
247648ac72SIdo Schimmel#      |                                      |
257648ac72SIdo Schimmel# +----|-------------------------------+ +----|-------------------------------+
267648ac72SIdo Schimmel# |    + swp1                   + vx0  | |    + swp1                   + vx0  |
277648ac72SIdo Schimmel# |    |                        |      | |    |                        |      |
287648ac72SIdo Schimmel# |    |           br0          |      | |    |                        |      |
297648ac72SIdo Schimmel# |    +------------+-----------+      | |    +------------+-----------+      |
307648ac72SIdo Schimmel# |                 |                  | |                 |                  |
317648ac72SIdo Schimmel# |                 |                  | |                 |                  |
327648ac72SIdo Schimmel# |             +---+---+              | |             +---+---+              |
337648ac72SIdo Schimmel# |             |       |              | |             |       |              |
347648ac72SIdo Schimmel# |             |       |              | |             |       |              |
357648ac72SIdo Schimmel# |             +       +              | |             +       +              |
367648ac72SIdo Schimmel# |          br0.10  br0.20            | |          br0.10  br0.20            |
377648ac72SIdo Schimmel# |                                    | |                                    |
387648ac72SIdo Schimmel# |                 192.0.2.33         | |                 192.0.2.34         |
397648ac72SIdo Schimmel# |                 + lo               | |                 + lo               |
407648ac72SIdo Schimmel# |                                    | |                                    |
417648ac72SIdo Schimmel# |                                    | |                                    |
427648ac72SIdo Schimmel# |                   192.0.2.49/28    | |    192.0.2.50/28                   |
437648ac72SIdo Schimmel# |                           veth0 +-------+ veth0                           |
447648ac72SIdo Schimmel# |                                    | |                                    |
457648ac72SIdo Schimmel# | sw1                                | | sw2                                |
467648ac72SIdo Schimmel# +------------------------------------+ +------------------------------------+
477648ac72SIdo Schimmel
482ee2fc67SHangbin Liusource lib.sh
497648ac72SIdo Schimmelret=0
507648ac72SIdo Schimmel
517648ac72SIdo Schimmel# All tests in this script. Can be overridden with -t option.
527648ac72SIdo SchimmelTESTS="
537648ac72SIdo Schimmel	neigh_suppress_arp
547648ac72SIdo Schimmel	neigh_suppress_ns
557648ac72SIdo Schimmel	neigh_vlan_suppress_arp
567648ac72SIdo Schimmel	neigh_vlan_suppress_ns
577648ac72SIdo Schimmel"
587648ac72SIdo SchimmelVERBOSE=0
597648ac72SIdo SchimmelPAUSE_ON_FAIL=no
607648ac72SIdo SchimmelPAUSE=no
617648ac72SIdo Schimmel
627648ac72SIdo Schimmel################################################################################
637648ac72SIdo Schimmel# Utilities
647648ac72SIdo Schimmel
657648ac72SIdo Schimmellog_test()
667648ac72SIdo Schimmel{
677648ac72SIdo Schimmel	local rc=$1
687648ac72SIdo Schimmel	local expected=$2
697648ac72SIdo Schimmel	local msg="$3"
707648ac72SIdo Schimmel
717648ac72SIdo Schimmel	if [ ${rc} -eq ${expected} ]; then
727648ac72SIdo Schimmel		printf "TEST: %-60s  [ OK ]\n" "${msg}"
737648ac72SIdo Schimmel		nsuccess=$((nsuccess+1))
747648ac72SIdo Schimmel	else
757648ac72SIdo Schimmel		ret=1
767648ac72SIdo Schimmel		nfail=$((nfail+1))
777648ac72SIdo Schimmel		printf "TEST: %-60s  [FAIL]\n" "${msg}"
787648ac72SIdo Schimmel		if [ "$VERBOSE" = "1" ]; then
797648ac72SIdo Schimmel			echo "    rc=$rc, expected $expected"
807648ac72SIdo Schimmel		fi
817648ac72SIdo Schimmel
827648ac72SIdo Schimmel		if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
837648ac72SIdo Schimmel		echo
847648ac72SIdo Schimmel			echo "hit enter to continue, 'q' to quit"
857648ac72SIdo Schimmel			read a
867648ac72SIdo Schimmel			[ "$a" = "q" ] && exit 1
877648ac72SIdo Schimmel		fi
887648ac72SIdo Schimmel	fi
897648ac72SIdo Schimmel
907648ac72SIdo Schimmel	if [ "${PAUSE}" = "yes" ]; then
917648ac72SIdo Schimmel		echo
927648ac72SIdo Schimmel		echo "hit enter to continue, 'q' to quit"
937648ac72SIdo Schimmel		read a
947648ac72SIdo Schimmel		[ "$a" = "q" ] && exit 1
957648ac72SIdo Schimmel	fi
967648ac72SIdo Schimmel
977648ac72SIdo Schimmel	[ "$VERBOSE" = "1" ] && echo
987648ac72SIdo Schimmel}
997648ac72SIdo Schimmel
1007648ac72SIdo Schimmelrun_cmd()
1017648ac72SIdo Schimmel{
1027648ac72SIdo Schimmel	local cmd="$1"
1037648ac72SIdo Schimmel	local out
1047648ac72SIdo Schimmel	local stderr="2>/dev/null"
1057648ac72SIdo Schimmel
1067648ac72SIdo Schimmel	if [ "$VERBOSE" = "1" ]; then
1077648ac72SIdo Schimmel		printf "COMMAND: $cmd\n"
1087648ac72SIdo Schimmel		stderr=
1097648ac72SIdo Schimmel	fi
1107648ac72SIdo Schimmel
1117648ac72SIdo Schimmel	out=$(eval $cmd $stderr)
1127648ac72SIdo Schimmel	rc=$?
1137648ac72SIdo Schimmel	if [ "$VERBOSE" = "1" -a -n "$out" ]; then
1147648ac72SIdo Schimmel		echo "    $out"
1157648ac72SIdo Schimmel	fi
1167648ac72SIdo Schimmel
1177648ac72SIdo Schimmel	return $rc
1187648ac72SIdo Schimmel}
1197648ac72SIdo Schimmel
1207648ac72SIdo Schimmeltc_check_packets()
1217648ac72SIdo Schimmel{
1227648ac72SIdo Schimmel	local ns=$1; shift
1237648ac72SIdo Schimmel	local id=$1; shift
1247648ac72SIdo Schimmel	local handle=$1; shift
1257648ac72SIdo Schimmel	local count=$1; shift
1267648ac72SIdo Schimmel	local pkts
1277648ac72SIdo Schimmel
1287648ac72SIdo Schimmel	sleep 0.1
1297648ac72SIdo Schimmel	pkts=$(tc -n $ns -j -s filter show $id \
1307648ac72SIdo Schimmel		| jq ".[] | select(.options.handle == $handle) | \
1317648ac72SIdo Schimmel		.options.actions[0].stats.packets")
1327648ac72SIdo Schimmel	[[ $pkts == $count ]]
1337648ac72SIdo Schimmel}
1347648ac72SIdo Schimmel
1357648ac72SIdo Schimmel################################################################################
1367648ac72SIdo Schimmel# Setup
1377648ac72SIdo Schimmel
1387648ac72SIdo Schimmelsetup_topo_ns()
1397648ac72SIdo Schimmel{
1407648ac72SIdo Schimmel	local ns=$1; shift
1417648ac72SIdo Schimmel
1427648ac72SIdo Schimmel	ip netns exec $ns sysctl -qw net.ipv6.conf.all.keep_addr_on_down=1
1437648ac72SIdo Schimmel	ip netns exec $ns sysctl -qw net.ipv6.conf.default.ignore_routes_with_linkdown=1
1447648ac72SIdo Schimmel	ip netns exec $ns sysctl -qw net.ipv6.conf.all.accept_dad=0
1457648ac72SIdo Schimmel	ip netns exec $ns sysctl -qw net.ipv6.conf.default.accept_dad=0
1467648ac72SIdo Schimmel}
1477648ac72SIdo Schimmel
1487648ac72SIdo Schimmelsetup_topo()
1497648ac72SIdo Schimmel{
1507648ac72SIdo Schimmel	local ns
1517648ac72SIdo Schimmel
1522ee2fc67SHangbin Liu	setup_ns h1 h2 sw1 sw2
1532ee2fc67SHangbin Liu	for ns in $h1 $h2 $sw1 $sw2; do
1547648ac72SIdo Schimmel		setup_topo_ns $ns
1557648ac72SIdo Schimmel	done
1567648ac72SIdo Schimmel
157*438d7cebSIdo Schimmel	ip -n $h1 link add name eth0 type veth peer name swp1 netns $sw1
158*438d7cebSIdo Schimmel	ip -n $sw1 link add name veth0 type veth peer name veth0 netns $sw2
159*438d7cebSIdo Schimmel	ip -n $h2 link add name eth0 type veth peer name swp1 netns $sw2
1607648ac72SIdo Schimmel}
1617648ac72SIdo Schimmel
1627648ac72SIdo Schimmelsetup_host_common()
1637648ac72SIdo Schimmel{
1647648ac72SIdo Schimmel	local ns=$1; shift
1657648ac72SIdo Schimmel	local v4addr1=$1; shift
1667648ac72SIdo Schimmel	local v4addr2=$1; shift
1677648ac72SIdo Schimmel	local v6addr1=$1; shift
1687648ac72SIdo Schimmel	local v6addr2=$1; shift
1697648ac72SIdo Schimmel
1707648ac72SIdo Schimmel	ip -n $ns link set dev eth0 up
1717648ac72SIdo Schimmel	ip -n $ns link add link eth0 name eth0.10 up type vlan id 10
1727648ac72SIdo Schimmel	ip -n $ns link add link eth0 name eth0.20 up type vlan id 20
1737648ac72SIdo Schimmel
1747648ac72SIdo Schimmel	ip -n $ns address add $v4addr1 dev eth0.10
1757648ac72SIdo Schimmel	ip -n $ns address add $v4addr2 dev eth0.20
1767648ac72SIdo Schimmel	ip -n $ns address add $v6addr1 dev eth0.10
1777648ac72SIdo Schimmel	ip -n $ns address add $v6addr2 dev eth0.20
1787648ac72SIdo Schimmel}
1797648ac72SIdo Schimmel
1807648ac72SIdo Schimmelsetup_h1()
1817648ac72SIdo Schimmel{
1822ee2fc67SHangbin Liu	local ns=$h1
1837648ac72SIdo Schimmel	local v4addr1=192.0.2.1/28
1847648ac72SIdo Schimmel	local v4addr2=192.0.2.17/28
1857648ac72SIdo Schimmel	local v6addr1=2001:db8:1::1/64
1867648ac72SIdo Schimmel	local v6addr2=2001:db8:2::1/64
1877648ac72SIdo Schimmel
1887648ac72SIdo Schimmel	setup_host_common $ns $v4addr1 $v4addr2 $v6addr1 $v6addr2
1897648ac72SIdo Schimmel}
1907648ac72SIdo Schimmel
1917648ac72SIdo Schimmelsetup_h2()
1927648ac72SIdo Schimmel{
1932ee2fc67SHangbin Liu	local ns=$h2
1947648ac72SIdo Schimmel	local v4addr1=192.0.2.2/28
1957648ac72SIdo Schimmel	local v4addr2=192.0.2.18/28
1967648ac72SIdo Schimmel	local v6addr1=2001:db8:1::2/64
1977648ac72SIdo Schimmel	local v6addr2=2001:db8:2::2/64
1987648ac72SIdo Schimmel
1997648ac72SIdo Schimmel	setup_host_common $ns $v4addr1 $v4addr2 $v6addr1 $v6addr2
2007648ac72SIdo Schimmel}
2017648ac72SIdo Schimmel
2027648ac72SIdo Schimmelsetup_sw_common()
2037648ac72SIdo Schimmel{
2047648ac72SIdo Schimmel	local ns=$1; shift
2057648ac72SIdo Schimmel	local local_addr=$1; shift
2067648ac72SIdo Schimmel	local remote_addr=$1; shift
2077648ac72SIdo Schimmel	local veth_addr=$1; shift
2087648ac72SIdo Schimmel	local gw_addr=$1; shift
2097648ac72SIdo Schimmel
2107648ac72SIdo Schimmel	ip -n $ns address add $local_addr/32 dev lo
2117648ac72SIdo Schimmel
2127648ac72SIdo Schimmel	ip -n $ns link set dev veth0 up
2137648ac72SIdo Schimmel	ip -n $ns address add $veth_addr/28 dev veth0
2147648ac72SIdo Schimmel	ip -n $ns route add default via $gw_addr
2157648ac72SIdo Schimmel
2167648ac72SIdo Schimmel	ip -n $ns link add name br0 up type bridge vlan_filtering 1 \
2177648ac72SIdo Schimmel		vlan_default_pvid 0 mcast_snooping 0
2187648ac72SIdo Schimmel
2197648ac72SIdo Schimmel	ip -n $ns link add link br0 name br0.10 up type vlan id 10
2207648ac72SIdo Schimmel	bridge -n $ns vlan add vid 10 dev br0 self
2217648ac72SIdo Schimmel
2227648ac72SIdo Schimmel	ip -n $ns link add link br0 name br0.20 up type vlan id 20
2237648ac72SIdo Schimmel	bridge -n $ns vlan add vid 20 dev br0 self
2247648ac72SIdo Schimmel
2257648ac72SIdo Schimmel	ip -n $ns link set dev swp1 up master br0
2267648ac72SIdo Schimmel	bridge -n $ns vlan add vid 10 dev swp1
2277648ac72SIdo Schimmel	bridge -n $ns vlan add vid 20 dev swp1
2287648ac72SIdo Schimmel
2297648ac72SIdo Schimmel	ip -n $ns link add name vx0 up master br0 type vxlan \
2307648ac72SIdo Schimmel		local $local_addr dstport 4789 nolearning external
2317648ac72SIdo Schimmel	bridge -n $ns fdb add 00:00:00:00:00:00 dev vx0 self static \
2327648ac72SIdo Schimmel		dst $remote_addr src_vni 10010
2337648ac72SIdo Schimmel	bridge -n $ns fdb add 00:00:00:00:00:00 dev vx0 self static \
2347648ac72SIdo Schimmel		dst $remote_addr src_vni 10020
2357648ac72SIdo Schimmel	bridge -n $ns link set dev vx0 vlan_tunnel on learning off
2367648ac72SIdo Schimmel
2377648ac72SIdo Schimmel	bridge -n $ns vlan add vid 10 dev vx0
2387648ac72SIdo Schimmel	bridge -n $ns vlan add vid 10 dev vx0 tunnel_info id 10010
2397648ac72SIdo Schimmel
2407648ac72SIdo Schimmel	bridge -n $ns vlan add vid 20 dev vx0
2417648ac72SIdo Schimmel	bridge -n $ns vlan add vid 20 dev vx0 tunnel_info id 10020
2427648ac72SIdo Schimmel}
2437648ac72SIdo Schimmel
2447648ac72SIdo Schimmelsetup_sw1()
2457648ac72SIdo Schimmel{
2462ee2fc67SHangbin Liu	local ns=$sw1
2477648ac72SIdo Schimmel	local local_addr=192.0.2.33
2487648ac72SIdo Schimmel	local remote_addr=192.0.2.34
2497648ac72SIdo Schimmel	local veth_addr=192.0.2.49
2507648ac72SIdo Schimmel	local gw_addr=192.0.2.50
2517648ac72SIdo Schimmel
2527648ac72SIdo Schimmel	setup_sw_common $ns $local_addr $remote_addr $veth_addr $gw_addr
2537648ac72SIdo Schimmel}
2547648ac72SIdo Schimmel
2557648ac72SIdo Schimmelsetup_sw2()
2567648ac72SIdo Schimmel{
2572ee2fc67SHangbin Liu	local ns=$sw2
2587648ac72SIdo Schimmel	local local_addr=192.0.2.34
2597648ac72SIdo Schimmel	local remote_addr=192.0.2.33
2607648ac72SIdo Schimmel	local veth_addr=192.0.2.50
2617648ac72SIdo Schimmel	local gw_addr=192.0.2.49
2627648ac72SIdo Schimmel
2637648ac72SIdo Schimmel	setup_sw_common $ns $local_addr $remote_addr $veth_addr $gw_addr
2647648ac72SIdo Schimmel}
2657648ac72SIdo Schimmel
2667648ac72SIdo Schimmelsetup()
2677648ac72SIdo Schimmel{
2687648ac72SIdo Schimmel	set -e
2697648ac72SIdo Schimmel
2707648ac72SIdo Schimmel	setup_topo
2717648ac72SIdo Schimmel	setup_h1
2727648ac72SIdo Schimmel	setup_h2
2737648ac72SIdo Schimmel	setup_sw1
2747648ac72SIdo Schimmel	setup_sw2
2757648ac72SIdo Schimmel
2767648ac72SIdo Schimmel	sleep 5
2777648ac72SIdo Schimmel
2787648ac72SIdo Schimmel	set +e
2797648ac72SIdo Schimmel}
2807648ac72SIdo Schimmel
2817648ac72SIdo Schimmelcleanup()
2827648ac72SIdo Schimmel{
2832ee2fc67SHangbin Liu	cleanup_ns $h1 $h2 $sw1 $sw2
2847648ac72SIdo Schimmel}
2857648ac72SIdo Schimmel
2867648ac72SIdo Schimmel################################################################################
2877648ac72SIdo Schimmel# Tests
2887648ac72SIdo Schimmel
2897648ac72SIdo Schimmelneigh_suppress_arp_common()
2907648ac72SIdo Schimmel{
2917648ac72SIdo Schimmel	local vid=$1; shift
2927648ac72SIdo Schimmel	local sip=$1; shift
2937648ac72SIdo Schimmel	local tip=$1; shift
2947648ac72SIdo Schimmel	local h2_mac
2957648ac72SIdo Schimmel
2967648ac72SIdo Schimmel	echo
2977648ac72SIdo Schimmel	echo "Per-port ARP suppression - VLAN $vid"
2987648ac72SIdo Schimmel	echo "----------------------------------"
2997648ac72SIdo Schimmel
3002ee2fc67SHangbin Liu	run_cmd "tc -n $sw1 qdisc replace dev vx0 clsact"
3012ee2fc67SHangbin Liu	run_cmd "tc -n $sw1 filter replace dev vx0 egress pref 1 handle 101 proto 0x0806 flower indev swp1 arp_tip $tip arp_sip $sip arp_op request action pass"
3027648ac72SIdo Schimmel
3037648ac72SIdo Schimmel	# Initial state - check that ARP requests are not suppressed and that
3047648ac72SIdo Schimmel	# ARP replies are received.
3052ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip -I eth0.$vid $tip"
3067648ac72SIdo Schimmel	log_test $? 0 "arping"
3072ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 1
3087648ac72SIdo Schimmel	log_test $? 0 "ARP suppression"
3097648ac72SIdo Schimmel
3107648ac72SIdo Schimmel	# Enable neighbor suppression and check that nothing changes compared
3117648ac72SIdo Schimmel	# to the initial state.
3122ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 link set dev vx0 neigh_suppress on"
3132ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d link show dev vx0 | grep \"neigh_suppress on\""
3147648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is on"
3157648ac72SIdo Schimmel
3162ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip -I eth0.$vid $tip"
3177648ac72SIdo Schimmel	log_test $? 0 "arping"
3182ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 2
3197648ac72SIdo Schimmel	log_test $? 0 "ARP suppression"
3207648ac72SIdo Schimmel
3217648ac72SIdo Schimmel	# Install an FDB entry for the remote host and check that nothing
3227648ac72SIdo Schimmel	# changes compared to the initial state.
3232ee2fc67SHangbin Liu	h2_mac=$(ip -n $h2 -j -p link show eth0.$vid | jq -r '.[]["address"]')
3242ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 fdb replace $h2_mac dev vx0 master static vlan $vid"
3257648ac72SIdo Schimmel	log_test $? 0 "FDB entry installation"
3267648ac72SIdo Schimmel
3272ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip -I eth0.$vid $tip"
3287648ac72SIdo Schimmel	log_test $? 0 "arping"
3292ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 3
3307648ac72SIdo Schimmel	log_test $? 0 "ARP suppression"
3317648ac72SIdo Schimmel
3327648ac72SIdo Schimmel	# Install a neighbor on the matching SVI interface and check that ARP
3337648ac72SIdo Schimmel	# requests are suppressed.
3342ee2fc67SHangbin Liu	run_cmd "ip -n $sw1 neigh replace $tip lladdr $h2_mac nud permanent dev br0.$vid"
3357648ac72SIdo Schimmel	log_test $? 0 "Neighbor entry installation"
3367648ac72SIdo Schimmel
3372ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip -I eth0.$vid $tip"
3387648ac72SIdo Schimmel	log_test $? 0 "arping"
3392ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 3
3407648ac72SIdo Schimmel	log_test $? 0 "ARP suppression"
3417648ac72SIdo Schimmel
3427648ac72SIdo Schimmel	# Take the second host down and check that ARP requests are suppressed
3437648ac72SIdo Schimmel	# and that ARP replies are received.
3442ee2fc67SHangbin Liu	run_cmd "ip -n $h2 link set dev eth0.$vid down"
3457648ac72SIdo Schimmel	log_test $? 0 "H2 down"
3467648ac72SIdo Schimmel
3472ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip -I eth0.$vid $tip"
3487648ac72SIdo Schimmel	log_test $? 0 "arping"
3492ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 3
3507648ac72SIdo Schimmel	log_test $? 0 "ARP suppression"
3517648ac72SIdo Schimmel
3522ee2fc67SHangbin Liu	run_cmd "ip -n $h2 link set dev eth0.$vid up"
3537648ac72SIdo Schimmel	log_test $? 0 "H2 up"
3547648ac72SIdo Schimmel
3557648ac72SIdo Schimmel	# Disable neighbor suppression and check that ARP requests are no
3567648ac72SIdo Schimmel	# longer suppressed.
3572ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 link set dev vx0 neigh_suppress off"
3582ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d link show dev vx0 | grep \"neigh_suppress off\""
3597648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is off"
3607648ac72SIdo Schimmel
3612ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip -I eth0.$vid $tip"
3627648ac72SIdo Schimmel	log_test $? 0 "arping"
3632ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 4
3647648ac72SIdo Schimmel	log_test $? 0 "ARP suppression"
3657648ac72SIdo Schimmel
3667648ac72SIdo Schimmel	# Take the second host down and check that ARP requests are not
3677648ac72SIdo Schimmel	# suppressed and that ARP replies are not received.
3682ee2fc67SHangbin Liu	run_cmd "ip -n $h2 link set dev eth0.$vid down"
3697648ac72SIdo Schimmel	log_test $? 0 "H2 down"
3707648ac72SIdo Schimmel
3712ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip -I eth0.$vid $tip"
3727648ac72SIdo Schimmel	log_test $? 1 "arping"
3732ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 5
3747648ac72SIdo Schimmel	log_test $? 0 "ARP suppression"
3757648ac72SIdo Schimmel}
3767648ac72SIdo Schimmel
3777648ac72SIdo Schimmelneigh_suppress_arp()
3787648ac72SIdo Schimmel{
3797648ac72SIdo Schimmel	local vid=10
3807648ac72SIdo Schimmel	local sip=192.0.2.1
3817648ac72SIdo Schimmel	local tip=192.0.2.2
3827648ac72SIdo Schimmel
3837648ac72SIdo Schimmel	neigh_suppress_arp_common $vid $sip $tip
3847648ac72SIdo Schimmel
3857648ac72SIdo Schimmel	vid=20
3867648ac72SIdo Schimmel	sip=192.0.2.17
3877648ac72SIdo Schimmel	tip=192.0.2.18
3887648ac72SIdo Schimmel	neigh_suppress_arp_common $vid $sip $tip
3897648ac72SIdo Schimmel}
3907648ac72SIdo Schimmel
3917648ac72SIdo Schimmelneigh_suppress_ns_common()
3927648ac72SIdo Schimmel{
3937648ac72SIdo Schimmel	local vid=$1; shift
3947648ac72SIdo Schimmel	local saddr=$1; shift
3957648ac72SIdo Schimmel	local daddr=$1; shift
3967648ac72SIdo Schimmel	local maddr=$1; shift
3977648ac72SIdo Schimmel	local h2_mac
3987648ac72SIdo Schimmel
3997648ac72SIdo Schimmel	echo
4007648ac72SIdo Schimmel	echo "Per-port NS suppression - VLAN $vid"
4017648ac72SIdo Schimmel	echo "---------------------------------"
4027648ac72SIdo Schimmel
4032ee2fc67SHangbin Liu	run_cmd "tc -n $sw1 qdisc replace dev vx0 clsact"
4042ee2fc67SHangbin Liu	run_cmd "tc -n $sw1 filter replace dev vx0 egress pref 1 handle 101 proto ipv6 flower indev swp1 ip_proto icmpv6 dst_ip $maddr src_ip $saddr type 135 code 0 action pass"
4057648ac72SIdo Schimmel
4067648ac72SIdo Schimmel	# Initial state - check that NS messages are not suppressed and that ND
4077648ac72SIdo Schimmel	# messages are received.
4082ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr -w 5000 $daddr eth0.$vid"
4097648ac72SIdo Schimmel	log_test $? 0 "ndisc6"
4102ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 1
4117648ac72SIdo Schimmel	log_test $? 0 "NS suppression"
4127648ac72SIdo Schimmel
4137648ac72SIdo Schimmel	# Enable neighbor suppression and check that nothing changes compared
4147648ac72SIdo Schimmel	# to the initial state.
4152ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 link set dev vx0 neigh_suppress on"
4162ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d link show dev vx0 | grep \"neigh_suppress on\""
4177648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is on"
4187648ac72SIdo Schimmel
4192ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr -w 5000 $daddr eth0.$vid"
4207648ac72SIdo Schimmel	log_test $? 0 "ndisc6"
4212ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 2
4227648ac72SIdo Schimmel	log_test $? 0 "NS suppression"
4237648ac72SIdo Schimmel
4247648ac72SIdo Schimmel	# Install an FDB entry for the remote host and check that nothing
4257648ac72SIdo Schimmel	# changes compared to the initial state.
4262ee2fc67SHangbin Liu	h2_mac=$(ip -n $h2 -j -p link show eth0.$vid | jq -r '.[]["address"]')
4272ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 fdb replace $h2_mac dev vx0 master static vlan $vid"
4287648ac72SIdo Schimmel	log_test $? 0 "FDB entry installation"
4297648ac72SIdo Schimmel
4302ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr -w 5000 $daddr eth0.$vid"
4317648ac72SIdo Schimmel	log_test $? 0 "ndisc6"
4322ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 3
4337648ac72SIdo Schimmel	log_test $? 0 "NS suppression"
4347648ac72SIdo Schimmel
4357648ac72SIdo Schimmel	# Install a neighbor on the matching SVI interface and check that NS
4367648ac72SIdo Schimmel	# messages are suppressed.
4372ee2fc67SHangbin Liu	run_cmd "ip -n $sw1 neigh replace $daddr lladdr $h2_mac nud permanent dev br0.$vid"
4387648ac72SIdo Schimmel	log_test $? 0 "Neighbor entry installation"
4397648ac72SIdo Schimmel
4402ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr -w 5000 $daddr eth0.$vid"
4417648ac72SIdo Schimmel	log_test $? 0 "ndisc6"
4422ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 3
4437648ac72SIdo Schimmel	log_test $? 0 "NS suppression"
4447648ac72SIdo Schimmel
4457648ac72SIdo Schimmel	# Take the second host down and check that NS messages are suppressed
4467648ac72SIdo Schimmel	# and that ND messages are received.
4472ee2fc67SHangbin Liu	run_cmd "ip -n $h2 link set dev eth0.$vid down"
4487648ac72SIdo Schimmel	log_test $? 0 "H2 down"
4497648ac72SIdo Schimmel
4502ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr -w 5000 $daddr eth0.$vid"
4517648ac72SIdo Schimmel	log_test $? 0 "ndisc6"
4522ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 3
4537648ac72SIdo Schimmel	log_test $? 0 "NS suppression"
4547648ac72SIdo Schimmel
4552ee2fc67SHangbin Liu	run_cmd "ip -n $h2 link set dev eth0.$vid up"
4567648ac72SIdo Schimmel	log_test $? 0 "H2 up"
4577648ac72SIdo Schimmel
4587648ac72SIdo Schimmel	# Disable neighbor suppression and check that NS messages are no longer
4597648ac72SIdo Schimmel	# suppressed.
4602ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 link set dev vx0 neigh_suppress off"
4612ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d link show dev vx0 | grep \"neigh_suppress off\""
4627648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is off"
4637648ac72SIdo Schimmel
4642ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr -w 5000 $daddr eth0.$vid"
4657648ac72SIdo Schimmel	log_test $? 0 "ndisc6"
4662ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 4
4677648ac72SIdo Schimmel	log_test $? 0 "NS suppression"
4687648ac72SIdo Schimmel
4697648ac72SIdo Schimmel	# Take the second host down and check that NS messages are not
4707648ac72SIdo Schimmel	# suppressed and that ND messages are not received.
4712ee2fc67SHangbin Liu	run_cmd "ip -n $h2 link set dev eth0.$vid down"
4727648ac72SIdo Schimmel	log_test $? 0 "H2 down"
4737648ac72SIdo Schimmel
4742ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr -w 5000 $daddr eth0.$vid"
4757648ac72SIdo Schimmel	log_test $? 2 "ndisc6"
4762ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 5
4777648ac72SIdo Schimmel	log_test $? 0 "NS suppression"
4787648ac72SIdo Schimmel}
4797648ac72SIdo Schimmel
4807648ac72SIdo Schimmelneigh_suppress_ns()
4817648ac72SIdo Schimmel{
4827648ac72SIdo Schimmel	local vid=10
4837648ac72SIdo Schimmel	local saddr=2001:db8:1::1
4847648ac72SIdo Schimmel	local daddr=2001:db8:1::2
4857648ac72SIdo Schimmel	local maddr=ff02::1:ff00:2
4867648ac72SIdo Schimmel
4877648ac72SIdo Schimmel	neigh_suppress_ns_common $vid $saddr $daddr $maddr
4887648ac72SIdo Schimmel
4897648ac72SIdo Schimmel	vid=20
4907648ac72SIdo Schimmel	saddr=2001:db8:2::1
4917648ac72SIdo Schimmel	daddr=2001:db8:2::2
4927648ac72SIdo Schimmel	maddr=ff02::1:ff00:2
4937648ac72SIdo Schimmel
4947648ac72SIdo Schimmel	neigh_suppress_ns_common $vid $saddr $daddr $maddr
4957648ac72SIdo Schimmel}
4967648ac72SIdo Schimmel
4977648ac72SIdo Schimmelneigh_vlan_suppress_arp()
4987648ac72SIdo Schimmel{
4997648ac72SIdo Schimmel	local vid1=10
5007648ac72SIdo Schimmel	local vid2=20
5017648ac72SIdo Schimmel	local sip1=192.0.2.1
5027648ac72SIdo Schimmel	local sip2=192.0.2.17
5037648ac72SIdo Schimmel	local tip1=192.0.2.2
5047648ac72SIdo Schimmel	local tip2=192.0.2.18
5057648ac72SIdo Schimmel	local h2_mac1
5067648ac72SIdo Schimmel	local h2_mac2
5077648ac72SIdo Schimmel
5087648ac72SIdo Schimmel	echo
5097648ac72SIdo Schimmel	echo "Per-{Port, VLAN} ARP suppression"
5107648ac72SIdo Schimmel	echo "--------------------------------"
5117648ac72SIdo Schimmel
5122ee2fc67SHangbin Liu	run_cmd "tc -n $sw1 qdisc replace dev vx0 clsact"
5132ee2fc67SHangbin Liu	run_cmd "tc -n $sw1 filter replace dev vx0 egress pref 1 handle 101 proto 0x0806 flower indev swp1 arp_tip $tip1 arp_sip $sip1 arp_op request action pass"
5142ee2fc67SHangbin Liu	run_cmd "tc -n $sw1 filter replace dev vx0 egress pref 1 handle 102 proto 0x0806 flower indev swp1 arp_tip $tip2 arp_sip $sip2 arp_op request action pass"
5157648ac72SIdo Schimmel
5162ee2fc67SHangbin Liu	h2_mac1=$(ip -n $h2 -j -p link show eth0.$vid1 | jq -r '.[]["address"]')
5172ee2fc67SHangbin Liu	h2_mac2=$(ip -n $h2 -j -p link show eth0.$vid2 | jq -r '.[]["address"]')
5182ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 fdb replace $h2_mac1 dev vx0 master static vlan $vid1"
5192ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 fdb replace $h2_mac2 dev vx0 master static vlan $vid2"
5202ee2fc67SHangbin Liu	run_cmd "ip -n $sw1 neigh replace $tip1 lladdr $h2_mac1 nud permanent dev br0.$vid1"
5212ee2fc67SHangbin Liu	run_cmd "ip -n $sw1 neigh replace $tip2 lladdr $h2_mac2 nud permanent dev br0.$vid2"
5227648ac72SIdo Schimmel
5237648ac72SIdo Schimmel	# Enable per-{Port, VLAN} neighbor suppression and check that ARP
5247648ac72SIdo Schimmel	# requests are not suppressed and that ARP replies are received.
5252ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 link set dev vx0 neigh_vlan_suppress on"
5262ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d link show dev vx0 | grep \"neigh_vlan_suppress on\""
5277648ac72SIdo Schimmel	log_test $? 0 "\"neigh_vlan_suppress\" is on"
5287648ac72SIdo Schimmel
5292ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip1 -I eth0.$vid1 $tip1"
5307648ac72SIdo Schimmel	log_test $? 0 "arping (VLAN $vid1)"
5312ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip2 -I eth0.$vid2 $tip2"
5327648ac72SIdo Schimmel	log_test $? 0 "arping (VLAN $vid2)"
5337648ac72SIdo Schimmel
5342ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 1
5357648ac72SIdo Schimmel	log_test $? 0 "ARP suppression (VLAN $vid1)"
5362ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 102 1
5377648ac72SIdo Schimmel	log_test $? 0 "ARP suppression (VLAN $vid2)"
5387648ac72SIdo Schimmel
5397648ac72SIdo Schimmel	# Enable neighbor suppression on VLAN 10 and check that only on this
5407648ac72SIdo Schimmel	# VLAN ARP requests are suppressed.
5412ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 vlan set vid $vid1 dev vx0 neigh_suppress on"
5422ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d vlan show dev vx0 vid $vid1 | grep \"neigh_suppress on\""
5437648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is on (VLAN $vid1)"
5442ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d vlan show dev vx0 vid $vid2 | grep \"neigh_suppress off\""
5457648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is off (VLAN $vid2)"
5467648ac72SIdo Schimmel
5472ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip1 -I eth0.$vid1 $tip1"
5487648ac72SIdo Schimmel	log_test $? 0 "arping (VLAN $vid1)"
5492ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip2 -I eth0.$vid2 $tip2"
5507648ac72SIdo Schimmel	log_test $? 0 "arping (VLAN $vid2)"
5517648ac72SIdo Schimmel
5522ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 1
5537648ac72SIdo Schimmel	log_test $? 0 "ARP suppression (VLAN $vid1)"
5542ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 102 2
5557648ac72SIdo Schimmel	log_test $? 0 "ARP suppression (VLAN $vid2)"
5567648ac72SIdo Schimmel
5577648ac72SIdo Schimmel	# Enable neighbor suppression on the port and check that it has no
5587648ac72SIdo Schimmel	# effect compared to previous state.
5592ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 link set dev vx0 neigh_suppress on"
5602ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d link show dev vx0 | grep \"neigh_suppress on\""
5617648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is on"
5627648ac72SIdo Schimmel
5632ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip1 -I eth0.$vid1 $tip1"
5647648ac72SIdo Schimmel	log_test $? 0 "arping (VLAN $vid1)"
5652ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip2 -I eth0.$vid2 $tip2"
5667648ac72SIdo Schimmel	log_test $? 0 "arping (VLAN $vid2)"
5677648ac72SIdo Schimmel
5682ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 1
5697648ac72SIdo Schimmel	log_test $? 0 "ARP suppression (VLAN $vid1)"
5702ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 102 3
5717648ac72SIdo Schimmel	log_test $? 0 "ARP suppression (VLAN $vid2)"
5727648ac72SIdo Schimmel
5737648ac72SIdo Schimmel	# Disable neighbor suppression on the port and check that it has no
5747648ac72SIdo Schimmel	# effect compared to previous state.
5752ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 link set dev vx0 neigh_suppress off"
5762ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d link show dev vx0 | grep \"neigh_suppress off\""
5777648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is off"
5787648ac72SIdo Schimmel
5792ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip1 -I eth0.$vid1 $tip1"
5807648ac72SIdo Schimmel	log_test $? 0 "arping (VLAN $vid1)"
5812ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip2 -I eth0.$vid2 $tip2"
5827648ac72SIdo Schimmel	log_test $? 0 "arping (VLAN $vid2)"
5837648ac72SIdo Schimmel
5842ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 1
5857648ac72SIdo Schimmel	log_test $? 0 "ARP suppression (VLAN $vid1)"
5862ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 102 4
5877648ac72SIdo Schimmel	log_test $? 0 "ARP suppression (VLAN $vid2)"
5887648ac72SIdo Schimmel
5897648ac72SIdo Schimmel	# Disable neighbor suppression on VLAN 10 and check that ARP requests
5907648ac72SIdo Schimmel	# are no longer suppressed on this VLAN.
5912ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 vlan set vid $vid1 dev vx0 neigh_suppress off"
5922ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d vlan show dev vx0 vid $vid1 | grep \"neigh_suppress off\""
5937648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is off (VLAN $vid1)"
5947648ac72SIdo Schimmel
5952ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip1 -I eth0.$vid1 $tip1"
5967648ac72SIdo Schimmel	log_test $? 0 "arping (VLAN $vid1)"
5972ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip2 -I eth0.$vid2 $tip2"
5987648ac72SIdo Schimmel	log_test $? 0 "arping (VLAN $vid2)"
5997648ac72SIdo Schimmel
6002ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 2
6017648ac72SIdo Schimmel	log_test $? 0 "ARP suppression (VLAN $vid1)"
6022ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 102 5
6037648ac72SIdo Schimmel	log_test $? 0 "ARP suppression (VLAN $vid2)"
6047648ac72SIdo Schimmel
6057648ac72SIdo Schimmel	# Disable per-{Port, VLAN} neighbor suppression, enable neighbor
6067648ac72SIdo Schimmel	# suppression on the port and check that on both VLANs ARP requests are
6077648ac72SIdo Schimmel	# suppressed.
6082ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 link set dev vx0 neigh_vlan_suppress off"
6092ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d link show dev vx0 | grep \"neigh_vlan_suppress off\""
6107648ac72SIdo Schimmel	log_test $? 0 "\"neigh_vlan_suppress\" is off"
6117648ac72SIdo Schimmel
6122ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 link set dev vx0 neigh_suppress on"
6132ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d link show dev vx0 | grep \"neigh_suppress on\""
6147648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is on"
6157648ac72SIdo Schimmel
6162ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip1 -I eth0.$vid1 $tip1"
6177648ac72SIdo Schimmel	log_test $? 0 "arping (VLAN $vid1)"
6182ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 arping -q -b -c 1 -w 5 -s $sip2 -I eth0.$vid2 $tip2"
6197648ac72SIdo Schimmel	log_test $? 0 "arping (VLAN $vid2)"
6207648ac72SIdo Schimmel
6212ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 2
6227648ac72SIdo Schimmel	log_test $? 0 "ARP suppression (VLAN $vid1)"
6232ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 102 5
6247648ac72SIdo Schimmel	log_test $? 0 "ARP suppression (VLAN $vid2)"
6257648ac72SIdo Schimmel}
6267648ac72SIdo Schimmel
6277648ac72SIdo Schimmelneigh_vlan_suppress_ns()
6287648ac72SIdo Schimmel{
6297648ac72SIdo Schimmel	local vid1=10
6307648ac72SIdo Schimmel	local vid2=20
6317648ac72SIdo Schimmel	local saddr1=2001:db8:1::1
6327648ac72SIdo Schimmel	local saddr2=2001:db8:2::1
6337648ac72SIdo Schimmel	local daddr1=2001:db8:1::2
6347648ac72SIdo Schimmel	local daddr2=2001:db8:2::2
6357648ac72SIdo Schimmel	local maddr=ff02::1:ff00:2
6367648ac72SIdo Schimmel	local h2_mac1
6377648ac72SIdo Schimmel	local h2_mac2
6387648ac72SIdo Schimmel
6397648ac72SIdo Schimmel	echo
6407648ac72SIdo Schimmel	echo "Per-{Port, VLAN} NS suppression"
6417648ac72SIdo Schimmel	echo "-------------------------------"
6427648ac72SIdo Schimmel
6432ee2fc67SHangbin Liu	run_cmd "tc -n $sw1 qdisc replace dev vx0 clsact"
6442ee2fc67SHangbin Liu	run_cmd "tc -n $sw1 filter replace dev vx0 egress pref 1 handle 101 proto ipv6 flower indev swp1 ip_proto icmpv6 dst_ip $maddr src_ip $saddr1 type 135 code 0 action pass"
6452ee2fc67SHangbin Liu	run_cmd "tc -n $sw1 filter replace dev vx0 egress pref 1 handle 102 proto ipv6 flower indev swp1 ip_proto icmpv6 dst_ip $maddr src_ip $saddr2 type 135 code 0 action pass"
6467648ac72SIdo Schimmel
6472ee2fc67SHangbin Liu	h2_mac1=$(ip -n $h2 -j -p link show eth0.$vid1 | jq -r '.[]["address"]')
6482ee2fc67SHangbin Liu	h2_mac2=$(ip -n $h2 -j -p link show eth0.$vid2 | jq -r '.[]["address"]')
6492ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 fdb replace $h2_mac1 dev vx0 master static vlan $vid1"
6502ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 fdb replace $h2_mac2 dev vx0 master static vlan $vid2"
6512ee2fc67SHangbin Liu	run_cmd "ip -n $sw1 neigh replace $daddr1 lladdr $h2_mac1 nud permanent dev br0.$vid1"
6522ee2fc67SHangbin Liu	run_cmd "ip -n $sw1 neigh replace $daddr2 lladdr $h2_mac2 nud permanent dev br0.$vid2"
6537648ac72SIdo Schimmel
6547648ac72SIdo Schimmel	# Enable per-{Port, VLAN} neighbor suppression and check that NS
6557648ac72SIdo Schimmel	# messages are not suppressed and that ND messages are received.
6562ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 link set dev vx0 neigh_vlan_suppress on"
6572ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d link show dev vx0 | grep \"neigh_vlan_suppress on\""
6587648ac72SIdo Schimmel	log_test $? 0 "\"neigh_vlan_suppress\" is on"
6597648ac72SIdo Schimmel
6602ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr1 -w 5000 $daddr1 eth0.$vid1"
6617648ac72SIdo Schimmel	log_test $? 0 "ndisc6 (VLAN $vid1)"
6622ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr2 -w 5000 $daddr2 eth0.$vid2"
6637648ac72SIdo Schimmel	log_test $? 0 "ndisc6 (VLAN $vid2)"
6647648ac72SIdo Schimmel
6652ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 1
6667648ac72SIdo Schimmel	log_test $? 0 "NS suppression (VLAN $vid1)"
6672ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 102 1
6687648ac72SIdo Schimmel	log_test $? 0 "NS suppression (VLAN $vid2)"
6697648ac72SIdo Schimmel
6707648ac72SIdo Schimmel	# Enable neighbor suppression on VLAN 10 and check that only on this
6717648ac72SIdo Schimmel	# VLAN NS messages are suppressed.
6722ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 vlan set vid $vid1 dev vx0 neigh_suppress on"
6732ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d vlan show dev vx0 vid $vid1 | grep \"neigh_suppress on\""
6747648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is on (VLAN $vid1)"
6752ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d vlan show dev vx0 vid $vid2 | grep \"neigh_suppress off\""
6767648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is off (VLAN $vid2)"
6777648ac72SIdo Schimmel
6782ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr1 -w 5000 $daddr1 eth0.$vid1"
6797648ac72SIdo Schimmel	log_test $? 0 "ndisc6 (VLAN $vid1)"
6802ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr2 -w 5000 $daddr2 eth0.$vid2"
6817648ac72SIdo Schimmel	log_test $? 0 "ndisc6 (VLAN $vid2)"
6827648ac72SIdo Schimmel
6832ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 1
6847648ac72SIdo Schimmel	log_test $? 0 "NS suppression (VLAN $vid1)"
6852ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 102 2
6867648ac72SIdo Schimmel	log_test $? 0 "NS suppression (VLAN $vid2)"
6877648ac72SIdo Schimmel
6887648ac72SIdo Schimmel	# Enable neighbor suppression on the port and check that it has no
6897648ac72SIdo Schimmel	# effect compared to previous state.
6902ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 link set dev vx0 neigh_suppress on"
6912ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d link show dev vx0 | grep \"neigh_suppress on\""
6927648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is on"
6937648ac72SIdo Schimmel
6942ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr1 -w 5000 $daddr1 eth0.$vid1"
6957648ac72SIdo Schimmel	log_test $? 0 "ndisc6 (VLAN $vid1)"
6962ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr2 -w 5000 $daddr2 eth0.$vid2"
6977648ac72SIdo Schimmel	log_test $? 0 "ndisc6 (VLAN $vid2)"
6987648ac72SIdo Schimmel
6992ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 1
7007648ac72SIdo Schimmel	log_test $? 0 "NS suppression (VLAN $vid1)"
7012ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 102 3
7027648ac72SIdo Schimmel	log_test $? 0 "NS suppression (VLAN $vid2)"
7037648ac72SIdo Schimmel
7047648ac72SIdo Schimmel	# Disable neighbor suppression on the port and check that it has no
7057648ac72SIdo Schimmel	# effect compared to previous state.
7062ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 link set dev vx0 neigh_suppress off"
7072ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d link show dev vx0 | grep \"neigh_suppress off\""
7087648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is off"
7097648ac72SIdo Schimmel
7102ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr1 -w 5000 $daddr1 eth0.$vid1"
7117648ac72SIdo Schimmel	log_test $? 0 "ndisc6 (VLAN $vid1)"
7122ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr2 -w 5000 $daddr2 eth0.$vid2"
7137648ac72SIdo Schimmel	log_test $? 0 "ndisc6 (VLAN $vid2)"
7147648ac72SIdo Schimmel
7152ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 1
7167648ac72SIdo Schimmel	log_test $? 0 "NS suppression (VLAN $vid1)"
7172ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 102 4
7187648ac72SIdo Schimmel	log_test $? 0 "NS suppression (VLAN $vid2)"
7197648ac72SIdo Schimmel
7207648ac72SIdo Schimmel	# Disable neighbor suppression on VLAN 10 and check that NS messages
7217648ac72SIdo Schimmel	# are no longer suppressed on this VLAN.
7222ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 vlan set vid $vid1 dev vx0 neigh_suppress off"
7232ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d vlan show dev vx0 vid $vid1 | grep \"neigh_suppress off\""
7247648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is off (VLAN $vid1)"
7257648ac72SIdo Schimmel
7262ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr1 -w 5000 $daddr1 eth0.$vid1"
7277648ac72SIdo Schimmel	log_test $? 0 "ndisc6 (VLAN $vid1)"
7282ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr2 -w 5000 $daddr2 eth0.$vid2"
7297648ac72SIdo Schimmel	log_test $? 0 "ndisc6 (VLAN $vid2)"
7307648ac72SIdo Schimmel
7312ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 2
7327648ac72SIdo Schimmel	log_test $? 0 "NS suppression (VLAN $vid1)"
7332ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 102 5
7347648ac72SIdo Schimmel	log_test $? 0 "NS suppression (VLAN $vid2)"
7357648ac72SIdo Schimmel
7367648ac72SIdo Schimmel	# Disable per-{Port, VLAN} neighbor suppression, enable neighbor
7377648ac72SIdo Schimmel	# suppression on the port and check that on both VLANs NS messages are
7387648ac72SIdo Schimmel	# suppressed.
7392ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 link set dev vx0 neigh_vlan_suppress off"
7402ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d link show dev vx0 | grep \"neigh_vlan_suppress off\""
7417648ac72SIdo Schimmel	log_test $? 0 "\"neigh_vlan_suppress\" is off"
7427648ac72SIdo Schimmel
7432ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 link set dev vx0 neigh_suppress on"
7442ee2fc67SHangbin Liu	run_cmd "bridge -n $sw1 -d link show dev vx0 | grep \"neigh_suppress on\""
7457648ac72SIdo Schimmel	log_test $? 0 "\"neigh_suppress\" is on"
7467648ac72SIdo Schimmel
7472ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr1 -w 5000 $daddr1 eth0.$vid1"
7487648ac72SIdo Schimmel	log_test $? 0 "ndisc6 (VLAN $vid1)"
7492ee2fc67SHangbin Liu	run_cmd "ip netns exec $h1 ndisc6 -q -r 1 -s $saddr2 -w 5000 $daddr2 eth0.$vid2"
7507648ac72SIdo Schimmel	log_test $? 0 "ndisc6 (VLAN $vid2)"
7517648ac72SIdo Schimmel
7522ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 101 2
7537648ac72SIdo Schimmel	log_test $? 0 "NS suppression (VLAN $vid1)"
7542ee2fc67SHangbin Liu	tc_check_packets $sw1 "dev vx0 egress" 102 5
7557648ac72SIdo Schimmel	log_test $? 0 "NS suppression (VLAN $vid2)"
7567648ac72SIdo Schimmel}
7577648ac72SIdo Schimmel
7587648ac72SIdo Schimmel################################################################################
7597648ac72SIdo Schimmel# Usage
7607648ac72SIdo Schimmel
7617648ac72SIdo Schimmelusage()
7627648ac72SIdo Schimmel{
7637648ac72SIdo Schimmel	cat <<EOF
7647648ac72SIdo Schimmelusage: ${0##*/} OPTS
7657648ac72SIdo Schimmel
7667648ac72SIdo Schimmel        -t <test>   Test(s) to run (default: all)
7677648ac72SIdo Schimmel                    (options: $TESTS)
7687648ac72SIdo Schimmel        -p          Pause on fail
7697648ac72SIdo Schimmel        -P          Pause after each test before cleanup
7707648ac72SIdo Schimmel        -v          Verbose mode (show commands and output)
7717648ac72SIdo SchimmelEOF
7727648ac72SIdo Schimmel}
7737648ac72SIdo Schimmel
7747648ac72SIdo Schimmel################################################################################
7757648ac72SIdo Schimmel# Main
7767648ac72SIdo Schimmel
7777648ac72SIdo Schimmeltrap cleanup EXIT
7787648ac72SIdo Schimmel
7797648ac72SIdo Schimmelwhile getopts ":t:pPvh" opt; do
7807648ac72SIdo Schimmel	case $opt in
7817648ac72SIdo Schimmel		t) TESTS=$OPTARG;;
7827648ac72SIdo Schimmel		p) PAUSE_ON_FAIL=yes;;
7837648ac72SIdo Schimmel		P) PAUSE=yes;;
7847648ac72SIdo Schimmel		v) VERBOSE=$(($VERBOSE + 1));;
7857648ac72SIdo Schimmel		h) usage; exit 0;;
7867648ac72SIdo Schimmel		*) usage; exit 1;;
7877648ac72SIdo Schimmel	esac
7887648ac72SIdo Schimmeldone
7897648ac72SIdo Schimmel
7907648ac72SIdo Schimmel# Make sure we don't pause twice.
7917648ac72SIdo Schimmel[ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no
7927648ac72SIdo Schimmel
7937648ac72SIdo Schimmelif [ "$(id -u)" -ne 0 ];then
7947648ac72SIdo Schimmel	echo "SKIP: Need root privileges"
7957648ac72SIdo Schimmel	exit $ksft_skip;
7967648ac72SIdo Schimmelfi
7977648ac72SIdo Schimmel
7987648ac72SIdo Schimmelif [ ! -x "$(command -v ip)" ]; then
7997648ac72SIdo Schimmel	echo "SKIP: Could not run test without ip tool"
8007648ac72SIdo Schimmel	exit $ksft_skip
8017648ac72SIdo Schimmelfi
8027648ac72SIdo Schimmel
8037648ac72SIdo Schimmelif [ ! -x "$(command -v bridge)" ]; then
8047648ac72SIdo Schimmel	echo "SKIP: Could not run test without bridge tool"
8057648ac72SIdo Schimmel	exit $ksft_skip
8067648ac72SIdo Schimmelfi
8077648ac72SIdo Schimmel
8087648ac72SIdo Schimmelif [ ! -x "$(command -v tc)" ]; then
8097648ac72SIdo Schimmel	echo "SKIP: Could not run test without tc tool"
8107648ac72SIdo Schimmel	exit $ksft_skip
8117648ac72SIdo Schimmelfi
8127648ac72SIdo Schimmel
8137648ac72SIdo Schimmelif [ ! -x "$(command -v arping)" ]; then
8147648ac72SIdo Schimmel	echo "SKIP: Could not run test without arping tool"
8157648ac72SIdo Schimmel	exit $ksft_skip
8167648ac72SIdo Schimmelfi
8177648ac72SIdo Schimmel
8187648ac72SIdo Schimmelif [ ! -x "$(command -v ndisc6)" ]; then
8197648ac72SIdo Schimmel	echo "SKIP: Could not run test without ndisc6 tool"
8207648ac72SIdo Schimmel	exit $ksft_skip
8217648ac72SIdo Schimmelfi
8227648ac72SIdo Schimmel
8237648ac72SIdo Schimmelif [ ! -x "$(command -v jq)" ]; then
8247648ac72SIdo Schimmel	echo "SKIP: Could not run test without jq tool"
8257648ac72SIdo Schimmel	exit $ksft_skip
8267648ac72SIdo Schimmelfi
8277648ac72SIdo Schimmel
8287648ac72SIdo Schimmelbridge link help 2>&1 | grep -q "neigh_vlan_suppress"
8297648ac72SIdo Schimmelif [ $? -ne 0 ]; then
8307648ac72SIdo Schimmel   echo "SKIP: iproute2 bridge too old, missing per-VLAN neighbor suppression support"
8317648ac72SIdo Schimmel   exit $ksft_skip
8327648ac72SIdo Schimmelfi
8337648ac72SIdo Schimmel
8347648ac72SIdo Schimmel# Start clean.
8357648ac72SIdo Schimmelcleanup
8367648ac72SIdo Schimmel
8377648ac72SIdo Schimmelfor t in $TESTS
8387648ac72SIdo Schimmeldo
8397648ac72SIdo Schimmel	setup; $t; cleanup;
8407648ac72SIdo Schimmeldone
8417648ac72SIdo Schimmel
8427648ac72SIdo Schimmelif [ "$TESTS" != "none" ]; then
8437648ac72SIdo Schimmel	printf "\nTests passed: %3d\n" ${nsuccess}
8447648ac72SIdo Schimmel	printf "Tests failed: %3d\n"   ${nfail}
8457648ac72SIdo Schimmelfi
8467648ac72SIdo Schimmel
8477648ac72SIdo Schimmelexit $ret
848