Permalink
Browse files

add SOA-EDIT INCEPTION-INCREMENT mode

  • Loading branch information...
1 parent 121a528 commit 6ca3fa73ddc6711b8f456f4daa68cd4ed1f79195 @stbuehler stbuehler committed May 11, 2013
Showing with 46 additions and 15 deletions.
  1. +11 −0 pdns/docs/pdns.xml
  2. +35 −15 pdns/serialtweaker.cc
View
@@ -12665,6 +12665,17 @@ sql> insert into domainmetadata (domain_id, kind, content) values (7,'ALLOW-AXFR
</listitem>
</varlistentry>
<varlistentry>
+ <term>INCEPTION-INCREMENT (available since 3.3)</term>
+ <listitem>
+ <para>
+ Uses YYYYMMDDSS format for SOA serial numbers. If the SOA serial from the backend is within two days after inception, it gets incremented by two (the backend should keep SS below 98). Otherwise it uses the maximum of the backend SOA serial number and inception time in YYYYMMDD01 format.
+ </para>
+ <para>
+ This requires your backend zone to use YYYYMMDDSS as SOA serial format. Uses localtime to find the day for inception time.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
<term>INCEPTION (not recommended)</term>
<listitem>
<para>
View
@@ -3,7 +3,7 @@
Copyright (C) 2002-2011 PowerDNS.COM BV
This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License version 2 as
+ it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation
This program is distributed in the hope that it will be useful,
@@ -21,6 +21,17 @@
#include "namespaces.hh"
#include <boost/foreach.hpp>
+static uint32_t localtime_format_YYYYMMDDSS(time_t t, uint32_t seq)
+{
+ struct tm tm;
+ localtime_r(&t, &tm);
+ return
+ (uint32_t)(tm.tm_year+1900) * 1000000u
+ + (uint32_t)(tm.tm_mon + 1) * 10000u
+ + (uint32_t)tm.tm_mday * 100u
+ + seq;
+}
+
bool editSOA(DNSSECKeeper& dk, const string& qname, DNSPacket* dp)
{
vector<DNSResourceRecord>& rrs = dp->getRRS();
@@ -29,36 +40,45 @@ bool editSOA(DNSSECKeeper& dk, const string& qname, DNSPacket* dp)
string kind;
dk.getFromMeta(qname, "SOA-EDIT", kind);
if(kind.empty())
- return false;
+ return false;
SOAData sd;
fillSOAData(rr.content, sd);
- if(pdns_iequals(kind,"INCEPTION")) {
+ if(pdns_iequals(kind,"INCEPTION")) {
+ time_t inception = getStartOfWeek();
+ sd.serial = localtime_format_YYYYMMDDSS(inception, 1);
+ }
+ else if(pdns_iequals(kind,"INCEPTION-INCREMENT")) {
time_t inception = getStartOfWeek();
- struct tm tm;
- localtime_r(&inception, &tm);
- boost::format fmt("%04d%02d%02d%02d");
- string newserdate=(fmt % (tm.tm_year+1900) % (tm.tm_mon +1 )% tm.tm_mday % 1).str();
- sd.serial = lexical_cast<uint32_t>(newserdate);
+ uint32_t inception_serial = localtime_format_YYYYMMDDSS(inception, 1);
+ uint32_t dont_increment_after = localtime_format_YYYYMMDDSS(inception + 2*86400, 99);
+
+ if(sd.serial <= dont_increment_after) {
+ /* "day00" and "day01" are reserved for inception increasing, so increment sd.serial by two */
+ sd.serial += 2;
+ }
+ else if(sd.serial < inception_serial) {
+ sd.serial = inception_serial;
+ }
}
- else if(pdns_iequals(kind,"INCEPTION-WEEK")) {
+ else if(pdns_iequals(kind,"INCEPTION-WEEK")) {
time_t inception = getStartOfWeek();
sd.serial = inception / (7*86400);
}
- else if(pdns_iequals(kind,"INCREMENT-WEEKS")) {
+ else if(pdns_iequals(kind,"INCREMENT-WEEKS")) {
time_t inception = getStartOfWeek();
sd.serial += inception / (7*86400);
}
- else if(pdns_iequals(kind,"EPOCH")) {
+ else if(pdns_iequals(kind,"EPOCH")) {
sd.serial = time(0);
}
- else if(pdns_iequals(kind,"INCEPTION-EPOCH")) {
- time_t inception = getStartOfWeek();
- if (sd.serial < inception) {
+ else if(pdns_iequals(kind,"INCEPTION-EPOCH")) {
+ time_t inception = getStartOfWeek();
+ if (sd.serial < inception) {
sd.serial = inception;
}
}
- rr.content = serializeSOAData(sd);
+ rr.content = serializeSOAData(sd);
return true;
}
}

0 comments on commit 6ca3fa7

Please sign in to comment.