ripd: replace inet_ntoa

Replace all uses of inet_ntoa, using pI4, pFX, or inet_pton.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
This commit is contained in:
Mark Stapp 2020-10-22 14:16:33 -04:00
parent 84de5a245a
commit 53bb7f9bb3
4 changed files with 71 additions and 81 deletions

View File

@ -172,8 +172,8 @@ static void rip_request_interface_send(struct interface *ifp, uint8_t version)
continue; continue;
if (IS_RIP_DEBUG_EVENT) if (IS_RIP_DEBUG_EVENT)
zlog_debug("SEND request to %s", zlog_debug("SEND request to %pI4",
inet_ntoa(to.sin_addr)); &to.sin_addr);
rip_request_send(&to, ifp, version, connected); rip_request_send(&to, ifp, version, connected);
} }
@ -1174,9 +1174,7 @@ int rip_show_network_config(struct vty *vty, struct rip *rip)
for (node = route_top(rip->enable_network); node; for (node = route_top(rip->enable_network); node;
node = route_next(node)) node = route_next(node))
if (node->info) if (node->info)
vty_out(vty, " %s/%u\n", vty_out(vty, " %pFX\n", &node->p);
inet_ntoa(node->p.u.prefix4),
node->p.prefixlen);
/* Interface name RIP enable statement. */ /* Interface name RIP enable statement. */
for (i = 0; i < vector_active(rip->enable_interface); i++) for (i = 0; i < vector_active(rip->enable_interface); i++)
@ -1186,7 +1184,7 @@ int rip_show_network_config(struct vty *vty, struct rip *rip)
/* RIP neighbors listing. */ /* RIP neighbors listing. */
for (node = route_top(rip->neighbor); node; node = route_next(node)) for (node = route_top(rip->neighbor); node; node = route_next(node))
if (node->info) if (node->info)
vty_out(vty, " %s\n", inet_ntoa(node->p.u.prefix4)); vty_out(vty, " %pI4\n", &node->p.u.prefix4);
return 0; return 0;
} }

View File

@ -155,8 +155,8 @@ void rip_peer_display(struct vty *vty, struct rip *rip)
char timebuf[RIP_UPTIME_LEN]; char timebuf[RIP_UPTIME_LEN];
for (ALL_LIST_ELEMENTS(rip->peer_list, node, nnode, peer)) { for (ALL_LIST_ELEMENTS(rip->peer_list, node, nnode, peer)) {
vty_out(vty, " %-16s %9d %9d %9d %s\n", vty_out(vty, " %-16pI4 %9d %9d %9d %s\n",
inet_ntoa(peer->addr), peer->recv_badpackets, &peer->addr, peer->recv_badpackets,
peer->recv_badroutes, ZEBRA_RIP_DISTANCE_DEFAULT, peer->recv_badroutes, ZEBRA_RIP_DISTANCE_DEFAULT,
rip_peer_uptime(peer, timebuf, RIP_UPTIME_LEN)); rip_peer_uptime(peer, timebuf, RIP_UPTIME_LEN));
} }

View File

@ -88,18 +88,16 @@ static void rip_zebra_ipv4_send(struct rip *rip, struct route_node *rp,
if (IS_RIP_DEBUG_ZEBRA) { if (IS_RIP_DEBUG_ZEBRA) {
if (rip->ecmp) if (rip->ecmp)
zlog_debug("%s: %s/%d nexthops %d", zlog_debug("%s: %pFX nexthops %d",
(cmd == ZEBRA_ROUTE_ADD) (cmd == ZEBRA_ROUTE_ADD)
? "Install into zebra" ? "Install into zebra"
: "Delete from zebra", : "Delete from zebra",
inet_ntoa(rp->p.u.prefix4), rp->p.prefixlen, &rp->p, count);
count);
else else
zlog_debug("%s: %s/%d", zlog_debug("%s: %pFX",
(cmd == ZEBRA_ROUTE_ADD) (cmd == ZEBRA_ROUTE_ADD)
? "Install into zebra" ? "Install into zebra"
: "Delete from zebra", : "Delete from zebra", &rp->p);
inet_ntoa(rp->p.u.prefix4), rp->p.prefixlen);
} }
rip->counters.route_changes++; rip->counters.route_changes++;

View File

@ -45,6 +45,7 @@
#include "lib_errors.h" #include "lib_errors.h"
#include "northbound_cli.h" #include "northbound_cli.h"
#include "network.h" #include "network.h"
#include "lib/printfrr.h"
#include "ripd/ripd.h" #include "ripd/ripd.h"
#include "ripd/rip_nb.h" #include "ripd/rip_nb.h"
@ -466,8 +467,8 @@ static void rip_rte_process(struct rte *rte, struct sockaddr_in *from,
if (ret == RMAP_DENYMATCH) { if (ret == RMAP_DENYMATCH) {
if (IS_RIP_DEBUG_PACKET) if (IS_RIP_DEBUG_PACKET)
zlog_debug( zlog_debug(
"RIP %s/%d is filtered by route-map in", "RIP %pFX is filtered by route-map in",
inet_ntoa(p.prefix), p.prefixlen); &p);
return; return;
} }
@ -502,8 +503,8 @@ static void rip_rte_process(struct rte *rte, struct sockaddr_in *from,
/* Check if nexthop address is myself, then do nothing. */ /* Check if nexthop address is myself, then do nothing. */
if (rip_nexthop_check(rip, nexthop) < 0) { if (rip_nexthop_check(rip, nexthop) < 0) {
if (IS_RIP_DEBUG_PACKET) if (IS_RIP_DEBUG_PACKET)
zlog_debug("Nexthop address %s is myself", zlog_debug("Nexthop address %pI4 is myself",
inet_ntoa(*nexthop)); nexthop);
return; return;
} }
@ -830,8 +831,8 @@ static int rip_auth_simple_password(struct rte *rte, struct sockaddr_in *from,
} }
if (IS_RIP_DEBUG_EVENT) if (IS_RIP_DEBUG_EVENT)
zlog_debug("RIPv2 simple password authentication from %s", zlog_debug("RIPv2 simple password authentication from %pI4",
inet_ntoa(from->sin_addr)); &from->sin_addr);
ri = ifp->info; ri = ifp->info;
@ -878,8 +879,8 @@ static int rip_auth_md5(struct rip_packet *packet, struct sockaddr_in *from,
char auth_str[RIP_AUTH_MD5_SIZE] = {}; char auth_str[RIP_AUTH_MD5_SIZE] = {};
if (IS_RIP_DEBUG_EVENT) if (IS_RIP_DEBUG_EVENT)
zlog_debug("RIPv2 MD5 authentication from %s", zlog_debug("RIPv2 MD5 authentication from %pI4",
inet_ntoa(from->sin_addr)); &from->sin_addr);
ri = ifp->info; ri = ifp->info;
md5 = (struct rip_md5_info *)&packet->rte; md5 = (struct rip_md5_info *)&packet->rte;
@ -1160,8 +1161,8 @@ static void rip_response_process(struct rip_packet *packet, int size,
rip->vrf->vrf_id) rip->vrf->vrf_id)
== NULL) { == NULL) {
zlog_info( zlog_info(
"This datagram doesn't came from a valid neighbor: %s", "This datagram doesn't come from a valid neighbor: %pI4",
inet_ntoa(from->sin_addr)); &from->sin_addr);
rip_peer_bad_packet(rip, from); rip_peer_bad_packet(rip, from);
return; return;
} }
@ -1190,9 +1191,9 @@ static void rip_response_process(struct rip_packet *packet, int size,
if (rte->family != htons(AF_INET)) { if (rte->family != htons(AF_INET)) {
/* Address family check. RIP only supports AF_INET. */ /* Address family check. RIP only supports AF_INET. */
zlog_info("Unsupported family %d from %s.", zlog_info("Unsupported family %d from %pI4",
ntohs(rte->family), ntohs(rte->family),
inet_ntoa(from->sin_addr)); &from->sin_addr);
continue; continue;
} }
@ -1218,8 +1219,8 @@ static void rip_response_process(struct rip_packet *packet, int size,
/* RIPv1 does not have nexthop value. */ /* RIPv1 does not have nexthop value. */
if (packet->version == RIPv1 if (packet->version == RIPv1
&& rte->nexthop.s_addr != INADDR_ANY) { && rte->nexthop.s_addr != INADDR_ANY) {
zlog_info("RIPv1 packet with nexthop value %s", zlog_info("RIPv1 packet with nexthop value %pI4",
inet_ntoa(rte->nexthop)); &rte->nexthop);
rip_peer_bad_route(rip, from); rip_peer_bad_route(rip, from);
continue; continue;
} }
@ -1236,8 +1237,8 @@ static void rip_response_process(struct rip_packet *packet, int size,
addrval = ntohl(rte->nexthop.s_addr); addrval = ntohl(rte->nexthop.s_addr);
if (IN_CLASSD(addrval)) { if (IN_CLASSD(addrval)) {
zlog_info( zlog_info(
"Nexthop %s is multicast address, skip this rte", "Nexthop %pI4 is multicast address, skip this rte",
inet_ntoa(rte->nexthop)); &rte->nexthop);
continue; continue;
} }
@ -1257,16 +1258,14 @@ static void rip_response_process(struct rip_packet *packet, int size,
== RIP_ROUTE_RTE) { == RIP_ROUTE_RTE) {
if (IS_RIP_DEBUG_EVENT) if (IS_RIP_DEBUG_EVENT)
zlog_debug( zlog_debug(
"Next hop %s is on RIP network. Set nexthop to the packet's originator", "Next hop %pI4 is on RIP network. Set nexthop to the packet's originator",
inet_ntoa( &rte->nexthop);
rte->nexthop));
rte->nexthop = rinfo->from; rte->nexthop = rinfo->from;
} else { } else {
if (IS_RIP_DEBUG_EVENT) if (IS_RIP_DEBUG_EVENT)
zlog_debug( zlog_debug(
"Next hop %s is not directly reachable. Treat it as 0.0.0.0", "Next hop %pI4 is not directly reachable. Treat it as 0.0.0.0",
inet_ntoa( &rte->nexthop);
rte->nexthop));
rte->nexthop.s_addr = rte->nexthop.s_addr =
INADDR_ANY; INADDR_ANY;
} }
@ -1275,9 +1274,8 @@ static void rip_response_process(struct rip_packet *packet, int size,
} else { } else {
if (IS_RIP_DEBUG_EVENT) if (IS_RIP_DEBUG_EVENT)
zlog_debug( zlog_debug(
"Next hop %s is not directly reachable. Treat it as 0.0.0.0", "Next hop %pI4 is not directly reachable. Treat it as 0.0.0.0",
inet_ntoa( &rte->nexthop);
rte->nexthop));
rte->nexthop.s_addr = INADDR_ANY; rte->nexthop.s_addr = INADDR_ANY;
} }
} }
@ -1331,8 +1329,8 @@ static void rip_response_process(struct rip_packet *packet, int size,
!= rte->prefix.s_addr) != rte->prefix.s_addr)
masklen2ip(32, &rte->mask); masklen2ip(32, &rte->mask);
if (IS_RIP_DEBUG_EVENT) if (IS_RIP_DEBUG_EVENT)
zlog_debug("Subnetted route %s", zlog_debug("Subnetted route %pI4",
inet_ntoa(rte->prefix)); &rte->prefix);
} else { } else {
if ((rte->prefix.s_addr & rte->mask.s_addr) if ((rte->prefix.s_addr & rte->mask.s_addr)
!= rte->prefix.s_addr) != rte->prefix.s_addr)
@ -1340,10 +1338,10 @@ static void rip_response_process(struct rip_packet *packet, int size,
} }
if (IS_RIP_DEBUG_EVENT) { if (IS_RIP_DEBUG_EVENT) {
zlog_debug("Resultant route %s", zlog_debug("Resultant route %pI4",
inet_ntoa(rte->prefix)); &rte->prefix);
zlog_debug("Resultant mask %s", zlog_debug("Resultant mask %pI4",
inet_ntoa(rte->mask)); &rte->mask);
} }
} }
@ -1354,8 +1352,8 @@ static void rip_response_process(struct rip_packet *packet, int size,
&& ((rte->prefix.s_addr & rte->mask.s_addr) && ((rte->prefix.s_addr & rte->mask.s_addr)
!= rte->prefix.s_addr)) { != rte->prefix.s_addr)) {
zlog_warn( zlog_warn(
"RIPv2 address %s is not mask /%d applied one", "RIPv2 address %pI4 is not mask /%d applied one",
inet_ntoa(rte->prefix), ip_masklen(rte->mask)); &rte->prefix, ip_masklen(rte->mask));
rip_peer_bad_route(rip, from); rip_peer_bad_route(rip, from);
continue; continue;
} }
@ -1418,8 +1416,8 @@ int rip_create_socket(struct vrf *vrf)
frr_with_privs(&ripd_privs) { frr_with_privs(&ripd_privs) {
if ((ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr))) if ((ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr)))
< 0) { < 0) {
zlog_err("%s: Can't bind socket %d to %s port %d: %s", zlog_err("%s: Can't bind socket %d to %pI4 port %d: %s",
__func__, sock, inet_ntoa(addr.sin_addr), __func__, sock, &addr.sin_addr,
(int)ntohs(addr.sin_port), (int)ntohs(addr.sin_port),
safe_strerror(errno)); safe_strerror(errno));
@ -1459,14 +1457,14 @@ static int rip_send_packet(uint8_t *buf, int size, struct sockaddr_in *to,
char dst[ADDRESS_SIZE]; char dst[ADDRESS_SIZE];
if (to) { if (to) {
strlcpy(dst, inet_ntoa(to->sin_addr), sizeof(dst)); inet_ntop(AF_INET, &to->sin_addr, dst, sizeof(dst));
} else { } else {
sin.sin_addr.s_addr = htonl(INADDR_RIP_GROUP); sin.sin_addr.s_addr = htonl(INADDR_RIP_GROUP);
strlcpy(dst, inet_ntoa(sin.sin_addr), sizeof(dst)); inet_ntop(AF_INET, &sin.sin_addr, dst, sizeof(dst));
} }
#undef ADDRESS_SIZE #undef ADDRESS_SIZE
zlog_debug("rip_send_packet %s > %s (%s)", zlog_debug("rip_send_packet %pI4 > %s (%s)",
inet_ntoa(ifc->address->u.prefix4), dst, &ifc->address->u.prefix4, dst,
ifc->ifp->name); ifc->ifp->name);
} }
@ -1533,7 +1531,7 @@ static int rip_send_packet(uint8_t *buf, int size, struct sockaddr_in *to,
ret = sendmsg(rip->sock, &msg, 0); ret = sendmsg(rip->sock, &msg, 0);
if (IS_RIP_DEBUG_EVENT) if (IS_RIP_DEBUG_EVENT)
zlog_debug("SEND to %s.%d", inet_ntoa(sin.sin_addr), zlog_debug("SEND to %pI4%d", &sin.sin_addr,
ntohs(sin.sin_port)); ntohs(sin.sin_port));
if (ret < 0) if (ret < 0)
@ -1782,15 +1780,15 @@ static int rip_read(struct thread *t)
/* RIP packet received */ /* RIP packet received */
if (IS_RIP_DEBUG_EVENT) if (IS_RIP_DEBUG_EVENT)
zlog_debug("RECV packet from %s port %d on %s (VRF %s)", zlog_debug("RECV packet from %pI4 port %d on %s (VRF %s)",
inet_ntoa(from.sin_addr), ntohs(from.sin_port), &from.sin_addr, ntohs(from.sin_port),
ifp ? ifp->name : "unknown", rip->vrf_name); ifp ? ifp->name : "unknown", rip->vrf_name);
/* If this packet come from unknown interface, ignore it. */ /* If this packet come from unknown interface, ignore it. */
if (ifp == NULL) { if (ifp == NULL) {
zlog_info( zlog_info(
"rip_read: cannot find interface for packet from %s port %d (VRF %s)", "rip_read: cannot find interface for packet from %pI4 port %d (VRF %s)",
inet_ntoa(from.sin_addr), ntohs(from.sin_port), &from.sin_addr, ntohs(from.sin_port),
rip->vrf_name); rip->vrf_name);
return -1; return -1;
} }
@ -1803,8 +1801,8 @@ static int rip_read(struct thread *t)
if (ifc == NULL) { if (ifc == NULL) {
zlog_info( zlog_info(
"rip_read: cannot find connected address for packet from %s port %d on interface %s (VRF %s)", "rip_read: cannot find connected address for packet from %pI4 port %d on interface %s (VRF %s)",
inet_ntoa(from.sin_addr), ntohs(from.sin_port), &from.sin_addr, ntohs(from.sin_port),
ifp->name, rip->vrf_name); ifp->name, rip->vrf_name);
return -1; return -1;
} }
@ -2077,8 +2075,8 @@ void rip_output_process(struct connected *ifc, struct sockaddr_in *to,
/* Logging output event. */ /* Logging output event. */
if (IS_RIP_DEBUG_EVENT) { if (IS_RIP_DEBUG_EVENT) {
if (to) if (to)
zlog_debug("update routes to neighbor %s", zlog_debug("update routes to neighbor %pI4",
inet_ntoa(to->sin_addr)); &to->sin_addr);
else else
zlog_debug("update routes on interface %s ifindex %d", zlog_debug("update routes on interface %s ifindex %d",
ifc->ifp->name, ifc->ifp->ifindex); ifc->ifp->name, ifc->ifp->ifindex);
@ -2143,9 +2141,8 @@ void rip_output_process(struct connected *ifc, struct sockaddr_in *to,
if (IS_RIP_DEBUG_PACKET) if (IS_RIP_DEBUG_PACKET)
zlog_debug( zlog_debug(
"RIPv1 mask check, %s/%d considered for output", "RIPv1 mask check, %pFX considered for output",
inet_ntoa(rp->p.u.prefix4), &rp->p);
rp->p.prefixlen);
if (subnetted if (subnetted
&& prefix_match( && prefix_match(
@ -2166,9 +2163,8 @@ void rip_output_process(struct connected *ifc, struct sockaddr_in *to,
} }
if (IS_RIP_DEBUG_PACKET) if (IS_RIP_DEBUG_PACKET)
zlog_debug( zlog_debug(
"RIPv1 mask check, %s/%d made it through", "RIPv1 mask check, %pFX made it through",
inet_ntoa(rp->p.u.prefix4), &rp->p);
rp->p.prefixlen);
} else } else
p = (struct prefix_ipv4 *)&rp->p; p = (struct prefix_ipv4 *)&rp->p;
@ -2452,10 +2448,10 @@ static void rip_update_interface(struct connected *ifc, uint8_t version,
to.sin_port = htons(RIP_PORT_DEFAULT); to.sin_port = htons(RIP_PORT_DEFAULT);
if (IS_RIP_DEBUG_EVENT) if (IS_RIP_DEBUG_EVENT)
zlog_debug("%s announce to %s on %s", zlog_debug("%s announce to %pI4 on %s",
CONNECTED_PEER(ifc) ? "unicast" CONNECTED_PEER(ifc) ? "unicast"
: "broadcast", : "broadcast",
inet_ntoa(to.sin_addr), ifp->name); &to.sin_addr, ifp->name);
rip_output_process(ifc, &to, route_type, version); rip_output_process(ifc, &to, route_type, version);
} }
@ -2530,8 +2526,8 @@ static void rip_update_process(struct rip *rip, int route_type)
rip->vrf->vrf_id); rip->vrf->vrf_id);
if (!connected) { if (!connected) {
zlog_warn( zlog_warn(
"Neighbor %s doesn't have connected interface!", "Neighbor %pI4 doesn't have connected interface!",
inet_ntoa(p->u.prefix4)); &p->u.prefix4);
continue; continue;
} }
@ -2957,8 +2953,7 @@ static void rip_distance_show(struct vty *vty, struct rip *rip)
" Address Distance List\n"); " Address Distance List\n");
header = 0; header = 0;
} }
snprintf(buf, sizeof(buf), "%s/%d", snprintfrr(buf, sizeof(buf), "%pFX", &rn->p);
inet_ntoa(rn->p.u.prefix4), rn->p.prefixlen);
vty_out(vty, " %-20s %4d %s\n", buf, vty_out(vty, " %-20s %4d %s\n", buf,
rdistance->distance, rdistance->distance,
rdistance->access_list ? rdistance->access_list rdistance->access_list ? rdistance->access_list
@ -3085,12 +3080,11 @@ DEFUN (show_ip_rip,
int len; int len;
len = vty_out( len = vty_out(
vty, "%c(%s) %s/%d", vty, "%c(%s) %pFX",
/* np->lock, For debugging. */ /* np->lock, For debugging. */
zebra_route_char(rinfo->type), zebra_route_char(rinfo->type),
rip_route_type_print(rinfo->sub_type), rip_route_type_print(rinfo->sub_type),
inet_ntoa(np->p.u.prefix4), &np->p);
np->p.prefixlen);
len = 24 - len; len = 24 - len;
@ -3100,8 +3094,8 @@ DEFUN (show_ip_rip,
switch (rinfo->nh.type) { switch (rinfo->nh.type) {
case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4_IFINDEX:
vty_out(vty, "%-20s %2d ", vty_out(vty, "%-20pI4 %2d ",
inet_ntoa(rinfo->nh.gate.ipv4), &rinfo->nh.gate.ipv4,
rinfo->metric); rinfo->metric);
break; break;
case NEXTHOP_TYPE_IFINDEX: case NEXTHOP_TYPE_IFINDEX:
@ -3125,8 +3119,8 @@ DEFUN (show_ip_rip,
/* Route which exist in kernel routing table. */ /* Route which exist in kernel routing table. */
if ((rinfo->type == ZEBRA_ROUTE_RIP) if ((rinfo->type == ZEBRA_ROUTE_RIP)
&& (rinfo->sub_type == RIP_ROUTE_RTE)) { && (rinfo->sub_type == RIP_ROUTE_RTE)) {
vty_out(vty, "%-15s ", vty_out(vty, "%-15pI4 ",
inet_ntoa(rinfo->from)); &rinfo->from);
vty_out(vty, "%3" ROUTE_TAG_PRI " ", vty_out(vty, "%3" ROUTE_TAG_PRI " ",
(route_tag_t)rinfo->tag); (route_tag_t)rinfo->tag);
rip_vty_out_uptime(vty, rinfo); rip_vty_out_uptime(vty, rinfo);