From 987a720a11e897b764ed40cd779d80661c76ae16 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 27 Jan 2021 19:56:13 -0500 Subject: [PATCH] bgpd: Add bgp_nexthop_dump_bnc_flags Add a function that allows us to see a string version of the bnc->flags bit fields. Signed-off-by: Donald Sharp --- bgpd/bgp_nexthop.c | 26 ++++++++++++++++++++++++++ bgpd/bgp_nexthop.h | 3 +++ bgpd/bgp_nht.c | 18 +++++++++++++----- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 1a9f59db64..dcada04680 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -33,6 +33,7 @@ #include "nexthop.h" #include "queue.h" #include "filter.h" +#include "printfrr.h" #include "bgpd/bgpd.h" #include "bgpd/bgp_route.h" @@ -1020,3 +1021,28 @@ void bgp_scan_finish(struct bgp *bgp) bgp->connected_table[afi] = NULL; } } + +char *bgp_nexthop_dump_bnc_flags(struct bgp_nexthop_cache *bnc, char *buf, + size_t len) +{ + if (bnc->flags == 0) { + snprintfrr(buf, len, "None "); + return buf; + } + + snprintfrr(buf, len, "%s%s%s%s%s%s%s", + CHECK_FLAG(bnc->flags, BGP_NEXTHOP_VALID) ? "Valid " : "", + CHECK_FLAG(bnc->flags, BGP_NEXTHOP_REGISTERED) ? "Reg " : "", + CHECK_FLAG(bnc->flags, BGP_NEXTHOP_CONNECTED) ? "Conn " : "", + CHECK_FLAG(bnc->flags, BGP_NEXTHOP_PEER_NOTIFIED) ? "Notify " + : "", + CHECK_FLAG(bnc->flags, BGP_STATIC_ROUTE) ? "Static " : "", + CHECK_FLAG(bnc->flags, BGP_STATIC_ROUTE_EXACT_MATCH) + ? "Static Exact " + : "", + CHECK_FLAG(bnc->flags, BGP_NEXTHOP_LABELED_VALID) + ? "Label Valid " + : ""); + + return buf; +} diff --git a/bgpd/bgp_nexthop.h b/bgpd/bgp_nexthop.h index c4b913faf4..27486cf475 100644 --- a/bgpd/bgp_nexthop.h +++ b/bgpd/bgp_nexthop.h @@ -100,6 +100,9 @@ struct update_subgroup; struct bgp_dest; struct attr; +#define BNC_FLAG_DUMP_SIZE 180 +extern char *bgp_nexthop_dump_bnc_flags(struct bgp_nexthop_cache *bnc, + char *buf, size_t len); extern void bgp_connected_add(struct bgp *bgp, struct connected *c); extern void bgp_connected_delete(struct bgp *bgp, struct connected *c); extern bool bgp_subgrp_multiaccess_check_v4(struct in_addr nexthop, diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index 85a65bc2ce..8030f2e39e 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -320,12 +320,17 @@ static void bgp_process_nexthop_update(struct bgp_nexthop_cache *bnc, bnc->change_flags = 0; /* debug print the input */ - if (BGP_DEBUG(nht, NHT)) + if (BGP_DEBUG(nht, NHT)) { + char bnc_buf[BNC_FLAG_DUMP_SIZE]; + zlog_debug( - "%s(%u): Rcvd NH update %pFX(%u) - metric %d/%d #nhops %d/%d flags 0x%x", + "%s(%u): Rcvd NH update %pFX(%u) - metric %d/%d #nhops %d/%d flags %s", bnc->bgp->name_pretty, bnc->bgp->vrf_id, &nhr->prefix, bnc->srte_color, nhr->metric, bnc->metric, - nhr->nexthop_num, bnc->nexthop_num, bnc->flags); + nhr->nexthop_num, bnc->nexthop_num, + bgp_nexthop_dump_bnc_flags(bnc, bnc_buf, + sizeof(bnc_buf))); + } if (nhr->metric != bnc->metric) bnc->change_flags |= BGP_NEXTHOP_METRIC_CHANGED; @@ -702,10 +707,13 @@ static void evaluate_paths(struct bgp_nexthop_cache *bnc) if (BGP_DEBUG(nht, NHT)) { char buf[PREFIX2STR_BUFFER]; + char bnc_buf[BNC_FLAG_DUMP_SIZE]; + bnc_str(bnc, buf, PREFIX2STR_BUFFER); zlog_debug( - "NH update for %s(%u)(%s) - flags 0x%x chgflags 0x%x - evaluate paths", - buf, bnc->srte_color, bnc->bgp->name_pretty, bnc->flags, + "NH update for %s(%u)(%s) - flags %s chgflags 0x%x - evaluate paths", + buf, bnc->srte_color, bnc->bgp->name_pretty, + bgp_nexthop_dump_bnc_flags(bnc, bnc_buf, sizeof(bnc_buf)), bnc->change_flags); } -- 2.39.5