Skip to content

Commit bc13af2

Browse files
jpirkodavem330
authored andcommitted
selftests: forwarding: Introduce tc actions tests
Add first part of actions tests. This patch only contains tests of gact ok/drop/trap and mirred redirect egress. Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 07e5c75 commit bc13af2

File tree

1 file changed

+195
-0
lines changed

1 file changed

+195
-0
lines changed
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
NUM_NETIFS=4
5+
source lib.sh
6+
source tc_common.sh
7+
8+
tcflags="skip_hw"
9+
10+
h1_create()
11+
{
12+
simple_if_init $h1 192.0.2.1/24
13+
}
14+
15+
h1_destroy()
16+
{
17+
simple_if_fini $h1 192.0.2.1/24
18+
}
19+
20+
h2_create()
21+
{
22+
simple_if_init $h2 192.0.2.2/24
23+
tc qdisc add dev $h2 clsact
24+
}
25+
26+
h2_destroy()
27+
{
28+
tc qdisc del dev $h2 clsact
29+
simple_if_fini $h2 192.0.2.2/24
30+
}
31+
32+
switch_create()
33+
{
34+
simple_if_init $swp1 192.0.2.2/24
35+
tc qdisc add dev $swp1 clsact
36+
37+
simple_if_init $swp2 192.0.2.1/24
38+
}
39+
40+
switch_destroy()
41+
{
42+
simple_if_fini $swp2 192.0.2.1/24
43+
44+
tc qdisc del dev $swp1 clsact
45+
simple_if_fini $swp1 192.0.2.2/24
46+
}
47+
48+
mirred_egress_redirect_test()
49+
{
50+
RET=0
51+
52+
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
53+
$tcflags dst_ip 192.0.2.2 action drop
54+
55+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
56+
-t ip -q
57+
58+
tc_check_packets "dev $h2 ingress" 101 1
59+
check_fail $? "Matched without redirect rule inserted"
60+
61+
tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
62+
$tcflags dst_ip 192.0.2.2 action mirred egress redirect \
63+
dev $swp2
64+
65+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
66+
-t ip -q
67+
68+
tc_check_packets "dev $h2 ingress" 101 1
69+
check_err $? "Did not match incoming redirected packet"
70+
71+
tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
72+
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
73+
74+
log_test "mirred egress redirect ($tcflags)"
75+
}
76+
77+
gact_drop_and_ok_test()
78+
{
79+
RET=0
80+
81+
tc filter add dev $swp1 ingress protocol ip pref 2 handle 102 flower \
82+
skip_hw dst_ip 192.0.2.2 action drop
83+
84+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
85+
-t ip -q
86+
87+
tc_check_packets "dev $swp1 ingress" 102 1
88+
check_err $? "Packet was not dropped"
89+
90+
tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
91+
$tcflags dst_ip 192.0.2.2 action ok
92+
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
95+
96+
tc_check_packets "dev $swp1 ingress" 101 1
97+
check_err $? "Did not see trapped packet"
98+
99+
tc filter del dev $swp1 ingress protocol ip pref 2 handle 102 flower
100+
tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
101+
102+
log_test "gact drop and ok ($tcflags)"
103+
}
104+
105+
gact_trap_test()
106+
{
107+
RET=0
108+
109+
tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
110+
skip_hw dst_ip 192.0.2.2 action drop
111+
tc filter add dev $swp1 ingress protocol ip pref 3 handle 103 flower \
112+
$tcflags dst_ip 192.0.2.2 action mirred egress redirect \
113+
dev $swp2
114+
115+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
116+
-t ip -q
117+
118+
tc_check_packets "dev $swp1 ingress" 101 1
119+
check_fail $? "Saw packet without trap rule inserted"
120+
121+
tc filter add dev $swp1 ingress protocol ip pref 2 handle 102 flower \
122+
$tcflags dst_ip 192.0.2.2 action trap
123+
124+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
125+
-t ip -q
126+
127+
tc_check_packets "dev $swp1 ingress" 102 1
128+
check_err $? "Packet was not trapped"
129+
130+
tc_check_packets "dev $swp1 ingress" 101 1
131+
check_err $? "Did not see trapped packet"
132+
133+
tc filter del dev $swp1 ingress protocol ip pref 3 handle 103 flower
134+
tc filter del dev $swp1 ingress protocol ip pref 2 handle 102 flower
135+
tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
136+
137+
log_test "trap ($tcflags)"
138+
}
139+
140+
setup_prepare()
141+
{
142+
h1=${NETIFS[p1]}
143+
swp1=${NETIFS[p2]}
144+
145+
swp2=${NETIFS[p3]}
146+
h2=${NETIFS[p4]}
147+
148+
h1mac=$(mac_get $h1)
149+
h2mac=$(mac_get $h2)
150+
151+
swp1origmac=$(mac_get $swp1)
152+
swp2origmac=$(mac_get $swp2)
153+
ip link set $swp1 address $h2mac
154+
ip link set $swp2 address $h1mac
155+
156+
vrf_prepare
157+
158+
h1_create
159+
h2_create
160+
switch_create
161+
}
162+
163+
cleanup()
164+
{
165+
pre_cleanup
166+
167+
switch_destroy
168+
h2_destroy
169+
h1_destroy
170+
171+
vrf_cleanup
172+
173+
ip link set $swp2 address $swp2origmac
174+
ip link set $swp1 address $swp1origmac
175+
}
176+
177+
trap cleanup EXIT
178+
179+
setup_prepare
180+
setup_wait
181+
182+
gact_drop_and_ok_test
183+
mirred_egress_redirect_test
184+
185+
tc_offload_check
186+
if [[ $? -ne 0 ]]; then
187+
log_info "Could not test offloaded functionality"
188+
else
189+
tcflags="skip_sw"
190+
gact_drop_and_ok_test
191+
mirred_egress_redirect_test
192+
gact_trap_test
193+
fi
194+
195+
exit $EXIT_STATUS

0 commit comments

Comments
 (0)