From 27850a5ad236650dfde77ffa1f4f3015e8ec830a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Fri, 11 Mar 2022 22:34:45 +0100 Subject: [PATCH] Change isc_timer_reset() usage to never use expires argument 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 | 47 +++++++++++++++++++++++++++------------------- lib/dns/zone.c | 20 +++++++++++++++++--- lib/isc/timer.c | 4 ++-- 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index a81e4285ef..1f1b5efad9 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -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 diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 304bfb5a32..4d2178e66e 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -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", diff --git a/lib/isc/timer.c b/lib/isc/timer.c index 17322b2e44..ae6d20552a 100644 --- a/lib/isc/timer.c +++ b/lib/isc/timer.c @@ -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;