Merge pull request #13576 from chiragshah6/mdev1

zebra:returns empty dict when evpn is disabled II
This commit is contained in:
Donatas Abraitis 2023-10-30 08:55:49 +02:00 committed by GitHub
commit 73914a3e73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 101 additions and 57 deletions

View File

@ -383,11 +383,14 @@ int vty_json_no_pretty(struct vty *vty, struct json_object *json)
return vty_json_helper(vty, json, JSON_C_TO_STRING_NOSLASHESCAPE);
}
void vty_json_empty(struct vty *vty)
void vty_json_empty(struct vty *vty, struct json_object *json)
{
json_object *json = json_object_new_object();
json_object *jsonobj = json;
vty_json(vty, json);
if (!json)
jsonobj = json_object_new_object();
vty_json(vty, jsonobj);
}
/* Output current time to the vty. */

View File

@ -377,7 +377,7 @@ extern bool vty_set_include(struct vty *vty, const char *regexp);
*/
extern int vty_json(struct vty *vty, struct json_object *json);
extern int vty_json_no_pretty(struct vty *vty, struct json_object *json);
extern void vty_json_empty(struct vty *vty);
extern void vty_json_empty(struct vty *vty, struct json_object *json);
/* post fd to be passed to the vtysh client
* fd is owned by the VTY code after this and will be closed when done
*/

View File

@ -5709,7 +5709,7 @@ DEFPY(show_ip_ospf_neighbor_id,
"%% OSPF is not enabled in vrf %s\n",
vrf_name);
else
vty_json_empty(vty);
vty_json_empty(vty, NULL);
return CMD_SUCCESS;
}
ret = show_ip_ospf_neighbor_id_common(
@ -6210,7 +6210,7 @@ DEFPY(show_ip_ospf_neighbor_int,
if (!ospf || !ospf->oi_running) {
if (json)
vty_json_empty(vty);
vty_json_empty(vty, NULL);
return ret;
}
@ -6220,7 +6220,7 @@ DEFPY(show_ip_ospf_neighbor_int,
ifp = if_lookup_by_name(ifname, vrf_id);
if (!ifp) {
if (json)
vty_json_empty(vty);
vty_json_empty(vty, NULL);
else
vty_out(vty, "No such interface.\n");
return ret;
@ -6257,7 +6257,7 @@ DEFPY(show_ip_ospf_neighbor_int_detail,
"%% OSPF is not enabled in vrf %s\n",
vrf_name);
else
vty_json_empty(vty);
vty_json_empty(vty, NULL);
return CMD_SUCCESS;
}
return show_ip_ospf_neighbor_int_detail_common(

View File

@ -78,7 +78,7 @@ static struct vrf *pim_cmd_lookup_vrf(struct vty *vty, struct cmd_token *argv[],
if (!vrf) {
if (uj)
vty_json_empty(vty);
vty_json_empty(vty, NULL);
else
vty_out(vty, "Specified VRF: %s does not exist\n",
argv[*idx]->arg);

View File

@ -308,7 +308,7 @@ static void zevpn_print_neigh_hash_all_evpn_detail(struct hash_bucket *bucket,
zevpn = (struct zebra_evpn *)bucket->data;
if (!zevpn) {
if (json)
vty_out(vty, "{}\n");
vty_json_empty(vty, json);
return;
}
num_neigh = hashcount(zevpn->neigh_table);
@ -515,7 +515,7 @@ static void zevpn_print_mac_hash_all_evpn_detail(struct hash_bucket *bucket,
zevpn = (struct zebra_evpn *)bucket->data;
if (!zevpn) {
if (json)
vty_out(vty, "{}\n");
vty_json_empty(vty, json);
return;
}
wctx->zevpn = zevpn;
@ -2590,14 +2590,15 @@ void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni,
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
zl3vni = zl3vni_lookup(l3vni);
if (!zl3vni) {
if (use_json)
vty_json(vty, json);
vty_json_empty(vty, json);
else
vty_out(vty, "%% L3-VNI %u doesn't exist\n", l3vni);
return;
@ -2631,14 +2632,15 @@ void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t l3vni, bool use_json)
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
zl3vni = zl3vni_lookup(l3vni);
if (!zl3vni) {
if (use_json)
vty_json(vty, json);
vty_json_empty(vty, json);
else
vty_out(vty, "%% L3-VNI %u does not exist\n", l3vni);
return;
@ -2672,7 +2674,8 @@ void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, bool use_json)
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
@ -2698,7 +2701,8 @@ void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, vni_t l3vni,
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
@ -2709,7 +2713,7 @@ void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, vni_t l3vni,
zl3vni = zl3vni_lookup(l3vni);
if (!zl3vni) {
if (use_json)
vty_out(vty, "{}\n");
vty_json(vty, json);
else
vty_out(vty, "%% L3-VNI %u does not exist\n",
l3vni);
@ -2721,7 +2725,7 @@ void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, vni_t l3vni,
if (!n) {
if (use_json)
vty_out(vty, "{}\n");
vty_json_empty(vty, json);
else
vty_out(vty,
"%% Requested next-hop not present for L3-VNI %u\n",
@ -2742,13 +2746,16 @@ static void l3vni_print_nh_table(struct hash *nh_table, struct vty *vty,
struct nh_walk_ctx wctx;
json_object *json = NULL;
num_nh = hashcount(nh_table);
if (!num_nh)
return;
if (use_json)
json = json_object_new_object();
num_nh = hashcount(nh_table);
if (!num_nh) {
if (use_json)
vty_json_empty(vty, json);
return;
}
wctx.vty = vty;
wctx.json = json;
if (!use_json) {
@ -2770,14 +2777,14 @@ void zebra_vxlan_print_nh_l3vni(struct vty *vty, vni_t l3vni, bool use_json)
if (!is_evpn_enabled()) {
if (use_json)
vty_out(vty, "{}\n");
vty_json_empty(vty, NULL);
return;
}
zl3vni = zl3vni_lookup(l3vni);
if (!zl3vni) {
if (use_json)
vty_out(vty, "{}\n");
vty_json_empty(vty, NULL);
else
vty_out(vty, "%% L3-VNI %u does not exist\n", l3vni);
return;
@ -2790,7 +2797,7 @@ void zebra_vxlan_print_nh_svd(struct vty *vty, bool use_json)
{
if (!is_evpn_enabled()) {
if (use_json)
vty_out(vty, "{}\n");
vty_json_empty(vty, NULL);
return;
}
@ -2806,7 +2813,8 @@ void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, bool use_json)
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
@ -2834,14 +2842,15 @@ void zebra_vxlan_print_l3vni(struct vty *vty, vni_t vni, bool use_json)
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
zl3vni = zl3vni_lookup(vni);
if (!zl3vni) {
if (use_json)
vty_json(vty, json);
vty_json_empty(vty, json);
else
vty_out(vty, "%% VNI %u does not exist\n", vni);
return;
@ -2905,14 +2914,15 @@ void zebra_vxlan_print_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf,
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
if (use_json)
vty_json(vty, json);
vty_json_empty(vty, json);
else
vty_out(vty, "%% VNI %u does not exist\n", vni);
return;
@ -2959,7 +2969,8 @@ void zebra_vxlan_print_neigh_all_vni(struct vty *vty, struct zebra_vrf *zvrf,
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
@ -2989,7 +3000,8 @@ void zebra_vxlan_print_neigh_all_vni_detail(struct vty *vty,
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
@ -3020,14 +3032,15 @@ void zebra_vxlan_print_specific_neigh_vni(struct vty *vty,
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
if (use_json)
vty_json(vty, json);
vty_json_empty(vty, json);
else
vty_out(vty, "%% VNI %u does not exist\n", vni);
return;
@ -3064,14 +3077,15 @@ void zebra_vxlan_print_neigh_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf,
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
if (use_json)
vty_json(vty, json);
vty_json_empty(vty, json);
else
vty_out(vty, "%% VNI %u does not exist\n", vni);
return;
@ -3113,14 +3127,15 @@ void zebra_vxlan_print_neigh_vni_dad(struct vty *vty,
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
if (use_json)
vty_json(vty, json);
vty_json_empty(vty, json);
else
vty_out(vty, "%% VNI %u does not exist\n", vni);
return;
@ -3177,21 +3192,24 @@ void zebra_vxlan_print_macs_vni(struct vty *vty, struct zebra_vrf *zvrf,
if (!is_evpn_enabled()) {
if (use_json)
vty_out(vty, "{}\n");
vty_json_empty(vty, NULL);
return;
}
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
if (use_json)
vty_out(vty, "{}\n");
vty_json_empty(vty, NULL);
else
vty_out(vty, "%% VNI %u does not exist\n", vni);
return;
}
num_macs = num_valid_macs(zevpn);
if (!num_macs)
if (!num_macs) {
if (use_json)
vty_json_empty(vty, NULL);
return;
}
if (use_json) {
json = json_object_new_object();
@ -3250,7 +3268,8 @@ void zebra_vxlan_print_macs_all_vni(struct vty *vty, struct zebra_vrf *zvrf,
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
@ -3278,7 +3297,8 @@ void zebra_vxlan_print_macs_all_vni_detail(struct vty *vty,
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
@ -3307,7 +3327,8 @@ void zebra_vxlan_print_macs_all_vni_vtep(struct vty *vty,
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
@ -3337,7 +3358,8 @@ void zebra_vxlan_print_specific_mac_vni(struct vty *vty, struct zebra_vrf *zvrf,
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
@ -3377,22 +3399,34 @@ void zebra_vxlan_print_macs_vni_dad(struct vty *vty,
json_object *json = NULL;
json_object *json_mac = NULL;
if (!is_evpn_enabled())
if (!is_evpn_enabled()) {
if (use_json)
vty_json_empty(vty, NULL);
return;
}
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
vty_out(vty, "%% VNI %u does not exist\n", vni);
if (use_json)
vty_json_empty(vty, NULL);
else
vty_out(vty, "%% VNI %u does not exist\n", vni);
return;
}
num_macs = num_valid_macs(zevpn);
if (!num_macs)
if (!num_macs) {
if (use_json)
vty_json_empty(vty, NULL);
return;
}
num_macs = num_dup_detected_macs(zevpn);
if (!num_macs)
if (!num_macs) {
if (use_json)
vty_json_empty(vty, NULL);
return;
}
if (use_json) {
json = json_object_new_object();
@ -3727,21 +3761,25 @@ void zebra_vxlan_print_macs_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf,
json_object *json_mac = NULL;
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, NULL);
return;
}
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
if (use_json)
vty_out(vty, "{}\n");
vty_json_empty(vty, NULL);
else
vty_out(vty, "%% VNI %u does not exist\n", vni);
return;
}
num_macs = num_valid_macs(zevpn);
if (!num_macs)
if (!num_macs) {
if (use_json)
vty_json_empty(vty, NULL);
return;
}
if (use_json) {
json = json_object_new_object();
@ -3785,7 +3823,8 @@ void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni,
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
@ -3829,7 +3868,8 @@ void zebra_vxlan_print_evpn(struct vty *vty, bool uj)
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (uj)
vty_json(vty, json);
return;
}
@ -3906,7 +3946,8 @@ void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf,
json = json_object_new_object();
if (!is_evpn_enabled()) {
vty_json(vty, json);
if (use_json)
vty_json_empty(vty, json);
return;
}
@ -3990,7 +4031,7 @@ void zebra_vxlan_print_vnis_detail(struct vty *vty, struct zebra_vrf *zvrf,
if (!is_evpn_enabled()) {
if (use_json)
vty_out(vty, "{}\n");
vty_json_empty(vty, NULL);
return;
}