Skip to content

Commit 203ee5c

Browse files
Guillaume Naultdavem330
authored andcommitted
selftests: tc: Add basic mpls_* matching support for tc-flower
Add tests in tc_flower.sh for mpls_label, mpls_tc, mpls_bos and mpls_ttl. For each keyword, test the minimal and maximal values. Selectively skip these new mpls tests for tc versions that don't support them. Signed-off-by: Guillaume Nault <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 4098ced commit 203ee5c

File tree

3 files changed

+187
-1
lines changed

3 files changed

+187
-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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ 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+
4560
check_tc_shblock_support()
4661
{
4762
tc filter help 2>&1 | grep block &> /dev/null

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

Lines changed: 171 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
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"
78
NUM_NETIFS=2
89
source tc_common.sh
910
source lib.sh
@@ -334,6 +335,175 @@ match_indev_test()
334335
log_test "indev match ($tcflags)"
335336
}
336337

338+
# Unfortunately, mausezahn can't build MPLS headers when used in L2
339+
# mode, so we have this function to build Label Stack Entries.
340+
mpls_lse()
341+
{
342+
local label=$1
343+
local tc=$2
344+
local bos=$3
345+
local ttl=$4
346+
347+
printf "%02x %02x %02x %02x" \
348+
$((label >> 12)) \
349+
$((label >> 4 & 0xff)) \
350+
$((((label & 0xf) << 4) + (tc << 1) + bos)) \
351+
$ttl
352+
}
353+
354+
match_mpls_label_test()
355+
{
356+
local ethtype="88 47"; readonly ethtype
357+
local pkt
358+
359+
RET=0
360+
361+
check_tc_mpls_support $h2 || return 0
362+
363+
tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
364+
flower $tcflags mpls_label 0 action drop
365+
tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
366+
flower $tcflags mpls_label 1048575 action drop
367+
368+
pkt="$ethtype $(mpls_lse 1048575 0 1 255)"
369+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
370+
371+
tc_check_packets "dev $h2 ingress" 101 1
372+
check_fail $? "Matched on a wrong filter (1048575)"
373+
374+
tc_check_packets "dev $h2 ingress" 102 1
375+
check_err $? "Did not match on correct filter (1048575)"
376+
377+
pkt="$ethtype $(mpls_lse 0 0 1 255)"
378+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
379+
380+
tc_check_packets "dev $h2 ingress" 102 2
381+
check_fail $? "Matched on a wrong filter (0)"
382+
383+
tc_check_packets "dev $h2 ingress" 101 1
384+
check_err $? "Did not match on correct filter (0)"
385+
386+
tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
387+
tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
388+
389+
log_test "mpls_label match ($tcflags)"
390+
}
391+
392+
match_mpls_tc_test()
393+
{
394+
local ethtype="88 47"; readonly ethtype
395+
local pkt
396+
397+
RET=0
398+
399+
check_tc_mpls_support $h2 || return 0
400+
401+
tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
402+
flower $tcflags mpls_tc 0 action drop
403+
tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
404+
flower $tcflags mpls_tc 7 action drop
405+
406+
pkt="$ethtype $(mpls_lse 0 7 1 255)"
407+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
408+
409+
tc_check_packets "dev $h2 ingress" 101 1
410+
check_fail $? "Matched on a wrong filter (7)"
411+
412+
tc_check_packets "dev $h2 ingress" 102 1
413+
check_err $? "Did not match on correct filter (7)"
414+
415+
pkt="$ethtype $(mpls_lse 0 0 1 255)"
416+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
417+
418+
tc_check_packets "dev $h2 ingress" 102 2
419+
check_fail $? "Matched on a wrong filter (0)"
420+
421+
tc_check_packets "dev $h2 ingress" 101 1
422+
check_err $? "Did not match on correct filter (0)"
423+
424+
tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
425+
tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
426+
427+
log_test "mpls_tc match ($tcflags)"
428+
}
429+
430+
match_mpls_bos_test()
431+
{
432+
local ethtype="88 47"; readonly ethtype
433+
local pkt
434+
435+
RET=0
436+
437+
check_tc_mpls_support $h2 || return 0
438+
439+
tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
440+
flower $tcflags mpls_bos 0 action drop
441+
tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
442+
flower $tcflags mpls_bos 1 action drop
443+
444+
pkt="$ethtype $(mpls_lse 0 0 1 255)"
445+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
446+
447+
tc_check_packets "dev $h2 ingress" 101 1
448+
check_fail $? "Matched on a wrong filter (1)"
449+
450+
tc_check_packets "dev $h2 ingress" 102 1
451+
check_err $? "Did not match on correct filter (1)"
452+
453+
# Need to add a second label to properly mark the Bottom of Stack
454+
pkt="$ethtype $(mpls_lse 0 0 0 255) $(mpls_lse 0 0 1 255)"
455+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
456+
457+
tc_check_packets "dev $h2 ingress" 102 2
458+
check_fail $? "Matched on a wrong filter (0)"
459+
460+
tc_check_packets "dev $h2 ingress" 101 1
461+
check_err $? "Did not match on correct filter (0)"
462+
463+
tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
464+
tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
465+
466+
log_test "mpls_bos match ($tcflags)"
467+
}
468+
469+
match_mpls_ttl_test()
470+
{
471+
local ethtype="88 47"; readonly ethtype
472+
local pkt
473+
474+
RET=0
475+
476+
check_tc_mpls_support $h2 || return 0
477+
478+
tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
479+
flower $tcflags mpls_ttl 0 action drop
480+
tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
481+
flower $tcflags mpls_ttl 255 action drop
482+
483+
pkt="$ethtype $(mpls_lse 0 0 1 255)"
484+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
485+
486+
tc_check_packets "dev $h2 ingress" 101 1
487+
check_fail $? "Matched on a wrong filter (255)"
488+
489+
tc_check_packets "dev $h2 ingress" 102 1
490+
check_err $? "Did not match on correct filter (255)"
491+
492+
pkt="$ethtype $(mpls_lse 0 0 1 0)"
493+
$MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
494+
495+
tc_check_packets "dev $h2 ingress" 102 2
496+
check_fail $? "Matched on a wrong filter (0)"
497+
498+
tc_check_packets "dev $h2 ingress" 101 1
499+
check_err $? "Did not match on correct filter (0)"
500+
501+
tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
502+
tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
503+
504+
log_test "mpls_ttl match ($tcflags)"
505+
}
506+
337507
setup_prepare()
338508
{
339509
h1=${NETIFS[p1]}

0 commit comments

Comments
 (0)