2 # SPDX-License-Identifier: GPL-2.0
4 ALL_TESTS
="gact_drop_and_ok_test mirred_egress_redirect_test \
5 mirred_egress_mirror_test matchall_mirred_egress_mirror_test \
15 simple_if_init
$h1 192.0.2.1/24
20 simple_if_fini
$h1 192.0.2.1/24
25 simple_if_init
$h2 192.0.2.2/24
26 tc qdisc add dev
$h2 clsact
31 tc qdisc del dev
$h2 clsact
32 simple_if_fini
$h2 192.0.2.2/24
37 simple_if_init
$swp1 192.0.2.2/24
38 tc qdisc add dev
$swp1 clsact
40 simple_if_init
$swp2 192.0.2.1/24
45 simple_if_fini
$swp2 192.0.2.1/24
47 tc qdisc del dev
$swp1 clsact
48 simple_if_fini
$swp1 192.0.2.2/24
56 local classifier_args
=$4
60 tc filter add dev
$h2 ingress protocol ip pref
1 handle
101 flower \
61 $tcflags dst_ip
192.0.2.2 action drop
63 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
66 tc_check_packets
"dev $h2 ingress" 101 1
67 check_fail $?
"Matched without redirect rule inserted"
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
73 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
76 tc_check_packets
"dev $h2 ingress" 101 1
77 check_err $?
"Did not match incoming $action packet"
79 tc filter del dev
$swp1 ingress protocol
$protocol pref
1 handle
101 \
81 tc filter del dev
$h2 ingress protocol ip pref
1 handle
101 flower
83 log_test
"mirred egress $classifier $action ($tcflags)"
86 gact_drop_and_ok_test
()
90 tc filter add dev
$swp1 ingress protocol ip pref
2 handle
102 flower \
91 $tcflags dst_ip
192.0.2.2 action drop
93 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
96 tc_check_packets
"dev $swp1 ingress" 102 1
97 check_err $?
"Packet was not dropped"
99 tc filter add dev
$swp1 ingress protocol ip pref
1 handle
101 flower \
100 $tcflags dst_ip
192.0.2.2 action ok
102 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
105 tc_check_packets
"dev $swp1 ingress" 101 1
106 check_err $?
"Did not see passed packet"
108 tc_check_packets
"dev $swp1 ingress" 102 2
109 check_fail $?
"Packet was dropped and it should not reach here"
111 tc filter del dev
$swp1 ingress protocol ip pref
2 handle
102 flower
112 tc filter del dev
$swp1 ingress protocol ip pref
1 handle
101 flower
114 log_test
"gact drop and ok ($tcflags)"
121 if [[ "$tcflags" != "skip_sw" ]]; then
125 tc filter add dev
$swp1 ingress protocol ip pref
1 handle
101 flower \
126 skip_hw dst_ip
192.0.2.2 action drop
127 tc filter add dev
$swp1 ingress protocol ip pref
3 handle
103 flower \
128 $tcflags dst_ip
192.0.2.2 action mirred egress redirect \
131 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
134 tc_check_packets
"dev $swp1 ingress" 101 1
135 check_fail $?
"Saw packet without trap rule inserted"
137 tc filter add dev
$swp1 ingress protocol ip pref
2 handle
102 flower \
138 $tcflags dst_ip
192.0.2.2 action
trap
140 $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
143 tc_check_packets
"dev $swp1 ingress" 102 1
144 check_err $?
"Packet was not trapped"
146 tc_check_packets
"dev $swp1 ingress" 101 1
147 check_err $?
"Did not see trapped packet"
149 tc filter del dev
$swp1 ingress protocol ip pref
3 handle
103 flower
150 tc filter del dev
$swp1 ingress protocol ip pref
2 handle
102 flower
151 tc filter del dev
$swp1 ingress protocol ip pref
1 handle
101 flower
153 log_test
"trap ($tcflags)"
167 swp1origmac
=$
(mac_get
$swp1)
168 swp2origmac
=$
(mac_get
$swp2)
169 ip link
set $swp1 address
$h2mac
170 ip link
set $swp2 address
$h1mac
189 ip link
set $swp2 address
$swp2origmac
190 ip link
set $swp1 address
$swp1origmac
193 mirred_egress_redirect_test
()
195 mirred_egress_test
"redirect" "ip" "flower" "dst_ip 192.0.2.2"
198 mirred_egress_mirror_test
()
200 mirred_egress_test
"mirror" "ip" "flower" "dst_ip 192.0.2.2"
203 matchall_mirred_egress_mirror_test
()
205 mirred_egress_test
"mirror" "all" "matchall" ""
216 if [[ $?
-ne 0 ]]; then
217 log_info
"Could not test offloaded functionality"