brintos

brintos / linux-shallow public Read only

0
0
Text · 1.6 KiB · 86e7878 Raw
102 lines · bash
1# SPDX-License-Identifier: GPL-2.02 3TC_POLICE_NUM_NETIFS=24 5tc_police_h1_create()6{7	simple_if_init $h18}9 10tc_police_h1_destroy()11{12	simple_if_fini $h113}14 15tc_police_switch_create()16{17	simple_if_init $swp118	tc qdisc add dev $swp1 clsact19}20 21tc_police_switch_destroy()22{23	tc qdisc del dev $swp1 clsact24	simple_if_fini $swp125}26 27tc_police_addr()28{29       local num=$1; shift30 31       printf "2001:db8:1::%x" $num32}33 34tc_police_rules_create()35{36	local count=$1; shift37	local should_fail=$1; shift38 39	TC_POLICE_BATCH_FILE="$(mktemp)"40 41	for ((i = 0; i < count; ++i)); do42		cat >> $TC_POLICE_BATCH_FILE <<-EOF43			filter add dev $swp1 ingress \44				prot ipv6 \45				pref 1000 \46				flower skip_sw dst_ip $(tc_police_addr $i) \47				action police rate 10mbit burst 100k \48				conform-exceed drop/ok49		EOF50	done51 52	tc -b $TC_POLICE_BATCH_FILE53	check_err_fail $should_fail $? "Rule insertion"54}55 56__tc_police_test()57{58	local count=$1; shift59	local should_fail=$1; shift60 61	tc_police_rules_create $count $should_fail62 63	offload_count=$(tc -j filter show dev $swp1 ingress |64			jq "[.[] | select(.options.in_hw == true)] | length")65	((offload_count == count))66	check_err_fail $should_fail $? "tc police offload count"67}68 69tc_police_test()70{71	local count=$1; shift72	local should_fail=$1; shift73 74	if ! tc_offload_check $TC_POLICE_NUM_NETIFS; then75		check_err 1 "Could not test offloaded functionality"76		return77	fi78 79	__tc_police_test $count $should_fail80}81 82tc_police_setup_prepare()83{84	h1=${NETIFS[p1]}85	swp1=${NETIFS[p2]}86 87	vrf_prepare88 89	tc_police_h1_create90	tc_police_switch_create91}92 93tc_police_cleanup()94{95	pre_cleanup96 97	tc_police_switch_destroy98	tc_police_h1_destroy99 100	vrf_cleanup101}102