]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Change isc_timer_reset() usage to never use expires argument
authorOndřej Surý <ondrej@isc.org>
Fri, 11 Mar 2022 21:34:45 +0000 (22:34 +0100)
committerEvan Hunt <each@isc.org>
Mon, 14 Mar 2022 20:00:05 +0000 (13:00 -0700)
There were two places where expires argument (absolute isc_time_t value)
was being used.  Both places has been converted to use relative interval
argument in preparation of simplification and refactoring of isc_timer
API.

lib/dns/resolver.c
lib/dns/zone.c
lib/isc/timer.c

index a81e4285eff50c2a46de7c144c275d77537dffef..1f1b5efad979eb219f7aa6861f0c3cdd8dc6c67c 100644 (file)
@@ -337,7 +337,6 @@ struct fetchctx {
        isc_time_t expires;
        isc_time_t expires_try_stale;
        isc_time_t next_timeout;
-       isc_time_t final;
        isc_interval_t interval;
        dns_message_t *qmessage;
        ISC_LIST(resquery_t) queries;
@@ -1255,8 +1254,27 @@ update_edns_stats(resquery_t *query) {
  */
 static inline isc_result_t
 fctx_starttimer(fetchctx_t *fctx) {
-       return (isc_timer_reset(fctx->timer, isc_timertype_once, &fctx->final,
-                               NULL, true));
+       isc_interval_t interval;
+       isc_time_t now;
+       isc_time_t expires;
+
+       isc_interval_set(&interval, 2, 0);
+       isc_time_add(&fctx->expires, &interval, &expires);
+
+       isc_time_now(&now);
+       if (isc_time_compare(&expires, &now) <= 0) {
+               isc_interval_set(&interval, 0, 1);
+       } else {
+               isc_time_t tmp;
+               isc_interval_set(&interval, isc_time_seconds(&now),
+                                isc_time_nanoseconds(&now));
+               isc_time_subtract(&expires, &interval, &tmp);
+               isc_interval_set(&interval, isc_time_seconds(&tmp),
+                                isc_time_nanoseconds(&tmp));
+       }
+
+       return (isc_timer_reset(fctx->timer, isc_timertype_once, NULL,
+                               &interval, true));
 }
 
 static inline void
@@ -4533,6 +4551,13 @@ fctx_start(isc_task_t *task, isc_event_t *event) {
 
        UNLOCK(&res->buckets[bucketnum].lock);
 
+       /*
+        * As a backstop, we also set a timer to stop the fetch
+        * if in-band netmgr timeouts don't work. It will fire two
+        * seconds after the fetch should have finished. (This
+        * should be enough of a gap to avoid the timer firing
+        * while a response is being processed normally.)
+        */
        result = fctx_starttimer(fctx);
        if (result != ISC_R_SUCCESS) {
                fctx_done(fctx, result, __LINE__);
@@ -4836,22 +4861,6 @@ fctx_create(dns_resolver_t *res, isc_task_t *task, const dns_name_t *name,
                goto cleanup_qmessage;
        }
 
-       /*
-        * As a backstop, we also set a timer to stop the fetch
-        * if in-band netmgr timeouts don't work. It will fire two
-        * seconds after the fetch should have finished. (This
-        * should be enough of a gap to avoid the timer firing
-        * while a response is being processed normally.)
-        */
-       isc_interval_set(&interval, 2, 0);
-       iresult = isc_time_add(&fctx->expires, &interval, &fctx->final);
-       if (iresult != ISC_R_SUCCESS) {
-               UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_time_add: %s",
-                                isc_result_totext(iresult));
-               result = ISC_R_UNEXPECTED;
-               goto cleanup_qmessage;
-       }
-
        /*
         * Create an inactive timer to enforce maximum query
         * lifetime. It will be made active when the fetch is
index 304bfb5a32a74b1f9c306448ddf4c81fac3db992..4d2178e66e28cc8d2f2cdcd40b2ec11d187cc727 100644 (file)
@@ -15279,11 +15279,25 @@ zone_settimer(dns_zone_t *zone, isc_time_t *now) {
                                     isc_result_totext(result));
                }
        } else {
+               isc_interval_t interval;
                if (isc_time_compare(&next, now) <= 0) {
-                       next = *now;
+                       isc_interval_set(&interval, 0, 1);
+               } else {
+                       /*
+                        * In theory, we could just type isc_interval_t to
+                        * isc_time_t and back, but there's no such guarantee,
+                        * so a safer method is being used here.
+                        */
+                       isc_time_t tmp;
+                       isc_interval_set(&interval, isc_time_seconds(now),
+                                        isc_time_nanoseconds(now));
+                       isc_time_subtract(&next, &interval, &tmp);
+                       isc_interval_set(&interval, isc_time_seconds(&tmp),
+                                        isc_time_nanoseconds(&tmp));
                }
-               result = isc_timer_reset(zone->timer, isc_timertype_once, &next,
-                                        NULL, true);
+
+               result = isc_timer_reset(zone->timer, isc_timertype_once, NULL,
+                                        &interval, true);
                if (result != ISC_R_SUCCESS) {
                        dns_zone_log(zone, ISC_LOG_ERROR,
                                     "could not reset zone timer: %s",
index 17322b2e444f0c0429162a614c190ddfb2bfd5f6..ae6d20552a89ccab79f41c0615a56a41c0c0ec14 100644 (file)
@@ -92,7 +92,7 @@ struct isc_timermgr {
        isc_heap_t *heap;
 };
 
-static inline isc_result_t
+static isc_result_t
 schedule(isc_timer_t *timer, isc_time_t *now, bool signal_ok) {
        isc_timermgr_t *manager;
        isc_time_t due;
@@ -170,7 +170,7 @@ schedule(isc_timer_t *timer, isc_time_t *now, bool signal_ok) {
        return (ISC_R_SUCCESS);
 }
 
-static inline void
+static void
 deschedule(isc_timer_t *timer) {
        isc_timermgr_t *manager;