Commit fd346d4b authored by Wolfgang Jung's avatar Wolfgang Jung Committed by Daniel Salzman

config: add rfc1912 dateserial policy

close #582
parent 0b2887a5
...@@ -79,3 +79,8 @@ version.h ...@@ -79,3 +79,8 @@ version.h
# Vagrant # Vagrant
.vagrant .vagrant
# eclipse
/.project
/.cproject
/.settings/
\ No newline at end of file
Knot DNS 2.7.0 (2018-xx-xx)
===========================
Features:
---------
- New zone serial policy DATESERIAL: yyyyMMDDvv (Thanks to Wolfgang Jung)
Knot DNS 2.6.0 (2017-09-29) Knot DNS 2.6.0 (2017-09-29)
=========================== ===========================
......
...@@ -983,7 +983,7 @@ zone: ...@@ -983,7 +983,7 @@ zone:
dnssec\-signing: BOOL dnssec\-signing: BOOL
dnssec\-policy: STR dnssec\-policy: STR
request\-edns\-option: INT:[HEXSTR] request\-edns\-option: INT:[HEXSTR]
serial\-policy: increment | unixtime serial\-policy: increment | unixtime | dateserial
min\-refresh\-interval: TIME min\-refresh\-interval: TIME
max\-refresh\-interval: TIME max\-refresh\-interval: TIME
module: STR/STR ... module: STR/STR ...
...@@ -1219,6 +1219,12 @@ Possible values: ...@@ -1219,6 +1219,12 @@ Possible values:
\fBincrement\fP – The serial is incremented according to serial number arithmetic \fBincrement\fP – The serial is incremented according to serial number arithmetic
.IP \(bu 2 .IP \(bu 2
\fBunixtime\fP – The serial is set to the current unix time \fBunixtime\fP – The serial is set to the current unix time
.IP \(bu 2
.INDENT 2.0
.TP
\fBdateserial\fP – The 10\-digit serial (YYYYMMDDnn) is incremented, the first
8 digits match the current iso\-date
.UNINDENT
.UNINDENT .UNINDENT
.sp .sp
\fBNOTE:\fP \fBNOTE:\fP
...@@ -1228,6 +1234,8 @@ If your serial was in other than unix time format, be careful ...@@ -1228,6 +1234,8 @@ If your serial was in other than unix time format, be careful
with the transition to unix time. It may happen that the new serial will with the transition to unix time. It may happen that the new serial will
be \(aqlower\(aq than the old one. If this is the case, the transition should be be \(aqlower\(aq than the old one. If this is the case, the transition should be
done by hand (\fI\%RFC 1982\fP). done by hand (\fI\%RFC 1982\fP).
.sp
Use dateserial only if you expect less than 100 updates per day per zone.
.UNINDENT .UNINDENT
.UNINDENT .UNINDENT
.sp .sp
......
...@@ -1110,7 +1110,7 @@ Definition of zones served by the server. ...@@ -1110,7 +1110,7 @@ Definition of zones served by the server.
dnssec-signing: BOOL dnssec-signing: BOOL
dnssec-policy: STR dnssec-policy: STR
request-edns-option: INT:[HEXSTR] request-edns-option: INT:[HEXSTR]
serial-policy: increment | unixtime serial-policy: increment | unixtime | dateserial
min-refresh-interval: TIME min-refresh-interval: TIME
max-refresh-interval: TIME max-refresh-interval: TIME
module: STR/STR ... module: STR/STR ...
...@@ -1382,6 +1382,8 @@ Possible values: ...@@ -1382,6 +1382,8 @@ Possible values:
- ``increment`` – The serial is incremented according to serial number arithmetic - ``increment`` – The serial is incremented according to serial number arithmetic
- ``unixtime`` – The serial is set to the current unix time - ``unixtime`` – The serial is set to the current unix time
- ``dateserial`` – The 10-digit serial (YYYYMMDDnn) is incremented, the first
8 digits match the current iso-date
.. NOTE:: .. NOTE::
If your serial was in other than unix time format, be careful If your serial was in other than unix time format, be careful
...@@ -1389,6 +1391,8 @@ Possible values: ...@@ -1389,6 +1391,8 @@ Possible values:
be \'lower\' than the old one. If this is the case, the transition should be be \'lower\' than the old one. If this is the case, the transition should be
done by hand (:rfc:`1982`). done by hand (:rfc:`1982`).
Use dateserial only if you expect less than 100 updates per day per zone.
*Default:* increment *Default:* increment
.. _zone_min-refresh-interval: .. _zone_min-refresh-interval:
......
...@@ -87,8 +87,9 @@ const knot_lookup_t acl_actions[] = { ...@@ -87,8 +87,9 @@ const knot_lookup_t acl_actions[] = {
}; };
static const knot_lookup_t serial_policies[] = { static const knot_lookup_t serial_policies[] = {
{ SERIAL_POLICY_INCREMENT, "increment" }, { SERIAL_POLICY_INCREMENT, "increment" },
{ SERIAL_POLICY_UNIXTIME, "unixtime" }, { SERIAL_POLICY_UNIXTIME, "unixtime" },
{ SERIAL_POLICY_DATESERIAL, "dateserial" },
{ 0, NULL } { 0, NULL }
}; };
......
...@@ -129,8 +129,9 @@ enum { ...@@ -129,8 +129,9 @@ enum {
}; };
enum { enum {
SERIAL_POLICY_INCREMENT = 1, SERIAL_POLICY_INCREMENT = 1,
SERIAL_POLICY_UNIXTIME = 2, SERIAL_POLICY_UNIXTIME = 2,
SERIAL_POLICY_DATESERIAL = 3,
}; };
enum { enum {
......
...@@ -35,6 +35,28 @@ serial_cmp_result_t serial_compare(uint32_t s1, uint32_t s2) ...@@ -35,6 +35,28 @@ serial_cmp_result_t serial_compare(uint32_t s1, uint32_t s2)
return diffbrief2result[diffbrief]; return diffbrief2result[diffbrief];
} }
static uint32_t serial_next_date(uint32_t current)
{
uint32_t next = current + 1;
struct tm now;
time_t current_time = time(NULL);
struct tm *gmtime_result = gmtime_r(&current_time, &now);
if (gmtime_result == NULL) {
return next;
}
uint32_t yyyyMMdd00 = (1900 + now.tm_year) * 1000000 +
( 1 + now.tm_mon ) * 10000 +
( now.tm_mday) * 100;
if (next < yyyyMMdd00) {
next = yyyyMMdd00;
}
return next;
}
uint32_t serial_next(uint32_t current, int policy) uint32_t serial_next(uint32_t current, int policy)
{ {
switch (policy) { switch (policy) {
...@@ -42,6 +64,8 @@ uint32_t serial_next(uint32_t current, int policy) ...@@ -42,6 +64,8 @@ uint32_t serial_next(uint32_t current, int policy)
return current + 1; return current + 1;
case SERIAL_POLICY_UNIXTIME: case SERIAL_POLICY_UNIXTIME:
return time(NULL); return time(NULL);
case SERIAL_POLICY_DATESERIAL:
return serial_next_date(current);
default: default:
assert(0); assert(0);
return 0; return 0;
......
...@@ -47,7 +47,8 @@ inline static bool serial_equal(uint32_t a, uint32_t b) ...@@ -47,7 +47,8 @@ inline static bool serial_equal(uint32_t a, uint32_t b)
* \brief Get next serial for given serial update policy. * \brief Get next serial for given serial update policy.
* *
* \param current Current SOA serial. * \param current Current SOA serial.
* \param policy SERIAL_POLICY_INCREMENT or SERIAL_POLICY_UNIXTIME. * \param policy SERIAL_POLICY_INCREMENT, SERIAL_POLICY_UNIXTIME or
* SERIAL_POLICY_DATESERIAL.
* *
* \return New serial. * \return New serial.
*/ */
......
/* Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> /* Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -14,10 +14,14 @@ ...@@ -14,10 +14,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <assert.h>
#include <tap/basic.h> #include <tap/basic.h>
#include <stdlib.h> #include <stdlib.h>
#include <time.h>
#include "knot/zone/serial.h" #include "knot/zone/serial.h"
#include "knot/conf/schema.h"
#include "contrib/strtonum.h"
enum serials { enum serials {
S_LOWEST = 0, // lowest value S_LOWEST = 0, // lowest value
...@@ -38,9 +42,36 @@ static uint32_t random_serial(void) ...@@ -38,9 +42,36 @@ static uint32_t random_serial(void)
return s; return s;
} }
static void check_dateserial(uint32_t current, uint32_t expected, const char *msg)
{
uint32_t next = serial_next(current, SERIAL_POLICY_DATESERIAL);
ok(next == expected, "dateserial: %s", msg);
}
static void test_dateserial(void)
{
time_t now = time(NULL);
struct tm *gm_ret = gmtime(&now);
assert(gm_ret);
char str[32];
int ret = strftime(str, sizeof(str), "%Y%m%d00", gm_ret);
assert(ret > 0);
uint32_t serial0;
ret = str_to_u32(str, &serial0);
assert(ret == KNOT_EOK);
check_dateserial(2000010100, serial0, "from old date");
check_dateserial(serial0, serial0 + 1, "today's first increment");
check_dateserial(serial0 + 98, serial0 + 99, "today's last increment");
check_dateserial(2100010100, 2100010101, "from future date");
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
plan(20); plan_lazy();
/* Serial compare test. */ /* Serial compare test. */
ok(serial_compare(S_LOWEST, S_BELOW_MIDDLE) == SERIAL_LOWER, ok(serial_compare(S_LOWEST, S_BELOW_MIDDLE) == SERIAL_LOWER,
...@@ -98,5 +129,7 @@ int main(int argc, char *argv[]) ...@@ -98,5 +129,7 @@ int main(int argc, char *argv[])
ok(serial_compare(s2, s1) == SERIAL_INCOMPARABLE, ok(serial_compare(s2, s1) == SERIAL_INCOMPARABLE,
"serial compare: random opposites (s2 < s1)"); "serial compare: random opposites (s2 < s1)");
test_dateserial();
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment