zebra: Replace inet_ntop to %pI4/6 for JSON outputs

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
This commit is contained in:
Donatas Abraitis 2021-11-18 10:58:23 +02:00
parent b0d5264e3f
commit 08edf9c6af
8 changed files with 40 additions and 74 deletions

View File

@ -2062,18 +2062,14 @@ static void if_dump_vty_json(struct vty *vty, struct interface *ifp,
vxlan_info = &zebra_if->l2info.vxl; vxlan_info = &zebra_if->l2info.vxl;
json_object_int_add(json_if, "vxlanId", vxlan_info->vni); json_object_int_add(json_if, "vxlanId", vxlan_info->vni);
if (vxlan_info->vtep_ip.s_addr != INADDR_ANY) if (vxlan_info->vtep_ip.s_addr != INADDR_ANY)
json_object_string_add(json_if, "vtepIp", json_object_string_addf(json_if, "vtepIp", "%pI4",
inet_ntop(AF_INET, &vxlan_info->vtep_ip);
&vxlan_info->vtep_ip,
buf, sizeof(buf)));
if (vxlan_info->access_vlan) if (vxlan_info->access_vlan)
json_object_int_add(json_if, "accessVlanId", json_object_int_add(json_if, "accessVlanId",
vxlan_info->access_vlan); vxlan_info->access_vlan);
if (vxlan_info->mcast_grp.s_addr != INADDR_ANY) if (vxlan_info->mcast_grp.s_addr != INADDR_ANY)
json_object_string_add(json_if, "mcastGroup", json_object_string_addf(json_if, "mcastGroup", "%pI4",
inet_ntop(AF_INET, &vxlan_info->mcast_grp);
&vxlan_info->mcast_grp,
buf, sizeof(buf)));
if (vxlan_info->ifindex_link if (vxlan_info->ifindex_link
&& (vxlan_info->link_nsid != NS_UNKNOWN)) { && (vxlan_info->link_nsid != NS_UNKNOWN)) {
struct interface *ifp; struct interface *ifp;
@ -2090,16 +2086,12 @@ static void if_dump_vty_json(struct vty *vty, struct interface *ifp,
gre_info = &zebra_if->l2info.gre; gre_info = &zebra_if->l2info.gre;
if (gre_info->vtep_ip.s_addr != INADDR_ANY) { if (gre_info->vtep_ip.s_addr != INADDR_ANY) {
json_object_string_add(json_if, "vtepIp", json_object_string_addf(json_if, "vtepIp", "%pI4",
inet_ntop(AF_INET, &gre_info->vtep_ip);
&gre_info->vtep_ip,
buf, sizeof(buf)));
if (gre_info->vtep_ip_remote.s_addr != INADDR_ANY) if (gre_info->vtep_ip_remote.s_addr != INADDR_ANY)
json_object_string_add( json_object_string_addf(
json_if, "vtepRemoteIp", json_if, "vtepRemoteIp", "%pI4",
inet_ntop(AF_INET, &gre_info->vtep_ip_remote);
&gre_info->vtep_ip_remote,
buf, sizeof(buf)));
} }
if (gre_info->ifindex_link if (gre_info->ifindex_link
&& (gre_info->link_nsid != NS_UNKNOWN)) { && (gre_info->link_nsid != NS_UNKNOWN)) {
@ -2233,9 +2225,8 @@ static void if_dump_vty_json(struct vty *vty, struct interface *ifp,
json_object_double_add(json_te, "utilizedBandwidth", json_object_double_add(json_te, "utilizedBandwidth",
iflp->use_bw); iflp->use_bw);
if (IS_PARAM_SET(iflp, LP_RMT_AS)) if (IS_PARAM_SET(iflp, LP_RMT_AS))
json_object_string_add(json_te, "neighborAsbrIp", json_object_string_addf(json_te, "neighborAsbrIp",
inet_ntop(AF_INET, &iflp->rmt_ip, "%pI4", &iflp->rmt_ip);
buf, sizeof(buf)));
json_object_int_add(json_te, "neighborAsbrAs", iflp->rmt_as); json_object_int_add(json_te, "neighborAsbrAs", iflp->rmt_as);
} }

View File

@ -152,12 +152,10 @@ void zebra_evpn_print(struct zebra_evpn *zevpn, void **ctxt)
json_object_int_add(json, "sviIfindex", json_object_int_add(json, "sviIfindex",
zevpn->svi_if->ifindex); zevpn->svi_if->ifindex);
} }
json_object_string_add(json, "vtepIp", json_object_string_addf(json, "vtepIp", "%pI4",
inet_ntop(AF_INET, &zevpn->local_vtep_ip, &zevpn->local_vtep_ip);
buf, sizeof(buf))); json_object_string_addf(json, "mcastGroup", "%pI4",
json_object_string_add(json, "mcastGroup", &zevpn->mcast_grp);
inet_ntop(AF_INET, &zevpn->mcast_grp,
buf, sizeof(buf)));
json_object_string_add(json, "advertiseGatewayMacip", json_object_string_add(json, "advertiseGatewayMacip",
zevpn->advertise_gw_macip ? "Yes" : "No"); zevpn->advertise_gw_macip ? "Yes" : "No");
json_object_string_add(json, "advertiseSviMacip", json_object_string_add(json, "advertiseSviMacip",

View File

@ -658,10 +658,8 @@ void zebra_evpn_print_mac(struct zebra_mac *mac, void *ctxt, json_object *json)
json_object_int_add(json_mac, "vlan", vid); json_object_int_add(json_mac, "vlan", vid);
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) { } else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) {
json_object_string_add(json_mac, "type", "remote"); json_object_string_add(json_mac, "type", "remote");
json_object_string_add( json_object_string_addf(json_mac, "remoteVtep", "%pI4",
json_mac, "remoteVtep", &mac->fwd_info.r_vtep_ip);
inet_ntop(AF_INET, &mac->fwd_info.r_vtep_ip,
addr_buf, sizeof(addr_buf)));
} else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO)) } else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO))
json_object_string_add(json_mac, "type", "auto"); json_object_string_add(json_mac, "type", "auto");
@ -944,10 +942,8 @@ void zebra_evpn_print_mac_hash(struct hash_bucket *bucket, void *ctxt)
"", mac->loc_seq, mac->rem_seq); "", mac->loc_seq, mac->rem_seq);
} else { } else {
json_object_string_add(json_mac, "type", "remote"); json_object_string_add(json_mac, "type", "remote");
json_object_string_add( json_object_string_addf(json_mac, "remoteVtep", "%pI4",
json_mac, "remoteVtep", &mac->fwd_info.r_vtep_ip);
inet_ntop(AF_INET, &mac->fwd_info.r_vtep_ip,
addr_buf, sizeof(addr_buf)));
json_object_object_add(json_mac_hdr, buf1, json_mac); json_object_object_add(json_mac_hdr, buf1, json_mac);
json_object_int_add(json_mac, "localSequence", json_object_int_add(json_mac, "localSequence",
mac->loc_seq); mac->loc_seq);

View File

@ -1328,9 +1328,7 @@ static void zebra_evpn_es_l2_nh_show_entry(struct zebra_evpn_l2_nh *nh,
char ip_buf[INET6_ADDRSTRLEN]; char ip_buf[INET6_ADDRSTRLEN];
json = json_object_new_object(); json = json_object_new_object();
json_object_string_add(json, "vtep", json_object_string_addf(json, "vtep", "%pI4", &nh->vtep_ip);
inet_ntop(AF_INET, &nh->vtep_ip, ip_buf,
sizeof(ip_buf)));
json_object_int_add(json, "nhId", nh->nh_id); json_object_int_add(json, "nhId", nh->nh_id);
json_object_int_add(json, "refCnt", nh->ref_cnt); json_object_int_add(json, "refCnt", nh->ref_cnt);
@ -3012,9 +3010,8 @@ static void zebra_evpn_es_json_vtep_fill(struct zebra_evpn_es *es,
for (ALL_LIST_ELEMENTS_RO(es->es_vtep_list, node, es_vtep)) { for (ALL_LIST_ELEMENTS_RO(es->es_vtep_list, node, es_vtep)) {
json_vtep_entry = json_object_new_object(); json_vtep_entry = json_object_new_object();
json_object_string_add(json_vtep_entry, "vtep", json_object_string_addf(json_vtep_entry, "vtep", "%pI4",
inet_ntop(AF_INET, &es_vtep->vtep_ip, &es_vtep->vtep_ip);
ip_buf, sizeof(ip_buf)));
if (es_vtep->flags & ZEBRA_EVPNES_VTEP_RXED_ESR) { if (es_vtep->flags & ZEBRA_EVPNES_VTEP_RXED_ESR) {
json_object_string_add( json_object_string_add(
json_vtep_entry, "dfAlgorithm", json_vtep_entry, "dfAlgorithm",

View File

@ -1812,10 +1812,8 @@ void zebra_evpn_print_neigh(struct zebra_neigh *n, void *ctxt,
n->mac->es->esi_str); n->mac->es->esi_str);
} else { } else {
if (json) if (json)
json_object_string_add( json_object_string_addf(json, "remoteVtep",
json, "remoteVtep", "%pI4", &n->r_vtep_ip);
inet_ntop(AF_INET, &n->r_vtep_ip,
addr_buf, sizeof(addr_buf)));
else else
vty_out(vty, " Remote VTEP: %pI4\n", vty_out(vty, " Remote VTEP: %pI4\n",
&n->r_vtep_ip); &n->r_vtep_ip);
@ -1974,10 +1972,8 @@ void zebra_evpn_print_neigh_hash(struct hash_bucket *bucket, void *ctxt)
json_object_string_add(json_row, "remoteEs", json_object_string_add(json_row, "remoteEs",
n->mac->es->esi_str); n->mac->es->esi_str);
else else
json_object_string_add( json_object_string_addf(json_row, "remoteVtep",
json_row, "remoteVtep", "%pI4", &n->r_vtep_ip);
inet_ntop(AF_INET, &n->r_vtep_ip,
addr_buf, sizeof(addr_buf)));
if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW)) if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW))
json_object_boolean_true_add(json_row, json_object_boolean_true_add(json_row,
"defaultGateway"); "defaultGateway");

View File

@ -1531,15 +1531,13 @@ static json_object *nhlfe_json(struct zebra_nhlfe *nhlfe)
switch (nexthop->type) { switch (nexthop->type) {
case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4_IFINDEX:
json_object_string_add(json_nhlfe, "nexthop", json_object_string_addf(json_nhlfe, "nexthop", "%pI4",
inet_ntop(AF_INET, &nexthop->gate.ipv4, &nexthop->gate.ipv4);
buf, sizeof(buf)));
break; break;
case NEXTHOP_TYPE_IPV6: case NEXTHOP_TYPE_IPV6:
case NEXTHOP_TYPE_IPV6_IFINDEX: case NEXTHOP_TYPE_IPV6_IFINDEX:
json_object_string_add( json_object_string_addf(json_nhlfe, "nexthop", "%pI6",
json_nhlfe, "nexthop", &nexthop->gate.ipv6);
inet_ntop(AF_INET6, &nexthop->gate.ipv6, buf, BUFSIZ));
if (nexthop->ifindex) if (nexthop->ifindex)
json_object_string_add(json_nhlfe, "interface", json_object_string_add(json_nhlfe, "interface",

View File

@ -709,10 +709,8 @@ static void show_nexthop_json_helper(json_object *json_nexthop,
switch (nexthop->type) { switch (nexthop->type) {
case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4_IFINDEX:
json_object_string_add( json_object_string_addf(json_nexthop, "ip", "%pI4",
json_nexthop, "ip", &nexthop->gate.ipv4);
inet_ntop(AF_INET, &nexthop->gate.ipv4,
buf, sizeof(buf)));
json_object_string_add(json_nexthop, "afi", json_object_string_add(json_nexthop, "afi",
"ipv4"); "ipv4");
@ -729,10 +727,8 @@ static void show_nexthop_json_helper(json_object *json_nexthop,
break; break;
case NEXTHOP_TYPE_IPV6: case NEXTHOP_TYPE_IPV6:
case NEXTHOP_TYPE_IPV6_IFINDEX: case NEXTHOP_TYPE_IPV6_IFINDEX:
json_object_string_add( json_object_string_addf(json_nexthop, "ip", "%pI6",
json_nexthop, "ip", &nexthop->gate.ipv6);
inet_ntop(AF_INET6, &nexthop->gate.ipv6,
buf, sizeof(buf)));
json_object_string_add(json_nexthop, "afi", json_object_string_add(json_nexthop, "afi",
"ipv6"); "ipv6");

View File

@ -385,10 +385,8 @@ static void zl3vni_print_rmac(struct zebra_mac *zrmac, struct vty *vty,
json_object_string_add( json_object_string_add(
json, "routerMac", json, "routerMac",
prefix_mac2str(&zrmac->macaddr, buf1, sizeof(buf1))); prefix_mac2str(&zrmac->macaddr, buf1, sizeof(buf1)));
json_object_string_add(json, "vtepIp", json_object_string_addf(json, "vtepIp", "%pI4",
inet_ntop(AF_INET, &zrmac->fwd_info.r_vtep_ip);
&zrmac->fwd_info.r_vtep_ip,
buf1, sizeof(buf1)));
json_object_int_add(json, "refCount", json_object_int_add(json, "refCount",
rb_host_count(&zrmac->host_rb)); rb_host_count(&zrmac->host_rb));
RB_FOREACH (hle, host_rb_tree_entry, &zrmac->host_rb) RB_FOREACH (hle, host_rb_tree_entry, &zrmac->host_rb)
@ -680,10 +678,8 @@ static void zl3vni_print_rmac_hash(struct hash_bucket *bucket, void *ctx)
json_object_string_add( json_object_string_add(
json_rmac, "routerMac", json_rmac, "routerMac",
prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf))); prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf)));
json_object_string_add(json_rmac, "vtepIp", json_object_string_addf(json_rmac, "vtepIp", "%pI4",
inet_ntop(AF_INET, &zrmac->fwd_info.r_vtep_ip);
&zrmac->fwd_info.r_vtep_ip,
buf, sizeof(buf)));
json_object_object_add( json_object_object_add(
json, prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf)), json, prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf)),
json_rmac); json_rmac);
@ -729,10 +725,8 @@ static void zl3vni_print(struct zebra_l3vni *zl3vni, void **ctx)
json_evpn_list = json_object_new_array(); json_evpn_list = json_object_new_array();
json_object_int_add(json, "vni", zl3vni->vni); json_object_int_add(json, "vni", zl3vni->vni);
json_object_string_add(json, "type", "L3"); json_object_string_add(json, "type", "L3");
json_object_string_add( json_object_string_addf(json, "localVtepIp", "%pI4",
json, "localVtepIp", &zl3vni->local_vtep_ip);
inet_ntop(AF_INET, &zl3vni->local_vtep_ip, buf,
sizeof(buf)));
json_object_string_add(json, "vxlanIntf", json_object_string_add(json, "vxlanIntf",
zl3vni_vxlan_if_name(zl3vni)); zl3vni_vxlan_if_name(zl3vni));
json_object_string_add(json, "sviIntf", json_object_string_add(json, "sviIntf",