Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next] selftests: net: match the local port in wait_port_listen
@ 2026-11-22 15:49 Jingjing Xu
  2026-11-30 17:49 ` Paolo Abeni
  0 siblings, 1 reply; 2+ messages in thread
From: Jingjing Xu @ 2026-11-22 15:49 UTC (permalink / raw)
  To: netdev; +Cc: linux-kselftest, kuba, edumazet, pabeni, horms, shuah, willemb

wait_port_listen() searches anywhere in each /proc/net/{tcp,udp}* row.
For UDP, a connected client whose remote port matches the requested port
therefore makes the helper return even if no local receiver is bound.
Callers waiting for a UDP server can consequently continue too early.

Anchor the pattern to the start of the row and consume the slot and local
address before matching the port. Consume the remote address before the
TCP state, and terminate the LISTEN state match at a word boundary.
Keep accepting locally bound connected UDP sockets.

For example, in an isolated network namespace with loopback up, run this
from tools/testing/selftests/net, with port 12345 unused locally:

  import socket
  from lib.py import wait_port_listen
  s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  s.connect(("127.0.0.1", 12345))
  wait_port_listen(12345, proto="udp", deadline=0.1)

The original helper returns; the fixed helper times out as expected.
AI-assisted review found this issue. Real IPv4/IPv6 socket tests covered
absent, remote-only, bound and connected UDP ports, and absent, bound,
established and listening TCP sockets: the original failed two of 16
cases, and the fixed helper passed all 16. No hardware tests were run.

No kernel instrumentation or fault injection was used.

Fixes: 31611cea8f0f ("selftests: drv-net: add a TCP ping test case (and useful helpers)")
Signed-off-by: Jingjing Xu <xujingjing@cmss.chinamobile.com>
---
 tools/testing/selftests/net/lib/py/utils.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/net/lib/py/utils.py b/tools/testing/selftests/net/lib/py/utils.py
index 1727bc418073..d3877f8bc2df 100644
--- a/tools/testing/selftests/net/lib/py/utils.py
+++ b/tools/testing/selftests/net/lib/py/utils.py
@@ -342,9 +342,9 @@ def rand_ports(count, stype=socket.SOCK_STREAM):
 def wait_port_listen(port, proto="tcp", ns=None, host=None, sleep=0.005, deadline=5):
     end = time.monotonic() + deadline
 
-    pattern = f":{port:04X} .* "
+    pattern = rf"^\s*\d+:\s+\S+:{port:04X}\s+\S+\s+"
     if proto == "tcp": # for tcp protocol additionally check the socket state
-        pattern += "0A"
+        pattern += r"0A\b"
     pattern = re.compile(pattern)
 
     while True:
base-commit: 2208ab00f4f213ade91ab775e7f8c4dacdcc856e
-- 
2.53.0




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] selftests: net: match the local port in wait_port_listen
  2026-11-22 15:49 [PATCH net-next] selftests: net: match the local port in wait_port_listen Jingjing Xu
@ 2026-11-30 17:49 ` Paolo Abeni
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Abeni @ 2026-11-30 17:49 UTC (permalink / raw)
  To: Jingjing Xu, netdev
  Cc: linux-kselftest, kuba, edumazet, horms, shuah, willemb

On 11/22/26 16:49, Jingjing Xu wrote:
> wait_port_listen() searches anywhere in each /proc/net/{tcp,udp}* row.
> For UDP, a connected client whose remote port matches the requested port
> therefore makes the helper return even if no local receiver is bound.
> Callers waiting for a UDP server can consequently continue too early.
> 
> Anchor the pattern to the start of the row and consume the slot and local
> address before matching the port. Consume the remote address before the
> TCP state, and terminate the LISTEN state match at a word boundary.
> Keep accepting locally bound connected UDP sockets.
> 
> For example, in an isolated network namespace with loopback up, run this
> from tools/testing/selftests/net, with port 12345 unused locally:
> 
>    import socket
>    from lib.py import wait_port_listen
>    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>    s.connect(("127.0.0.1", 12345))
>    wait_port_listen(12345, proto="udp", deadline=0.1)
> 
> The original helper returns; the fixed helper times out as expected.
> AI-assisted review found this issue. Real IPv4/IPv6 socket tests covered
> absent, remote-only, bound and connected UDP ports, and absent, bound,
> established and listening TCP sockets: the original failed two of 16
> cases, and the fixed helper passed all 16. No hardware tests were run.
> 
> No kernel instrumentation or fault injection was used.
> 
> Fixes: 31611cea8f0f ("selftests: drv-net: add a TCP ping test case (and useful helpers)")
> Signed-off-by: Jingjing Xu <xujingjing@cmss.chinamobile.com>
Can the unmodified self-tests really hit this condition? If so, repost
updating the changelog accordingly. Otherwise do not resubmit.

/P

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-30 17:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 15:49 [PATCH net-next] selftests: net: match the local port in wait_port_listen Jingjing Xu
2026-11-30 17:49 ` Paolo Abeni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox