]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Add connection direction to debug logs
authorDonald Sharp <sharpd@nvidia.com>
Sat, 15 Feb 2025 23:47:21 +0000 (18:47 -0500)
committerDonald Sharp <sharpd@nvidia.com>
Fri, 28 Feb 2025 15:28:50 +0000 (10:28 -0500)
Currently the incoming and outgoing connections mix up their
logs and there is absolutely no way to tell which way is being
talked about when both are operating.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
bgpd/bgp_fsm.c
bgpd/bgp_network.c
bgpd/bgpd.c
bgpd/bgpd.h

index c7a4c6928adf2ba9f788658d3340722159e936e4..b6025ea29fbfeebe6880847ee80463ec61bbae7d 100644 (file)
@@ -472,7 +472,8 @@ static void bgp_start_timer(struct event *thread)
        struct peer *peer = connection->peer;
 
        if (bgp_debug_neighbor_events(peer))
-               zlog_debug("%s [FSM] Timer (start timer expire).", peer->host);
+               zlog_debug("%s [FSM] Timer (start timer expire for %s).", peer->host,
+                          bgp_peer_get_connection_direction(connection));
 
        EVENT_VAL(thread) = BGP_Start;
        bgp_event(thread); /* bgp_event unlocks peer */
@@ -491,8 +492,8 @@ static void bgp_connect_timer(struct event *thread)
        assert(!connection->t_read);
 
        if (bgp_debug_neighbor_events(peer))
-               zlog_debug("%s [FSM] Timer (connect timer (%us) expire)", peer->host,
-                          peer->v_connect);
+               zlog_debug("%s [FSM] Timer (connect timer (%us) expire for %s)", peer->host,
+                          peer->v_connect, bgp_peer_get_connection_direction(connection));
 
        if (CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER))
                bgp_stop(connection);
@@ -512,8 +513,8 @@ static void bgp_holdtime_timer(struct event *thread)
        struct peer *peer = connection->peer;
 
        if (bgp_debug_neighbor_events(peer))
-               zlog_debug("%s [FSM] Timer (holdtime timer expire)",
-                          peer->host);
+               zlog_debug("%s [FSM] Timer (holdtime timer expire for %s)", peer->host,
+                          bgp_peer_get_connection_direction(connection));
 
        /*
         * Given that we do not have any expectation of ordering
@@ -542,7 +543,8 @@ void bgp_routeadv_timer(struct event *thread)
        struct peer *peer = connection->peer;
 
        if (bgp_debug_neighbor_events(peer))
-               zlog_debug("%s [FSM] Timer (routeadv timer expire)", peer->host);
+               zlog_debug("%s [FSM] Timer (routeadv timer expire for %s)", peer->host,
+                          bgp_peer_get_connection_direction(connection));
 
        peer->synctime = monotime(NULL);
 
@@ -561,8 +563,8 @@ void bgp_delayopen_timer(struct event *thread)
        struct peer *peer = connection->peer;
 
        if (bgp_debug_neighbor_events(peer))
-               zlog_debug("%s [FSM] Timer (DelayOpentimer expire)",
-                          peer->host);
+               zlog_debug("%s [FSM] Timer (DelayOpentimer expire for %s)", peer->host,
+                          bgp_peer_get_connection_direction(connection));
 
        EVENT_VAL(thread) = DelayOpen_timer_expired;
        bgp_event(thread); /* bgp_event unlocks peer */
@@ -628,8 +630,8 @@ static void bgp_graceful_restart_timer_off(struct peer_connection *connection,
        if (peer_dynamic_neighbor(peer) &&
            !(CHECK_FLAG(peer->flags, PEER_FLAG_DELETE))) {
                if (bgp_debug_neighbor_events(peer))
-                       zlog_debug("%s (dynamic neighbor) deleted (%s)",
-                                  peer->host, __func__);
+                       zlog_debug("%s (dynamic neighbor) deleted (%s) for %s", __func__,
+                                  peer->host, bgp_peer_get_connection_direction(connection));
                peer_delete(peer);
        }
 
@@ -654,8 +656,9 @@ static void bgp_llgr_stale_timer_expire(struct event *thread)
         * stale routes from the neighbor that it is retaining.
         */
        if (bgp_debug_neighbor_events(peer))
-               zlog_debug("%pBP Long-lived stale timer (%s) expired", peer,
-                          get_afi_safi_str(afi, safi, false));
+               zlog_debug("%pBP Long-lived stale timer (%s) expired for %s", peer,
+                          get_afi_safi_str(afi, safi, false),
+                          bgp_peer_get_connection_direction(peer->connection));
 
        UNSET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_LLGR_WAIT);
 
@@ -753,11 +756,9 @@ static void bgp_graceful_restart_timer_expire(struct event *thread)
        afi_t afi;
        safi_t safi;
 
-       if (bgp_debug_neighbor_events(peer)) {
-               zlog_debug("%pBP graceful restart timer expired", peer);
-               zlog_debug("%pBP graceful restart stalepath timer stopped",
-                          peer);
-       }
+       if (bgp_debug_neighbor_events(peer))
+               zlog_debug("%pBP graceful restart timer expired and graceful restart stalepath timer stopped for %s",
+                          peer, bgp_peer_get_connection_direction(connection));
 
        FOREACH_AFI_SAFI (afi, safi) {
                if (!peer->nsf[afi][safi])
@@ -781,11 +782,10 @@ static void bgp_graceful_restart_timer_expire(struct event *thread)
                                continue;
 
                        if (bgp_debug_neighbor_events(peer))
-                               zlog_debug(
-                                       "%pBP Long-lived stale timer (%s) started for %d sec",
-                                       peer,
-                                       get_afi_safi_str(afi, safi, false),
-                                       peer->llgr[afi][safi].stale_time);
+                               zlog_debug("%pBP Long-lived stale timer (%s) started for %d sec for %s",
+                                          peer, get_afi_safi_str(afi, safi, false),
+                                          peer->llgr[afi][safi].stale_time,
+                                          bgp_peer_get_connection_direction(connection));
 
                        SET_FLAG(peer->af_sflags[afi][safi],
                                 PEER_STATUS_LLGR_WAIT);
@@ -816,8 +816,8 @@ static void bgp_graceful_stale_timer_expire(struct event *thread)
        safi_t safi;
 
        if (bgp_debug_neighbor_events(peer))
-               zlog_debug("%pBP graceful restart stalepath timer expired",
-                          peer);
+               zlog_debug("%pBP graceful restart stalepath timer expired for %s", peer,
+                          bgp_peer_get_connection_direction(connection));
 
        /* NSF delete stale route */
        FOREACH_AFI_SAFI_NSF (afi, safi)
@@ -1242,10 +1242,10 @@ void bgp_fsm_change_status(struct peer_connection *connection,
        if (bgp_debug_neighbor_events(peer)) {
                struct vrf *vrf = vrf_lookup_by_id(bgp->vrf_id);
 
-               zlog_debug("%s : vrf %s(%u), Status: %s established_peers %u", __func__,
+               zlog_debug("%s : vrf %s(%u), Status: %s established_peers %u for %s", __func__,
                           vrf ? vrf->name : "Unknown", bgp->vrf_id,
-                          lookup_msg(bgp_status_msg, status, NULL),
-                          bgp->established_peers);
+                          lookup_msg(bgp_status_msg, status, NULL), bgp->established_peers,
+                          bgp_peer_get_connection_direction(connection));
        }
 
        /* Set to router ID to the value provided by RIB if there are no peers
@@ -1322,10 +1322,10 @@ void bgp_fsm_change_status(struct peer_connection *connection,
                bgp_update_delay_process_status_change(peer);
 
        if (bgp_debug_neighbor_events(peer))
-               zlog_debug("%s fd %d went from %s to %s", peer->host,
-                          connection->fd,
+               zlog_debug("%s fd %d went from %s to %s for %s", peer->host, connection->fd,
                           lookup_msg(bgp_status_msg, connection->ostatus, NULL),
-                          lookup_msg(bgp_status_msg, connection->status, NULL));
+                          lookup_msg(bgp_status_msg, connection->status, NULL),
+                          bgp_peer_get_connection_direction(connection));
 }
 
 /* Flush the event queue and ensure the peer is shut down */
@@ -1357,8 +1357,8 @@ enum bgp_fsm_state_progress bgp_stop(struct peer_connection *connection)
        if (peer_dynamic_neighbor_no_nsf(peer) &&
            !(CHECK_FLAG(peer->flags, PEER_FLAG_DELETE))) {
                if (bgp_debug_neighbor_events(peer))
-                       zlog_debug("%s (dynamic neighbor) deleted (%s)",
-                                  peer->host, __func__);
+                       zlog_debug("%s (dynamic neighbor) deleted (%s) for %s", __func__,
+                                  peer->host, bgp_peer_get_connection_direction(connection));
                peer_delete(peer);
                return BGP_FSM_FAILURE_AND_DELETE;
        }
@@ -1399,18 +1399,17 @@ enum bgp_fsm_state_progress bgp_stop(struct peer_connection *connection)
                if (connection->t_gr_stale) {
                        EVENT_OFF(connection->t_gr_stale);
                        if (bgp_debug_neighbor_events(peer))
-                               zlog_debug(
-                                       "%pBP graceful restart stalepath timer stopped",
-                                       peer);
+                               zlog_debug("%pBP graceful restart stalepath timer stopped for %s",
+                                          peer, bgp_peer_get_connection_direction(connection));
                }
                if (CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT)) {
                        if (bgp_debug_neighbor_events(peer)) {
-                               zlog_debug(
-                                       "%pBP graceful restart timer started for %d sec",
-                                       peer, peer->v_gr_restart);
-                               zlog_debug(
-                                       "%pBP graceful restart stalepath timer started for %d sec",
-                                       peer, peer->bgp->stalepath_time);
+                               zlog_debug("%pBP graceful restart timer started for %d sec for %s",
+                                          peer, peer->v_gr_restart,
+                                          bgp_peer_get_connection_direction(connection));
+                               zlog_debug("%pBP graceful restart stalepath timer started for %d sec for %s",
+                                          peer, peer->bgp->stalepath_time,
+                                          bgp_peer_get_connection_direction(connection));
                        }
                        BGP_TIMER_ON(connection->t_gr_restart,
                                     bgp_graceful_restart_timer_expire,
@@ -1430,9 +1429,8 @@ enum bgp_fsm_state_progress bgp_stop(struct peer_connection *connection)
                        EVENT_OFF(peer->t_refresh_stalepath);
 
                        if (bgp_debug_neighbor_events(peer))
-                               zlog_debug(
-                                       "%pBP route-refresh restart stalepath timer stopped",
-                                       peer);
+                               zlog_debug("%pBP route-refresh restart stalepath timer stopped for %s",
+                                          peer, bgp_peer_get_connection_direction(connection));
                }
 
                /* If peer reset before receiving EOR, decrement EOR count and
@@ -1454,9 +1452,9 @@ enum bgp_fsm_state_progress bgp_stop(struct peer_connection *connection)
                                        gr_info->eor_required--;
 
                                if (BGP_DEBUG(update, UPDATE_OUT))
-                                       zlog_debug("peer %s, EOR_required %d",
-                                                  peer->host,
-                                                  gr_info->eor_required);
+                                       zlog_debug("peer %s, EOR_required %d for %s", peer->host,
+                                                  gr_info->eor_required,
+                                                  bgp_peer_get_connection_direction(connection));
 
                                /* There is no pending EOR message */
                                if (gr_info->eor_required == 0) {
@@ -1475,8 +1473,8 @@ enum bgp_fsm_state_progress bgp_stop(struct peer_connection *connection)
                peer->resettime = peer->uptime = monotime(NULL);
 
                if (BGP_DEBUG(update_groups, UPDATE_GROUPS))
-                       zlog_debug("%s remove from all update group",
-                                  peer->host);
+                       zlog_debug("%s remove from all update group for %s", peer->host,
+                                  bgp_peer_get_connection_direction(connection));
                update_group_remove_peer_afs(peer);
 
                /* Reset peer synctime */
@@ -1522,6 +1520,7 @@ enum bgp_fsm_state_progress bgp_stop(struct peer_connection *connection)
        if (connection->fd >= 0) {
                close(connection->fd);
                connection->fd = -1;
+               connection->dir = UNKNOWN;
        }
 
        /* Reset capabilities. */
@@ -1596,8 +1595,8 @@ bgp_stop_with_error(struct peer_connection *connection)
 
        if (peer_dynamic_neighbor_no_nsf(peer)) {
                if (bgp_debug_neighbor_events(peer))
-                       zlog_debug("%s (dynamic neighbor) deleted (%s)",
-                                  peer->host, __func__);
+                       zlog_debug("%s (dynamic neighbor) deleted (%s) for %s", __func__,
+                                  peer->host, bgp_peer_get_connection_direction(connection));
                peer_delete(peer);
                return BGP_FSM_FAILURE;
        }
@@ -1618,8 +1617,8 @@ bgp_stop_with_notify(struct peer_connection *connection, uint8_t code,
 
        if (peer_dynamic_neighbor_no_nsf(peer)) {
                if (bgp_debug_neighbor_events(peer))
-                       zlog_debug("%s (dynamic neighbor) deleted (%s)",
-                                  peer->host, __func__);
+                       zlog_debug("%s (dynamic neighbor) deleted (%s) for %s", __func__,
+                                  peer->host, bgp_peer_get_connection_direction(connection));
                peer_delete(peer);
                return BGP_FSM_FAILURE;
        }
@@ -1684,8 +1683,9 @@ static void bgp_connect_check(struct event *thread)
                return;
        } else {
                if (bgp_debug_neighbor_events(peer))
-                       zlog_debug("%s [Event] Connect failed %d(%s)",
-                                  peer->host, status, safe_strerror(status));
+                       zlog_debug("%s [Event] Connect failed %d(%s) for connection %s", peer->host,
+                                  status, safe_strerror(status),
+                                  bgp_peer_get_connection_direction(connection));
                BGP_EVENT_ADD(connection, TCP_connection_open_failed);
                return;
        }
@@ -1724,10 +1724,12 @@ bgp_connect_success(struct peer_connection *connection)
 
        if (bgp_debug_neighbor_events(peer)) {
                if (!CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER))
-                       zlog_debug("%s open active, local address %pSU", peer->host,
-                                  connection->su_local);
+                       zlog_debug("%s open active, local address %pSU for %s", peer->host,
+                                  connection->su_local,
+                                  bgp_peer_get_connection_direction(connection));
                else
-                       zlog_debug("%s passive open", peer->host);
+                       zlog_debug("%s passive open for %s", peer->host,
+                                  bgp_peer_get_connection_direction(connection));
        }
 
        /* Send an open message */
@@ -1770,10 +1772,12 @@ bgp_connect_success_w_delayopen(struct peer_connection *connection)
 
        if (bgp_debug_neighbor_events(peer)) {
                if (!CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER))
-                       zlog_debug("%s open active, local address %pSU", peer->host,
-                                  connection->su_local);
+                       zlog_debug("%s open active, local address %pSU for %s", peer->host,
+                                  connection->su_local,
+                                  bgp_peer_get_connection_direction(connection));
                else
-                       zlog_debug("%s passive open", peer->host);
+                       zlog_debug("%s passive open for %s", peer->host,
+                                  bgp_peer_get_connection_direction(connection));
        }
 
        /* set the DelayOpenTime to the inital value */
@@ -1785,8 +1789,9 @@ bgp_connect_success_w_delayopen(struct peer_connection *connection)
                             peer->v_delayopen);
 
        if (bgp_debug_neighbor_events(peer))
-               zlog_debug("%s [FSM] BGP OPEN message delayed for %d seconds",
-                          peer->host, peer->delayopen);
+               zlog_debug("%s [FSM] BGP OPEN message delayed for %d seconds for connection %s",
+                          peer->host, peer->delayopen,
+                          bgp_peer_get_connection_direction(connection));
 
        return BGP_FSM_SUCCESS;
 }
@@ -1799,8 +1804,8 @@ bgp_connect_fail(struct peer_connection *connection)
 
        if (peer_dynamic_neighbor_no_nsf(peer)) {
                if (bgp_debug_neighbor_events(peer))
-                       zlog_debug("%s (dynamic neighbor) deleted (%s)",
-                                  peer->host, __func__);
+                       zlog_debug("%s (dynamic neighbor) deleted (%s) for %s", __func__,
+                                  peer->host, bgp_peer_get_connection_direction(connection));
                peer_delete(peer);
                return BGP_FSM_FAILURE_AND_DELETE;
        }
@@ -1843,9 +1848,8 @@ static enum bgp_fsm_state_progress bgp_start(struct peer_connection *connection)
 
        if (connection->su.sa.sa_family == AF_UNSPEC) {
                if (bgp_debug_neighbor_events(peer))
-                       zlog_debug(
-                               "%s [FSM] Unable to get neighbor's IP address, waiting...",
-                               peer->host);
+                       zlog_debug("%s [FSM] Unable to get neighbor's IP address, waiting... for %s",
+                                  peer->host, bgp_peer_get_connection_direction(connection));
                peer->last_reset = PEER_DOWN_NBR_ADDR;
                return BGP_FSM_FAILURE;
        }
@@ -1888,9 +1892,9 @@ static enum bgp_fsm_state_progress bgp_start(struct peer_connection *connection)
        if (!bgp_peer_reg_with_nht(peer)) {
                if (bgp_zebra_num_connects()) {
                        if (bgp_debug_neighbor_events(peer))
-                               zlog_debug(
-                                       "%s [FSM] Waiting for NHT, no path to neighbor present",
-                                       peer->host);
+                               zlog_debug("%s [FSM] Waiting for NHT, no path to neighbor present for %s",
+                                          peer->host,
+                                          bgp_peer_get_connection_direction(connection));
                        peer->last_reset = PEER_DOWN_WAITING_NHT;
                        BGP_EVENT_ADD(connection, TCP_connection_open_failed);
                        return BGP_FSM_SUCCESS;
@@ -1906,13 +1910,14 @@ static enum bgp_fsm_state_progress bgp_start(struct peer_connection *connection)
        switch (status) {
        case connect_error:
                if (bgp_debug_neighbor_events(peer))
-                       zlog_debug("%s [FSM] Connect error", peer->host);
+                       zlog_debug("%s [FSM] Connect error for %s", peer->host,
+                                  bgp_peer_get_connection_direction(connection));
                BGP_EVENT_ADD(connection, TCP_connection_open_failed);
                break;
        case connect_success:
                if (bgp_debug_neighbor_events(peer))
-                       zlog_debug("%s [FSM] Connect immediately success, fd %d",
-                                  peer->host, connection->fd);
+                       zlog_debug("%s [FSM] Connect immediately success, fd %d for %s", peer->host,
+                                  connection->fd, bgp_peer_get_connection_direction(connection));
 
                BGP_EVENT_ADD(connection, TCP_connection_open);
                break;
@@ -1920,8 +1925,9 @@ static enum bgp_fsm_state_progress bgp_start(struct peer_connection *connection)
                /* To check nonblocking connect, we wait until socket is
                   readable or writable. */
                if (bgp_debug_neighbor_events(peer))
-                       zlog_debug("%s [FSM] Non blocking connect waiting result, fd %d",
-                                  peer->host, connection->fd);
+                       zlog_debug("%s [FSM] Non blocking connect waiting result, fd %d for %s",
+                                  peer->host, connection->fd,
+                                  bgp_peer_get_connection_direction(connection));
                if (connection->fd < 0) {
                        flog_err(EC_BGP_FSM, "%s peer's fd is negative value %d",
                                 __func__, peer->connection->fd);
@@ -2003,7 +2009,8 @@ bgp_fsm_holdtime_expire(struct peer_connection *connection)
        struct peer *peer = connection->peer;
 
        if (bgp_debug_neighbor_events(peer))
-               zlog_debug("%s [FSM] Hold timer expire", peer->host);
+               zlog_debug("%s [FSM] Hold timer expire for %s", peer->host,
+                          bgp_peer_get_connection_direction(connection));
 
        /* RFC8538 updates RFC 4724 by defining an extension that permits
         * the Graceful Restart procedures to be performed when the BGP
@@ -2184,9 +2191,11 @@ bgp_establish(struct peer_connection *connection)
        UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT);
        if (bgp_debug_neighbor_events(peer)) {
                if (BGP_PEER_RESTARTING_MODE(peer))
-                       zlog_debug("%pBP BGP_RESTARTING_MODE", peer);
+                       zlog_debug("%pBP BGP_RESTARTING_MODE %s", peer,
+                                  bgp_peer_get_connection_direction(connection));
                else if (BGP_PEER_HELPER_MODE(peer))
-                       zlog_debug("%pBP BGP_HELPER_MODE", peer);
+                       zlog_debug("%pBP BGP_HELPER_MODE %s", peer,
+                                  bgp_peer_get_connection_direction(connection));
        }
 
        FOREACH_AFI_SAFI_NSF (afi, safi) {
@@ -2259,16 +2268,16 @@ bgp_establish(struct peer_connection *connection)
                if (connection->t_gr_stale) {
                        EVENT_OFF(connection->t_gr_stale);
                        if (bgp_debug_neighbor_events(peer))
-                               zlog_debug(
-                                       "%pBP graceful restart stalepath timer stopped",
-                                       peer);
+                               zlog_debug("%pBP graceful restart stalepath timer stopped for %s",
+                                          peer, bgp_peer_get_connection_direction(connection));
                }
        }
 
        if (connection->t_gr_restart) {
                EVENT_OFF(connection->t_gr_restart);
                if (bgp_debug_neighbor_events(peer))
-                       zlog_debug("%pBP graceful restart timer stopped", peer);
+                       zlog_debug("%pBP graceful restart timer stopped for %s", peer,
+                                  bgp_peer_get_connection_direction(connection));
        }
 
        /* Reset uptime, turn on keepalives, send current table. */
@@ -2284,9 +2293,9 @@ bgp_establish(struct peer_connection *connection)
                if (peer->t_llgr_stale[afi][safi]) {
                        EVENT_OFF(peer->t_llgr_stale[afi][safi]);
                        if (bgp_debug_neighbor_events(peer))
-                               zlog_debug(
-                                       "%pBP Long-lived stale timer stopped for afi/safi: %d/%d",
-                                       peer, afi, safi);
+                               zlog_debug("%pBP Long-lived stale timer stopped for afi/safi: %d/%d for %s",
+                                          peer, afi, safi,
+                                          bgp_peer_get_connection_direction(connection));
                }
 
                if (CHECK_FLAG(peer->af_cap[afi][safi],
@@ -2327,9 +2336,8 @@ bgp_establish(struct peer_connection *connection)
        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);
+                       zlog_debug("[Event] Deleting stub connection for peer %s for %s", peer->host,
+                                  bgp_peer_get_connection_direction(peer->doppelganger->connection));
 
                if (peer->doppelganger->connection->status > Active)
                        bgp_notify_send(peer->doppelganger->connection,
@@ -2636,11 +2644,10 @@ int bgp_event_update(struct peer_connection *connection,
        next = FSM[connection->status - 1][event - 1].next_state;
 
        if (bgp_debug_neighbor_events(peer) && connection->status != next)
-               zlog_debug("%s [FSM] %s (%s->%s), fd %d", peer->host,
-                          bgp_event_str[event],
+               zlog_debug("%s [FSM] %s (%s->%s), fd %d for %s", peer->host, bgp_event_str[event],
                           lookup_msg(bgp_status_msg, connection->status, NULL),
-                          lookup_msg(bgp_status_msg, next, NULL),
-                          connection->fd);
+                          lookup_msg(bgp_status_msg, next, NULL), connection->fd,
+                          bgp_peer_get_connection_direction(connection));
 
        peer->last_event = peer->cur_event;
        peer->cur_event = event;
index 3df4aa286eb3e62942679447f62416950aa716e5..d4e630d8025ddb3b389e54af1c97f1a970831236 100644 (file)
@@ -483,6 +483,7 @@ static void bgp_accept(struct event *thread)
                        connection1 = peer1->connection;
                        /* Dynamic neighbor has been created, let it proceed */
                        connection1->fd = bgp_sock;
+                       connection1->dir = CONNECTION_INCOMING;
 
                        connection1->su_local = sockunion_getsockname(connection1->fd);
                        connection1->su_remote = sockunion_dup(&su);
@@ -636,6 +637,7 @@ static void bgp_accept(struct event *thread)
        peer1->doppelganger = peer;
 
        connection->fd = bgp_sock;
+       connection->dir = CONNECTION_INCOMING;
        connection->su_local = sockunion_getsockname(connection->fd);
        connection->su_remote = sockunion_dup(&su);
 
@@ -801,6 +803,7 @@ enum connect_result bgp_connect(struct peer_connection *connection)
                connection->fd =
                        vrf_sockunion_socket(&connection->su, peer->bgp->vrf_id,
                                             bgp_get_bound_name(connection));
+               connection->dir = CONNECTION_OUTGOING;
        }
        if (connection->fd < 0) {
                peer->last_reset = PEER_DOWN_SOCKET_ERROR;
index cf1ea78acf32559becf09cbe79cf288d7a9b9a8e..6a56eb45987b215a8bc5755db8a0f21c412e73ff 100644 (file)
@@ -1180,6 +1180,22 @@ void bgp_peer_connection_free(struct peer_connection **connection)
        connection = NULL;
 }
 
+const char *bgp_peer_get_connection_direction(struct peer_connection *connection)
+{
+       switch (connection->dir) {
+       case UNKNOWN:
+               return "Unknown";
+       case CONNECTION_INCOMING:
+               return "Incoming";
+       case CONNECTION_OUTGOING:
+               return "Outgoing";
+       case ESTABLISHED:
+               return "Established";
+       }
+
+       assert(!"DEV Escape: Expected switch to take care of this state");
+}
+
 struct peer_connection *bgp_peer_connection_new(struct peer *peer)
 {
        struct peer_connection *connection;
@@ -1527,6 +1543,7 @@ struct peer *peer_new(struct bgp *bgp)
 
        /* Create buffers. */
        peer->connection = bgp_peer_connection_new(peer);
+       peer->connection->dir = CONNECTION_OUTGOING;
 
        /* Set default value. */
        peer->v_start = BGP_INIT_START_TIMER;
index d331adff886f2bfd33aaac07277ad2e237d76700..9b13270ca7048df3494de955e51d677bafe63a36 100644 (file)
@@ -1213,8 +1213,28 @@ struct addpath_paths_limit {
        uint16_t receive;
 };
 
+/*
+ * The peer data structure has a incoming and outgoing peer connection
+ * variables.  In the early stage of the FSM, it is possible to have
+ * both a incoming and outgoing connection at the same time.  These
+ * connections both have events scheduled to happen that both produce
+ * logs.  It is very hard to tell these debugs apart when looking at
+ * the log files so the debugs are now adding direction strings to
+ * help figure out what is going on.  At a later stage in the FSM
+ * one of the connections will be closed and the other one kept.
+ * The one being kept is moved to the ESTABLISHED connection direction
+ * so that debugs can be figured out.
+ */
+enum connection_direction {
+       UNKNOWN,
+       CONNECTION_INCOMING,
+       CONNECTION_OUTGOING,
+       ESTABLISHED,
+};
+
 struct peer_connection {
        struct peer *peer;
+       enum connection_direction dir;
 
        /* Status of the peer connection. */
        enum bgp_fsm_status status;
@@ -1263,6 +1283,7 @@ struct peer_connection {
        union sockunion *su_local;  /* Sockunion of local address. */
        union sockunion *su_remote; /* Sockunion of remote address. */
 };
+const char *bgp_peer_get_connection_direction(struct peer_connection *connection);
 extern struct peer_connection *bgp_peer_connection_new(struct peer *peer);
 extern void bgp_peer_connection_free(struct peer_connection **connection);
 extern void bgp_peer_connection_buffers_free(struct peer_connection *connection);