forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/tools/testing/selftests/net/forwarding/tc_flower.sh
....@@ -2,7 +2,8 @@
22 # SPDX-License-Identifier: GPL-2.0
33
44 ALL_TESTS="match_dst_mac_test match_src_mac_test match_dst_ip_test \
5
- match_src_ip_test match_ip_flags_test"
5
+ match_src_ip_test match_ip_flags_test match_pcp_test match_vlan_test \
6
+ match_ip_tos_test match_indev_test match_ip_ttl_test"
67 NUM_NETIFS=2
78 source tc_common.sh
89 source lib.sh
....@@ -48,8 +49,8 @@
4849 tc_check_packets "dev $h2 ingress" 101 1
4950 check_fail $? "Matched on a wrong filter"
5051
51
- tc_check_packets "dev $h2 ingress" 102 1
52
- check_err $? "Did not match on correct filter"
52
+ tc_check_packets "dev $h2 ingress" 102 0
53
+ check_fail $? "Did not match on correct filter"
5354
5455 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
5556 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
....@@ -74,8 +75,8 @@
7475 tc_check_packets "dev $h2 ingress" 101 1
7576 check_fail $? "Matched on a wrong filter"
7677
77
- tc_check_packets "dev $h2 ingress" 102 1
78
- check_err $? "Did not match on correct filter"
78
+ tc_check_packets "dev $h2 ingress" 102 0
79
+ check_fail $? "Did not match on correct filter"
7980
8081 tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
8182 tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
....@@ -219,6 +220,156 @@
219220 log_test "ip_flags match ($tcflags)"
220221 }
221222
223
+match_pcp_test()
224
+{
225
+ RET=0
226
+
227
+ vlan_create $h2 85 v$h2 192.0.2.11/24
228
+
229
+ tc filter add dev $h2 ingress protocol 802.1q pref 1 handle 101 \
230
+ flower vlan_prio 6 $tcflags dst_mac $h2mac action drop
231
+ tc filter add dev $h2 ingress protocol 802.1q pref 2 handle 102 \
232
+ flower vlan_prio 7 $tcflags dst_mac $h2mac action drop
233
+
234
+ $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 7:85 -t ip -q
235
+ $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 0:85 -t ip -q
236
+
237
+ tc_check_packets "dev $h2 ingress" 101 0
238
+ check_err $? "Matched on specified PCP when should not"
239
+
240
+ tc_check_packets "dev $h2 ingress" 102 1
241
+ check_err $? "Did not match on specified PCP"
242
+
243
+ tc filter del dev $h2 ingress protocol 802.1q pref 2 handle 102 flower
244
+ tc filter del dev $h2 ingress protocol 802.1q pref 1 handle 101 flower
245
+
246
+ vlan_destroy $h2 85
247
+
248
+ log_test "PCP match ($tcflags)"
249
+}
250
+
251
+match_vlan_test()
252
+{
253
+ RET=0
254
+
255
+ vlan_create $h2 85 v$h2 192.0.2.11/24
256
+ vlan_create $h2 75 v$h2 192.0.2.10/24
257
+
258
+ tc filter add dev $h2 ingress protocol 802.1q pref 1 handle 101 \
259
+ flower vlan_id 75 $tcflags action drop
260
+ tc filter add dev $h2 ingress protocol 802.1q pref 2 handle 102 \
261
+ flower vlan_id 85 $tcflags action drop
262
+
263
+ $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 0:85 -t ip -q
264
+
265
+ tc_check_packets "dev $h2 ingress" 101 0
266
+ check_err $? "Matched on specified VLAN when should not"
267
+
268
+ tc_check_packets "dev $h2 ingress" 102 1
269
+ check_err $? "Did not match on specified VLAN"
270
+
271
+ tc filter del dev $h2 ingress protocol 802.1q pref 2 handle 102 flower
272
+ tc filter del dev $h2 ingress protocol 802.1q pref 1 handle 101 flower
273
+
274
+ vlan_destroy $h2 75
275
+ vlan_destroy $h2 85
276
+
277
+ log_test "VLAN match ($tcflags)"
278
+}
279
+
280
+match_ip_tos_test()
281
+{
282
+ RET=0
283
+
284
+ tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
285
+ $tcflags dst_ip 192.0.2.2 ip_tos 0x20 action drop
286
+ tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
287
+ $tcflags dst_ip 192.0.2.2 ip_tos 0x18 action drop
288
+
289
+ $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
290
+ -t ip tos=18 -q
291
+
292
+ tc_check_packets "dev $h2 ingress" 101 1
293
+ check_fail $? "Matched on a wrong filter (0x18)"
294
+
295
+ tc_check_packets "dev $h2 ingress" 102 1
296
+ check_err $? "Did not match on correct filter (0x18)"
297
+
298
+ $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
299
+ -t ip tos=20 -q
300
+
301
+ tc_check_packets "dev $h2 ingress" 102 2
302
+ check_fail $? "Matched on a wrong filter (0x20)"
303
+
304
+ tc_check_packets "dev $h2 ingress" 101 1
305
+ check_err $? "Did not match on correct filter (0x20)"
306
+
307
+ tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
308
+ tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
309
+
310
+ log_test "ip_tos match ($tcflags)"
311
+}
312
+
313
+match_ip_ttl_test()
314
+{
315
+ RET=0
316
+
317
+ tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
318
+ $tcflags dst_ip 192.0.2.2 ip_ttl 63 action drop
319
+ tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
320
+ $tcflags dst_ip 192.0.2.2 action drop
321
+
322
+ $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
323
+ -t ip "ttl=63" -q
324
+
325
+ $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
326
+ -t ip "ttl=63,mf,frag=256" -q
327
+
328
+ tc_check_packets "dev $h2 ingress" 102 1
329
+ check_fail $? "Matched on the wrong filter (no check on ttl)"
330
+
331
+ tc_check_packets "dev $h2 ingress" 101 2
332
+ check_err $? "Did not match on correct filter (ttl=63)"
333
+
334
+ $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
335
+ -t ip "ttl=255" -q
336
+
337
+ tc_check_packets "dev $h2 ingress" 101 3
338
+ check_fail $? "Matched on a wrong filter (ttl=63)"
339
+
340
+ tc_check_packets "dev $h2 ingress" 102 1
341
+ check_err $? "Did not match on correct filter (no check on ttl)"
342
+
343
+ tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
344
+ tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
345
+
346
+ log_test "ip_ttl match ($tcflags)"
347
+}
348
+
349
+match_indev_test()
350
+{
351
+ RET=0
352
+
353
+ tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
354
+ $tcflags indev $h1 dst_mac $h2mac action drop
355
+ tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
356
+ $tcflags indev $h2 dst_mac $h2mac action drop
357
+
358
+ $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
359
+ -t ip -q
360
+
361
+ tc_check_packets "dev $h2 ingress" 101 1
362
+ check_fail $? "Matched on a wrong filter"
363
+
364
+ tc_check_packets "dev $h2 ingress" 102 1
365
+ check_err $? "Did not match on correct filter"
366
+
367
+ tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
368
+ tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
369
+
370
+ log_test "indev match ($tcflags)"
371
+}
372
+
222373 setup_prepare()
223374 {
224375 h1=${NETIFS[p1]}