0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-20 01:58:42 +00:00

RPKI: Update to new timers

This commit is contained in:
Ondrej Zajicek (work) 2017-06-14 16:32:15 +02:00
parent 21f4f0f4b0
commit d59c1a2958
3 changed files with 33 additions and 31 deletions

View File

@ -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) * (https://tools.ietf.org/html/draft-ietf-sidr-rpki-rtr-rfc6810-bis-07#section-7)
*/ */
} }
else if (cache->last_update == 0 else if (!cache->last_update &&
&& pdu->ver <= RPKI_MAX_VERSION (pdu->ver <= RPKI_MAX_VERSION) &&
&& pdu->ver < cache->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_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; 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->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 * 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; 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 */ /* A place for 'flags' is same for both data structures pdu_ipv4 or pdu_ipv6 */
struct pdu_ipv4 *pfx = (void *) pdu; 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); 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; cache->serial_num = pdu->serial_num;
rpki_cache_change_state(cache, RPKI_CS_ESTABLISHED); rpki_cache_change_state(cache, RPKI_CS_ESTABLISHED);
} }

View File

@ -318,59 +318,60 @@ rpki_cache_change_state(struct rpki_cache *cache, const enum rpki_cache_state ne
static void static void
rpki_schedule_next_refresh(struct rpki_cache *cache) 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); CACHE_DBG(cache, "after %t s", t);
tm_start(cache->refresh_timer, time_to_wait); tm2_start(cache->refresh_timer, t);
} }
static void static void
rpki_schedule_next_retry(struct rpki_cache *cache) 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); CACHE_DBG(cache, "after %t s", t);
tm_start(cache->retry_timer, time_to_wait); tm2_start(cache->retry_timer, t);
} }
static void static void
rpki_schedule_next_expire_check(struct rpki_cache *cache) rpki_schedule_next_expire_check(struct rpki_cache *cache)
{ {
/* A minimum time to wait is 1 second */ /* 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); CACHE_DBG(cache, "after %t s", t);
tm_start(cache->expire_timer, time_to_wait); tm2_start(cache->expire_timer, t);
} }
static void static void
rpki_stop_refresh_timer_event(struct rpki_cache *cache) rpki_stop_refresh_timer_event(struct rpki_cache *cache)
{ {
CACHE_DBG(cache, "Stop"); CACHE_DBG(cache, "Stop");
tm_stop(cache->refresh_timer); tm2_stop(cache->refresh_timer);
} }
static void static void
rpki_stop_retry_timer_event(struct rpki_cache *cache) rpki_stop_retry_timer_event(struct rpki_cache *cache)
{ {
CACHE_DBG(cache, "Stop"); CACHE_DBG(cache, "Stop");
tm_stop(cache->retry_timer); tm2_stop(cache->retry_timer);
} }
static void UNUSED static void UNUSED
rpki_stop_expire_timer_event(struct rpki_cache *cache) rpki_stop_expire_timer_event(struct rpki_cache *cache)
{ {
CACHE_DBG(cache, "Stop"); CACHE_DBG(cache, "Stop");
tm_stop(cache->expire_timer); tm2_stop(cache->expire_timer);
} }
static int static int
rpki_do_we_recv_prefix_pdu_in_last_seconds(struct rpki_cache *cache) 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 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; struct rpki_cache *cache = tm->data;
if (cache->last_update == 0) if (!cache->last_update)
return; return;
CACHE_DBG(cache, "%s", rpki_cache_state_to_str(cache->state)); 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"); CACHE_TRACE(D_EVENTS, cache, "All ROAs expired");
rpki_force_restart_proto(cache->p); rpki_force_restart_proto(cache->p);
} }
else 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); 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->refresh_interval = cf->refresh_interval;
cache->retry_interval = cf->retry_interval; cache->retry_interval = cf->retry_interval;
cache->expire_interval = cf->expire_interval; cache->expire_interval = cf->expire_interval;
cache->refresh_timer = tm_new_set(pool, &rpki_refresh_hook, cache, 0, 0); cache->refresh_timer = tm2_new_init(pool, &rpki_refresh_hook, cache, 0, 0);
cache->retry_timer = tm_new_set(pool, &rpki_retry_hook, cache, 0, 0); cache->retry_timer = tm2_new_init(pool, &rpki_retry_hook, cache, 0, 0);
cache->expire_timer = tm_new_set(pool, &rpki_expire_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 = mb_allocz(pool, sizeof(struct rpki_tr_sock));
cache->tr_sock->cache = cache; cache->tr_sock->cache = cache;
@ -789,7 +791,7 @@ rpki_get_status(struct proto *P, byte *buf)
static void static void
rpki_show_proto_info_timer(const char *name, uint num, timer *t) 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); cli_msg(-1006, " %-16s: %t/%u", name, tm2_remains(t), num);
else else
cli_msg(-1006, " %-16s: ---", name); cli_msg(-1006, " %-16s: ---", name);
@ -828,7 +830,7 @@ rpki_show_proto_info(struct proto *P)
if (cache->last_update) if (cache->last_update)
{ {
cli_msg(-1006, " Serial number: %u", cache->serial_num); 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 else
{ {

View File

@ -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 */ 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 */ u32 serial_num; /* Serial number denotes the logical version of data from cache server */
u8 version; /* Protocol version */ u8 version; /* Protocol version */
bird_clock_t last_update; /* Last successful synchronization with cache server */ btime last_update; /* Last successful synchronization with cache server */
bird_clock_t last_rx_prefix; /* Last received prefix PDU */ btime last_rx_prefix; /* Last received prefix PDU */
/* Intervals can be changed by cache server on the fly */ /* 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 retry_interval;
u32 expire_interval; u32 expire_interval;
timer *retry_timer; /* Retry timer event */ timer *retry_timer; /* Retry timer event */