.. | .. |
---|
2 | 2 | # SPDX-License-Identifier: GPL-2.0 |
---|
3 | 3 | |
---|
4 | 4 | ALL_TESTS="gact_drop_and_ok_test mirred_egress_redirect_test \ |
---|
5 | | - mirred_egress_mirror_test gact_trap_test" |
---|
| 5 | + mirred_egress_mirror_test matchall_mirred_egress_mirror_test \ |
---|
| 6 | + gact_trap_test mirred_egress_to_ingress_tcp_test" |
---|
6 | 7 | NUM_NETIFS=4 |
---|
7 | 8 | source tc_common.sh |
---|
8 | 9 | source lib.sh |
---|
.. | .. |
---|
50 | 51 | mirred_egress_test() |
---|
51 | 52 | { |
---|
52 | 53 | local action=$1 |
---|
| 54 | + local protocol=$2 |
---|
| 55 | + local classifier=$3 |
---|
| 56 | + local classifier_args=$4 |
---|
53 | 57 | |
---|
54 | 58 | RET=0 |
---|
55 | 59 | |
---|
.. | .. |
---|
62 | 66 | tc_check_packets "dev $h2 ingress" 101 1 |
---|
63 | 67 | check_fail $? "Matched without redirect rule inserted" |
---|
64 | 68 | |
---|
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 | + tc filter add dev $swp1 ingress protocol $protocol pref 1 handle 101 \ |
---|
| 70 | + $classifier $tcflags $classifier_args \ |
---|
| 71 | + action mirred egress $action dev $swp2 |
---|
68 | 72 | |
---|
69 | 73 | $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ |
---|
70 | 74 | -t ip -q |
---|
.. | .. |
---|
72 | 76 | tc_check_packets "dev $h2 ingress" 101 1 |
---|
73 | 77 | check_err $? "Did not match incoming $action packet" |
---|
74 | 78 | |
---|
75 | | - tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower |
---|
| 79 | + tc filter del dev $swp1 ingress protocol $protocol pref 1 handle 101 \ |
---|
| 80 | + $classifier |
---|
76 | 81 | tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower |
---|
77 | 82 | |
---|
78 | | - log_test "mirred egress $action ($tcflags)" |
---|
| 83 | + log_test "mirred egress $classifier $action ($tcflags)" |
---|
79 | 84 | } |
---|
80 | 85 | |
---|
81 | 86 | gact_drop_and_ok_test() |
---|
.. | .. |
---|
148 | 153 | log_test "trap ($tcflags)" |
---|
149 | 154 | } |
---|
150 | 155 | |
---|
| 156 | +mirred_egress_to_ingress_tcp_test() |
---|
| 157 | +{ |
---|
| 158 | + local tmpfile=$(mktemp) tmpfile1=$(mktemp) |
---|
| 159 | + |
---|
| 160 | + RET=0 |
---|
| 161 | + dd conv=sparse status=none if=/dev/zero bs=1M count=2 of=$tmpfile |
---|
| 162 | + tc filter add dev $h1 protocol ip pref 100 handle 100 egress flower \ |
---|
| 163 | + $tcflags ip_proto tcp src_ip 192.0.2.1 dst_ip 192.0.2.2 \ |
---|
| 164 | + action ct commit nat src addr 192.0.2.2 pipe \ |
---|
| 165 | + action ct clear pipe \ |
---|
| 166 | + action ct commit nat dst addr 192.0.2.1 pipe \ |
---|
| 167 | + action ct clear pipe \ |
---|
| 168 | + action skbedit ptype host pipe \ |
---|
| 169 | + action mirred ingress redirect dev $h1 |
---|
| 170 | + tc filter add dev $h1 protocol ip pref 101 handle 101 egress flower \ |
---|
| 171 | + $tcflags ip_proto icmp \ |
---|
| 172 | + action mirred ingress redirect dev $h1 |
---|
| 173 | + tc filter add dev $h1 protocol ip pref 102 handle 102 ingress flower \ |
---|
| 174 | + ip_proto icmp \ |
---|
| 175 | + action drop |
---|
| 176 | + |
---|
| 177 | + ip vrf exec v$h1 nc --recv-only -w10 -l -p 12345 -o $tmpfile1 & |
---|
| 178 | + local rpid=$! |
---|
| 179 | + ip vrf exec v$h1 nc -w1 --send-only 192.0.2.2 12345 <$tmpfile |
---|
| 180 | + wait -n $rpid |
---|
| 181 | + cmp -s $tmpfile $tmpfile1 |
---|
| 182 | + check_err $? "server output check failed" |
---|
| 183 | + |
---|
| 184 | + $MZ $h1 -c 10 -p 64 -a $h1mac -b $h1mac -A 192.0.2.1 -B 192.0.2.1 \ |
---|
| 185 | + -t icmp "ping,id=42,seq=5" -q |
---|
| 186 | + tc_check_packets "dev $h1 egress" 101 10 |
---|
| 187 | + check_err $? "didn't mirred redirect ICMP" |
---|
| 188 | + tc_check_packets "dev $h1 ingress" 102 10 |
---|
| 189 | + check_err $? "didn't drop mirred ICMP" |
---|
| 190 | + local overlimits=$(tc_rule_stats_get ${h1} 101 egress .overlimits) |
---|
| 191 | + test ${overlimits} = 10 |
---|
| 192 | + check_err $? "wrong overlimits, expected 10 got ${overlimits}" |
---|
| 193 | + |
---|
| 194 | + tc filter del dev $h1 egress protocol ip pref 100 handle 100 flower |
---|
| 195 | + tc filter del dev $h1 egress protocol ip pref 101 handle 101 flower |
---|
| 196 | + tc filter del dev $h1 ingress protocol ip pref 102 handle 102 flower |
---|
| 197 | + |
---|
| 198 | + rm -f $tmpfile $tmpfile1 |
---|
| 199 | + log_test "mirred_egress_to_ingress_tcp ($tcflags)" |
---|
| 200 | +} |
---|
| 201 | + |
---|
151 | 202 | setup_prepare() |
---|
152 | 203 | { |
---|
153 | 204 | h1=${NETIFS[p1]} |
---|
.. | .. |
---|
187 | 238 | |
---|
188 | 239 | mirred_egress_redirect_test() |
---|
189 | 240 | { |
---|
190 | | - mirred_egress_test "redirect" |
---|
| 241 | + mirred_egress_test "redirect" "ip" "flower" "dst_ip 192.0.2.2" |
---|
191 | 242 | } |
---|
192 | 243 | |
---|
193 | 244 | mirred_egress_mirror_test() |
---|
194 | 245 | { |
---|
195 | | - mirred_egress_test "mirror" |
---|
| 246 | + mirred_egress_test "mirror" "ip" "flower" "dst_ip 192.0.2.2" |
---|
| 247 | +} |
---|
| 248 | + |
---|
| 249 | +matchall_mirred_egress_mirror_test() |
---|
| 250 | +{ |
---|
| 251 | + mirred_egress_test "mirror" "all" "matchall" "" |
---|
196 | 252 | } |
---|
197 | 253 | |
---|
198 | 254 | trap cleanup EXIT |
---|