struct bgp_table *table;
struct bgp_adj_in *ain;
struct bgp_adj_out *adj;
- unsigned long output_count;
- unsigned long filtered_count;
+ unsigned long output_count = 0;
+ unsigned long filtered_count = 0;
struct bgp_node *rn;
int header1 = 1;
struct bgp *bgp;
vty_out(vty, "%s\n", json_object_to_json_string_ext(
json, JSON_C_TO_STRING_PRETTY));
+
+ if (!output_count && !filtered_count) {
+ json_object_free(json_scode);
+ json_object_free(json_ocode);
+ }
+
json_object_free(json);
} else if (output_count > 0) {
if (filtered_count > 0)
enum show_type type,
union sockunion *su,
const char *conf_if, afi_t afi,
- bool use_json, json_object *json)
+ bool use_json)
{
struct listnode *node, *nnode;
struct peer *peer;
int find = 0;
safi_t safi = SAFI_UNICAST;
+ json_object *json = NULL;
json_object *json_neighbor = NULL;
+ if (use_json) {
+ json = json_object_new_object();
+ json_neighbor = json_object_new_object();
+ }
+
for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) {
if (!CHECK_FLAG(peer->flags, PEER_FLAG_CONFIG_NODE))
if ((peer->afc[afi][safi]) == 0)
continue;
- if (use_json)
- json_neighbor = json_object_new_object();
-
if (type == show_all) {
bgp_show_peer_gr_status(vty, peer, use_json,
json_neighbor);
- if (use_json)
+ if (use_json) {
json_object_object_add(json, peer->host,
json_neighbor);
+ json_neighbor = NULL;
+ }
} else if (type == show_peer) {
if (conf_if) {
json_neighbor);
}
- if (find)
+ if (find) {
+ json_neighbor = NULL;
break;
+ }
}
if (type == show_peer && !find) {
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);
} else {
vty_out(vty, "\n");
}
int ret;
struct bgp *bgp;
union sockunion su;
- json_object *json = NULL;
bgp = bgp_get_default();
bgp_show_global_graceful_restart_mode_vty(vty, bgp, use_json,
NULL);
- json = json_object_new_object();
if (ip_str) {
ret = str2sockunion(ip_str, &su);
if (ret < 0)
- bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL,
- ip_str, afi,
- use_json, json);
- else
bgp_show_neighbor_graceful_restart(
- vty, bgp, type, &su, NULL, afi, use_json, json);
+ vty, bgp, type, NULL, ip_str, afi, use_json);
+ else
+ bgp_show_neighbor_graceful_restart(vty, bgp, type, &su,
+ NULL, afi, use_json);
} else
bgp_show_neighbor_graceful_restart(vty, bgp, type, NULL, NULL,
- afi, use_json, json);
- json_object_free(json);
+ afi, use_json);
}
static void bgp_show_all_instances_neighbors_vty(struct vty *vty,