Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1# SPDX-License-Identifier: GPL-2.0
2
3TC_POLICE_NUM_NETIFS=2
4
5tc_police_h1_create()
6{
7 simple_if_init $h1
8}
9
10tc_police_h1_destroy()
11{
12 simple_if_fini $h1
13}
14
15tc_police_switch_create()
16{
17 simple_if_init $swp1
18 tc qdisc add dev $swp1 clsact
19}
20
21tc_police_switch_destroy()
22{
23 tc qdisc del dev $swp1 clsact
24 simple_if_fini $swp1
25}
26
27tc_police_rules_create()
28{
29 local count=$1; shift
30 local should_fail=$1; shift
31
32 TC_POLICE_BATCH_FILE="$(mktemp)"
33
34 for ((i = 0; i < count; ++i)); do
35 cat >> $TC_POLICE_BATCH_FILE <<-EOF
36 filter add dev $swp1 ingress \
37 prot ip \
38 flower skip_sw \
39 action police rate 10mbit burst 100k \
40 conform-exceed drop/ok
41 EOF
42 done
43
44 tc -b $TC_POLICE_BATCH_FILE
45 check_err_fail $should_fail $? "Rule insertion"
46}
47
48__tc_police_test()
49{
50 local count=$1; shift
51 local should_fail=$1; shift
52
53 tc_police_rules_create $count $should_fail
54
55 offload_count=$(tc filter show dev $swp1 ingress | grep in_hw | wc -l)
56 ((offload_count == count))
57 check_err_fail $should_fail $? "tc police offload count"
58}
59
60tc_police_test()
61{
62 local count=$1; shift
63 local should_fail=$1; shift
64
65 if ! tc_offload_check $TC_POLICE_NUM_NETIFS; then
66 check_err 1 "Could not test offloaded functionality"
67 return
68 fi
69
70 __tc_police_test $count $should_fail
71}
72
73tc_police_setup_prepare()
74{
75 h1=${NETIFS[p1]}
76 swp1=${NETIFS[p2]}
77
78 vrf_prepare
79
80 tc_police_h1_create
81 tc_police_switch_create
82}
83
84tc_police_cleanup()
85{
86 pre_cleanup
87
88 tc_police_switch_destroy
89 tc_police_h1_destroy
90
91 vrf_cleanup
92}