]> www.infradead.org Git - users/hch/misc.git/commitdiff
selftests: fib_rule_tests: Add DSCP mask match tests
authorIdo Schimmel <idosch@nvidia.com>
Thu, 20 Feb 2025 08:05:25 +0000 (10:05 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sat, 22 Feb 2025 00:08:49 +0000 (16:08 -0800)
Add tests for FIB rules that match on DSCP with a mask. Test both good
and bad flows and both the input and output paths.

 # ./fib_rule_tests.sh
 IPv6 FIB rule tests
 [...]
    TEST: rule6 check: dscp redirect to table                           [ OK ]
    TEST: rule6 check: dscp no redirect to table                        [ OK ]
    TEST: rule6 del by pref: dscp redirect to table                     [ OK ]
    TEST: rule6 check: iif dscp redirect to table                       [ OK ]
    TEST: rule6 check: iif dscp no redirect to table                    [ OK ]
    TEST: rule6 del by pref: iif dscp redirect to table                 [ OK ]
    TEST: rule6 check: dscp masked redirect to table                    [ OK ]
    TEST: rule6 check: dscp masked no redirect to table                 [ OK ]
    TEST: rule6 del by pref: dscp masked redirect to table              [ OK ]
    TEST: rule6 check: iif dscp masked redirect to table                [ OK ]
    TEST: rule6 check: iif dscp masked no redirect to table             [ OK ]
    TEST: rule6 del by pref: iif dscp masked redirect to table          [ OK ]
 [...]

 Tests passed: 316
 Tests failed:   0

Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Guillaume Nault <gnault@redhat.com>
Link: https://patch.msgid.link/20250220080525.831924-7-idosch@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/fib_rule_tests.sh

index 06c51d7ceb4a1ffc05d84d0a76e5898e6c8a31e2..b866bab1d92a1caac8e32574e6d03e65ecc24530 100755 (executable)
@@ -310,6 +310,25 @@ fib_rule6_test()
                        "iif dscp no redirect to table"
        fi
 
+       ip rule help 2>&1 | grep -q "DSCP\[/MASK\]"
+       if [ $? -eq 0 ]; then
+               match="dscp 0x0f/0x0f"
+               tosmatch=$(printf 0x"%x" $((0x1f << 2)))
+               tosnomatch=$(printf 0x"%x" $((0x1e << 2)))
+               getmatch="tos $tosmatch"
+               getnomatch="tos $tosnomatch"
+               fib_rule6_test_match_n_redirect "$match" "$getmatch" \
+                       "$getnomatch" "dscp masked redirect to table" \
+                       "dscp masked no redirect to table"
+
+               match="dscp 0x0f/0x0f"
+               getmatch="from $SRC_IP6 iif $DEV tos $tosmatch"
+               getnomatch="from $SRC_IP6 iif $DEV tos $tosnomatch"
+               fib_rule6_test_match_n_redirect "$match" "$getmatch" \
+                       "$getnomatch" "iif dscp masked redirect to table" \
+                       "iif dscp masked no redirect to table"
+       fi
+
        fib_check_iproute_support "flowlabel" "flowlabel"
        if [ $? -eq 0 ]; then
                match="flowlabel 0xfffff"
@@ -597,6 +616,25 @@ fib_rule4_test()
                        "$getnomatch" "iif dscp redirect to table" \
                        "iif dscp no redirect to table"
        fi
+
+       ip rule help 2>&1 | grep -q "DSCP\[/MASK\]"
+       if [ $? -eq 0 ]; then
+               match="dscp 0x0f/0x0f"
+               tosmatch=$(printf 0x"%x" $((0x1f << 2)))
+               tosnomatch=$(printf 0x"%x" $((0x1e << 2)))
+               getmatch="tos $tosmatch"
+               getnomatch="tos $tosnomatch"
+               fib_rule4_test_match_n_redirect "$match" "$getmatch" \
+                       "$getnomatch" "dscp masked redirect to table" \
+                       "dscp masked no redirect to table"
+
+               match="dscp 0x0f/0x0f"
+               getmatch="from $SRC_IP iif $DEV tos $tosmatch"
+               getnomatch="from $SRC_IP iif $DEV tos $tosnomatch"
+               fib_rule4_test_match_n_redirect "$match" "$getmatch" \
+                       "$getnomatch" "iif dscp masked redirect to table" \
+                       "iif dscp masked no redirect to table"
+       fi
 }
 
 fib_rule4_vrf_test()