WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / net / forwarding / tc_actions.sh
blobd9eca227136bb6d4a1c7921251190c65d76fcb04
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 ALL_TESTS="gact_drop_and_ok_test mirred_egress_redirect_test \
5 mirred_egress_mirror_test matchall_mirred_egress_mirror_test \
6 gact_trap_test"
7 NUM_NETIFS=4
8 source tc_common.sh
9 source lib.sh
11 tcflags="skip_hw"
13 h1_create()
15 simple_if_init $h1 192.0.2.1/24
18 h1_destroy()
20 simple_if_fini $h1 192.0.2.1/24
23 h2_create()
25 simple_if_init $h2 192.0.2.2/24
26 tc qdisc add dev $h2 clsact
29 h2_destroy()
31 tc qdisc del dev $h2 clsact
32 simple_if_fini $h2 192.0.2.2/24
35 switch_create()
37 simple_if_init $swp1 192.0.2.2/24
38 tc qdisc add dev $swp1 clsact
40 simple_if_init $swp2 192.0.2.1/24
43 switch_destroy()
45 simple_if_fini $swp2 192.0.2.1/24
47 tc qdisc del dev $swp1 clsact
48 simple_if_fini $swp1 192.0.2.2/24
51 mirred_egress_test()
53 local action=$1
54 local protocol=$2
55 local classifier=$3
56 local classifier_args=$4
58 RET=0
60 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
61 $tcflags dst_ip 192.0.2.2 action drop
63 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
64 -t ip -q
66 tc_check_packets "dev $h2 ingress" 101 1
67 check_fail $? "Matched without redirect rule inserted"
69 tc filter add dev $swp1 ingress protocol $protocol pref 1 handle 101 \
70 $classifier $tcflags $classifier_args \
71 action mirred egress $action dev $swp2
73 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
74 -t ip -q
76 tc_check_packets "dev $h2 ingress" 101 1
77 check_err $? "Did not match incoming $action packet"
79 tc filter del dev $swp1 ingress protocol $protocol pref 1 handle 101 \
80 $classifier
81 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
83 log_test "mirred egress $classifier $action ($tcflags)"
86 gact_drop_and_ok_test()
88 RET=0
90 tc filter add dev $swp1 ingress protocol ip pref 2 handle 102 flower \
91 $tcflags dst_ip 192.0.2.2 action drop
93 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
94 -t ip -q
96 tc_check_packets "dev $swp1 ingress" 102 1
97 check_err $? "Packet was not dropped"
99 tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
100 $tcflags dst_ip 192.0.2.2 action ok
102 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
103 -t ip -q
105 tc_check_packets "dev $swp1 ingress" 101 1
106 check_err $? "Did not see passed packet"
108 tc_check_packets "dev $swp1 ingress" 102 2
109 check_fail $? "Packet was dropped and it should not reach here"
111 tc filter del dev $swp1 ingress protocol ip pref 2 handle 102 flower
112 tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
114 log_test "gact drop and ok ($tcflags)"
117 gact_trap_test()
119 RET=0
121 if [[ "$tcflags" != "skip_sw" ]]; then
122 return 0;
125 tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
126 skip_hw dst_ip 192.0.2.2 action drop
127 tc filter add dev $swp1 ingress protocol ip pref 3 handle 103 flower \
128 $tcflags dst_ip 192.0.2.2 action mirred egress redirect \
129 dev $swp2
131 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
132 -t ip -q
134 tc_check_packets "dev $swp1 ingress" 101 1
135 check_fail $? "Saw packet without trap rule inserted"
137 tc filter add dev $swp1 ingress protocol ip pref 2 handle 102 flower \
138 $tcflags dst_ip 192.0.2.2 action trap
140 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
141 -t ip -q
143 tc_check_packets "dev $swp1 ingress" 102 1
144 check_err $? "Packet was not trapped"
146 tc_check_packets "dev $swp1 ingress" 101 1
147 check_err $? "Did not see trapped packet"
149 tc filter del dev $swp1 ingress protocol ip pref 3 handle 103 flower
150 tc filter del dev $swp1 ingress protocol ip pref 2 handle 102 flower
151 tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
153 log_test "trap ($tcflags)"
156 setup_prepare()
158 h1=${NETIFS[p1]}
159 swp1=${NETIFS[p2]}
161 swp2=${NETIFS[p3]}
162 h2=${NETIFS[p4]}
164 h1mac=$(mac_get $h1)
165 h2mac=$(mac_get $h2)
167 swp1origmac=$(mac_get $swp1)
168 swp2origmac=$(mac_get $swp2)
169 ip link set $swp1 address $h2mac
170 ip link set $swp2 address $h1mac
172 vrf_prepare
174 h1_create
175 h2_create
176 switch_create
179 cleanup()
181 pre_cleanup
183 switch_destroy
184 h2_destroy
185 h1_destroy
187 vrf_cleanup
189 ip link set $swp2 address $swp2origmac
190 ip link set $swp1 address $swp1origmac
193 mirred_egress_redirect_test()
195 mirred_egress_test "redirect" "ip" "flower" "dst_ip 192.0.2.2"
198 mirred_egress_mirror_test()
200 mirred_egress_test "mirror" "ip" "flower" "dst_ip 192.0.2.2"
203 matchall_mirred_egress_mirror_test()
205 mirred_egress_test "mirror" "all" "matchall" ""
208 trap cleanup EXIT
210 setup_prepare
211 setup_wait
213 tests_run
215 tc_offload_check
216 if [[ $? -ne 0 ]]; then
217 log_info "Could not test offloaded functionality"
218 else
219 tcflags="skip_sw"
220 tests_run
223 exit $EXIT_STATUS