Skip to content

Commit b13f245

Browse files
jpirkodavem330
authored andcommitted
selftests: forwarding: Introduce basic tc chains tests
Tests chains matching and goto chain action. Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bc13af2 commit b13f245

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
NUM_NETIFS=2
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+
unreachable_chain_test()
33+
{
34+
RET=0
35+
36+
tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
37+
flower $tcflags dst_mac $h2mac action drop
38+
39+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
40+
-t ip -q
41+
42+
tc_check_packets "dev $h2 ingress" 1101 1
43+
check_fail $? "matched on filter in unreachable chain"
44+
45+
tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
46+
flower
47+
48+
log_test "unreachable chain ($tcflags)"
49+
}
50+
51+
gact_goto_chain_test()
52+
{
53+
RET=0
54+
55+
tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
56+
flower $tcflags dst_mac $h2mac action drop
57+
tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
58+
$tcflags dst_mac $h2mac action drop
59+
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
60+
$tcflags dst_mac $h2mac action goto chain 1
61+
62+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
63+
-t ip -q
64+
65+
tc_check_packets "dev $h2 ingress" 102 1
66+
check_fail $? "Matched on a wrong filter"
67+
68+
tc_check_packets "dev $h2 ingress" 101 1
69+
check_err $? "Did not match on correct filter with goto chain action"
70+
71+
tc_check_packets "dev $h2 ingress" 1101 1
72+
check_err $? "Did not match on correct filter in chain 1"
73+
74+
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
75+
tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
76+
tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
77+
flower
78+
79+
log_test "gact goto chain ($tcflags)"
80+
}
81+
82+
setup_prepare()
83+
{
84+
h1=${NETIFS[p1]}
85+
h2=${NETIFS[p2]}
86+
h1mac=$(mac_get $h1)
87+
h2mac=$(mac_get $h2)
88+
89+
vrf_prepare
90+
91+
h1_create
92+
h2_create
93+
}
94+
95+
cleanup()
96+
{
97+
pre_cleanup
98+
99+
h2_destroy
100+
h1_destroy
101+
102+
vrf_cleanup
103+
}
104+
105+
trap cleanup EXIT
106+
107+
setup_prepare
108+
setup_wait
109+
110+
unreachable_chain_test
111+
gact_goto_chain_test
112+
113+
tc_offload_check
114+
if [[ $? -ne 0 ]]; then
115+
log_info "Could not test offloaded functionality"
116+
else
117+
tcflags="skip_sw"
118+
unreachable_chain_test
119+
gact_goto_chain_test
120+
fi
121+
122+
exit $EXIT_STATUS

0 commit comments

Comments
 (0)