diff --git a/proto/rpki/packets.c b/proto/rpki/packets.c index 60ca3936..59a5efaf 100644 --- a/proto/rpki/packets.c +++ b/proto/rpki/packets.c @@ -554,9 +554,9 @@ rpki_check_receive_packet(struct rpki_cache *cache, const struct pdu_header *pdu * (https://tools.ietf.org/html/draft-ietf-sidr-rpki-rtr-rfc6810-bis-07#section-7) */ } - else if (cache->last_update == 0 - && pdu->ver <= RPKI_MAX_VERSION - && pdu->ver < cache->version) + else if (!cache->last_update && + (pdu->ver <= RPKI_MAX_VERSION) && + (pdu->ver < cache->version)) { CACHE_TRACE(D_EVENTS, cache, "Downgrade session to %s from %u to %u version", rpki_get_cache_ident(cache), cache->version, pdu->ver); cache->version = pdu->ver; @@ -652,7 +652,7 @@ rpki_handle_cache_response_pdu(struct rpki_cache *cache, const struct pdu_cache_ { if (cache->request_session_id) { - if (cache->last_update != 0) + if (cache->last_update) { /* * This isn't the first sync and we already received records. This point @@ -748,7 +748,7 @@ rpki_handle_prefix_pdu(struct rpki_cache *cache, const struct pdu_header *pdu) return RPKI_ERROR; } - cache->last_rx_prefix = now; + cache->last_rx_prefix = current_time(); /* A place for 'flags' is same for both data structures pdu_ipv4 or pdu_ipv6 */ struct pdu_ipv4 *pfx = (void *) pdu; @@ -814,7 +814,7 @@ rpki_handle_end_of_data_pdu(struct rpki_cache *cache, const struct pdu_end_of_da rt_refresh_end(cache->p->roa6_channel->table, cache->p->roa6_channel); } - cache->last_update = now; + cache->last_update = current_time(); cache->serial_num = pdu->serial_num; rpki_cache_change_state(cache, RPKI_CS_ESTABLISHED); } diff --git a/proto/rpki/rpki.c b/proto/rpki/rpki.c index 7930363f..cddbf017 100644 --- a/proto/rpki/rpki.c +++ b/proto/rpki/rpki.c @@ -318,59 +318,60 @@ rpki_cache_change_state(struct rpki_cache *cache, const enum rpki_cache_state ne static void rpki_schedule_next_refresh(struct rpki_cache *cache) { - uint time_to_wait = cache->refresh_interval; + btime t = (btime) cache->refresh_interval S; - CACHE_DBG(cache, "after %u seconds", time_to_wait); - tm_start(cache->refresh_timer, time_to_wait); + CACHE_DBG(cache, "after %t s", t); + tm2_start(cache->refresh_timer, t); } static void rpki_schedule_next_retry(struct rpki_cache *cache) { - uint time_to_wait = cache->retry_interval; + btime t = (btime) cache->retry_interval S; - CACHE_DBG(cache, "after %u seconds", time_to_wait); - tm_start(cache->retry_timer, time_to_wait); + CACHE_DBG(cache, "after %t s", t); + tm2_start(cache->retry_timer, t); } static void rpki_schedule_next_expire_check(struct rpki_cache *cache) { /* A minimum time to wait is 1 second */ - uint time_to_wait = MAX(((int)cache->expire_interval - (int)(now - cache->last_update)), 1); + btime t = cache->last_update + (btime) cache->expire_interval S - current_time(); + t = MAX(t, 1 S); - CACHE_DBG(cache, "after %u seconds", time_to_wait); - tm_start(cache->expire_timer, time_to_wait); + CACHE_DBG(cache, "after %t s", t); + tm2_start(cache->expire_timer, t); } static void rpki_stop_refresh_timer_event(struct rpki_cache *cache) { CACHE_DBG(cache, "Stop"); - tm_stop(cache->refresh_timer); + tm2_stop(cache->refresh_timer); } static void rpki_stop_retry_timer_event(struct rpki_cache *cache) { CACHE_DBG(cache, "Stop"); - tm_stop(cache->retry_timer); + tm2_stop(cache->retry_timer); } static void UNUSED rpki_stop_expire_timer_event(struct rpki_cache *cache) { CACHE_DBG(cache, "Stop"); - tm_stop(cache->expire_timer); + tm2_stop(cache->expire_timer); } static int rpki_do_we_recv_prefix_pdu_in_last_seconds(struct rpki_cache *cache) { - if (cache->last_rx_prefix == 0) + if (!cache->last_rx_prefix) return 0; - return ((now - cache->last_rx_prefix) <= 2); + return ((current_time() - cache->last_rx_prefix) <= 2 S); } /** @@ -477,19 +478,20 @@ rpki_expire_hook(timer *tm) { struct rpki_cache *cache = tm->data; - if (cache->last_update == 0) + if (!cache->last_update) return; CACHE_DBG(cache, "%s", rpki_cache_state_to_str(cache->state)); - if ((cache->last_update + cache->expire_interval) < now) + btime t = cache->last_update + (btime) cache->expire_interval S - current_time(); + if (t <= 0) { CACHE_TRACE(D_EVENTS, cache, "All ROAs expired"); rpki_force_restart_proto(cache->p); } else { - CACHE_DBG(cache, "Remains %d seconds to become ROAs obsolete", (int)cache->expire_interval - (int)(now - cache->last_update)); + CACHE_DBG(cache, "Remains %t seconds to become ROAs obsolete", t); rpki_schedule_next_expire_check(cache); } } @@ -567,9 +569,9 @@ rpki_init_cache(struct rpki_proto *p, struct rpki_config *cf) cache->refresh_interval = cf->refresh_interval; cache->retry_interval = cf->retry_interval; cache->expire_interval = cf->expire_interval; - cache->refresh_timer = tm_new_set(pool, &rpki_refresh_hook, cache, 0, 0); - cache->retry_timer = tm_new_set(pool, &rpki_retry_hook, cache, 0, 0); - cache->expire_timer = tm_new_set(pool, &rpki_expire_hook, cache, 0, 0); + cache->refresh_timer = tm2_new_init(pool, &rpki_refresh_hook, cache, 0, 0); + cache->retry_timer = tm2_new_init(pool, &rpki_retry_hook, cache, 0, 0); + cache->expire_timer = tm2_new_init(pool, &rpki_expire_hook, cache, 0, 0); cache->tr_sock = mb_allocz(pool, sizeof(struct rpki_tr_sock)); cache->tr_sock->cache = cache; @@ -789,7 +791,7 @@ rpki_get_status(struct proto *P, byte *buf) static void rpki_show_proto_info_timer(const char *name, uint num, timer *t) { - if (tm_active(t)) + if (tm2_active(t)) cli_msg(-1006, " %-16s: %t/%u", name, tm2_remains(t), num); else cli_msg(-1006, " %-16s: ---", name); @@ -828,7 +830,7 @@ rpki_show_proto_info(struct proto *P) if (cache->last_update) { cli_msg(-1006, " Serial number: %u", cache->serial_num); - cli_msg(-1006, " Last update: before %us", now - cache->last_update); + cli_msg(-1006, " Last update: before %t s", current_time() - cache->last_update); } else { diff --git a/proto/rpki/rpki.h b/proto/rpki/rpki.h index 80ef83df..8972b33a 100644 --- a/proto/rpki/rpki.h +++ b/proto/rpki/rpki.h @@ -60,11 +60,11 @@ struct rpki_cache { u8 request_session_id; /* 1: have to request new session id; 0: we have already received session id */ u32 serial_num; /* Serial number denotes the logical version of data from cache server */ u8 version; /* Protocol version */ - bird_clock_t last_update; /* Last successful synchronization with cache server */ - bird_clock_t last_rx_prefix; /* Last received prefix PDU */ + btime last_update; /* Last successful synchronization with cache server */ + btime last_rx_prefix; /* Last received prefix PDU */ /* Intervals can be changed by cache server on the fly */ - u32 refresh_interval; /* Actual refresh interval */ + u32 refresh_interval; /* Actual refresh interval (in seconds) */ u32 retry_interval; u32 expire_interval; timer *retry_timer; /* Retry timer event */