Adjust returned method from dns_updatemethod_date

if dns_updatemethod_date is used do that the returned method is only
set to dns_updatemethod_increment if the new serial does not encode
the current day (YYYYMMDDXX).
This commit is contained in:
Mark Andrews
2021-05-17 13:32:26 +10:00
parent 3dc094c8e0
commit 5d21042ed8
2 changed files with 46 additions and 6 deletions

View File

@@ -233,6 +233,7 @@ unixtime_zero_test(void **state) {
static void
past_to_date_test(void **state) {
uint32_t old, serial;
dns_updatemethod_t used = dns_updatemethod_none;
UNUSED(state);
@@ -240,11 +241,11 @@ past_to_date_test(void **state) {
old = dns_update_soaserial(0, dns_updatemethod_date, NULL);
set_mystdtime(2014, 4, 1);
serial = dns_update_soaserial(old, dns_updatemethod_date, NULL);
serial = dns_update_soaserial(old, dns_updatemethod_date, &used);
assert_true(isc_serial_lt(old, serial));
assert_int_not_equal(serial, 0);
assert_int_equal(serial, 2014040100);
assert_int_equal(dns_updatemethod_date, used);
}
/* now to date */
@@ -252,16 +253,35 @@ static void
now_to_date_test(void **state) {
uint32_t old;
uint32_t serial;
dns_updatemethod_t used = dns_updatemethod_none;
UNUSED(state);
set_mystdtime(2014, 4, 1);
old = dns_update_soaserial(0, dns_updatemethod_date, NULL);
serial = dns_update_soaserial(old, dns_updatemethod_date, NULL);
serial = dns_update_soaserial(old, dns_updatemethod_date, &used);
assert_true(isc_serial_lt(old, serial));
assert_int_not_equal(serial, 0);
assert_int_equal(serial, 2014040101);
assert_int_equal(dns_updatemethod_date, used);
old = 2014040198;
serial = dns_update_soaserial(old, dns_updatemethod_date, &used);
assert_true(isc_serial_lt(old, serial));
assert_int_not_equal(serial, 0);
assert_int_equal(serial, 2014040199);
assert_int_equal(dns_updatemethod_date, used);
/*
* Stealing from "tomorrow".
*/
old = 2014040199;
serial = dns_update_soaserial(old, dns_updatemethod_date, &used);
assert_true(isc_serial_lt(old, serial));
assert_int_not_equal(serial, 0);
assert_int_equal(serial, 2014040200);
assert_int_equal(dns_updatemethod_increment, used);
}
/* future to date */
@@ -269,6 +289,7 @@ static void
future_to_date_test(void **state) {
uint32_t old;
uint32_t serial;
dns_updatemethod_t used = dns_updatemethod_none;
UNUSED(state);
@@ -276,10 +297,18 @@ future_to_date_test(void **state) {
old = dns_update_soaserial(0, dns_updatemethod_date, NULL);
set_mystdtime(2014, 3, 31);
serial = dns_update_soaserial(old, dns_updatemethod_date, NULL);
serial = dns_update_soaserial(old, dns_updatemethod_date, &used);
assert_true(isc_serial_lt(old, serial));
assert_int_not_equal(serial, 0);
assert_int_equal(serial, 2014040101);
assert_int_equal(dns_updatemethod_increment, used);
old = serial;
serial = dns_update_soaserial(old, dns_updatemethod_date, &used);
assert_true(isc_serial_lt(old, serial));
assert_int_not_equal(serial, 0);
assert_int_equal(serial, 2014040102);
assert_int_equal(dns_updatemethod_increment, used);
}
int

View File

@@ -2244,8 +2244,19 @@ dns_update_soaserial(uint32_t serial, dns_updatemethod_t method,
case dns_updatemethod_unixtime:
case dns_updatemethod_date:
if (!(new_serial != 0 && isc_serial_gt(new_serial, serial))) {
method = dns_updatemethod_increment;
new_serial = dns__update_soaserial(serial, method);
/*
* If the new date serial following YYYYMMDD00 is equal
* to or smaller than the current serial, but YYYYMMDD99
* would be larger, pretend we have used the
* "dns_updatemethod_date" method.
*/
if (method == dns_updatemethod_unixtime ||
!isc_serial_gt(new_serial + 99, serial))
{
method = dns_updatemethod_increment;
}
new_serial = dns__update_soaserial(
serial, dns_updatemethod_increment);
}
break;
default: