Skip to content

Commit

Permalink
bgpd: peer_active is connection oriented, make it so
Browse files Browse the repository at this point in the history
Signed-off-by: Donald Sharp <[email protected]>
  • Loading branch information
donaldsharp committed Nov 26, 2024
1 parent 1baeb81 commit 7bf3f53
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions bgpd/bgp_fsm.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ void bgp_timer_set(struct peer_connection *connection)
/* First entry point of peer's finite state machine. In Idle
status start timer is on unless peer is shutdown or peer is
inactive. All other timer must be turned off */
if (BGP_PEER_START_SUPPRESSED(peer) || !peer_active(peer)
|| peer->bgp->vrf_id == VRF_UNKNOWN) {
if (BGP_PEER_START_SUPPRESSED(peer) || !peer_active(connection) ||
peer->bgp->vrf_id == VRF_UNKNOWN) {
EVENT_OFF(connection->t_start);
} else {
BGP_TIMER_ON(connection->t_start, bgp_start_timer,
Expand Down
6 changes: 3 additions & 3 deletions bgpd/bgp_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ static void bgp_accept(struct event *thread)
bgp_fsm_change_status(connection1, Active);
EVENT_OFF(connection1->t_start);

if (peer_active(peer1)) {
if (peer_active(peer1->connection)) {
if (CHECK_FLAG(peer1->flags,
PEER_FLAG_TIMER_DELAYOPEN))
BGP_EVENT_ADD(connection1,
Expand Down Expand Up @@ -557,7 +557,7 @@ static void bgp_accept(struct event *thread)
}

/* Check that at least one AF is activated for the peer. */
if (!peer_active(peer1)) {
if (!peer_active(connection1)) {
if (bgp_debug_neighbor_events(peer1))
zlog_debug(
"%s - incoming conn rejected - no AF activated for peer",
Expand Down Expand Up @@ -658,7 +658,7 @@ static void bgp_accept(struct event *thread)
bgp_event_update(connection1, TCP_connection_closed);
}

if (peer_active(peer)) {
if (peer_active(peer->connection)) {
if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER_DELAYOPEN))
BGP_EVENT_ADD(connection, TCP_connection_open_w_delay);
else
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ void bgp_connected_add(struct bgp *bgp, struct connected *ifc)
!peer_established(peer->connection) &&
!CHECK_FLAG(peer->flags, PEER_FLAG_IFPEER_V6ONLY)) {
connection = peer->connection;
if (peer_active(peer))
if (peer_active(connection))
BGP_EVENT_ADD(connection, BGP_Stop);
BGP_EVENT_ADD(connection, BGP_Start);
}
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static void bgp_start_interface_nbrs(struct bgp *bgp, struct interface *ifp)
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
if (peer->conf_if && (strcmp(peer->conf_if, ifp->name) == 0) &&
!peer_established(peer->connection)) {
if (peer_active(peer))
if (peer_active(peer->connection))
BGP_EVENT_ADD(peer->connection, BGP_Stop);
BGP_EVENT_ADD(peer->connection, BGP_Start);
}
Expand Down
27 changes: 14 additions & 13 deletions bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ struct peer *peer_create(union sockunion *su, const char *conf_if,
bgp->coalesce_time = MIN(BGP_MAX_SUBGROUP_COALESCE_TIME, ct);
}

active = peer_active(peer);
active = peer_active(peer->connection);
if (!active) {
if (peer->connection->su.sa.sa_family == AF_UNSPEC)
peer->last_reset = PEER_DOWN_NBR_ADDR;
Expand Down Expand Up @@ -2019,7 +2019,7 @@ struct peer *peer_create(union sockunion *su, const char *conf_if,
if (bgp->autoshutdown)
peer_flag_set(peer, PEER_FLAG_SHUTDOWN);
/* Set up peer's events and timers. */
else if (!active && peer_active(peer))
else if (!active && peer_active(peer->connection))
bgp_timer_set(peer->connection);

bgp_peer_gr_flags_update(peer);
Expand Down Expand Up @@ -2412,13 +2412,13 @@ static int peer_activate_af(struct peer *peer, afi_t afi, safi_t safi)
if (peer_af_create(peer, afi, safi) == NULL)
return 1;

active = peer_active(peer);
active = peer_active(peer->connection);
peer->afc[afi][safi] = 1;

if (peer->group)
peer_group2peer_config_copy_af(peer->group, peer, afi, safi);

if (!active && peer_active(peer)) {
if (!active && peer_active(peer->connection)) {
bgp_timer_set(peer->connection);
} else {
peer->last_reset = PEER_DOWN_AF_ACTIVATE;
Expand Down Expand Up @@ -3358,7 +3358,7 @@ int peer_group_bind(struct bgp *bgp, union sockunion *su, struct peer *peer,
}

/* Set up peer's events and timers. */
if (peer_active(peer))
if (peer_active(peer->connection))
bgp_timer_set(peer->connection);
}

Expand Down Expand Up @@ -4599,9 +4599,11 @@ bool bgp_path_attribute_treat_as_withdraw(struct peer *peer, char *buf,
}

/* If peer is configured at least one address family return 1. */
bool peer_active(struct peer *peer)
bool peer_active(struct peer_connection *connection)
{
if (BGP_CONNECTION_SU_UNSPEC(peer->connection))
struct peer *peer = connection->peer;

if (BGP_CONNECTION_SU_UNSPEC(connection))
return false;

if (peer->bfd_config) {
Expand Down Expand Up @@ -6296,7 +6298,7 @@ int peer_timers_connect_set(struct peer *peer, uint32_t connect)
/* Skip peer-group mechanics for regular peers. */
if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
if (!peer_established(peer->connection)) {
if (peer_active(peer))
if (peer_active(peer->connection))
BGP_EVENT_ADD(peer->connection, BGP_Stop);
BGP_EVENT_ADD(peer->connection, BGP_Start);
}
Expand All @@ -6317,7 +6319,7 @@ int peer_timers_connect_set(struct peer *peer, uint32_t connect)
member->v_connect = connect;

if (!peer_established(member->connection)) {
if (peer_active(member))
if (peer_active(member->connection))
BGP_EVENT_ADD(member->connection, BGP_Stop);
BGP_EVENT_ADD(member->connection, BGP_Start);
}
Expand Down Expand Up @@ -6350,7 +6352,7 @@ int peer_timers_connect_unset(struct peer *peer)
/* Skip peer-group mechanics for regular peers. */
if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
if (!peer_established(peer->connection)) {
if (peer_active(peer))
if (peer_active(peer->connection))
BGP_EVENT_ADD(peer->connection, BGP_Stop);
BGP_EVENT_ADD(peer->connection, BGP_Start);
}
Expand All @@ -6371,7 +6373,7 @@ int peer_timers_connect_unset(struct peer *peer)
member->v_connect = peer->bgp->default_connect_retry;

if (!peer_established(member->connection)) {
if (peer_active(member))
if (peer_active(member->connection))
BGP_EVENT_ADD(member->connection, BGP_Stop);
BGP_EVENT_ADD(member->connection, BGP_Start);
}
Expand Down Expand Up @@ -8646,8 +8648,7 @@ static int peer_unshut_after_cfg(struct bgp *bgp)
peer->host);

peer->shut_during_cfg = false;
if (peer_active(peer) &&
peer->connection->status != Established) {
if (peer_active(peer->connection) && peer->connection->status != Established) {
if (peer->connection->status != Idle)
BGP_EVENT_ADD(peer->connection, BGP_Stop);
BGP_EVENT_ADD(peer->connection, BGP_Start);
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -2295,7 +2295,7 @@ extern struct peer *peer_unlock_with_caller(const char *, struct peer *);
extern enum bgp_peer_sort peer_sort(struct peer *peer);
extern enum bgp_peer_sort peer_sort_lookup(struct peer *peer);

extern bool peer_active(struct peer *);
extern bool peer_active(struct peer_connection *connection);
extern bool peer_active_nego(struct peer *);
extern bool peer_afc_received(struct peer *peer);
extern bool peer_afc_advertised(struct peer *peer);
Expand Down

0 comments on commit 7bf3f53

Please sign in to comment.