mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-14 10:09:17 +00:00
bgpd: json route table brace counting
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
This commit is contained in:
parent
509d742fb3
commit
9386b58830
@ -7872,7 +7872,8 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
|
|||||||
struct bgp_table *table, enum bgp_show_type type,
|
struct bgp_table *table, enum bgp_show_type type,
|
||||||
void *output_arg, u_char use_json,
|
void *output_arg, u_char use_json,
|
||||||
char *rd, int is_last,
|
char *rd, int is_last,
|
||||||
unsigned long *output_cum, unsigned long *total_cum)
|
unsigned long *output_cum, unsigned long *total_cum,
|
||||||
|
unsigned long *json_header_depth)
|
||||||
{
|
{
|
||||||
struct bgp_info *ri;
|
struct bgp_info *ri;
|
||||||
struct bgp_node *rn;
|
struct bgp_node *rn;
|
||||||
@ -7889,7 +7890,7 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
|
|||||||
if (output_cum && *output_cum != 0)
|
if (output_cum && *output_cum != 0)
|
||||||
header = 0;
|
header = 0;
|
||||||
|
|
||||||
if (use_json && header) {
|
if (use_json && !*json_header_depth) {
|
||||||
vty_out(vty,
|
vty_out(vty,
|
||||||
"{\n \"vrfId\": %d,\n \"vrfName\": \"%s\",\n \"tableVersion\": %" PRId64
|
"{\n \"vrfId\": %d,\n \"vrfName\": \"%s\",\n \"tableVersion\": %" PRId64
|
||||||
",\n \"routerId\": \"%s\",\n \"routes\": { ",
|
",\n \"routerId\": \"%s\",\n \"routes\": { ",
|
||||||
@ -7897,8 +7898,11 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
|
|||||||
bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ? "Default"
|
bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT ? "Default"
|
||||||
: bgp->name,
|
: bgp->name,
|
||||||
table->version, inet_ntoa(bgp->router_id));
|
table->version, inet_ntoa(bgp->router_id));
|
||||||
if (rd)
|
*json_header_depth = 2;
|
||||||
|
if (rd) {
|
||||||
vty_out(vty, " \"routeDistinguishers\" : {");
|
vty_out(vty, " \"routeDistinguishers\" : {");
|
||||||
|
++*json_header_depth;
|
||||||
|
}
|
||||||
json_paths = json_object_new_object();
|
json_paths = json_object_new_object();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8131,10 +8135,14 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi,
|
|||||||
if (use_json) {
|
if (use_json) {
|
||||||
if (json_paths)
|
if (json_paths)
|
||||||
json_object_free(json_paths);
|
json_object_free(json_paths);
|
||||||
if (is_last)
|
if (rd) {
|
||||||
vty_out(vty, " } }\n");
|
vty_out(vty, " }%s ", (is_last? "": ","));
|
||||||
else
|
}
|
||||||
vty_out(vty, " }, ");
|
if (is_last) {
|
||||||
|
unsigned long i;
|
||||||
|
for (i = 0; i < *json_header_depth; ++i)
|
||||||
|
vty_out(vty, " } ");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (is_last) {
|
if (is_last) {
|
||||||
/* No route is displayed */
|
/* No route is displayed */
|
||||||
@ -8161,6 +8169,7 @@ int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi,
|
|||||||
struct bgp_node *rn, *next;
|
struct bgp_node *rn, *next;
|
||||||
unsigned long output_cum = 0;
|
unsigned long output_cum = 0;
|
||||||
unsigned long total_cum = 0;
|
unsigned long total_cum = 0;
|
||||||
|
unsigned long json_header_depth = 0;
|
||||||
bool show_msg;
|
bool show_msg;
|
||||||
|
|
||||||
show_msg = (!use_json && type == bgp_show_type_normal);
|
show_msg = (!use_json && type == bgp_show_type_normal);
|
||||||
@ -8178,7 +8187,8 @@ int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi,
|
|||||||
bgp_show_table(vty, bgp, safi, rn->info, type,
|
bgp_show_table(vty, bgp, safi, rn->info, type,
|
||||||
output_arg, use_json,
|
output_arg, use_json,
|
||||||
rd, next == NULL,
|
rd, next == NULL,
|
||||||
&output_cum, &total_cum);
|
&output_cum, &total_cum,
|
||||||
|
&json_header_depth);
|
||||||
if (next == NULL)
|
if (next == NULL)
|
||||||
show_msg = false;
|
show_msg = false;
|
||||||
}
|
}
|
||||||
@ -8192,14 +8202,13 @@ int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi,
|
|||||||
"\nDisplayed %ld routes and %ld total paths\n",
|
"\nDisplayed %ld routes and %ld total paths\n",
|
||||||
output_cum, total_cum);
|
output_cum, total_cum);
|
||||||
}
|
}
|
||||||
if (use_json)
|
|
||||||
vty_out(vty, " } }");
|
|
||||||
return CMD_SUCCESS;
|
return CMD_SUCCESS;
|
||||||
}
|
}
|
||||||
static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
|
static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
|
||||||
enum bgp_show_type type, void *output_arg, u_char use_json)
|
enum bgp_show_type type, void *output_arg, u_char use_json)
|
||||||
{
|
{
|
||||||
struct bgp_table *table;
|
struct bgp_table *table;
|
||||||
|
unsigned long json_header_depth = 0;
|
||||||
|
|
||||||
if (bgp == NULL) {
|
if (bgp == NULL) {
|
||||||
bgp = bgp_get_default();
|
bgp = bgp_get_default();
|
||||||
@ -8224,7 +8233,7 @@ static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
|
|||||||
safi = SAFI_UNICAST;
|
safi = SAFI_UNICAST;
|
||||||
|
|
||||||
return bgp_show_table(vty, bgp, safi, table, type, output_arg, use_json,
|
return bgp_show_table(vty, bgp, safi, table, type, output_arg, use_json,
|
||||||
NULL, 1, NULL, NULL);
|
NULL, 1, NULL, NULL, &json_header_depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bgp_show_all_instances_routes_vty(struct vty *vty, afi_t afi,
|
static void bgp_show_all_instances_routes_vty(struct vty *vty, afi_t afi,
|
||||||
|
Loading…
Reference in New Issue
Block a user