summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas.abraitis@gmail.com>2019-11-26 08:49:54 +0200
committerGitHub <noreply@github.com>2019-11-26 08:49:54 +0200
commitd656cf7fd1b256d6ae4ba9ee80dd8cc95e1d7952 (patch)
tree62939c56c430d43d86b76c6836ce48a250e60e21
parentee6e8c1cb07986c0c271bb414e3d139c6e41c284 (diff)
parent06931fdb128f7f80b7934c0bd31d0690ed9682fd (diff)
Merge pull request #5407 from lkrishnamoor/evpn_vni_json
zebra: "show evpn vni details json" prints incorrect JSON format
-rw-r--r--zebra/zebra_vty.c2
-rw-r--r--zebra/zebra_vxlan.c78
-rw-r--r--zebra/zebra_vxlan.h3
3 files changed, 48 insertions, 35 deletions
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
index 12517f3135..8a7c7e359f 100644
--- a/zebra/zebra_vty.c
+++ b/zebra/zebra_vty.c
@@ -2227,7 +2227,7 @@ DEFUN (show_evpn_vni_vni,
vni = strtoul(argv[3]->arg, NULL, 10);
zvrf = zebra_vrf_get_evpn();
- zebra_vxlan_print_vni(vty, zvrf, vni, uj);
+ zebra_vxlan_print_vni(vty, zvrf, vni, uj, NULL);
return CMD_SUCCESS;
}
diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c
index 3efb407fae..e81f26bc56 100644
--- a/zebra/zebra_vxlan.c
+++ b/zebra/zebra_vxlan.c
@@ -1987,6 +1987,7 @@ struct zvni_evpn_show {
struct vty *vty;
json_object *json;
struct zebra_vrf *zvrf;
+ bool use_json;
};
/* print a L3 VNI hash entry in detail*/
@@ -1994,20 +1995,21 @@ static void zl3vni_print_hash_detail(struct hash_bucket *bucket, void *data)
{
struct vty *vty = NULL;
zebra_l3vni_t *zl3vni = NULL;
- json_object *json = NULL;
+ json_object *json_array = NULL;
bool use_json = false;
struct zvni_evpn_show *zes = data;
vty = zes->vty;
- json = zes->json;
-
- if (json)
- use_json = true;
+ json_array = zes->json;
+ use_json = zes->use_json;
zl3vni = (zebra_l3vni_t *)bucket->data;
- zebra_vxlan_print_vni(vty, zes->zvrf, zl3vni->vni, use_json);
- vty_out(vty, "\n");
+ zebra_vxlan_print_vni(vty, zes->zvrf, zl3vni->vni,
+ use_json, json_array);
+
+ if (!use_json)
+ vty_out(vty, "\n");
}
@@ -2082,20 +2084,20 @@ static void zvni_print_hash_detail(struct hash_bucket *bucket, void *data)
{
struct vty *vty;
zebra_vni_t *zvni;
- json_object *json = NULL;
+ json_object *json_array = NULL;
bool use_json = false;
struct zvni_evpn_show *zes = data;
vty = zes->vty;
- json = zes->json;
-
- if (json)
- use_json = true;
+ json_array = zes->json;
+ use_json = zes->use_json;
zvni = (zebra_vni_t *)bucket->data;
- zebra_vxlan_print_vni(vty, zes->zvrf, zvni->vni, use_json);
- vty_out(vty, "\n");
+ zebra_vxlan_print_vni(vty, zes->zvrf, zvni->vni, use_json, json_array);
+
+ if (!use_json)
+ vty_out(vty, "\n");
}
/*
@@ -7169,9 +7171,14 @@ void zebra_vxlan_print_macs_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf,
/*
* Display VNI information (VTY command handler).
+ *
+ * use_json flag indicates that output should be in JSON format.
+ * json_array is non NULL when JSON output needs to be aggregated (by the
+ * caller) and then printed, otherwise, JSON evpn vni info is printed
+ * right away.
*/
void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni,
- bool use_json)
+ bool use_json, json_object *json_array)
{
json_object *json = NULL;
void *args[2];
@@ -7183,6 +7190,7 @@ void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni,
if (use_json)
json = json_object_new_object();
+
args[0] = vty;
args[1] = json;
@@ -7191,21 +7199,25 @@ void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni,
zl3vni_print(zl3vni, (void *)args);
} else {
zvni = zvni_lookup(vni);
- if (!zvni) {
- if (use_json)
- vty_out(vty, "{}\n");
- else
- vty_out(vty, "%% VNI %u does not exist\n", vni);
- return;
- }
-
- zvni_print(zvni, (void *)args);
+ if (zvni)
+ zvni_print(zvni, (void *)args);
+ else if (!json)
+ vty_out(vty, "%% VNI %u does not exist\n", vni);
}
if (use_json) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
+ /*
+ * Each "json" object contains info about 1 VNI.
+ * When "json_array" is non-null, we aggreggate the json output
+ * into json_array and print it as a JSON array.
+ */
+ if (json_array)
+ json_object_array_add(json_array, json);
+ else {
+ vty_out(vty, "%s\n", json_object_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
+ json_object_free(json);
+ }
}
}
@@ -7362,7 +7374,7 @@ stream_failure:
void zebra_vxlan_print_vnis_detail(struct vty *vty, struct zebra_vrf *zvrf,
bool use_json)
{
- json_object *json = NULL;
+ json_object *json_array = NULL;
struct zebra_ns *zns = NULL;
struct zvni_evpn_show zes;
@@ -7373,13 +7385,13 @@ void zebra_vxlan_print_vnis_detail(struct vty *vty, struct zebra_vrf *zvrf,
if (!zns)
return;
-
if (use_json)
- json = json_object_new_object();
+ json_array = json_object_new_array();
zes.vty = vty;
- zes.json = json;
+ zes.json = json_array;
zes.zvrf = zvrf;
+ zes.use_json = use_json;
/* Display all L2-VNIs */
hash_iterate(
@@ -7396,8 +7408,8 @@ void zebra_vxlan_print_vnis_detail(struct vty *vty, struct zebra_vrf *zvrf,
if (use_json) {
vty_out(vty, "%s\n",
json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
+ json_array, JSON_C_TO_STRING_PRETTY));
+ json_object_free(json_array);
}
}
diff --git a/zebra/zebra_vxlan.h b/zebra/zebra_vxlan.h
index bb80ae1c9a..c85e932d35 100644
--- a/zebra/zebra_vxlan.h
+++ b/zebra/zebra_vxlan.h
@@ -141,7 +141,8 @@ extern void zebra_vxlan_print_neigh_vni_dad(struct vty *vty,
struct zebra_vrf *zvrf, vni_t vni,
bool use_json);
extern void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf,
- vni_t vni, bool use_json);
+ vni_t vni, bool use_json,
+ json_object *json_array);
extern void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf,
bool use_json);
extern void zebra_vxlan_print_vnis_detail(struct vty *vty,