Commit 661a4f30 authored by Florian Westphal's avatar Florian Westphal
Browse files

selftests: netfilter: fix udpclash tool hang



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: default avatarYi Chen <yiche@redhat.com>
Suggested-by: default avatarYi Chen <yiche@redhat.com>
Fixes: 78a58836 ("selftests: netfilter: add conntrack clash resolution test case")
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
parent 8156210d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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.
+3 −2
Original line number Diff line number Diff line
@@ -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
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ struct thread_args {
	int sockfd;
};

static int wait = 1;
static volatile int wait = 1;

static void *thread_main(void *varg)
{