]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Don;t take refresh time from SOA, allow for single shot (refreshPeriod = 0) and
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Fri, 1 Oct 2021 13:40:47 +0000 (15:40 +0200)
committerOtto <otto.moerbeek@open-xchange.com>
Mon, 4 Oct 2021 10:46:07 +0000 (12:46 +0200)
docs fixes.

pdns/recursordist/rec-zonetocache.cc
pdns/recursordist/rec-zonetocache.hh

index bfff560d216b49efca4d75651110edb9b7b4d922..ffdd6777248617ff3ae58c4cb9858decb120ab0c 100644 (file)
@@ -39,7 +39,8 @@
 
 struct ZoneData
 {
-  ZoneData(shared_ptr<Logr::Logger>& log) : d_log(log) {}
+  ZoneData(shared_ptr<Logr::Logger>& log) :
+    d_log(log) {}
 
   std::map<pair<DNSName, QType>, vector<DNSRecord>> d_all;
   std::map<pair<DNSName, QType>, vector<shared_ptr<RRSIGRecordContent>>> d_sigs;
@@ -51,7 +52,7 @@ struct ZoneData
   bool isRRSetAuth(const DNSName& qname, QType qtype);
   void parseDRForCache(DNSRecord& dr);
   void getByAXFR(const RecZoneToCache::Config&);
-  time_t ZoneToCache(const RecZoneToCache::Config& config);
+  void ZoneToCache(const RecZoneToCache::Config& config);
 };
 
 bool ZoneData::isRRSetAuth(const DNSName& qname, QType qtype)
@@ -180,10 +181,10 @@ static std::vector<std::string> getURL(const RecZoneToCache::Config& config)
   return lines;
 }
 
-time_t ZoneData::ZoneToCache(const RecZoneToCache::Config& config)
+void ZoneData::ZoneToCache(const RecZoneToCache::Config& config)
 {
   if (config.d_sources.size() > 1) {
-    d_log->info("Multiple sources not yet supported, using first"); 
+    d_log->info("Multiple sources not yet supported, using first");
   }
   d_zone = DNSName(config.d_zone);
   d_now = time(nullptr);
@@ -219,7 +220,6 @@ time_t ZoneData::ZoneToCache(const RecZoneToCache::Config& config)
 
   // Rerun, now inserting the rrsets into the cache with associated sigs
   d_now = time(nullptr);
-  time_t refreshFromSoa = 0;
   for (const auto& [key, v] : d_all) {
     const auto& [qname, qtype] = key;
     switch (qtype) {
@@ -229,11 +229,6 @@ time_t ZoneData::ZoneToCache(const RecZoneToCache::Config& config)
     case QType::RRSIG:
       break;
     default: {
-      if (qtype == QType::SOA) {
-        const auto& rr = getRR<SOARecordContent>(v[0]);
-        refreshFromSoa = rr->d_st.refresh;
-      }
-
       vector<shared_ptr<RRSIGRecordContent>> sigsrr;
       auto it = d_sigs.find(key);
       if (it != d_sigs.end()) {
@@ -251,8 +246,6 @@ time_t ZoneData::ZoneToCache(const RecZoneToCache::Config& config)
     }
     }
   }
-
-  return refreshFromSoa;
 }
 
 // Config must be a copy, so call by value!
@@ -260,7 +253,6 @@ void RecZoneToCache::ZoneToCache(RecZoneToCache::Config config, uint64_t configG
 {
   setThreadName("pdns-r/ztc/" + config.d_zone);
   auto luaconfsLocal = g_luaconfs.getLocal();
-
   auto log = g_slog->withName("ztc")->withValues("zone", Logging::Loggable(config.d_zone));
 
   while (true) {
@@ -275,14 +267,11 @@ void RecZoneToCache::ZoneToCache(RecZoneToCache::Config config, uint64_t configG
     time_t refresh = config.d_retryOnError;
     try {
       ZoneData data(log);
-      time_t refreshFromSoa = data.ZoneToCache(config);
+      data.ZoneToCache(config);
       refresh = config.d_refreshPeriod;
-      if (refresh == 0) {
-        refresh = refreshFromSoa;
-      }
       log->info("Loaded zone into cache", "refresh", Logging::Loggable(refresh));
     }
-    catch (const PDNSException &e) {
+    catch (const PDNSExceptione) {
       log->info("Unable to load zone into cache, will retry", "exception", Logging::Loggable(e.reason), "refresh", Logging::Loggable(refresh));
     }
     catch (const std::runtime_error& e) {
@@ -291,6 +280,9 @@ void RecZoneToCache::ZoneToCache(RecZoneToCache::Config config, uint64_t configG
     catch (...) {
       log->info("Unable to load zone into cache, will retry", "exception", Logging::Loggable("unknown"), "refresh", Logging::Loggable(refresh));
     }
+    if (refresh == 0) {
+      return; // single shot
+    }
     sleep(refresh);
   }
 }
index 715ca7ecb67ae00b7daa60f11aa02cd020bf21e1..8eb6425af2214c3e5042a38d03eabb1c25f1f90c 100644 (file)
@@ -38,7 +38,7 @@ public:
     TSIGTriplet d_tt; // Authentication data
     size_t d_maxReceivedBytes{0}; // Maximum size
     time_t d_retryOnError{60}; // Retry on error
-    time_t d_refreshPeriod{0}; // Take from SOA by default
+    time_t d_refreshPeriod{24 * 3600}; // Time between refetch
     uint32_t d_timeout{20}; // timeout in seconds
   };
   static void ZoneToCache(Config config, uint64_t gen);