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.c774
1 files changed, 272 insertions, 502 deletions
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 4109ada64a..8cab6b9897 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -178,19 +178,11 @@ static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty,
{
if (use_vrf) {
if (json) {
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_string_add(json, "vrfName",
- "default");
- else
- json_object_string_add(json, "vrfName",
- ospf->name);
+ json_object_string_add(json, "vrfName",
+ ospf_get_name(ospf));
json_object_int_add(json, "vrfId", ospf->vrf_id);
- } else {
- if (ospf->vrf_id == VRF_DEFAULT)
- vty_out(vty, "VRF Name: %s\n", "default");
- else if (ospf->name)
- vty_out(vty, "VRF Name: %s\n", ospf->name);
- }
+ } else
+ vty_out(vty, "VRF Name: %s\n", ospf_get_name(ospf));
}
}
@@ -230,8 +222,8 @@ DEFUN_NOSH (router_ospf,
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
- ospf->instance, ospf->name ? ospf->name : "NIL",
- ospf->vrf_id, ospf->oi_running);
+ ospf->instance, ospf_get_name(ospf), ospf->vrf_id,
+ ospf->oi_running);
VTY_PUSH_CONTEXT(OSPF_NODE, ospf);
@@ -453,7 +445,7 @@ DEFUN_HIDDEN (ospf_passive_interface_addr,
"Please, use \"ip ospf passive\" on an interface instead.\n");
if (ospf->vrf_id != VRF_UNKNOWN)
- ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id);
+ ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id, ospf->name);
if (ifp == NULL) {
vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg);
@@ -514,7 +506,7 @@ DEFUN_HIDDEN (no_ospf_passive_interface,
"Please, use \"no ip ospf passive\" on an interface instead.\n");
if (ospf->vrf_id != VRF_UNKNOWN)
- ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id);
+ ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id, ospf->name);
if (ifp == NULL) {
vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg);
@@ -571,8 +563,7 @@ DEFUN (ospf_network_area,
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
"%s ospf vrf %s num of %u ip ospf area x config",
- __func__, ospf->name ? ospf->name : "NIL",
- count);
+ __func__, ospf_get_name(ospf), count);
return CMD_WARNING_CONFIG_FAILED;
}
@@ -1784,7 +1775,7 @@ DEFUN (no_ospf_area_default_cost,
DEFUN (ospf_area_export_list,
ospf_area_export_list_cmd,
- "area <A.B.C.D|(0-4294967295)> export-list NAME",
+ "area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
"OSPF area ID as a decimal value\n"
@@ -1808,7 +1799,7 @@ DEFUN (ospf_area_export_list,
DEFUN (no_ospf_area_export_list,
no_ospf_area_export_list_cmd,
- "no area <A.B.C.D|(0-4294967295)> export-list NAME",
+ "no area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
NO_STR
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
@@ -1836,7 +1827,7 @@ DEFUN (no_ospf_area_export_list,
DEFUN (ospf_area_import_list,
ospf_area_import_list_cmd,
- "area <A.B.C.D|(0-4294967295)> import-list NAME",
+ "area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
"OSPF area ID as a decimal value\n"
@@ -1860,7 +1851,7 @@ DEFUN (ospf_area_import_list,
DEFUN (no_ospf_area_import_list,
no_ospf_area_import_list_cmd,
- "no area <A.B.C.D|(0-4294967295)> import-list NAME",
+ "no area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
NO_STR
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
@@ -1887,7 +1878,7 @@ DEFUN (no_ospf_area_import_list,
DEFUN (ospf_area_filter_list,
ospf_area_filter_list_cmd,
- "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
+ "area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
"OSPF area ID as a decimal value\n"
@@ -1932,7 +1923,7 @@ DEFUN (ospf_area_filter_list,
DEFUN (no_ospf_area_filter_list,
no_ospf_area_filter_list_cmd,
- "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
+ "no area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
NO_STR
"OSPF area parameters\n"
"OSPF area ID in IP address format\n"
@@ -3052,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;
@@ -3077,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);
@@ -3343,12 +3332,8 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf,
if (json) {
if (use_vrf) {
json_object_object_add(json_vrf, "areas", json_areas);
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
+ json_object_object_add(json, ospf_get_name(ospf),
+ json_vrf);
} else {
json_object_object_add(json, "areas", json_areas);
}
@@ -3401,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;
@@ -3426,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;
@@ -3481,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;
}
@@ -3546,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? */
@@ -3616,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);
@@ -3650,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);
@@ -3672,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]);
@@ -3719,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",
@@ -3748,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,",
@@ -3970,12 +3925,8 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
if (use_json) {
if (use_vrf) {
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
+ json_object_object_add(json, ospf_get_name(ospf),
+ json_vrf);
}
} else
vty_out(vty, "\n");
@@ -4115,14 +4066,9 @@ static int show_ip_ospf_interface_traffic_common(
}
if (use_json) {
- if (use_vrf) {
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
- }
+ if (use_vrf)
+ json_object_object_add(json, ospf_get_name(ospf),
+ json_vrf);
} else
vty_out(vty, "\n");
@@ -4172,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;
@@ -4201,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;
@@ -4215,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;
}
@@ -4260,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;
}
@@ -4315,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;
}
@@ -4345,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;
}
@@ -4357,9 +4281,9 @@ DEFUN (show_ip_ospf_interface_traffic,
static void show_ip_ospf_neighbour_header(struct vty *vty)
{
- vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-32s %5s %5s %5s\n",
- "Neighbor ID", "Pri", "State", "Dead Time", "Address",
- "Interface", "RXmtL", "RqstL", "DBsmL");
+ vty_out(vty, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n",
+ "Neighbor ID", "Pri", "State", "Up Time", "Dead Time",
+ "Address", "Interface", "RXmtL", "RqstL", "DBsmL");
}
static void show_ip_ospf_neighbor_sub(struct vty *vty,
@@ -4369,9 +4293,11 @@ 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};
+ long time_val = 0;
+ char uptime[OSPF_TIME_DUMP_SIZE];
for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
if ((nbr = rn->info)) {
@@ -4381,6 +4307,13 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty,
/* Down state is not shown. */
if (nbr->state == NSM_Down)
continue;
+
+ if (nbr->ts_last_progress.tv_sec
+ || nbr->ts_last_progress.tv_usec)
+ time_val = monotime_since(
+ &nbr->ts_last_progress, &res)
+ / 1000LL;
+
if (use_json) {
char neigh_str[INET_ADDRSTRLEN];
@@ -4412,13 +4345,23 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty,
json_neighbor = json_object_new_object();
- ospf_nbr_state_message(nbr, msgbuf, 16);
+ ospf_nbr_ism_state_message(nbr, msgbuf, 16);
json_object_int_add(json_neighbor, "priority",
nbr->priority);
json_object_string_add(json_neighbor, "state",
msgbuf);
+ json_object_string_add(
+ json_neighbor, "converged",
+ lookup_msg(ospf_nsm_state_msg,
+ nbr->state, NULL));
+ json_object_string_add(
+ json_neighbor, "role",
+ lookup_msg(ospf_ism_state_msg,
+ ospf_nbr_ism_state(nbr),
+ NULL));
+
if (nbr->t_inactivity) {
long time_store;
@@ -4428,17 +4371,30 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty,
NULL)
/ 1000LL;
json_object_int_add(json_neighbor,
+ "upTimeInMsec",
+ time_val);
+ json_object_int_add(json_neighbor,
"deadTimeMsecs",
time_store);
+ json_object_string_add(
+ json_neighbor, "upTime",
+ ospf_timeval_dump(
+ &res, uptime,
+ sizeof(uptime)));
+ json_object_string_add(
+ json_neighbor, "deadTime",
+ ospf_timer_dump(
+ nbr->t_inactivity,
+ timebuf,
+ sizeof(timebuf)));
} else {
json_object_string_add(json_neighbor,
"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));
@@ -4455,7 +4411,7 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty,
json_object_array_add(json_neigh_array,
json_neighbor);
} else {
- ospf_nbr_state_message(nbr, msgbuf, 16);
+ ospf_nbr_ism_state_message(nbr, msgbuf, 16);
if (nbr->state == NSM_Attempt
&& nbr->router_id.s_addr == INADDR_ANY)
@@ -4463,8 +4419,12 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty,
nbr->priority, msgbuf);
else
vty_out(vty, "%-15pI4 %3d %-15s ",
- &nbr->router_id,
- nbr->priority, msgbuf);
+ &nbr->router_id, nbr->priority,
+ msgbuf);
+
+ vty_out(vty, "%-15s ",
+ ospf_timeval_dump(&res, uptime,
+ sizeof(uptime)));
vty_out(vty, "%9s ",
ospf_timer_dump(nbr->t_inactivity,
@@ -4519,14 +4479,9 @@ static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
if (use_json) {
json_object_object_add(json_vrf, "neighbors", json_nbr_sub);
- if (use_vrf) {
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
- }
+ if (use_vrf)
+ json_object_object_add(json, ospf_get_name(ospf),
+ json_vrf);
} else
vty_out(vty, "\n");
@@ -4571,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;
@@ -4584,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;
@@ -4598,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;
@@ -4658,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;
}
@@ -4748,14 +4691,9 @@ static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf,
}
if (use_json) {
- if (use_vrf) {
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
- }
+ if (use_vrf)
+ json_object_object_add(json, ospf_get_name(ospf),
+ json_vrf);
} else
vty_out(vty, "\n");
@@ -4801,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;
}
@@ -4873,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;
}
@@ -4922,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;
@@ -5022,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)
@@ -5032,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);
@@ -5107,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 &&
@@ -5144,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);
@@ -5224,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);
@@ -5433,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;
@@ -5541,14 +5461,9 @@ static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
if (use_json) {
json_object_object_add(json_vrf, "neighbors",
json_nbr_sub);
- if (use_vrf) {
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
- }
+ if (use_vrf)
+ json_object_object_add(json, ospf_get_name(ospf),
+ json_vrf);
} else
vty_out(vty, "\n");
@@ -5593,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;
}
@@ -5665,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;
}
@@ -5732,14 +5640,9 @@ static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty,
}
if (use_json) {
- if (use_vrf) {
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
- }
+ if (use_vrf)
+ json_object_object_add(json, ospf_get_name(ospf),
+ json_vrf);
} else {
vty_out(vty, "\n");
}
@@ -5787,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;
}
@@ -5860,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;
}
@@ -5920,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;
@@ -5999,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. */
@@ -6022,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(
@@ -6062,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:
@@ -6087,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(
@@ -6166,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) {
@@ -6247,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));
@@ -6482,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) {
@@ -6517,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));
@@ -6534,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) {
@@ -6570,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));
@@ -6965,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(
@@ -7015,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) {
@@ -7037,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);
@@ -7049,14 +6920,9 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
if ((argc == arg_base + 4) || (uj && (argc == arg_base + 5))) {
show_ip_ospf_database_summary(vty, ospf, 0, json_vrf);
if (json) {
- if (use_vrf) {
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
- }
+ if (use_vrf)
+ json_object_object_add(
+ json, ospf_get_name(ospf), json_vrf);
}
return CMD_SUCCESS;
}
@@ -7077,27 +6943,17 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) {
show_ip_ospf_database_summary(vty, ospf, 1, json_vrf);
if (json) {
- if (use_vrf) {
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
- }
+ if (use_vrf)
+ json_object_object_add(
+ json, ospf_get_name(ospf), json_vrf);
}
return CMD_SUCCESS;
} else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) {
show_ip_ospf_database_maxage(vty, ospf, json_vrf);
if (json) {
- if (use_vrf) {
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
- }
+ if (use_vrf)
+ json_object_object_add(
+ json, ospf_get_name(ospf), json_vrf);
}
return CMD_SUCCESS;
} else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
@@ -7137,14 +6993,9 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
}
if (json) {
- if (use_vrf) {
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
- }
+ if (use_vrf)
+ json_object_object_add(json, ospf_get_name(ospf),
+ json_vrf);
}
return CMD_SUCCESS;
@@ -7273,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;
}
@@ -7309,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) {
@@ -7331,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);
@@ -7373,14 +7218,9 @@ static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
show_lsa_detail_adv_router(vty, ospf, type, &adv_router, json_vrf);
if (json) {
- if (use_vrf) {
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
- }
+ if (use_vrf)
+ json_object_object_add(json, ospf_get_name(ospf),
+ json_vrf);
}
return CMD_SUCCESS;
@@ -7497,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;
}
@@ -8154,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)
@@ -8272,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)
@@ -8924,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);
@@ -8955,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);
}
@@ -9048,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);
@@ -9376,7 +9212,7 @@ DEFUN (no_ospf_redistribute_instance_source,
DEFUN (ospf_distribute_list_out,
ospf_distribute_list_out_cmd,
- "distribute-list WORD out " FRR_REDIST_STR_OSPFD,
+ "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD,
"Filter networks in routing updates\n"
"Access-list name\n"
OUT_STR
@@ -9398,7 +9234,7 @@ DEFUN (ospf_distribute_list_out,
DEFUN (no_ospf_distribute_list_out,
no_ospf_distribute_list_out_cmd,
- "no distribute-list WORD out " FRR_REDIST_STR_OSPFD,
+ "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD,
NO_STR
"Filter networks in routing updates\n"
"Access-list name\n"
@@ -10187,14 +10023,9 @@ static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf,
ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
if (uj) {
- if (use_vrf) {
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
- }
+ if (use_vrf)
+ json_object_object_add(json, ospf_get_name(ospf),
+ json_vrf);
} else
vty_out(vty, "\n");
@@ -10619,7 +10450,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;
@@ -10649,11 +10479,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",
@@ -10678,10 +10506,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,
@@ -10732,14 +10559,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",
@@ -10808,10 +10631,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");
@@ -10876,13 +10698,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",
@@ -10915,7 +10734,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;
@@ -11006,13 +10824,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(
@@ -11183,12 +10997,8 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
if (use_vrf) {
// json_object_object_add(json_vrf, "areas",
// json_areas);
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
+ json_object_object_add(json, ospf_get_name(ospf),
+ json_vrf);
}
} else {
vty_out(vty, "\n");
@@ -11241,11 +11051,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");
@@ -11253,14 +11059,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;
@@ -11269,14 +11070,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;
@@ -11338,7 +11134,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) {
@@ -11358,10 +11153,7 @@ DEFUN (show_ip_ospf_vrfs,
if (uj)
json_vrf = json_object_new_object();
- if (ospf->vrf_id == VRF_DEFAULT)
- name = VRF_DEFAULT_NAME;
- else
- name = ospf->name;
+ name = ospf_get_name(ospf);
vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN)
? -1
@@ -11369,10 +11161,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);
@@ -11386,9 +11176,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",
@@ -11623,14 +11411,9 @@ static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf,
}
if (uj) {
- if (use_vrf) {
- if (ospf->vrf_id == VRF_DEFAULT)
- json_object_object_add(json, "default",
- json_vrf);
- else
- json_object_object_add(json, ospf->name,
- json_vrf);
- }
+ if (use_vrf)
+ json_object_object_add(json, ospf_get_name(ospf),
+ json_vrf);
} else
vty_out(vty, "\n");
@@ -11680,12 +11463,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;
}
@@ -11693,12 +11472,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;
@@ -11709,12 +11485,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;
@@ -11723,11 +11496,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;
}
@@ -11781,7 +11551,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,