dateserial documentation misleading
Both the documentation and the man page contain the warning
Use dateserial only if you expect less than 100 updates per day per zone.
To me, this looks like the serial number would not reliably increment if this expectation is violated. How about combining with the paragraph above, resulting in the following:
If the serial for
unixtime
ordateserial
is lower or equal than the current zone's (this happens e.g. in case of migrating from other policy or frequent updates), the serial is incremented instead.To avoid user confusion, use
dateserial
only if you expect fewer than 100 updates per day per zone.
I would have created a merge request for that, if I could fork the repository here.
PS: I also wondered about the relatively complex code in serial.c.
I think combining serial_next()
and serial_must_increment()
into a new serial_next()
with an additional must_increment
parameter would make the serial-number related code more readable and easier to understand the interactions. must_increment
is set to 0 or 1, depending on whether the resulting serial may be identical to the current one (when adapting to a slave policy, i.e., when called from axfr_slave_sign_serial()
) or when having done a modification locally, respectively.
What do you think?
static uint32_t serial_dateserial(uint32_t current)
{
struct tm now;
time_t current_time = time(NULL);
struct tm *gmtime_result = gmtime_r(¤t_time, &now);
if (gmtime_result == NULL) {
return current;
}
return (1900 + now.tm_year) * 1000000 +
( 1 + now.tm_mon ) * 10000 +
( now.tm_mday) * 100;
}
uint32_t serial_next(uint32_t current, int policy, int must_increment)
{
uint32_t minimum;
switch (policy) {
case SERIAL_POLICY_INCREMENT:
minimum = current;
break;
case SERIAL_POLICY_UNIXTIME:
minimum = time(NULL);
break;
case SERIAL_POLICY_DATESERIAL:
minimum = serial_dateserial(current);
break;
default:
assert(0);
return 0;
}
if (serial_compare(minimum, current) != SERIAL_GREATER) {
return current + must_increment;
} else {
return minimum;
}
}