]> git.ipfire.org Git - thirdparty/squid.git/commit - src/comm/Connection.h
Optimize ephemeral port reuse with IP_BIND_ADDRESS_NO_PORT (#1115)
authorpponakan <52429302+pponakan@users.noreply.github.com>
Mon, 22 Aug 2022 22:28:34 +0000 (22:28 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 22 Aug 2022 22:28:44 +0000 (22:28 +0000)
commit74d7d19689da352281d1045cb8451a8b56028c6d
tree492e10662da46d4b133f2caf7778f819dc504ffb
parent24c937808c28bc755cdce682d624bc7c4225a227
Optimize ephemeral port reuse with IP_BIND_ADDRESS_NO_PORT (#1115)

    commBind: Cannot bind socket ... : (98) Address already in use

When opening a TCP connection from a specific IP address (e.g., set by
tcp_outgoing_address), Squid usually lets the OS select the source port
by performing the traditional bind(2)+connect(2) sequence with zero
source port. This sequence consumes ephemeral ports at the connection
opening rate even if many destinations are unique (and, hence, could
reuse the same source port) because the OS must pick a source port at
bind(2) time, before connect(2) supplies the destination address.

Starting with v4.2, Linux supports IP_BIND_ADDRESS_NO_PORT socket option
designed to decrease ephemeral port consumption by delaying port binding
until connect(2) time. If available, Squid now uses that option when
opening any outgoing TCP connection bound to a source IP address.
src/comm.cc
src/comm.h
src/comm/ConnOpener.cc
src/comm/Connection.h
src/tests/stub_comm.cc