Skip to content

Commit

Permalink
bgpd: peer_established should be connection oriented
Browse files Browse the repository at this point in the history
The peer_established function should be connection oriented.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
  • Loading branch information
donaldsharp committed Sep 10, 2023
1 parent d1e7215 commit 7b1158b
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 97 deletions.
4 changes: 2 additions & 2 deletions bgpd/bgp_bfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ static void bfd_session_status_update(struct bfd_session_params *bsp,
BGP_EVENT_ADD(peer, BGP_Stop);
}

if (bss->state == BSS_UP && bss->previous_state != BSS_UP
&& !peer_established(peer)) {
if (bss->state == BSS_UP && bss->previous_state != BSS_UP &&
!peer_established(peer->connection)) {
if (!BGP_PEER_START_SUPPRESSED(peer)) {
bgp_fsm_nht_update(peer, true);
BGP_EVENT_ADD(peer, BGP_Start);
Expand Down
8 changes: 4 additions & 4 deletions bgpd/bgp_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ static struct stream *bmp_peerstate(struct peer *peer, bool down)
#define BGP_BMP_MAX_PACKET_SIZE 1024
s = stream_new(BGP_MAX_PACKET_SIZE);

if (peer_established(peer) && !down) {
if (peer_established(peer->connection) && !down) {
struct bmp_bgp_peer *bbpeer;

bmp_common_hdr(s, BMP_VERSION_3,
Expand Down Expand Up @@ -716,7 +716,7 @@ static int bmp_peer_status_changed(struct peer *peer)

/* Check if this peer just went to Established */
if ((peer->connection->ostatus != OpenConfirm) ||
!(peer_established(peer)))
!(peer_established(peer->connection)))
return 0;

if (peer->doppelganger &&
Expand Down Expand Up @@ -1170,7 +1170,7 @@ static bool bmp_wrqueue(struct bmp *bmp, struct pullwr *pullwr)
zlog_info("bmp: skipping queued item for deleted peer");
goto out;
}
if (!peer_established(peer))
if (!peer_established(peer->connection))
goto out;

bool is_vpn = (bqe->afi == AFI_L2VPN && bqe->safi == SAFI_EVPN) ||
Expand Down Expand Up @@ -1355,7 +1355,7 @@ static void bmp_stats(struct event *thread)
for (ALL_LIST_ELEMENTS_RO(bt->bgp->peer, node, peer)) {
size_t count = 0, count_pos, len;

if (!peer_established(peer))
if (!peer_established(peer->connection))
continue;

s = stream_new(BGP_MAX_PACKET_SIZE);
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_conditional_adv.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ static void bgp_conditional_adv_timer(struct event *t)
if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
continue;

if (!peer_established(peer))
if (!peer_established(peer->connection))
continue;

FOREACH_AFI_SAFI (afi, safi) {
Expand Down
16 changes: 9 additions & 7 deletions bgpd/bgp_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,9 @@ void bgp_start_routeadv(struct bgp *bgp)
sizeof(bgp->update_delay_peers_resume_time));

for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
if (!peer_established(peer))
struct peer_connection *connection = peer->connection;

if (!peer_established(connection))
continue;
EVENT_OFF(peer->connection->t_routeadv);
BGP_TIMER_ON(peer->connection->t_routeadv, bgp_routeadv_timer,
Expand Down Expand Up @@ -1160,7 +1162,7 @@ static void bgp_maxmed_onstartup_begin(struct bgp *bgp)

static void bgp_maxmed_onstartup_process_status_change(struct peer *peer)
{
if (peer_established(peer) && !peer->bgp->established) {
if (peer_established(peer->connection) && !peer->bgp->established) {
bgp_maxmed_onstartup_begin(peer->bgp);
}
}
Expand Down Expand Up @@ -1218,7 +1220,7 @@ static void bgp_update_delay_begin(struct bgp *bgp)

static void bgp_update_delay_process_status_change(struct peer *peer)
{
if (peer_established(peer)) {
if (peer_established(peer->connection)) {
if (!peer->bgp->established++) {
bgp_update_delay_begin(peer->bgp);
zlog_info(
Expand Down Expand Up @@ -1254,7 +1256,7 @@ void bgp_fsm_change_status(struct peer *peer, enum bgp_fsm_status status)

if (status == Established)
bgp->established_peers++;
else if ((peer_established(peer)) && (status != Established))
else if ((peer_established(peer->connection)) && (status != Established))
bgp->established_peers--;

if (bgp_debug_neighbor_events(peer)) {
Expand Down Expand Up @@ -1397,7 +1399,7 @@ enum bgp_fsm_state_progress bgp_stop(struct peer_connection *connection)
}

/* Increment Dropped count. */
if (peer_established(peer)) {
if (peer_established(connection)) {
peer->dropped++;

/* Notify BGP conditional advertisement process */
Expand Down Expand Up @@ -1567,7 +1569,7 @@ enum bgp_fsm_state_progress bgp_stop(struct peer_connection *connection)
peer->orf_plist[afi][safi] = NULL;

if ((connection->status == OpenConfirm) ||
peer_established(peer)) {
peer_established(connection)) {
/* ORF received prefix-filter pnt */
snprintf(orf_name, sizeof(orf_name), "%s.%d.%d",
peer->host, afi, safi);
Expand Down Expand Up @@ -2034,7 +2036,7 @@ bgp_fsm_holdtime_expire(struct peer_connection *connection)
* the Graceful Restart procedures to be performed when the BGP
* speaker receives a BGP NOTIFICATION message or the Hold Time expires.
*/
if (peer_established(peer) &&
if (peer_established(connection) &&
bgp_has_graceful_restart_notification(peer))
if (CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_MODE))
SET_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT);
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ static void bgp_mac_rescan_evpn_table(struct bgp *bgp, struct ethaddr *macaddr)
if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP))
continue;

if (!peer_established(peer))
if (!peer_established(peer->connection))
continue;

if (bgp_debug_update(peer, NULL, NULL, 1))
Expand Down
4 changes: 2 additions & 2 deletions bgpd/bgp_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,8 +573,8 @@ static void bgp_accept(struct event *thread)

SET_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER);
/* Make dummy peer until read Open packet. */
if (peer_established(peer1)
&& CHECK_FLAG(peer1->sflags, PEER_STATUS_NSF_MODE)) {
if (peer_established(peer1->connection) &&
CHECK_FLAG(peer1->sflags, PEER_STATUS_NSF_MODE)) {
/* If we have an existing established connection with graceful
* restart
* capability announced with one or more address families, then
Expand Down
9 changes: 4 additions & 5 deletions bgpd/bgp_nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,11 +409,10 @@ void bgp_connected_add(struct bgp *bgp, struct connected *ifc)
}

for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
if (peer->conf_if
&& (strcmp(peer->conf_if, ifc->ifp->name) == 0)
&& !peer_established(peer)
&& !CHECK_FLAG(peer->flags,
PEER_FLAG_IFPEER_V6ONLY)) {
if (peer->conf_if &&
(strcmp(peer->conf_if, ifc->ifp->name) == 0) &&
!peer_established(peer->connection) &&
!CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY)) {
if (peer_active(peer))
BGP_EVENT_ADD(peer, BGP_Stop);
BGP_EVENT_ADD(peer, BGP_Start);
Expand Down
23 changes: 12 additions & 11 deletions bgpd/bgp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void bgp_update_restarted_peers(struct peer *peer)
if (bgp_debug_neighbor_events(peer))
zlog_debug("Peer %s: Checking restarted", peer->host);

if (peer_established(peer)) {
if (peer_established(peer->connection)) {
peer->update_delay_over = 1;
peer->bgp->restarted_peers++;
bgp_check_update_delay(peer->bgp);
Expand All @@ -283,7 +283,7 @@ void bgp_update_implicit_eors(struct peer *peer)
if (bgp_debug_neighbor_events(peer))
zlog_debug("Peer %s: Checking implicit EORs", peer->host);

if (peer_established(peer)) {
if (peer_established(peer->connection)) {
peer->update_delay_over = 1;
peer->bgp->implicit_eors++;
bgp_check_update_delay(peer->bgp);
Expand Down Expand Up @@ -463,7 +463,7 @@ void bgp_generate_updgrp_packets(struct event *thread)
* if peer is Established and updates are not on hold (as part of
* update-delay processing).
*/
if (!peer_established(peer))
if (!peer_established(peer->connection))
return;

if ((peer->bgp->main_peers_update_hold)
Expand Down Expand Up @@ -1210,7 +1210,7 @@ void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi,
uint16_t len;
uint32_t gr_restart_time;

if (!peer_established(peer))
if (!peer_established(peer->connection))
return;

if (!CHECK_FLAG(peer->cap, PEER_CAP_DYNAMIC_RCV) &&
Expand Down Expand Up @@ -1389,7 +1389,8 @@ static int bgp_collision_detect(struct peer *new, struct in_addr remote_id)
* states. Note that a peer GR is handled by closing the existing
* connection upon receipt of new one.
*/
if (peer_established(peer) || peer->connection->status == Clearing) {
if (peer_established(peer->connection) ||
peer->connection->status == Clearing) {
bgp_notify_send(new->connection, BGP_NOTIFY_CEASE,
BGP_NOTIFY_CEASE_COLLISION_RESOLUTION);
return -1;
Expand Down Expand Up @@ -1986,7 +1987,7 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size)
struct bgp_nlri nlris[NLRI_TYPE_MAX];

/* Status must be Established. */
if (!peer_established(peer)) {
if (!peer_established(peer->connection)) {
flog_err(EC_BGP_INVALID_STATUS,
"%s [FSM] Update packet received under status %s",
peer->host,
Expand Down Expand Up @@ -2178,7 +2179,7 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size)
&& nlri_ret != BGP_NLRI_PARSE_ERROR_PREFIX_OVERFLOW) {
flog_err(EC_BGP_UPDATE_RCV,
"%s [Error] Error parsing NLRI", peer->host);
if (peer_established(peer))
if (peer_established(peer->connection))
bgp_notify_send(peer->connection,
BGP_NOTIFY_UPDATE_ERR,
i <= NLRI_WITHDRAW
Expand Down Expand Up @@ -2438,7 +2439,7 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
}

/* Status must be Established. */
if (!peer_established(peer)) {
if (!peer_established(peer->connection)) {
flog_err(EC_BGP_INVALID_STATUS,
"%s [Error] Route refresh packet received under status %s",
peer->host,
Expand Down Expand Up @@ -2736,7 +2737,7 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
bgp_set_stale_route(peer, afi, safi);
}

if (peer_established(peer))
if (peer_established(peer->connection))
event_add_timer(bm->master,
bgp_refresh_stalepath_timer_expire, paf,
peer->bgp->stalepath_time,
Expand Down Expand Up @@ -3131,7 +3132,7 @@ int bgp_capability_receive(struct peer *peer, bgp_size_t size)
}

/* Status must be Established. */
if (!peer_established(peer)) {
if (!peer_established(peer->connection)) {
flog_err(EC_BGP_NO_CAP,
"%s [Error] Dynamic capability packet received under status %s",
peer->host,
Expand Down Expand Up @@ -3354,7 +3355,7 @@ void bgp_packet_process_error(struct event *thread)
connection->fd);

/* Closed connection or error on the socket */
if (peer_established(peer)) {
if (peer_established(connection)) {
if ((CHECK_FLAG(peer->flags, PEER_FLAG_GRACEFUL_RESTART)
|| CHECK_FLAG(peer->flags,
PEER_FLAG_GRACEFUL_RESTART_HELPER))
Expand Down
12 changes: 6 additions & 6 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -2742,7 +2742,7 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
if (pi1->peer != bgp->peer_self &&
!CHECK_FLAG(pi1->peer->sflags,
PEER_STATUS_NSF_WAIT)) {
if (!peer_established(pi1->peer))
if (!peer_established(pi1->peer->connection))
continue;
}

Expand All @@ -2757,7 +2757,8 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
if (pi2->peer != bgp->peer_self &&
!CHECK_FLAG(pi2->peer->sflags,
PEER_STATUS_NSF_WAIT) &&
!peer_established(pi2->peer))
!peer_established(
pi2->peer->connection))
continue;

if (!aspath_cmp_left(pi1->attr->aspath,
Expand Down Expand Up @@ -2828,8 +2829,7 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,

if (pi->peer && pi->peer != bgp->peer_self
&& !CHECK_FLAG(pi->peer->sflags, PEER_STATUS_NSF_WAIT))
if (!peer_established(pi->peer)) {

if (!peer_established(pi->peer->connection)) {
if (debug)
zlog_debug(
"%s: %pBD(%s) non self peer %s not estab state",
Expand Down Expand Up @@ -2903,7 +2903,7 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
if (pi->peer && pi->peer != bgp->peer_self
&& !CHECK_FLAG(pi->peer->sflags,
PEER_STATUS_NSF_WAIT))
if (!peer_established(pi->peer))
if (!peer_established(pi->peer->connection))
continue;

if (!bgp_path_info_nexthop_cmp(pi, new_select)) {
Expand Down Expand Up @@ -5173,7 +5173,7 @@ static void bgp_announce_route_timer_expired(struct event *t)
paf = EVENT_ARG(t);
peer = paf->peer;

if (!peer_established(peer))
if (!peer_established(peer->connection))
return;

if (!peer->afc_nego[paf->afi][paf->safi])
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_routemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -4340,7 +4340,7 @@ static void bgp_route_map_process_peer(const char *rmap_name,
&& (strcmp(rmap_name, filter->map[RMAP_IN].name) == 0)) {
filter->map[RMAP_IN].map = map;

if (route_update && peer_established(peer)) {
if (route_update && peer_established(peer->connection)) {
if (CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_SOFT_RECONFIG)) {
if (bgp_debug_update(peer, NULL, NULL, 1))
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_rpki.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ static void revalidate_all_routes(void)
if (!bgp->rib[afi][safi])
continue;

if (!peer_established(peer))
if (!peer_established(peer->connection))
continue;

rvp = XCALLOC(MTYPE_BGP_RPKI_REVALIDATE,
Expand Down
5 changes: 3 additions & 2 deletions bgpd/bgp_snmp_bgp4.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,10 +754,11 @@ int bgpTrapEstablished(struct peer *peer)
int ret;
struct in_addr addr;
oid index[sizeof(oid) * IN_ADDR_SIZE];
struct peer_connection *connection = peer->connection;

/* Check if this peer just went to Established */
if ((peer->connection->ostatus != OpenConfirm) ||
!(peer_established(peer)))
if ((connection->ostatus != OpenConfirm) ||
!(peer_established(connection)))
return 0;

ret = inet_aton(peer->host, &addr);
Expand Down
17 changes: 10 additions & 7 deletions bgpd/bgp_updgrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ static struct update_group *update_group_find(struct peer_af *paf)
struct update_group tmp;
struct peer tmp_conf;

if (!peer_established(PAF_PEER(paf)))
if (!peer_established((PAF_PEER(paf))->connection))
return NULL;

memset(&tmp, 0, sizeof(tmp));
Expand Down Expand Up @@ -1251,7 +1251,7 @@ static struct update_subgroup *update_subgroup_find(struct update_group *updgrp,
} else
version = 0;

if (!peer_established(PAF_PEER(paf)))
if (!peer_established(PAF_PEER(paf)->connection))
return NULL;

UPDGRP_FOREACH_SUBGRP (updgrp, subgrp) {
Expand Down Expand Up @@ -1945,7 +1945,7 @@ void update_group_adjust_peer(struct peer_af *paf)
return;

peer = PAF_PEER(paf);
if (!peer_established(peer)) {
if (!peer_established(peer->connection)) {
return;
}

Expand Down Expand Up @@ -2000,13 +2000,13 @@ int update_group_adjust_soloness(struct peer *peer, int set)

if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
peer_lonesoul_or_not(peer, set);
if (peer_established(peer))
if (peer_established(peer->connection))
bgp_announce_route_all(peer);
} else {
group = peer->group;
for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
peer_lonesoul_or_not(peer, set);
if (peer_established(peer))
if (peer_established(peer->connection))
bgp_announce_route_all(peer);
}
}
Expand Down Expand Up @@ -2199,13 +2199,16 @@ void subgroup_trigger_write(struct update_subgroup *subgrp)
* the subgroup output queue into their own output queue. This action
* will trigger a write job on the I/O thread.
*/
SUBGRP_FOREACH_PEER (subgrp, paf)
if (peer_established(paf->peer))
SUBGRP_FOREACH_PEER (subgrp, paf) {
struct peer_connection *connection = paf->peer->connection;

if (peer_established(connection))
event_add_timer_msec(bm->master,
bgp_generate_updgrp_packets,
paf->peer, 0,
&paf->peer->connection
->t_generate_updgrp_packets);
}
}

int update_group_clear_update_dbg(struct update_group *updgrp, void *arg)
Expand Down
Loading

0 comments on commit 7b1158b

Please sign in to comment.