Skip to content

Commit

Permalink
bgpd: Implement connect retry backoff
Browse files Browse the repository at this point in the history
Instead of starting with a fairly high value of retry, let's try with a lower
and increase with a backoff to reach what was a default value (120s).

Signed-off-by: Donatas Abraitis <[email protected]>
  • Loading branch information
ton31337 committed Dec 11, 2024
1 parent 44f4a8e commit ab3535f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions bgpd/bgp_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -491,11 +491,14 @@ static void bgp_connect_timer(struct event *thread)
assert(!connection->t_read);

if (bgp_debug_neighbor_events(peer))
zlog_debug("%s [FSM] Timer (connect timer expire)", peer->host);
zlog_debug("%s [FSM] Timer (connect timer (%us) expire)", peer->host,
peer->v_connect);

if (CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER))
bgp_stop(connection);
else {
if (!peer->connect)
peer->v_connect = MIN(BGP_MAX_CONNECT_RETRY, peer->v_connect * 2);
EVENT_VAL(thread) = ConnectRetry_timer_expired;
bgp_event(thread); /* bgp_event unlocks peer */
}
Expand Down Expand Up @@ -1224,9 +1227,14 @@ void bgp_fsm_change_status(struct peer_connection *connection,

peer_count = bgp->established_peers;

if (status == Established)
if (status == Established) {
bgp->established_peers++;
else if ((peer_established(connection)) && (status != Established))
/* Reset the retry timer if we already established */
if (peer->connect)
peer->v_connect = peer->connect;
else
peer->v_connect = peer->bgp->default_connect_retry;
} else if ((peer_established(connection)) && (status != Established))
bgp->established_peers--;

if (bgp_debug_neighbor_events(peer)) {
Expand Down
1 change: 1 addition & 0 deletions bgpd/bgpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -2106,6 +2106,7 @@ struct bgp_nlri {
#define BGP_DEFAULT_HOLDTIME 180
#define BGP_DEFAULT_KEEPALIVE 60
#define BGP_DEFAULT_CONNECT_RETRY 30
#define BGP_MAX_CONNECT_RETRY 120

#define BGP_DEFAULT_EBGP_ROUTEADV 0
#define BGP_DEFAULT_IBGP_ROUTEADV 0
Expand Down

0 comments on commit ab3535f

Please sign in to comment.