Skip to content

Commit

Permalink
zebra: move peer conn error list to connection struct
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Mark Stapp committed Nov 26, 2024
1 parent 7e73ebf commit cdd3a61
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion bgpd/bgp_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
44 changes: 23 additions & 21 deletions bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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);
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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 */
Expand All @@ -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)
Expand All @@ -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;
}

/*
Expand Down
17 changes: 9 additions & 8 deletions bgpd/bgpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) \
Expand Down

0 comments on commit cdd3a61

Please sign in to comment.