Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4NUM_NETIFS=2
5source tc_common.sh
6source lib.sh
7
8tcflags="skip_hw"
9
10h1_create()
11{
12 simple_if_init $h1 192.0.2.1/24
13}
14
15h1_destroy()
16{
17 simple_if_fini $h1 192.0.2.1/24
18}
19
20h2_create()
21{
22 simple_if_init $h2 192.0.2.2/24
23 tc qdisc add dev $h2 clsact
24}
25
26h2_destroy()
27{
28 tc qdisc del dev $h2 clsact
29 simple_if_fini $h2 192.0.2.2/24
30}
31
32unreachable_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
51gact_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
82setup_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
95cleanup()
96{
97 pre_cleanup
98
99 h2_destroy
100 h1_destroy
101
102 vrf_cleanup
103}
104
105trap cleanup EXIT
106
107setup_prepare
108setup_wait
109
110unreachable_chain_test
111gact_goto_chain_test
112
113tc_offload_check
114if [[ $? -ne 0 ]]; then
115 log_info "Could not test offloaded functionality"
116else
117 tcflags="skip_sw"
118 unreachable_chain_test
119 gact_goto_chain_test
120fi
121
122exit $EXIT_STATUS