Merge pull request #6745 from ton31337/fix/handle_bgp_vrf_all_statistics_crash

This commit is contained in:
David Lamparter 2020-07-21 08:01:22 +02:00 committed by GitHub
commit eae0446618
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -10610,6 +10610,8 @@ DEFUN (show_ip_bgp_large_community,
bgp_show_type_lcommunity_all, NULL, uj); 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, static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi,
safi_t safi, struct json_object *json); safi_t safi, struct json_object *json);
@ -10629,7 +10631,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_vty_find_and_parse_afi_safi_bgp(vty, argv, argc, &idx, &afi, &safi,
&bgp, false); &bgp, false);
if (!bgp) if (!idx)
return CMD_WARNING; return CMD_WARNING;
if (uj) if (uj)
@ -11387,7 +11389,17 @@ static int bgp_table_stats_walker(struct thread *t)
return 0; return 0;
} }
static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi, 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) safi_t safi, struct json_object *json_array)
{ {
struct bgp_table_stats ts; struct bgp_table_stats ts;
@ -11416,8 +11428,10 @@ static int bgp_table_stats(struct vty *vty, struct bgp *bgp, afi_t afi,
} }
if (!json) if (!json)
vty_out(vty, "BGP %s RIB statistics\n", vty_out(vty, "BGP %s RIB statistics (%s)\n",
get_afi_safi_str(afi, safi, false)); 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 */ /* labeled-unicast routes live in the unicast table */
if (safi == SAFI_LABELED_UNICAST) if (safi == SAFI_LABELED_UNICAST)
@ -11606,6 +11620,17 @@ end_table_stats:
return ret; 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 { enum bgp_pcounts {
PCOUNT_ADJ_IN = 0, PCOUNT_ADJ_IN = 0,
PCOUNT_DAMPED, PCOUNT_DAMPED,