Skip to content

Commit

Permalink
dnsdist: disallow TCP disablement
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlexis committed May 29, 2019
1 parent 09bc847 commit 0230e35
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 25 deletions.
30 changes: 8 additions & 22 deletions pdns/dnsdist-lua.cc
Expand Up @@ -89,12 +89,9 @@ void resetLuaSideEffect()

typedef std::unordered_map<std::string, boost::variant<bool, int, std::string, std::vector<std::pair<int,int> > > > localbind_t;

static void parseLocalBindVars(boost::optional<localbind_t> vars, bool& doTCP, bool& reusePort, int& tcpFastOpenQueueSize, std::string& interface, std::set<int>& cpus)
static void parseLocalBindVars(boost::optional<localbind_t> vars, bool& reusePort, int& tcpFastOpenQueueSize, std::string& interface, std::set<int>& cpus)
{
if (vars) {
if (vars->count("doTCP")) {
doTCP = boost::get<bool>((*vars)["doTCP"]);
}
if (vars->count("reusePort")) {
reusePort = boost::get<bool>((*vars)["reusePort"]);
}
Expand Down Expand Up @@ -485,13 +482,12 @@ void setupLuaConfig(bool client)
g_outputBuffer="setLocal cannot be used at runtime!\n";
return;
}
bool doTCP = true;
bool reusePort = false;
int tcpFastOpenQueueSize = 0;
std::string interface;
std::set<int> cpus;

parseLocalBindVars(vars, doTCP, reusePort, tcpFastOpenQueueSize, interface, cpus);
parseLocalBindVars(vars, reusePort, tcpFastOpenQueueSize, interface, cpus);

try {
ComboAddress loc(addr, 53);
Expand All @@ -507,9 +503,7 @@ void setupLuaConfig(bool client)

// only works pre-startup, so no sync necessary
g_frontends.push_back(std::unique_ptr<ClientState>(new ClientState(loc, false, reusePort, tcpFastOpenQueueSize, interface, cpus)));
if (doTCP) {
g_frontends.push_back(std::unique_ptr<ClientState>(new ClientState(loc, true, reusePort, tcpFastOpenQueueSize, interface, cpus)));
}
g_frontends.push_back(std::unique_ptr<ClientState>(new ClientState(loc, true, reusePort, tcpFastOpenQueueSize, interface, cpus)));
}
catch(const std::exception& e) {
g_outputBuffer="Error: "+string(e.what())+"\n";
Expand All @@ -524,21 +518,18 @@ void setupLuaConfig(bool client)
g_outputBuffer="addLocal cannot be used at runtime!\n";
return;
}
bool doTCP = true;
bool reusePort = false;
int tcpFastOpenQueueSize = 0;
std::string interface;
std::set<int> cpus;

parseLocalBindVars(vars, doTCP, reusePort, tcpFastOpenQueueSize, interface, cpus);
parseLocalBindVars(vars, reusePort, tcpFastOpenQueueSize, interface, cpus);

try {
ComboAddress loc(addr, 53);
// only works pre-startup, so no sync necessary
g_frontends.push_back(std::unique_ptr<ClientState>(new ClientState(loc, false, reusePort, tcpFastOpenQueueSize, interface, cpus)));
if (doTCP) {
g_frontends.push_back(std::unique_ptr<ClientState>(new ClientState(loc, true, reusePort, tcpFastOpenQueueSize, interface, cpus)));
}
g_frontends.push_back(std::unique_ptr<ClientState>(new ClientState(loc, true, reusePort, tcpFastOpenQueueSize, interface, cpus)));
}
catch(std::exception& e) {
g_outputBuffer="Error: "+string(e.what())+"\n";
Expand Down Expand Up @@ -1100,13 +1091,12 @@ void setupLuaConfig(bool client)
return;
}
#ifdef HAVE_DNSCRYPT
bool doTCP = true;
bool reusePort = false;
int tcpFastOpenQueueSize = 0;
std::string interface;
std::set<int> cpus;

parseLocalBindVars(vars, doTCP, reusePort, tcpFastOpenQueueSize, interface, cpus);
parseLocalBindVars(vars, reusePort, tcpFastOpenQueueSize, interface, cpus);

try {
auto ctx = std::make_shared<DNSCryptContext>(providerName, certFile, keyFile);
Expand Down Expand Up @@ -1680,15 +1670,13 @@ void setupLuaConfig(bool client)
frontend->d_urls = {"/"};
}

bool doTCP = true;
bool reusePort = false;
int tcpFastOpenQueueSize = 0;
std::string interface;
std::set<int> cpus;
(void) doTCP;

if(vars) {
parseLocalBindVars(vars, doTCP, reusePort, tcpFastOpenQueueSize, interface, cpus);
parseLocalBindVars(vars, reusePort, tcpFastOpenQueueSize, interface, cpus);

if (vars->count("idleTimeout")) {
frontend->d_idleTimeout = boost::get<int>((*vars)["idleTimeout"]);
Expand Down Expand Up @@ -1779,15 +1767,13 @@ void setupLuaConfig(bool client)
return;
}

bool doTCP = true;
bool reusePort = false;
int tcpFastOpenQueueSize = 0;
std::string interface;
std::set<int> cpus;
(void) doTCP;

if (vars) {
parseLocalBindVars(vars, doTCP, reusePort, tcpFastOpenQueueSize, interface, cpus);
parseLocalBindVars(vars, reusePort, tcpFastOpenQueueSize, interface, cpus);

if (vars->count("provider")) {
frontend->d_provider = boost::get<const string>((*vars)["provider"]);
Expand Down
7 changes: 5 additions & 2 deletions pdns/dnsdistdist/docs/reference/config.rst
Expand Up @@ -66,6 +66,9 @@ Listen Sockets
.. versionchanged:: 1.3.0
Added ``cpus`` to the options.

.. versionchanged:: 1.4.0
Removed ``doTCP`` from the options. A listen socket on TCP is always created.

Add to the list of listen addresses.

:param str address: The IP Address with an optional port to listen on.
Expand All @@ -74,15 +77,15 @@ Listen Sockets

Options:

* ``doTCP=true``: bool - Also bind on TCP on ``address``.
* ``doTCP=true``: bool - Also bind on TCP on ``address``. Removed in 1.4.0.
* ``reusePort=false``: bool - Set the ``SO_REUSEPORT`` socket option.
* ``tcpFastOpenSize=0``: int - Set the TCP Fast Open queue size, enabling TCP Fast Open when available and the value is larger than 0.
* ``interface=""``: str - Set the network interface to use.
* ``cpus={}``: table - Set the CPU affinity for this listener thread, asking the scheduler to run it on a single CPU id, or a set of CPU ids. This parameter is only available if the OS provides the pthread_setaffinity_np() function.

.. code-block:: lua
addLocal('0.0.0.0:5300', { doTCP=true, reusePort=true })
addLocal('0.0.0.0:5300', { reusePort=true })
This will bind to both UDP and TCP on port 5300 with SO_REUSEPORT enabled.

Expand Down
5 changes: 4 additions & 1 deletion pdns/dnsdistdist/docs/reference/dnscrypt.rst
Expand Up @@ -6,6 +6,9 @@ DNSCrypt objects and functions
.. versionchanged:: 1.3.0
``cpus`` option added.

.. versionchanged:: 1.4.0
Removed ``doTCP`` from the options. A listen socket on TCP is always created.

Adds a DNSCrypt listen socket on ``address``.

:param string address: The address and port to listen on
Expand All @@ -16,7 +19,7 @@ DNSCrypt objects and functions

Options:

* ``doTCP=true``: bool - Also bind on TCP on ``address``.
* ``doTCP=true``: bool - Also bind on TCP on ``address``, removed in 1.4.0.
* ``reusePort=false``: bool - Set the ``SO_REUSEPORT`` socket option.
* ``tcpFastOpenSize=0``: int - Set the TCP Fast Open queue size, enabling TCP Fast Open when available and the value is larger than 0
* ``interface=""``: str - Sets the network interface to use
Expand Down

0 comments on commit 0230e35

Please sign in to comment.