]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Adjust returned method from dns_updatemethod_date
authorMark Andrews <marka@isc.org>
Mon, 17 May 2021 03:32:26 +0000 (13:32 +1000)
committerMark Andrews <marka@isc.org>
Tue, 18 May 2021 12:30:22 +0000 (12:30 +0000)
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).

lib/dns/tests/update_test.c
lib/dns/update.c

index 8036229a949ac859e97b91db58e7527d266e2584..ae7baf3871b7eae979ee67441b9a587a49d2d671 100644 (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
index 6b8b868b99ea3ed59c3a36f0417c782e45543fe5..6bd84823e24bec89ff879b73f317fc269c52fece 100644 (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: