Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auth: Add TCP Fast Open support #5137

Merged
merged 1 commit into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/markdown/authoritative/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pdns/common_startup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
26 changes: 25 additions & 1 deletion pdns/tcpreceiver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <cstring>
#include <cstdlib>
#include <sys/types.h>
#include <netinet/tcp.h>
#include <iostream>
#include <string>
#include "tcpreceiver.hh"
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand Down