brintos

brintos / linux-shallow public Read only

0
0
Text · 4.4 KiB · d14efb2 Raw
202 lines · bash
1#!/bin/bash2# SPDX-License-Identifier: GPL-2.03 4# This test sends traffic from H1 to H2. Either on ingress of $swp1, or on5# egress of $swp2, the traffic is acted upon by a pedit action. An ingress6# filter installed on $h2 verifies that the packet looks like expected.7#8# +----------------------+                             +----------------------+9# | H1                   |                             |                   H2 |10# |    + $h1             |                             |            $h2 +     |11# |    | 192.0.2.1/28    |                             |   192.0.2.2/28 |     |12# +----|-----------------+                             +----------------|-----+13#      |                                                                |14# +----|----------------------------------------------------------------|-----+15# | SW |                                                                |     |16# |  +-|----------------------------------------------------------------|-+   |17# |  | + $swp1                       BR                           $swp2 + |   |18# |  +--------------------------------------------------------------------+   |19# +---------------------------------------------------------------------------+20 21ALL_TESTS="22	ping_ipv423	ping_ipv624	test_ip4_src25	test_ip4_dst26	test_ip6_src27	test_ip6_dst28"29 30NUM_NETIFS=431source lib.sh32source tc_common.sh33 34h1_create()35{36	simple_if_init $h1 192.0.2.1/28 2001:db8:1::1/6437}38 39h1_destroy()40{41	simple_if_fini $h1 192.0.2.1/28 2001:db8:1::1/6442}43 44h2_create()45{46	simple_if_init $h2 192.0.2.2/28 2001:db8:1::2/6447	tc qdisc add dev $h2 clsact48}49 50h2_destroy()51{52	tc qdisc del dev $h2 clsact53	simple_if_fini $h2 192.0.2.2/28 2001:db8:1::2/6454}55 56switch_create()57{58	ip link add name br1 up type bridge vlan_filtering 159	ip link set dev $swp1 master br160	ip link set dev $swp1 up61	ip link set dev $swp2 master br162	ip link set dev $swp2 up63 64	tc qdisc add dev $swp1 clsact65	tc qdisc add dev $swp2 clsact66}67 68switch_destroy()69{70	tc qdisc del dev $swp2 clsact71	tc qdisc del dev $swp1 clsact72 73	ip link set dev $swp2 down74	ip link set dev $swp2 nomaster75	ip link set dev $swp1 down76	ip link set dev $swp1 nomaster77	ip link del dev br178}79 80setup_prepare()81{82	h1=${NETIFS[p1]}83	swp1=${NETIFS[p2]}84 85	swp2=${NETIFS[p3]}86	h2=${NETIFS[p4]}87 88	h2mac=$(mac_get $h2)89 90	vrf_prepare91	h1_create92	h2_create93	switch_create94}95 96cleanup()97{98	pre_cleanup99 100	switch_destroy101	h2_destroy102	h1_destroy103	vrf_cleanup104}105 106ping_ipv4()107{108	ping_test $h1 192.0.2.2109}110 111ping_ipv6()112{113	ping6_test $h1 2001:db8:1::2114}115 116do_test_pedit_ip()117{118	local pedit_locus=$1; shift119	local pedit_action=$1; shift120	local match_prot=$1; shift121	local match_flower=$1; shift122	local mz_flags=$1; shift123 124	tc filter add $pedit_locus handle 101 pref 1 \125	   flower action pedit ex munge $pedit_action126	tc filter add dev $h2 ingress handle 101 pref 1 prot $match_prot \127	   flower skip_hw $match_flower action pass128 129	RET=0130 131	$MZ $mz_flags $h1 -c 10 -d 20msec -p 100 -a own -b $h2mac -q -t ip132 133	local pkts134	pkts=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= 10" \135			tc_rule_handle_stats_get "dev $h2 ingress" 101)136	check_err $? "Expected to get 10 packets, but got $pkts."137 138	pkts=$(tc_rule_handle_stats_get "$pedit_locus" 101)139	((pkts >= 10))140	check_err $? "Expected to get 10 packets on pedit rule, but got $pkts."141 142	log_test "$pedit_locus pedit $pedit_action"143 144	tc filter del dev $h2 ingress pref 1145	tc filter del $pedit_locus pref 1146}147 148do_test_pedit_ip6()149{150	local locus=$1; shift151	local pedit_addr=$1; shift152	local flower_addr=$1; shift153 154	do_test_pedit_ip "$locus" "$pedit_addr set 2001:db8:2::1" ipv6	\155			 "$flower_addr 2001:db8:2::1"			\156			 "-6 -A 2001:db8:1::1 -B 2001:db8:1::2"157}158 159do_test_pedit_ip4()160{161	local locus=$1; shift162	local pedit_addr=$1; shift163	local flower_addr=$1; shift164 165	do_test_pedit_ip "$locus" "$pedit_addr set 198.51.100.1" ip	\166			 "$flower_addr 198.51.100.1"			\167			 "-A 192.0.2.1 -B 192.0.2.2"168}169 170test_ip4_src()171{172	do_test_pedit_ip4 "dev $swp1 ingress" "ip src" src_ip173	do_test_pedit_ip4 "dev $swp2 egress"  "ip src" src_ip174}175 176test_ip4_dst()177{178	do_test_pedit_ip4 "dev $swp1 ingress" "ip dst" dst_ip179	do_test_pedit_ip4 "dev $swp2 egress"  "ip dst" dst_ip180}181 182test_ip6_src()183{184	do_test_pedit_ip6 "dev $swp1 ingress" "ip6 src" src_ip185	do_test_pedit_ip6 "dev $swp2 egress"  "ip6 src" src_ip186}187 188test_ip6_dst()189{190	do_test_pedit_ip6 "dev $swp1 ingress" "ip6 dst" dst_ip191	do_test_pedit_ip6 "dev $swp2 egress"  "ip6 dst" dst_ip192}193 194trap cleanup EXIT195 196setup_prepare197setup_wait198 199tests_run200 201exit $EXIT_STATUS202