]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: evpn json cli bug fix
authorLakshman Krishnamoorthy <lkrishnamoor@vmware.com>
Sat, 11 May 2019 16:33:10 +0000 (09:33 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 16 May 2019 20:35:06 +0000 (16:35 -0400)
Bug: If there are 2 different prefixes under an rd, the
output of "show bgp l2vpn evpn json" would print only one of the
prefixes.

RCA: prefix info was added to the json_object once per rd. Hence,
prefix and rd were added just once, as the loop iterated over all
the prefixes and paths.

This is related to my earlier commit that went in via PR 4283:
https://github.com/FRRouting/frr/pull/4283

Signed-off-by: Lakshman Krishnamoorthy <lkrishnamoor@vmware.com>
bgpd/bgp_evpn_vty.c

index 1bd153639bf1d03dac82b6a2315d0aeb0c6fc47b..4296604c4a4a9c4f53ff9db3f2da0c68c5ccd8ec 100644 (file)
@@ -1048,7 +1048,20 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd,
                rd_header = 1;
                tbl_ver = table->version;
 
-               for (rm = bgp_table_top(table); rm; rm = bgp_route_next(rm))
+               for (rm = bgp_table_top(table); rm; rm = bgp_route_next(rm)) {
+                       if (use_json) {
+                               json_array = json_object_new_array();
+                               json_prefix_info = json_object_new_object();
+
+                               json_object_string_add(json_prefix_info,
+                                       "prefix", bgp_evpn_route2str(
+                                       (struct prefix_evpn *)&rm->p, buf,
+                                       BUFSIZ));
+
+                               json_object_int_add(json_prefix_info,
+                                       "prefixLen", rm->p.prefixlen);
+                       }
+
                        for (pi = bgp_node_get_bgp_path_info(rm); pi;
                             pi = pi->next) {
                                total_count++;
@@ -1121,10 +1134,6 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd,
                                        if (use_json) {
                                                json_nroute =
                                                      json_object_new_object();
-                                               json_prefix_info =
-                                                      json_object_new_object();
-                                               json_array =
-                                                       json_object_new_array();
                                                if (type == RD_TYPE_AS
                                                    || type == RD_TYPE_AS4)
                                                        sprintf(rd_str, "%u:%d",
@@ -1140,18 +1149,6 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd,
                                                        "rd",
                                                        rd_str);
 
-                                               json_object_string_add(
-                                                       json_prefix_info,
-                                                       "prefix",
-                                                       bgp_evpn_route2str(
-                                                       (struct prefix_evpn *)
-                                                       &rm->p, buf, BUFSIZ));
-
-                                               json_object_int_add(
-                                                       json_prefix_info,
-                                                       "prefixLen",
-                                                       rm->p.prefixlen);
-
                                        } else {
                                                vty_out(vty,
                                                        "Route Distinguisher: ");
@@ -1174,6 +1171,7 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd,
                                        }
                                        rd_header = 0;
                                }
+
                                if (option == SHOW_DISPLAY_TAGS)
                                        route_vty_out_tag(vty, &rm->p, pi, 0,
                                                          SAFI_EVPN,
@@ -1186,14 +1184,16 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd,
                                                      SAFI_EVPN, json_array);
                                output_count++;
                        }
+                       if (use_json) {
+                               json_object_object_add(json_prefix_info,
+                                       "paths", json_array);
+                               json_object_object_add(json_nroute, buf,
+                                       json_prefix_info);
+                       }
+               }
 
-               if (use_json) {
-                       json_object_object_add(json_prefix_info, "paths",
-                               json_array);
-                       json_object_object_add(json_nroute, buf,
-                               json_prefix_info);
+               if (use_json)
                        json_object_object_add(json, rd_str, json_nroute);
-               }
        }
 
        if (use_json) {