brintos

brintos / linux-shallow public Read only

0
0
Text · 14.4 KiB · c355487 Raw
597 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4ALL_TESTS="standalone vlan_unaware_bridge vlan_aware_bridge test_vlan \5	   vlan_over_vlan_unaware_bridged_port vlan_over_vlan_aware_bridged_port \6	   vlan_over_vlan_unaware_bridge vlan_over_vlan_aware_bridge"7NUM_NETIFS=28PING_COUNT=19REQUIRE_MTOOLS=yes10REQUIRE_MZ=no11 12source lib.sh13 14H1_IPV4="192.0.2.1"15H2_IPV4="192.0.2.2"16H1_IPV6="2001:db8:1::1"17H2_IPV6="2001:db8:1::2"18 19BRIDGE_ADDR="00:00:de:ad:be:ee"20MACVLAN_ADDR="00:00:de:ad:be:ef"21UNKNOWN_UC_ADDR1="de:ad:be:ef:ee:03"22UNKNOWN_UC_ADDR2="de:ad:be:ef:ee:04"23UNKNOWN_UC_ADDR3="de:ad:be:ef:ee:05"24JOINED_IPV4_MC_ADDR="225.1.2.3"25UNKNOWN_IPV4_MC_ADDR1="225.1.2.4"26UNKNOWN_IPV4_MC_ADDR2="225.1.2.5"27UNKNOWN_IPV4_MC_ADDR3="225.1.2.6"28JOINED_IPV6_MC_ADDR="ff2e::0102:0304"29UNKNOWN_IPV6_MC_ADDR1="ff2e::0102:0305"30UNKNOWN_IPV6_MC_ADDR2="ff2e::0102:0306"31UNKNOWN_IPV6_MC_ADDR3="ff2e::0102:0307"32 33JOINED_MACV4_MC_ADDR="01:00:5e:01:02:03"34UNKNOWN_MACV4_MC_ADDR1="01:00:5e:01:02:04"35UNKNOWN_MACV4_MC_ADDR2="01:00:5e:01:02:05"36UNKNOWN_MACV4_MC_ADDR3="01:00:5e:01:02:06"37JOINED_MACV6_MC_ADDR="33:33:01:02:03:04"38UNKNOWN_MACV6_MC_ADDR1="33:33:01:02:03:05"39UNKNOWN_MACV6_MC_ADDR2="33:33:01:02:03:06"40UNKNOWN_MACV6_MC_ADDR3="33:33:01:02:03:07"41 42PTP_1588_L2_SYNC=" \4301:1b:19:00:00:00 00:00:de:ad:be:ef 88:f7 00 02 \4400 2c 00 00 02 00 00 00 00 00 00 00 00 00 00 00 \4500 00 3e 37 63 ff fe cf 17 0e 00 01 00 00 00 00 \4600 00 00 00 00 00 00 00 00 00"47PTP_1588_L2_FOLLOW_UP=" \4801:1b:19:00:00:00 00:00:de:ad:be:ef 88:f7 08 02 \4900 2c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \5000 00 3e 37 63 ff fe cf 17 0e 00 01 00 00 02 00 \5100 00 66 83 c5 f1 17 97 ed f0"52PTP_1588_L2_PDELAY_REQ=" \5301:80:c2:00:00:0e 00:00:de:ad:be:ef 88:f7 02 02 \5400 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \5500 00 3e 37 63 ff fe cf 17 0e 00 01 00 06 05 7f \5600 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \5700 00 00 00"58PTP_1588_IPV4_SYNC=" \5901:00:5e:00:01:81 00:00:de:ad:be:ef 08:00 45 00 \6000 48 0a 9a 40 00 01 11 cb 88 c0 00 02 01 e0 00 \6101 81 01 3f 01 3f 00 34 a3 c8 00 02 00 2c 00 00 \6202 00 00 00 00 00 00 00 00 00 00 00 00 00 3e 37 \6363 ff fe cf 17 0e 00 01 00 00 00 00 00 00 00 00 \6400 00 00 00 00 00"65PTP_1588_IPV4_FOLLOW_UP="6601:00:5e:00:01:81 00:00:de:ad:be:ef 08:00 45 00 \6700 48 0a 9b 40 00 01 11 cb 87 c0 00 02 01 e0 00 \6801 81 01 40 01 40 00 34 a3 c8 08 02 00 2c 00 00 \6900 00 00 00 00 00 00 00 00 00 00 00 00 00 3e 37 \7063 ff fe cf 17 0e 00 01 00 00 02 00 00 00 66 83 \71c6 0f 1d 9a 61 87"72PTP_1588_IPV4_PDELAY_REQ=" \7301:00:5e:00:00:6b 00:00:de:ad:be:ef 08:00 45 00 \7400 52 35 a9 40 00 01 11 a1 85 c0 00 02 01 e0 00 \7500 6b 01 3f 01 3f 00 3e a2 bc 02 02 00 36 00 00 \7600 00 00 00 00 00 00 00 00 00 00 00 00 00 3e 37 \7763 ff fe cf 17 0e 00 01 00 01 05 7f 00 00 00 00 \7800 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"79PTP_1588_IPV6_SYNC=" \8033:33:00:00:01:81 00:00:de:ad:be:ef 86:dd 60 06 \817c 2f 00 36 11 01 20 01 0d b8 00 01 00 00 00 00 \8200 00 00 00 00 01 ff 0e 00 00 00 00 00 00 00 00 \8300 00 00 00 01 81 01 3f 01 3f 00 36 2e 92 00 02 \8400 2c 00 00 02 00 00 00 00 00 00 00 00 00 00 00 \8500 00 3e 37 63 ff fe cf 17 0e 00 01 00 00 00 00 \8600 00 00 00 00 00 00 00 00 00 00 00"87PTP_1588_IPV6_FOLLOW_UP=" \8833:33:00:00:01:81 00:00:de:ad:be:ef 86:dd 60 0a \8900 bc 00 36 11 01 20 01 0d b8 00 01 00 00 00 00 \9000 00 00 00 00 01 ff 0e 00 00 00 00 00 00 00 00 \9100 00 00 00 01 81 01 40 01 40 00 36 2e 92 08 02 \9200 2c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \9300 00 3e 37 63 ff fe cf 17 0e 00 01 00 00 02 00 \9400 00 66 83 c6 2a 32 09 bd 74 00 00"95PTP_1588_IPV6_PDELAY_REQ=" \9633:33:00:00:00:6b 00:00:de:ad:be:ef 86:dd 60 0c \975c fd 00 40 11 01 fe 80 00 00 00 00 00 00 3c 37 \9863 ff fe cf 17 0e ff 02 00 00 00 00 00 00 00 00 \9900 00 00 00 00 6b 01 3f 01 3f 00 40 b4 54 02 02 \10000 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \10100 00 3e 37 63 ff fe cf 17 0e 00 01 00 01 05 7f \10200 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 \10300 00 00 00 00 00"104 105# Disable promisc to ensure we don't receive unknown MAC DA packets106export TCPDUMP_EXTRA_FLAGS="-pl"107 108h1=${NETIFS[p1]}109h2=${NETIFS[p2]}110 111send_raw()112{113	local if_name=$1; shift114	local pkt="$1"; shift115	local smac=$(mac_get $if_name)116 117	pkt="${pkt/00:00:de:ad:be:ef/$smac}"118 119	$MZ -q $if_name "$pkt"120}121 122send_uc_ipv4()123{124	local if_name=$1125	local dmac=$2126 127	ip neigh add $H2_IPV4 lladdr $dmac dev $if_name128	ping_do $if_name $H2_IPV4129	ip neigh del $H2_IPV4 dev $if_name130}131 132check_rcv()133{134	local if_name=$1; shift135	local type=$1; shift136	local pattern=$1; shift137	local should_receive=$1; shift138	local test_name="$1"; shift139	local should_fail=140 141	[ $should_receive = true ] && should_fail=0 || should_fail=1142	RET=0143 144	tcpdump_show $if_name | grep -q "$pattern"145 146	check_err_fail "$should_fail" "$?" "reception"147 148	log_test "$test_name: $type"149}150 151mc_route_prepare()152{153	local if_name=$1154	local vrf_name=$(master_name_get $if_name)155 156	ip route add 225.100.1.0/24 dev $if_name vrf $vrf_name157	ip -6 route add ff2e::/64 dev $if_name vrf $vrf_name158}159 160mc_route_destroy()161{162	local if_name=$1163	local vrf_name=$(master_name_get $if_name)164 165	ip route del 225.100.1.0/24 dev $if_name vrf $vrf_name166	ip -6 route del ff2e::/64 dev $if_name vrf $vrf_name167}168 169run_test()170{171	local send_if_name=$1; shift172	local rcv_if_name=$1; shift173	local skip_ptp=$1; shift174	local no_unicast_flt=$1; shift175	local test_name="$1"; shift176	local smac=$(mac_get $send_if_name)177	local rcv_dmac=$(mac_get $rcv_if_name)178	local should_receive179 180	tcpdump_start $rcv_if_name181 182	mc_route_prepare $send_if_name183	mc_route_prepare $rcv_if_name184 185	send_uc_ipv4 $send_if_name $rcv_dmac186	send_uc_ipv4 $send_if_name $MACVLAN_ADDR187	send_uc_ipv4 $send_if_name $UNKNOWN_UC_ADDR1188 189	ip link set dev $rcv_if_name promisc on190	send_uc_ipv4 $send_if_name $UNKNOWN_UC_ADDR2191	mc_send $send_if_name $UNKNOWN_IPV4_MC_ADDR2192	mc_send $send_if_name $UNKNOWN_IPV6_MC_ADDR2193	ip link set dev $rcv_if_name promisc off194 195	mc_join $rcv_if_name $JOINED_IPV4_MC_ADDR196	mc_send $send_if_name $JOINED_IPV4_MC_ADDR197	mc_leave198 199	mc_join $rcv_if_name $JOINED_IPV6_MC_ADDR200	mc_send $send_if_name $JOINED_IPV6_MC_ADDR201	mc_leave202 203	mc_send $send_if_name $UNKNOWN_IPV4_MC_ADDR1204	mc_send $send_if_name $UNKNOWN_IPV6_MC_ADDR1205 206	ip link set dev $rcv_if_name allmulticast on207	send_uc_ipv4 $send_if_name $UNKNOWN_UC_ADDR3208	mc_send $send_if_name $UNKNOWN_IPV4_MC_ADDR3209	mc_send $send_if_name $UNKNOWN_IPV6_MC_ADDR3210	ip link set dev $rcv_if_name allmulticast off211 212	mc_route_destroy $rcv_if_name213	mc_route_destroy $send_if_name214 215	if [ $skip_ptp = false ]; then216		ip maddress add 01:1b:19:00:00:00 dev $rcv_if_name217		send_raw $send_if_name "$PTP_1588_L2_SYNC"218		send_raw $send_if_name "$PTP_1588_L2_FOLLOW_UP"219		ip maddress del 01:1b:19:00:00:00 dev $rcv_if_name220 221		ip maddress add 01:80:c2:00:00:0e dev $rcv_if_name222		send_raw $send_if_name "$PTP_1588_L2_PDELAY_REQ"223		ip maddress del 01:80:c2:00:00:0e dev $rcv_if_name224 225		mc_join $rcv_if_name 224.0.1.129226		send_raw $send_if_name "$PTP_1588_IPV4_SYNC"227		send_raw $send_if_name "$PTP_1588_IPV4_FOLLOW_UP"228		mc_leave229 230		mc_join $rcv_if_name 224.0.0.107231		send_raw $send_if_name "$PTP_1588_IPV4_PDELAY_REQ"232		mc_leave233 234		mc_join $rcv_if_name ff0e::181235		send_raw $send_if_name "$PTP_1588_IPV6_SYNC"236		send_raw $send_if_name "$PTP_1588_IPV6_FOLLOW_UP"237		mc_leave238 239		mc_join $rcv_if_name ff02::6b240		send_raw $send_if_name "$PTP_1588_IPV6_PDELAY_REQ"241		mc_leave242	fi243 244	sleep 1245 246	tcpdump_stop $rcv_if_name247 248	check_rcv $rcv_if_name "Unicast IPv4 to primary MAC address" \249		"$smac > $rcv_dmac, ethertype IPv4 (0x0800)" \250		true "$test_name"251 252	check_rcv $rcv_if_name "Unicast IPv4 to macvlan MAC address" \253		"$smac > $MACVLAN_ADDR, ethertype IPv4 (0x0800)" \254		true "$test_name"255 256	[ $no_unicast_flt = true ] && should_receive=true || should_receive=false257	check_rcv $rcv_if_name "Unicast IPv4 to unknown MAC address" \258		"$smac > $UNKNOWN_UC_ADDR1, ethertype IPv4 (0x0800)" \259		$should_receive "$test_name"260 261	check_rcv $rcv_if_name "Unicast IPv4 to unknown MAC address, promisc" \262		"$smac > $UNKNOWN_UC_ADDR2, ethertype IPv4 (0x0800)" \263		true "$test_name"264 265	[ $no_unicast_flt = true ] && should_receive=true || should_receive=false266	check_rcv $rcv_if_name \267		"Unicast IPv4 to unknown MAC address, allmulti" \268		"$smac > $UNKNOWN_UC_ADDR3, ethertype IPv4 (0x0800)" \269		$should_receive "$test_name"270 271	check_rcv $rcv_if_name "Multicast IPv4 to joined group" \272		"$smac > $JOINED_MACV4_MC_ADDR, ethertype IPv4 (0x0800)" \273		true "$test_name"274 275	xfail \276		check_rcv $rcv_if_name \277			"Multicast IPv4 to unknown group" \278			"$smac > $UNKNOWN_MACV4_MC_ADDR1, ethertype IPv4 (0x0800)" \279			false "$test_name"280 281	check_rcv $rcv_if_name "Multicast IPv4 to unknown group, promisc" \282		"$smac > $UNKNOWN_MACV4_MC_ADDR2, ethertype IPv4 (0x0800)" \283		true "$test_name"284 285	check_rcv $rcv_if_name "Multicast IPv4 to unknown group, allmulti" \286		"$smac > $UNKNOWN_MACV4_MC_ADDR3, ethertype IPv4 (0x0800)" \287		true "$test_name"288 289	check_rcv $rcv_if_name "Multicast IPv6 to joined group" \290		"$smac > $JOINED_MACV6_MC_ADDR, ethertype IPv6 (0x86dd)" \291		true "$test_name"292 293	xfail \294		check_rcv $rcv_if_name "Multicast IPv6 to unknown group" \295			"$smac > $UNKNOWN_MACV6_MC_ADDR1, ethertype IPv6 (0x86dd)" \296			false "$test_name"297 298	check_rcv $rcv_if_name "Multicast IPv6 to unknown group, promisc" \299		"$smac > $UNKNOWN_MACV6_MC_ADDR2, ethertype IPv6 (0x86dd)" \300		true "$test_name"301 302	check_rcv $rcv_if_name "Multicast IPv6 to unknown group, allmulti" \303		"$smac > $UNKNOWN_MACV6_MC_ADDR3, ethertype IPv6 (0x86dd)" \304		true "$test_name"305 306	if [ $skip_ptp = false ]; then307		check_rcv $rcv_if_name "1588v2 over L2 transport, Sync" \308			"ethertype PTP (0x88f7).* PTPv2.* msg type : sync msg" \309			true "$test_name"310 311		check_rcv $rcv_if_name "1588v2 over L2 transport, Follow-Up" \312			"ethertype PTP (0x88f7).* PTPv2.* msg type : follow up msg" \313			true "$test_name"314 315		check_rcv $rcv_if_name "1588v2 over L2 transport, Peer Delay Request" \316			"ethertype PTP (0x88f7).* PTPv2.* msg type : peer delay req msg" \317			true "$test_name"318 319		check_rcv $rcv_if_name "1588v2 over IPv4, Sync" \320			"ethertype IPv4 (0x0800).* PTPv2.* msg type : sync msg" \321			true "$test_name"322 323		check_rcv $rcv_if_name "1588v2 over IPv4, Follow-Up" \324			"ethertype IPv4 (0x0800).* PTPv2.* msg type : follow up msg" \325			true "$test_name"326 327		check_rcv $rcv_if_name "1588v2 over IPv4, Peer Delay Request" \328			"ethertype IPv4 (0x0800).* PTPv2.* msg type : peer delay req msg" \329			true "$test_name"330 331		check_rcv $rcv_if_name "1588v2 over IPv6, Sync" \332			"ethertype IPv6 (0x86dd).* PTPv2.* msg type : sync msg" \333			true "$test_name"334 335		check_rcv $rcv_if_name "1588v2 over IPv6, Follow-Up" \336			"ethertype IPv6 (0x86dd).* PTPv2.* msg type : follow up msg" \337			true "$test_name"338 339		check_rcv $rcv_if_name "1588v2 over IPv6, Peer Delay Request" \340			"ethertype IPv6 (0x86dd).* PTPv2.* msg type : peer delay req msg" \341			true "$test_name"342	fi343 344	tcpdump_cleanup $rcv_if_name345}346 347h1_create()348{349	simple_if_init $h1 $H1_IPV4/24 $H1_IPV6/64350}351 352h1_destroy()353{354	simple_if_fini $h1 $H1_IPV4/24 $H1_IPV6/64355}356 357h2_create()358{359	simple_if_init $h2 $H2_IPV4/24 $H2_IPV6/64360}361 362h2_destroy()363{364	simple_if_fini $h2 $H2_IPV4/24 $H2_IPV6/64365}366 367h1_vlan_create()368{369	simple_if_init $h1370	vlan_create $h1 100 v$h1 $H1_IPV4/24 $H1_IPV6/64371}372 373h1_vlan_destroy()374{375	vlan_destroy $h1 100376	simple_if_fini $h1377}378 379h2_vlan_create()380{381	simple_if_init $h2382	vlan_create $h2 100 v$h2 $H2_IPV4/24 $H2_IPV6/64383}384 385h2_vlan_destroy()386{387	vlan_destroy $h2 100388	simple_if_fini $h2389}390 391bridge_create()392{393	local vlan_filtering=$1394 395	ip link add br0 type bridge vlan_filtering $vlan_filtering396	ip link set br0 address $BRIDGE_ADDR397	ip link set br0 up398 399	ip link set $h2 master br0400	ip link set $h2 up401}402 403bridge_destroy()404{405	ip link del br0406}407 408macvlan_create()409{410	local lower=$1411 412	ip link add link $lower name macvlan0 type macvlan mode private413	ip link set macvlan0 address $MACVLAN_ADDR414	ip link set macvlan0 up415}416 417macvlan_destroy()418{419	ip link del macvlan0420}421 422standalone()423{424	local no_unicast_flt=true425	local skip_ptp=false426 427	if [ $(has_unicast_flt $h2) = yes ]; then428		no_unicast_flt=false429	fi430 431	h1_create432	h2_create433	macvlan_create $h2434 435	run_test $h1 $h2 $skip_ptp $no_unicast_flt "$h2"436 437	macvlan_destroy438	h2_destroy439	h1_destroy440}441 442test_bridge()443{444	local no_unicast_flt=true445	local vlan_filtering=$1446	local skip_ptp=true447 448	h1_create449	bridge_create $vlan_filtering450	simple_if_init br0 $H2_IPV4/24 $H2_IPV6/64451	macvlan_create br0452 453	run_test $h1 br0 $skip_ptp $no_unicast_flt \454		"vlan_filtering=$vlan_filtering bridge"455 456	macvlan_destroy457	simple_if_fini br0 $H2_IPV4/24 $H2_IPV6/64458	bridge_destroy459	h1_destroy460}461 462vlan_unaware_bridge()463{464	test_bridge 0465}466 467vlan_aware_bridge()468{469	test_bridge 1470}471 472test_vlan()473{474	local no_unicast_flt=true475	local skip_ptp=false476 477	if [ $(has_unicast_flt $h2) = yes ]; then478		no_unicast_flt=false479	fi480 481	h1_vlan_create482	h2_vlan_create483	macvlan_create $h2.100484 485	run_test $h1.100 $h2.100 $skip_ptp $no_unicast_flt "VLAN upper"486 487	macvlan_destroy488	h2_vlan_destroy489	h1_vlan_destroy490}491 492vlan_over_bridged_port()493{494	local no_unicast_flt=true495	local vlan_filtering=$1496	local skip_ptp=false497 498	# br_manage_promisc() will not force a single vlan_filtering port to499	# promiscuous mode, so we should still expect unicast filtering to take500	# place if the device can do it.501	if [ $(has_unicast_flt $h2) = yes ] && [ $vlan_filtering = 1 ]; then502		no_unicast_flt=false503	fi504 505	h1_vlan_create506	h2_vlan_create507	bridge_create $vlan_filtering508	macvlan_create $h2.100509 510	run_test $h1.100 $h2.100 $skip_ptp $no_unicast_flt \511		"VLAN over vlan_filtering=$vlan_filtering bridged port"512 513	macvlan_destroy514	bridge_destroy515	h2_vlan_destroy516	h1_vlan_destroy517}518 519vlan_over_vlan_unaware_bridged_port()520{521	vlan_over_bridged_port 0522}523 524vlan_over_vlan_aware_bridged_port()525{526	vlan_over_bridged_port 1527}528 529vlan_over_bridge()530{531	local no_unicast_flt=true532	local vlan_filtering=$1533	local skip_ptp=true534 535	h1_vlan_create536	bridge_create $vlan_filtering537	simple_if_init br0538	vlan_create br0 100 vbr0 $H2_IPV4/24 $H2_IPV6/64539	macvlan_create br0.100540 541	if [ $vlan_filtering = 1 ]; then542		bridge vlan add dev $h2 vid 100 master543		bridge vlan add dev br0 vid 100 self544	fi545 546	run_test $h1.100 br0.100 $skip_ptp $no_unicast_flt \547		"VLAN over vlan_filtering=$vlan_filtering bridge"548 549	if [ $vlan_filtering = 1 ]; then550		bridge vlan del dev br0 vid 100 self551		bridge vlan del dev $h2 vid 100 master552	fi553 554	macvlan_destroy555	vlan_destroy br0 100556	simple_if_fini br0557	bridge_destroy558	h1_vlan_destroy559}560 561vlan_over_vlan_unaware_bridge()562{563	vlan_over_bridge 0564}565 566vlan_over_vlan_aware_bridge()567{568	vlan_over_bridge 1569}570 571cleanup()572{573	pre_cleanup574 575	ip link set $h2 down576	ip link set $h1 down577 578	vrf_cleanup579}580 581setup_prepare()582{583	vrf_prepare584	# setup_wait() needs this585	ip link set $h1 up586	ip link set $h2 up587}588 589trap cleanup EXIT590 591setup_prepare592setup_wait593 594tests_run595 596exit $EXIT_STATUS597