diff options
| author | Donald Sharp <donaldsharp72@gmail.com> | 2024-04-08 11:12:40 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-08 11:12:40 -0400 |
| commit | 8cfa3b57e905ea2d5536c0c44b70a44cb11f4bb2 (patch) | |
| tree | 83c99449e1614ce5c31a32f46f0a6885e0f64df0 /zebra/zebra_vty.c | |
| parent | a2df7e2a167edecbffc57e3bb20ef53bbe83011a (diff) | |
| parent | ca13121849b58552743890b19154b4076342e36e (diff) | |
Merge pull request #15645 from opensourcerouting/fix/show_ip_route_vrf_all_summary_json
zebra: Fix JSON output for `show route summary json`
Diffstat (limited to 'zebra/zebra_vty.c')
| -rw-r--r-- | zebra/zebra_vty.c | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 2fba5ebd9d..0b5362094e 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -68,10 +68,11 @@ static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi, bool show_ng, struct route_show_ctx *ctx); static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, int mcast, bool use_fib, bool show_ng); -static void vty_show_ip_route_summary(struct vty *vty, - struct route_table *table, bool use_json); +static void vty_show_ip_route_summary(struct vty *vty, struct route_table *table, + json_object *vrf_json, bool use_json); static void vty_show_ip_route_summary_prefix(struct vty *vty, struct route_table *table, + json_object *vrf_json, bool use_json); /* Helper api to format a nexthop in the 'detailed' output path. */ static void show_nexthop_detail_helper(struct vty *vty, @@ -1997,11 +1998,15 @@ DEFPY (show_route_summary, afi_t afi = ipv4 ? AFI_IP : AFI_IP6; struct route_table *table; bool uj = use_json(argc, argv); + json_object *vrf_json = NULL; if (vrf_all) { struct vrf *vrf; struct zebra_vrf *zvrf; + if (uj && !vrf_json) + vrf_json = json_object_new_object(); + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { if ((zvrf = vrf->info) == NULL) continue; @@ -2019,10 +2024,14 @@ DEFPY (show_route_summary, if (prefix) vty_show_ip_route_summary_prefix(vty, table, - uj); + vrf_json, uj); else - vty_show_ip_route_summary(vty, table, uj); + vty_show_ip_route_summary(vty, table, vrf_json, + uj); } + + if (uj) + vty_json(vty, vrf_json); } else { vrf_id_t vrf_id = VRF_DEFAULT; @@ -2038,9 +2047,9 @@ DEFPY (show_route_summary, return CMD_SUCCESS; if (prefix) - vty_show_ip_route_summary_prefix(vty, table, uj); + vty_show_ip_route_summary_prefix(vty, table, NULL, uj); else - vty_show_ip_route_summary(vty, table, uj); + vty_show_ip_route_summary(vty, table, NULL, uj); } return CMD_SUCCESS; @@ -2246,8 +2255,8 @@ static void show_ip_route_dump_vty(struct vty *vty, struct route_table *table) } } -static void vty_show_ip_route_summary(struct vty *vty, - struct route_table *table, bool use_json) +static void vty_show_ip_route_summary(struct vty *vty, struct route_table *table, + json_object *vrf_json, bool use_json) { struct route_node *rn; struct route_entry *re; @@ -2261,6 +2270,8 @@ static void vty_show_ip_route_summary(struct vty *vty, uint32_t is_ibgp; json_object *json_route_summary = NULL; json_object *json_route_routes = NULL; + const char *vrf_name = zvrf_name( + ((struct rib_table_info *)route_table_get_info(table))->zvrf); memset(&rib_cnt, 0, sizeof(rib_cnt)); memset(&fib_cnt, 0, sizeof(fib_cnt)); @@ -2311,10 +2322,7 @@ static void vty_show_ip_route_summary(struct vty *vty, if (!use_json) vty_out(vty, "%-20s %-20s %s (vrf %s)\n", "Route Source", - "Routes", "FIB", - zvrf_name(((struct rib_table_info *) - route_table_get_info(table)) - ->zvrf)); + "Routes", "FIB", vrf_name); for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { if ((rib_cnt[i] > 0) || (i == ZEBRA_ROUTE_BGP @@ -2406,7 +2414,11 @@ static void vty_show_ip_route_summary(struct vty *vty, json_object_int_add(json_route_summary, "routesTotalFib", fib_cnt[ZEBRA_ROUTE_TOTAL]); - vty_json(vty, json_route_summary); + if (!vrf_json) + vty_json(vty, json_route_summary); + else + json_object_object_add(vrf_json, vrf_name, + json_route_summary); } else { vty_out(vty, "------\n"); vty_out(vty, "%-20s %-20d %-20d \n", "Totals", @@ -2424,6 +2436,7 @@ static void vty_show_ip_route_summary(struct vty *vty, */ static void vty_show_ip_route_summary_prefix(struct vty *vty, struct route_table *table, + json_object *vrf_json, bool use_json) { struct route_node *rn; @@ -2437,6 +2450,8 @@ static void vty_show_ip_route_summary_prefix(struct vty *vty, int cnt; json_object *json_route_summary = NULL; json_object *json_route_routes = NULL; + const char *vrf_name = zvrf_name( + ((struct rib_table_info *)route_table_get_info(table))->zvrf); memset(&rib_cnt, 0, sizeof(rib_cnt)); memset(&fib_cnt, 0, sizeof(fib_cnt)); @@ -2476,10 +2491,7 @@ static void vty_show_ip_route_summary_prefix(struct vty *vty, if (!use_json) vty_out(vty, "%-20s %-20s %s (vrf %s)\n", "Route Source", - "Prefix Routes", "FIB", - zvrf_name(((struct rib_table_info *) - route_table_get_info(table)) - ->zvrf)); + "Prefix Routes", "FIB", vrf_name); for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { if (rib_cnt[i] > 0) { @@ -2554,7 +2566,11 @@ static void vty_show_ip_route_summary_prefix(struct vty *vty, json_object_int_add(json_route_summary, "prefixRoutesTotalFib", fib_cnt[ZEBRA_ROUTE_TOTAL]); - vty_json(vty, json_route_summary); + if (!vrf_json) + vty_json(vty, json_route_summary); + else + json_object_object_add(vrf_json, vrf_name, + json_route_summary); } else { vty_out(vty, "------\n"); vty_out(vty, "%-20s %-20d %-20d \n", "Totals", |
