]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: improve 'show bgp nexthop' command 12038/head
authorPhilippe Guibert <philippe.guibert@6wind.com>
Wed, 28 Sep 2022 15:23:51 +0000 (17:23 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Wed, 5 Oct 2022 09:12:59 +0000 (11:12 +0200)
- 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 <philippe.guibert@6wind.com>
bgpd/bgp_nexthop.c

index 59b31072b5263dbd1cac195da86e34dbb37a8eaa..075350cd2b8e8571faad871a42c7d0f9c5f4d9d1 100644 (file)
@@ -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);