brintos

brintos / linux-shallow public Read only

0
0
Text · 3.0 KiB · 4aee9c9 Raw
173 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4ALL_TESTS="match_indev_egress_test"5NUM_NETIFS=66source tc_common.sh7source lib.sh8 9h1_create()10{11	simple_if_init $h1 192.0.1.1/2412 13	ip route add 192.0.2.0/24 vrf v$h1 nexthop via 192.0.1.214	ip route add 192.0.3.0/24 vrf v$h1 nexthop via 192.0.1.215}16 17h1_destroy()18{19	ip route del 192.0.3.0/24 vrf v$h120	ip route del 192.0.2.0/24 vrf v$h121 22	simple_if_fini $h1 192.0.1.1/2423}24 25h2_create()26{27	simple_if_init $h2 192.0.2.1/2428 29	ip route add 192.0.1.0/24 vrf v$h2 nexthop via 192.0.2.230	ip route add 192.0.3.0/24 vrf v$h2 nexthop via 192.0.2.231}32 33h2_destroy()34{35	ip route del 192.0.3.0/24 vrf v$h236	ip route del 192.0.1.0/24 vrf v$h237 38	simple_if_fini $h2 192.0.2.1/2439}40 41h3_create()42{43	simple_if_init $h3 192.0.3.1/2444 45	ip route add 192.0.1.0/24 vrf v$h3 nexthop via 192.0.3.246	ip route add 192.0.2.0/24 vrf v$h3 nexthop via 192.0.3.247}48 49h3_destroy()50{51	ip route del 192.0.2.0/24 vrf v$h352	ip route del 192.0.1.0/24 vrf v$h353 54	simple_if_fini $h3 192.0.3.1/2455}56 57 58router_create()59{60	ip link set dev $rp1 up61	ip link set dev $rp2 up62	ip link set dev $rp3 up63 64	tc qdisc add dev $rp3 clsact65 66	ip address add 192.0.1.2/24 dev $rp167	ip address add 192.0.2.2/24 dev $rp268	ip address add 192.0.3.2/24 dev $rp369}70 71router_destroy()72{73	ip address del 192.0.3.2/24 dev $rp374	ip address del 192.0.2.2/24 dev $rp275	ip address del 192.0.1.2/24 dev $rp176 77	tc qdisc del dev $rp3 clsact78 79	ip link set dev $rp3 down80	ip link set dev $rp2 down81	ip link set dev $rp1 down82}83 84match_indev_egress_test()85{86	RET=087 88	tc filter add dev $rp3 egress protocol ip pref 1 handle 101 flower \89		$tcflags indev $rp1 dst_ip 192.0.3.1 action drop90	tc filter add dev $rp3 egress protocol ip pref 2 handle 102 flower \91		$tcflags indev $rp2 dst_ip 192.0.3.1 action drop92 93	$MZ $h1 -c 1 -p 64 -a $h1mac -b $rp1mac -A 192.0.1.1 -B 192.0.3.1 \94		-t ip -q95 96	tc_check_packets "dev $rp3 egress" 102 197	check_fail $? "Matched on a wrong filter"98 99	tc_check_packets "dev $rp3 egress" 101 1100	check_err $? "Did not match on correct filter"101 102	$MZ $h2 -c 1 -p 64 -a $h2mac -b $rp2mac -A 192.0.2.1 -B 192.0.3.1 \103		-t ip -q104 105	tc_check_packets "dev $rp3 egress" 101 2106	check_fail $? "Matched on a wrong filter"107 108	tc_check_packets "dev $rp3 egress" 102 1109	check_err $? "Did not match on correct filter"110 111	tc filter del dev $rp3 egress protocol ip pref 2 handle 102 flower112	tc filter del dev $rp3 egress protocol ip pref 1 handle 101 flower113 114	log_test "indev egress match ($tcflags)"115}116 117setup_prepare()118{119	h1=${NETIFS[p1]}120	rp1=${NETIFS[p2]}121 122	h2=${NETIFS[p3]}123	rp2=${NETIFS[p4]}124 125	h3=${NETIFS[p5]}126	rp3=${NETIFS[p6]}127 128	h1mac=$(mac_get $h1)129	rp1mac=$(mac_get $rp1)130	h2mac=$(mac_get $h2)131	rp2mac=$(mac_get $rp2)132 133	vrf_prepare134 135	h1_create136	h2_create137	h3_create138 139	router_create140 141	forwarding_enable142}143 144cleanup()145{146	pre_cleanup147 148	forwarding_restore149 150	router_destroy151 152	h3_destroy153	h2_destroy154	h1_destroy155 156	vrf_cleanup157}158 159trap cleanup EXIT160 161setup_prepare162setup_wait163 164tc_offload_check165if [[ $? -ne 0 ]]; then166	log_info "Could not test offloaded functionality"167else168	tcflags="skip_sw"169	tests_run170fi171 172exit $EXIT_STATUS173