From: Donatas Abraitis Date: Sun, 12 Jul 2020 19:12:36 +0000 (+0300) Subject: bgpd: Do not crash if bgp argument is NULL for bgp_table_stats() X-Git-Tag: base_7.5~168^2~1 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=71f1613a3ff73e652375079f8f548d15164d37f6;p=matthieu%2Ffrr.git 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 --- 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,