From: Remi Gacogne Date: Thu, 30 May 2024 14:56:38 +0000 (+0200) Subject: dnsdist: Clean up Dynamic Rules configuration X-Git-Tag: rec-5.2.0-alpha1~172^2~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=245f46fc3283e310513ee63604f0d5799aecc904;p=thirdparty%2Fpdns.git dnsdist: Clean up Dynamic Rules configuration --- diff --git a/pdns/dnsdistdist/dnsdist-configuration.hh b/pdns/dnsdistdist/dnsdist-configuration.hh index f33b7ea7e0..a671652393 100644 --- a/pdns/dnsdistdist/dnsdist-configuration.hh +++ b/pdns/dnsdistdist/dnsdist-configuration.hh @@ -183,6 +183,7 @@ struct RuntimeConfiguration dnsdist::QueryCount::Configuration d_queryCountConfig; std::string d_secPollSuffix{"secpoll.powerdns.com."}; std::string d_apiConfigDirectory; + uint64_t d_dynBlocksPurgeInterval{60}; size_t d_maxTCPQueriesPerConn{0}; size_t d_maxTCPConnectionDuration{0}; size_t d_proxyProtocolMaximumSize{512}; diff --git a/pdns/dnsdistdist/dnsdist-dynblocks.cc b/pdns/dnsdistdist/dnsdist-dynblocks.cc index 1b276003b1..4a451efd97 100644 --- a/pdns/dnsdistdist/dnsdist-dynblocks.cc +++ b/pdns/dnsdistdist/dnsdist-dynblocks.cc @@ -612,8 +612,6 @@ struct DynBlockEntryStat std::list DynBlockMaintenance::s_metricsData; LockGuarded DynBlockMaintenance::s_tops; -size_t DynBlockMaintenance::s_topN{20}; -time_t DynBlockMaintenance::s_expiredDynBlocksPurgeInterval{60}; void DynBlockMaintenance::collectMetrics() { @@ -773,13 +771,14 @@ void DynBlockMaintenance::run() static const time_t metricsGenerationInterval = 60; time_t now = time(nullptr); - time_t nextExpiredPurge = now + s_expiredDynBlocksPurgeInterval; + auto purgeInterval = dnsdist::configuration::getCurrentRuntimeConfiguration().d_dynBlocksPurgeInterval; + time_t nextExpiredPurge = now + purgeInterval; time_t nextMetricsCollect = now + metricsCollectionInterval; time_t nextMetricsGeneration = now + metricsGenerationInterval; while (true) { time_t sleepDelay = std::numeric_limits::max(); - if (s_expiredDynBlocksPurgeInterval > 0) { + if (purgeInterval > 0) { sleepDelay = std::min(sleepDelay, (nextExpiredPurge - now)); } sleepDelay = std::min(sleepDelay, (nextMetricsCollect - now)); @@ -807,15 +806,14 @@ void DynBlockMaintenance::run() nextMetricsGeneration = now + metricsGenerationInterval; } - if (s_expiredDynBlocksPurgeInterval > 0 && now >= nextExpiredPurge) { - struct timespec tspec - { - }; + purgeInterval = dnsdist::configuration::getCurrentRuntimeConfiguration().d_dynBlocksPurgeInterval; + if (purgeInterval > 0 && now >= nextExpiredPurge) { + timespec tspec{}; gettime(&tspec); purgeExpired(tspec); now = time(nullptr); - nextExpiredPurge = now + s_expiredDynBlocksPurgeInterval; + nextExpiredPurge = now + purgeInterval; } } catch (const std::exception& e) { diff --git a/pdns/dnsdistdist/dnsdist-dynblocks.hh b/pdns/dnsdistdist/dnsdist-dynblocks.hh index 2cb39fcc28..d0a75ae3c7 100644 --- a/pdns/dnsdistdist/dnsdist-dynblocks.hh +++ b/pdns/dnsdistdist/dnsdist-dynblocks.hh @@ -358,8 +358,6 @@ public: static std::map>> getTopSuffixes(size_t topN); static void purgeExpired(const struct timespec& now); - static time_t s_expiredDynBlocksPurgeInterval; - private: static void collectMetrics(); static void generateMetrics(); @@ -380,7 +378,7 @@ private: /* s_metricsData should only be accessed by the dynamic blocks maintenance thread so it does not need a lock */ // need N+1 datapoints to be able to do the diff after a collection point has been reached static std::list s_metricsData; - static size_t s_topN; + static constexpr size_t s_topN{20}; }; namespace dnsdist::DynamicBlocks diff --git a/pdns/dnsdistdist/dnsdist-lua.cc b/pdns/dnsdistdist/dnsdist-lua.cc index 8e55dea4ba..9f9f428283 100644 --- a/pdns/dnsdistdist/dnsdist-lua.cc +++ b/pdns/dnsdistdist/dnsdist-lua.cc @@ -814,6 +814,9 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) config.d_payloadSizeSelfGenAnswers = newValue; }, std::numeric_limits::max()}, +#ifndef DISABLE_DYNBLOCKS + {"setDynBlocksPurgeInterval", [](dnsdist::configuration::RuntimeConfiguration& config, uint64_t newValue) { config.d_dynBlocksPurgeInterval = newValue; }, std::numeric_limits::max()}, +#endif /* DISABLE_DYNBLOCKS */ }; struct StringConfigurationItems @@ -1735,10 +1738,6 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck) } }); #endif /* DISABLE_DEPRECATED_DYNBLOCK */ - - luaCtx.writeFunction("setDynBlocksPurgeInterval", [](uint64_t interval) { - DynBlockMaintenance::s_expiredDynBlocksPurgeInterval = static_cast(interval); - }); #endif /* DISABLE_DYNBLOCKS */ #ifdef HAVE_DNSCRYPT