Skip to content

Commit 7650815

Browse files
Florian Westphalkuba-moo
authored andcommitted
selftests: netfilter: conntrack_tcp_unreplied.sh: wait for initial connection attempt
Netdev CI reports occasional failures with this test ("ERROR: ns2-dX6bUE did not pick up tcp connection from peer"). Add explicit busywait call until the initial connection attempt shows up in conntrack rather than a one-shot 'must exist' check. Signed-off-by: Florian Westphal <fw@strlen.de> Link: https://lore.kernel.org/r/20240506114320.12178-1-fw@strlen.de Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 1eb2cde commit 7650815

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

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

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ ip netns exec "$ns1" bash -c 'for i in $(seq 1 $BUSYWAIT_TIMEOUT) ; do
106106
sleep 0.1
107107
done' &
108108

109+
wait_for_attempt()
110+
{
111+
count=$(ip netns exec "$ns2" conntrack -L -p tcp --dport 80 2>/dev/null | wc -l)
112+
if [ "$count" -gt 0 ]; then
113+
return 0
114+
fi
115+
116+
return 1
117+
}
118+
119+
# wait for conntrack to pick the new connection request up before loading
120+
# the nat redirect rule.
121+
if ! busywait "$BUSYWAIT_TIMEOUT" wait_for_attempt; then
122+
echo "ERROR: $ns2 did not pick up tcp connection from peer"
123+
exit 1
124+
fi
125+
109126
ip netns exec "$ns2" nft -f - <<EOF
110127
table inet nat {
111128
chain prerouting {
@@ -119,12 +136,6 @@ if [ $? -ne 0 ]; then
119136
exit 1
120137
fi
121138

122-
count=$(ip netns exec "$ns2" conntrack -L -p tcp --dport 80 2>/dev/null | wc -l)
123-
if [ "$count" -eq 0 ]; then
124-
echo "ERROR: $ns2 did not pick up tcp connection from peer"
125-
exit 1
126-
fi
127-
128139
wait_for_redirect()
129140
{
130141
count=$(ip netns exec "$ns2" conntrack -L -p tcp --reply-port-src 8080 2>/dev/null | wc -l)
@@ -136,7 +147,7 @@ wait_for_redirect()
136147
}
137148
echo "INFO: NAT redirect added in ns $ns2, waiting for $BUSYWAIT_TIMEOUT ms for nat to take effect"
138149

139-
busywait $BUSYWAIT_TIMEOUT wait_for_redirect
150+
busywait "$BUSYWAIT_TIMEOUT" wait_for_redirect
140151
ret=$?
141152

142153
expect="packets 1 bytes 60"

0 commit comments

Comments
 (0)