]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: Do not crash if bgp argument is NULL for bgp_table_stats()
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Sun, 12 Jul 2020 19:12:36 +0000 (22:12 +0300)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Wed, 15 Jul 2020 18:36:27 +0000 (21:36 +0300)
```
(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=<optimized out>) at lib/sigevent.c:228
3  <signal handler called>
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=<optimized out>, vty=0x55a415acb240, argc=6, argv=<optimized out>) 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=<optimized out>) 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 <donatas.abraitis@gmail.com>
bgpd/bgp_route.c

index 19e398fc88a48b4ced70290c5e7ce26c0baa6aa9..d2ae35339cd9ff961b72ed386fbce60f9753e149 100644 (file)
@@ -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,