diff options
Diffstat (limited to 'proto/bgp/bgp.c')
-rw-r--r-- | proto/bgp/bgp.c | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index 9823be6b..df4c240a 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -314,23 +314,24 @@ err1: /** * bgp_start_timer - start a BGP timer * @t: timer - * @value: time to fire (0 to disable the timer) + * @value: time (in seconds) to fire (0 to disable the timer) * * This functions calls tm_start() on @t with time @value and the amount of * randomization suggested by the BGP standard. Please use it for all BGP * timers. */ void -bgp_start_timer(timer *t, int value) +bgp_start_timer(timer *t, uint value) { if (value) { - /* The randomization procedure is specified in RFC 1771: 9.2.3.3 */ - int randomize = random() % ((value / 4) + 1); - tm_start(t, value - randomize); + /* The randomization procedure is specified in RFC 4271 section 10 */ + btime time = value S; + btime randomize = random() % ((time / 4) + 1); + tm2_start(t, time - randomize); } else - tm_stop(t); + tm2_stop(t); } /** @@ -383,10 +384,10 @@ bgp_update_startup_delay(struct bgp_proto *p) DBG("BGP: Updating startup delay\n"); - if (p->last_proto_error && ((now - p->last_proto_error) >= (int) cf->error_amnesia_time)) + if (p->last_proto_error && ((current_time() - p->last_proto_error) >= cf->error_amnesia_time S)) p->startup_delay = 0; - p->last_proto_error = now; + p->last_proto_error = current_time(); if (cf->disable_after_error) { @@ -516,7 +517,7 @@ bgp_conn_enter_established_state(struct bgp_conn *conn) int peer_gr_ready = peer->gr_aware && !(peer->gr_flags & BGP_GRF_RESTART); if (p->gr_active_num) - tm_stop(p->gr_timer); + tm2_stop(p->gr_timer); /* Number of active channels */ int num = 0; @@ -615,7 +616,7 @@ bgp_conn_enter_close_state(struct bgp_conn *conn) int os = conn->state; bgp_conn_set_state(conn, BS_CLOSE); - tm_stop(conn->keepalive_timer); + tm2_stop(conn->keepalive_timer); conn->sk->rx_hook = NULL; /* Timeout for CLOSE state, if we cannot send notification soon then we just hangup */ @@ -778,7 +779,7 @@ bgp_send_open(struct bgp_conn *conn) DBG("BGP: Sending open\n"); conn->sk->rx_hook = bgp_rx; conn->sk->tx_hook = bgp_tx; - tm_stop(conn->connect_timer); + tm2_stop(conn->connect_timer); bgp_schedule_packet(conn, NULL, PKT_OPEN); bgp_conn_set_state(conn, BS_OPENSENT); bgp_start_timer(conn->hold_timer, conn->bgp->cf->initial_hold_time); @@ -887,9 +888,9 @@ bgp_setup_conn(struct bgp_proto *p, struct bgp_conn *conn) conn->last_channel = 0; conn->last_channel_count = 0; - conn->connect_timer = tm_new_set(p->p.pool, bgp_connect_timeout, conn, 0, 0); - conn->hold_timer = tm_new_set(p->p.pool, bgp_hold_timeout, conn, 0, 0); - conn->keepalive_timer = tm_new_set(p->p.pool, bgp_keepalive_timeout, conn, 0, 0); + conn->connect_timer = tm2_new_init(p->p.pool, bgp_connect_timeout, conn, 0, 0); + conn->hold_timer = tm2_new_init(p->p.pool, bgp_hold_timeout, conn, 0, 0); + conn->keepalive_timer = tm2_new_init(p->p.pool, bgp_keepalive_timeout, conn, 0, 0); conn->tx_ev = ev_new(p->p.pool); conn->tx_ev->hook = bgp_kick_tx; @@ -1302,13 +1303,8 @@ bgp_start(struct proto *P) p->event->hook = bgp_decision; p->event->data = p; - p->startup_timer = tm_new(p->p.pool); - p->startup_timer->hook = bgp_startup_timeout; - p->startup_timer->data = p; - - p->gr_timer = tm_new(p->p.pool); - p->gr_timer->hook = bgp_graceful_restart_timeout; - p->gr_timer->data = p; + p->startup_timer = tm2_new_init(p->p.pool, bgp_startup_timeout, p, 0, 0); + p->gr_timer = tm2_new_init(p->p.pool, bgp_graceful_restart_timeout, p, 0, 0); p->local_id = proto_get_router_id(P->cf); if (p->rr_client) @@ -2008,16 +2004,16 @@ bgp_show_proto_info(struct proto *P) struct bgp_conn *oc = &p->outgoing_conn; if ((p->start_state < BSS_CONNECT) && - (tm_active(p->startup_timer))) + (tm2_active(p->startup_timer))) cli_msg(-1006, " Error wait: %t/%u", tm2_remains(p->startup_timer), p->startup_delay); if ((oc->state == BS_ACTIVE) && - (tm_active(oc->connect_timer))) + (tm2_active(oc->connect_timer))) cli_msg(-1006, " Connect delay: %t/%u", tm2_remains(oc->connect_timer), p->cf->connect_delay_time); - if (p->gr_active_num && tm_active(p->gr_timer)) + if (p->gr_active_num && tm2_active(p->gr_timer)) cli_msg(-1006, " Restart timer: %t/-", tm2_remains(p->gr_timer)); } |