linux-kselftest.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net v3 0/2] net: tcp: lookup the best matched listen socket
@ 2025-08-02  9:24 Menglong Dong
  2025-08-02  9:24 ` [PATCH net v3 1/2] " Menglong Dong
  2025-08-02  9:24 ` [PATCH net v3 2/2] selftests/net: test TCP reuseport socket selection Menglong Dong
  0 siblings, 2 replies; 12+ messages in thread
From: Menglong Dong @ 2025-08-02  9:24 UTC (permalink / raw)
  To: edumazet, kuniyu
  Cc: ncardwell, davem, dsahern, kuba, pabeni, horms, shuah, kraig,
	linux-kernel, netdev, linux-kselftest

For now, the tcp socket lookup will terminate if the socket is reuse port
in inet_lhash2_lookup(), which makes the socket is not the best match.

For example, we have socket1 and socket2 both listen on "0.0.0.0:1234",
but socket1 bind on "eth0". We create socket1 first, and then socket2.
Then, all connections will goto socket2, which is not expected, as socket1
has higher priority.

The 1st patch fix this problem, and the 2nd patch is a selftests for this
problem. Without the 1st patch, the selftests will fail with:

$ ./tcp_reuseport.py
TAP version 13
1..1
FAIL: wrong assignment
not ok 1 tcp_reuseport.test_reuseport_select
Totals: pass:0 fail:1 xfail:0 xpass:0 skip:0 error:0

With the 1st patch, it will success:
$ ./tcp_reuseport.py
TAP version 13
1..1
SUCCESS: assigned properly: (<socket.socket fd=6, family=2, type=1, proto=0, laddr=('127.0.0.1', 33787), raddr=('127.0.0.1', 43140)>, ('127.0.0.1', 43140))
SUCCESS: assigned properly: (<socket.socket fd=5, family=2, type=1, proto=0, laddr=('127.0.0.1', 33787), raddr=('127.0.0.1', 43146)>, ('127.0.0.1', 43146))
SUCCESS: assigned properly: (<socket.socket fd=6, family=2, type=1, proto=0, laddr=('127.0.0.1', 33787), raddr=('127.0.0.1', 43162)>, ('127.0.0.1', 43162))
ok 1 tcp_reuseport.test_reuseport_select
Totals: pass:1 fail:0 xfail:0 xpass:0 skip:0 error:0

Changes since V2:
* use the approach in V1
* add the Fixes tag in the 1st patch
* introduce the selftests

Menglong Dong (2):
  net: tcp: lookup the best matched listen socket
  selftests/net: test TCP reuseport socket selection

 net/ipv4/inet_hashtables.c                   | 13 +++----
 net/ipv6/inet6_hashtables.c                  | 13 +++----
 tools/testing/selftests/net/Makefile         |  1 +
 tools/testing/selftests/net/tcp_reuseport.py | 36 ++++++++++++++++++++
 4 files changed, 51 insertions(+), 12 deletions(-)
 create mode 100755 tools/testing/selftests/net/tcp_reuseport.py

-- 
2.50.1


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

end of thread, other threads:[~2025-08-13 17:52 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-02  9:24 [PATCH net v3 0/2] net: tcp: lookup the best matched listen socket Menglong Dong
2025-08-02  9:24 ` [PATCH net v3 1/2] " Menglong Dong
2025-08-02 13:05   ` Jason Xing
2025-08-03  1:59     ` Menglong Dong
2025-08-03  2:53       ` Jason Xing
2025-08-03  4:00         ` Menglong Dong
2025-08-03  8:32           ` Jason Xing
2025-08-13 12:54             ` Menglong Dong
2025-08-13 17:52               ` Kuniyuki Iwashima
2025-08-02  9:24 ` [PATCH net v3 2/2] selftests/net: test TCP reuseport socket selection Menglong Dong
2025-08-05 19:00   ` Kuniyuki Iwashima
2025-08-13 12:57     ` Menglong Dong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).