Merge pull request #10942 from opensourcerouting/feature/printfrr_extension_for_peer_hostname

bgpd: Add `%pBP` printfrr() extension to print `IP(hostname)` for BGP peer
This commit is contained in:
Donald Sharp 2022-04-01 11:28:47 -04:00 committed by GitHub
commit ef0b66450d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 132 additions and 140 deletions

View File

@ -677,8 +677,7 @@ static void bgp_llgr_stale_timer_expire(struct thread *thread)
* stale routes from the neighbor that it is retaining. * stale routes from the neighbor that it is retaining.
*/ */
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug("%s(%s) Long-lived stale timer (%s) expired", zlog_debug("%pBP Long-lived stale timer (%s) expired", peer,
peer->host, bgp_peer_hostname(peer),
get_afi_safi_str(afi, safi, false)); get_afi_safi_str(afi, safi, false));
UNSET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_LLGR_WAIT); UNSET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_LLGR_WAIT);
@ -720,10 +719,8 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi)
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) Long-lived set stale community (LLGR_STALE) for: %pFX", "%pBP Long-lived set stale community (LLGR_STALE) for: %pFX",
peer->host, peer, &dest->p);
bgp_peer_hostname(peer),
&dest->p);
attr = *pi->attr; attr = *pi->attr;
bgp_attr_add_llgr_community(&attr); bgp_attr_add_llgr_community(&attr);
@ -750,10 +747,8 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi)
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) Long-lived set stale community (LLGR_STALE) for: %pFX", "%pBP Long-lived set stale community (LLGR_STALE) for: %pFX",
peer->host, peer, &dest->p);
bgp_peer_hostname(peer),
&dest->p);
attr = *pi->attr; attr = *pi->attr;
bgp_attr_add_llgr_community(&attr); bgp_attr_add_llgr_community(&attr);
@ -777,10 +772,9 @@ static void bgp_graceful_restart_timer_expire(struct thread *thread)
peer = THREAD_ARG(thread); peer = THREAD_ARG(thread);
if (bgp_debug_neighbor_events(peer)) { if (bgp_debug_neighbor_events(peer)) {
zlog_debug("%s(%s) graceful restart timer expired", peer->host, zlog_debug("%pBP graceful restart timer expired", peer);
bgp_peer_hostname(peer)); zlog_debug("%pBP graceful restart stalepath timer stopped",
zlog_debug("%s(%s) graceful restart stalepath timer stopped", peer);
peer->host, bgp_peer_hostname(peer));
} }
FOREACH_AFI_SAFI (afi, safi) { FOREACH_AFI_SAFI (afi, safi) {
@ -806,8 +800,8 @@ static void bgp_graceful_restart_timer_expire(struct thread *thread)
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) Long-lived stale timer (%s) started for %d sec", "%pBP Long-lived stale timer (%s) started for %d sec",
peer->host, bgp_peer_hostname(peer), peer,
get_afi_safi_str(afi, safi, false), get_afi_safi_str(afi, safi, false),
peer->llgr[afi][safi].stale_time); peer->llgr[afi][safi].stale_time);
@ -842,8 +836,8 @@ static void bgp_graceful_stale_timer_expire(struct thread *thread)
peer = THREAD_ARG(thread); peer = THREAD_ARG(thread);
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug("%s(%s) graceful restart stalepath timer expired", zlog_debug("%pBP graceful restart stalepath timer expired",
peer->host, bgp_peer_hostname(peer)); peer);
/* NSF delete stale route */ /* NSF delete stale route */
FOREACH_AFI_SAFI_NSF (afi, safi) FOREACH_AFI_SAFI_NSF (afi, safi)
@ -1395,8 +1389,8 @@ int bgp_stop(struct peer *peer)
struct vrf *vrf = vrf_lookup_by_id(peer->bgp->vrf_id); struct vrf *vrf = vrf_lookup_by_id(peer->bgp->vrf_id);
zlog_info( zlog_info(
"%%ADJCHANGE: neighbor %s(%s) in vrf %s Down %s", "%%ADJCHANGE: neighbor %pBP in vrf %s Down %s",
peer->host, bgp_peer_hostname(peer), peer,
vrf ? ((vrf->vrf_id != VRF_DEFAULT) vrf ? ((vrf->vrf_id != VRF_DEFAULT)
? vrf->name ? vrf->name
: VRF_DEFAULT_NAME) : VRF_DEFAULT_NAME)
@ -1409,19 +1403,17 @@ int bgp_stop(struct peer *peer)
BGP_TIMER_OFF(peer->t_gr_stale); BGP_TIMER_OFF(peer->t_gr_stale);
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) graceful restart stalepath timer stopped", "%pBP graceful restart stalepath timer stopped",
peer->host, bgp_peer_hostname(peer)); peer);
} }
if (CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT)) { if (CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT)) {
if (bgp_debug_neighbor_events(peer)) { if (bgp_debug_neighbor_events(peer)) {
zlog_debug( zlog_debug(
"%s(%s) graceful restart timer started for %d sec", "%pBP graceful restart timer started for %d sec",
peer->host, bgp_peer_hostname(peer), peer, peer->v_gr_restart);
peer->v_gr_restart);
zlog_debug( zlog_debug(
"%s(%s) graceful restart stalepath timer started for %d sec", "%pBP graceful restart stalepath timer started for %d sec",
peer->host, bgp_peer_hostname(peer), peer, peer->bgp->stalepath_time);
peer->bgp->stalepath_time);
} }
BGP_TIMER_ON(peer->t_gr_restart, BGP_TIMER_ON(peer->t_gr_restart,
bgp_graceful_restart_timer_expire, bgp_graceful_restart_timer_expire,
@ -1442,8 +1434,8 @@ int bgp_stop(struct peer *peer)
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) route-refresh restart stalepath timer stopped", "%pBP route-refresh restart stalepath timer stopped",
peer->host, bgp_peer_hostname(peer)); peer);
} }
/* If peer reset before receiving EOR, decrement EOR count and /* If peer reset before receiving EOR, decrement EOR count and
@ -2099,8 +2091,7 @@ static int bgp_establish(struct peer *peer)
/* bgp log-neighbor-changes of neighbor Up */ /* bgp log-neighbor-changes of neighbor Up */
if (CHECK_FLAG(peer->bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)) { if (CHECK_FLAG(peer->bgp->flags, BGP_FLAG_LOG_NEIGHBOR_CHANGES)) {
struct vrf *vrf = vrf_lookup_by_id(peer->bgp->vrf_id); struct vrf *vrf = vrf_lookup_by_id(peer->bgp->vrf_id);
zlog_info("%%ADJCHANGE: neighbor %s(%s) in vrf %s Up", zlog_info("%%ADJCHANGE: neighbor %pBP in vrf %s Up", peer,
peer->host, bgp_peer_hostname(peer),
vrf ? ((vrf->vrf_id != VRF_DEFAULT) vrf ? ((vrf->vrf_id != VRF_DEFAULT)
? vrf->name ? vrf->name
: VRF_DEFAULT_NAME) : VRF_DEFAULT_NAME)
@ -2113,9 +2104,9 @@ static int bgp_establish(struct peer *peer)
UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT); UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT);
if (bgp_debug_neighbor_events(peer)) { if (bgp_debug_neighbor_events(peer)) {
if (BGP_PEER_RESTARTING_MODE(peer)) if (BGP_PEER_RESTARTING_MODE(peer))
zlog_debug("peer %s BGP_RESTARTING_MODE", peer->host); zlog_debug("%pBP BGP_RESTARTING_MODE", peer);
else if (BGP_PEER_HELPER_MODE(peer)) else if (BGP_PEER_HELPER_MODE(peer))
zlog_debug("peer %s BGP_HELPER_MODE", peer->host); zlog_debug("%pBP BGP_HELPER_MODE", peer);
} }
FOREACH_AFI_SAFI_NSF (afi, safi) { FOREACH_AFI_SAFI_NSF (afi, safi) {
@ -2189,16 +2180,15 @@ static int bgp_establish(struct peer *peer)
BGP_TIMER_OFF(peer->t_gr_stale); BGP_TIMER_OFF(peer->t_gr_stale);
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) graceful restart stalepath timer stopped", "%pBP graceful restart stalepath timer stopped",
peer->host, bgp_peer_hostname(peer)); peer);
} }
} }
if (peer->t_gr_restart) { if (peer->t_gr_restart) {
BGP_TIMER_OFF(peer->t_gr_restart); BGP_TIMER_OFF(peer->t_gr_restart);
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug("%s(%s) graceful restart timer stopped", zlog_debug("%pBP graceful restart timer stopped", peer);
peer->host, bgp_peer_hostname(peer));
} }
/* Reset uptime, turn on keepalives, send current table. */ /* Reset uptime, turn on keepalives, send current table. */
@ -2215,8 +2205,8 @@ static int bgp_establish(struct peer *peer)
BGP_TIMER_OFF(peer->t_llgr_stale[afi][safi]); BGP_TIMER_OFF(peer->t_llgr_stale[afi][safi]);
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s Long-lived stale timer stopped for afi/safi: %d/%d", "%pBP Long-lived stale timer stopped for afi/safi: %d/%d",
peer->host, afi, safi); peer, afi, safi);
} }
if (CHECK_FLAG(peer->af_cap[afi][safi], if (CHECK_FLAG(peer->af_cap[afi][safi],

View File

@ -313,14 +313,14 @@ static int bgp_nlri_get_labels(struct peer *peer, uint8_t *pnt, uint8_t plen,
/* If we RX multiple labels we will end up keeping only the last /* If we RX multiple labels we will end up keeping only the last
* one. We do not yet support a label stack greater than 1. */ * one. We do not yet support a label stack greater than 1. */
if (label_depth > 1) if (label_depth > 1)
zlog_info("%s rcvd UPDATE with label stack %d deep", peer->host, zlog_info("%pBP rcvd UPDATE with label stack %d deep", peer,
label_depth); label_depth);
if (!(bgp_is_withdraw_label(label) || label_bos(label))) if (!(bgp_is_withdraw_label(label) || label_bos(label)))
flog_warn( flog_warn(
EC_BGP_INVALID_LABEL_STACK, EC_BGP_INVALID_LABEL_STACK,
"%s rcvd UPDATE with invalid label stack - no bottom of stack", "%pBP rcvd UPDATE with invalid label stack - no bottom of stack",
peer->host); peer);
return llen; return llen;
} }

View File

@ -483,10 +483,8 @@ void bgp_generate_updgrp_packets(struct thread *thread)
if (bgp_debug_neighbor_events( if (bgp_debug_neighbor_events(
peer)) peer))
zlog_debug( zlog_debug(
"%s(%s) sending route-refresh (EoRR) for %s/%s", "%pBP sending route-refresh (EoRR) for %s/%s",
peer->host, peer,
bgp_peer_hostname(
peer),
afi2str(afi), afi2str(afi),
safi2str(safi)); safi2str(safi));
} }
@ -915,10 +913,8 @@ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi,
stream_putc(s, ORF_COMMON_PART_REMOVE_ALL); stream_putc(s, ORF_COMMON_PART_REMOVE_ALL);
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) sending REFRESH_REQ to remove ORF(%d) (%s) for afi/safi: %s/%s", "%pBP sending REFRESH_REQ to remove ORF(%d) (%s) for afi/safi: %s/%s",
peer->host, peer, orf_type,
bgp_peer_hostname(peer),
orf_type,
(when_to_refresh == (when_to_refresh ==
REFRESH_DEFER REFRESH_DEFER
? "defer" ? "defer"
@ -935,10 +931,8 @@ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi,
ORF_COMMON_PART_DENY); ORF_COMMON_PART_DENY);
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) sending REFRESH_REQ with pfxlist ORF(%d) (%s) for afi/safi: %s/%s", "%pBP sending REFRESH_REQ with pfxlist ORF(%d) (%s) for afi/safi: %s/%s",
peer->host, peer, orf_type,
bgp_peer_hostname(peer),
orf_type,
(when_to_refresh == (when_to_refresh ==
REFRESH_DEFER REFRESH_DEFER
? "defer" ? "defer"
@ -958,9 +952,9 @@ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi,
if (bgp_debug_neighbor_events(peer)) { if (bgp_debug_neighbor_events(peer)) {
if (!orf_refresh) if (!orf_refresh)
zlog_debug( zlog_debug(
"%s(%s) sending REFRESH_REQ for afi/safi: %s/%s", "%pBP sending REFRESH_REQ for afi/safi: %s/%s",
peer->host, bgp_peer_hostname(peer), peer, iana_afi2str(pkt_afi),
iana_afi2str(pkt_afi), iana_safi2str(pkt_safi)); iana_safi2str(pkt_safi));
} }
/* Add packet to the peer. */ /* Add packet to the peer. */
@ -1004,8 +998,8 @@ void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi,
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) sending CAPABILITY has %s MP_EXT CAP for afi/safi: %s/%s", "%pBP sending CAPABILITY has %s MP_EXT CAP for afi/safi: %s/%s",
peer->host, bgp_peer_hostname(peer), peer,
action == CAPABILITY_ACTION_SET ? "Advertising" action == CAPABILITY_ACTION_SET ? "Advertising"
: "Removing", : "Removing",
iana_afi2str(pkt_afi), iana_safi2str(pkt_safi)); iana_afi2str(pkt_afi), iana_safi2str(pkt_safi));
@ -1561,8 +1555,8 @@ static void bgp_refresh_stalepath_timer_expire(struct thread *thread)
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) route-refresh (BoRR) timer expired for afi/safi: %d/%d", "%pBP route-refresh (BoRR) timer expired for afi/safi: %d/%d",
peer->host, bgp_peer_hostname(peer), afi, safi); peer, afi, safi);
bgp_timer_set(peer); bgp_timer_set(peer);
} }
@ -1714,12 +1708,11 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size)
if (attr_parse_ret == BGP_ATTR_PARSE_WITHDRAW) if (attr_parse_ret == BGP_ATTR_PARSE_WITHDRAW)
flog_err( flog_err(
EC_BGP_UPDATE_RCV, EC_BGP_UPDATE_RCV,
"%s rcvd UPDATE with errors in attr(s)!! Withdrawing route.", "%pBP rcvd UPDATE with errors in attr(s)!! Withdrawing route.",
peer->host); peer);
if (ret && bgp_debug_update(peer, NULL, NULL, 1)) { if (ret && bgp_debug_update(peer, NULL, NULL, 1)) {
zlog_debug("%s(%s) rcvd UPDATE w/ attr: %s", peer->host, zlog_debug("%pBP rcvd UPDATE w/ attr: %s", peer,
bgp_peer_hostname(peer),
peer->rcvd_attr_str); peer->rcvd_attr_str);
peer->rcvd_attr_printed = 1; peer->rcvd_attr_printed = 1;
} }
@ -1749,9 +1742,8 @@ static int bgp_update_receive(struct peer *peer, bgp_size_t size)
} }
if (BGP_DEBUG(update, UPDATE_IN)) if (BGP_DEBUG(update, UPDATE_IN))
zlog_debug("%s(%s) rcvd UPDATE wlen %d attrlen %d alen %d", zlog_debug("%pBP rcvd UPDATE wlen %d attrlen %d alen %d", peer,
peer->host, bgp_peer_hostname(peer), withdraw_len, withdraw_len, attribute_len, update_len);
attribute_len, update_len);
/* Parse any given NLRIs */ /* Parse any given NLRIs */
for (int i = NLRI_UPDATE; i < NLRI_TYPE_MAX; i++) { for (int i = NLRI_UPDATE; i < NLRI_TYPE_MAX; i++) {
@ -2104,8 +2096,8 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
if (bgp_debug_neighbor_events(peer)) { if (bgp_debug_neighbor_events(peer)) {
zlog_debug( zlog_debug(
"%s rcvd Prefixlist ORF(%d) length %d", "%pBP rcvd Prefixlist ORF(%d) length %d",
peer->host, orf_type, orf_len); peer, orf_type, orf_len);
} }
/* we're going to read at least 1 byte of common /* we're going to read at least 1 byte of common
@ -2137,8 +2129,8 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
if (bgp_debug_neighbor_events( if (bgp_debug_neighbor_events(
peer)) peer))
zlog_debug( zlog_debug(
"%s rcvd Remove-All pfxlist ORF request", "%pBP rcvd Remove-All pfxlist ORF request",
peer->host); peer);
prefix_bgp_orf_remove_all(afi, prefix_bgp_orf_remove_all(afi,
name); name);
break; break;
@ -2189,8 +2181,8 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
char buf[INET6_BUFSIZ]; char buf[INET6_BUFSIZ];
zlog_debug( zlog_debug(
"%s rcvd %s %s seq %u %s/%d ge %d le %d%s", "%pBP rcvd %s %s seq %u %s/%d ge %d le %d%s",
peer->host, peer,
(common & ORF_COMMON_PART_REMOVE (common & ORF_COMMON_PART_REMOVE
? "Remove" ? "Remove"
: "Add"), : "Add"),
@ -2220,8 +2212,8 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
if (!ok || (ok && ret != CMD_SUCCESS)) { if (!ok || (ok && ret != CMD_SUCCESS)) {
zlog_info( zlog_info(
"%s Received misformatted prefixlist ORF. Remove All pfxlist", "%pBP Received misformatted prefixlist ORF. Remove All pfxlist",
peer->host); peer);
prefix_bgp_orf_remove_all(afi, prefix_bgp_orf_remove_all(afi,
name); name);
break; break;
@ -2234,7 +2226,7 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
stream_forward_getp(s, orf_len); stream_forward_getp(s, orf_len);
} }
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug("%s rcvd Refresh %s ORF request", peer->host, zlog_debug("%pBP rcvd Refresh %s ORF request", peer,
when_to_refresh == REFRESH_DEFER when_to_refresh == REFRESH_DEFER
? "Defer" ? "Defer"
: "Immediate"); : "Immediate");
@ -2285,18 +2277,16 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
PEER_STATUS_EOR_RECEIVED)) { PEER_STATUS_EOR_RECEIVED)) {
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) rcvd route-refresh (BoRR) for %s/%s before EoR", "%pBP rcvd route-refresh (BoRR) for %s/%s before EoR",
peer->host, bgp_peer_hostname(peer), peer, afi2str(afi), safi2str(safi));
afi2str(afi), safi2str(safi));
return BGP_PACKET_NOOP; return BGP_PACKET_NOOP;
} }
if (peer->t_refresh_stalepath) { if (peer->t_refresh_stalepath) {
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) rcvd route-refresh (BoRR) for %s/%s, whereas BoRR already received", "%pBP rcvd route-refresh (BoRR) for %s/%s, whereas BoRR already received",
peer->host, bgp_peer_hostname(peer), peer, afi2str(afi), safi2str(safi));
afi2str(afi), safi2str(safi));
return BGP_PACKET_NOOP; return BGP_PACKET_NOOP;
} }
@ -2324,16 +2314,14 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) rcvd route-refresh (BoRR) for %s/%s, triggering timer for %u seconds", "%pBP rcvd route-refresh (BoRR) for %s/%s, triggering timer for %u seconds",
peer->host, bgp_peer_hostname(peer), peer, afi2str(afi), safi2str(safi),
afi2str(afi), safi2str(safi),
peer->bgp->stalepath_time); peer->bgp->stalepath_time);
} else if (subtype == BGP_ROUTE_REFRESH_EORR) { } else if (subtype == BGP_ROUTE_REFRESH_EORR) {
if (!peer->t_refresh_stalepath) { if (!peer->t_refresh_stalepath) {
zlog_err( zlog_err(
"%s(%s) rcvd route-refresh (EoRR) for %s/%s, whereas no BoRR received", "%pBP rcvd route-refresh (EoRR) for %s/%s, whereas no BoRR received",
peer->host, bgp_peer_hostname(peer), peer, afi2str(afi), safi2str(safi));
afi2str(afi), safi2str(safi));
return BGP_PACKET_NOOP; return BGP_PACKET_NOOP;
} }
@ -2345,18 +2333,16 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) rcvd route-refresh (EoRR) for %s/%s, stopping BoRR timer", "%pBP rcvd route-refresh (EoRR) for %s/%s, stopping BoRR timer",
peer->host, bgp_peer_hostname(peer), peer, afi2str(afi), safi2str(safi));
afi2str(afi), safi2str(safi));
if (peer->nsf[afi][safi]) if (peer->nsf[afi][safi])
bgp_clear_stale_route(peer, afi, safi); bgp_clear_stale_route(peer, afi, safi);
} else { } else {
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) rcvd route-refresh (REQUEST) for %s/%s", "%pBP rcvd route-refresh (REQUEST) for %s/%s",
peer->host, bgp_peer_hostname(peer), peer, afi2str(afi), safi2str(safi));
afi2str(afi), safi2str(safi));
/* In response to a "normal route refresh request" from the /* In response to a "normal route refresh request" from the
* peer, the speaker MUST send a BoRR message. * peer, the speaker MUST send a BoRR message.
@ -2371,10 +2357,9 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
PEER_STATUS_EOR_SEND)) { PEER_STATUS_EOR_SEND)) {
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) rcvd route-refresh (REQUEST) for %s/%s before EoR", "%pBP rcvd route-refresh (REQUEST) for %s/%s before EoR",
peer->host, peer, afi2str(afi),
bgp_peer_hostname(peer), safi2str(safi));
afi2str(afi), safi2str(safi));
return BGP_PACKET_NOOP; return BGP_PACKET_NOOP;
} }
@ -2383,9 +2368,8 @@ static int bgp_route_refresh_receive(struct peer *peer, bgp_size_t size)
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) sending route-refresh (BoRR) for %s/%s", "%pBP sending route-refresh (BoRR) for %s/%s",
peer->host, bgp_peer_hostname(peer), peer, afi2str(afi), safi2str(safi));
afi2str(afi), safi2str(safi));
/* Set flag Ready-To-Send to know when we can send EoRR /* Set flag Ready-To-Send to know when we can send EoRR
* message. * message.

View File

@ -3433,9 +3433,9 @@ bool bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi,
return false; return false;
zlog_info( zlog_info(
"%%MAXPFXEXCEED: No. of %s prefix received from %s(%s) %u exceed, limit %u", "%%MAXPFXEXCEED: No. of %s prefix received from %pBP %u exceed, limit %u",
get_afi_safi_str(afi, safi, false), peer->host, get_afi_safi_str(afi, safi, false), peer, pcount,
bgp_peer_hostname(peer), pcount, peer->pmax[afi][safi]); peer->pmax[afi][safi]);
SET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT); SET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
if (CHECK_FLAG(peer->af_flags[afi][safi], if (CHECK_FLAG(peer->af_flags[afi][safi],
@ -3473,9 +3473,8 @@ bool bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi,
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) Maximum-prefix restart timer started for %d secs", "%pBP Maximum-prefix restart timer started for %d secs",
peer->host, bgp_peer_hostname(peer), peer, peer->v_pmax_restart);
peer->v_pmax_restart);
BGP_TIMER_ON(peer->t_pmax_restart, BGP_TIMER_ON(peer->t_pmax_restart,
bgp_maximum_prefix_restart_timer, bgp_maximum_prefix_restart_timer,
@ -3495,8 +3494,8 @@ bool bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi,
return false; return false;
zlog_info( zlog_info(
"%%MAXPFX: No. of %s prefix received from %s reaches %u, max %u", "%%MAXPFX: No. of %s prefix received from %pBP reaches %u, max %u",
get_afi_safi_str(afi, safi, false), peer->host, pcount, get_afi_safi_str(afi, safi, false), peer, pcount,
peer->pmax[afi][safi]); peer->pmax[afi][safi]);
SET_FLAG(peer->af_sflags[afi][safi], SET_FLAG(peer->af_sflags[afi][safi],
PEER_STATUS_PREFIX_THRESHOLD); PEER_STATUS_PREFIX_THRESHOLD);
@ -4009,7 +4008,7 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
num_labels, addpath_id ? 1 : 0, num_labels, addpath_id ? 1 : 0,
addpath_id, evpn, pfx_buf, addpath_id, evpn, pfx_buf,
sizeof(pfx_buf)); sizeof(pfx_buf));
zlog_debug("%s rcvd %s", peer->host, zlog_debug("%pBP rcvd %s", peer,
pfx_buf); pfx_buf);
} }
@ -4024,8 +4023,8 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
if (bgp_debug_update(peer, p, NULL, 1)) { if (bgp_debug_update(peer, p, NULL, 1)) {
if (!peer->rcvd_attr_printed) { if (!peer->rcvd_attr_printed) {
zlog_debug( zlog_debug(
"%s rcvd UPDATE w/ attr: %s", "%pBP rcvd UPDATE w/ attr: %s",
peer->host, peer,
peer->rcvd_attr_str); peer->rcvd_attr_str);
peer->rcvd_attr_printed = 1; peer->rcvd_attr_printed = 1;
} }
@ -4036,8 +4035,8 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
addpath_id, evpn, pfx_buf, addpath_id, evpn, pfx_buf,
sizeof(pfx_buf)); sizeof(pfx_buf));
zlog_debug( zlog_debug(
"%s rcvd %s...duplicate ignored", "%pBP rcvd %s...duplicate ignored",
peer->host, pfx_buf); peer, pfx_buf);
} }
/* graceful restart STALE flag unset. */ /* graceful restart STALE flag unset. */
@ -4063,8 +4062,8 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
addpath_id ? 1 : 0, addpath_id, evpn, addpath_id ? 1 : 0, addpath_id, evpn,
pfx_buf, sizeof(pfx_buf)); pfx_buf, sizeof(pfx_buf));
zlog_debug( zlog_debug(
"%s rcvd %s, flapped quicker than processing", "%pBP rcvd %s, flapped quicker than processing",
peer->host, pfx_buf); peer, pfx_buf);
} }
bgp_path_info_restore(dest, pi); bgp_path_info_restore(dest, pi);
@ -4084,7 +4083,7 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
num_labels, addpath_id ? 1 : 0, num_labels, addpath_id ? 1 : 0,
addpath_id, evpn, pfx_buf, addpath_id, evpn, pfx_buf,
sizeof(pfx_buf)); sizeof(pfx_buf));
zlog_debug("%s rcvd %s", peer->host, pfx_buf); zlog_debug("%pBP rcvd %s", peer, pfx_buf);
} }
/* graceful restart STALE flag unset. */ /* graceful restart STALE flag unset. */
@ -4381,7 +4380,7 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
/* Received Logging. */ /* Received Logging. */
if (bgp_debug_update(peer, p, NULL, 1)) { if (bgp_debug_update(peer, p, NULL, 1)) {
if (!peer->rcvd_attr_printed) { if (!peer->rcvd_attr_printed) {
zlog_debug("%s rcvd UPDATE w/ attr: %s", peer->host, zlog_debug("%pBP rcvd UPDATE w/ attr: %s", peer,
peer->rcvd_attr_str); peer->rcvd_attr_str);
peer->rcvd_attr_printed = 1; peer->rcvd_attr_printed = 1;
} }
@ -4389,7 +4388,7 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
bgp_debug_rdpfxpath2str(afi, safi, prd, p, label, num_labels, bgp_debug_rdpfxpath2str(afi, safi, prd, p, label, num_labels,
addpath_id ? 1 : 0, addpath_id, evpn, addpath_id ? 1 : 0, addpath_id, evpn,
pfx_buf, sizeof(pfx_buf)); pfx_buf, sizeof(pfx_buf));
zlog_debug("%s rcvd %s", peer->host, pfx_buf); zlog_debug("%pBP rcvd %s", peer, pfx_buf);
} }
/* Make new BGP info. */ /* Make new BGP info. */
@ -4533,7 +4532,7 @@ filtered:
if (bgp_debug_update(peer, p, NULL, 1)) { if (bgp_debug_update(peer, p, NULL, 1)) {
if (!peer->rcvd_attr_printed) { if (!peer->rcvd_attr_printed) {
zlog_debug("%s rcvd UPDATE w/ attr: %s", peer->host, zlog_debug("%pBP rcvd UPDATE w/ attr: %s", peer,
peer->rcvd_attr_str); peer->rcvd_attr_str);
peer->rcvd_attr_printed = 1; peer->rcvd_attr_printed = 1;
} }
@ -4541,8 +4540,8 @@ filtered:
bgp_debug_rdpfxpath2str(afi, safi, prd, p, label, num_labels, bgp_debug_rdpfxpath2str(afi, safi, prd, p, label, num_labels,
addpath_id ? 1 : 0, addpath_id, evpn, addpath_id ? 1 : 0, addpath_id, evpn,
pfx_buf, sizeof(pfx_buf)); pfx_buf, sizeof(pfx_buf));
zlog_debug("%s rcvd UPDATE about %s -- DENIED due to: %s", zlog_debug("%pBP rcvd UPDATE about %s -- DENIED due to: %s",
peer->host, pfx_buf, reason); peer, pfx_buf, reason);
} }
if (pi) { if (pi) {
@ -4646,7 +4645,7 @@ int bgp_withdraw(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
bgp_debug_rdpfxpath2str(afi, safi, prd, p, label, num_labels, bgp_debug_rdpfxpath2str(afi, safi, prd, p, label, num_labels,
addpath_id ? 1 : 0, addpath_id, NULL, addpath_id ? 1 : 0, addpath_id, NULL,
pfx_buf, sizeof(pfx_buf)); pfx_buf, sizeof(pfx_buf));
zlog_debug("%s rcvd UPDATE about %s -- withdrawn", peer->host, zlog_debug("%pBP rcvd UPDATE about %s -- withdrawn", peer,
pfx_buf); pfx_buf);
} }

View File

@ -2349,15 +2349,14 @@ void peer_nsf_stop(struct peer *peer)
if (peer->t_gr_restart) { if (peer->t_gr_restart) {
BGP_TIMER_OFF(peer->t_gr_restart); BGP_TIMER_OFF(peer->t_gr_restart);
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug("%s(%s) graceful restart timer stopped", zlog_debug("%pBP graceful restart timer stopped", peer);
peer->host, bgp_peer_hostname(peer));
} }
if (peer->t_gr_stale) { if (peer->t_gr_stale) {
BGP_TIMER_OFF(peer->t_gr_stale); BGP_TIMER_OFF(peer->t_gr_stale);
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) graceful restart stalepath timer stopped", "%pBP graceful restart stalepath timer stopped",
peer->host, bgp_peer_hostname(peer)); peer);
} }
bgp_clear_route_all(peer); bgp_clear_route_all(peer);
} }
@ -4296,9 +4295,8 @@ static void peer_flag_modify_action(struct peer *peer, uint32_t flag)
BGP_TIMER_OFF(peer->t_pmax_restart); BGP_TIMER_OFF(peer->t_pmax_restart);
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) Maximum-prefix restart timer canceled", "%pBP Maximum-prefix restart timer canceled",
peer->host, peer);
bgp_peer_hostname(peer));
} }
if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) { if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) {
@ -7189,8 +7187,8 @@ static bool peer_maximum_prefix_clear_overflow(struct peer *peer)
BGP_TIMER_OFF(peer->t_pmax_restart); BGP_TIMER_OFF(peer->t_pmax_restart);
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug( zlog_debug(
"%s(%s) Maximum-prefix restart timer cancelled", "%pBP Maximum-prefix restart timer cancelled",
peer->host, bgp_peer_hostname(peer)); peer);
} }
BGP_EVENT_ADD(peer, BGP_Start); BGP_EVENT_ADD(peer, BGP_Start);
return true; return true;
@ -8138,3 +8136,16 @@ void bgp_gr_apply_running_config(void)
gr_router_detected = false; gr_router_detected = false;
} }
} }
printfrr_ext_autoreg_p("BP", printfrr_bp);
static ssize_t printfrr_bp(struct fbuf *buf, struct printfrr_eargs *ea,
const void *ptr)
{
const struct peer *peer = ptr;
if (!peer)
return bputs(buf, "(null)");
return bprintfrr(buf, "%s(%s)", peer->host,
peer->hostname ? peer->hostname : "Unknown");
}

View File

@ -2473,11 +2473,6 @@ static inline bool bgp_in_graceful_shutdown(struct bgp *bgp)
!!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN)); !!CHECK_FLAG(bm->flags, BM_FLAG_GRACEFUL_SHUTDOWN));
} }
static inline const char *bgp_peer_hostname(struct peer *peer)
{
return peer->hostname ? peer->hostname : "Unknown";
}
/* For benefit of rfapi */ /* For benefit of rfapi */
extern struct peer *peer_new(struct bgp *bgp); extern struct peer *peer_new(struct bgp *bgp);
@ -2508,4 +2503,11 @@ void peer_tcp_mss_unset(struct peer *peer);
extern void bgp_recalculate_afi_safi_bestpaths(struct bgp *bgp, afi_t afi, extern void bgp_recalculate_afi_safi_bestpaths(struct bgp *bgp, afi_t afi,
safi_t safi); safi_t safi);
#ifdef _FRR_ATTRIBUTE_PRINTFRR
/* clang-format off */
#pragma FRR printfrr_ext "%pBP" (struct peer *)
/* clang-format on */
#endif
#endif /* _QUAGGA_BGPD_H */ #endif /* _QUAGGA_BGPD_H */

View File

@ -381,6 +381,12 @@ bgpd
:frrfmtout:`fe80::1234/64` :frrfmtout:`fe80::1234/64`
.. frrfmt:: %pBP (struct peer *)
:frrfmtout:`192.168.1.1(leaf1.frrouting.org)`
Print BGP peer's IP and hostname together.
pimd/pim6d pimd/pim6d
"""""""""" """"""""""

View File

@ -169,7 +169,7 @@ def test_bgp_community_update_path_change():
if ( if (
len( len(
tgen.gears["c1"].run( tgen.gears["c1"].run(
'grep "10.0.1.2 rcvd 192.168.255.254/32 IPv4 unicast...duplicate ignored" bgpd.log' 'grep "10.0.1.2(x1) rcvd 192.168.255.254/32 IPv4 unicast...duplicate ignored" bgpd.log'
) )
) )
> 0 > 0