Skip to content

Commit 7aceeb7

Browse files
committed
Merge branch 'tc-mpls-selftests'
Guillaume Nault says: ==================== selftests: tc: Test tc-flower's MPLS features A couple of patches for exercising the MPLS filters of tc-flower. Patch 1 tests basic MPLS matching features: those that only work on the first label stack entry (that is, the mpls_label, mpls_tc, mpls_bos and mpls_ttl options). Patch 2 tests the more generic "mpls" and "lse" options, which allow matching MPLS fields beyond the first stack entry. In both patches, special care is taken to skip these new tests for incompatible versions of tc. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 4098ced + c09bfd9 commit 7aceeb7

File tree

3 files changed

+348
-1
lines changed

3 files changed

+348
-1
lines changed

tools/testing/selftests/net/forwarding/config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ CONFIG_NET_ACT_MIRRED=m
1010
CONFIG_NET_ACT_MPLS=m
1111
CONFIG_NET_ACT_VLAN=m
1212
CONFIG_NET_CLS_FLOWER=m
13+
CONFIG_NET_CLS_MATCHALL=m
1314
CONFIG_NET_SCH_INGRESS=m
1415
CONFIG_NET_ACT_GACT=m
1516
CONFIG_VETH=m

tools/testing/selftests/net/forwarding/lib.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,47 @@ check_tc_version()
4242
fi
4343
}
4444

45+
# Old versions of tc don't understand "mpls_uc"
46+
check_tc_mpls_support()
47+
{
48+
local dev=$1; shift
49+
50+
tc filter add dev $dev ingress protocol mpls_uc pref 1 handle 1 \
51+
matchall action pipe &> /dev/null
52+
if [[ $? -ne 0 ]]; then
53+
echo "SKIP: iproute2 too old; tc is missing MPLS support"
54+
return 1
55+
fi
56+
tc filter del dev $dev ingress protocol mpls_uc pref 1 handle 1 \
57+
matchall
58+
}
59+
60+
# Old versions of tc produce invalid json output for mpls lse statistics
61+
check_tc_mpls_lse_stats()
62+
{
63+
local dev=$1; shift
64+
local ret;
65+
66+
tc filter add dev $dev ingress protocol mpls_uc pref 1 handle 1 \
67+
flower mpls lse depth 2 \
68+
action continue &> /dev/null
69+
70+
if [[ $? -ne 0 ]]; then
71+
echo "SKIP: iproute2 too old; tc-flower is missing extended MPLS support"
72+
return 1
73+
fi
74+
75+
tc -j filter show dev $dev ingress protocol mpls_uc | jq . &> /dev/null
76+
ret=$?
77+
tc filter del dev $dev ingress protocol mpls_uc pref 1 handle 1 \
78+
flower
79+
80+
if [[ $ret -ne 0 ]]; then
81+
echo "SKIP: iproute2 too old; tc-flower produces invalid json output for extended MPLS filters"
82+
return 1
83+
fi
84+
}
85+
4586
check_tc_shblock_support()
4687
{
4788
tc filter help 2>&1 | grep block &> /dev/null

tools/testing/selftests/net/forwarding/tc_flower.sh

Lines changed: 306 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
ALL_TESTS="match_dst_mac_test match_src_mac_test match_dst_ip_test \
55
match_src_ip_test match_ip_flags_test match_pcp_test match_vlan_test \
6-
match_ip_tos_test match_indev_test"
6+
match_ip_tos_test match_indev_test match_mpls_label_test \
7+
match_mpls_tc_test match_mpls_bos_test match_mpls_ttl_test \
8+
match_mpls_lse_test"
79
NUM_NETIFS=2
810
source tc_common.sh
911
source lib.sh
@@ -334,6 +336,309 @@ match_indev_test()
334336
log_test "indev match ($tcflags)"
335337
}
336338

339+
# Unfortunately, mausezahn can't build MPLS headers when used in L2
340+
# mode, so we have this function to build Label Stack Entries.
341+
mpls_lse()
342+
{
343+
local label=$1
344+
local tc=$2
345+
local bos=$3
346+
local ttl=$4
347+
348+
printf "%02x %02x %02x %02x" \
349+
$((label >> 12)) \
350+
$((label >> 4 & 0xff)) \
351+
$((((label & 0xf) << 4) + (tc << 1) + bos)) \
352+
$ttl
353+
}
354+
355+
match_mpls_label_test()
356+
{
357+
local ethtype="88 47"; readonly ethtype
358+
local pkt
359+
360+
RET=0
361+
362+
check_tc_mpls_support $h2 || return 0
363+
364+
tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
365+
flower $tcflags mpls_label 0 action drop
366+
tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
367+
flower $tcflags mpls_label 1048575 action drop
368+
369+
pkt="$ethtype $(mpls_lse 1048575 0 1 255)"
370+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
371+
372+
tc_check_packets "dev $h2 ingress" 101 1
373+
check_fail $? "Matched on a wrong filter (1048575)"
374+
375+
tc_check_packets "dev $h2 ingress" 102 1
376+
check_err $? "Did not match on correct filter (1048575)"
377+
378+
pkt="$ethtype $(mpls_lse 0 0 1 255)"
379+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
380+
381+
tc_check_packets "dev $h2 ingress" 102 2
382+
check_fail $? "Matched on a wrong filter (0)"
383+
384+
tc_check_packets "dev $h2 ingress" 101 1
385+
check_err $? "Did not match on correct filter (0)"
386+
387+
tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
388+
tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
389+
390+
log_test "mpls_label match ($tcflags)"
391+
}
392+
393+
match_mpls_tc_test()
394+
{
395+
local ethtype="88 47"; readonly ethtype
396+
local pkt
397+
398+
RET=0
399+
400+
check_tc_mpls_support $h2 || return 0
401+
402+
tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
403+
flower $tcflags mpls_tc 0 action drop
404+
tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
405+
flower $tcflags mpls_tc 7 action drop
406+
407+
pkt="$ethtype $(mpls_lse 0 7 1 255)"
408+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
409+
410+
tc_check_packets "dev $h2 ingress" 101 1
411+
check_fail $? "Matched on a wrong filter (7)"
412+
413+
tc_check_packets "dev $h2 ingress" 102 1
414+
check_err $? "Did not match on correct filter (7)"
415+
416+
pkt="$ethtype $(mpls_lse 0 0 1 255)"
417+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
418+
419+
tc_check_packets "dev $h2 ingress" 102 2
420+
check_fail $? "Matched on a wrong filter (0)"
421+
422+
tc_check_packets "dev $h2 ingress" 101 1
423+
check_err $? "Did not match on correct filter (0)"
424+
425+
tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
426+
tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
427+
428+
log_test "mpls_tc match ($tcflags)"
429+
}
430+
431+
match_mpls_bos_test()
432+
{
433+
local ethtype="88 47"; readonly ethtype
434+
local pkt
435+
436+
RET=0
437+
438+
check_tc_mpls_support $h2 || return 0
439+
440+
tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
441+
flower $tcflags mpls_bos 0 action drop
442+
tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
443+
flower $tcflags mpls_bos 1 action drop
444+
445+
pkt="$ethtype $(mpls_lse 0 0 1 255)"
446+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
447+
448+
tc_check_packets "dev $h2 ingress" 101 1
449+
check_fail $? "Matched on a wrong filter (1)"
450+
451+
tc_check_packets "dev $h2 ingress" 102 1
452+
check_err $? "Did not match on correct filter (1)"
453+
454+
# Need to add a second label to properly mark the Bottom of Stack
455+
pkt="$ethtype $(mpls_lse 0 0 0 255) $(mpls_lse 0 0 1 255)"
456+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
457+
458+
tc_check_packets "dev $h2 ingress" 102 2
459+
check_fail $? "Matched on a wrong filter (0)"
460+
461+
tc_check_packets "dev $h2 ingress" 101 1
462+
check_err $? "Did not match on correct filter (0)"
463+
464+
tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
465+
tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
466+
467+
log_test "mpls_bos match ($tcflags)"
468+
}
469+
470+
match_mpls_ttl_test()
471+
{
472+
local ethtype="88 47"; readonly ethtype
473+
local pkt
474+
475+
RET=0
476+
477+
check_tc_mpls_support $h2 || return 0
478+
479+
tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
480+
flower $tcflags mpls_ttl 0 action drop
481+
tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
482+
flower $tcflags mpls_ttl 255 action drop
483+
484+
pkt="$ethtype $(mpls_lse 0 0 1 255)"
485+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
486+
487+
tc_check_packets "dev $h2 ingress" 101 1
488+
check_fail $? "Matched on a wrong filter (255)"
489+
490+
tc_check_packets "dev $h2 ingress" 102 1
491+
check_err $? "Did not match on correct filter (255)"
492+
493+
pkt="$ethtype $(mpls_lse 0 0 1 0)"
494+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
495+
496+
tc_check_packets "dev $h2 ingress" 102 2
497+
check_fail $? "Matched on a wrong filter (0)"
498+
499+
tc_check_packets "dev $h2 ingress" 101 1
500+
check_err $? "Did not match on correct filter (0)"
501+
502+
tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
503+
tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
504+
505+
log_test "mpls_ttl match ($tcflags)"
506+
}
507+
508+
match_mpls_lse_test()
509+
{
510+
local ethtype="88 47"; readonly ethtype
511+
local pkt
512+
513+
RET=0
514+
515+
check_tc_mpls_lse_stats $h2 || return 0
516+
517+
# Match on first LSE (minimal values for each field)
518+
tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
519+
flower $tcflags mpls lse depth 1 label 0 action continue
520+
tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
521+
flower $tcflags mpls lse depth 1 tc 0 action continue
522+
tc filter add dev $h2 ingress protocol mpls_uc pref 3 handle 103 \
523+
flower $tcflags mpls lse depth 1 bos 0 action continue
524+
tc filter add dev $h2 ingress protocol mpls_uc pref 4 handle 104 \
525+
flower $tcflags mpls lse depth 1 ttl 0 action continue
526+
527+
# Match on second LSE (maximal values for each field)
528+
tc filter add dev $h2 ingress protocol mpls_uc pref 5 handle 105 \
529+
flower $tcflags mpls lse depth 2 label 1048575 action continue
530+
tc filter add dev $h2 ingress protocol mpls_uc pref 6 handle 106 \
531+
flower $tcflags mpls lse depth 2 tc 7 action continue
532+
tc filter add dev $h2 ingress protocol mpls_uc pref 7 handle 107 \
533+
flower $tcflags mpls lse depth 2 bos 1 action continue
534+
tc filter add dev $h2 ingress protocol mpls_uc pref 8 handle 108 \
535+
flower $tcflags mpls lse depth 2 ttl 255 action continue
536+
537+
# Match on LSE depth
538+
tc filter add dev $h2 ingress protocol mpls_uc pref 9 handle 109 \
539+
flower $tcflags mpls lse depth 1 action continue
540+
tc filter add dev $h2 ingress protocol mpls_uc pref 10 handle 110 \
541+
flower $tcflags mpls lse depth 2 action continue
542+
tc filter add dev $h2 ingress protocol mpls_uc pref 11 handle 111 \
543+
flower $tcflags mpls lse depth 3 action continue
544+
545+
# Base packet, matched by all filters (except for stack depth 3)
546+
pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048575 7 1 255)"
547+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
548+
549+
# Make a variant of the above packet, with a non-matching value
550+
# for each LSE field
551+
552+
# Wrong label at depth 1
553+
pkt="$ethtype $(mpls_lse 1 0 0 0) $(mpls_lse 1048575 7 1 255)"
554+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
555+
556+
# Wrong TC at depth 1
557+
pkt="$ethtype $(mpls_lse 0 1 0 0) $(mpls_lse 1048575 7 1 255)"
558+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
559+
560+
# Wrong BOS at depth 1 (not adding a second LSE here since BOS is set
561+
# in the first label, so anything that'd follow wouldn't be considered)
562+
pkt="$ethtype $(mpls_lse 0 0 1 0)"
563+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
564+
565+
# Wrong TTL at depth 1
566+
pkt="$ethtype $(mpls_lse 0 0 0 1) $(mpls_lse 1048575 7 1 255)"
567+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
568+
569+
# Wrong label at depth 2
570+
pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048574 7 1 255)"
571+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
572+
573+
# Wrong TC at depth 2
574+
pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048575 6 1 255)"
575+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
576+
577+
# Wrong BOS at depth 2 (adding a third LSE here since BOS isn't set in
578+
# the second label)
579+
pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048575 7 0 255)"
580+
pkt="$pkt $(mpls_lse 0 0 1 255)"
581+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
582+
583+
# Wrong TTL at depth 2
584+
pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048575 7 1 254)"
585+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
586+
587+
# Filters working at depth 1 should match all packets but one
588+
589+
tc_check_packets "dev $h2 ingress" 101 8
590+
check_err $? "Did not match on correct filter"
591+
592+
tc_check_packets "dev $h2 ingress" 102 8
593+
check_err $? "Did not match on correct filter"
594+
595+
tc_check_packets "dev $h2 ingress" 103 8
596+
check_err $? "Did not match on correct filter"
597+
598+
tc_check_packets "dev $h2 ingress" 104 8
599+
check_err $? "Did not match on correct filter"
600+
601+
# Filters working at depth 2 should match all packets but two (because
602+
# of the test packet where the label stack depth is just one)
603+
604+
tc_check_packets "dev $h2 ingress" 105 7
605+
check_err $? "Did not match on correct filter"
606+
607+
tc_check_packets "dev $h2 ingress" 106 7
608+
check_err $? "Did not match on correct filter"
609+
610+
tc_check_packets "dev $h2 ingress" 107 7
611+
check_err $? "Did not match on correct filter"
612+
613+
tc_check_packets "dev $h2 ingress" 108 7
614+
check_err $? "Did not match on correct filter"
615+
616+
# Finally, verify the filters that only match on LSE depth
617+
618+
tc_check_packets "dev $h2 ingress" 109 9
619+
check_err $? "Did not match on correct filter"
620+
621+
tc_check_packets "dev $h2 ingress" 110 8
622+
check_err $? "Did not match on correct filter"
623+
624+
tc_check_packets "dev $h2 ingress" 111 1
625+
check_err $? "Did not match on correct filter"
626+
627+
tc filter del dev $h2 ingress protocol mpls_uc pref 11 handle 111 flower
628+
tc filter del dev $h2 ingress protocol mpls_uc pref 10 handle 110 flower
629+
tc filter del dev $h2 ingress protocol mpls_uc pref 9 handle 109 flower
630+
tc filter del dev $h2 ingress protocol mpls_uc pref 8 handle 108 flower
631+
tc filter del dev $h2 ingress protocol mpls_uc pref 7 handle 107 flower
632+
tc filter del dev $h2 ingress protocol mpls_uc pref 6 handle 106 flower
633+
tc filter del dev $h2 ingress protocol mpls_uc pref 5 handle 105 flower
634+
tc filter del dev $h2 ingress protocol mpls_uc pref 4 handle 104 flower
635+
tc filter del dev $h2 ingress protocol mpls_uc pref 3 handle 103 flower
636+
tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
637+
tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
638+
639+
log_test "mpls lse match ($tcflags)"
640+
}
641+
337642
setup_prepare()
338643
{
339644
h1=${NETIFS[p1]}

0 commit comments

Comments
 (0)