Le mar. 10 nov. 2026 à 07:45, Kuniyuki Iwashima [off-list ref] a écrit :
On Fri, 06 Nov 2026 19:14:41 +0200, Florin Badita-Nistor wrote:
quoted
inet_csk_find_open_port() rounds the range length down to an even
number but keeps the original exclusive upper bound for wrapping.
For an odd-sized range, the two scans can therefore miss a valid port
and return EADDRINUSE while an eligible port remains free.
For example, restrict a TCP socket to IP_LOCAL_PORT_RANGE [40000, 40002]
and hold explicit binds on 40000 and 40001. bind(..., 0) always fails,
although an explicit bind to 40002 succeeds. Both IPv4 and IPv6 TCP and
This is the reason of warning in set_local_port_range(),
so kind of WAI to me.
The change should be fine, but we should remove the warning.
I would keep the warning.
It was added in commit ed2dfd900992 ("tcp/dccp: warn user for preferred
ip_local_port_range") because connect() wants an even number of ports.
This is still the case: __inet_hash_connect() rounds an odd-sized netns
range down to an even size, so connect() can still miss one port there.
The per-socket IP_LOCAL_PORT_RANGE case has no warning at all, and
bind() can miss a free port there without any hint to the user.
This patch fixes that.
Reviewed-by: Eric Dumazet <edumazet@kernel.org>