bgpd: make bgp_keepalives_on|off connection oriented

The bgp_keepalives_on|off functions should use a peer_connection
as a basis for it's operation.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2023-08-26 21:34:59 -04:00
parent 1f8274e050
commit d1e7215da0
4 changed files with 21 additions and 17 deletions

View file

@ -157,7 +157,7 @@ static struct peer *peer_xfer_conn(struct peer *from_peer)
* fd is set to -1. If blocked on lock then keepalive * fd is set to -1. If blocked on lock then keepalive
* thread can access peer pointer with fd -1. * thread can access peer pointer with fd -1.
*/ */
bgp_keepalives_off(from_peer); bgp_keepalives_off(from_peer->connection);
EVENT_OFF(peer->connection->t_routeadv); EVENT_OFF(peer->connection->t_routeadv);
EVENT_OFF(peer->connection->t_connect); EVENT_OFF(peer->connection->t_connect);
@ -366,7 +366,7 @@ void bgp_timer_set(struct peer_connection *connection)
} }
EVENT_OFF(connection->t_connect); EVENT_OFF(connection->t_connect);
EVENT_OFF(connection->t_holdtime); EVENT_OFF(connection->t_holdtime);
bgp_keepalives_off(peer); bgp_keepalives_off(connection);
EVENT_OFF(connection->t_routeadv); EVENT_OFF(connection->t_routeadv);
EVENT_OFF(connection->t_delayopen); EVENT_OFF(connection->t_delayopen);
break; break;
@ -384,7 +384,7 @@ void bgp_timer_set(struct peer_connection *connection)
peer->v_connect); peer->v_connect);
EVENT_OFF(connection->t_holdtime); EVENT_OFF(connection->t_holdtime);
bgp_keepalives_off(peer); bgp_keepalives_off(connection);
EVENT_OFF(connection->t_routeadv); EVENT_OFF(connection->t_routeadv);
break; break;
@ -407,7 +407,7 @@ void bgp_timer_set(struct peer_connection *connection)
bgp_connect_timer, peer->v_connect); bgp_connect_timer, peer->v_connect);
} }
EVENT_OFF(connection->t_holdtime); EVENT_OFF(connection->t_holdtime);
bgp_keepalives_off(peer); bgp_keepalives_off(connection);
EVENT_OFF(connection->t_routeadv); EVENT_OFF(connection->t_routeadv);
break; break;
@ -421,7 +421,7 @@ void bgp_timer_set(struct peer_connection *connection)
} else { } else {
EVENT_OFF(connection->t_holdtime); EVENT_OFF(connection->t_holdtime);
} }
bgp_keepalives_off(peer); bgp_keepalives_off(connection);
EVENT_OFF(connection->t_routeadv); EVENT_OFF(connection->t_routeadv);
EVENT_OFF(connection->t_delayopen); EVENT_OFF(connection->t_delayopen);
break; break;
@ -439,11 +439,11 @@ void bgp_timer_set(struct peer_connection *connection)
*/ */
EVENT_OFF(connection->t_holdtime); EVENT_OFF(connection->t_holdtime);
if (peer->v_holdtime == 0) if (peer->v_holdtime == 0)
bgp_keepalives_off(peer); bgp_keepalives_off(connection);
else { else {
BGP_TIMER_ON(connection->t_holdtime, bgp_holdtime_timer, BGP_TIMER_ON(connection->t_holdtime, bgp_holdtime_timer,
peer->v_holdtime); peer->v_holdtime);
bgp_keepalives_on(peer); bgp_keepalives_on(connection);
} }
EVENT_OFF(connection->t_routeadv); EVENT_OFF(connection->t_routeadv);
EVENT_OFF(connection->t_delayopen); EVENT_OFF(connection->t_delayopen);
@ -464,11 +464,11 @@ void bgp_timer_set(struct peer_connection *connection)
*/ */
EVENT_OFF(connection->t_holdtime); EVENT_OFF(connection->t_holdtime);
if (peer->v_holdtime == 0) if (peer->v_holdtime == 0)
bgp_keepalives_off(peer); bgp_keepalives_off(connection);
else { else {
BGP_TIMER_ON(connection->t_holdtime, bgp_holdtime_timer, BGP_TIMER_ON(connection->t_holdtime, bgp_holdtime_timer,
peer->v_holdtime); peer->v_holdtime);
bgp_keepalives_on(peer); bgp_keepalives_on(connection);
} }
break; break;
case Deleted: case Deleted:
@ -485,7 +485,7 @@ void bgp_timer_set(struct peer_connection *connection)
EVENT_OFF(connection->t_start); EVENT_OFF(connection->t_start);
EVENT_OFF(connection->t_connect); EVENT_OFF(connection->t_connect);
EVENT_OFF(connection->t_holdtime); EVENT_OFF(connection->t_holdtime);
bgp_keepalives_off(peer); bgp_keepalives_off(connection);
EVENT_OFF(connection->t_routeadv); EVENT_OFF(connection->t_routeadv);
EVENT_OFF(connection->t_delayopen); EVENT_OFF(connection->t_delayopen);
break; break;
@ -1507,7 +1507,7 @@ enum bgp_fsm_state_progress bgp_stop(struct peer_connection *connection)
} }
/* stop keepalives */ /* stop keepalives */
bgp_keepalives_off(peer); bgp_keepalives_off(connection);
/* Stop read and write threads. */ /* Stop read and write threads. */
bgp_writes_off(connection); bgp_writes_off(connection);
@ -2290,7 +2290,7 @@ bgp_establish(struct peer_connection *connection)
/* Reset uptime, turn on keepalives, send current table. */ /* Reset uptime, turn on keepalives, send current table. */
if (!peer->v_holdtime) if (!peer->v_holdtime)
bgp_keepalives_on(peer); bgp_keepalives_on(connection);
peer->uptime = monotime(NULL); peer->uptime = monotime(NULL);

View file

@ -229,8 +229,10 @@ void *bgp_keepalives_start(void *arg)
/* --- thread external functions ------------------------------------------- */ /* --- thread external functions ------------------------------------------- */
void bgp_keepalives_on(struct peer *peer) void bgp_keepalives_on(struct peer_connection *connection)
{ {
struct peer *peer = connection->peer;
if (CHECK_FLAG(peer->thread_flags, PEER_THREAD_KEEPALIVES_ON)) if (CHECK_FLAG(peer->thread_flags, PEER_THREAD_KEEPALIVES_ON))
return; return;
@ -258,8 +260,10 @@ void bgp_keepalives_on(struct peer *peer)
} }
} }
void bgp_keepalives_off(struct peer *peer) void bgp_keepalives_off(struct peer_connection *connection)
{ {
struct peer *peer = connection->peer;
if (!CHECK_FLAG(peer->thread_flags, PEER_THREAD_KEEPALIVES_ON)) if (!CHECK_FLAG(peer->thread_flags, PEER_THREAD_KEEPALIVES_ON))
return; return;

View file

@ -27,7 +27,7 @@
* If the peer is already registered for keepalives via this function, nothing * If the peer is already registered for keepalives via this function, nothing
* happens. * happens.
*/ */
extern void bgp_keepalives_on(struct peer *); extern void bgp_keepalives_on(struct peer_connection *connection);
/** /**
* Turns off keepalives for a peer. * Turns off keepalives for a peer.
@ -36,7 +36,7 @@ extern void bgp_keepalives_on(struct peer *);
* *
* If the peer is already unregistered for keepalives, nothing happens. * If the peer is already unregistered for keepalives, nothing happens.
*/ */
extern void bgp_keepalives_off(struct peer *); extern void bgp_keepalives_off(struct peer_connection *connection);
/** /**
* Pre-run initialization function for keepalives pthread. * Pre-run initialization function for keepalives pthread.

View file

@ -2588,7 +2588,7 @@ int peer_delete(struct peer *peer)
bgp_soft_reconfig_table_task_cancel(bgp, NULL, peer); bgp_soft_reconfig_table_task_cancel(bgp, NULL, peer);
bgp_keepalives_off(peer); bgp_keepalives_off(peer->connection);
bgp_reads_off(peer->connection); bgp_reads_off(peer->connection);
bgp_writes_off(peer->connection); bgp_writes_off(peer->connection);
event_cancel_event_ready(bm->master, peer); event_cancel_event_ready(bm->master, peer);