From: Remi Gacogne Date: Fri, 2 Dec 2016 18:12:48 +0000 (+0100) Subject: dnsdist: Use `IP_BIND_ADDRESS_NO_PORT` when available X-Git-Tag: rec-4.1.0-alpha1~322^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ead60f8329b39068d99b5ac3028c031a95c10e9a;p=thirdparty%2Fpdns.git dnsdist: Use `IP_BIND_ADDRESS_NO_PORT` when available Since Linux 4.2, we can use `IP_BIND_ADDRESS_NO_PORT` to let the kernel know that we are calling `bind()` only to select the source address without any intention to listen on the socket. That way the source port "will be automatically chosen at `connect()` time, in a way that allows sharing a source port as long as the 4-tuples are unique." Suggested by Willy Tarreau (thanks!). --- diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 69ea938785..7ca0dc7575 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -54,6 +54,9 @@ static int setupTCPDownstream(shared_ptr ds) try { if (!IsAnyAddress(ds->sourceAddr)) { SSetsockopt(sock, SOL_SOCKET, SO_REUSEADDR, 1); +#ifdef IP_BIND_ADDRESS_NO_PORT + SSetsockopt(sock, SOL_IP, IP_BIND_ADDRESS_NO_PORT, 1); +#endif SBind(sock, ds->sourceAddr); } SConnect(sock, ds->remote);