Skip to content

Commit a126ab6

Browse files
author
Florian Westphal
committed
selftests: netfilter: nft_fib.sh: fix spurious test failures
Jakub reports spurious failure of nft_fib.sh test. This is caused by a subtle bug inherited when i moved faulty ping from one test case to another. nft_fib.sh not only checks that the fib expression matched, it also records the number of matches and then validates we have the expected count. When I did this it was under the assumption that we would have 0 to n matching packets. In case of the failure, the entry has n+1 matching packets. This happens because ping_unreachable helper uses "ping -c 1 -w 1", instead of the intended "-W". -w alters the meaning of -c (count), namely, its then treated as number of wanted *replies* instead of "number of packets to send". So, in some cases, ping -c 1 -w 1 ends up sending two packets which then makes the test fail due to the higher-than-expected packet count. Fix the actual bug (s/-w/-W) and also change the error handling: 1. Show the number of expected packets in the error message 2. Always try to delete the key from the set. Else, later test that makes sure we don't have unexpected keys in there will always fail as well. Reported-by: Jakub Kicinski <kuba@kernel.org> Closes: https://lore.kernel.org/netfilter-devel/20250927090709.0b3cd783@kernel.org/ Fixes: 9828704 ("selftests: netfilter: move fib vrf test to nft_fib.sh") Signed-off-by: Florian Westphal <fw@strlen.de>
1 parent bbf0c98 commit a126ab6

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

tools/testing/selftests/net/netfilter/nft_fib.sh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,12 @@ test_ping_unreachable() {
256256
local daddr4=$1
257257
local daddr6=$2
258258

259-
if ip netns exec "$ns1" ping -c 1 -w 1 -q "$daddr4" > /dev/null; then
259+
if ip netns exec "$ns1" ping -c 1 -W 0.1 -q "$daddr4" > /dev/null; then
260260
echo "FAIL: ${ns1} could reach $daddr4" 1>&2
261261
return 1
262262
fi
263263

264-
if ip netns exec "$ns1" ping -c 1 -w 1 -q "$daddr6" > /dev/null; then
264+
if ip netns exec "$ns1" ping -c 1 -W 0.1 -q "$daddr6" > /dev/null; then
265265
echo "FAIL: ${ns1} could reach $daddr6" 1>&2
266266
return 1
267267
fi
@@ -437,14 +437,17 @@ check_type()
437437
local addr="$3"
438438
local type="$4"
439439
local count="$5"
440+
local lret=0
440441

441442
[ -z "$count" ] && count=1
442443

443444
if ! ip netns exec "$nsrouter" nft get element inet t "$setname" { "$iifname" . "$addr" . "$type" } |grep -q "counter packets $count";then
444-
echo "FAIL: did not find $iifname . $addr . $type in $setname"
445+
echo "FAIL: did not find $iifname . $addr . $type in $setname with $count packets"
445446
ip netns exec "$nsrouter" nft list set inet t "$setname"
446447
ret=1
447-
return 1
448+
# do not fail right away, delete entry if it exists so later test that
449+
# checks for unwanted keys don't get confused by this *expected* key.
450+
lret=1
448451
fi
449452

450453
# delete the entry, this allows to check if anything unexpected appeared
@@ -456,7 +459,7 @@ check_type()
456459
return 1
457460
fi
458461

459-
return 0
462+
return $lret
460463
}
461464

462465
check_local()

0 commit comments

Comments
 (0)