]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Allow the default ZoneParserTNG TTL to be modified. 15389/head
authorMiod Vallat <miod.vallat@powerdns.com>
Thu, 3 Apr 2025 10:08:48 +0000 (12:08 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Thu, 3 Apr 2025 10:43:33 +0000 (12:43 +0200)
Fixes #8494

pdns/pdnsutil.cc
pdns/zoneparser-tng.cc
pdns/zoneparser-tng.hh

index 4bbb0f9b3d76b708048098b678ee93afe1a0d6bc..413ab676cf3a92ab2d58ef66ec8c32c2bf64474e 100644 (file)
@@ -1543,6 +1543,7 @@ static int loadZone(const DNSName& zone, const string& fname) {
   }
   DNSBackend* db = di.backend;
   ZoneParserTNG zpt(fname, zone);
+  zpt.setDefaultTTL(::arg().asNum("default-ttl"));
   zpt.setMaxGenerateSteps(::arg().asNum("max-generate-steps"));
 
   DNSResourceRecord rr;
index 41bd5e5683c816a830e330c00d660efad72a49a4..7a7e971c0db058c9d50d7191df5418d57316aac2 100644 (file)
@@ -41,7 +41,7 @@ const static string g_INstr("IN");
 ZoneParserTNG::ZoneParserTNG(const string& fname, DNSName  zname, string  reldir, bool upgradeContent):
   d_reldir(std::move(reldir)), d_zonename(std::move(zname)), d_defaultttl(3600),
   d_templatecounter(0), d_templatestop(0), d_templatestep(0),
-  d_havedollarttl(false), d_fromfile(true), d_upgradeContent(upgradeContent)
+  d_havespecificttl(false), d_fromfile(true), d_upgradeContent(upgradeContent)
 {
   stackFile(fname);
 }
@@ -49,7 +49,7 @@ ZoneParserTNG::ZoneParserTNG(const string& fname, DNSName  zname, string  reldir
 ZoneParserTNG::ZoneParserTNG(const vector<string>& zonedata, DNSName  zname, bool upgradeContent):
   d_zonename(std::move(zname)), d_zonedata(zonedata), d_defaultttl(3600),
   d_templatecounter(0), d_templatestop(0), d_templatestep(0),
-  d_havedollarttl(false), d_fromfile(false), d_upgradeContent(upgradeContent)
+  d_havespecificttl(false), d_fromfile(false), d_upgradeContent(upgradeContent)
 {
   d_zonedataline = d_zonedata.begin();
 }
@@ -338,6 +338,7 @@ pair<string,int> ZoneParserTNG::getLineNumAndFile()
     return {d_filestates.top().d_filename, d_filestates.top().d_lineno};
 }
 
+// NOLINTNEXTLINE(readability-function-cognitive-complexity)
 bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment)
 {
  retry:;
@@ -363,7 +364,7 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment)
     string command=makeString(d_line, d_parts[0]);
     if(pdns_iequals(command,"$TTL") && d_parts.size() > 1) {
       d_defaultttl=makeTTLFromZone(trim_right_copy_if(makeString(d_line, d_parts[1]), boost::is_any_of(";")));
-      d_havedollarttl=true;
+      d_havespecificttl=true;
     }
     else if(pdns_iequals(command,"$INCLUDE") && d_parts.size() > 1 && d_fromfile) {
       string fname=unquotify(makeString(d_line, d_parts[1]));
@@ -515,8 +516,9 @@ bool ZoneParserTNG::get(DNSResourceRecord& rr, std::string* comment)
     }
     if(!haveTTL && !haveQTYPE && isTimeSpec(nextpart)) {
       rr.ttl=makeTTLFromZone(nextpart);
-      if(!d_havedollarttl)
+      if (!d_havespecificttl) {
         d_defaultttl = rr.ttl;
+      }
       haveTTL=true;
       // cout<<"ttl is probably: "<<rr.ttl<<endl;
       continue;
index 977fcb768210ae1c831556098f75df6163eecbb1..84055946355164a156be84d1942f928aeed05b9b 100644 (file)
@@ -53,6 +53,11 @@ public:
   {
     d_maxIncludes = max;
   }
+  void setDefaultTTL(int ttl)
+  {
+    d_defaultttl = ttl;
+    d_havespecificttl = true;
+  }
 private:
   bool getLine();
   bool getTemplateLine();
@@ -81,7 +86,7 @@ private:
   size_t d_maxIncludes{20};
   int d_defaultttl;
   uint32_t d_templatecounter, d_templatestop, d_templatestep;
-  bool d_havedollarttl;
+  bool d_havespecificttl;
   bool d_fromfile;
   bool d_generateEnabled{true};
   bool d_upgradeContent;