]> git.puffer.fish Git - mirror/frr.git/commitdiff
ripngd: use pI6 instead of inet6_ntoa
authorMark Stapp <mjs@voltanet.io>
Wed, 31 Mar 2021 12:28:30 +0000 (08:28 -0400)
committerMark Stapp <mjs@voltanet.io>
Wed, 31 Mar 2021 12:32:48 +0000 (08:32 -0400)
Stop using unsafe inet6_ntoa(), just use %pI6.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
ripngd/ripng_peer.c
ripngd/ripngd.c

index 479fcaeb54d6a21312f3734b59a1afcc02539ceb..554b1d68f6bb483b825f7cd0c36d1bab5935bfdd 100644 (file)
@@ -163,8 +163,8 @@ void ripng_peer_display(struct vty *vty, struct ripng *ripng)
        char timebuf[RIPNG_UPTIME_LEN];
 
        for (ALL_LIST_ELEMENTS(ripng->peer_list, node, nnode, peer)) {
-               vty_out(vty, "    %s \n%14s %10d %10d %10d      %s\n",
-                       inet6_ntoa(peer->addr), " ", peer->recv_badpackets,
+               vty_out(vty, "    %pI6 \n%14s %10d %10d %10d      %s\n",
+                       &peer->addr, " ", peer->recv_badpackets,
                        peer->recv_badroutes, ZEBRA_RIPNG_DISTANCE_DEFAULT,
                        ripng_peer_uptime(peer, timebuf, RIPNG_UPTIME_LEN));
        }
index 749feaca6cdadb370e7cc9d7b8f8a6039b7918f6..0e831401493b0f210f88d7c24694433117c45ca9 100644 (file)
@@ -191,7 +191,7 @@ int ripng_send_packet(caddr_t buf, int bufsize, struct sockaddr_in6 *to,
 
        if (IS_RIPNG_DEBUG_SEND) {
                if (to)
-                       zlog_debug("send to %s", inet6_ntoa(to->sin6_addr));
+                       zlog_debug("send to %pI6", &to->sin6_addr);
                zlog_debug("  send interface %s", ifp->name);
                zlog_debug("  send packet size %d", bufsize);
        }
@@ -237,8 +237,8 @@ int ripng_send_packet(caddr_t buf, int bufsize, struct sockaddr_in6 *to,
        if (ret < 0) {
                if (to)
                        flog_err_sys(EC_LIB_SOCKET,
-                                    "RIPng send fail on %s to %s: %s",
-                                    ifp->name, inet6_ntoa(to->sin6_addr),
+                                    "RIPng send fail on %s to %pI6: %s",
+                                    ifp->name, &to->sin6_addr,
                                     safe_strerror(errno));
                else
                        flog_err_sys(EC_LIB_SOCKET, "RIPng send fail on %s: %s",
@@ -338,11 +338,11 @@ void ripng_packet_dump(struct ripng_packet *packet, int size,
 
        for (lim = (caddr_t)packet + size; (caddr_t)rte < lim; rte++) {
                if (rte->metric == RIPNG_METRIC_NEXTHOP)
-                       zlog_debug("  nexthop %s/%d", inet6_ntoa(rte->addr),
+                       zlog_debug("  nexthop %pI6/%d", &rte->addr,
                                   rte->prefixlen);
                else
-                       zlog_debug("  %s/%d metric %d tag %" ROUTE_TAG_PRI,
-                                  inet6_ntoa(rte->addr), rte->prefixlen,
+                       zlog_debug("  %pI6/%d metric %d tag %" ROUTE_TAG_PRI,
+                                  &rte->addr, rte->prefixlen,
                                   rte->metric, (route_tag_t)ntohs(rte->tag));
        }
 }
@@ -353,9 +353,9 @@ static void ripng_nexthop_rte(struct rte *rte, struct sockaddr_in6 *from,
 {
        /* Logging before checking RTE. */
        if (IS_RIPNG_DEBUG_RECV)
-               zlog_debug("RIPng nexthop RTE address %s tag %" ROUTE_TAG_PRI
+               zlog_debug("RIPng nexthop RTE address %pI6 tag %" ROUTE_TAG_PRI
                           " prefixlen %d",
-                          inet6_ntoa(rte->addr), (route_tag_t)ntohs(rte->tag),
+                          &rte->addr, (route_tag_t)ntohs(rte->tag),
                           rte->prefixlen);
 
        /* RFC2080 2.1.1 Next Hop:
@@ -364,14 +364,13 @@ static void ripng_nexthop_rte(struct rte *rte, struct sockaddr_in6 *from,
        if (ntohs(rte->tag) != 0)
                zlog_warn(
                        "RIPng nexthop RTE with non zero tag value %" ROUTE_TAG_PRI
-                       " from %s",
-                       (route_tag_t)ntohs(rte->tag),
-                       inet6_ntoa(from->sin6_addr));
+                       " from %pI6",
+                       (route_tag_t)ntohs(rte->tag), &from->sin6_addr);
 
        if (rte->prefixlen != 0)
                zlog_warn(
-                       "RIPng nexthop RTE with non zero prefixlen value %d from %s",
-                       rte->prefixlen, inet6_ntoa(from->sin6_addr));
+                       "RIPng nexthop RTE with non zero prefixlen value %d from %pI6",
+                       rte->prefixlen, &from->sin6_addr);
 
        /* Specifying a value of 0:0:0:0:0:0:0:0 in the prefix field of a
         next hop RTE indicates that the next hop address should be the
@@ -396,8 +395,8 @@ static void ripng_nexthop_rte(struct rte *rte, struct sockaddr_in6 *from,
         information is ignored, a possibly sub-optimal, but absolutely
         valid, route may be taken.  If the received next hop address is not
         a link-local address, it should be treated as 0:0:0:0:0:0:0:0.  */
-       zlog_warn("RIPng nexthop RTE with non link-local address %s from %pI6",
-                 inet6_ntoa(rte->addr), &from->sin6_addr);
+       zlog_warn("RIPng nexthop RTE with non link-local address %pI6 from %pI6",
+                 &rte->addr, &from->sin6_addr);
 
        nexthop->flag = RIPNG_NEXTHOP_UNSPEC;
        memset(&nexthop->address, 0, sizeof(struct in6_addr));
@@ -750,8 +749,8 @@ static void ripng_route_process(struct rte *rte, struct sockaddr_in6 *from,
                if (ret == RMAP_DENYMATCH) {
                        if (IS_RIPNG_DEBUG_PACKET)
                                zlog_debug(
-                                       "RIPng %s/%d is filtered by route-map in",
-                                       inet6_ntoa(p.prefix), p.prefixlen);
+                                       "RIPng %pFX is filtered by route-map in",
+                                       &p);
                        return;
                }
 
@@ -993,8 +992,8 @@ void ripng_redistribute_add(struct ripng *ripng, int type, int sub_type,
                                p, ifindex2ifname(ifindex, ripng->vrf->vrf_id));
                else
                        zlog_debug(
-                               "Redistribute new prefix %pFX with nexthop %s on the interface %s",
-                               p, inet6_ntoa(*nexthop),
+                               "Redistribute new prefix %pFX with nexthop %pI6 on the interface %s",
+                               p, nexthop,
                                ifindex2ifname(ifindex, ripng->vrf->vrf_id));
        }
 
@@ -1106,8 +1105,8 @@ static void ripng_response_process(struct ripng_packet *packet, int size,
        /* RFC2080 2.4.2  Response Messages:
         The Response must be ignored if it is not from the RIPng port.  */
        if (ntohs(from->sin6_port) != RIPNG_PORT_DEFAULT) {
-               zlog_warn("RIPng packet comes from non RIPng port %d from %s",
-                         ntohs(from->sin6_port), inet6_ntoa(from->sin6_addr));
+               zlog_warn("RIPng packet comes from non RIPng port %d from %pI6",
+                         ntohs(from->sin6_port), &from->sin6_addr);
                ripng_peer_bad_packet(ripng, from);
                return;
        }
@@ -1116,8 +1115,8 @@ static void ripng_response_process(struct ripng_packet *packet, int size,
         whether the datagram is from a valid neighbor; the source of the
         datagram must be a link-local address.  */
        if (!IN6_IS_ADDR_LINKLOCAL(&from->sin6_addr)) {
-               zlog_warn("RIPng packet comes from non link local address %s",
-                         inet6_ntoa(from->sin6_addr));
+               zlog_warn("RIPng packet comes from non link local address %pI6",
+                         &from->sin6_addr);
                ripng_peer_bad_packet(ripng, from);
                return;
        }
@@ -1129,8 +1128,8 @@ static void ripng_response_process(struct ripng_packet *packet, int size,
         and such datagrams must be ignored. */
        if (ripng_lladdr_check(ifp, &from->sin6_addr)) {
                zlog_warn(
-                       "RIPng packet comes from my own link local address %s",
-                       inet6_ntoa(from->sin6_addr));
+                       "RIPng packet comes from my own link local address %pI6",
+                       &from->sin6_addr);
                ripng_peer_bad_packet(ripng, from);
                return;
        }
@@ -1141,8 +1140,8 @@ static void ripng_response_process(struct ripng_packet *packet, int size,
         packets) must be examined to ensure that the hop count is 255. */
        if (hoplimit >= 0 && hoplimit != 255) {
                zlog_warn(
-                       "RIPng packet comes with non 255 hop count %d from %s",
-                       hoplimit, inet6_ntoa(from->sin6_addr));
+                       "RIPng packet comes with non 255 hop count %d from %pI6",
+                       hoplimit, &from->sin6_addr);
                ripng_peer_bad_packet(ripng, from);
                return;
        }
@@ -1173,25 +1172,22 @@ static void ripng_response_process(struct ripng_packet *packet, int size,
                   should never be present in an RTE. */
                if (IN6_IS_ADDR_MULTICAST(&rte->addr)) {
                        zlog_warn(
-                               "Destination prefix is a multicast address %s/%d [%d]",
-                               inet6_ntoa(rte->addr), rte->prefixlen,
-                               rte->metric);
+                               "Destination prefix is a multicast address %pI6/%d [%d]",
+                               &rte->addr, rte->prefixlen, rte->metric);
                        ripng_peer_bad_route(ripng, from);
                        continue;
                }
                if (IN6_IS_ADDR_LINKLOCAL(&rte->addr)) {
                        zlog_warn(
-                               "Destination prefix is a link-local address %s/%d [%d]",
-                               inet6_ntoa(rte->addr), rte->prefixlen,
-                               rte->metric);
+                               "Destination prefix is a link-local address %pI6/%d [%d]",
+                               &rte->addr, rte->prefixlen, rte->metric);
                        ripng_peer_bad_route(ripng, from);
                        continue;
                }
                if (IN6_IS_ADDR_LOOPBACK(&rte->addr)) {
                        zlog_warn(
-                               "Destination prefix is a loopback address %s/%d [%d]",
-                               inet6_ntoa(rte->addr), rte->prefixlen,
-                               rte->metric);
+                               "Destination prefix is a loopback address %pI6/%d [%d]",
+                               &rte->addr, rte->prefixlen, rte->metric);
                        ripng_peer_bad_route(ripng, from);
                        continue;
                }
@@ -1199,17 +1195,17 @@ static void ripng_response_process(struct ripng_packet *packet, int size,
                /* - is the prefix length valid (i.e., between 0 and 128,
                   inclusive) */
                if (rte->prefixlen > 128) {
-                       zlog_warn("Invalid prefix length %s/%d from %s%%%s",
-                                 inet6_ntoa(rte->addr), rte->prefixlen,
-                                 inet6_ntoa(from->sin6_addr), ifp->name);
+                       zlog_warn("Invalid prefix length %pI6/%d from %pI6%%%s",
+                                 &rte->addr, rte->prefixlen,
+                                 &from->sin6_addr, ifp->name);
                        ripng_peer_bad_route(ripng, from);
                        continue;
                }
 
                /* - is the metric valid (i.e., between 1 and 16, inclusive) */
                if (!(rte->metric >= 1 && rte->metric <= 16)) {
-                       zlog_warn("Invalid metric %d from %s%%%s", rte->metric,
-                                 inet6_ntoa(from->sin6_addr), ifp->name);
+                       zlog_warn("Invalid metric %d from %pI6%%%s",
+                                 rte->metric, &from->sin6_addr, ifp->name);
                        ripng_peer_bad_route(ripng, from);
                        continue;
                }
@@ -1342,8 +1338,8 @@ static int ripng_read(struct thread *thread)
        /* Check RTE boundary.  RTE size (Packet length - RIPng header size
           (4)) must be multiple size of one RTE size (20). */
        if (((len - 4) % 20) != 0) {
-               zlog_warn("RIPng invalid packet size %d from %s (VRF %s)", len,
-                         inet6_ntoa(from.sin6_addr), ripng->vrf_name);
+               zlog_warn("RIPng invalid packet size %d from %pI6 (VRF %s)",
+                         len, &from.sin6_addr, ripng->vrf_name);
                ripng_peer_bad_packet(ripng, &from);
                return 0;
        }
@@ -1354,8 +1350,8 @@ static int ripng_read(struct thread *thread)
        /* RIPng packet received. */
        if (IS_RIPNG_DEBUG_EVENT)
                zlog_debug(
-                       "RIPng packet received from %s port %d on %s (VRF %s)",
-                       inet6_ntoa(from.sin6_addr), ntohs(from.sin6_port),
+                       "RIPng packet received from %pI6 port %d on %s (VRF %s)",
+                       &from.sin6_addr, ntohs(from.sin6_port),
                        ifp ? ifp->name : "unknown", ripng->vrf_name);
 
        /* Logging before packet checking. */
@@ -1581,8 +1577,8 @@ void ripng_output_process(struct interface *ifp, struct sockaddr_in6 *to,
 
        if (IS_RIPNG_DEBUG_EVENT) {
                if (to)
-                       zlog_debug("RIPng update routes to neighbor %s",
-                                  inet6_ntoa(to->sin6_addr));
+                       zlog_debug("RIPng update routes to neighbor %pI6",
+                                  &to->sin6_addr);
                else
                        zlog_debug("RIPng update routes on interface %s",
                                   ifp->name);
@@ -2089,8 +2085,8 @@ DEFUN (show_ipv6_ripng,
 #endif /* DEBUG */
                                vty_out(vty, "\n");
                                vty_out(vty, "%*s", 18, " ");
-                               len = vty_out(vty, "%s",
-                                             inet6_ntoa(rinfo->nexthop));
+                               len = vty_out(vty, "%pI6",
+                                             &rinfo->nexthop);
 
                                len = 28 - len;
                                if (len > 0)