diff options
| author | Donatas Abraitis <donatas@opensourcerouting.org> | 2023-10-30 08:55:49 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-30 08:55:49 +0200 | 
| commit | 73914a3e730f5d8464d72a7228a060183ced8209 (patch) | |
| tree | c8478cfaada4f791a7fe0a0be43146e7eb45e2d8 | |
| parent | f969bc0459a0aa530a5a8e2eddd6faf8249d8f21 (diff) | |
| parent | 28eaac01315d41a3bb7a903b9c4d74da412e4317 (diff) | |
Merge pull request #13576 from chiragshah6/mdev1
zebra:returns empty dict when evpn is disabled II
| -rw-r--r-- | lib/vty.c | 9 | ||||
| -rw-r--r-- | lib/vty.h | 2 | ||||
| -rw-r--r-- | ospfd/ospf_vty.c | 8 | ||||
| -rw-r--r-- | pimd/pim_cmd.c | 2 | ||||
| -rw-r--r-- | zebra/zebra_vxlan.c | 137 | 
5 files changed, 101 insertions, 57 deletions
@@ -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. */ @@ -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   */ diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 8c3ad7f372..0fcbee9b08 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -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( diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 2e90cf9053..628a445945 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -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); diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index 50a7462d89..5480a94d27 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -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;  	}  | 
