From: Florian Westphal Date: Wed, 21 May 2025 09:38:49 +0000 (+0200) Subject: selftests: netfilter: nft_fib.sh: add type and oif tests with and without VRFs X-Git-Tag: v6.16-rc1~132^2~30^2~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=996d62ece03137b2462308acc15acadebe357c66;p=thirdparty%2Fkernel%2Fstable.git selftests: netfilter: nft_fib.sh: add type and oif tests with and without VRFs Replace the existing VRF test with a more comprehensive one. It tests following combinations: - fib type (returns address type, e.g. unicast) - fib oif (route output interface index - both with and without 'iif' keyword (changes result, e.g. 'fib daddr type local' will be true when the destination address is configured on the local machine, but 'fib daddr . iif type local' will only be true when the destination address is configured on the incoming interface. Add all types of addresses to test with for both ipv4 and ipv6: - local address on the incoming interface - local address on another interface - local address on another interface thats part of a vrf - address on another host The ruleset stores obtained results from 'fib' in nftables sets and then queries the sets to check that it has the expected results. Perform one pass while packets are coming in on interface NOT part of a VRF and then again when it was added and make sure fib returns the expected routes and address types for the various addresses in the setup. Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso --- diff --git a/tools/testing/selftests/net/netfilter/nft_fib.sh b/tools/testing/selftests/net/netfilter/nft_fib.sh index f636ad7810336..9929a9ffef652 100755 --- a/tools/testing/selftests/net/netfilter/nft_fib.sh +++ b/tools/testing/selftests/net/netfilter/nft_fib.sh @@ -324,12 +324,338 @@ test_fib_vrf_dev_add_dummy() return 1 fi - ip -net "$nsrouter" link set veth0 master tvrf ip -net "$nsrouter" link set dummy0 master tvrf ip -net "$nsrouter" link set dummy0 up ip -net "$nsrouter" link set tvrf up } +load_ruleset_vrf() +{ +# Due to the many different possible combinations using named counters +# or one-rule-per-expected-result is complex. +# +# Instead, add dynamic sets for the fib modes +# (fib address type, fib output interface lookup .. ), +# and then add the obtained fib results to them. +# +# The test is successful if the sets contain the expected results +# and no unexpected extra entries existed. +ip netns exec "$nsrouter" nft -f - < /dev/null