]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Clean up Dynamic Rules configuration
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 30 May 2024 14:56:38 +0000 (16:56 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 15 Jul 2024 09:39:36 +0000 (11:39 +0200)
pdns/dnsdistdist/dnsdist-configuration.hh
pdns/dnsdistdist/dnsdist-dynblocks.cc
pdns/dnsdistdist/dnsdist-dynblocks.hh
pdns/dnsdistdist/dnsdist-lua.cc

index f33b7ea7e0a1b89b5650a90eaaf23e048ab86475..a671652393d955274201a2a62a4a7cbce08932bf 100644 (file)
@@ -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};
index 1b276003b1f64be3d1d99b50aa571574d05e42be..4a451efd97d5de3e03f54da1669f607bc3313b6e 100644 (file)
@@ -612,8 +612,6 @@ struct DynBlockEntryStat
 std::list<DynBlockMaintenance::MetricsSnapshot> DynBlockMaintenance::s_metricsData;
 
 LockGuarded<DynBlockMaintenance::Tops> 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<time_t>::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) {
index 2cb39fcc28ddd3946ee414f614b08ced4e6a1961..d0a75ae3c737c006a82b02461ed43cd5293a2a67 100644 (file)
@@ -358,8 +358,6 @@ public:
   static std::map<std::string, std::list<std::pair<DNSName, unsigned int>>> 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<MetricsSnapshot> s_metricsData;
-  static size_t s_topN;
+  static constexpr size_t s_topN{20};
 };
 
 namespace dnsdist::DynamicBlocks
index 8e55dea4ba44d5d4e9cab327faae205074755209..9f9f4282836bf350c16280a48b1af5179abfaa48 100644 (file)
@@ -814,6 +814,9 @@ static void setupLuaConfig(LuaContext& luaCtx, bool client, bool configCheck)
        config.d_payloadSizeSelfGenAnswers = newValue;
      },
      std::numeric_limits<uint64_t>::max()},
+#ifndef DISABLE_DYNBLOCKS
+    {"setDynBlocksPurgeInterval", [](dnsdist::configuration::RuntimeConfiguration& config, uint64_t newValue) { config.d_dynBlocksPurgeInterval = newValue; }, std::numeric_limits<uint32_t>::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<time_t>(interval);
-  });
 #endif /* DISABLE_DYNBLOCKS */
 
 #ifdef HAVE_DNSCRYPT