From 71f1613a3ff73e652375079f8f548d15164d37f6 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Sun, 12 Jul 2020 22:12:36 +0300 Subject: [PATCH 1/2] bgpd: Do not crash if bgp argument is NULL for bgp_table_stats() ``` (gdb) bt 0 0x00007f45a6f0a781 in raise () from /lib/x86_64-linux-gnu/libc.so.6 1 0x00007f45a6ef455b in abort () from /lib/x86_64-linux-gnu/libc.so.6 2 0x00007f45a7781920 in core_handler (signo=11, siginfo=0x7fffac7b84b0, context=) at lib/sigevent.c:228 3 4 0x000055a4133c0f32 in bgp_table_stats (vty=vty@entry=0x55a415acb240, bgp=0x0, afi=AFI_IP, safi=SAFI_UNICAST, json_array=json_array@entry=0x0) at bgpd/bgp_route.c:11412 5 0x000055a4133c13fb in show_ip_bgp_afi_safi_statistics (self=, vty=0x55a415acb240, argc=6, argv=) at bgpd/bgp_route.c:10749 6 0x00007f45a773917d in cmd_execute_command_real (vline=vline@entry=0x55a415ab7e10, vty=vty@entry=0x55a415acb240, cmd=cmd@entry=0x0, filter=FILTER_RELAXED) at lib/command.c:909 7 0x00007f45a773afdf in cmd_execute_command (vline=vline@entry=0x55a415ab7e10, vty=vty@entry=0x55a415acb240, cmd=0x0, vtysh=vtysh@entry=0) at lib/command.c:968 8 0x00007f45a773b135 in cmd_execute (vty=vty@entry=0x55a415acb240, cmd=cmd@entry=0x55a415ace950 "show ip bgp vrf all statistics", matched=matched@entry=0x0, vtysh=vtysh@entry=0) at lib/command.c:1122 9 0x00007f45a7794d62 in vty_command (vty=vty@entry=0x55a415acb240, buf=0x55a415ace950 "show ip bgp vrf all statistics") at lib/vty.c:526 10 0x00007f45a7794fb6 in vty_execute (vty=vty@entry=0x55a415acb240) at lib/vty.c:1293 11 0x00007f45a7797804 in vtysh_read (thread=) at lib/vty.c:2126 12 0x00007f45a778f641 in thread_call (thread=thread@entry=0x7fffac7bb040) at lib/thread.c:1550 13 0x00007f45a775b6d8 in frr_run (master=0x55a415542820) at lib/libfrr.c:1098 14 0x000055a4133815d6 in main (argc=10, argv=0x7fffac7bb2a8) at bgpd/bgp_main.c:509 ``` "show ip bgp vrf all statistics" should show statistics for all VRFs if "all" is specified. Signed-off-by: Donatas Abraitis --- bgpd/bgp_route.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 19e398fc88..d2ae35339c 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -10618,6 +10618,8 @@ DEFUN (show_ip_bgp_large_community, bgp_show_type_lcommunity_all, NULL, uj); } +static int bgp_table_stats_single(struct vty *vty, struct bgp *bgp, afi_t afi, + safi_t safi, struct json_object *json_array); static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, struct json_object *json); @@ -10637,7 +10639,7 @@ DEFUN(show_ip_bgp_statistics_all, show_ip_bgp_statistics_all_cmd, bgp_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi, &bgp, false); - if (!bgp) + if (!idx) return CMD_WARNING; if (uj) @@ -11396,8 +11398,18 @@ static int bgp_table_stats_walker(struct thread *t) return 0; } -static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi, - safi_t safi, struct json_object *json_array) +static void bgp_table_stats_all(struct vty *vty, afi_t afi, safi_t safi, + struct json_object *json_array) +{ + struct listnode *node, *nnode; + struct bgp *bgp; + + for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) + bgp_table_stats_single(vty, bgp, afi, safi, json_array); +} + +static int bgp_table_stats_single(struct vty *vty, struct bgp *bgp, afi_t afi, + safi_t safi, struct json_object *json_array) { struct bgp_table_stats ts; unsigned int i; @@ -11615,6 +11627,17 @@ end_table_stats: return ret; } +static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi, + safi_t safi, struct json_object *json_array) +{ + if (!bgp) { + bgp_table_stats_all(vty, afi, safi, json_array); + return CMD_SUCCESS; + } + + return bgp_table_stats_single(vty, bgp, afi, safi, json_array); +} + enum bgp_pcounts { PCOUNT_ADJ_IN = 0, PCOUNT_DAMPED, From 5290ceab0c86bbb18a07a7509187c5aee48df00c Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Wed, 15 Jul 2020 17:52:12 +0300 Subject: [PATCH 2/2] bgpd: Show the instance name when displaying statistics ``` exit1-debian-9# sh ip bgp vrf all statistics json { "ipv4Unicast":[ { "instance":"VRF default", "totalAdvertisements":2, "totalPrefixes":2, "averagePrefixLength":24, "unaggregateablePrefixes":2, "maximumAggregateablePrefixes":0, "bgpAggregateAdvertisements":0, "addressSpaceAdvertised":512, "%announced":1.1920928955078125e-05, "\/8equivalent":3.0517578125e-05, "\/24equivalent":2, "advertisementsWithPaths":2, "longestAsPath":0, "averageAsPathLengthHops":0, "largestAsPath":0, "averageAsPathSizeBytes":0, "highestPublicAsn":0 }, { "instance":"VRF testas", "totalAdvertisements":0, "totalPrefixes":0, "averagePrefixLength":0, "unaggregateablePrefixes":0, "maximumAggregateablePrefixes":0, "bgpAggregateAdvertisements":0, "addressSpaceAdvertised":0, "%announced":0, "\/8equivalent":0, "\/24equivalent":0, "advertisementsWithPaths":0, "longestAsPath":0, "averageAsPathLengthHops":0, "largestAsPath":0, "averageAsPathSizeBytes":0, "highestPublicAsn":0 } ] } ``` Signed-off-by: Donatas Abraitis --- bgpd/bgp_route.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index d2ae35339c..7bc9550da9 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -11437,8 +11437,10 @@ static int bgp_table_stats_single(struct vty *vty, struct bgp *bgp, afi_t afi, } if (!json) - vty_out(vty, "BGP %s RIB statistics\n", - get_afi_safi_str(afi, safi, false)); + vty_out(vty, "BGP %s RIB statistics (%s)\n", + get_afi_safi_str(afi, safi, false), bgp->name_pretty); + else + json_object_string_add(json, "instance", bgp->name_pretty); /* labeled-unicast routes live in the unicast table */ if (safi == SAFI_LABELED_UNICAST)