selftests: fib_rule_tests: Add port mask match tests
authorIdo Schimmel <idosch@nvidia.com>
Mon, 17 Feb 2025 13:41:09 +0000 (15:41 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 20 Feb 2025 02:43:38 +0000 (18:43 -0800)
Add tests for FIB rules that match on source and destination ports with
a mask. Test both good and bad flows.

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

 Tests passed: 292
 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>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://patch.msgid.link/20250217134109.311176-9-idosch@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
tools/testing/selftests/net/fib_rule_tests.sh

index 12a6e21..06c51d7 100755 (executable)
@@ -266,6 +266,16 @@ fib_rule6_test()
                        "sport and dport range no redirect to table"
        fi
 
+       ip rule help 2>&1 | grep sport | grep -q MASK
+       if [ $? -eq 0 ]; then
+               match="sport 0x0f00/0xff00 dport 0x000f/0x00ff"
+               getmatch="sport 0x0f11 dport 0x220f"
+               getnomatch="sport 0x1f11 dport 0x221f"
+               fib_rule6_test_match_n_redirect "$match" "$getmatch" \
+                       "$getnomatch" "sport and dport masked redirect to table" \
+                       "sport and dport masked no redirect to table"
+       fi
+
        fib_check_iproute_support "ipproto" "ipproto"
        if [ $? -eq 0 ]; then
                match="ipproto tcp"
@@ -543,6 +553,16 @@ fib_rule4_test()
                        "sport and dport range no redirect to table"
        fi
 
+       ip rule help 2>&1 | grep sport | grep -q MASK
+       if [ $? -eq 0 ]; then
+               match="sport 0x0f00/0xff00 dport 0x000f/0x00ff"
+               getmatch="sport 0x0f11 dport 0x220f"
+               getnomatch="sport 0x1f11 dport 0x221f"
+               fib_rule4_test_match_n_redirect "$match" "$getmatch" \
+                       "$getnomatch" "sport and dport masked redirect to table" \
+                       "sport and dport masked no redirect to table"
+       fi
+
        fib_check_iproute_support "ipproto" "ipproto"
        if [ $? -eq 0 ]; then
                match="ipproto tcp"