selftests: net: more strict check in net_helper

commit a71d0908e3 upstream.

The helper waiting for a listener port can match any socket whose
hexadecimal representation of source or destination addresses
matches that of the given port.

Additionally, any socket state is accepted.

All the above can let the helper return successfully before the
relevant listener is actually ready, with unexpected results.

So far I could not find any related failure in the netdev CI, but
the next patch is going to make the critical event more easily
reproducible.

Address the issue matching the port hex only vs the relevant socket
field and additionally checking the socket state for TCP sockets.

Fixes: 3bdd9fd29c ("selftests/net: synchronize udpgro tests' tx and rx connection")
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Link: https://lore.kernel.org/r/192b3dbc443d953be32991d1b0ca432bd4c65008.1707731086.git.pabeni@redhat.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Paolo Abeni 2024-02-12 11:19:23 +01:00 committed by Greg Kroah-Hartman
parent 225de871dd
commit 50f3931746

View File

@ -8,13 +8,16 @@ wait_local_port_listen()
local listener_ns="${1}" local listener_ns="${1}"
local port="${2}" local port="${2}"
local protocol="${3}" local protocol="${3}"
local port_hex local pattern
local i local i
port_hex="$(printf "%04X" "${port}")" pattern=":$(printf "%04X" "${port}") "
# for tcp protocol additionally check the socket state
[ ${protocol} = "tcp" ] && pattern="${pattern}0A"
for i in $(seq 10); do for i in $(seq 10); do
if ip netns exec "${listener_ns}" cat /proc/net/"${protocol}"* | \ if ip netns exec "${listener_ns}" awk '{print $2" "$4}' \
grep -q "${port_hex}"; then /proc/net/"${protocol}"* | grep -q "${pattern}"; then
break break
fi fi
sleep 0.1 sleep 0.1