]> git.ipfire.org Git - thirdparty/bind9.git/commit
Implement IP_LOCAL_PORT_RANGE socket option for Linux
authorOndřej Surý <ondrej@isc.org>
Thu, 24 Jul 2025 09:43:14 +0000 (11:43 +0200)
committerOndřej Surý <ondrej@isc.org>
Fri, 20 Feb 2026 13:06:23 +0000 (14:06 +0100)
commit04c81b55d2debfc9a401dca2c4ac4e4cffd9cce1
tree0b863a1bb516e0a53877c21574535aeb0291e8af
parent2c48fcaeedbe29205c0e0283a0d13aa9a2161280
Implement IP_LOCAL_PORT_RANGE socket option for Linux

For Linux >= 6.8:

Since 2023, Linux has introduced a change to the IP_LOCAL_PORT_RANGE
socket option that eliminates the need for the random window
shifting (implemented as a fallback in the next commit).

By setting IP_LOCAL_PORT_RANGE option, we tell the kernel to use better
approach to the source port selection.

For Linux << 6.8:

This implement selecting port by random shifting range leveraging the
IP_LOCAL_PORT_RANGE socket option.  The network manager is initialized
with the ephemeral port range (on startup and on reconfig) and then for
every outgoing TCP connection, we define a custom port range (1000
ports) and then randomly shift the custom range within the system range.

This helps the kernel to reduce the search space to the custom window
between <random_offset, random_offset + 1000>.

Reference:
https://blog.cloudflare.com/linux-transport-protocol-port-selection-performance/#kernel
bin/named/server.c
lib/isc/include/isc/net.h
lib/isc/include/isc/netmgr.h
lib/isc/include/isc/os.h
lib/isc/managers.c
lib/isc/net.c
lib/isc/netmgr/netmgr-int.h
lib/isc/netmgr/netmgr.c
lib/isc/netmgr/socket.c
lib/isc/netmgr/tcp.c
lib/isc/os.c