]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: Add TCP Fast Open support 5137/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Sun, 12 Mar 2017 15:48:38 +0000 (16:48 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 17 Mar 2017 15:04:05 +0000 (16:04 +0100)
docs/markdown/authoritative/settings.md
pdns/common_startup.cc
pdns/tcpreceiver.cc

index 642782b6987e80d6f48e6d85a3efbdceb0ff7b7e..ca6611841614bf05b02100761715e17f2b2c6144 100644 (file)
@@ -805,6 +805,14 @@ Limit TCP control to a specific client range.
 
 Password for TCP control.
 
+## `tcp-fast-open`
+* Integer
+* Default: 0 (Disabled)
+* Available since: 4.1
+
+Enable TCP Fast Open support, if available, on the listening sockets. The numerical
+value supplied is used as the queue size, 0 meaning disabled.
+
 ## `tcp-idle-timeout`
 * Integer
 * Default: 5
index 4dd592b6bceac32d769798d0b6d3d4a8058ff9a2..87bb65c223d701b498b65561d08f624668cc8ddf 100644 (file)
@@ -195,6 +195,8 @@ void declareArguments()
   ::arg().setSwitch("8bit-dns", "Allow 8bit dns queries")="no";
 
   ::arg().set("xfr-max-received-mbytes", "Maximum number of megabytes received from an incoming XFR")="100";
+
+  ::arg().set("tcp-fast-open", "Enable TCP Fast Open support on the listening sockets, using the supplied numerical value as the queue size")="0";
 }
 
 static time_t s_start=time(0);
index 03cf47ffe1510eb22537330ed8bab573e3d3ef56..f16eda32d96656def04e094043d02c959ab50f26 100644 (file)
@@ -32,6 +32,7 @@
 #include <cstring>
 #include <cstdlib>
 #include <sys/types.h>
+#include <netinet/tcp.h>
 #include <iostream>
 #include <string>
 #include "tcpreceiver.hh"
@@ -1233,7 +1234,18 @@ TCPNameserver::TCPNameserver()
       L<<Logger::Error<<"Setsockopt failed"<<endl;
       exit(1);  
     }
-    
+
+    if (::arg().asNum("tcp-fast-open") > 0) {
+#ifdef TCP_FASTOPEN
+      int fastOpenQueueSize = ::arg().asNum("tcp-fast-open");
+      if (setsockopt(s, IPPROTO_TCP, TCP_FASTOPEN, &fastOpenQueueSize, sizeof fastOpenQueueSize) < 0) {
+        L<<Logger::Error<<"Failed to enable TCP Fast Open for listening socket: "<<strerror(errno)<<endl;
+      }
+#else
+      L<<Logger::Warning<<"TCP Fast Open configured but not supported for listening socket"<<endl;
+#endif
+    }
+
     if( ::arg().mustDo("non-local-bind") )
        Utility::setBindAny(AF_INET, s);
 
@@ -1274,6 +1286,18 @@ TCPNameserver::TCPNameserver()
       L<<Logger::Error<<"Setsockopt failed"<<endl;
       exit(1);  
     }
+
+    if (::arg().asNum("tcp-fast-open") > 0) {
+#ifdef TCP_FASTOPEN
+      int fastOpenQueueSize = ::arg().asNum("tcp-fast-open");
+      if (setsockopt(s, IPPROTO_TCP, TCP_FASTOPEN, &fastOpenQueueSize, sizeof fastOpenQueueSize) < 0) {
+        L<<Logger::Error<<"Failed to enable TCP Fast Open for listening socket: "<<strerror(errno)<<endl;
+      }
+#else
+      L<<Logger::Warning<<"TCP Fast Open configured but not supported for listening socket"<<endl;
+#endif
+    }
+
     if( ::arg().mustDo("non-local-bind") )
        Utility::setBindAny(AF_INET6, s);
     if(setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &tmp, sizeof(tmp)) < 0) {