mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-04-29 11:47:08 +00:00
ospfd: Replace inet_ntop to %pI4/6 for JSON outputs
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
This commit is contained in:
parent
e46a4ac958
commit
20308be317
@ -2674,10 +2674,8 @@ static void show_sr_prefix(struct sbuf *sbuf, struct json_object *json,
|
||||
srp->nhlfe.label_out);
|
||||
json_object_string_add(json_obj, "interface",
|
||||
itf ? itf->name : "-");
|
||||
json_object_string_add(
|
||||
json_obj, "nexthop",
|
||||
inet_ntop(AF_INET, &srp->nhlfe.nexthop,
|
||||
buf, sizeof(buf)));
|
||||
json_object_string_addf(json_obj, "nexthop", "%pI4",
|
||||
&srp->nhlfe.nexthop);
|
||||
json_object_array_add(json_route, json_obj);
|
||||
} else {
|
||||
sbuf_push(sbuf, 0, "%20s %9s %15s\n",
|
||||
@ -2712,10 +2710,8 @@ static void show_sr_prefix(struct sbuf *sbuf, struct json_object *json,
|
||||
path->srni.label_out);
|
||||
json_object_string_add(json_obj, "interface",
|
||||
itf ? itf->name : "-");
|
||||
json_object_string_add(
|
||||
json_obj, "nexthop",
|
||||
inet_ntop(AF_INET, &path->nexthop,
|
||||
buf, sizeof(buf)));
|
||||
json_object_string_addf(json_obj, "nexthop", "%pI4",
|
||||
&path->nexthop);
|
||||
json_object_array_add(json_route, json_obj);
|
||||
} else {
|
||||
sbuf_push(sbuf, indent, "%20s %9s %15s\n",
|
||||
@ -2755,9 +2751,8 @@ static void show_sr_node(struct vty *vty, struct json_object *json,
|
||||
|
||||
if (json) {
|
||||
json_node = json_object_new_object();
|
||||
json_object_string_add(json_node, "routerID",
|
||||
inet_ntop(AF_INET, &srn->adv_router,
|
||||
buf, sizeof(buf)));
|
||||
json_object_string_addf(json_node, "routerID", "%pI4",
|
||||
&srn->adv_router);
|
||||
json_object_int_add(json_node, "srgbSize",
|
||||
srn->srgb.range_size);
|
||||
json_object_int_add(json_node, "srgbLabel",
|
||||
@ -2846,10 +2841,8 @@ static void show_sr_node(struct vty *vty, struct json_object *json,
|
||||
srl->nhlfe[0].label_out);
|
||||
json_object_string_add(json_obj, "interface",
|
||||
itf ? itf->name : "-");
|
||||
json_object_string_add(
|
||||
json_obj, "nexthop",
|
||||
inet_ntop(AF_INET, &srl->nhlfe[0].nexthop,
|
||||
buf, sizeof(buf)));
|
||||
json_object_string_addf(json_obj, "nexthop", "%pI4",
|
||||
&srl->nhlfe[0].nexthop);
|
||||
json_object_array_add(json_link, json_obj);
|
||||
/* Backup Link */
|
||||
json_obj = json_object_new_object();
|
||||
@ -2862,10 +2855,8 @@ static void show_sr_node(struct vty *vty, struct json_object *json,
|
||||
srl->nhlfe[1].label_out);
|
||||
json_object_string_add(json_obj, "interface",
|
||||
itf ? itf->name : "-");
|
||||
json_object_string_add(
|
||||
json_obj, "nexthop",
|
||||
inet_ntop(AF_INET, &srl->nhlfe[1].nexthop,
|
||||
buf, sizeof(buf)));
|
||||
json_object_string_addf(json_obj, "nexthop", "%pI4",
|
||||
&srl->nhlfe[1].nexthop);
|
||||
json_object_array_add(json_link, json_obj);
|
||||
} else {
|
||||
sbuf_push(&sbuf, 0, "%18s %21s %20s %9s %15s\n",
|
||||
@ -2937,10 +2928,8 @@ DEFUN (show_ip_opsf_srdb,
|
||||
if (uj) {
|
||||
json = json_object_new_object();
|
||||
json_node_array = json_object_new_array();
|
||||
json_object_string_add(
|
||||
json, "srdbID",
|
||||
inet_ntop(AF_INET, &OspfSR.self->adv_router,
|
||||
buf, sizeof(buf)));
|
||||
json_object_string_addf(json, "srdbID", "%pI4",
|
||||
&OspfSR.self->adv_router);
|
||||
json_object_object_add(json, "srNodes", json_node_array);
|
||||
} else {
|
||||
vty_out(vty,
|
||||
|
206
ospfd/ospf_vty.c
206
ospfd/ospf_vty.c
@ -3068,9 +3068,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);
|
||||
@ -3603,11 +3602,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 +3634,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 +3652,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 +3697,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 +3722,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,",
|
||||
@ -4447,10 +4429,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));
|
||||
@ -5038,9 +5019,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);
|
||||
@ -5150,10 +5130,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 +5208,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);
|
||||
|
||||
@ -6018,15 +5994,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(
|
||||
@ -6243,13 +6215,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));
|
||||
@ -6513,10 +6482,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));
|
||||
@ -6566,10 +6533,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 +6926,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(
|
||||
@ -7033,9 +6994,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);
|
||||
@ -7307,9 +7267,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);
|
||||
@ -10112,11 +10071,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 +10098,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 +10151,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 +10223,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 +10290,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",
|
||||
@ -10469,13 +10417,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(
|
||||
@ -10825,10 +10769,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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user