summaryrefslogtreecommitdiff
path: root/ospfd/ospf_vty.c
diff options
context:
space:
mode:
Diffstat (limited to 'ospfd/ospf_vty.c')
-rw-r--r--ospfd/ospf_vty.c518
1 files changed, 167 insertions, 351 deletions
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 5b9519ea59..6979b34196 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -3043,7 +3043,6 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf,
struct ospf_area *area;
struct timeval result;
char timebuf[OSPF_TIME_DUMP_SIZE];
- char buf[PREFIX_STRLEN];
json_object *json_vrf = NULL;
json_object *json_areas = NULL;
@@ -3068,9 +3067,8 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf,
/* Show Router ID. */
if (json) {
- json_object_string_add(json_vrf, "routerId",
- inet_ntop(AF_INET, &ospf->router_id,
- buf, sizeof(buf)));
+ json_object_string_addf(json_vrf, "routerId", "%pI4",
+ &ospf->router_id);
} else {
vty_out(vty, " OSPF Routing Process, Router ID: %pI4\n",
&ospf->router_id);
@@ -3388,23 +3386,17 @@ DEFUN (show_ip_ospf,
ret = show_ip_ospf_common(vty, ospf, json,
use_vrf);
}
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else if (!ospf_output)
+ if (uj)
+ vty_json(vty, json);
+ else if (!ospf_output)
vty_out(vty, "%% OSPF instance not found\n");
return ret;
}
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if ((ospf == NULL) || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -3413,12 +3405,9 @@ DEFUN (show_ip_ospf,
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
/* Display default ospf (instance 0) info */
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -3468,11 +3457,8 @@ DEFUN (show_ip_ospf_instance,
ret = show_ip_ospf_common(vty, ospf, json, 0);
- if (uj) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -3533,7 +3519,6 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
int is_up;
struct ospf_neighbor *nbr;
struct route_node *rn;
- char buf[PREFIX_STRLEN];
uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed;
/* Is interface up? */
@@ -3603,11 +3588,9 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
/* Show OSPF interface information. */
if (use_json) {
- json_object_string_add(
- json_interface_sub, "ipAddress",
- inet_ntop(AF_INET,
- &oi->address->u.prefix4,
- buf, sizeof(buf)));
+ json_object_string_addf(
+ json_interface_sub, "ipAddress", "%pI4",
+ &oi->address->u.prefix4);
json_object_int_add(json_interface_sub,
"ipAddressPrefixlen",
oi->address->prefixlen);
@@ -3637,17 +3620,13 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
json_interface_sub,
"ospfIfType", dstr);
if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
- json_object_string_add(
- json_interface_sub,
- "vlinkPeer",
- inet_ntop(AF_INET, &dest,
- buf, sizeof(buf)));
+ json_object_string_addf(
+ json_interface_sub, "vlinkPeer",
+ "%pI4", &dest);
else
- json_object_string_add(
+ json_object_string_addf(
json_interface_sub,
- "localIfUsed",
- inet_ntop(AF_INET, &dest,
- buf, sizeof(buf)));
+ "localIfUsed", "%pI4", &dest);
} else
vty_out(vty, " %s %pI4,", dstr,
&dest);
@@ -3659,10 +3638,8 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
json_object_boolean_true_add(
json_interface_sub,
"mtuMismatchDetect");
- json_object_string_add(
- json_interface_sub, "routerId",
- inet_ntop(AF_INET, &ospf->router_id,
- buf, sizeof(buf)));
+ json_object_string_addf(json_interface_sub, "routerId",
+ "%pI4", &ospf->router_id);
json_object_string_add(json_interface_sub,
"networkType",
ospf_network_type_str[oi->type]);
@@ -3706,17 +3683,13 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi));
if (nbr) {
if (use_json) {
- json_object_string_add(
+ json_object_string_addf(
json_interface_sub, "drId",
- inet_ntop(AF_INET,
- &nbr->router_id, buf,
- sizeof(buf)));
- json_object_string_add(
+ "%pI4", &nbr->router_id);
+ json_object_string_addf(
json_interface_sub, "drAddress",
- inet_ntop(
- AF_INET,
- &nbr->address.u.prefix4,
- buf, sizeof(buf)));
+ "%pI4",
+ &nbr->address.u.prefix4);
} else {
vty_out(vty,
" Designated Router (ID) %pI4",
@@ -3735,18 +3708,13 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
" No backup designated router on this network\n");
} else {
if (use_json) {
- json_object_string_add(
+ json_object_string_addf(
json_interface_sub, "bdrId",
- inet_ntop(AF_INET,
- &nbr->router_id,
- buf, sizeof(buf)));
- json_object_string_add(
+ "%pI4", &nbr->router_id);
+ json_object_string_addf(
json_interface_sub,
- "bdrAddress",
- inet_ntop(AF_INET,
- &nbr->address.u
- .prefix4,
- buf, sizeof(buf)));
+ "bdrAddress", "%pI4",
+ &nbr->address.u.prefix4);
} else {
vty_out(vty,
" Backup Designated Router (ID) %pI4,",
@@ -4150,24 +4118,18 @@ DEFUN (show_ip_ospf_interface,
uj);
}
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else if (!ospf)
+ if (uj)
+ vty_json(vty, json);
+ else if (!ospf)
vty_out(vty, "%% OSPF instance not found\n");
return ret;
}
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -4179,12 +4141,9 @@ DEFUN (show_ip_ospf_interface,
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -4193,11 +4152,8 @@ DEFUN (show_ip_ospf_interface,
use_vrf, json, uj);
}
- if (uj) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -4238,11 +4194,8 @@ DEFUN (show_ip_ospf_instance_interface,
ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj);
- if (uj) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -4293,12 +4246,8 @@ DEFUN (show_ip_ospf_interface_traffic,
display_once = 1;
}
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -4323,11 +4272,8 @@ DEFUN (show_ip_ospf_interface_traffic,
vty, ospf, intf_name, json, display_once, use_vrf, uj);
}
- if (uj) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -4347,7 +4293,6 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty,
struct route_node *rn;
struct ospf_neighbor *nbr, *prev_nbr = NULL;
char msgbuf[16];
- char buf[PREFIX_STRLEN];
char timebuf[OSPF_TIME_DUMP_SIZE];
json_object *json_neighbor = NULL, *json_neigh_array = NULL;
struct timeval res = {.tv_sec = 0, .tv_usec = 0};
@@ -4447,10 +4392,9 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty,
"deadTimeMsecs",
"inactive");
}
- json_object_string_add(
- json_neighbor, "address",
- inet_ntop(AF_INET, &nbr->src,
- buf, sizeof(buf)));
+ json_object_string_addf(json_neighbor,
+ "address", "%pI4",
+ &nbr->src);
json_object_string_add(json_neighbor,
"ifaceName",
IF_NAME(oi));
@@ -4582,12 +4526,9 @@ DEFUN (show_ip_ospf_neighbor,
vty, ospf, json, uj, use_vrf);
}
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else if (!ospf)
+ if (uj)
+ vty_json(vty, json);
+ else if (!ospf)
vty_out(vty, "OSPF instance not found\n");
return ret;
@@ -4595,12 +4536,9 @@ DEFUN (show_ip_ospf_neighbor,
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -4609,12 +4547,9 @@ DEFUN (show_ip_ospf_neighbor,
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -4669,11 +4604,8 @@ DEFUN (show_ip_ospf_instance_neighbor,
ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0);
- if (uj) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -4807,12 +4739,8 @@ DEFUN (show_ip_ospf_neighbor_all,
vty, ospf, json, uj, use_vrf);
}
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -4879,11 +4807,8 @@ DEFUN (show_ip_ospf_instance_neighbor_all,
ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0);
- if (uj) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -4928,11 +4853,9 @@ static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
show_ip_ospf_neighbor_sub(vty, oi, json, use_json);
}
- if (use_json) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (use_json)
+ vty_json(vty, json);
+ else
vty_out(vty, "\n");
return CMD_SUCCESS;
@@ -5028,7 +4951,6 @@ static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
bool use_json, json_object *json)
{
char timebuf[OSPF_TIME_DUMP_SIZE];
- char buf[PREFIX_STRLEN];
json_object *json_sub = NULL;
if (use_json)
@@ -5038,9 +4960,8 @@ static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
/* Show interface address. */
if (use_json)
- json_object_string_add(json_sub, "ifaceAddress",
- inet_ntop(AF_INET, &nbr_nbma->addr,
- buf, sizeof(buf)));
+ json_object_string_addf(json_sub, "ifaceAddress", "%pI4",
+ &nbr_nbma->addr);
else
vty_out(vty, " interface address %pI4\n",
&nbr_nbma->addr);
@@ -5113,7 +5034,6 @@ static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
char timebuf[OSPF_TIME_DUMP_SIZE];
json_object *json_neigh = NULL, *json_neigh_array = NULL;
char neigh_str[INET_ADDRSTRLEN] = {0};
- char buf[PREFIX_STRLEN];
if (use_json) {
if (prev_nbr &&
@@ -5150,10 +5070,8 @@ static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
/* Show interface address. */
if (use_json)
- json_object_string_add(json_neigh, "ifaceAddress",
- inet_ntop(AF_INET,
- &nbr->address.u.prefix4,
- buf, sizeof(buf)));
+ json_object_string_addf(json_neigh, "ifaceAddress", "%pI4",
+ &nbr->address.u.prefix4);
else
vty_out(vty, " interface address %pI4\n",
&nbr->address.u.prefix4);
@@ -5230,17 +5148,15 @@ static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
/* Show Designated Rotuer ID. */
if (use_json)
- json_object_string_add(json_neigh, "routerDesignatedId",
- inet_ntop(AF_INET, &nbr->d_router,
- buf, sizeof(buf)));
+ json_object_string_addf(json_neigh, "routerDesignatedId",
+ "%pI4", &nbr->d_router);
else
vty_out(vty, " DR is %pI4,", &nbr->d_router);
/* Show Backup Designated Rotuer ID. */
if (use_json)
- json_object_string_add(json_neigh, "routerDesignatedBackupId",
- inet_ntop(AF_INET, &nbr->bd_router,
- buf, sizeof(buf)));
+ json_object_string_addf(json_neigh, "routerDesignatedBackupId",
+ "%pI4", &nbr->bd_router);
else
vty_out(vty, " BDR is %pI4\n", &nbr->bd_router);
@@ -5439,11 +5355,9 @@ static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
}
}
- if (use_json) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (use_json)
+ vty_json(vty, json);
+ else
vty_out(vty, "\n");
return CMD_SUCCESS;
@@ -5594,12 +5508,8 @@ DEFUN (show_ip_ospf_neighbor_detail,
ret = show_ip_ospf_neighbor_detail_common(
vty, ospf, json, uj, use_vrf);
}
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -5666,11 +5576,8 @@ DEFUN (show_ip_ospf_instance_neighbor_detail,
ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0);
- if (uj) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -5783,12 +5690,8 @@ DEFUN (show_ip_ospf_neighbor_detail_all,
vty, ospf, json, uj, use_vrf);
}
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -5856,11 +5759,8 @@ DEFUN (show_ip_ospf_instance_neighbor_detail_all,
ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0);
- if (uj) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -5916,11 +5816,9 @@ static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty,
}
}
- if (use_json) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (use_json)
+ vty_json(vty, json);
+ else
vty_out(vty, "\n");
return CMD_SUCCESS;
@@ -5995,7 +5893,6 @@ static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self,
struct summary_lsa *sl;
struct as_external_lsa *asel;
struct prefix_ipv4 p;
- char buf[PREFIX2STR_BUFFER];
if (lsa != NULL)
/* If self option is set, check LSA self flag. */
@@ -6018,15 +5915,11 @@ static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self,
ntohl(lsa->data->ls_seqnum));
snprintf(checksum, sizeof(checksum), "%x",
ntohs(lsa->data->checksum));
- json_object_string_add(
- json_lsa, "lsId",
- inet_ntop(AF_INET, &lsa->data->id,
- buf, sizeof(buf)));
- json_object_string_add(
- json_lsa, "advertisedRouter",
- inet_ntop(AF_INET,
- &lsa->data->adv_router,
- buf, sizeof(buf)));
+ json_object_string_addf(json_lsa, "lsId",
+ "%pI4", &lsa->data->id);
+ json_object_string_addf(
+ json_lsa, "advertisedRouter", "%pI4",
+ &lsa->data->adv_router);
json_object_int_add(json_lsa, "lsaAge",
LS_AGE(lsa));
json_object_string_add(
@@ -6058,10 +5951,9 @@ static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self,
if (!json_lsa)
vty_out(vty, " %pFX", &p);
else {
- prefix2str(&p, buf, sizeof(buf));
- json_object_string_add(json_lsa,
- "summaryAddress",
- buf);
+ json_object_string_addf(
+ json_lsa, "summaryAddress",
+ "%pFX", &p);
}
break;
case OSPF_AS_EXTERNAL_LSA:
@@ -6083,15 +5975,14 @@ static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self,
(unsigned long)ntohl(
asel->e[0].route_tag));
else {
- prefix2str(&p, buf, sizeof(buf));
json_object_string_add(
json_lsa, "metricType",
IS_EXTERNAL_METRIC(
asel->e[0].tos)
? "E2"
: "E1");
- json_object_string_add(json_lsa,
- "route", buf);
+ json_object_string_addf(
+ json_lsa, "route", "%pFX", &p);
json_object_int_add(
json_lsa, "tag",
(unsigned long)ntohl(
@@ -6162,7 +6053,6 @@ static const char *const show_database_header[] = {
static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa,
json_object *json)
{
- char buf[PREFIX_STRLEN];
struct router_lsa *rlsa = (struct router_lsa *)lsa->data;
if (!json) {
@@ -6243,13 +6133,10 @@ static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa,
json_object_string_add(
json, "lsaType",
lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
- json_object_string_add(json, "linkStateId",
- inet_ntop(AF_INET, &lsa->data->id,
- buf, sizeof(buf)));
- json_object_string_add(json, "advertisingRouter",
- inet_ntop(AF_INET,
- &lsa->data->adv_router,
- buf, sizeof(buf)));
+ json_object_string_addf(json, "linkStateId", "%pI4",
+ &lsa->data->id);
+ json_object_string_addf(json, "advertisingRouter", "%pI4",
+ &lsa->data->adv_router);
json_object_string_add(json, "lsaSeqNumber", seqnum);
json_object_string_add(json, "checksum", checksum);
json_object_int_add(json, "length", ntohs(lsa->data->length));
@@ -6478,7 +6365,6 @@ static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
json_object *json)
{
- char buf[PREFIX_STRLEN];
int tos = 0;
if (lsa != NULL) {
@@ -6513,10 +6399,8 @@ static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
json_object_int_add(json, "tos", tos);
json_object_int_add(json, "metric",
GET_METRIC(al->e[0].metric));
- json_object_string_add(json, "forwardAddress",
- inet_ntop(AF_INET,
- &(al->e[0].fwd_addr),
- buf, sizeof(buf)));
+ json_object_string_addf(json, "forwardAddress", "%pI4",
+ &(al->e[0].fwd_addr));
json_object_int_add(
json, "externalRouteTag",
(route_tag_t)ntohl(al->e[0].route_tag));
@@ -6530,7 +6414,6 @@ static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
json_object *json)
{
- char buf[PREFIX_STRLEN];
int tos = 0;
if (lsa != NULL) {
@@ -6566,10 +6449,8 @@ static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
json_object_int_add(json, "tos", tos);
json_object_int_add(json, "metric",
GET_METRIC(al->e[0].metric));
- json_object_string_add(json, "nssaForwardAddress",
- inet_ntop(AF_INET,
- &al->e[0].fwd_addr,
- buf, sizeof(buf)));
+ json_object_string_addf(json, "nssaForwardAddress",
+ "%pI4", &al->e[0].fwd_addr);
json_object_int_add(
json, "externalRouteTag",
(route_tag_t)ntohl(al->e[0].route_tag));
@@ -6961,15 +6842,11 @@ static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf,
json_lsa = json_object_new_object();
json_object_int_add(json_lsa, "linkType",
lsa->data->type);
- json_object_string_add(
- json_lsa, "linkStateId",
- inet_ntop(AF_INET, &lsa->data->id,
- buf, sizeof(buf)));
- json_object_string_add(
- json_lsa, "advertisingRouter",
- inet_ntop(AF_INET,
- &lsa->data->adv_router,
- buf, sizeof(buf)));
+ json_object_string_addf(json_lsa, "linkStateId",
+ "%pI4", &lsa->data->id);
+ json_object_string_addf(
+ json_lsa, "advertisingRouter", "%pI4",
+ &lsa->data->adv_router);
json_object_int_add(json_lsa, "lsaLockCount",
lsa->lock);
json_object_object_add(
@@ -7011,7 +6888,6 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
int idx_type = 4;
int type, ret;
struct in_addr id, adv_router;
- char buf[PREFIX_STRLEN];
json_object *json_vrf = NULL;
if (uj) {
@@ -7033,9 +6909,8 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
/* Show Router ID. */
if (uj) {
- json_object_string_add(json_vrf, "routerId",
- inet_ntop(AF_INET, &ospf->router_id,
- buf, sizeof(buf)));
+ json_object_string_addf(json_vrf, "routerId", "%pI4",
+ &ospf->router_id);
} else {
vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
&ospf->router_id);
@@ -7249,12 +7124,8 @@ DEFUN (show_ip_ospf_instance_database_max,
show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0, json, uj);
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return CMD_SUCCESS;
}
@@ -7285,7 +7156,6 @@ static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
int idx_type = 4;
int type, ret;
struct in_addr adv_router;
- char buf[PREFIX_STRLEN];
json_object *json_vrf = NULL;
if (uj) {
@@ -7307,9 +7177,8 @@ static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
/* Show Router ID. */
if (uj) {
- json_object_string_add(json_vrf, "routerId",
- inet_ntop(AF_INET, &ospf->router_id,
- buf, sizeof(buf)));
+ json_object_string_addf(json_vrf, "routerId", "%pI4",
+ &ospf->router_id);
} else {
vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
&ospf->router_id);
@@ -7468,12 +7337,8 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router,
show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv,
0, json, uj);
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return CMD_SUCCESS;
}
@@ -8125,7 +7990,7 @@ static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str,
if (nbr_str) {
struct ospf *ospf = NULL;
- ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ ospf = ifp->vrf->info;
if (ospf) {
oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
if (oi)
@@ -8243,7 +8108,7 @@ DEFUN (no_ip_ospf_dead_interval,
if (argc == 1) {
struct ospf *ospf = NULL;
- ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ ospf = ifp->vrf->info;
if (ospf) {
oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
if (oi)
@@ -8895,7 +8760,7 @@ DEFUN (ip_ospf_area,
areaid = argv[idx + 1]->arg;
if (!instance)
- ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ ospf = ifp->vrf->info;
else
ospf = ospf_lookup_instance(instance);
@@ -8926,7 +8791,7 @@ DEFUN (ip_ospf_area,
}
if (count > 0) {
- ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ ospf = ifp->vrf->info;
if (ospf)
ospf_interface_area_unset(ospf, ifp);
}
@@ -9019,7 +8884,7 @@ DEFUN (no_ip_ospf_area,
instance = strtol(argv[idx]->arg, NULL, 10);
if (!instance)
- ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ ospf = ifp->vrf->info;
else
ospf = ospf_lookup_instance(instance);
@@ -10082,7 +9947,6 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
struct ospf_route * or ;
struct listnode *pnode, *pnnode;
struct ospf_path *path;
- char buf[PREFIX_STRLEN];
json_object *json_route = NULL, *json_nexthop_array = NULL,
*json_nexthop = NULL;
@@ -10112,11 +9976,9 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
"N IA");
json_object_int_add(json_route, "cost",
or->cost);
- json_object_string_add(
- json_route, "area",
- inet_ntop(AF_INET,
- &or->u.std.area_id,
- buf1, sizeof(buf1)));
+ json_object_string_addf(
+ json_route, "area", "%pI4",
+ &or->u.std.area_id);
} else {
vty_out(vty,
"N IA %-18s [%d] area: %pI4\n",
@@ -10141,10 +10003,9 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
"N");
json_object_int_add(json_route, "cost",
or->cost);
- json_object_string_add(
- json_route, "area",
- inet_ntop(AF_INET, &or->u.std.area_id,
- buf1, sizeof(buf1)));
+ json_object_string_addf(json_route, "area",
+ "%pI4",
+ &or->u.std.area_id);
} else {
vty_out(vty, "N %-18s [%d] area: %pI4\n",
buf1, or->cost,
@@ -10195,14 +10056,10 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
}
} else {
if (json) {
- json_object_string_add(
+ json_object_string_addf(
json_nexthop,
- "ip",
- inet_ntop(
- AF_INET,
- &path->nexthop,
- buf,
- sizeof(buf)));
+ "ip", "%pI4",
+ &path->nexthop);
json_object_string_add(
json_nexthop,
"via",
@@ -10271,10 +10128,9 @@ static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
if (json) {
json_object_int_add(json_route, "cost",
or->cost);
- json_object_string_add(
- json_route, "area",
- inet_ntop(AF_INET, &or->u.std.area_id,
- buf, sizeof(buf)));
+ json_object_string_addf(json_route, "area",
+ "%pI4",
+ &or->u.std.area_id);
if (or->path_type == OSPF_PATH_INTER_AREA)
json_object_boolean_true_add(json_route,
"IA");
@@ -10339,13 +10195,10 @@ static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
}
} else {
if (json) {
- json_object_string_add(
+ json_object_string_addf(
json_nexthop,
- "ip",
- inet_ntop(
- AF_INET,
- &path->nexthop,
- buf, sizeof(buf)));
+ "ip", "%pI4",
+ &path->nexthop);
json_object_string_add(
json_nexthop,
"via",
@@ -10378,7 +10231,6 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
struct ospf_route *er;
struct listnode *pnode, *pnnode;
struct ospf_path *path;
- char buf[PREFIX_STRLEN];
json_object *json_route = NULL, *json_nexthop_array = NULL,
*json_nexthop = NULL;
@@ -10469,13 +10321,9 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
}
} else {
if (json) {
- json_object_string_add(
+ json_object_string_addf(
json_nexthop, "ip",
- inet_ntop(
- AF_INET,
- &path->nexthop,
- buf,
- sizeof(buf)));
+ "%pI4", &path->nexthop);
json_object_string_add(
json_nexthop, "via",
ifindex2ifname(
@@ -10700,11 +10548,7 @@ DEFUN (show_ip_ospf_route,
if (uj) {
/* Keep Non-pretty format */
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json,
- JSON_C_TO_STRING_NOSLASHESCAPE));
- json_object_free(json);
+ vty_json(vty, json);
} else if (!ospf_output)
vty_out(vty, "%% OSPF instance not found\n");
@@ -10712,14 +10556,9 @@ DEFUN (show_ip_ospf_route,
}
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if (ospf == NULL || !ospf->oi_running) {
- 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);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -10728,14 +10567,9 @@ DEFUN (show_ip_ospf_route,
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
- 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);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -10797,7 +10631,6 @@ DEFUN (show_ip_ospf_vrfs,
struct ospf *ospf = NULL;
struct listnode *node = NULL;
int count = 0;
- char buf[PREFIX_STRLEN];
static const char header[] = "Name Id RouterId ";
if (uj) {
@@ -10825,10 +10658,8 @@ DEFUN (show_ip_ospf_vrfs,
if (uj) {
json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
- json_object_string_add(
- json_vrf, "routerId",
- inet_ntop(AF_INET, &ospf->router_id,
- buf, sizeof(buf)));
+ json_object_string_addf(json_vrf, "routerId", "%pI4",
+ &ospf->router_id);
json_object_object_add(json_vrfs, name, json_vrf);
@@ -10842,9 +10673,7 @@ DEFUN (show_ip_ospf_vrfs,
json_object_object_add(json, "vrfs", json_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, "\nTotal number of OSPF VRFs: %d\n",
@@ -11131,12 +10960,8 @@ DEFUN (show_ip_ospf_external_aggregator,
vty, ospf, use_vrf, json, uj, detail);
}
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -11144,12 +10969,9 @@ DEFUN (show_ip_ospf_external_aggregator,
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -11160,12 +10982,9 @@ DEFUN (show_ip_ospf_external_aggregator,
/* Default Vrf */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -11174,11 +10993,8 @@ DEFUN (show_ip_ospf_external_aggregator,
ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
}
- if (uj) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return CMD_SUCCESS;
}
@@ -11232,7 +11048,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
continue;
vty_frame(vty, "!\n");
- if (ifp->vrf_id == VRF_DEFAULT)
+ if (ifp->vrf->vrf_id == VRF_DEFAULT)
vty_frame(vty, "interface %s\n", ifp->name);
else
vty_frame(vty, "interface %s vrf %s\n", ifp->name,