2 # SPDX-License-Identifier: GPL-2.0
4 # This test sends traffic from H1 to H2. Either on ingress of $swp1, or on
5 # egress of $swp2, the traffic is acted upon by a pedit action. An ingress
6 # filter installed on $h2 verifies that the packet looks like expected.
8 # +----------------------+ +----------------------+
11 # | | 192.0.2.1/28 | | 192.0.2.2/28 | |
12 # +----|-----------------+ +----------------|-----+
14 # +----|----------------------------------------------------------------|-----+
16 # | +-|----------------------------------------------------------------|-+ |
17 # | | + $swp1 BR $swp2 + | |
18 # | +--------------------------------------------------------------------+ |
19 # +---------------------------------------------------------------------------+
37 : ${HIT_TIMEOUT:=2000} # ms
41 simple_if_init
$h1 192.0.2.1/28 2001:db8
:1::1/64
46 simple_if_fini
$h1 192.0.2.1/28 2001:db8
:1::1/64
51 simple_if_init
$h2 192.0.2.2/28 2001:db8
:1::2/64
52 tc qdisc add dev
$h2 clsact
57 tc qdisc del dev
$h2 clsact
58 simple_if_fini
$h2 192.0.2.2/28 2001:db8
:1::2/64
63 ip link add name br1 up
type bridge vlan_filtering
1
64 ip link
set dev
$swp1 master br1
65 ip link
set dev
$swp1 up
66 ip link
set dev
$swp2 master br1
67 ip link
set dev
$swp2 up
69 tc qdisc add dev
$swp1 clsact
70 tc qdisc add dev
$swp2 clsact
75 tc qdisc del dev
$swp2 clsact
76 tc qdisc del dev
$swp1 clsact
78 ip link
set dev
$swp2 nomaster
79 ip link
set dev
$swp1 nomaster
111 ping_test
$h1 192.0.2.2
116 ping6_test
$h1 2001:db8
:1::2
119 do_test_pedit_dsfield_common
()
121 local pedit_locus
=$1; shift
122 local pedit_action
=$1; shift
123 local mz_flags
=$1; shift
127 # TOS 125: DSCP 31, ECN 1. Used for testing that the relevant part is
128 # overwritten when zero is selected.
129 $MZ $mz_flags $h1 -c 10 -d 20msec
-p 100 \
130 -a own
-b $h2mac -q -t tcp tos
=0x7d,sp
=54321,dp
=12345
133 pkts
=$
(busywait
"$TC_HIT_TIMEOUT" until_counter_is
">= 10" \
134 tc_rule_handle_stats_get
"dev $h2 ingress" 101)
135 check_err $?
"Expected to get 10 packets on test probe, but got $pkts."
137 pkts
=$
(tc_rule_handle_stats_get
"$pedit_locus" 101)
139 check_err $?
"Expected to get 10 packets on pedit rule, but got $pkts."
141 log_test
"$pedit_locus pedit $pedit_action"
144 do_test_pedit_dsfield
()
146 local pedit_locus
=$1; shift
147 local pedit_action
=$1; shift
148 local match_prot
=$1; shift
149 local match_flower
=$1; shift
150 local mz_flags
=$1; shift
151 local saddr
=$1; shift
152 local daddr
=$1; shift
154 tc filter add
$pedit_locus handle
101 pref
1 \
155 flower action pedit ex munge
$pedit_action
156 tc filter add dev
$h2 ingress handle
101 pref
1 prot
$match_prot \
157 flower skip_hw
$match_flower action pass
159 do_test_pedit_dsfield_common
"$pedit_locus" "$pedit_action" "$mz_flags"
161 tc filter del dev
$h2 ingress pref
1
162 tc filter del
$pedit_locus pref
1
167 local locus
=$1; shift
170 for dsfield
in 0 1 2 3 128 252 253 254 255; do
171 do_test_pedit_dsfield
"$locus" \
172 "ip dsfield set $dsfield" \
173 ip
"ip_tos $dsfield" \
174 "-A 192.0.2.1 -B 192.0.2.2"
180 do_test_ip_dsfield
"dev $swp1 ingress"
181 do_test_ip_dsfield
"dev $swp2 egress"
186 local locus
=$1; shift
189 for dscp
in 0 1 2 3 32 61 62 63; do
190 do_test_pedit_dsfield
"$locus" \
191 "ip dsfield set $((dscp << 2)) retain 0xfc" \
192 ip
"ip_tos $(((dscp << 2) | 1))" \
193 "-A 192.0.2.1 -B 192.0.2.2"
199 do_test_ip_dscp
"dev $swp1 ingress"
200 do_test_ip_dscp
"dev $swp2 egress"
205 local locus
=$1; shift
208 for ecn
in 0 1 2 3; do
209 do_test_pedit_dsfield
"$locus" \
210 "ip dsfield set $ecn retain 0x03" \
211 ip
"ip_tos $((124 | $ecn))" \
212 "-A 192.0.2.1 -B 192.0.2.2"
218 do_test_ip_ecn
"dev $swp1 ingress"
219 do_test_ip_ecn
"dev $swp2 egress"
222 do_test_ip_dscp_ecn
()
224 local locus
=$1; shift
226 tc filter add
$locus handle
101 pref
1 \
227 flower action pedit ex munge ip dsfield
set 124 retain
0xfc \
228 action pedit ex munge ip dsfield
set 1 retain
0x03
229 tc filter add dev
$h2 ingress handle
101 pref
1 prot ip \
230 flower skip_hw ip_tos
125 action pass
232 do_test_pedit_dsfield_common
"$locus" "set DSCP + set ECN" \
233 "-A 192.0.2.1 -B 192.0.2.2"
235 tc filter del dev
$h2 ingress pref
1
236 tc filter del
$locus pref
1
241 do_test_ip_dscp_ecn
"dev $swp1 ingress"
242 do_test_ip_dscp_ecn
"dev $swp2 egress"
245 do_test_ip6_dsfield
()
247 local locus
=$1; shift
250 for dsfield
in 0 1 2 3 128 252 253 254 255; do
251 do_test_pedit_dsfield
"$locus" \
252 "ip6 traffic_class set $dsfield" \
253 ipv6
"ip_tos $dsfield" \
254 "-6 -A 2001:db8:1::1 -B 2001:db8:1::2"
260 do_test_ip6_dsfield
"dev $swp1 ingress"
261 do_test_ip6_dsfield
"dev $swp2 egress"
266 local locus
=$1; shift
269 for dscp
in 0 1 2 3 32 61 62 63; do
270 do_test_pedit_dsfield
"$locus" \
271 "ip6 traffic_class set $((dscp << 2)) retain 0xfc" \
272 ipv6
"ip_tos $(((dscp << 2) | 1))" \
273 "-6 -A 2001:db8:1::1 -B 2001:db8:1::2"
279 do_test_ip6_dscp
"dev $swp1 ingress"
280 do_test_ip6_dscp
"dev $swp2 egress"
285 local locus
=$1; shift
288 for ecn
in 0 1 2 3; do
289 do_test_pedit_dsfield
"$locus" \
290 "ip6 traffic_class set $ecn retain 0x3" \
291 ipv6
"ip_tos $((124 | $ecn))" \
292 "-6 -A 2001:db8:1::1 -B 2001:db8:1::2"
298 do_test_ip6_ecn
"dev $swp1 ingress"
299 do_test_ip6_ecn
"dev $swp2 egress"