Linux 4.19.133
[linux/fpc-iii.git] / tools / testing / selftests / net / forwarding / tc_actions.sh
blob813d02d1939dd2cbbcc3bc55c8f1a71a074edc2f
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 gact_trap_test"
6 NUM_NETIFS=4
7 source tc_common.sh
8 source lib.sh
10 tcflags="skip_hw"
12 h1_create()
14 simple_if_init $h1 192.0.2.1/24
17 h1_destroy()
19 simple_if_fini $h1 192.0.2.1/24
22 h2_create()
24 simple_if_init $h2 192.0.2.2/24
25 tc qdisc add dev $h2 clsact
28 h2_destroy()
30 tc qdisc del dev $h2 clsact
31 simple_if_fini $h2 192.0.2.2/24
34 switch_create()
36 simple_if_init $swp1 192.0.2.2/24
37 tc qdisc add dev $swp1 clsact
39 simple_if_init $swp2 192.0.2.1/24
42 switch_destroy()
44 simple_if_fini $swp2 192.0.2.1/24
46 tc qdisc del dev $swp1 clsact
47 simple_if_fini $swp1 192.0.2.2/24
50 mirred_egress_test()
52 local action=$1
54 RET=0
56 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
57 $tcflags dst_ip 192.0.2.2 action drop
59 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
60 -t ip -q
62 tc_check_packets "dev $h2 ingress" 101 1
63 check_fail $? "Matched without redirect rule inserted"
65 tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
66 $tcflags dst_ip 192.0.2.2 action mirred egress $action \
67 dev $swp2
69 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
70 -t ip -q
72 tc_check_packets "dev $h2 ingress" 101 1
73 check_err $? "Did not match incoming $action packet"
75 tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
76 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
78 log_test "mirred egress $action ($tcflags)"
81 gact_drop_and_ok_test()
83 RET=0
85 tc filter add dev $swp1 ingress protocol ip pref 2 handle 102 flower \
86 $tcflags dst_ip 192.0.2.2 action drop
88 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
89 -t ip -q
91 tc_check_packets "dev $swp1 ingress" 102 1
92 check_err $? "Packet was not dropped"
94 tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
95 $tcflags dst_ip 192.0.2.2 action ok
97 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
98 -t ip -q
100 tc_check_packets "dev $swp1 ingress" 101 1
101 check_err $? "Did not see passed packet"
103 tc_check_packets "dev $swp1 ingress" 102 2
104 check_fail $? "Packet was dropped and it should not reach here"
106 tc filter del dev $swp1 ingress protocol ip pref 2 handle 102 flower
107 tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
109 log_test "gact drop and ok ($tcflags)"
112 gact_trap_test()
114 RET=0
116 if [[ "$tcflags" != "skip_sw" ]]; then
117 return 0;
120 tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
121 skip_hw dst_ip 192.0.2.2 action drop
122 tc filter add dev $swp1 ingress protocol ip pref 3 handle 103 flower \
123 $tcflags dst_ip 192.0.2.2 action mirred egress redirect \
124 dev $swp2
126 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
127 -t ip -q
129 tc_check_packets "dev $swp1 ingress" 101 1
130 check_fail $? "Saw packet without trap rule inserted"
132 tc filter add dev $swp1 ingress protocol ip pref 2 handle 102 flower \
133 $tcflags dst_ip 192.0.2.2 action trap
135 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
136 -t ip -q
138 tc_check_packets "dev $swp1 ingress" 102 1
139 check_err $? "Packet was not trapped"
141 tc_check_packets "dev $swp1 ingress" 101 1
142 check_err $? "Did not see trapped packet"
144 tc filter del dev $swp1 ingress protocol ip pref 3 handle 103 flower
145 tc filter del dev $swp1 ingress protocol ip pref 2 handle 102 flower
146 tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
148 log_test "trap ($tcflags)"
151 setup_prepare()
153 h1=${NETIFS[p1]}
154 swp1=${NETIFS[p2]}
156 swp2=${NETIFS[p3]}
157 h2=${NETIFS[p4]}
159 h1mac=$(mac_get $h1)
160 h2mac=$(mac_get $h2)
162 swp1origmac=$(mac_get $swp1)
163 swp2origmac=$(mac_get $swp2)
164 ip link set $swp1 address $h2mac
165 ip link set $swp2 address $h1mac
167 vrf_prepare
169 h1_create
170 h2_create
171 switch_create
174 cleanup()
176 pre_cleanup
178 switch_destroy
179 h2_destroy
180 h1_destroy
182 vrf_cleanup
184 ip link set $swp2 address $swp2origmac
185 ip link set $swp1 address $swp1origmac
188 mirred_egress_redirect_test()
190 mirred_egress_test "redirect"
193 mirred_egress_mirror_test()
195 mirred_egress_test "mirror"
198 trap cleanup EXIT
200 setup_prepare
201 setup_wait
203 tests_run
205 tc_offload_check
206 if [[ $? -ne 0 ]]; then
207 log_info "Could not test offloaded functionality"
208 else
209 tcflags="skip_sw"
210 tests_run
213 exit $EXIT_STATUS