Skip to content

[tools] Honour default-ttl in pdnsutil load-zone #15389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pdns/pdnsutil.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions pdns/zoneparser-tng.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ 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);
}

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();
}
Expand Down Expand Up @@ -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:;
Expand All @@ -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]));
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion pdns/zoneparser-tng.hh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public:
{
d_maxIncludes = max;
}
void setDefaultTTL(int ttl)
{
d_defaultttl = ttl;
d_havespecificttl = true;
}
private:
bool getLine();
bool getTemplateLine();
Expand Down Expand Up @@ -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;
Expand Down