diff options
| author | Donatas Abraitis <donatas@opensourcerouting.org> | 2023-04-06 12:48:52 +0300 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-06 12:48:52 +0300 | 
| commit | cf35e49354699fb920997ba2448ea2088acb6a30 (patch) | |
| tree | 023ff53576e4cd4c0f4ac3d7da6ded5bdd0d5899 | |
| parent | 02619b55225de13bff05c187bc211b64f9761090 (diff) | |
| parent | 61f3a6c353dee5fbbdf178e3b234dc4465ae99bc (diff) | |
Merge pull request #13214 from chiragshah6/fdev2
zebra:return empty dict in json when evpn is disabled
| -rw-r--r-- | zebra/zebra_vxlan.c | 214 | 
1 files changed, 127 insertions, 87 deletions
diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index c370ad9169..36290f99e0 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -2582,19 +2582,18 @@ void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni,  	struct zebra_mac *zrmac = NULL;  	json_object *json = NULL; +	if (use_json) +		json = json_object_new_object(); +  	if (!is_evpn_enabled()) { -		if (use_json) -			vty_out(vty, "{}\n"); +		vty_json(vty, json);  		return;  	} -	if (use_json) -		json = json_object_new_object(); -  	zl3vni = zl3vni_lookup(l3vni);  	if (!zl3vni) {  		if (use_json) -			vty_out(vty, "{}\n"); +			vty_json(vty, json);  		else  			vty_out(vty, "%% L3-VNI %u doesn't exist\n", l3vni);  		return; @@ -2603,7 +2602,7 @@ void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni,  	zrmac = zl3vni_rmac_lookup(zl3vni, rmac);  	if (!zrmac) {  		if (use_json) -			vty_out(vty, "{}\n"); +			vty_json(vty, json);  		else  			vty_out(vty,  				"%% Requested RMAC doesn't exist in L3-VNI %u\n", @@ -2624,13 +2623,18 @@ void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t l3vni, bool use_json)  	struct rmac_walk_ctx wctx;  	json_object *json = NULL; -	if (!is_evpn_enabled()) +	if (use_json) +		json = json_object_new_object(); + +	if (!is_evpn_enabled()) { +		vty_json(vty, json);  		return; +	}  	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);  		return; @@ -2639,9 +2643,6 @@ void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t l3vni, bool use_json)  	if (!num_rmacs)  		return; -	if (use_json) -		json = json_object_new_object(); -  	memset(&wctx, 0, sizeof(wctx));  	wctx.vty = vty;  	wctx.json = json; @@ -2663,15 +2664,14 @@ void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, bool use_json)  	json_object *json = NULL;  	void *args[2]; +	if (use_json) +		json = json_object_new_object(); +  	if (!is_evpn_enabled()) { -		if (use_json) -			vty_out(vty, "{}\n"); +		vty_json(vty, json);  		return;  	} -	if (use_json) -		json = json_object_new_object(); -  	args[0] = vty;  	args[1] = json;  	hash_iterate(zrouter.l3vni_table, @@ -2690,15 +2690,14 @@ void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, vni_t l3vni,  	struct zebra_neigh *n = NULL;  	json_object *json = NULL; +	if (use_json) +		json = json_object_new_object(); +  	if (!is_evpn_enabled()) { -		if (use_json) -			vty_out(vty, "{}\n"); +		vty_json(vty, json);  		return;  	} -	if (use_json) -		json = json_object_new_object(); -  	/* If vni=0 passed, assume svd lookup */  	if (!l3vni)  		n = svd_nh_lookup(ip); @@ -2799,15 +2798,14 @@ void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, bool use_json)  	json_object *json = NULL;  	void *args[2]; +	if (use_json) +		json = json_object_new_object(); +  	if (!is_evpn_enabled()) { -		if (use_json) -			vty_out(vty, "{}\n"); +		vty_json(vty, json);  		return;  	} -	if (use_json) -		json = json_object_new_object(); -  	args[0] = vty;  	args[1] = json;  	hash_iterate(zrouter.l3vni_table, @@ -2828,24 +2826,23 @@ void zebra_vxlan_print_l3vni(struct vty *vty, vni_t vni, bool use_json)  	json_object *json = NULL;  	struct zebra_l3vni *zl3vni = NULL; +	if (use_json) +		json = json_object_new_object(); +  	if (!is_evpn_enabled()) { -		if (use_json) -			vty_out(vty, "{}\n"); +		vty_json(vty, json);  		return;  	}  	zl3vni = zl3vni_lookup(vni);  	if (!zl3vni) {  		if (use_json) -			vty_out(vty, "{}\n"); +			vty_json(vty, json);  		else  			vty_out(vty, "%% VNI %u does not exist\n", vni);  		return;  	} -	if (use_json) -		json = json_object_new_object(); -  	args[0] = vty;  	args[1] = json;  	zl3vni_print(zl3vni, (void *)args); @@ -2900,12 +2897,18 @@ void zebra_vxlan_print_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf,  	struct neigh_walk_ctx wctx;  	json_object *json = NULL; -	if (!is_evpn_enabled()) +	if (use_json) +		json = json_object_new_object(); + +	if (!is_evpn_enabled()) { +		vty_json(vty, json);  		return; +	} +  	zevpn = zebra_evpn_lookup(vni);  	if (!zevpn) {  		if (use_json) -			vty_out(vty, "{}\n"); +			vty_json(vty, json);  		else  			vty_out(vty, "%% VNI %u does not exist\n", vni);  		return; @@ -2914,9 +2917,6 @@ void zebra_vxlan_print_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf,  	if (!num_neigh)  		return; -	if (use_json) -		json = json_object_new_object(); -  	/* Since we have IPv6 addresses to deal with which can vary widely in  	 * size, we try to be a bit more elegant in display by first computing  	 * the maximum width. @@ -2951,12 +2951,14 @@ void zebra_vxlan_print_neigh_all_vni(struct vty *vty, struct zebra_vrf *zvrf,  	json_object *json = NULL;  	void *args[3]; -	if (!is_evpn_enabled()) -		return; -  	if (use_json)  		json = json_object_new_object(); +	if (!is_evpn_enabled()) { +		vty_json(vty, json); +		return; +	} +  	args[0] = vty;  	args[1] = json;  	args[2] = (void *)(ptrdiff_t)print_dup; @@ -2979,12 +2981,14 @@ void zebra_vxlan_print_neigh_all_vni_detail(struct vty *vty,  	json_object *json = NULL;  	void *args[3]; -	if (!is_evpn_enabled()) -		return; -  	if (use_json)  		json = json_object_new_object(); +	if (!is_evpn_enabled()) { +		vty_json(vty, json); +		return; +	} +  	args[0] = vty;  	args[1] = json;  	args[2] = (void *)(ptrdiff_t)print_dup; @@ -3008,12 +3012,18 @@ void zebra_vxlan_print_specific_neigh_vni(struct vty *vty,  	struct zebra_neigh *n;  	json_object *json = NULL; -	if (!is_evpn_enabled()) +	if (use_json) +		json = json_object_new_object(); + +	if (!is_evpn_enabled()) { +		vty_json(vty, json);  		return; +	} +  	zevpn = zebra_evpn_lookup(vni);  	if (!zevpn) {  		if (use_json) -			vty_out(vty, "{}\n"); +			vty_json(vty, json);  		else  			vty_out(vty, "%% VNI %u does not exist\n", vni);  		return; @@ -3026,8 +3036,6 @@ void zebra_vxlan_print_specific_neigh_vni(struct vty *vty,  				vni);  		return;  	} -	if (use_json) -		json = json_object_new_object();  	zebra_evpn_print_neigh(n, vty, json); @@ -3048,12 +3056,18 @@ void zebra_vxlan_print_neigh_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf,  	struct neigh_walk_ctx wctx;  	json_object *json = NULL; -	if (!is_evpn_enabled()) +	if (use_json) +		json = json_object_new_object(); + +	if (!is_evpn_enabled()) { +		vty_json(vty, json);  		return; +	} +  	zevpn = zebra_evpn_lookup(vni);  	if (!zevpn) {  		if (use_json) -			vty_out(vty, "{}\n"); +			vty_json(vty, json);  		else  			vty_out(vty, "%% VNI %u does not exist\n", vni);  		return; @@ -3062,9 +3076,6 @@ void zebra_vxlan_print_neigh_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf,  	if (!num_neigh)  		return; -	if (use_json) -		json = json_object_new_object(); -  	memset(&wctx, 0, sizeof(wctx));  	wctx.zevpn = zevpn;  	wctx.vty = vty; @@ -3094,12 +3105,20 @@ void zebra_vxlan_print_neigh_vni_dad(struct vty *vty,  	struct neigh_walk_ctx wctx;  	json_object *json = NULL; -	if (!is_evpn_enabled()) +	if (use_json) +		json = json_object_new_object(); + +	if (!is_evpn_enabled()) { +		vty_json(vty, json);  		return; +	}  	zevpn = zebra_evpn_lookup(vni);  	if (!zevpn) { -		vty_out(vty, "%% VNI %u does not exist\n", vni); +		if (use_json) +			vty_json(vty, json); +		else +			vty_out(vty, "%% VNI %u does not exist\n", vni);  		return;  	} @@ -3111,9 +3130,6 @@ void zebra_vxlan_print_neigh_vni_dad(struct vty *vty,  	if (!num_neigh)  		return; -	if (use_json) -		json = json_object_new_object(); -  	/* Since we have IPv6 addresses to deal with which can vary widely in  	 * size, we try to be a bit more elegant in display by first computing  	 * the maximum width. @@ -3155,8 +3171,12 @@ void zebra_vxlan_print_macs_vni(struct vty *vty, struct zebra_vrf *zvrf,  	json_object *json = NULL;  	json_object *json_mac = NULL; -	if (!is_evpn_enabled()) +	if (!is_evpn_enabled()) { +		if (use_json) +			vty_out(vty, "{}\n");  		return; +	} +  	zevpn = zebra_evpn_lookup(vni);  	if (!zevpn) {  		if (use_json) @@ -3218,13 +3238,13 @@ void zebra_vxlan_print_macs_all_vni(struct vty *vty, struct zebra_vrf *zvrf,  	struct mac_walk_ctx wctx;  	json_object *json = NULL; +	if (use_json) +		json = json_object_new_object(); +  	if (!is_evpn_enabled()) { -		if (use_json) -			vty_out(vty, "{}\n"); +		vty_json(vty, json);  		return;  	} -	if (use_json) -		json = json_object_new_object();  	memset(&wctx, 0, sizeof(wctx));  	wctx.vty = vty; @@ -3246,13 +3266,13 @@ void zebra_vxlan_print_macs_all_vni_detail(struct vty *vty,  	struct mac_walk_ctx wctx;  	json_object *json = NULL; +	if (use_json) +		json = json_object_new_object(); +  	if (!is_evpn_enabled()) { -		if (use_json) -			vty_out(vty, "{}\n"); +		vty_json(vty, json);  		return;  	} -	if (use_json) -		json = json_object_new_object();  	memset(&wctx, 0, sizeof(wctx));  	wctx.vty = vty; @@ -3275,12 +3295,14 @@ void zebra_vxlan_print_macs_all_vni_vtep(struct vty *vty,  	struct mac_walk_ctx wctx;  	json_object *json = NULL; -	if (!is_evpn_enabled()) -		return; -  	if (use_json)  		json = json_object_new_object(); +	if (!is_evpn_enabled()) { +		vty_json(vty, json); +		return; +	} +  	memset(&wctx, 0, sizeof(wctx));  	wctx.vty = vty;  	wctx.flags = SHOW_REMOTE_MAC_FROM_VTEP; @@ -3303,13 +3325,18 @@ void zebra_vxlan_print_specific_mac_vni(struct vty *vty, struct zebra_vrf *zvrf,  	struct zebra_mac *mac;  	json_object *json = NULL; -	if (!is_evpn_enabled()) +	if (use_json) +		json = json_object_new_object(); + +	if (!is_evpn_enabled()) { +		vty_json(vty, json);  		return; +	}  	zevpn = zebra_evpn_lookup(vni);  	if (!zevpn) {  		if (use_json) -			vty_out(vty, "{}\n"); +			vty_json(vty, json);  		else  			vty_out(vty, "%% VNI %u does not exist\n", vni);  		return; @@ -3317,7 +3344,7 @@ void zebra_vxlan_print_specific_mac_vni(struct vty *vty, struct zebra_vrf *zvrf,  	mac = zebra_evpn_mac_lookup(zevpn, macaddr);  	if (!mac) {  		if (use_json) -			vty_out(vty, "{}\n"); +			vty_json(vty, json);  		else  			vty_out(vty,  				"%% Requested MAC does not exist in VNI %u\n", @@ -3325,10 +3352,8 @@ void zebra_vxlan_print_specific_mac_vni(struct vty *vty, struct zebra_vrf *zvrf,  		return;  	} -	if (use_json) -		json = json_object_new_object(); -  	zebra_evpn_print_mac(mac, vty, json); +  	if (use_json)  		vty_json(vty, json);  } @@ -3693,8 +3718,11 @@ void zebra_vxlan_print_macs_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf,  	json_object *json = NULL;  	json_object *json_mac = NULL; -	if (!is_evpn_enabled()) +	if (!is_evpn_enabled()) { +		vty_json(vty, json);  		return; +	} +  	zevpn = zebra_evpn_lookup(vni);  	if (!zevpn) {  		if (use_json) @@ -3745,12 +3773,14 @@ void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni,  	struct zebra_l3vni *zl3vni = NULL;  	struct zebra_evpn *zevpn = NULL; -	if (!is_evpn_enabled()) -		return; -  	if (use_json)  		json = json_object_new_object(); +	if (!is_evpn_enabled()) { +		vty_json(vty, json); +		return; +	} +  	args[0] = vty;  	args[1] = json; @@ -3787,8 +3817,13 @@ void zebra_vxlan_print_evpn(struct vty *vty, bool uj)  	json_object *json = NULL;  	struct zebra_vrf *zvrf = NULL; -	if (!is_evpn_enabled()) +	if (uj) +		json = json_object_new_object(); + +	if (!is_evpn_enabled()) { +		vty_json(vty, json);  		return; +	}  	zvrf = zebra_vrf_get_evpn(); @@ -3797,7 +3832,6 @@ void zebra_vxlan_print_evpn(struct vty *vty, bool uj)  	num_vnis = num_l2vnis + num_l3vnis;  	if (uj) { -		json = json_object_new_object();  		json_object_string_add(json, "advertiseGatewayMacip",  				       zvrf->advertise_gw_macip ? "Yes" : "No");  		json_object_string_add(json, "advertiseSviMacip", @@ -3860,12 +3894,15 @@ void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf,  	json_object *json = NULL;  	void *args[2]; -	if (!is_evpn_enabled()) -		return; -  	if (use_json)  		json = json_object_new_object(); -	else + +	if (!is_evpn_enabled()) { +		vty_json(vty, json); +		return; +	} + +	if (!use_json)  		vty_out(vty, "%-10s %-4s %-21s %-8s %-8s %-15s %-37s\n", "VNI",  			"Type", "VxLAN IF", "# MACs", "# ARPs",  			"# Remote VTEPs", "Tenant VRF"); @@ -3943,8 +3980,11 @@ void zebra_vxlan_print_vnis_detail(struct vty *vty, struct zebra_vrf *zvrf,  	struct zebra_ns *zns = NULL;  	struct zebra_evpn_show zes; -	if (!is_evpn_enabled()) +	if (!is_evpn_enabled()) { +		if (use_json) +			vty_out(vty, "{}\n");  		return; +	}  	zns = zebra_ns_lookup(NS_DEFAULT);  	if (!zns)  | 
