Article View: linux.kernel.netdev
Article #27250[PATCH net-next v4 0/2] tcp: prefer device-bound listeners over unbound SO_REUSEPORT ones
From: Kalash Nainwal via B4 Relay
Date: Sat, 05 Dec 2026 05:06
Date: Sat, 05 Dec 2026 05:06
104 lines
16348 bytes
16348 bytes
When an unbound TCP listener and a listener bound to a device share a
port with SO_REUSEPORT, the listener lookup returns whichever is first
in the listen bucket, so the more specific device-bound listener can
lose. AF_INET and AF_INET6 reuseport listeners are added at opposite
ends of the bucket, so the same setup picks different listeners for
IPv4 and IPv6.
We hit this with a BGP daemon in a VRF with tcp_l3mdev_accept=1: only
the VRF-bound :179 listener had TCP-MD5 keys, and IPv6 peers in the VRF
reached the unbound listener and came up without MD5. The same happens
without a VRF, with SO_BINDTODEVICE.
v1-v3 added a sysctl to exempt ports from tcp_l3mdev_accept in the
listener lookup. Following review, v4 drops it and fixes the lookup
instead (patch 1). Patch 2 replaces the selftest.
Notes:
- The fast reuseport return is kept unless the listen bucket holds a
device-bound listener. Each bucket counts its device-bound listeners
under the bucket lock, so a bucket without one behaves as before. With
one, after a pick from an unbound reuseport group, the lookup walks
the rest of the bucket for a device-bound socket, skipping unbound
sockets without scoring them. This follows the has_conns check that
commit acdcecc61285 added for UDP.
- If the SK_REUSEPORT program of an unbound group refuses a connection,
a matching device-bound listener still gets it. Without one, the
connection is refused as before.
- UDP (udp4_lib_lookup2() and udp6_lib_lookup2()) has the same early
return. I can send a follow-up for it if this approach is acceptable.
Testing:
- New selftest in virtme-ng: all 20 cases pass. Without patch 1, 7
cases fail in the expected pattern: IPv4 when the device-bound
listener is created first, IPv6 when the unbound one is.
- Without the SO_BINDTODEVICE update of the count, the IPv4 case with
a listener bound after listen() fails.
- fcnal-test.sh ipv4_tcp (134 tests) and ipv6_tcp (132 tests),
reuseport_addr_any, reuseport_dualstack, reuseport_bpf,
reuseport_bpf_cpu and so_incoming_cpu pass.
---
Changes in v4:
- Drop the tcp_l3mdev_exempt_ports sysctl and fix the listener lookup
instead: prefer a matching device-bound listener over an unbound one
whatever their scores, and after a pick from an unbound reuseport
group, keep looking for one when the bucket has device-bound
listeners.
- Update Documentation/networking/vrf.rst, which described the listener
choice for VRF traffic as unspecified.
- Replace the selftest with tcp_bound_dev_listener.sh, which also covers
SO_BINDTODEVICE without a VRF, and a listener bound to the VRF after
listen() (new nettest --bind-after-listen option).
- Rebase on current net-next.
- Link to v3: https://patch.msgid.link/20261127-tcp-l3mdev-exempt-ports-v3-0-f875b1184f26@nexthop.ai
Changes in v3:
- Patch 1: explain in the commit message why this is opt-in instead of
a change to the default lookup.
- Patch 1: drop the fast path annotation from the net_cachelines row;
the field is not in a fast path cacheline group.
- Patch 2: add cases with a listener bound to the VRF slave device, and
say in the header that such a listener also matches.
- Patch 2: stop the listener that must not get the connection instead
of waiting for its timeout, so a slow setup cannot make it exit early.
- Patch 2: do not connect if the listeners did not start.
- Rebase on current net-next.
- Link to v2: https://patch.msgid.link/20261125-tcp-l3mdev-exempt-ports-v2-0-b920f3ff8f5e@nexthop.ai
Changes in v2:
- Patch 1: only build the sysctl with CONFIG_NET_L3_MASTER_DEV, next to
tcp_l3mdev_accept.
- Patch 1: say in the docs that only listener lookup changes, and that
a listener bound to the receiving device also matches.
- Patch 1: add the field to net_cachelines/netns_ipv4_sysctl.rst.
- Patch 2: wait for the listeners with ss instead of a fixed sleep.
- Patch 2: skip if VRF is not supported; fail if setup fails.
- Patch 2: require a timeout from the listener that must not get the
connection.
- Patch 2: use ALL_TESTS and check_gen_prog; fix shellcheck warnings.
- Wrap lines at 80 columns.
- Link to v1: https://patch.msgid.link/20261120-tcp-l3mdev-exempt-ports-v1-0-ccc2a3a6cd09@nexthop.ai
---
Kalash Nainwal (2):
tcp: prefer a device-bound listener over an unbound SO_REUSEPORT one
selftests: net: add tcp_bound_dev_listener test
Documentation/networking/vrf.rst | 24 +-
include/net/inet_hashtables.h | 3 +
net/core/sock.c | 5 +
net/ipv4/inet_hashtables.c | 42 ++-
net/ipv6/inet6_hashtables.c | 21 +-
tools/testing/selftests/net/Makefile | 1 +
tools/testing/selftests/net/nettest.c | 17 +-
.../selftests/net/tcp_bound_dev_listener.sh | 308 +++++++++++++++++++++
8 files changed, 401 insertions(+), 20 deletions(-)
---
base-commit: d5cf954cebe4f175dfd834e1dc471a3aa203ec7d
change-id: 20261120-tcp-l3mdev-exempt-ports-c9f5dfebe356
Best regards,
--
Kalash Nainwal <kalash@nexthop.ai>
Technical Details
Message-ID:
<20261204-tcp-l3mdev-exempt-ports-v4-0-b2d4465a937c@nexthop.ai>Path:
mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mi.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377837-linux-kernel-netdev=dewy.ruShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!feed-us-txt.newsdeef.eu!feed-us-mi.newsdeef.eu!srv.newsdeef.eu!newsfeed.endofthelinebbs.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-377837-linux-kernel-netdev=dewy.ru From: devnull+kalash.nexthop.ai@kernel.org (Kalash Nainwal via B4 Relay) Newsgroups: linux.kernel.netdev Subject: [PATCH net-next v4 0/2] tcp: prefer device-bound listeners over unbound SO_REUSEPORT ones Date: Fri, 04 Dec 2026 22:06:13 -0700 Organization: Usenet Network Message-ID: <20261204-tcp-l3mdev-exempt-ports-v4-0-b2d4465a937c@nexthop.ai> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="2958013"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:ULboofQ3EDDSDmmPeGHcqsaVQnA= sha256:JJ1ceK5f4rWzKSrasKsD7gHYxlXvrqojVjCk/yIWC5Q= sha1:BqyuQNp7Pj64hYmJRNs2c+7UsUc= sha256:7cA1GVHLpRyxwJKpoVZ6vTMQk0TDq2loUVgNoi6C8FM= 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 167D5117D76; Sat, 5 Dec 2026 08:06:40 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.541 X-Spam-Status: No, score=-3.541 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.142, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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=pass (2048-bit key) header.d=kernel.org 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 DShjGL-9N2jF; Sat, 5 Dec 2026 08:06:37 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-377837-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id AB9FC117D73; Sat, 5 Dec 2026 08:06:26 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id 9369B32DFF; Sat, 5 Dec 2026 05:06:20 +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=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796447178; b=1KLKuY2z3RUk/BDZPjk5DF60Lb5GCaRm095WrN5AQC/eQZxdYOEcbS5Yv/A0vpip1NXk U/MBhfOQ0K4klKSsK4WNHfpGyUQLXAq8FtI0+R1fanE/8ReEb6QoEj9ZEmwxCrrmNEPr2 oZLVOBIf1L5v4ZJs2Z4iQ8bX+Psrxavc6gVV1pXvb0XabH5EyAoYqgzGs7IA1d0UBnpR8 fQmfv/mj7mawOzIsMwyxVzgngT/ZdJzYbI/c6G11m5CBy6c89nIIpMI1I8J7/gor1TpYm RWXpbfet9BbauLuXtxQrnCUXrtBWrjqEuV2BsZI6zuvE+iQRBScvcXNQskm16Ik11pg== X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796447178; h=X-Original-To:Received:Received:DKIM-Signature:Received:From:Subject: Date:Message-Id:X-Mailing-List:List-Id:List-Post:List-Help: List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version: Content-Type:Content-Transfer-Encoding:X-B4-Tracking:X-Change-ID:To: Cc:X-Mailer:X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To; bh=uJy7FLLTAwpCjIIed9wQA8x2A4u1yhX+dY3ac4mcnaQ=; b=C6hGcJvTJy3FBoOt8onAz330c6L3d2AP+XmEuF3hwKtQXjkPqFn31WoaVkGuqomSuV59 NMZJj/jp5EaMdo3ACSBhpeLE8EQZjZmVxGQRVknWMPUArDI005kmBQ9tZMBOpxOuA0oBH y4dYE2ABPTqqmoI8yfxmrwrhsrPNfNN2KifIprO2XLYAy8WOzjVlI5GQhydItT9NJTrTu rGh3+jiQEofqm3dKgtZQQPBzG7kVC6Y8K7ad+qqnfCeThovVFfFbE8j77cl7b9+vxuqrh mDO/h9dQTT/s+5yCY0LN/El8ZUTh2pw+I1B/zgclPtflxu+z2VVbNqsJ6ERG2JWiSig== X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aaLCTgIC; 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 4504D606A691; Sat, 5 Dec 2026 05:06:18 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aaLCTgIC X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796447177; b=rC3B5wMwXJp2+MP/7yjetX0dDBq3slMFpgW+B3V+vliDQEkojzs+PVHIhVRXP7B+em9u iOyNsWZn8X8g185YhoVTeY/EfLcs4yefdElOJQAGZMLVnl1mx+zYIGALvc8Zma+0ObEnu ABrD3Ck710hRhqn9scR6iIeNHSAk2EAR0Z79cexnamd+hHQxWeqqI9ELsbaf39gak7XlJ MxRMKz7QmiRLc0R5PJSHhMIiW2sSDPZNJJV769c9qmY5iP7RAi6HLiXNAGnw369YjtpDt 4C6TGFHSmZzc17XT0bK5C5X1KGlvmg7C4z1BE2yLJeWQEX+XBxhc8H+Rfn5IVnXpynQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796447177; h=Received:DKIM-Signature:Received:From:Subject:Date:Message-Id: MIME-Version:Content-Type:Content-Transfer-Encoding:X-B4-Tracking: X-Change-ID:To:Cc:X-Mailer:X-Developer-Signature:X-Developer-Key: X-Endpoint-Received:X-Original-From:Reply-To; bh=uJy7FLLTAwpCjIIed9wQA8x2A4u1yhX+dY3ac4mcnaQ=; b=eGUweqS55dKQVLIU+eVKMpVbClbYfYFebmKTDJS8Jv2EozeTLo0PWN2k81uXhzKvmM6I Z4OgzDiBzEsauWfQAF0NE6qiuec39VyyfUcyJlF70v3HWIAL10HpBRPbXj9UsPxe/nYoU ACOUHK3CB/ldnIUky4eLx3wrW6cc6Rtan3YVWUtCvhUeIV8Vbc9MU/v+s1T5CuHVXupM9 yzEZYsfBKaKcvrkMLdi0u8oQaR9fxHhdx2Me8eWwAGsGxR8LLi+ghQYJCTPZsZ3/xies4 FTi/7HH818nEo33WrJcPIBwtd8f8oIpNZKTTk7bDwj96+AbR6ORdUHqtqc4Af0uIwAw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aaLCTgIC; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57F7C606A322; Sat, 5 Dec 2026 05:06:17 +0000 (UTC) X-Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 X-ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796447176; b=xM7hPmQsc6SSg5GY1o2VUetNLFvFKCkVm6MufP5V21QqfsSlsIXCg8BjkXMIiCi065j/ MPlIirZDy1oJicx2JY9P3/mRDlITDZAitQHQZTpQVvNggmORM6cdRWwCN+20x7pCeEf/T R3Tm9TkjsEZB3FDvIXXnksEz3UM+VN0gjJDhZDoQZZ2PLmIRdKQNRrXLwtoPufw7z17Ti aKomCcqJlnxfDkpHYv3vzSZf7cmxHdeekt/SVQzePUNKCD73O54zJ26mB0QqBdKg/mjEm nUxhMBw+q1BA2V/MOd+sSDBMTMWV7kZiiBeA/+ogAW6qa5JhwiEQd/6bhLnuCp08OPw== X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796447176; h=DKIM-Signature:Received:From:Subject:Date:Message-Id:MIME-Version: Content-Type:Content-Transfer-Encoding:X-B4-Tracking:X-Change-ID:To: Cc:X-Mailer:X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To; bh=uJy7FLLTAwpCjIIed9wQA8x2A4u1yhX+dY3ac4mcnaQ=; b=ZqwLk9bztEsJF0iOKYWEXEVLJfrZWiy+dm9zc/V0dYm8vEpzytCoU6IZE9f7zFI/nn9W xM028i5LzpdTRQYRLBewDxgIKPztmjkLaL/TVUdkr7HK5ra4hFrm3NHYQTQqMavDDg4Ei uWXD6WCRn7v1PTE/8PG1D3QRe3l9rhoRTPZbdZTisXKGqV+5Y5ZHvKBSEGNxTc/eoolW7 5Kt+dTH9gOVWhW8pIKGjNKOCvXzOLlXM+pVkzUVRoInjdEhosXIHJUi0h68Abs0X8W36S YK9RzL8QJjvUUqxjC/AZsIh+gJejJZ///57enaLe2NGjZkiS0n1BwGriZ4+L6UNvzfQ== X-ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 X-Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 12DA91F00936; Sat, 5 Dec 2026 05:06:16 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796447176; bh=uJy7FLLTAwpCjIIed9wQA8x2A4u1yhX+dY3ac4mcnaQ=; h=From:Subject:Date:To:Cc:Reply-To; b=aaLCTgICqERlo23yICruxKvws8QyhtwE8ndSH0NEMTTMPU6q0ZR/yNSblBaTKfXzi MpWTVrM0gwTxd2QZ5M/cxWjAj77nKY3gz7wsNuR5fZW+2odEVqIY46MeKOyYCsa1of 6LoFBkVtaO+ai5yFOmzkorW01cloCDVPkWwPyH1b35RbrDWOO0qMGzErqd7mFcqAA4 hdX6CRs+H0GVOdTC2VEQPcKt7RnUDwbIKU8b/LcP1+8aNx2JAuUZIqIrDDgSHktue+ m37mv0vCPpFrtIDX92BiOVNF3Tmr+qtgfbarZI0ql7DLv2qZiYXKfcgI6VZ4HnsfFz a7rThIY/ODHeg== X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 5ED0850197; Sat, 5 Dec 2026 05:06:15 +0000 (UTC) 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 X-B4-Tracking: v=1; b=H4sIAMabE2sC/4XOTY7CMAwF4KugrMcoP01pWXEPxKJNbRo0tFESo iLUu5OWDWiEZmnZ73t+sIDeYmD7zYN5TDbYcchD8bNhpm+GM4Lt8swkl6UQkkM0Dn7VtcMEOOH VRXCjjwFMTbojbFHpkuW080h2WuUjGzDCgFNkp9cm3NoLmrjAy21vQxz9fX0iiTXxb18SwMEYI xvVlKbj9WEp6Ee3bexak+Q7pL9DMkNtLTkpooo0/oHUO7T7DqkMUbXTrRBVQbL8gOZ5fgI81Zk VbQEAAA== X-Change-ID: 20261120-tcp-l3mdev-exempt-ports-c9f5dfebe356 X-Cc: Shuah Khan <shuah@kernel.org>, netdev@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Kalash Nainwal <kalash@nexthop.ai> X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5208; i=kalash@nexthop.ai; h=from:subject:message-id; bh=oJqRLKEfo1vYAy+j3/hNj+zlWn/2udqqodwx49tDCiQ=; b=owEB7QES/pANAwAKAdTKslu1X9B2AcsmYgBrE5vGTyppwrt0LSPkZCYMdD/Qxguxbs2+D0+Ci 1boO+o349GJAbMEAAEKAB0WIQSWKdfHnHcAucb08LDUyrJbtV/QdgUCaxObxgAKCRDUyrJbtV/Q dls/DACXC0fsG1sBPuvKMYkU1K4lGZs/VUtx3qE40YFYzZN37IlaGEL2KT5lx0GZvxQYj4rj75j QjHojjoLabLL5HZXkrTtTOMCNZDLKgEnAIe6zT5dbFKGCTfJDoIeFNXjJKXgSc3FiFkKGYCaOFj QvB2ols8ggSG2GOWIayuogmd2f3LMy7+zrIKnwMlDIhzlqBrlQXicF8vJaxhX2DhtKGWalxpLnL sxkSMpImtixUzSm+t/ejDeWK3yKfei0Gk2xCVumDdD2LD8WfB8nDoGr0y9RWopu7JL0oGa6fSkg Lmx0bTRJ529kIxTG5w6G55WOZTEQ5CQW2E17a8zcZt8kO1E+AX3IWmymKfgKj/ElrdvP4kYeqFV /1cDUPtl07iSRTH4GM0KsJ/frZeSyVgtYShMYgv9E9+1vSfLn77B344XpOonWq6vDrdZw3SQjTr wyW3PBC+xCEEo5obuVH1/vWXLWEu4YMoha0a57qotDgESpRT9wWCmQnPO6I3+OV+0/GIY= X-Developer-Key: i=kalash@nexthop.ai; a=openpgp; fpr=9629D7C79C7700B9C6F4F0B0D4CAB25BB55FD076 X-Endpoint-Received: by B4 Relay for kalash@nexthop.ai/default with auth_id=1588 X-Original-From: Kalash Nainwal <kalash@nexthop.ai> X-Reply-To: kalash@nexthop.ai