Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / tools / testing / selftests / net / forwarding / bridge_vlan_aware.sh
blob90f8a244ea90159d867a8e6c1231dcf31d2ae244
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 ALL_TESTS="ping_ipv4 ping_ipv6 learning flooding vlan_deletion extern_learn other_tpid"
5 NUM_NETIFS=4
6 CHECK_TC="yes"
7 source lib.sh
9 h1_create()
11 simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/64
14 h1_destroy()
16 simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/64
19 h2_create()
21 simple_if_init $h2 192.0.2.2/24 2001:db8:1::2/64
24 h2_destroy()
26 simple_if_fini $h2 192.0.2.2/24 2001:db8:1::2/64
29 switch_create()
31 ip link add dev br0 type bridge \
32 vlan_filtering 1 \
33 ageing_time $LOW_AGEING_TIME \
34 mcast_snooping 0
36 ip link set dev $swp1 master br0
37 ip link set dev $swp2 master br0
39 ip link set dev br0 up
40 ip link set dev $swp1 up
41 ip link set dev $swp2 up
44 switch_destroy()
46 ip link set dev $swp2 down
47 ip link set dev $swp1 down
49 ip link del dev br0
52 setup_prepare()
54 h1=${NETIFS[p1]}
55 swp1=${NETIFS[p2]}
57 swp2=${NETIFS[p3]}
58 h2=${NETIFS[p4]}
60 vrf_prepare
62 h1_create
63 h2_create
65 switch_create
68 cleanup()
70 pre_cleanup
72 switch_destroy
74 h2_destroy
75 h1_destroy
77 vrf_cleanup
80 ping_ipv4()
82 ping_test $h1 192.0.2.2
85 ping_ipv6()
87 ping6_test $h1 2001:db8:1::2
90 learning()
92 learning_test "br0" $swp1 $h1 $h2
95 flooding()
97 flood_test $swp2 $h1 $h2
100 vlan_deletion()
102 # Test that the deletion of a VLAN on a bridge port does not affect
103 # the PVID VLAN
104 log_info "Add and delete a VLAN on bridge port $swp1"
106 bridge vlan add vid 10 dev $swp1
107 bridge vlan del vid 10 dev $swp1
109 ping_ipv4
110 ping_ipv6
113 extern_learn()
115 local mac=de:ad:be:ef:13:37
116 local ageing_time
118 # Test that externally learned FDB entries can roam, but not age out
119 RET=0
121 bridge fdb add de:ad:be:ef:13:37 dev $swp1 master extern_learn vlan 1
123 bridge fdb show brport $swp1 | grep -q de:ad:be:ef:13:37
124 check_err $? "Did not find FDB entry when should"
126 # Wait for 10 seconds after the ageing time to make sure the FDB entry
127 # was not aged out
128 ageing_time=$(bridge_ageing_time_get br0)
129 sleep $((ageing_time + 10))
131 bridge fdb show brport $swp1 | grep -q de:ad:be:ef:13:37
132 check_err $? "FDB entry was aged out when should not"
134 $MZ $h2 -c 1 -p 64 -a $mac -t ip -q
136 bridge fdb show brport $swp2 | grep -q de:ad:be:ef:13:37
137 check_err $? "FDB entry did not roam when should"
139 log_test "Externally learned FDB entry - ageing & roaming"
141 bridge fdb del de:ad:be:ef:13:37 dev $swp2 master vlan 1 &> /dev/null
142 bridge fdb del de:ad:be:ef:13:37 dev $swp1 master vlan 1 &> /dev/null
145 other_tpid()
147 local mac=de:ad:be:ef:13:37
149 # Test that packets with TPID 802.1ad VID 3 + TPID 802.1Q VID 5 are
150 # classified as untagged by a bridge with vlan_protocol 802.1Q, and
151 # are processed in the PVID of the ingress port (here 1). Not VID 3,
152 # and not VID 5.
153 RET=0
155 tc qdisc add dev $h2 clsact
156 tc filter add dev $h2 ingress protocol all pref 1 handle 101 \
157 flower dst_mac $mac action drop
158 ip link set $h2 promisc on
159 ethtool -K $h2 rx-vlan-filter off rx-vlan-stag-filter off
161 $MZ -q $h1 -c 1 -b $mac -a own "88:a8 00:03 81:00 00:05 08:00 aa-aa-aa-aa-aa-aa-aa-aa-aa"
162 sleep 1
164 # Match on 'self' addresses as well, for those drivers which
165 # do not push their learned addresses to the bridge software
166 # database
167 bridge -j fdb show $swp1 | \
168 jq -e ".[] | select(.mac == \"$(mac_get $h1)\") | select(.vlan == 1)" &> /dev/null
169 check_err $? "FDB entry was not learned when it should"
171 log_test "FDB entry in PVID for VLAN-tagged with other TPID"
173 RET=0
174 tc -j -s filter show dev $h2 ingress \
175 | jq -e ".[] | select(.options.handle == 101) \
176 | select(.options.actions[0].stats.packets == 1)" &> /dev/null
177 check_err $? "Packet was not forwarded when it should"
178 log_test "Reception of VLAN with other TPID as untagged"
180 bridge vlan del dev $swp1 vid 1
182 $MZ -q $h1 -c 1 -b $mac -a own "88:a8 00:03 81:00 00:05 08:00 aa-aa-aa-aa-aa-aa-aa-aa-aa"
183 sleep 1
185 RET=0
186 tc -j -s filter show dev $h2 ingress \
187 | jq -e ".[] | select(.options.handle == 101) \
188 | select(.options.actions[0].stats.packets == 1)" &> /dev/null
189 check_err $? "Packet was forwarded when should not"
190 log_test "Reception of VLAN with other TPID as untagged (no PVID)"
192 bridge vlan add dev $swp1 vid 1 pvid untagged
193 ip link set $h2 promisc off
194 tc qdisc del dev $h2 clsact
197 trap cleanup EXIT
199 setup_prepare
200 setup_wait
202 tests_run
204 exit $EXIT_STATUS