Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

selftests: netfilter: nft_queue.sh: fix spurious timeout on debug kernel

The sctp selftest is very slow on debug kernels.

Its possible that the nf_queue listener program exits due to timeout
before first sctp packet is processed.

In this case socat hangs until script times out.
Fix this by removing the -t option where possible and kill the test
program once the file transfer/socat has exited.

-t sets SO_RCVTIMEO, its inteded for the 'ping' part of the selftest
where we want to make sure that packets get reinjected properly without
skipping a second queue request.

While at it, add a helper to compare the (binary) files instead of diff.
The 'diff' part was copied from a another sub-test that compares text.

Let helper dump file sizes on error so we can see the progress made.

Tested on an old 2010-ish box with a debug kernel and 100 iterations.

This is a followup to the earlier filesize reduction change.

Reported-by: Jakub Kicinski <kuba@kernel.org>
Closes: https://lore.kernel.org/netdev/20240829080109.GB30766@breakpoint.cc/
Fixes: 0a8b08c554da ("selftests: netfilter: nft_queue.sh: reduce test file size for debug build")
Signed-off-by: Florian Westphal <fw@strlen.de>
Link: https://patch.msgid.link/20240830092254.8029-1-fw@strlen.de
Signed-off-by: Paolo Abeni <pabeni@redhat.com>

authored by

Florian Westphal and committed by
Paolo Abeni
5ceb87dc 4c93b0bc

+40 -22
+40 -22
tools/testing/selftests/net/netfilter/nft_queue.sh
··· 8 8 9 9 source lib.sh 10 10 ret=0 11 - timeout=2 11 + timeout=5 12 12 13 13 cleanup() 14 14 { ··· 255 255 256 256 test_tcp_forward() 257 257 { 258 - ip netns exec "$nsrouter" ./nf_queue -q 2 -t "$timeout" & 258 + ip netns exec "$nsrouter" ./nf_queue -q 2 & 259 259 local nfqpid=$! 260 260 261 261 timeout 5 ip netns exec "$ns2" socat -u TCP-LISTEN:12345 STDOUT >/dev/null & 262 262 local rpid=$! 263 263 264 264 busywait "$BUSYWAIT_TIMEOUT" listener_ready "$ns2" 265 + busywait "$BUSYWAIT_TIMEOUT" nf_queue_wait "$nsrouter" 2 265 266 266 267 ip netns exec "$ns1" socat -u STDIN TCP:10.0.2.99:12345 <"$TMPINPUT" >/dev/null 267 268 268 269 wait "$rpid" && echo "PASS: tcp and nfqueue in forward chain" 270 + kill "$nfqpid" 269 271 } 270 272 271 273 test_tcp_localhost() ··· 275 273 timeout 5 ip netns exec "$nsrouter" socat -u TCP-LISTEN:12345 STDOUT >/dev/null & 276 274 local rpid=$! 277 275 278 - ip netns exec "$nsrouter" ./nf_queue -q 3 -t "$timeout" & 276 + ip netns exec "$nsrouter" ./nf_queue -q 3 & 279 277 local nfqpid=$! 280 278 281 279 busywait "$BUSYWAIT_TIMEOUT" listener_ready "$nsrouter" 280 + busywait "$BUSYWAIT_TIMEOUT" nf_queue_wait "$nsrouter" 3 282 281 283 282 ip netns exec "$nsrouter" socat -u STDIN TCP:127.0.0.1:12345 <"$TMPINPUT" >/dev/null 284 283 285 284 wait "$rpid" && echo "PASS: tcp via loopback" 286 - wait 2>/dev/null 285 + kill "$nfqpid" 287 286 } 288 287 289 288 test_tcp_localhost_connectclose() 290 289 { 291 - ip netns exec "$nsrouter" ./connect_close -p 23456 -t "$timeout" & 292 - ip netns exec "$nsrouter" ./nf_queue -q 3 -t "$timeout" & 290 + ip netns exec "$nsrouter" ./nf_queue -q 3 & 291 + local nfqpid=$! 293 292 294 293 busywait "$BUSYWAIT_TIMEOUT" nf_queue_wait "$nsrouter" 3 295 294 295 + timeout 10 ip netns exec "$nsrouter" ./connect_close -p 23456 -t 3 296 + 297 + kill "$nfqpid" 296 298 wait && echo "PASS: tcp via loopback with connect/close" 297 - wait 2>/dev/null 298 299 } 299 300 300 301 test_tcp_localhost_requeue() ··· 362 357 } 363 358 } 364 359 EOF 365 - ip netns exec "$ns1" ./nf_queue -q 1 -t "$timeout" & 360 + ip netns exec "$ns1" ./nf_queue -q 1 & 366 361 local nfqpid=$! 367 362 368 363 busywait "$BUSYWAIT_TIMEOUT" nf_queue_wait "$ns1" 1 ··· 372 367 for n in output post; do 373 368 for d in tvrf eth0; do 374 369 if ! ip netns exec "$ns1" nft list chain inet filter "$n" | grep -q "oifname \"$d\" icmp type echo-request counter packets 1"; then 370 + kill "$nfqpid" 375 371 echo "FAIL: chain $n: icmp packet counter mismatch for device $d" 1>&2 376 372 ip netns exec "$ns1" nft list ruleset 377 373 ret=1 ··· 381 375 done 382 376 done 383 377 384 - wait "$nfqpid" && echo "PASS: icmp+nfqueue via vrf" 385 - wait 2>/dev/null 378 + kill "$nfqpid" 379 + echo "PASS: icmp+nfqueue via vrf" 386 380 } 387 381 388 382 sctp_listener_ready() 389 383 { 390 384 ss -S -N "$1" -ln -o "sport = :12345" | grep -q 12345 385 + } 386 + 387 + check_output_files() 388 + { 389 + local f1="$1" 390 + local f2="$2" 391 + local err="$3" 392 + 393 + if ! cmp "$f1" "$f2" ; then 394 + echo "FAIL: $err: input and output file differ" 1>&2 395 + echo -n " Input file" 1>&2 396 + ls -l "$f1" 1>&2 397 + echo -n "Output file" 1>&2 398 + ls -l "$f2" 1>&2 399 + ret=1 400 + fi 391 401 } 392 402 393 403 test_sctp_forward() ··· 422 400 423 401 busywait "$BUSYWAIT_TIMEOUT" sctp_listener_ready "$ns2" 424 402 425 - ip netns exec "$nsrouter" ./nf_queue -q 10 -G -t "$timeout" & 403 + ip netns exec "$nsrouter" ./nf_queue -q 10 -G & 426 404 local nfqpid=$! 427 405 428 406 ip netns exec "$ns1" socat -u STDIN SCTP:10.0.2.99:12345 <"$TMPINPUT" >/dev/null ··· 433 411 fi 434 412 435 413 wait "$rpid" && echo "PASS: sctp and nfqueue in forward chain" 414 + kill "$nfqpid" 436 415 437 - if ! diff -u "$TMPINPUT" "$TMPFILE1" ; then 438 - echo "FAIL: lost packets?!" 1>&2 439 - exit 1 440 - fi 416 + check_output_files "$TMPINPUT" "$TMPFILE1" "sctp forward" 441 417 } 442 418 443 419 test_sctp_output() ··· 449 429 } 450 430 EOF 451 431 # reduce test file size, software segmentation causes sk wmem increase. 452 - dd conv=sparse status=none if=/dev/zero bs=1M count=50 of="$TMPINPUT" 432 + dd conv=sparse status=none if=/dev/zero bs=1M count=$((COUNT/2)) of="$TMPINPUT" 453 433 454 434 timeout 60 ip netns exec "$ns2" socat -u SCTP-LISTEN:12345 STDOUT > "$TMPFILE1" & 455 435 local rpid=$! 456 436 457 437 busywait "$BUSYWAIT_TIMEOUT" sctp_listener_ready "$ns2" 458 438 459 - ip netns exec "$ns1" ./nf_queue -q 11 -t "$timeout" & 439 + ip netns exec "$ns1" ./nf_queue -q 11 & 460 440 local nfqpid=$! 461 441 462 442 ip netns exec "$ns1" socat -u STDIN SCTP:10.0.2.99:12345 <"$TMPINPUT" >/dev/null ··· 468 448 469 449 # must wait before checking completeness of output file. 470 450 wait "$rpid" && echo "PASS: sctp and nfqueue in output chain with GSO" 451 + kill "$nfqpid" 471 452 472 - if ! diff -u "$TMPINPUT" "$TMPFILE1" ; then 473 - echo "FAIL: lost packets?!" 1>&2 474 - exit 1 475 - fi 453 + check_output_files "$TMPINPUT" "$TMPFILE1" "sctp output" 476 454 } 477 455 478 456 test_queue_removal() ··· 486 468 } 487 469 } 488 470 EOF 489 - ip netns exec "$ns1" ./nf_queue -q 0 -d 30000 -t "$timeout" & 471 + ip netns exec "$ns1" ./nf_queue -q 0 -d 30000 & 490 472 local nfqpid=$! 491 473 492 474 busywait "$BUSYWAIT_TIMEOUT" nf_queue_wait "$ns1" 0