X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=pdns%2Fserialtweaker.cc;h=094e8a8a31c8197603fb0297bd0a73f96393f00e;hb=876dd46192156ebb5c8d34d007d73479ad2a7802;hp=f55b5b6880659986bc3dde555c2c035707ace937;hpb=1e519c89e277c51500839117ccd3c0069fe7f756;p=thirdparty%2Fpdns.git diff --git a/pdns/serialtweaker.cc b/pdns/serialtweaker.cc index f55b5b6880..094e8a8a31 100644 --- a/pdns/serialtweaker.cc +++ b/pdns/serialtweaker.cc @@ -27,7 +27,6 @@ #include "dnspacket.hh" #include "namespaces.hh" - uint32_t localtime_format_YYYYMMDDSS(time_t t, uint32_t seq) { struct tm tm; @@ -39,135 +38,121 @@ uint32_t localtime_format_YYYYMMDDSS(time_t t, uint32_t seq) + seq; } -bool editSOA(DNSSECKeeper& dk, const DNSName& qname, DNSPacket* dp) -{ - for(auto& rr : dp->getRRS()) { - if(rr.dr.d_type == QType::SOA && rr.dr.d_name == qname) { - string kind; - dk.getSoaEdit(qname, kind); - return editSOARecord(rr, kind); - } - } - return false; -} - -bool editSOARecord(DNSZoneRecord& rr, const string& kind) { - if(kind.empty()) - return false; - auto src = getRR(rr.dr); - src->d_st.serial=calculateEditSOA(rr, kind); - - return true; -} - -uint32_t calculateEditSOA(const DNSZoneRecord& rr, const string& kind) +uint32_t calculateEditSOA(uint32_t old_serial, const string& kind, const DNSName& zonename) { - auto src = getRR(rr.dr); - if(pdns_iequals(kind,"INCEPTION")) { - L<d_st.serial < inception_serial - 1) { /* less than 00 */ + if(old_serial < inception_serial - 1) { /* less than 00 */ return inception_serial; /* return 01 (skipping 00 as possible value) */ - } else if(src->d_st.serial <= dont_increment_after) { /* >= 00 but <= 99 */ - return (src->d_st.serial + 2); /* "00" and "01" are reserved for inception increasing, so increment sd.serial by two */ + } else if (old_serial < inception_serial+1) { + /* "00" and "01" are reserved for inception increasing, so jump to "02" */ + return inception_serial+1; + } else if(old_serial <= dont_increment_after) { /* >= 00 but <= 99 */ + return old_serial + 1; } } - else if(pdns_iequals(kind,"INCEPTION-WEEK")) { - L<d_st.serial + (inception / (7*86400))); + return (old_serial + (inception / (7*86400))); } else if(pdns_iequals(kind,"EPOCH")) { - L<d_st.serial < inception) + if (old_serial < inception) return inception; - } else if(!kind.empty()) { - L<d_st.serial; + else if(pdns_iequals(kind,"NONE")) { + // do nothing to serial. needed because a metadata of "" will use the default-soa-edit setting instead. + } + else if(!kind.empty()) { + g_log<(sd.nameserver, sd.hostmaster, st); - return calculateEditSOA(dzr, kind); +uint32_t calculateEditSOA(uint32_t old_serial, DNSSECKeeper& dk, const DNSName& zonename) { + string kind; + dk.getSoaEdit(zonename, kind); + return calculateEditSOA(old_serial, kind, zonename); } -// Used for SOA-EDIT-DNSUPDATE and SOA-EDIT-API. -uint32_t calculateIncreaseSOA(DNSZoneRecord& dzr, const string& increaseKind, const string& editKind) { - auto src = getRR(dzr.dr); - // These only work when SOA-EDIT is set, otherwise fall back to default. - if (!editKind.empty()) { - if (pdns_iequals(increaseKind, "SOA-EDIT-INCREASE")) { - uint32_t new_serial = calculateEditSOA(dzr, editKind); - if (new_serial <= src->d_st.serial) { - new_serial = src->d_st.serial + 1; - } - return new_serial; +/** Used for SOA-EDIT-DNSUPDATE and SOA-EDIT-API. */ +static uint32_t calculateIncreaseSOA(uint32_t old_serial, const string& increaseKind, const string& editKind, const DNSName& zonename) { + if (pdns_iequals(increaseKind, "SOA-EDIT-INCREASE")) { + uint32_t new_serial = old_serial; + if (!editKind.empty()) { + new_serial = calculateEditSOA(old_serial, editKind, zonename); } - else if (pdns_iequals(increaseKind, "SOA-EDIT")) { - return calculateEditSOA(dzr, editKind); + if (new_serial <= old_serial) { + new_serial = old_serial + 1; } + return new_serial; } - - if (pdns_iequals(increaseKind, "INCREASE")) { - return src->d_st.serial + 1; + else if (pdns_iequals(increaseKind, "SOA-EDIT")) { + return calculateEditSOA(old_serial, editKind, zonename); + } + else if (pdns_iequals(increaseKind, "INCREASE")) { + return old_serial + 1; } else if (pdns_iequals(increaseKind, "EPOCH")) { return time(0); } - - // DEFAULT case - time_t now = time(0); - struct tm tm; - localtime_r(&now, &tm); - boost::format fmt("%04d%02d%02d%02d"); - string newdate = (fmt % (tm.tm_year + 1900) % (tm.tm_mon + 1) % tm.tm_mday % 1).str(); - uint32_t new_serial = pdns_stou(newdate); - if (new_serial <= src->d_st.serial) { - new_serial = src->d_st.serial + 1; + else if (pdns_iequals(increaseKind, "DEFAULT")) { + time_t now = time(0); + uint32_t new_serial = localtime_format_YYYYMMDDSS(now, 1); + if (new_serial <= old_serial) { + new_serial = old_serial + 1; + } + return new_serial; + } else if(!increaseKind.empty()) { + g_log<(sd.nameserver, sd.hostmaster, st); - return calculateIncreaseSOA(dzr, increaseKind, editKind); -} - - - +/** Used for SOA-EDIT-DNSUPDATE and SOA-EDIT-API. + * Good if you already *have* a DNSResourceRecord. + * Content in rr is suitable for writing into a backend. + * + * @return true if changes may have been made + */ bool increaseSOARecord(DNSResourceRecord& rr, const string& increaseKind, const string& editKind) { if (increaseKind.empty()) return false; SOAData sd; fillSOAData(rr.content, sd); - sd.serial = calculateIncreaseSOA(sd, increaseKind, editKind); - rr.content = serializeSOAData(sd); + + sd.serial = calculateIncreaseSOA(sd.serial, increaseKind, editKind, rr.qname); + rr.content = makeSOAContent(sd)->getZoneRepresentation(true); + return true; +} + +/** Used for SOA-EDIT-DNSUPDATE and SOA-EDIT-API. + * Makes a mostly reset DNSResourceRecord for you in @param rrout. + * Content in rrout is suitable for writing into a backend. + * + * @return true if rrout is now valid + */ +bool makeIncreasedSOARecord(SOAData& sd, const string& increaseKind, const string& editKind, DNSResourceRecord& rrout) { + if (increaseKind.empty()) + return false; + + sd.serial = calculateIncreaseSOA(sd.serial, increaseKind, editKind, sd.qname); + rrout.qname = sd.qname; + rrout.content = makeSOAContent(sd)->getZoneRepresentation(true); + rrout.qtype = QType::SOA; + rrout.domain_id = sd.domain_id; + rrout.auth = 1; + rrout.ttl = sd.ttl; + return true; }