]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Convert inet_ntoa to %pI4
authorDonatas Abraitis <donatas.abraitis@gmail.com>
Sun, 18 Oct 2020 11:21:26 +0000 (14:21 +0300)
committerDonatas Abraitis <donatas.abraitis@gmail.com>
Thu, 22 Oct 2020 12:32:50 +0000 (15:32 +0300)
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
lib/filter.c
lib/if.c
lib/nexthop.c
lib/nexthop_group.c
lib/sockunion.c

index e6add0462b9d3f93e5087d2b65d94a79ec53f262..f5ae9ee2b75e321b19f88223932a6a60b684372c 100644 (file)
@@ -576,14 +576,12 @@ static int filter_show(struct vty *vty, const char *name, afi_t afi)
                                if (filter->addr_mask.s_addr == 0xffffffff)
                                        vty_out(vty, " any\n");
                                else {
-                                       vty_out(vty, " %s",
-                                               inet_ntoa(filter->addr));
+                                       vty_out(vty, " %pI4", &filter->addr);
                                        if (filter->addr_mask.s_addr
                                            != INADDR_ANY)
                                                vty_out(vty,
-                                                       ", wildcard bits %s",
-                                                       inet_ntoa(
-                                                               filter->addr_mask));
+                                                       ", wildcard bits %pI4",
+                                                       &filter->addr_mask);
                                        vty_out(vty, "\n");
                                }
                        }
@@ -625,14 +623,12 @@ static int filter_show(struct vty *vty, const char *name, afi_t afi)
                                if (filter->addr_mask.s_addr == 0xffffffff)
                                        vty_out(vty, " any\n");
                                else {
-                                       vty_out(vty, " %s",
-                                               inet_ntoa(filter->addr));
+                                       vty_out(vty, " %pI4", &filter->addr);
                                        if (filter->addr_mask.s_addr
                                            != INADDR_ANY)
                                                vty_out(vty,
-                                                       ", wildcard bits %s",
-                                                       inet_ntoa(
-                                                               filter->addr_mask));
+                                                       ", wildcard bits %pI4",
+                                                       &filter->addr_mask);
                                        vty_out(vty, "\n");
                                }
                        }
@@ -722,29 +718,28 @@ static void config_write_access_cisco(struct vty *vty, struct filter *mfilter)
                if (filter->addr_mask.s_addr == 0xffffffff)
                        vty_out(vty, " any");
                else if (filter->addr_mask.s_addr == INADDR_ANY)
-                       vty_out(vty, " host %s", inet_ntoa(filter->addr));
+                       vty_out(vty, " host %pI4", &filter->addr);
                else {
-                       vty_out(vty, " %s", inet_ntoa(filter->addr));
-                       vty_out(vty, " %s", inet_ntoa(filter->addr_mask));
+                       vty_out(vty, " %pI4", &filter->addr);
+                       vty_out(vty, " %pI4", &filter->addr_mask);
                }
 
                if (filter->mask_mask.s_addr == 0xffffffff)
                        vty_out(vty, " any");
                else if (filter->mask_mask.s_addr == INADDR_ANY)
-                       vty_out(vty, " host %s", inet_ntoa(filter->mask));
+                       vty_out(vty, " host %pI4", &filter->mask);
                else {
-                       vty_out(vty, " %s", inet_ntoa(filter->mask));
-                       vty_out(vty, " %s", inet_ntoa(filter->mask_mask));
+                       vty_out(vty, " %pI4", &filter->mask);
+                       vty_out(vty, " %pI4", &filter->mask_mask);
                }
                vty_out(vty, "\n");
        } else {
                if (filter->addr_mask.s_addr == 0xffffffff)
                        vty_out(vty, " any\n");
                else {
-                       vty_out(vty, " %s", inet_ntoa(filter->addr));
+                       vty_out(vty, " %pI4", &filter->addr);
                        if (filter->addr_mask.s_addr != INADDR_ANY)
-                               vty_out(vty, " %s",
-                                       inet_ntoa(filter->addr_mask));
+                               vty_out(vty, " %pI4", &filter->addr_mask);
                        vty_out(vty, "\n");
                }
        }
index 35aa46ca2d8a2e16547fff6d2f5695b943dd883a..c707c4c6d9040cc6794fa4c0eda291639d443ae5 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -1106,8 +1106,8 @@ ifaddr_ipv4_add (struct in_addr *ifaddr, struct interface *ifp)
   if (rn)
     {
       route_unlock_node (rn);
-      zlog_info ("ifaddr_ipv4_add(): address %s is already added",
-                inet_ntoa (*ifaddr));
+      zlog_info("ifaddr_ipv4_add(): address %pI4 is already added",
+                               ifaddr);
       return;
     }
   rn->info = ifp;
@@ -1126,8 +1126,7 @@ ifaddr_ipv4_delete (struct in_addr *ifaddr, struct interface *ifp)
   rn = route_node_lookup (ifaddr_ipv4_table, (struct prefix *) &p);
   if (! rn)
     {
-      zlog_info ("ifaddr_ipv4_delete(): can't find address %s",
-                inet_ntoa (*ifaddr));
+      zlog_info("%s: can't find address %pI4", __func__, ifaddr);
       return;
     }
   rn->info = NULL;
index f1575649b17b9e99bd5fd3a1f4b26cb464354a32..b2fa9456909fe802834a5d1c225bf1ce3385aa33 100644 (file)
@@ -431,13 +431,13 @@ const char *nexthop2str(const struct nexthop *nexthop, char *str, int size)
                break;
        case NEXTHOP_TYPE_IPV4:
        case NEXTHOP_TYPE_IPV4_IFINDEX:
-               snprintf(str, size, "%s if %u", inet_ntoa(nexthop->gate.ipv4),
-                        nexthop->ifindex);
+               snprintfrr(str, size, "%pI4 if %u", &nexthop->gate.ipv4,
+                          nexthop->ifindex);
                break;
        case NEXTHOP_TYPE_IPV6:
        case NEXTHOP_TYPE_IPV6_IFINDEX:
-               snprintf(str, size, "%s if %u", inet6_ntoa(nexthop->gate.ipv6),
-                        nexthop->ifindex);
+               snprintfrr(str, size, "%pI6 if %u", &nexthop->gate.ipv6,
+                          nexthop->ifindex);
                break;
        case NEXTHOP_TYPE_BLACKHOLE:
                snprintf(str, size, "blackhole");
index 4afb1d642a35426ae181d2a296cbe06d6db7c5ce..dee98ad8d73ab7ee06b25e50483102ad01ef70e6 100644 (file)
@@ -975,7 +975,6 @@ void nexthop_group_write_nexthop_simple(struct vty *vty,
                                        const struct nexthop *nh,
                                        char *altifname)
 {
-       char buf[100];
        char *ifname;
 
        vty_out(vty, "nexthop ");
@@ -990,19 +989,16 @@ void nexthop_group_write_nexthop_simple(struct vty *vty,
                vty_out(vty, "%s", ifname);
                break;
        case NEXTHOP_TYPE_IPV4:
-               vty_out(vty, "%s", inet_ntoa(nh->gate.ipv4));
+               vty_out(vty, "%pI4", &nh->gate.ipv4);
                break;
        case NEXTHOP_TYPE_IPV4_IFINDEX:
-               vty_out(vty, "%s %s", inet_ntoa(nh->gate.ipv4), ifname);
+               vty_out(vty, "%pI4 %s", &nh->gate.ipv4, ifname);
                break;
        case NEXTHOP_TYPE_IPV6:
-               vty_out(vty, "%s",
-                       inet_ntop(AF_INET6, &nh->gate.ipv6, buf, sizeof(buf)));
+               vty_out(vty, "%pI6", &nh->gate.ipv6);
                break;
        case NEXTHOP_TYPE_IPV6_IFINDEX:
-               vty_out(vty, "%s %s",
-                       inet_ntop(AF_INET6, &nh->gate.ipv6, buf, sizeof(buf)),
-                       ifname);
+               vty_out(vty, "%pI6 %s", &nh->gate.ipv6, ifname);
                break;
        case NEXTHOP_TYPE_BLACKHOLE:
                break;
@@ -1056,10 +1052,14 @@ void nexthop_group_json_nexthop(json_object *j, const struct nexthop *nh)
                                       ifindex2ifname(nh->ifindex, nh->vrf_id));
                break;
        case NEXTHOP_TYPE_IPV4:
-               json_object_string_add(j, "nexthop", inet_ntoa(nh->gate.ipv4));
+               json_object_string_add(
+                       j, "nexthop",
+                       inet_ntop(AF_INET, &nh->gate.ipv4, buf, sizeof(buf)));
                break;
        case NEXTHOP_TYPE_IPV4_IFINDEX:
-               json_object_string_add(j, "nexthop", inet_ntoa(nh->gate.ipv4));
+               json_object_string_add(
+                       j, "nexthop",
+                       inet_ntop(AF_INET, &nh->gate.ipv4, buf, sizeof(buf)));
                json_object_string_add(j, "vrfId",
                                       ifindex2ifname(nh->ifindex, nh->vrf_id));
                break;
index d77229797c06b356355a2ea60e36524cce0b75b9..c9998456593bcd34b8fee12373c7e333affdbdc5 100644 (file)
@@ -587,15 +587,11 @@ static void __attribute__((unused)) sockunion_print(const union sockunion *su)
 
        switch (su->sa.sa_family) {
        case AF_INET:
-               printf("%s\n", inet_ntoa(su->sin.sin_addr));
+               printf("%pI4\n", &su->sin.sin_addr);
+               break;
+       case AF_INET6:
+               printf("%pI6\n", &su->sin6.sin6_addr);
                break;
-       case AF_INET6: {
-               char buf[SU_ADDRSTRLEN];
-
-               printf("%s\n", inet_ntop(AF_INET6, &(su->sin6.sin6_addr), buf,
-                                        sizeof(buf)));
-       } break;
-
 #ifdef AF_LINK
        case AF_LINK: {
                struct sockaddr_dl *sdl;