diff options
author | Kazuki Yamaguchi <k@rhe.jp> | 2023-10-11 17:57:54 +0900 |
---|---|---|
committer | Kazuki Yamaguchi <k@rhe.jp> | 2023-10-11 17:57:54 +0900 |
commit | 984fe10a607fa4948567ff90c0faa92f93552273 (patch) | |
tree | bd67a6c91bf5cde35a09470c56def171aec2a614 | |
parent | 62002560f83b2a4af7b4e973b268bf59be3b087a (diff) | |
parent | 9e4df80dcb15325ac715c834a334418e4fad43ea (diff) | |
download | bird-984fe10a607fa4948567ff90c0faa92f93552273.tar.gz |
Merge branch 'ky/bgp-fix-timer-jitter' into pu
* ky/bgp-fix-timer-jitter:
BGP: Do not apply jitter to HoldTimer
-rw-r--r-- | proto/bgp/bgp.c | 19 | ||||
-rw-r--r-- | proto/bgp/bgp.h | 2 | ||||
-rw-r--r-- | proto/bgp/packets.c | 8 |
3 files changed, 16 insertions, 13 deletions
diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index f8146bdf..c25d02e0 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -312,7 +312,7 @@ bgp_initiate(struct bgp_proto *p) { p->start_state = BSS_DELAY; BGP_TRACE(D_EVENTS, "Startup delayed by %d seconds due to errors", p->startup_delay); - bgp_start_timer(p->startup_timer, p->startup_delay); + bgp_start_timer(p->startup_timer, p->startup_delay, 1); } else bgp_startup(p); @@ -335,21 +335,24 @@ err1: * bgp_start_timer - start a BGP timer * @t: timer * @value: time (in seconds) to fire (0 to disable the timer) + * @use_randomize: the randomization procedure in RFC 4271 should be applied * * 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, uint value) +bgp_start_timer(timer *t, uint value, int use_randomize) { - if (value) + if (value && use_randomize) { /* The randomization procedure is specified in RFC 4271 section 10 */ btime time = value S; btime randomize = random() % ((time / 4) + 1); tm_start(t, time - randomize); } + else if (value) + tm_start(t, value S); else tm_stop(t); } @@ -724,7 +727,7 @@ bgp_conn_enter_close_state(struct bgp_conn *conn) conn->sk->rx_hook = NULL; /* Timeout for CLOSE state, if we cannot send notification soon then we just hangup */ - bgp_start_timer(conn->hold_timer, 10); + bgp_start_timer(conn->hold_timer, 10, 0); if (os == BS_ESTABLISHED) bgp_conn_leave_established_state(conn, p); @@ -960,7 +963,7 @@ bgp_send_open(struct bgp_conn *conn) bgp_prepare_capabilities(conn); 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); + bgp_start_timer(conn->hold_timer, conn->bgp->cf->initial_hold_time, 0); } static void @@ -1037,7 +1040,7 @@ bgp_hold_timeout(timer *t) and perhaps just not processed BGP packets in time. */ if (sk_rx_ready(conn->sk) > 0) - bgp_start_timer(conn->hold_timer, 10); + bgp_start_timer(conn->hold_timer, 10, 0); else if ((conn->state == BS_ESTABLISHED) && p->llgr_ready) { BGP_TRACE(D_EVENTS, "Hold timer expired"); @@ -1097,7 +1100,7 @@ bgp_active(struct bgp_proto *p) BGP_TRACE(D_EVENTS, "Connect delayed by %d seconds", delay); bgp_setup_conn(p, conn); bgp_conn_set_state(conn, BS_ACTIVE); - bgp_start_timer(conn->connect_timer, delay); + bgp_start_timer(conn->connect_timer, delay, 1); } /** @@ -1145,7 +1148,7 @@ bgp_connect(struct bgp_proto *p) /* Enter Connect state and start establishing c goto err; DBG("BGP: Waiting for connect success\n"); - bgp_start_timer(conn->connect_timer, p->cf->connect_retry_time); + bgp_start_timer(conn->connect_timer, p->cf->connect_retry_time, 1); return; err: diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h index 2e95037c..e23e5de2 100644 --- a/proto/bgp/bgp.h +++ b/proto/bgp/bgp.h @@ -540,7 +540,7 @@ bgp_parse_error(struct bgp_parse_state *s, uint subcode) } -void bgp_start_timer(timer *t, uint value); +void bgp_start_timer(timer *t, uint value, int use_randomize); 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); diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index b7df5a7a..3e025a7b 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -989,7 +989,7 @@ bgp_rx_open(struct bgp_conn *conn, byte *pkt, uint len) conn->hold_time, conn->keepalive_time, p->remote_as, p->remote_id, conn->as4_session); bgp_schedule_packet(conn, NULL, PKT_KEEPALIVE); - bgp_start_timer(conn->hold_timer, conn->hold_time); + bgp_start_timer(conn->hold_timer, conn->hold_time, 0); bgp_conn_enter_openconfirm_state(conn); } @@ -2717,7 +2717,7 @@ bgp_rx_update(struct bgp_conn *conn, byte *pkt, uint len) if (conn->state != BS_ESTABLISHED) { bgp_error(conn, 5, fsm_err_subcode[conn->state], NULL, 0); return; } - bgp_start_timer(conn->hold_timer, conn->hold_time); + bgp_start_timer(conn->hold_timer, conn->hold_time, 0); struct lp_state tmpp; lp_save(tmp_linpool, &tmpp); @@ -3061,7 +3061,7 @@ bgp_fire_tx(struct bgp_conn *conn) { conn->packets_to_send &= ~(1 << PKT_KEEPALIVE); BGP_TRACE(D_PACKETS, "Sending KEEPALIVE"); - bgp_start_timer(conn->keepalive_timer, conn->keepalive_time); + bgp_start_timer(conn->keepalive_timer, conn->keepalive_time, 1); return bgp_send(conn, PKT_KEEPALIVE, BGP_HEADER_LENGTH); } else while (conn->channels_to_send) @@ -3367,7 +3367,7 @@ bgp_rx_keepalive(struct bgp_conn *conn) struct bgp_proto *p = conn->bgp; BGP_TRACE(D_PACKETS, "Got KEEPALIVE"); - bgp_start_timer(conn->hold_timer, conn->hold_time); + bgp_start_timer(conn->hold_timer, conn->hold_time, 0); if (conn->state == BS_OPENCONFIRM) { bgp_conn_enter_established_state(conn); return; } |