]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Use `IP_BIND_ADDRESS_NO_PORT` when available 4786/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 2 Dec 2016 18:12:48 +0000 (19:12 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 19 Dec 2016 10:08:11 +0000 (11:08 +0100)
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!).

pdns/dnsdist-tcp.cc

index 69ea938785d278b986b2039543ec34a4cf8f8d5a..7ca0dc7575a9cdf9ab6f0dcb7d6e0ab9211cfbd4 100644 (file)
@@ -54,6 +54,9 @@ static int setupTCPDownstream(shared_ptr<DownstreamState> 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);