]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
tcp: Update bind bucket state on port release
authorJakub Sitnicki <jakub@cloudflare.com>
Wed, 17 Sep 2025 13:22:04 +0000 (15:22 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 23 Sep 2025 08:12:15 +0000 (10:12 +0200)
commitd57f4b874946e997be52f5ebb5e0e1dad368c16f
tree2a7751bc386282c4f36b9a06bbd634457f644c86
parent3afb106f3f9aa81c512ec5c7e2f7e1c01a2a6e6b
tcp: Update bind bucket state on port release

Today, once an inet_bind_bucket enters a state where fastreuse >= 0 or
fastreuseport >= 0 after a socket is explicitly bound to a port, it remains
in that state until all sockets are removed and the bucket is destroyed.

In this state, the bucket is skipped during ephemeral port selection in
connect(). For applications using a reduced ephemeral port
range (IP_LOCAL_PORT_RANGE socket option), this can cause faster port
exhaustion since blocked buckets are excluded from reuse.

The reason the bucket state isn't updated on port release is unclear.
Possibly a performance trade-off to avoid scanning bucket owners, or just
an oversight.

Fix it by recalculating the bucket state when a socket releases a port. To
limit overhead, each inet_bind2_bucket stores its own (fastreuse,
fastreuseport) state. On port release, only the relevant port-addr bucket
is scanned, and the overall state is derived from these.

Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@google.com>
Link: https://patch.msgid.link/20250917-update-bind-bucket-state-on-unhash-v5-1-57168b661b47@cloudflare.com
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
include/net/inet_connection_sock.h
include/net/inet_hashtables.h
include/net/inet_timewait_sock.h
include/net/sock.h
net/ipv4/inet_connection_sock.c
net/ipv4/inet_hashtables.c
net/ipv4/inet_timewait_sock.c