diff options
Diffstat (limited to 'proto/bgp')
-rw-r--r-- | proto/bgp/bgp.c | 44 | ||||
-rw-r--r-- | proto/bgp/bgp.h | 7 |
2 files changed, 24 insertions, 27 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)); } diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h index 3b38c05f..3d940c22 100644 --- a/proto/bgp/bgp.h +++ b/proto/bgp/bgp.h @@ -108,6 +108,7 @@ struct bgp_config { int allow_local_pref; /* Allow LOCAL_PREF in EBGP sessions */ int gr_mode; /* Graceful restart mode (BGP_GR_*) */ int setkey; /* Set MD5 password to system SA/SP database */ + /* Times below are in seconds */ unsigned gr_time; /* Graceful restart timeout */ unsigned connect_delay_time; /* Minimum delay between connect attempts */ unsigned connect_retry_time; /* Timeout for connect attempts */ @@ -257,8 +258,8 @@ struct bgp_proto { event *event; /* Event for respawning and shutting process */ timer *startup_timer; /* Timer used to delay protocol startup due to previous errors (startup_delay) */ timer *gr_timer; /* Timer waiting for reestablishment after graceful restart */ - unsigned startup_delay; /* Time to delay protocol startup by due to errors */ - bird_clock_t last_proto_error; /* Time of last error that leads to protocol stop */ + uint startup_delay; /* Delay (in seconds) of protocol startup due to previous errors */ + btime last_proto_error; /* Time of last error that leads to protocol stop */ u8 last_error_class; /* Error class of last error */ u32 last_error_code; /* Error code of last error. BGP protocol errors are encoded as (bgp_err_code << 16 | bgp_err_subcode) */ @@ -422,7 +423,7 @@ extern struct linpool *bgp_linpool; extern struct linpool *bgp_linpool2; -void bgp_start_timer(timer *t, int value); +void bgp_start_timer(timer *t, uint value); void bgp_check_config(struct bgp_config *c); void bgp_error(struct bgp_conn *c, unsigned code, unsigned subcode, byte *data, int len); void bgp_close_conn(struct bgp_conn *c); |