From 8c6a164f40178319fbaf2594ba36622dc2ea0586 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 28 Sep 2022 17:23:51 +0200 Subject: [PATCH] bgpd: improve 'show bgp nexthop' command - for a given IP nexthop, dump all NH entries, including colored entries, or entries with an ifindex. - when a given IP nexthop is requested, the path is displayed. For better readibility, remove the carriage return between 'Last update' and 'Paths', because ctime() function already performs carriage return. Signed-off-by: Philippe Guibert --- bgpd/bgp_nexthop.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 59b31072b5..075350cd2b 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -865,7 +865,6 @@ static void bgp_show_nexthop(struct vty *vty, struct bgp *bgp, } tbuf = time(NULL) - (monotime(NULL) - bnc->last_update); vty_out(vty, " Last update: %s", ctime(&tbuf)); - vty_out(vty, "\n"); /* show paths dependent on nexthop, if needed. */ if (specific) @@ -912,6 +911,7 @@ static int show_ip_bgp_nexthop_table(struct vty *vty, const char *name, struct prefix nhop; struct bgp_nexthop_cache_head (*tree)[AFI_MAX]; struct bgp_nexthop_cache *bnc; + bool found = false; if (!str2prefix(nhopip_str, &nhop)) { vty_out(vty, "nexthop address is malformed\n"); @@ -919,12 +919,16 @@ static int show_ip_bgp_nexthop_table(struct vty *vty, const char *name, } tree = import_table ? &bgp->import_check_table : &bgp->nexthop_cache_table; - bnc = bnc_find(&(*tree)[family2afi(nhop.family)], &nhop, 0, 0); - if (!bnc) { - vty_out(vty, "specified nexthop does not have entry\n"); - return CMD_SUCCESS; + frr_each (bgp_nexthop_cache, &(*tree)[family2afi(nhop.family)], + bnc) { + if (prefix_cmp(&bnc->prefix, &nhop)) + continue; + bgp_show_nexthop(vty, bgp, bnc, true); + found = true; } - bgp_show_nexthop(vty, bgp, bnc, true); + if (!found) + vty_out(vty, "nexthop %s does not have entry\n", + nhopip_str); } else bgp_show_nexthops(vty, bgp, import_table); -- 2.39.5