brintos

brintos / linux-shallow public Read only

0
0
Text · 4.2 KiB · 90f8a24 Raw
205 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4ALL_TESTS="ping_ipv4 ping_ipv6 learning flooding vlan_deletion extern_learn other_tpid"5NUM_NETIFS=46CHECK_TC="yes"7source lib.sh8 9h1_create()10{11	simple_if_init $h1 192.0.2.1/24 2001:db8:1::1/6412}13 14h1_destroy()15{16	simple_if_fini $h1 192.0.2.1/24 2001:db8:1::1/6417}18 19h2_create()20{21	simple_if_init $h2 192.0.2.2/24 2001:db8:1::2/6422}23 24h2_destroy()25{26	simple_if_fini $h2 192.0.2.2/24 2001:db8:1::2/6427}28 29switch_create()30{31	ip link add dev br0 type bridge \32		vlan_filtering 1 \33		ageing_time $LOW_AGEING_TIME \34		mcast_snooping 035 36	ip link set dev $swp1 master br037	ip link set dev $swp2 master br038 39	ip link set dev br0 up40	ip link set dev $swp1 up41	ip link set dev $swp2 up42}43 44switch_destroy()45{46	ip link set dev $swp2 down47	ip link set dev $swp1 down48 49	ip link del dev br050}51 52setup_prepare()53{54	h1=${NETIFS[p1]}55	swp1=${NETIFS[p2]}56 57	swp2=${NETIFS[p3]}58	h2=${NETIFS[p4]}59 60	vrf_prepare61 62	h1_create63	h2_create64 65	switch_create66}67 68cleanup()69{70	pre_cleanup71 72	switch_destroy73 74	h2_destroy75	h1_destroy76 77	vrf_cleanup78}79 80ping_ipv4()81{82	ping_test $h1 192.0.2.283}84 85ping_ipv6()86{87	ping6_test $h1 2001:db8:1::288}89 90learning()91{92	learning_test "br0" $swp1 $h1 $h293}94 95flooding()96{97	flood_test $swp2 $h1 $h298}99 100vlan_deletion()101{102	# Test that the deletion of a VLAN on a bridge port does not affect103	# the PVID VLAN104	log_info "Add and delete a VLAN on bridge port $swp1"105 106	bridge vlan add vid 10 dev $swp1107	bridge vlan del vid 10 dev $swp1108 109	ping_ipv4110	ping_ipv6111}112 113extern_learn()114{115	local mac=de:ad:be:ef:13:37116	local ageing_time117 118	# Test that externally learned FDB entries can roam, but not age out119	RET=0120 121	bridge fdb add de:ad:be:ef:13:37 dev $swp1 master extern_learn vlan 1122 123	bridge fdb show brport $swp1 | grep -q de:ad:be:ef:13:37124	check_err $? "Did not find FDB entry when should"125 126	# Wait for 10 seconds after the ageing time to make sure the FDB entry127	# was not aged out128	ageing_time=$(bridge_ageing_time_get br0)129	sleep $((ageing_time + 10))130 131	bridge fdb show brport $swp1 | grep -q de:ad:be:ef:13:37132	check_err $? "FDB entry was aged out when should not"133 134	$MZ $h2 -c 1 -p 64 -a $mac -t ip -q135 136	bridge fdb show brport $swp2 | grep -q de:ad:be:ef:13:37137	check_err $? "FDB entry did not roam when should"138 139	log_test "Externally learned FDB entry - ageing & roaming"140 141	bridge fdb del de:ad:be:ef:13:37 dev $swp2 master vlan 1 &> /dev/null142	bridge fdb del de:ad:be:ef:13:37 dev $swp1 master vlan 1 &> /dev/null143}144 145other_tpid()146{147	local mac=de:ad:be:ef:13:37148 149	# Test that packets with TPID 802.1ad VID 3 + TPID 802.1Q VID 5 are150	# classified as untagged by a bridge with vlan_protocol 802.1Q, and151	# are processed in the PVID of the ingress port (here 1). Not VID 3,152	# and not VID 5.153	RET=0154 155	tc qdisc add dev $h2 clsact156	tc filter add dev $h2 ingress protocol all pref 1 handle 101 \157		flower dst_mac $mac action drop158	ip link set $h2 promisc on159	ethtool -K $h2 rx-vlan-filter off rx-vlan-stag-filter off160 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 1163 164	# Match on 'self' addresses as well, for those drivers which165	# do not push their learned addresses to the bridge software166	# database167	bridge -j fdb show $swp1 | \168		jq -e ".[] | select(.mac == \"$(mac_get $h1)\") | select(.vlan == 1)" &> /dev/null169	check_err $? "FDB entry was not learned when it should"170 171	log_test "FDB entry in PVID for VLAN-tagged with other TPID"172 173	RET=0174	tc -j -s filter show dev $h2 ingress \175		| jq -e ".[] | select(.options.handle == 101) \176		| select(.options.actions[0].stats.packets == 1)" &> /dev/null177	check_err $? "Packet was not forwarded when it should"178	log_test "Reception of VLAN with other TPID as untagged"179 180	bridge vlan del dev $swp1 vid 1181 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 1184 185	RET=0186	tc -j -s filter show dev $h2 ingress \187		| jq -e ".[] | select(.options.handle == 101) \188		| select(.options.actions[0].stats.packets == 1)" &> /dev/null189	check_err $? "Packet was forwarded when should not"190	log_test "Reception of VLAN with other TPID as untagged (no PVID)"191 192	bridge vlan add dev $swp1 vid 1 pvid untagged193	ip link set $h2 promisc off194	tc qdisc del dev $h2 clsact195}196 197trap cleanup EXIT198 199setup_prepare200setup_wait201 202tests_run203 204exit $EXIT_STATUS205