summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_fsm.c
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2021-06-03 23:13:52 +0200
committerDonald Sharp <sharpd@nvidia.com>2023-08-18 15:29:04 +0200
commite20c23fa5b06f1dcef4e99df5099e55251d9d9bd (patch)
tree778b6c5e4e80c6970f0a1973ae7c597c20631552 /bgpd/bgp_fsm.c
parentbgpd: READ and WRITE flags are a part of the connection (diff)
downloadfrr-e20c23fa5b06f1dcef4e99df5099e55251d9d9bd.tar.xz
frr-e20c23fa5b06f1dcef4e99df5099e55251d9d9bd.zip
bgpd: Move status and ostatus to `struct peer_connection`
The status and ostatus are a function of the `struct peer_connection` move it into that data structure. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Diffstat (limited to 'bgpd/bgp_fsm.c')
-rw-r--r--bgpd/bgp_fsm.c79
1 files changed, 45 insertions, 34 deletions
diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c
index 20a5c4ce3..b951ada19 100644
--- a/bgpd/bgp_fsm.c
+++ b/bgpd/bgp_fsm.c
@@ -233,16 +233,16 @@ static struct peer *peer_xfer_conn(struct peer *from_peer)
peer->v_gr_restart = from_peer->v_gr_restart;
peer->cap = from_peer->cap;
peer->remote_role = from_peer->remote_role;
- status = peer->status;
- pstatus = peer->ostatus;
+ status = peer->connection.status;
+ pstatus = peer->connection.ostatus;
last_evt = peer->last_event;
last_maj_evt = peer->last_major_event;
- peer->status = from_peer->status;
- peer->ostatus = from_peer->ostatus;
+ peer->connection.status = from_peer->connection.status;
+ peer->connection.ostatus = from_peer->connection.ostatus;
peer->last_event = from_peer->last_event;
peer->last_major_event = from_peer->last_major_event;
- from_peer->status = status;
- from_peer->ostatus = pstatus;
+ from_peer->connection.status = status;
+ from_peer->connection.ostatus = pstatus;
from_peer->last_event = last_evt;
from_peer->last_major_event = last_maj_evt;
peer->remote_id = from_peer->remote_id;
@@ -310,7 +310,7 @@ static struct peer *peer_xfer_conn(struct peer *from_peer)
BGP_EVENT_ADD(from_peer, BGP_Stop);
return NULL;
}
- if (from_peer->status > Active) {
+ if (from_peer->connection.status > Active) {
if (bgp_getsockname(from_peer) < 0) {
flog_err(EC_LIB_SOCKET,
"%%bgp_getsockname() failed for %s from_peer %s fd %d (peer fd %d)",
@@ -354,7 +354,7 @@ void bgp_timer_set(struct peer *peer)
afi_t afi;
safi_t safi;
- switch (peer->status) {
+ switch (peer->connection.status) {
case Idle:
/* First entry point of peer's finite state machine. In Idle
status start timer is on unless peer is shutdown or peer is
@@ -1225,8 +1225,8 @@ static void bgp_update_delay_process_status_change(struct peer *peer)
if (CHECK_FLAG(peer->cap, PEER_CAP_GRACEFUL_RESTART_R_BIT_RCV))
bgp_update_restarted_peers(peer);
}
- if (peer->ostatus == Established
- && bgp_update_delay_active(peer->bgp)) {
+ if (peer->connection.ostatus == Established &&
+ bgp_update_delay_active(peer->bgp)) {
/* Adjust the update-delay state to account for this flap.
NOTE: Intentionally skipping adjusting implicit_eors or
explicit_eors
@@ -1302,14 +1302,15 @@ void bgp_fsm_change_status(struct peer *peer, enum bgp_fsm_status status)
}
/* Preserve old status and change into new status. */
- peer->ostatus = peer->status;
- peer->status = status;
+ peer->connection.ostatus = peer->connection.status;
+ peer->connection.status = status;
/* Reset received keepalives counter on every FSM change */
peer->rtt_keepalive_rcv = 0;
/* Fire backward transition hook if that's the case */
- if (peer->ostatus == Established && peer->status != Established)
+ if (peer->connection.ostatus == Established &&
+ peer->connection.status != Established)
hook_call(peer_backward_transition, peer);
/* Save event that caused status change. */
@@ -1338,8 +1339,10 @@ void bgp_fsm_change_status(struct peer *peer, enum bgp_fsm_status status)
if (bgp_debug_neighbor_events(peer))
zlog_debug("%s fd %d went from %s to %s", peer->host,
peer->connection.fd,
- lookup_msg(bgp_status_msg, peer->ostatus, NULL),
- lookup_msg(bgp_status_msg, peer->status, NULL));
+ lookup_msg(bgp_status_msg, peer->connection.ostatus,
+ NULL),
+ lookup_msg(bgp_status_msg, peer->connection.status,
+ NULL));
}
/* Flush the event queue and ensure the peer is shut down */
@@ -1381,7 +1384,7 @@ enum bgp_fsm_state_progress bgp_stop(struct peer *peer)
}
/* Can't do this in Clearing; events are used for state transitions */
- if (peer->status != Clearing) {
+ if (peer->connection.status != Clearing) {
/* Delete all existing events of the peer */
BGP_EVENT_FLUSH(peer);
}
@@ -1556,7 +1559,8 @@ enum bgp_fsm_state_progress bgp_stop(struct peer *peer)
/* Received ORF prefix-filter */
peer->orf_plist[afi][safi] = NULL;
- if ((peer->status == OpenConfirm) || (peer_established(peer))) {
+ if ((peer->connection.status == OpenConfirm) ||
+ peer_established(peer)) {
/* ORF received prefix-filter pnt */
snprintf(orf_name, sizeof(orf_name), "%s.%d.%d",
peer->host, afi, safi);
@@ -1711,7 +1715,7 @@ static enum bgp_fsm_state_progress bgp_connect_success(struct peer *peer)
"%s: bgp_getsockname(): failed for peer %s, fd %d",
__func__, peer->host, peer->connection.fd);
bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR,
- bgp_fsm_error_subcode(peer->status));
+ bgp_fsm_error_subcode(peer->connection.status));
bgp_writes_on(&peer->connection);
return BGP_FSM_FAILURE;
}
@@ -1755,7 +1759,7 @@ bgp_connect_success_w_delayopen(struct peer *peer)
"%s: bgp_getsockname(): failed for peer %s, fd %d",
__func__, peer->host, peer->connection.fd);
bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR,
- bgp_fsm_error_subcode(peer->status));
+ bgp_fsm_error_subcode(peer->connection.status));
bgp_writes_on(&peer->connection);
return BGP_FSM_FAILURE;
}
@@ -1965,7 +1969,8 @@ static enum bgp_fsm_state_progress bgp_reconnect(struct peer *peer)
static enum bgp_fsm_state_progress bgp_fsm_open(struct peer *peer)
{
/* If DelayOpen is active, we may still need to send an open message */
- if ((peer->status == Connect) || (peer->status == Active))
+ if ((peer->connection.status == Connect) ||
+ (peer->connection.status == Active))
bgp_open_send(peer);
/* Send keepalive and make keepalive timer */
@@ -1979,10 +1984,12 @@ static enum bgp_fsm_state_progress bgp_fsm_open(struct peer *peer)
static enum bgp_fsm_state_progress bgp_fsm_event_error(struct peer *peer)
{
flog_err(EC_BGP_FSM, "%s [FSM] unexpected packet received in state %s",
- peer->host, lookup_msg(bgp_status_msg, peer->status, NULL));
+ peer->host,
+ lookup_msg(bgp_status_msg, peer->connection.status, NULL));
return bgp_stop_with_notify(peer, BGP_NOTIFY_FSM_ERR,
- bgp_fsm_error_subcode(peer->status));
+ bgp_fsm_error_subcode(
+ peer->connection.status));
}
/* Hold timer expire. This is error of BGP connection. So cut the
@@ -2288,13 +2295,14 @@ static enum bgp_fsm_state_progress bgp_establish(struct peer *peer)
BGP_TIMER_ON(peer->t_routeadv, bgp_routeadv_timer, 0);
}
- if (peer->doppelganger && (peer->doppelganger->status != Deleted)) {
+ if (peer->doppelganger &&
+ (peer->doppelganger->connection.status != Deleted)) {
if (bgp_debug_neighbor_events(peer))
zlog_debug(
"[Event] Deleting stub connection for peer %s",
peer->host);
- if (peer->doppelganger->status > Active)
+ if (peer->doppelganger->connection.status > Active)
bgp_notify_send(peer->doppelganger, BGP_NOTIFY_CEASE,
BGP_NOTIFY_CEASE_COLLISION_RESOLUTION);
else
@@ -2336,7 +2344,7 @@ static enum bgp_fsm_state_progress bgp_ignore(struct peer *peer)
flog_err(EC_BGP_FSM,
"%s [FSM] Ignoring event %s in state %s, prior events %s, %s, fd %d",
peer->host, bgp_event_str[peer->cur_event],
- lookup_msg(bgp_status_msg, peer->status, NULL),
+ lookup_msg(bgp_status_msg, peer->connection.status, NULL),
bgp_event_str[peer->last_event],
bgp_event_str[peer->last_major_event], peer->connection.fd);
return BGP_FSM_SUCCESS;
@@ -2348,7 +2356,7 @@ static enum bgp_fsm_state_progress bgp_fsm_exception(struct peer *peer)
flog_err(EC_BGP_FSM,
"%s [FSM] Unexpected event %s in state %s, prior events %s, %s, fd %d",
peer->host, bgp_event_str[peer->cur_event],
- lookup_msg(bgp_status_msg, peer->status, NULL),
+ lookup_msg(bgp_status_msg, peer->connection.status, NULL),
bgp_event_str[peer->last_event],
bgp_event_str[peer->last_major_event], peer->connection.fd);
return bgp_stop(peer);
@@ -2359,7 +2367,7 @@ void bgp_fsm_nht_update(struct peer *peer, bool has_valid_nexthops)
if (!peer)
return;
- switch (peer->status) {
+ switch (peer->connection.status) {
case Idle:
if (has_valid_nexthops)
BGP_EVENT_ADD(peer, BGP_Start);
@@ -2588,12 +2596,13 @@ int bgp_event_update(struct peer *peer, enum bgp_fsm_events event)
dyn_nbr = peer_dynamic_neighbor(peer);
/* Logging this event. */
- next = FSM[peer->status - 1][event - 1].next_state;
+ next = FSM[peer->connection.status - 1][event - 1].next_state;
- if (bgp_debug_neighbor_events(peer) && peer->status != next)
+ if (bgp_debug_neighbor_events(peer) && peer->connection.status != next)
zlog_debug("%s [FSM] %s (%s->%s), fd %d", peer->host,
bgp_event_str[event],
- lookup_msg(bgp_status_msg, peer->status, NULL),
+ lookup_msg(bgp_status_msg, peer->connection.status,
+ NULL),
lookup_msg(bgp_status_msg, next, NULL),
peer->connection.fd);
@@ -2601,8 +2610,9 @@ int bgp_event_update(struct peer *peer, enum bgp_fsm_events event)
peer->cur_event = event;
/* Call function. */
- if (FSM[peer->status - 1][event - 1].func)
- ret = (*(FSM[peer->status - 1][event - 1].func))(peer);
+ if (FSM[peer->connection.status - 1][event - 1].func)
+ ret = (*(FSM[peer->connection.status - 1][event - 1].func))(
+ peer);
if (ret >= BGP_FSM_SUCCESS) {
if (ret == BGP_FSM_SUCCESS_STATE_TRANSFER &&
@@ -2615,7 +2625,7 @@ int bgp_event_update(struct peer *peer, enum bgp_fsm_events event)
}
/* If status is changed. */
- if (next != peer->status) {
+ if (next != peer->connection.status) {
bgp_fsm_change_status(peer, next);
/*
@@ -2645,7 +2655,8 @@ int bgp_event_update(struct peer *peer, enum bgp_fsm_events event)
flog_err(EC_BGP_FSM,
"%s [FSM] Failure handling event %s in state %s, prior events %s, %s, fd %d, last reset: %s",
peer->host, bgp_event_str[peer->cur_event],
- lookup_msg(bgp_status_msg, peer->status, NULL),
+ lookup_msg(bgp_status_msg,
+ peer->connection.status, NULL),
bgp_event_str[peer->last_event],
bgp_event_str[peer->last_major_event],
peer->connection.fd,