Skip to content

Commit

Permalink
dnsdist: Move outgoing connections settings to the new configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rgacogne committed Jul 5, 2024
1 parent 000749d commit f0a0605
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 56 deletions.
9 changes: 6 additions & 3 deletions pdns/dnsdistdist/dnsdist-backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -309,12 +309,15 @@ DownstreamState::DownstreamState(DownstreamState::Config&& config, std::shared_p
#ifdef HAVE_NGHTTP2
setupDoHClientProtocolNegotiation(d_tlsCtx);

if (dnsdist::configuration::isConfigurationDone() && g_outgoingDoHWorkerThreads && *g_outgoingDoHWorkerThreads == 0) {
auto outgoingDoHWorkerThreads = dnsdist::configuration::getImmutableConfiguration().d_outgoingDoHWorkers;
if (dnsdist::configuration::isConfigurationDone() && outgoingDoHWorkerThreads && *outgoingDoHWorkerThreads == 0) {
throw std::runtime_error("Error: setOutgoingDoHWorkerThreads() is set to 0 so no outgoing DoH worker thread is available to serve queries");
}

if (!g_outgoingDoHWorkerThreads || *g_outgoingDoHWorkerThreads == 0) {
g_outgoingDoHWorkerThreads = 1;
if (!dnsdist::configuration::isConfigurationDone() && (!outgoingDoHWorkerThreads || *outgoingDoHWorkerThreads == 0)) {
dnsdist::configuration::updateImmutableConfiguration([](dnsdist::configuration::Configuration& immutableConfig) {
immutableConfig.d_outgoingDoHWorkers = 1;
});
}
#endif /* HAVE_NGHTTP2 */
}
Expand Down
7 changes: 7 additions & 0 deletions pdns/dnsdistdist/dnsdist-configuration.hh
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,14 @@ struct Configuration
#endif
double d_weightedBalancingFactor{0};
double d_consistentHashBalancingFactor{0};
std::optional<uint64_t> d_outgoingDoHWorkers{std::nullopt};
uint64_t d_consoleMaxConcurrentConnections{0};
uint64_t d_outgoingDoHMaxIdleTime{300};
uint64_t d_outgoingTCPMaxIdleTime{300};
uint64_t d_outgoingDoHCleanupInterval{60};
uint64_t d_outgoingTCPCleanupInterval{60};
uint64_t d_outgoingDoHMaxIdlePerBackend{10};
uint64_t d_outgoingTCPMaxIdlePerBackend{10};
uint64_t d_maxTCPClientThreads{0};
size_t d_maxTCPConnectionsPerClient{0};
size_t d_udpVectorSize{1};
Expand Down
56 changes: 10 additions & 46 deletions pdns/dnsdistdist/dnsdist-lua.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
#include "dnsdist-secpoll.hh"
#include "dnsdist-session-cache.hh"
#include "dnsdist-snmp.hh"
#include "dnsdist-tcp-downstream.hh"
#include "dnsdist-web.hh"

#include "base64.hh"
Expand Down Expand Up @@ -873,6 +872,15 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
{"setMaxTCPClientThreads", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_maxTCPClientThreads = newValue; }, std::numeric_limits<uint16_t>::max()},
{"setMaxTCPConnectionsPerClient", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_maxTCPConnectionsPerClient = newValue; }, std::numeric_limits<uint64_t>::max()},
{"setTCPInternalPipeBufferSize", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_tcpInternalPipeBufferSize = newValue; }, std::numeric_limits<uint64_t>::max()},
{"setMaxCachedTCPConnectionsPerDownstream", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_outgoingTCPMaxIdlePerBackend = newValue; }, std::numeric_limits<uint16_t>::max()},
{"setTCPDownstreamCleanupInterval", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_outgoingTCPCleanupInterval = newValue; }, std::numeric_limits<uint32_t>::max()},
{"setTCPDownstreamMaxIdleTime", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_outgoingTCPMaxIdleTime = newValue; }, std::numeric_limits<uint16_t>::max()},
#if defined(HAVE_DNS_OVER_HTTPS) && defined(HAVE_NGHTTP2)
{"setOutgoingDoHWorkerThreads", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_outgoingDoHWorkers = newValue; }, std::numeric_limits<uint16_t>::max()},
{"setMaxIdleDoHConnectionsPerDownstream", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_outgoingDoHMaxIdlePerBackend = newValue; }, std::numeric_limits<uint16_t>::max()},
{"setDoHDownstreamCleanupInterval", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_outgoingDoHCleanupInterval = newValue; }, std::numeric_limits<uint32_t>::max()},
{"setDoHDownstreamMaxIdleTime", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_outgoingDoHMaxIdleTime = newValue; }, std::numeric_limits<uint16_t>::max()},
#endif /* HAVE_DNS_OVER_HTTPS && HAVE_NGHTTP2 */
{"setMaxUDPOutstanding", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_maxUDPOutstanding = newValue; }, std::numeric_limits<uint16_t>::max()},
{"setWHashedPertubation", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_hashPerturbation = newValue; }, std::numeric_limits<uint32_t>::max()},
#ifndef DISABLE_RECVMMSG
Expand All @@ -881,6 +889,7 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
{"setUDPTimeout", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_udpTimeout = newValue; }, std::numeric_limits<uint8_t>::max()},
{"setConsoleMaximumConcurrentConnections", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_consoleMaxConcurrentConnections = newValue; }, std::numeric_limits<uint32_t>::max()},
};

struct DoubleImmutableConfigurationItems
{
const std::string name;
Expand Down Expand Up @@ -1574,23 +1583,6 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
#endif
});

luaCtx.writeFunction("setMaxCachedTCPConnectionsPerDownstream", [](uint64_t max) {
setTCPDownstreamMaxIdleConnectionsPerBackend(max);
});

#if defined(HAVE_DNS_OVER_HTTPS) && defined(HAVE_NGHTTP2)
luaCtx.writeFunction("setMaxIdleDoHConnectionsPerDownstream", [](uint64_t max) {
setDoHDownstreamMaxIdleConnectionsPerBackend(max);
});

luaCtx.writeFunction("setOutgoingDoHWorkerThreads", [](uint64_t workers) {
if (!checkConfigurationTime("setOutgoingDoHWorkerThreads")) {
return;
}
g_outgoingDoHWorkerThreads = workers;
});
#endif /* HAVE_DNS_OVER_HTTPS && HAVE_NGHTTP2 */

luaCtx.writeFunction("getOutgoingTLSSessionCacheSize", []() {
setLuaNoSideEffect();
return g_sessionCache.getSize();
Expand Down Expand Up @@ -2310,34 +2302,6 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
});
#endif /* DISABLE_POLICIES_BINDINGS */

luaCtx.writeFunction("setTCPDownstreamCleanupInterval", [](uint64_t interval) {
setLuaSideEffect();
checkParameterBound("setTCPDownstreamCleanupInterval", interval);
setTCPDownstreamCleanupInterval(interval);
});

#if defined(HAVE_DNS_OVER_HTTPS) && defined(HAVE_NGHTTP2)
luaCtx.writeFunction("setDoHDownstreamCleanupInterval", [](uint64_t interval) {
setLuaSideEffect();
checkParameterBound("setDoHDownstreamCleanupInterval", interval);
setDoHDownstreamCleanupInterval(interval);
});
#endif /* HAVE_DNS_OVER_HTTPS && HAVE_NGHTTP2 */

luaCtx.writeFunction("setTCPDownstreamMaxIdleTime", [](uint64_t max) {
setLuaSideEffect();
checkParameterBound("setTCPDownstreamMaxIdleTime", max);
setTCPDownstreamMaxIdleTime(max);
});

#if defined(HAVE_DNS_OVER_HTTPS) && defined(HAVE_NGHTTP2)
luaCtx.writeFunction("setDoHDownstreamMaxIdleTime", [](uint64_t max) {
setLuaSideEffect();
checkParameterBound("setDoHDownstreamMaxIdleTime", max);
setDoHDownstreamMaxIdleTime(max);
});
#endif /* HAVE_DNS_OVER_HTTPS && HAVE_NGHTTP2 */

luaCtx.writeFunction("setProxyProtocolACL", [](LuaTypeOrArrayOf<std::string> inp) {
if (!checkConfigurationTime("setProxyProtocolACL")) {
return;
Expand Down
12 changes: 6 additions & 6 deletions pdns/dnsdistdist/dnsdist-nghttp2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

std::atomic<uint64_t> g_dohStatesDumpRequested{0};
std::unique_ptr<DoHClientCollection> g_dohClientThreads{nullptr};
std::optional<uint16_t> g_outgoingDoHWorkerThreads{std::nullopt};

#if defined(HAVE_DNS_OVER_HTTPS) && defined(HAVE_NGHTTP2)
class DoHConnectionToBackend : public ConnectionToBackend
Expand Down Expand Up @@ -1024,15 +1023,16 @@ void DoHClientCollection::addThread()
bool initDoHWorkers()
{
#if defined(HAVE_DNS_OVER_HTTPS) && defined(HAVE_NGHTTP2)
if (!g_outgoingDoHWorkerThreads) {
auto outgoingDoHWorkerThreads = dnsdist::configuration::getImmutableConfiguration().d_outgoingDoHWorkers;
if (!outgoingDoHWorkerThreads) {
/* Unless the value has been set to 0 explicitly, always start at least one outgoing DoH worker thread, in case a DoH backend
is added at a later time. */
g_outgoingDoHWorkerThreads = 1;
outgoingDoHWorkerThreads = 1;
}

if (g_outgoingDoHWorkerThreads && *g_outgoingDoHWorkerThreads > 0) {
g_dohClientThreads = std::make_unique<DoHClientCollection>(*g_outgoingDoHWorkerThreads);
for (size_t idx = 0; idx < *g_outgoingDoHWorkerThreads; idx++) {
if (outgoingDoHWorkerThreads && *outgoingDoHWorkerThreads > 0) {
g_dohClientThreads = std::make_unique<DoHClientCollection>(*outgoingDoHWorkerThreads);
for (size_t idx = 0; idx < *outgoingDoHWorkerThreads; idx++) {
g_dohClientThreads->addThread();
}
}
Expand Down
1 change: 0 additions & 1 deletion pdns/dnsdistdist/dnsdist-nghttp2.hh
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ private:

extern std::unique_ptr<DoHClientCollection> g_dohClientThreads;
extern std::atomic<uint64_t> g_dohStatesDumpRequested;
extern std::optional<uint16_t> g_outgoingDoHWorkerThreads;

class TLSCtx;

Expand Down
13 changes: 13 additions & 0 deletions pdns/dnsdistdist/dnsdist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#include "dnsdist-secpoll.hh"
#include "dnsdist-snmp.hh"
#include "dnsdist-tcp.hh"
#include "dnsdist-tcp-downstream.hh"
#include "dnsdist-web.hh"
#include "dnsdist-xsk.hh"

Expand Down Expand Up @@ -3365,6 +3366,18 @@ int main(int argc, char** argv)

dnsdist::configuration::setConfigurationDone();

{
const auto& immutableConfig = dnsdist::configuration::getImmutableConfiguration();
setTCPDownstreamMaxIdleConnectionsPerBackend(immutableConfig.d_outgoingTCPMaxIdlePerBackend);
setTCPDownstreamMaxIdleTime(immutableConfig.d_outgoingTCPMaxIdleTime);
setTCPDownstreamCleanupInterval(immutableConfig.d_outgoingTCPCleanupInterval);
#if defined(HAVE_DNS_OVER_HTTPS) && defined(HAVE_NGHTTP2)
setDoHDownstreamMaxIdleConnectionsPerBackend(immutableConfig.d_outgoingDoHMaxIdlePerBackend);
setDoHDownstreamMaxIdleTime(immutableConfig.d_outgoingDoHMaxIdleTime);
setDoHDownstreamCleanupInterval(immutableConfig.d_outgoingDoHCleanupInterval);
#endif /* HAVE_DNS_OVER_HTTPS && HAVE_NGHTTP2 */
}

g_rings.init();

for (auto& frontend : g_frontends) {
Expand Down

0 comments on commit f0a0605

Please sign in to comment.