Skip to content

Commit bf9de1d

Browse files
vladimirolteankuba-moo
authored andcommitted
selftests: net: bridge_vlan_aware: test untagged/8021p-tagged with and without PVID
Recent discussions around commit ad1afb0 ("vlan_dev: VLAN 0 should be treated as "no vlan tag" (802.1p packet)") have sparked the question what happens with the DSA (and possibly other switchdev) data path when the bridge says that ports should have no PVID VLAN, but the 8021q module, as the result of a NETDEV_UP event, decides it should add VID 0 to the RX filter of those bridge ports. Do those bridge ports receive packets tagged with VID 0 or not, now? We don't know, there is no test. In the veth realm, this passes trivially, because veth is not VLAN filtering and this, the 8021q module lacks the instinct to add VID 0 in the first place. In the realm of VLAN filtering NICs with no switchdev offload, this should also pass, because the VLAN groups of the software bridge are consulted, where it can clearly be seen that a PVID is missing, even though the packet was initially accepted by the NIC. The test only poses a challenge for switchdev drivers, which usually have to program to hardware both VLANs from RX filtering, as well as from switchdev. Especially when a switchdev port joins a VLAN-aware bridge, it is unavoidable that it gains the NETIF_F_HW_VLAN_CTAG_FILTER feature, i.e. any 8021q uppers that the bridge port may have must also be committed to the RX filtering table of the interface. When a VLAN-tagged packet is physically received by the port, it is initially indistinguishable whether it will reach the bridge data path or the 8021q upper data path. That is rather the final step of the new tests that we introduce. We need to build context up to that stage, which means the following: - we need to test that 802.1p (VID 0) tagged traffic is received in the first place (on bridge ports with a valid PVID). This is the "8021p" test. - we need to test that the usual paths of reaching a configuration with no PVID on a bridge port are all covered and they all reach the same state. Signed-off-by: Vladimir Oltean <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Tested-by: Ido Schimmel <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 5ec6d7d commit bf9de1d

File tree

1 file changed

+95
-1
lines changed

1 file changed

+95
-1
lines changed

tools/testing/selftests/net/forwarding/bridge_vlan_aware.sh

Lines changed: 95 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# SPDX-License-Identifier: GPL-2.0
33

4-
ALL_TESTS="ping_ipv4 ping_ipv6 learning flooding vlan_deletion extern_learn other_tpid"
4+
ALL_TESTS="ping_ipv4 ping_ipv6 learning flooding vlan_deletion extern_learn other_tpid 8021p drop_untagged"
55
NUM_NETIFS=4
66
CHECK_TC="yes"
77
source lib.sh
@@ -194,6 +194,100 @@ other_tpid()
194194
tc qdisc del dev $h2 clsact
195195
}
196196

197+
8021p_do()
198+
{
199+
local should_fail=$1; shift
200+
local mac=de:ad:be:ef:13:37
201+
202+
tc filter add dev $h2 ingress protocol all pref 1 handle 101 \
203+
flower dst_mac $mac action drop
204+
205+
$MZ -q $h1 -c 1 -b $mac -a own "81:00 00:00 08:00 aa-aa-aa-aa-aa-aa-aa-aa-aa"
206+
sleep 1
207+
208+
tc -j -s filter show dev $h2 ingress \
209+
| jq -e ".[] | select(.options.handle == 101) \
210+
| select(.options.actions[0].stats.packets == 1)" &> /dev/null
211+
check_err_fail $should_fail $? "802.1p-tagged reception"
212+
213+
tc filter del dev $h2 ingress pref 1
214+
}
215+
216+
8021p()
217+
{
218+
RET=0
219+
220+
tc qdisc add dev $h2 clsact
221+
ip link set $h2 promisc on
222+
223+
# Test that with the default_pvid, 1, packets tagged with VID 0 are
224+
# accepted.
225+
8021p_do 0
226+
227+
# Test that packets tagged with VID 0 are still accepted after changing
228+
# the default_pvid.
229+
ip link set br0 type bridge vlan_default_pvid 10
230+
8021p_do 0
231+
232+
log_test "Reception of 802.1p-tagged traffic"
233+
234+
ip link set $h2 promisc off
235+
tc qdisc del dev $h2 clsact
236+
}
237+
238+
send_untagged_and_8021p()
239+
{
240+
ping_do $h1 192.0.2.2
241+
check_fail $?
242+
243+
8021p_do 1
244+
}
245+
246+
drop_untagged()
247+
{
248+
RET=0
249+
250+
tc qdisc add dev $h2 clsact
251+
ip link set $h2 promisc on
252+
253+
# Test that with no PVID, untagged and 802.1p-tagged traffic is
254+
# dropped.
255+
ip link set br0 type bridge vlan_default_pvid 1
256+
257+
# First we reconfigure the default_pvid, 1, as a non-PVID VLAN.
258+
bridge vlan add dev $swp1 vid 1 untagged
259+
send_untagged_and_8021p
260+
bridge vlan add dev $swp1 vid 1 pvid untagged
261+
262+
# Next we try to delete VID 1 altogether
263+
bridge vlan del dev $swp1 vid 1
264+
send_untagged_and_8021p
265+
bridge vlan add dev $swp1 vid 1 pvid untagged
266+
267+
# Set up the bridge without a default_pvid, then check that the 8021q
268+
# module, when the bridge port goes down and then up again, does not
269+
# accidentally re-enable untagged packet reception.
270+
ip link set br0 type bridge vlan_default_pvid 0
271+
ip link set $swp1 down
272+
ip link set $swp1 up
273+
setup_wait
274+
send_untagged_and_8021p
275+
276+
# Remove swp1 as a bridge port and let it rejoin the bridge while it
277+
# has no default_pvid.
278+
ip link set $swp1 nomaster
279+
ip link set $swp1 master br0
280+
send_untagged_and_8021p
281+
282+
# Restore settings
283+
ip link set br0 type bridge vlan_default_pvid 1
284+
285+
log_test "Dropping of untagged and 802.1p-tagged traffic with no PVID"
286+
287+
ip link set $h2 promisc off
288+
tc qdisc del dev $h2 clsact
289+
}
290+
197291
trap cleanup EXIT
198292

199293
setup_prepare

0 commit comments

Comments
 (0)