From cdd3a61496d2a55764b25f749ecd3b33bfa55299 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Thu, 7 Nov 2024 10:55:19 -0500 Subject: [PATCH] zebra: move peer conn error list to connection struct Move the peer connection error list to the peer_connection struct; that seems to line up better with the way that struct works. Signed-off-by: Mark Stapp --- bgpd/bgp_io.c | 2 +- bgpd/bgpd.c | 44 +++++++++++++++++++++++--------------------- bgpd/bgpd.h | 17 +++++++++-------- 3 files changed, 33 insertions(+), 30 deletions(-) diff --git a/bgpd/bgp_io.c b/bgpd/bgp_io.c index a00fed0973e9..c7aa946f4463 100644 --- a/bgpd/bgp_io.c +++ b/bgpd/bgp_io.c @@ -251,7 +251,7 @@ static void bgp_process_reads(struct event *thread) /* Handle the error in the main pthread, include the * specific state change from 'bgp_read'. */ - bgp_enqueue_conn_err_peer(peer->bgp, connection->peer, code); + bgp_enqueue_conn_err(peer->bgp, connection, code); goto done; } diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index dd900d9689f5..d579fde40cb6 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -88,7 +88,7 @@ DEFINE_HOOK(bgp_inst_delete, (struct bgp *bgp), (bgp)); DEFINE_HOOK(bgp_instance_state, (struct bgp *bgp), (bgp)); /* Peers with connection error/failure, per bgp instance */ -DECLARE_DLIST(bgp_peer_conn_errlist, struct peer, conn_err_link); +DECLARE_DLIST(bgp_peer_conn_errlist, struct peer_connection, conn_err_link); /* List of info about peers that are being cleared from BGP RIBs in a batch */ DECLARE_DLIST(bgp_clearing_info, struct bgp_clearing_info, link); @@ -2748,9 +2748,9 @@ int peer_delete(struct peer *peer) /* Ensure the peer is removed from the connection error list */ frr_with_mutex (&bgp->peer_errs_mtx) { - if (bgp_peer_conn_errlist_anywhere(peer)) + if (bgp_peer_conn_errlist_anywhere(peer->connection)) bgp_peer_conn_errlist_del(&bgp->peer_conn_errlist, - peer); + peer->connection); } if (CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT)) @@ -4038,6 +4038,7 @@ int bgp_delete(struct bgp *bgp) struct graceful_restart_info *gr_info; uint32_t cnt_before, cnt_after; struct bgp_clearing_info *cinfo; + struct peer_connection *connection; assert(bgp); @@ -4173,9 +4174,9 @@ int bgp_delete(struct bgp *bgp) */ frr_with_mutex (&bgp->peer_errs_mtx) { do { - peer = bgp_peer_conn_errlist_pop( + connection = bgp_peer_conn_errlist_pop( &bgp->peer_conn_errlist); - } while (peer != NULL); + } while (connection != NULL); } /* Free peers and peer-groups. */ @@ -9228,7 +9229,7 @@ static void bgp_process_conn_error(struct event *event) bgp = EVENT_ARG(event); frr_with_mutex (&bgp->peer_errs_mtx) { - peer = bgp_peer_conn_errlist_pop(&bgp->peer_conn_errlist); + connection = bgp_peer_conn_errlist_pop(&bgp->peer_conn_errlist); list_count = bgp_peer_conn_errlist_count(&bgp->peer_conn_errlist); @@ -9241,12 +9242,12 @@ static void bgp_process_conn_error(struct event *event) bgp_clearing_batch_begin(bgp); /* Dequeue peers from the error list */ - while (peer != NULL) { - connection = peer->connection; + while (connection != NULL) { + peer = connection->peer; if (bgp_debug_neighbor_events(peer)) zlog_debug("%s [Event] BGP error %d on fd %d", - peer->host, peer->connection_errcode, + peer->host, connection->connection_errcode, connection->fd); /* Closed connection or error on the socket */ @@ -9265,13 +9266,13 @@ static void bgp_process_conn_error(struct event *event) bgp_keepalives_off(peer->connection); /* Drive into state-machine changes */ - bgp_event_update(connection, peer->connection_errcode); + bgp_event_update(connection, connection->connection_errcode); counter++; if (counter >= BGP_CONN_ERROR_DEQUEUE_MAX) break; - peer = bgp_dequeue_conn_err_peer(bgp, &more_p); + connection = bgp_dequeue_conn_err(bgp, &more_p); } /* Reschedule event if necessary */ @@ -9288,18 +9289,19 @@ static void bgp_process_conn_error(struct event *event) } /* - * Enqueue a peer with a connection error to be handled in the main pthread; + * Enqueue a connection with an error to be handled in the main pthread; * this is called from the io pthread. */ -int bgp_enqueue_conn_err_peer(struct bgp *bgp, struct peer *peer, int errcode) +int bgp_enqueue_conn_err(struct bgp *bgp, struct peer_connection *connection, + int errcode) { frr_with_mutex (&bgp->peer_errs_mtx) { - peer->connection_errcode = errcode; + connection->connection_errcode = errcode; /* Careful not to double-enqueue */ - if (!bgp_peer_conn_errlist_anywhere(peer)) { + if (!bgp_peer_conn_errlist_anywhere(connection)) { bgp_peer_conn_errlist_add_tail(&bgp->peer_conn_errlist, - peer); + connection); } } /* Ensure an event is scheduled */ @@ -9309,16 +9311,16 @@ int bgp_enqueue_conn_err_peer(struct bgp *bgp, struct peer *peer, int errcode) } /* - * Dequeue a peer that encountered a connection error; signal whether there + * Dequeue a connection that encountered a connection error; signal whether there * are more queued peers. */ -struct peer *bgp_dequeue_conn_err_peer(struct bgp *bgp, bool *more_p) +struct peer_connection *bgp_dequeue_conn_err(struct bgp *bgp, bool *more_p) { - struct peer *peer = NULL; + struct peer_connection *connection = NULL; bool more = false; frr_with_mutex (&bgp->peer_errs_mtx) { - peer = bgp_peer_conn_errlist_pop(&bgp->peer_conn_errlist); + connection = bgp_peer_conn_errlist_pop(&bgp->peer_conn_errlist); if (bgp_peer_conn_errlist_const_first( &bgp->peer_conn_errlist) != NULL) @@ -9328,7 +9330,7 @@ struct peer *bgp_dequeue_conn_err_peer(struct bgp *bgp, bool *more_p) if (more_p) *more_p = more; - return peer; + return connection; } /* diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index cbeb30d8b4d5..843e4b405c42 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -1296,6 +1296,12 @@ struct peer_connection { struct event *t_stop_with_notify; + /* Linkage for list connections with errors, from IO pthread */ + struct bgp_peer_conn_errlist_item conn_err_link; + + /* Connection error code */ + uint16_t connection_errcode; + union sockunion su; #define BGP_CONNECTION_SU_UNSPEC(connection) \ (connection->su.sa.sa_family == AF_UNSPEC) @@ -1981,12 +1987,6 @@ struct peer { /* Add-Path Paths-Limit */ struct addpath_paths_limit addpath_paths_limit[AFI_MAX][SAFI_MAX]; - /* Linkage for list of peers with connection errors from IO pthread */ - struct bgp_peer_conn_errlist_item conn_err_link; - - /* Connection error code */ - uint16_t connection_errcode; - /* Linkage for hash of clearing peers being cleared in a batch */ struct bgp_clearing_hash_item clear_hash_link; @@ -2627,8 +2627,9 @@ int bgp_global_gr_init(struct bgp *bgp); int bgp_peer_gr_init(struct peer *peer); /* APIs for the per-bgp peer connection error list */ -int bgp_enqueue_conn_err_peer(struct bgp *bgp, struct peer *peer, int errcode); -struct peer *bgp_dequeue_conn_err_peer(struct bgp *bgp, bool *more_p); +int bgp_enqueue_conn_err(struct bgp *bgp, struct peer_connection *connection, + int errcode); +struct peer_connection *bgp_dequeue_conn_err(struct bgp *bgp, bool *more_p); void bgp_conn_err_reschedule(struct bgp *bgp); #define BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(_bgp, _peer_list) \