Skip to content

Commit c59d72d

Browse files
Florian Westphalkuba-moo
authored andcommitted
selftests: netfilter: nft_flowtable.sh: make first pass deterministic
The CI occasionaly encounters a failing test run. Example: # PASS: ipsec tunnel mode for ns1/ns2 # re-run with random mtus: -o 10966 -l 19499 -r 31322 # PASS: flow offloaded for ns1/ns2 [..] # FAIL: ipsec tunnel ... counter 1157059 exceeds expected value 878489 This script will re-exec itself, on the second run, random MTUs are chosen for the involved links. This is done so we can cover different combinations (large mtu on client, small on server, link has lowest mtu, etc). Furthermore, file size is random, even for the first run. Rework this script and always use the same file size on initial run so that at least the first round can be expected to have reproducible behavior. Second round will use random mtu/filesize. Raise the failure limit to that of the file size, this should avoid all errneous test errors. Currently, first fin will remove the offload, so if one peer is already closing remaining data is handled by classic path, which result in larger-than-expected counter and a test failure. Given packet path also counts tcp/ip headers, in case offload is completely broken this test will still fail (as expected). The test counter limit could be made more strict again in the future once flowtable can keep a connection in offloaded state until FINs in both directions were seen. Signed-off-by: Florian Westphal <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 7515e37 commit c59d72d

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ omtu=9000
7171
lmtu=1500
7272
rmtu=2000
7373

74+
filesize=$((2 * 1024 * 1024))
75+
7476
usage(){
7577
echo "nft_flowtable.sh [OPTIONS]"
7678
echo
@@ -81,12 +83,13 @@ usage(){
8183
exit 1
8284
}
8385

84-
while getopts "o:l:r:" o
86+
while getopts "o:l:r:s:" o
8587
do
8688
case $o in
8789
o) omtu=$OPTARG;;
8890
l) lmtu=$OPTARG;;
8991
r) rmtu=$OPTARG;;
92+
s) filesize=$OPTARG;;
9093
*) usage;;
9194
esac
9295
done
@@ -217,18 +220,10 @@ ns2out=$(mktemp)
217220

218221
make_file()
219222
{
220-
name=$1
221-
222-
SIZE=$((RANDOM % (1024 * 128)))
223-
SIZE=$((SIZE + (1024 * 8)))
224-
TSIZE=$((SIZE * 1024))
225-
226-
dd if=/dev/urandom of="$name" bs=1024 count=$SIZE 2> /dev/null
223+
name="$1"
224+
sz="$2"
227225

228-
SIZE=$((RANDOM % 1024))
229-
SIZE=$((SIZE + 128))
230-
TSIZE=$((TSIZE + SIZE))
231-
dd if=/dev/urandom conf=notrunc of="$name" bs=1 count=$SIZE 2> /dev/null
226+
head -c "$sz" < /dev/urandom > "$name"
232227
}
233228

234229
check_counters()
@@ -246,18 +241,18 @@ check_counters()
246241
local fs
247242
fs=$(du -sb "$nsin")
248243
local max_orig=${fs%%/*}
249-
local max_repl=$((max_orig/4))
244+
local max_repl=$((max_orig))
250245

251246
# flowtable fastpath should bypass normal routing one, i.e. the counters in forward hook
252247
# should always be lower than the size of the transmitted file (max_orig).
253248
if [ "$orig_cnt" -gt "$max_orig" ];then
254-
echo "FAIL: $what: original counter $orig_cnt exceeds expected value $max_orig" 1>&2
249+
echo "FAIL: $what: original counter $orig_cnt exceeds expected value $max_orig, reply counter $repl_cnt" 1>&2
255250
ret=1
256251
ok=0
257252
fi
258253

259254
if [ "$repl_cnt" -gt $max_repl ];then
260-
echo "FAIL: $what: reply counter $repl_cnt exceeds expected value $max_repl" 1>&2
255+
echo "FAIL: $what: reply counter $repl_cnt exceeds expected value $max_repl, original counter $orig_cnt" 1>&2
261256
ret=1
262257
ok=0
263258
fi
@@ -455,7 +450,7 @@ test_tcp_forwarding_nat()
455450
return $lret
456451
}
457452

458-
make_file "$nsin"
453+
make_file "$nsin" "$filesize"
459454

460455
# First test:
461456
# No PMTU discovery, nsr1 is expected to fragment packets from ns1 to ns2 as needed.
@@ -664,8 +659,16 @@ if [ "$1" = "" ]; then
664659
l=$(((RANDOM%mtu) + low))
665660
r=$(((RANDOM%mtu) + low))
666661

667-
echo "re-run with random mtus: -o $o -l $l -r $r"
668-
$0 -o "$o" -l "$l" -r "$r"
662+
MINSIZE=$((2 * 1000 * 1000))
663+
MAXSIZE=$((64 * 1000 * 1000))
664+
665+
filesize=$(((RANDOM * RANDOM) % MAXSIZE))
666+
if [ "$filesize" -lt "$MINSIZE" ]; then
667+
filesize=$((filesize+MINSIZE))
668+
fi
669+
670+
echo "re-run with random mtus and file size: -o $o -l $l -r $r -s $filesize"
671+
$0 -o "$o" -l "$l" -r "$r" -s "$filesize"
669672
fi
670673

671674
exit $ret

0 commit comments

Comments
 (0)