Add fib_nexthops_fdb_port.sh, which exercises the NHA_FDB_PORT rules: accept a port on an fdb nexthop that has a gateway and echo it back on dump, reject it on non-fdb or gateway-less nexthops, allow a group whose legs differ only in UDP port, and confirm a portless fdb nexthop omits the attribute. The test SKIPs cleanly on kernels or iproute2 without NHA_FDB_PORT support.
Signed-off-by: Jack Ma <[email protected]> --- tools/testing/selftests/net/Makefile | 1 + .../selftests/net/fib_nexthops_fdb_port.sh | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100755 tools/testing/selftests/net/fib_nexthops_fdb_port.sh diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 708d960ae..c06eb4927 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -36,6 +36,7 @@ TEST_PROGS := \ fib_nexthop_multiprefix.sh \ fib_nexthop_nongw.sh \ fib_nexthops.sh \ + fib_nexthops_fdb_port.sh \ fib_rule_tests.sh \ fib_tests.sh \ fin_ack_lat.sh \ diff --git a/tools/testing/selftests/net/fib_nexthops_fdb_port.sh b/tools/testing/selftests/net/fib_nexthops_fdb_port.sh new file mode 100755 index 000000000..8b401c6d2 --- /dev/null +++ b/tools/testing/selftests/net/fib_nexthops_fdb_port.sh @@ -0,0 +1,78 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# +# Control-plane selftest for per-nexthop VXLAN fdb destination port +# (NHA_FDB_PORT). Verifies the accept/reject rules and the dump roundtrip. +# No datapath traffic here -- see tests/integ/vxlan-fdb-port-integ.sh for the +# real forwarding test. +# +# Requires: patched kernel (NHA_FDB_PORT) and patched iproute2 (the "port" +# keyword on "ip nexthop ... fdb"). SKIPs cleanly otherwise. + +set -u + +ksft_skip=4 +NS="nhfdbport-$$" +IP="ip -netns $NS" +ret=0 + +log_test() { # $1 actual_rc $2 expected_rc $3 name + if [ "$1" = "$2" ]; then + printf "TEST: %-58s [ OK ]\n" "$3" + else + printf "TEST: %-58s [FAIL] (rc=$1 want=$2)\n" "$3" + ret=1 + fi +} + +# passes (returns 0) iff the command FAILS +expect_fail() { + if "$@" >/dev/null 2>&1; then return 1; else return 0; fi +} + +cleanup() { ip netns del "$NS" 2>/dev/null; } + +command -v ip >/dev/null 2>&1 || { echo "SKIP: iproute2 not found"; exit $ksft_skip; } +ip nexthop help 2>&1 | grep -q fdb || { echo "SKIP: no fdb nexthop support"; exit $ksft_skip; } + +trap cleanup EXIT +cleanup +ip netns add "$NS" || { echo "SKIP: cannot create netns"; exit $ksft_skip; } +$IP link set lo up + +# Probe for "port" keyword + kernel NHA_FDB_PORT support; SKIP if missing. +if ! $IP nexthop add id 1 via 10.0.0.1 fdb port 4790 2>/dev/null; then + echo "SKIP: 'ip nexthop ... fdb port' unsupported (needs patched kernel + iproute2)" + exit $ksft_skip +fi +log_test 0 0 "add fdb nexthop with port" + +# Dump roundtrip must echo the port back. +$IP nexthop show id 1 | grep -qw "port 4790" +log_test $? 0 "dump shows fdb port 4790" + +# Reject: port on a routed (non-fdb) nexthop. +expect_fail $IP nexthop add id 2 via 10.0.0.1 dev lo port 4790 +log_test $? 0 "reject port on non-fdb nexthop" + +# Reject: fdb port without a gateway. +expect_fail $IP nexthop add id 3 fdb port 4790 +log_test $? 0 "reject fdb port without gateway" + +# The HA case: a group whose legs share the gateway but differ in port. +$IP nexthop add id 10 via 10.0.0.1 fdb port 4789 && \ +$IP nexthop add id 11 via 10.0.0.1 fdb port 5789 && \ +$IP nexthop add id 100 group 10/11 fdb +log_test $? 0 "add fdb nexthop group with differing ports" + +# A fdb nexthop without a port must NOT emit one (backward compat). +$IP nexthop add id 20 via 10.0.0.1 fdb +$IP nexthop show id 20 | grep -qw "port" +log_test $? 1 "fdb nexthop without port omits NHA_FDB_PORT" + +if [ $ret -eq 0 ]; then + echo "PASS: all NHA_FDB_PORT control-plane checks" +else + echo "FAIL: one or more NHA_FDB_PORT checks failed" +fi +exit $ret -- 2.43.0

