diff --git a/pdns/dnsdistdist/dnsdist-backend.cc b/pdns/dnsdistdist/dnsdist-backend.cc index 496b30224458..a1b9a6d380d0 100644 --- a/pdns/dnsdistdist/dnsdist-backend.cc +++ b/pdns/dnsdistdist/dnsdist-backend.cc @@ -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 */ } diff --git a/pdns/dnsdistdist/dnsdist-configuration.hh b/pdns/dnsdistdist/dnsdist-configuration.hh index 966665282f18..9889d40b9a94 100644 --- a/pdns/dnsdistdist/dnsdist-configuration.hh +++ b/pdns/dnsdistdist/dnsdist-configuration.hh @@ -169,7 +169,14 @@ struct Configuration #endif double d_weightedBalancingFactor{0}; double d_consistentHashBalancingFactor{0}; + std::optional 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}; diff --git a/pdns/dnsdistdist/dnsdist-lua.cc b/pdns/dnsdistdist/dnsdist-lua.cc index 46e30872632f..991a8bcc94d0 100644 --- a/pdns/dnsdistdist/dnsdist-lua.cc +++ b/pdns/dnsdistdist/dnsdist-lua.cc @@ -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" @@ -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::max()}, {"setMaxTCPConnectionsPerClient", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_maxTCPConnectionsPerClient = newValue; }, std::numeric_limits::max()}, {"setTCPInternalPipeBufferSize", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_tcpInternalPipeBufferSize = newValue; }, std::numeric_limits::max()}, + {"setMaxCachedTCPConnectionsPerDownstream", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_outgoingTCPMaxIdlePerBackend = newValue; }, std::numeric_limits::max()}, + {"setTCPDownstreamCleanupInterval", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_outgoingTCPCleanupInterval = newValue; }, std::numeric_limits::max()}, + {"setTCPDownstreamMaxIdleTime", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_outgoingTCPMaxIdleTime = newValue; }, std::numeric_limits::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::max()}, + {"setMaxIdleDoHConnectionsPerDownstream", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_outgoingDoHMaxIdlePerBackend = newValue; }, std::numeric_limits::max()}, + {"setDoHDownstreamCleanupInterval", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_outgoingDoHCleanupInterval = newValue; }, std::numeric_limits::max()}, + {"setDoHDownstreamMaxIdleTime", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_outgoingDoHMaxIdleTime = newValue; }, std::numeric_limits::max()}, +#endif /* HAVE_DNS_OVER_HTTPS && HAVE_NGHTTP2 */ {"setMaxUDPOutstanding", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_maxUDPOutstanding = newValue; }, std::numeric_limits::max()}, {"setWHashedPertubation", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_hashPerturbation = newValue; }, std::numeric_limits::max()}, #ifndef DISABLE_RECVMMSG @@ -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::max()}, {"setConsoleMaximumConcurrentConnections", [](dnsdist::configuration::Configuration& config, uint64_t newValue) { config.d_consoleMaxConcurrentConnections = newValue; }, std::numeric_limits::max()}, }; + struct DoubleImmutableConfigurationItems { const std::string name; @@ -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(); @@ -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 inp) { if (!checkConfigurationTime("setProxyProtocolACL")) { return; diff --git a/pdns/dnsdistdist/dnsdist-nghttp2.cc b/pdns/dnsdistdist/dnsdist-nghttp2.cc index ffacf9a19ce4..79b39adc041a 100644 --- a/pdns/dnsdistdist/dnsdist-nghttp2.cc +++ b/pdns/dnsdistdist/dnsdist-nghttp2.cc @@ -43,7 +43,6 @@ std::atomic g_dohStatesDumpRequested{0}; std::unique_ptr g_dohClientThreads{nullptr}; -std::optional g_outgoingDoHWorkerThreads{std::nullopt}; #if defined(HAVE_DNS_OVER_HTTPS) && defined(HAVE_NGHTTP2) class DoHConnectionToBackend : public ConnectionToBackend @@ -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(*g_outgoingDoHWorkerThreads); - for (size_t idx = 0; idx < *g_outgoingDoHWorkerThreads; idx++) { + if (outgoingDoHWorkerThreads && *outgoingDoHWorkerThreads > 0) { + g_dohClientThreads = std::make_unique(*outgoingDoHWorkerThreads); + for (size_t idx = 0; idx < *outgoingDoHWorkerThreads; idx++) { g_dohClientThreads->addThread(); } } diff --git a/pdns/dnsdistdist/dnsdist-nghttp2.hh b/pdns/dnsdistdist/dnsdist-nghttp2.hh index 6e38f28cc383..4027c26aef5a 100644 --- a/pdns/dnsdistdist/dnsdist-nghttp2.hh +++ b/pdns/dnsdistdist/dnsdist-nghttp2.hh @@ -57,7 +57,6 @@ private: extern std::unique_ptr g_dohClientThreads; extern std::atomic g_dohStatesDumpRequested; -extern std::optional g_outgoingDoHWorkerThreads; class TLSCtx; diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index d4e6212ec0a4..8ac38960a8f4 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -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" @@ -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) {