2 # SPDX-License-Identifier: GPL-2.0
4 ALL_TESTS="unreachable_chain_test gact_goto_chain_test create_destroy_chain \
14 simple_if_init $h1 192.0.2.1/24
19 simple_if_fini $h1 192.0.2.1/24
24 simple_if_init $h2 192.0.2.2/24
25 tc qdisc add dev $h2 clsact
30 tc qdisc del dev $h2 clsact
31 simple_if_fini $h2 192.0.2.2/24
34 unreachable_chain_test()
38 tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
39 flower $tcflags dst_mac $h2mac action drop
41 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
44 tc_check_packets "dev $h2 ingress" 1101 1
45 check_fail $? "matched on filter in unreachable chain"
47 tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
50 log_test "unreachable chain ($tcflags)"
53 gact_goto_chain_test()
57 tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
58 flower $tcflags dst_mac $h2mac action drop
59 tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
60 $tcflags dst_mac $h2mac action drop
61 tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
62 $tcflags dst_mac $h2mac action goto chain 1
64 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
67 tc_check_packets "dev $h2 ingress" 102 1
68 check_fail $? "Matched on a wrong filter"
70 tc_check_packets "dev $h2 ingress" 101 1
71 check_err $? "Did not match on correct filter with goto chain action"
73 tc_check_packets "dev $h2 ingress" 1101 1
74 check_err $? "Did not match on correct filter in chain 1"
76 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
77 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
78 tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
81 log_test "gact goto chain ($tcflags)"
84 create_destroy_chain()
88 tc chain add dev $h2 ingress
89 check_err $? "Failed to create default chain"
91 output="$(tc -j chain get dev $h2 ingress)"
92 check_err $? "Failed to get default chain"
94 echo $output | jq -e ".[] | select(.chain == 0)" &> /dev/null
95 check_err $? "Unexpected output for default chain"
97 tc chain add dev $h2 ingress chain 1
98 check_err $? "Failed to create chain 1"
100 output="$(tc -j chain get dev $h2 ingress chain 1)"
101 check_err $? "Failed to get chain 1"
103 echo $output | jq -e ".[] | select(.chain == 1)" &> /dev/null
104 check_err $? "Unexpected output for chain 1"
106 output="$(tc -j chain show dev $h2 ingress)"
107 check_err $? "Failed to dump chains"
109 echo $output | jq -e ".[] | select(.chain == 0)" &> /dev/null
110 check_err $? "Can't find default chain in dump"
112 echo $output | jq -e ".[] | select(.chain == 1)" &> /dev/null
113 check_err $? "Can't find chain 1 in dump"
115 tc chain del dev $h2 ingress
116 check_err $? "Failed to destroy default chain"
118 tc chain del dev $h2 ingress chain 1
119 check_err $? "Failed to destroy chain 1"
121 log_test "create destroy chain"
124 template_filter_fits()
128 tc chain add dev $h2 ingress protocol ip \
129 flower dst_mac 00:00:00:00:00:00/FF:FF:FF:FF:FF:FF &> /dev/null
130 tc chain add dev $h2 ingress chain 1 protocol ip \
131 flower src_mac 00:00:00:00:00:00/FF:FF:FF:FF:FF:FF &> /dev/null
133 tc filter add dev $h2 ingress protocol ip pref 1 handle 1101 \
134 flower dst_mac $h2mac action drop
135 check_err $? "Failed to insert filter which fits template"
137 tc filter add dev $h2 ingress protocol ip pref 1 handle 1102 \
138 flower src_mac $h2mac action drop &> /dev/null
139 check_fail $? "Incorrectly succeded to insert filter which does not template"
141 tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
142 flower src_mac $h2mac action drop
143 check_err $? "Failed to insert filter which fits template"
145 tc filter add dev $h2 ingress chain 1 protocol ip pref 1 handle 1102 \
146 flower dst_mac $h2mac action drop &> /dev/null
147 check_fail $? "Incorrectly succeded to insert filter which does not template"
149 tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1102 \
151 tc filter del dev $h2 ingress chain 1 protocol ip pref 1 handle 1101 \
154 tc filter del dev $h2 ingress protocol ip pref 1 handle 1102 \
156 tc filter del dev $h2 ingress protocol ip pref 1 handle 1101 \
159 tc chain del dev $h2 ingress chain 1
160 tc chain del dev $h2 ingress
162 log_test "template filter fits"
188 check_tc_chain_support
198 if [[ $? -ne 0 ]]; then
199 log_info "Could not test offloaded functionality"