diff options
| author | Donatas Abraitis <donatas.abraitis@gmail.com> | 2021-11-25 17:51:12 +0200 | 
|---|---|---|
| committer | Donatas Abraitis <donatas.abraitis@gmail.com> | 2021-11-25 17:51:12 +0200 | 
| commit | 75eeda93231620d732be3b1d4e62e74e9ac46e14 (patch) | |
| tree | ed569233301f880e630f7262bce0f7e07b197296 | |
| parent | 4e37fcb61e55ffdbe6b60891684e1a995852bc42 (diff) | |
bgpd: Convert vty_out to vty_json for JSON
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
| -rw-r--r-- | bgpd/bgp_evpn_mh.c | 26 | ||||
| -rw-r--r-- | bgpd/bgp_evpn_vty.c | 65 | ||||
| -rw-r--r-- | bgpd/bgp_filter.c | 10 | ||||
| -rw-r--r-- | bgpd/bgp_flowspec_vty.c | 6 | ||||
| -rw-r--r-- | bgpd/bgp_labelpool.c | 25 | ||||
| -rw-r--r-- | bgpd/bgp_route.c | 15 | ||||
| -rw-r--r-- | bgpd/bgp_vpn.c | 4 | ||||
| -rw-r--r-- | bgpd/bgp_vty.c | 59 | ||||
| -rw-r--r-- | bgpd/bgpd.c | 11 | 
9 files changed, 47 insertions, 174 deletions
diff --git a/bgpd/bgp_evpn_mh.c b/bgpd/bgp_evpn_mh.c index d35f86caf5..06a4cab382 100644 --- a/bgpd/bgp_evpn_mh.c +++ b/bgpd/bgp_evpn_mh.c @@ -2452,9 +2452,7 @@ void bgp_evpn_es_show(struct vty *vty, bool uj, bool detail)  	/* print the array of json-ESs */  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					json_array, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json_array); +		vty_json(vty, json_array);  	}  } @@ -2476,9 +2474,7 @@ void bgp_evpn_es_show_esi(struct vty *vty, esi_t *esi, bool uj)  	}  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  } @@ -3031,10 +3027,7 @@ void bgp_evpn_es_vrf_show(struct vty *vty, bool uj, struct bgp_evpn_es *es)  	/* print the array of json-ESs */  	if (uj) { -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json_array, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json_array); +		vty_json(vty, json_array);  	}  } @@ -3885,9 +3878,7 @@ void bgp_evpn_es_evi_show(struct vty *vty, bool uj, bool detail)  				  void *))bgp_evpn_es_evi_show_one_vni_hash_cb,  				&wctx);  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					json_array, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json_array); +		vty_json(vty, json_array);  	}  } @@ -3923,9 +3914,7 @@ void bgp_evpn_es_evi_show_vni(struct vty *vty, vni_t vni,  	}  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					json_array, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json_array); +		vty_json(vty, json_array);  	}  } @@ -4655,10 +4644,7 @@ void bgp_evpn_nh_show(struct vty *vty, bool uj)  	/* print the array of json-ESs */  	if (uj) { -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json_array, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json_array); +		vty_json(vty, json_array);  	}  } diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 89ed9551ce..33fce08065 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -1368,9 +1368,7 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd,  	if (use_json) {  		json_object_int_add(json, "numPrefix", output_count);  		json_object_int_add(json, "totalPrefix", total_count); -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -			json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	} else {  		if (output_count == 0)  			vty_out(vty, "No prefixes displayed, %ld exist\n", @@ -4390,12 +4388,7 @@ DEFUN(show_bgp_l2vpn_evpn_vni,  	}  	if (uj) { -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json, -				JSON_C_TO_STRING_PRETTY -					| JSON_C_TO_STRING_NOSLASHESCAPE)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; @@ -4675,9 +4668,7 @@ DEFUN(show_bgp_l2vpn_evpn_route,  	evpn_show_all_routes(vty, bgp, type, json, detail);  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS;  } @@ -4739,9 +4730,7 @@ DEFUN(show_bgp_l2vpn_evpn_route_rd,  		evpn_show_route_rd(vty, bgp, &prd, type, json);  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; @@ -4825,9 +4814,7 @@ DEFUN(show_bgp_l2vpn_evpn_route_rd_macip,  		evpn_show_route_rd_macip(vty, bgp, &prd, &mac, &ip, json);  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; @@ -4869,9 +4856,7 @@ DEFUN(show_bgp_l2vpn_evpn_route_esi,  	evpn_show_routes_esi(vty, bgp, &esi, json);  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; @@ -4939,9 +4924,7 @@ DEFUN(show_bgp_l2vpn_evpn_route_vni, show_bgp_l2vpn_evpn_route_vni_cmd,  	evpn_show_routes_vni(vty, bgp, vni, type, vtep_ip, json);  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; @@ -5009,9 +4992,7 @@ DEFUN(show_bgp_l2vpn_evpn_route_vni_macip,  	evpn_show_route_vni_macip(vty, bgp, vni, &mac, &ip, json);  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; @@ -5067,9 +5048,7 @@ DEFUN(show_bgp_l2vpn_evpn_route_vni_multicast,  	evpn_show_route_vni_multicast(vty, bgp, vni, orig_ip, json);  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; @@ -5130,9 +5109,7 @@ DEFUN(show_bgp_l2vpn_evpn_route_vni_all,  	evpn_show_routes_vni_all(vty, bgp, vtep_ip, json, da);  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; @@ -5166,10 +5143,7 @@ DEFPY_HIDDEN(  		json = json_object_new_object();  	bgp_evpn_show_routes_mac_ip_evi_es(vty, esi_p, json, !!detail);  	if (uj) { -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; @@ -5203,10 +5177,7 @@ DEFPY_HIDDEN(  		json = json_object_new_object();  	bgp_evpn_show_routes_mac_ip_global_es(vty, esi_p, json, !!detail);  	if (uj) { -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; @@ -5240,9 +5211,7 @@ DEFUN(show_bgp_l2vpn_evpn_vrf_import_rt,  	evpn_show_vrf_import_rts(vty, bgp_evpn, json);  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; @@ -5276,9 +5245,7 @@ DEFUN(show_bgp_l2vpn_evpn_import_rt,  	evpn_show_import_rts(vty, bgp, json);  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; @@ -5862,9 +5829,7 @@ DEFUN (show_bgp_vrf_l3vni_info,  	}  	if (uj) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS;  } diff --git a/bgpd/bgp_filter.c b/bgpd/bgp_filter.c index 7dda4f0180..2774b41a36 100644 --- a/bgpd/bgp_filter.c +++ b/bgpd/bgp_filter.c @@ -673,10 +673,7 @@ DEFUN (show_as_path_access_list,  		as_list_show(vty, aslist, json);  	if (uj) { -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; @@ -708,10 +705,7 @@ DEFUN (show_as_path_access_list_all,  	as_list_show_all(vty, json);  	if (uj) { -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; diff --git a/bgpd/bgp_flowspec_vty.c b/bgpd/bgp_flowspec_vty.c index 11487ed847..8873ca5c0c 100644 --- a/bgpd/bgp_flowspec_vty.c +++ b/bgpd/bgp_flowspec_vty.c @@ -449,11 +449,7 @@ int bgp_show_table_flowspec(struct vty *vty, struct bgp *bgp, afi_t afi,  					       pi, display, json_paths);  		}  		if (use_json) { -			vty_out(vty, "%s\n", -				json_object_to_json_string_ext( -						json_paths, -						JSON_C_TO_STRING_PRETTY)); -			json_object_free(json_paths); +			vty_json(vty, json_paths);  			json_paths = NULL;  		}  	} diff --git a/bgpd/bgp_labelpool.c b/bgpd/bgp_labelpool.c index fcb2df9d6f..b4eb5d54ad 100644 --- a/bgpd/bgp_labelpool.c +++ b/bgpd/bgp_labelpool.c @@ -638,10 +638,7 @@ DEFUN(show_bgp_labelpool_summary, show_bgp_labelpool_summary_cmd,  		json_object_int_add(json, "LabelChunks", listcount(lp->chunks));  		json_object_int_add(json, "Pending", lp->pending_count);  		json_object_int_add(json, "Reconnects", lp->reconnect_count); -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	} else {  		vty_out(vty, "Labelpool Summary\n");  		vty_out(vty, "-----------------\n"); @@ -739,10 +736,7 @@ DEFUN(show_bgp_labelpool_ledger, show_bgp_labelpool_ledger_cmd,  		}  	}  	if (uj) { -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS;  } @@ -834,10 +828,7 @@ DEFUN(show_bgp_labelpool_inuse, show_bgp_labelpool_inuse_cmd,  		}  	}  	if (uj) { -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS;  } @@ -912,10 +903,7 @@ DEFUN(show_bgp_labelpool_requests, show_bgp_labelpool_requests_cmd,  		}  	}  	if (uj) { -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS;  } @@ -963,10 +951,7 @@ DEFUN(show_bgp_labelpool_chunks, show_bgp_labelpool_chunks_cmd,  				chunk->last);  	}  	if (uj) { -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS;  } diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index b79fe778ae..809186afbf 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -11674,10 +11674,7 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp,  	}  	if (use_json) { -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY | -					     JSON_C_TO_STRING_NOSLASHESCAPE)); -		json_object_free(json); +		vty_json(vty, json);  	} else {  		if (!display) {  			vty_out(vty, "%% Network not in table\n"); @@ -13203,9 +13200,7 @@ static int bgp_peer_counts(struct vty *vty, struct peer *peer, afi_t afi,  				json, "recommended",  				"Please report this bug, with the above command output");  		} -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	} else {  		if (peer->hostname @@ -13765,10 +13760,6 @@ static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi,  		json_object_int_add(json, "filteredPrefixCounter",  				    filtered_count); -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json, JSON_C_TO_STRING_PRETTY)); -  		/*  		 * These fields only give up ownership to `json` when `header1`  		 * is used (set to zero). See code in `show_adj_route` and @@ -13779,7 +13770,7 @@ static int peer_adj_routes(struct vty *vty, struct peer *peer, afi_t afi,  			json_object_free(json_ocode);  		} -		json_object_free(json); +		vty_json(vty, json);  	} else if (output_count > 0) {  		if (filtered_count > 0)  			vty_out(vty, diff --git a/bgpd/bgp_vpn.c b/bgpd/bgp_vpn.c index bf630c1d89..6308936aa8 100644 --- a/bgpd/bgp_vpn.c +++ b/bgpd/bgp_vpn.c @@ -239,9 +239,7 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer,  		json_object_object_add(json, "advertisedRoutes", json_adv);  		json_object_int_add(json,  			"totalPrefixCounter", output_count); -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	} else  		vty_out(vty, "\nTotal number of prefixes %ld\n", output_count); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 88d84a3c50..9b098d4685 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -645,10 +645,7 @@ int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,  					json_object_string_add(  					  json, "warning",  					  "View/Vrf is unknown"); -					vty_out(vty, "%s\n", -						json_object_to_json_string_ext(json, -							JSON_C_TO_STRING_PRETTY)); -					json_object_free(json); +					vty_json(vty, json);  				}  				else  					vty_out(vty, "View/Vrf %s is unknown\n", @@ -666,10 +663,7 @@ int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty,  				json_object_string_add(  					json, "warning",  					"Default BGP instance not found"); -				vty_out(vty, "%s\n", -					json_object_to_json_string_ext(json, -						JSON_C_TO_STRING_PRETTY)); -				json_object_free(json); +				vty_json(vty, json);  			}  			else  				vty_out(vty, @@ -9724,9 +9718,7 @@ DEFUN (show_bgp_vrfs,  		json_object_int_add(json, "totalVrfs", count); -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	} else {  		if (count)  			vty_out(vty, @@ -10258,9 +10250,7 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,  			json_object_int_add(json, "dynamicPeers", dn_count);  			json_object_int_add(json, "totalPeers", count); -			vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -			json_object_free(json); +			vty_json(vty, json);  		} else {  			vty_out(vty, "%% No failed BGP neighbors found\n");  		} @@ -10829,9 +10819,7 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,  		if (!show_failed)  			bgp_show_bestpath_json(bgp, json); -		vty_out(vty, "%s\n", json_object_to_json_string_ext( -					     json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	} else {  		if (count) {  			if (filtered_count == count) @@ -14178,13 +14166,9 @@ static int bgp_show_neighbor_graceful_restart(struct vty *vty, struct bgp *bgp,  			vty_out(vty, "%% No such neighbor\n");  	}  	if (use_json) { -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json, JSON_C_TO_STRING_PRETTY)); -  		if (json_neighbor)  			json_object_free(json_neighbor); -		json_object_free(json); +		vty_json(vty, json);  	} else {  		vty_out(vty, "\n");  	} @@ -14424,11 +14408,7 @@ static int bgp_show_neighbor_vty(struct vty *vty, const char *name,  			if (!bgp) {  				if (use_json) {  					json = json_object_new_object(); -					vty_out(vty, "%s\n", -						json_object_to_json_string_ext( -							json, -							JSON_C_TO_STRING_PRETTY)); -					json_object_free(json); +					vty_json(vty, json);  				} else  					vty_out(vty,  						"%% BGP instance not found\n"); @@ -14737,11 +14717,7 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name,  		bgp = name ? bgp_lookup_by_name(name) : bgp_get_default();  		if (!bgp) { -			vty_out(vty, "%s\n", -				json_object_to_json_string_ext( -					json, -					JSON_C_TO_STRING_PRETTY)); -			json_object_free(json); +			vty_json(vty, json);  			return CMD_WARNING;  		} @@ -14813,10 +14789,7 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name,  		}  		if (use_json) { -			vty_out(vty, "%s\n", -				json_object_to_json_string_ext(json, -						      JSON_C_TO_STRING_PRETTY)); -			json_object_free(json); +			vty_json(vty, json);  		}  	} else {  		bgp = name ? bgp_lookup_by_name(name) : bgp_get_default(); @@ -14928,9 +14901,7 @@ static int bgp_show_all_instance_route_leak_vty(struct vty *vty, afi_t afi,  	if (use_json) {  		json_object_object_add(json, "vrfs", json_vrfs); -		vty_out(vty, "%s\n", json_object_to_json_string_ext(json, -						JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; @@ -15410,10 +15381,7 @@ static int bgp_show_peer_group_vty(struct vty *vty, const char *name,  	if (!bgp) {  		if (uj) { -			vty_out(vty, "%s\n", -				json_object_to_json_string_ext( -					json, JSON_C_TO_STRING_PRETTY)); -			json_object_free(json); +			vty_json(vty, json);  		} else {  			vty_out(vty, "%% BGP instance not found\n");  		} @@ -15437,10 +15405,7 @@ static int bgp_show_peer_group_vty(struct vty *vty, const char *name,  		vty_out(vty, "%% No such peer-group\n");  	if (uj) { -		vty_out(vty, "%s\n", -			json_object_to_json_string_ext( -				json, JSON_C_TO_STRING_PRETTY)); -		json_object_free(json); +		vty_json(vty, json);  	}  	return CMD_SUCCESS; diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 9316d71baf..877585cec1 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -7903,11 +7903,7 @@ struct peer *peer_lookup_in_view(struct vty *vty, struct bgp *bgp,  						json_no,  						"malformedAddressOrName",  						ip_str); -					vty_out(vty, "%s\n", -						json_object_to_json_string_ext( -							json_no, -							JSON_C_TO_STRING_PRETTY)); -					json_object_free(json_no); +					vty_json(vty, json_no);  				} else  					vty_out(vty,  						"%% Malformed address or name: %s\n", @@ -7926,10 +7922,7 @@ struct peer *peer_lookup_in_view(struct vty *vty, struct bgp *bgp,  			json_no = json_object_new_object();  			json_object_string_add(json_no, "warning",  					       "No such neighbor in this view/vrf"); -			vty_out(vty, "%s\n", -				json_object_to_json_string_ext( -					json_no, JSON_C_TO_STRING_PRETTY)); -			json_object_free(json_no); +			vty_json(vty, json_no);  		} else  			vty_out(vty, "No such neighbor in this view/vrf\n");  		return NULL;  | 
