From: Lakshman Krishnamoorthy Date: Thu, 21 Nov 2019 23:30:00 +0000 (-0800) Subject: bgpd: Blank RD in "sh bgp l2vpn evpn all neighbors advertised-routes json" X-Git-Tag: frr-7.5.1~1031^2 X-Git-Url: https://git.proxmox.com/?a=commitdiff_plain;h=f5cfc290d3cc43be9f100846631afb0669020179;p=mirror_frr.git bgpd: Blank RD in "sh bgp l2vpn evpn all neighbors advertised-routes json" Bug: While preparing the JSON output, 2 loops are traversed: the outer loop loops through RD, and the inner loop loops through the prefixes of that RD. We hit the bug (printing blank RD and stale or null prefix info) when the inner loop exits with nothing to print, (without allocating json_routes) and the outer loop still tries to attach it to the parent, json_adv. Thus, we have key=, value= The fix: Avoid attaching json_routes to the parent json if there is nothing to print. Signed-off-by: Lakshman Krishnamoorthy --- diff --git a/bgpd/bgp_vpn.c b/bgpd/bgp_vpn.c index f922d066c..b67b0c322 100644 --- a/bgpd/bgp_vpn.c +++ b/bgpd/bgp_vpn.c @@ -85,9 +85,13 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer, if (table == NULL) continue; - + /* + * Initialize variables for each RD + * All prefixes under an RD is aggregated within "json_routes" + */ rd_header = 1; memset(rd_str, 0, sizeof(rd_str)); + json_routes = NULL; for (rm = bgp_table_top(table); rm; rm = bgp_route_next(rm)) { struct bgp_adj_out *adj = NULL; @@ -223,7 +227,7 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer, output_count++; } - if (use_json) + if (use_json && json_routes) json_object_object_add(json_adv, rd_str, json_routes); }