]> www.infradead.org Git - users/griffoul/linux.git/commitdiff
selftests: netfilter: fix udpclash tool hang
authorFlorian Westphal <fw@strlen.de>
Wed, 27 Aug 2025 17:17:32 +0000 (19:17 +0200)
committerFlorian Westphal <fw@strlen.de>
Thu, 4 Sep 2025 07:19:24 +0000 (09:19 +0200)
Yi Chen reports that 'udpclash' loops forever depending on compiler
(and optimization level used); while (x == 1) gets optimized into
for (;;).  Add volatile qualifier to avoid that.

While at it, also run it under timeout(1) and fix the resize script
to not ignore the timeout passed as second parameter to insert_flood.

Reported-by: Yi Chen <yiche@redhat.com>
Suggested-by: Yi Chen <yiche@redhat.com>
Fixes: 78a588363587 ("selftests: netfilter: add conntrack clash resolution test case")
Signed-off-by: Florian Westphal <fw@strlen.de>
tools/testing/selftests/net/netfilter/conntrack_clash.sh
tools/testing/selftests/net/netfilter/conntrack_resize.sh
tools/testing/selftests/net/netfilter/udpclash.c

index 606a43a60f7368bc444b7b9653460f89c1b1fd4a..7fc6c5dbd5516e91272ebb75e204b50873640a7d 100755 (executable)
@@ -99,7 +99,7 @@ run_one_clash_test()
        local entries
        local cre
 
-       if ! ip netns exec "$ns" ./udpclash $daddr $dport;then
+       if ! ip netns exec "$ns" timeout 30 ./udpclash $daddr $dport;then
                echo "INFO: did not receive expected number of replies for $daddr:$dport"
                ip netns exec "$ctns" conntrack -S
                # don't fail: check if clash resolution triggered after all.
index 788cd56ea4a0dcdc8690e91dce701ed808a422a4..615fe3c6f405da67036cf764eb62c7e1cdcfff5a 100755 (executable)
@@ -187,7 +187,7 @@ ct_udpclash()
        [ -x udpclash ] || return
 
         while [ $now -lt $end ]; do
-               ip netns exec "$ns" ./udpclash 127.0.0.1 $((RANDOM%65536)) > /dev/null 2>&1
+               ip netns exec "$ns" timeout 30 ./udpclash 127.0.0.1 $((RANDOM%65536)) > /dev/null 2>&1
 
                now=$(date +%s)
        done
@@ -277,6 +277,7 @@ check_taint()
 insert_flood()
 {
        local n="$1"
+       local timeout="$2"
        local r=0
 
        r=$((RANDOM%$insert_count))
@@ -302,7 +303,7 @@ test_floodresize_all()
        read tainted_then < /proc/sys/kernel/tainted
 
        for n in "$nsclient1" "$nsclient2";do
-               insert_flood "$n" &
+               insert_flood "$n" "$timeout" &
        done
 
        # resize table constantly while flood/insert/dump/flushs
index 85c7b906ad08f75ed897532d93675327a676028d..79de163d61ab7925d6aaf2f9d315bb49b40ed0c7 100644 (file)
@@ -29,7 +29,7 @@ struct thread_args {
        int sockfd;
 };
 
-static int wait = 1;
+static volatile int wait = 1;
 
 static void *thread_main(void *varg)
 {