bgpd: Delay setting peer data until after decision to allow open

Delay setting local data about a remote peer until after BGP
has decided to allow an open connection to proceed.

Modifying local peer data structures based upon what is
received from a peer should not be done until after BGP
has decided that the open is allowed to proceed.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2021-04-30 19:24:40 -04:00
parent f88221f3b4
commit 7a75470fe1

View File

@ -1261,9 +1261,6 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size)
return BGP_Stop;
}
/* Set remote router-id */
peer->remote_id = remote_id;
/* Peer BGP version check. */
if (version != BGP_VERSION_4) {
uint16_t maxver = htons(BGP_VERSION_4);
@ -1323,6 +1320,25 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size)
return BGP_Stop;
}
/*
* When collision is detected and this peer is closed.
* Return immediately.
*/
ret = bgp_collision_detect(peer, remote_id);
if (ret < 0)
return BGP_Stop;
/* Get sockname. */
if (bgp_getsockname(peer) < 0) {
flog_err_sys(EC_LIB_SOCKET,
"%s: bgp_getsockname() failed for peer: %s",
__func__, peer->host);
return BGP_Stop;
}
/* Set remote router-id */
peer->remote_id = remote_id;
/* From the rfc: Upon receipt of an OPEN message, a BGP speaker MUST
calculate the value of the Hold Timer by using the smaller of its
configured Hold Time and the Hold Time received in the OPEN message.
@ -1403,21 +1419,6 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size)
peer->afc[AFI_IP6][SAFI_FLOWSPEC];
}
/* When collision is detected and this peer is closed.
* Return immediately.
*/
ret = bgp_collision_detect(peer, remote_id);
if (ret < 0)
return BGP_Stop;
/* Get sockname. */
if (bgp_getsockname(peer) < 0) {
flog_err_sys(EC_LIB_SOCKET,
"%s: bgp_getsockname() failed for peer: %s",
__func__, peer->host);
return BGP_Stop;
}
/* Verify valid local address present based on negotiated
* address-families. */
if (peer->afc_nego[AFI_IP][SAFI_UNICAST]