diff options
| author | Donald Sharp <sharpd@nvidia.com> | 2023-08-28 13:04:26 -0400 | 
|---|---|---|
| committer | Donald Sharp <sharpd@nvidia.com> | 2023-09-10 08:31:25 -0400 | 
| commit | b2f25e1a17e601c687256715b50db109605c3a25 (patch) | |
| tree | bc3c1324de782e7258b55166b5d239f9d8591bd8 | |
| parent | b57e023cc2da413990c28c8495e23e0fd06e02dc (diff) | |
bgpd: First pass of BGP_EVENT_ADD
Pass through a bunch of BGP_EVENT_ADD's and make
the code use a proper connection instead of a
peer->connection.  There still are a bunch
of places where peer->connection is used and
later commits will probably go through and
clean these up more.
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
| -rw-r--r-- | bgpd/bgp_network.c | 41 | ||||
| -rw-r--r-- | bgpd/bgp_nexthop.c | 7 | ||||
| -rw-r--r-- | bgpd/bgp_packet.c | 38 | ||||
| -rw-r--r-- | bgpd/bgp_packet.h | 2 | 
4 files changed, 46 insertions, 42 deletions
diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index 68e5dcc8c6..fb5c297d4c 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -344,8 +344,8 @@ static void bgp_accept(struct event *thread)  	int accept_sock;  	union sockunion su;  	struct bgp_listener *listener = EVENT_ARG(thread); -	struct peer *peer; -	struct peer *peer1; +	struct peer *peer, *peer1; +	struct peer_connection *connection, *connection1;  	char buf[SU_ADDRSTRLEN];  	struct bgp *bgp = NULL; @@ -428,24 +428,24 @@ static void bgp_accept(struct event *thread)  	if (!peer1) {  		peer1 = peer_lookup_dynamic_neighbor(bgp, &su);  		if (peer1) { +			connection1 = peer1->connection;  			/* Dynamic neighbor has been created, let it proceed */ -			peer1->connection->fd = bgp_sock; +			connection1->fd = bgp_sock;  			/* Set the user configured MSS to TCP socket */  			if (CHECK_FLAG(peer1->flags, PEER_FLAG_TCP_MSS))  				sockopt_tcp_mss_set(bgp_sock, peer1->tcp_mss); -			bgp_fsm_change_status(peer1->connection, Active); -			EVENT_OFF(peer1->connection -					  ->t_start); /* created in peer_create() */ +			bgp_fsm_change_status(connection1, Active); +			EVENT_OFF(connection1->t_start);  			if (peer_active(peer1)) {  				if (CHECK_FLAG(peer1->flags,  					       PEER_FLAG_TIMER_DELAYOPEN)) -					BGP_EVENT_ADD(peer1->connection, +					BGP_EVENT_ADD(connection1,  						      TCP_connection_open_w_delay);  				else -					BGP_EVENT_ADD(peer1->connection, +					BGP_EVENT_ADD(connection1,  						      TCP_connection_open);  			} @@ -464,6 +464,7 @@ static void bgp_accept(struct event *thread)  		return;  	} +	connection1 = peer1->connection;  	if (CHECK_FLAG(peer1->flags, PEER_FLAG_SHUTDOWN)  	    || CHECK_FLAG(peer1->bgp->flags, BGP_FLAG_SHUTDOWN)) {  		if (bgp_debug_neighbor_events(peer1)) @@ -481,8 +482,7 @@ static void bgp_accept(struct event *thread)  	 * Established and then the Clearing_Completed event is generated. Also,  	 * block incoming connection in Deleted state.  	 */ -	if (peer1->connection->status == Clearing || -	    peer1->connection->status == Deleted) { +	if (connection1->status == Clearing || connection1->status == Deleted) {  		if (bgp_debug_neighbor_events(peer1))  			zlog_debug("[Event] Closing incoming conn for %s (%p) state %d",  				   peer1->host, peer1, @@ -522,8 +522,8 @@ static void bgp_accept(struct event *thread)  	if (bgp_debug_neighbor_events(peer1))  		zlog_debug("[Event] connection from %s fd %d, active peer status %d fd %d", -			   inet_sutop(&su, buf), bgp_sock, -			   peer1->connection->status, peer1->connection->fd); +			   inet_sutop(&su, buf), bgp_sock, connection1->status, +			   connection1->fd);  	if (peer1->doppelganger) {  		/* We have an existing connection. Kill the existing one and run @@ -545,6 +545,8 @@ static void bgp_accept(struct event *thread)  	peer = peer_create(&su, peer1->conf_if, peer1->bgp, peer1->local_as,  			   peer1->as, peer1->as_type, NULL, false, NULL); +	connection = peer->connection; +  	peer_xfer_config(peer, peer1);  	bgp_peer_gr_flags_update(peer); @@ -562,17 +564,17 @@ static void bgp_accept(struct event *thread)  	peer->doppelganger = peer1;  	peer1->doppelganger = peer; -	peer->connection->fd = bgp_sock; +	connection->fd = bgp_sock;  	frr_with_privs(&bgpd_privs) {  		vrf_bind(peer->bgp->vrf_id, bgp_sock, bgp_get_bound_name(peer));  	}  	bgp_peer_reg_with_nht(peer); -	bgp_fsm_change_status(peer->connection, Active); -	EVENT_OFF(peer->connection->t_start); /* created in peer_create() */ +	bgp_fsm_change_status(connection, Active); +	EVENT_OFF(connection->t_start); /* created in peer_create() */  	SET_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER);  	/* Make dummy peer until read Open packet. */ -	if (peer_established(peer1->connection) && +	if (peer_established(connection1) &&  	    CHECK_FLAG(peer1->sflags, PEER_STATUS_NSF_MODE)) {  		/* If we have an existing established connection with graceful  		 * restart @@ -587,15 +589,14 @@ static void bgp_accept(struct event *thread)  				  PEER_FLAG_GRACEFUL_RESTART_HELPER))  			SET_FLAG(peer1->sflags, PEER_STATUS_NSF_WAIT); -		bgp_event_update(peer1->connection, TCP_connection_closed); +		bgp_event_update(connection1, TCP_connection_closed);  	}  	if (peer_active(peer)) {  		if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER_DELAYOPEN)) -			BGP_EVENT_ADD(peer->connection, -				      TCP_connection_open_w_delay); +			BGP_EVENT_ADD(connection, TCP_connection_open_w_delay);  		else -			BGP_EVENT_ADD(peer->connection, TCP_connection_open); +			BGP_EVENT_ADD(connection, TCP_connection_open);  	}  	/* diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index e0f22ad4a0..729f5e6bbc 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -385,6 +385,7 @@ void bgp_connected_add(struct bgp *bgp, struct connected *ifc)  	struct bgp_connected_ref *bc;  	struct listnode *node, *nnode;  	struct peer *peer; +	struct peer_connection *connection;  	addr = ifc->address; @@ -413,10 +414,10 @@ void bgp_connected_add(struct bgp *bgp, struct connected *ifc)  			    (strcmp(peer->conf_if, ifc->ifp->name) == 0) &&  			    !peer_established(peer->connection) &&  			    !CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY)) { +				connection = peer->connection;  				if (peer_active(peer)) -					BGP_EVENT_ADD(peer->connection, -						      BGP_Stop); -				BGP_EVENT_ADD(peer->connection, BGP_Start); +					BGP_EVENT_ADD(connection, BGP_Stop); +				BGP_EVENT_ADD(connection, BGP_Start);  			}  		}  	} else if (addr->family == AF_INET6) { diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index 924c9a3daa..6ae418b98e 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -105,21 +105,22 @@ void bgp_packet_set_size(struct stream *s)   * Push a packet onto the beginning of the peer's output queue.   * This function acquires the peer's write mutex before proceeding.   */ -static void bgp_packet_add(struct peer *peer, struct stream *s) +static void bgp_packet_add(struct peer_connection *connection, +			   struct peer *peer, struct stream *s)  {  	intmax_t delta;  	uint32_t holdtime;  	intmax_t sendholdtime; -	frr_with_mutex (&peer->connection->io_mtx) { +	frr_with_mutex (&connection->io_mtx) {  		/* if the queue is empty, reset the "last OK" timestamp to  		 * now, otherwise if we write another packet immediately  		 * after it'll get confused  		 */ -		if (!stream_fifo_count_safe(peer->connection->obuf)) +		if (!stream_fifo_count_safe(connection->obuf))  			peer->last_sendq_ok = monotime(NULL); -		stream_fifo_push(peer->connection->obuf, s); +		stream_fifo_push(connection->obuf, s);  		delta = monotime(NULL) - peer->last_sendq_ok; @@ -146,7 +147,7 @@ static void bgp_packet_add(struct peer *peer, struct stream *s)  				EC_BGP_SENDQ_STUCK_PROPER,  				"%pBP has not made any SendQ progress for 2 holdtimes (%jds), terminating session",  				peer, sendholdtime); -			BGP_EVENT_ADD(peer->connection, TCP_fatal_error); +			BGP_EVENT_ADD(connection, TCP_fatal_error);  		} else if (delta > (intmax_t)holdtime &&  			   monotime(NULL) - peer->last_sendq_warn > 5) {  			flog_warn( @@ -602,7 +603,7 @@ void bgp_generate_updgrp_packets(struct event *thread)  			 * packet with appropriate attributes from peer  			 * and advance peer */  			s = bpacket_reformat_for_peer(next_pkt, paf); -			bgp_packet_add(peer, s); +			bgp_packet_add(connection, peer, s);  			bpacket_queue_advance_peer(paf);  		}  	} while (s && (++generated < wpq) && @@ -636,7 +637,7 @@ void bgp_keepalive_send(struct peer *peer)  		zlog_debug("%s sending KEEPALIVE", peer->host);  	/* Add packet to the peer. */ -	bgp_packet_add(peer, s); +	bgp_packet_add(peer->connection, peer, s);  	bgp_writes_on(peer->connection);  } @@ -706,7 +707,7 @@ void bgp_open_send(struct peer_connection *connection)  	hook_call(bgp_packet_send, peer, BGP_MSG_OPEN, stream_get_endp(s), s);  	/* Add packet to the peer. */ -	bgp_packet_add(peer, s); +	bgp_packet_add(connection, peer, s);  	bgp_writes_on(connection);  } @@ -723,14 +724,15 @@ void bgp_open_send(struct peer_connection *connection)   * @param peer   * @return 0   */ -static void bgp_write_notify(struct peer *peer) +static void bgp_write_notify(struct peer_connection *connection, +			     struct peer *peer)  {  	int ret, val;  	uint8_t type;  	struct stream *s;  	/* There should be at least one packet. */ -	s = stream_fifo_pop(peer->connection->obuf); +	s = stream_fifo_pop(connection->obuf);  	if (!s)  		return; @@ -741,7 +743,7 @@ static void bgp_write_notify(struct peer *peer)  	 * socket is in nonblocking mode, if we can't deliver the NOTIFY, well,  	 * we only care about getting a clean shutdown at this point.  	 */ -	ret = write(peer->connection->fd, STREAM_DATA(s), stream_get_endp(s)); +	ret = write(connection->fd, STREAM_DATA(s), stream_get_endp(s));  	/*  	 * only connection reset/close gets counted as TCP_fatal_error, failure @@ -749,14 +751,14 @@ static void bgp_write_notify(struct peer *peer)  	 */  	if (ret <= 0) {  		stream_free(s); -		BGP_EVENT_ADD(peer->connection, TCP_fatal_error); +		BGP_EVENT_ADD(connection, TCP_fatal_error);  		return;  	}  	/* Disable Nagle, make NOTIFY packet go out right away */  	val = 1; -	(void)setsockopt(peer->connection->fd, IPPROTO_TCP, TCP_NODELAY, -			 (char *)&val, sizeof(val)); +	(void)setsockopt(connection->fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, +			 sizeof(val));  	/* Retrieve BGP packet type. */  	stream_set_getp(s, BGP_MARKER_SIZE + 2); @@ -778,7 +780,7 @@ static void bgp_write_notify(struct peer *peer)  	 * Handle Graceful Restart case where the state changes to  	 * Connect instead of Idle  	 */ -	BGP_EVENT_ADD(peer->connection, BGP_Stop); +	BGP_EVENT_ADD(connection, BGP_Stop);  	stream_free(s);  } @@ -1038,7 +1040,7 @@ static void bgp_notify_send_internal(struct peer_connection *connection,  	BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(peer->bgp,  							  peer->bgp->peer); -	bgp_write_notify(peer); +	bgp_write_notify(connection, peer);  }  /* @@ -1186,7 +1188,7 @@ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi,  	}  	/* Add packet to the peer. */ -	bgp_packet_add(peer, s); +	bgp_packet_add(peer->connection, peer, s);  	bgp_writes_on(peer->connection);  } @@ -1360,7 +1362,7 @@ void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi,  	bgp_packet_set_size(s);  	/* Add packet to the peer. */ -	bgp_packet_add(peer, s); +	bgp_packet_add(peer->connection, peer, s);  	bgp_writes_on(peer->connection);  } diff --git a/bgpd/bgp_packet.h b/bgpd/bgp_packet.h index 3ce04bd9d2..b67acf2055 100644 --- a/bgpd/bgp_packet.h +++ b/bgpd/bgp_packet.h @@ -37,7 +37,7 @@ DECLARE_HOOK(bgp_packet_send,  	do {                                                                   \  		_s = bgp_update_packet_eor(_peer, _afi, _safi);                \  		if (_s) {                                                      \ -			bgp_packet_add(_peer, _s);                             \ +			bgp_packet_add(_peer->connection, _peer, _s);          \  		}                                                              \  	} while (0)  | 
