🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #20456

[PATCH net-next] selftests: net: match the local port in wait_port_listen

#20456
From: Jingjing Xu
Date: Sun, 22 Nov 2026 15:49
53 lines
10676 bytes
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
Technical Details
Message-ID: <20261122154923.1272551-1-xujingjing@cmss.chinamobile.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368734-linux-kernel-netdev=dewy.ru

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-368734-linux-kernel-netdev=dewy.ru
From: xujingjing@cmss.chinamobile.com (Jingjing Xu)
Newsgroups: linux.kernel.netdev
Subject: [PATCH net-next] selftests: net: match the local port in wait_port_listen
Date: Sun, 22 Nov 2026 15:49:23 +0000
Organization: Usenet Network
Message-ID: <20261122154923.1272551-1-xujingjing@cmss.chinamobile.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3669835"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:d4dLCtEn/dS5eUbp1ugsWY3CVv8= sha256:sJgyTw2wTsEbey1FvchJPCQFz0yMUmghjmXHb/Jg6Y4=
	sha1:AiGZyPtxGrV8dagvzIqhIagS7Ck= sha256:V3VKDeuTs9QI9cjFWOa1lZSMitVg5UnNJziEZp+tsKI=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 53C9D125D7F; Sun, 22 Nov 2026 18:49:54 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -2.75
X-Spam-Status: No, score=-2.75 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_INVALID=0.1, DKIM_SIGNED=0.1,
	HEADER_FROM_DIFFERENT_DOMAINS=0.249, MAILING_LIST_MULTI=-1,
	RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001,
	URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=fail (1024-bit key)
	reason="fail (body has been altered)" header.d=cmss.chinamobile.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id Rbg4Yzskl4xM;
	Sun, 22 Nov 2026 18:49:51 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-368734-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=cmss.chinamobile.com
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id D0BF9125D7A; Sun, 22 Nov 2026 18:49:40 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id 07F3E25209; Sun, 22 Nov 2026 15:49:38 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795362575;
	b=A75tIUxYIniZvhbTAtWJBdTpCdHtQQ8ffEr4YHSRkmUWGV2Xbl0TZly6yQM+CyKxRrb3
	 0ggOQ+XzENc0HhIi7MGGAWNMgLn5Bd/hxC2+cXAKzVud6tRpoEEPNr6VL/J2+p4DSSSil
	 ChpTkyeOz3ohriBMacdrKshAk9m+lO61EGvsUAHQ0RFmQtkFuSBoLZMesO+DRR8eed2uE
	 0OXCdoVR3VuSMmc+vxgWkRij8f8XT6wH+GDtCEGwPrDRksRlTCa7+9GDffX+lBDD9tPIA
	 YC7WNICX0fVkeRvt2gEf6cNf0itfeznqlSbqXXD4WthT0GVPwk9eYro2h0XDswlLNrA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795362575;
	h=X-Original-To:Received:DMARC-Filter:DKIM-Signature:X-RM-TagInfo:
	 X-RM-SPAM-FLAG:Received:X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:
	 Received:X-RM-TRANSID:From:To:Cc:Subject:Date:Message-ID:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=d88/0oANKlu0REFGFbk9K6Puvz6VVsJ4TyJhhFFvaw8=;
	b=tS7/Ns2x1PLO7Jb3BKRdxHZqBq7pzCfvE5ZPx/cdS8QP6M/SdaXW89R1ALYARhUobtu4
	 ZJewHuziicW2Sp50gYF0KgKbq7z4WhBUdScdOIvibiw8FpQcpDxeAYKc6JkrgFHnyWGvh
	 K0qZDyFZp5Ebs4WMyJMHuuysHFAPcKkuz2v7grOlOYrqwvrTyTl4J9HHmfzU2Fb1FjaPs
	 I5e5Olr3WFCgO2hc85y3g0idjkB5U3ELPYaj0NMbUJGQMpZNbx3TF7tFFfYsGn0YRgsxj
	 ddZE6ad7YMtobuMnSKsJuRniB82xMQ74ERjktrcLz31yd+Xt4HHW+PGQPtqMApK/Tmg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=US7gZquz;
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 599AC606A334;
	Sun, 22 Nov 2026 15:49:35 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (1024-bit key) header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=US7gZquz
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=111.22.67.135
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795362574;
	b=Whu1HVqXWCayh4UqRwIn/hP10UlhOcW966qMJAQDfViIoHFHr0NKYuKxwR6ayxrA31Mp
	 /92bnlrvj9YnXS94EVdCBsktbpqNX6VeMG0tpuySpEKBFLGCUqH9Gc7s4LnprSDH4kPs0
	 YjWaPqmdneKfrDnDmLWgzL4YQzb3m3169UbTbMJLBzRuT0W205FPlPjpyyyo8Sg7T3VsY
	 A36kC8aYUQJNR1gmyN36mew4ymsSPFj6TofsJ7jCCm69v4Nlb0iGBX2HUtF9VqlmoVKZo
	 qoRERST6ut40SirfJav5UfRPvfJqfqCF5emN9eqchpGnupfQopWBkqDtJkUltEN1s9g==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795362574;
	h=DMARC-Filter:DKIM-Signature:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:
	 X-RM-TRANSID:X-RM-TagInfo:X-RM-SPAM-FLAG:Received:X-RM-TRANSID:From:
	 To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Transfer-Encoding;
	bh=d88/0oANKlu0REFGFbk9K6Puvz6VVsJ4TyJhhFFvaw8=;
	b=DVK4N+2tKxTsPce95gKwbeXND7KMsiGRTghr3k9NwWMeGlIu154Fdy97M/kVDY58oKA+
	 4wLqNd0u0/9OTK1OrLHzbJlT7RPOS/MORfeW+dHmy+c62kOrESiUyiUFufR1MdZ/2tCTP
	 dW5OfJVGR35Nhzt/RPeI4hXiXqrz4Hvq99603m139TbDU+cE2Ho9YhpXrFEiExdZHrOCW
	 4YS4ropqCPZSxt9GEF0dN8LI8inxVQgwA7gAM/Vq6l2f1fPToqiHIBVp6oNjYmUZbW2re
	 RnloIDvmMLYmnxhA4N3x0atZEagRp6pphk+oVpRGR03WpubfqpN7TdZ9id/tp0hJp5A==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=cmss.chinamobile.com;
	spf=pass smtp.mailfrom=cmss.chinamobile.com;
	dkim=pass header.d=cmss.chinamobile.com header.i=@cmss.chinamobile.com header.a=rsa-sha256 header.s=default header.b=US7gZquz;
	arc=none smtp.remote-ip=111.22.67.135
X-Received: from cmccmta2.chinamobile.com (cmccmta2.chinamobile.com [111.22.67.135])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id DC47F606A320;
	Sun, 22 Nov 2026 15:49:32 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DC47F606A320
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmss.chinamobile.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmss.chinamobile.com
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=cmss.chinamobile.com; s=default; l=0;
	h=from:subject:message-id:to:cc:mime-version;
	bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
	b=US7gZquzk6TcYlwsaRwatyB5hkhd2PAftqRFYIudGXnHdEErZx6MkSTqElxfQbwr7oh9uRir3USeb
	 Y/h/OwOL1ksc6obcCUohcxCpDtNkNZpT1aaHECn+9Mjd3yVfngDmYxn/neSfBp1lBSPz8sPw5TFtS9
	 Nhn2vS3BB4uLbqW8=
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from spf.mail.chinamobile.com (unknown[10.188.0.87])
	by rmmx-syy-dmz-app07-12007 (RichMail) with SMTP id 2ee76b030f01e85-34f85;
	Sun, 22 Nov 2026 23:49:24 +0800 (CST)
X-RM-TRANSID: 2ee76b030f01e85-34f85
X-RM-TagInfo: emlType=0                                       
X-RM-SPAM-FLAG: 00000000
X-Received: from home-ubuntu-251 (unknown[180.106.213.53])
	by rmsmtp-syy-appsvr02-12002 (RichMail) with SMTP id 2ee26b030f01b31-73064;
	Sun, 22 Nov 2026 23:49:24 +0800 (CST)
X-RM-TRANSID: 2ee26b030f01b31-73064
X-Cc: linux-kselftest@vger.kernel.org,
	kuba@kernel.org,
	edumazet@kernel.org,
	pabeni@redhat.com,
	horms@kernel.org,
	shuah@kernel.org,
	willemb@google.com
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list