]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: inet_ntop() adjustments
authorDonatas Abraitis <donatas@opensourcerouting.org>
Tue, 29 Nov 2022 08:23:20 +0000 (10:23 +0200)
committerDonatas Abraitis <donatas@opensourcerouting.org>
Tue, 29 Nov 2022 15:36:13 +0000 (17:36 +0200)
Use %pI4/%pI6 where possible, otherwise at least atjust stack buffer sizes
for inet_ntop() calls.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
15 files changed:
bgpd/bgp_attr.c
bgpd/bgp_debug.c
bgpd/bgp_ecommunity.c
bgpd/bgp_evpn_mh.c
bgpd/bgp_evpn_vty.c
bgpd/bgp_flowspec_vty.c
bgpd/bgp_nexthop.c
bgpd/bgp_pbr.c
bgpd/bgp_route.c
bgpd/bgp_routemap.c
bgpd/bgp_vty.c
bgpd/bgp_zebra.c
bgpd/rfapi/rfapi.c
bgpd/rfapi/rfapi_import.c
bgpd/rfapi/rfapi_vty.c

index b8010364a7755af3ba98c64941eff6c9524b97e2..1f8c7dc098f916437852f2c549c48013020dd1f7 100644 (file)
@@ -904,20 +904,16 @@ static void attrhash_finish(void)
 static void attr_show_all_iterator(struct hash_bucket *bucket, struct vty *vty)
 {
        struct attr *attr = bucket->data;
-       char sid_str[BUFSIZ];
 
        vty_out(vty, "attr[%ld] nexthop %pI4\n", attr->refcnt, &attr->nexthop);
 
-       sid_str[0] = '\0';
-       if (attr->srv6_l3vpn)
-               inet_ntop(AF_INET6, &attr->srv6_l3vpn->sid, sid_str, BUFSIZ);
-       else if (attr->srv6_vpn)
-               inet_ntop(AF_INET6, &attr->srv6_vpn->sid, sid_str, BUFSIZ);
-
        vty_out(vty,
-               "\tflags: %" PRIu64" distance: %u med: %u local_pref: %u origin: %u weight: %u label: %u sid: %s\n",
+               "\tflags: %" PRIu64
+               " distance: %u med: %u local_pref: %u origin: %u weight: %u label: %u sid: %pI6\n",
                attr->flag, attr->distance, attr->med, attr->local_pref,
-               attr->origin, attr->weight, attr->label, sid_str);
+               attr->origin, attr->weight, attr->label,
+               attr->srv6_l3vpn ? &attr->srv6_l3vpn->sid
+                                : &attr->srv6_vpn->sid);
 }
 
 void attr_show_all(struct vty *vty)
@@ -1746,12 +1742,9 @@ enum bgp_attr_parse_ret bgp_attr_nexthop_valid(struct peer *peer,
 
        if (ipv4_martian(&attr->nexthop) && !bgp->allow_martian) {
                uint8_t data[7]; /* type(2) + length(1) + nhop(4) */
-               char buf[INET_ADDRSTRLEN];
 
-               inet_ntop(AF_INET, &attr->nexthop.s_addr, buf,
-                         INET_ADDRSTRLEN);
-               flog_err(EC_BGP_ATTR_MARTIAN_NH, "Martian nexthop %s",
-                        buf);
+               flog_err(EC_BGP_ATTR_MARTIAN_NH, "Martian nexthop %pI4",
+                        &attr->nexthop);
                data[0] = BGP_ATTR_FLAG_TRANS;
                data[1] = BGP_ATTR_NEXT_HOP;
                data[2] = BGP_ATTR_NHLEN_IPV4;
@@ -2758,7 +2751,6 @@ bgp_attr_srv6_service(struct bgp_attr_parser_args *args)
        uint16_t length, endpoint_behavior;
        size_t headersz = sizeof(type) + sizeof(length);
        enum bgp_attr_parse_ret err;
-       char buf[BUFSIZ];
 
        if (STREAM_READABLE(peer->curr) < headersz) {
                flog_err(
@@ -2789,12 +2781,11 @@ bgp_attr_srv6_service(struct bgp_attr_parser_args *args)
                stream_getc(peer->curr);
 
                /* Log SRv6 Service Sub-TLV */
-               if (BGP_DEBUG(vpn, VPN_LEAK_LABEL)) {
-                       inet_ntop(AF_INET6, &ipv6_sid, buf, sizeof(buf));
+               if (BGP_DEBUG(vpn, VPN_LEAK_LABEL))
                        zlog_debug(
-                               "%s: srv6-l3-srv sid %s, sid-flags 0x%02x, end-behaviour 0x%04x",
-                               __func__, buf, sid_flags, endpoint_behavior);
-               }
+                               "%s: srv6-l3-srv sid %pI6, sid-flags 0x%02x, end-behaviour 0x%04x",
+                               __func__, &ipv6_sid, sid_flags,
+                               endpoint_behavior);
 
                /* Configure from Info */
                if (attr->srv6_l3vpn) {
@@ -2855,7 +2846,6 @@ bgp_attr_psid_sub(uint8_t type, uint16_t length,
        uint32_t srgb_range;
        int srgb_count;
        uint8_t sid_type, sid_flags;
-       char buf[BUFSIZ];
 
        if (type == BGP_PREFIX_SID_LABEL_INDEX) {
                if (STREAM_READABLE(peer->curr) < length
@@ -2986,12 +2976,10 @@ bgp_attr_psid_sub(uint8_t type, uint16_t length,
                           sizeof(ipv6_sid)); /* sid_value */
 
                /* Log VPN-SID Sub-TLV */
-               if (BGP_DEBUG(vpn, VPN_LEAK_LABEL)) {
-                       inet_ntop(AF_INET6, &ipv6_sid, buf, sizeof(buf));
+               if (BGP_DEBUG(vpn, VPN_LEAK_LABEL))
                        zlog_debug(
-                               "%s: vpn-sid: sid %s, sid-type 0x%02x sid-flags 0x%02x",
-                               __func__, buf, sid_type, sid_flags);
-               }
+                               "%s: vpn-sid: sid %pI6, sid-type 0x%02x sid-flags 0x%02x",
+                               __func__, &ipv6_sid, sid_type, sid_flags);
 
                /* Configure from Info */
                if (attr->srv6_vpn) {
index 92a22d71b319220fb1943a3f9dbce3387499ba14..bfde1c127e1ec09aae6d34f74284c20f329b62f1 100644 (file)
@@ -378,8 +378,6 @@ bool bgp_debug_peer_updout_enabled(char *host)
 /* Dump attribute. */
 bool bgp_dump_attr(struct attr *attr, char *buf, size_t size)
 {
-       char addrbuf[BUFSIZ];
-
        if (!attr)
                return false;
 
@@ -395,15 +393,12 @@ bool bgp_dump_attr(struct attr *attr, char *buf, size_t size)
        /* Add MP case. */
        if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL
            || attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
-               snprintf(buf + strlen(buf), size - strlen(buf),
-                        ", mp_nexthop %s",
-                        inet_ntop(AF_INET6, &attr->mp_nexthop_global, addrbuf,
-                                  BUFSIZ));
+               snprintfrr(buf + strlen(buf), size - strlen(buf),
+                          ", mp_nexthop %pI6", &attr->mp_nexthop_global);
 
        if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
-               snprintf(buf + strlen(buf), size - strlen(buf), "(%s)",
-                        inet_ntop(AF_INET6, &attr->mp_nexthop_local, addrbuf,
-                                  BUFSIZ));
+               snprintfrr(buf + strlen(buf), size - strlen(buf), "(%pI6)",
+                          &attr->mp_nexthop_local);
 
        if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4)
                snprintfrr(buf, size, "nexthop %pI4", &attr->nexthop);
index 589d9af1e5efb0610761bf85ae39eacb0c4c9313..62fba1f58ec20770192398aec3354df71149fb43 100644 (file)
@@ -988,13 +988,8 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
                                    type == ECOMMUNITY_ENCODE_IP) {
                                        struct in_addr *ipv4 =
                                                (struct in_addr *)pnt;
-                                       char ipv4str[INET_ADDRSTRLEN];
-
-                                       inet_ntop(AF_INET, ipv4,
-                                                 ipv4str,
-                                                 INET_ADDRSTRLEN);
-                                       snprintf(encbuf, sizeof(encbuf),
-                                                "NH:%s:%d", ipv4str, pnt[5]);
+                                       snprintfrr(encbuf, sizeof(encbuf),
+                                                  "NH:%pI4:%d", ipv4, pnt[5]);
                                } else if (sub_type ==
                                           ECOMMUNITY_LINK_BANDWIDTH &&
                                           type == ECOMMUNITY_ENCODE_AS) {
index 2a5c5d7ec4b2b868e9b88054e3e5f74cc65ee9d2..77656dae34282d0111c24762eb7eb0509390a98b 100644 (file)
@@ -2435,7 +2435,7 @@ static char *bgp_evpn_es_vteps_str(char *vtep_str, struct bgp_evpn_es *es,
        struct listnode *node;
        struct bgp_evpn_es_vtep *es_vtep;
        bool first = true;
-       char ip_buf[INET6_ADDRSTRLEN];
+       char ip_buf[INET_ADDRSTRLEN];
 
        vtep_str[0] = '\0';
        for (ALL_LIST_ELEMENTS_RO(es->es_vtep_list, node, es_vtep)) {
@@ -3903,7 +3903,7 @@ static char *bgp_evpn_es_evi_vteps_str(char *vtep_str,
        struct listnode *node;
        struct bgp_evpn_es_evi_vtep *evi_vtep;
        bool first = true;
-       char ip_buf[INET6_ADDRSTRLEN];
+       char ip_buf[INET_ADDRSTRLEN];
 
        vtep_str[0] = '\0';
        for (ALL_LIST_ELEMENTS_RO(es_evi->es_evi_vtep_list, node, evi_vtep)) {
index 88c1329f48e0c342c96d2a4d3729c1861d8ae143..00545c96aebb88630597c06c1cacd528b4040dbd 100644 (file)
@@ -372,7 +372,6 @@ static void bgp_evpn_show_route_header(struct vty *vty, struct bgp *bgp,
 static void display_l3vni(struct vty *vty, struct bgp *bgp_vrf,
                          json_object *json)
 {
-       char buf1[INET6_ADDRSTRLEN];
        char *ecom_str;
        struct listnode *node, *nnode;
        struct vrf_route_target *l3rt;
@@ -419,9 +418,8 @@ static void display_l3vni(struct vty *vty, struct bgp *bgp_vrf,
                vty_out(vty, "  Advertise-svi-macip : %s\n", "n/a");
                vty_out(vty, "  Advertise-pip: %s\n",
                        bgp_vrf->evpn_info->advertise_pip ? "Yes" : "No");
-               vty_out(vty, "  System-IP: %s\n",
-                       inet_ntop(AF_INET, &bgp_vrf->evpn_info->pip_ip,
-                                 buf1, INET_ADDRSTRLEN));
+               vty_out(vty, "  System-IP: %pI4\n",
+                       &bgp_vrf->evpn_info->pip_ip);
                vty_out(vty, "  System-MAC: %s\n",
                                prefix_mac2str(&bgp_vrf->evpn_info->pip_rmac,
                                               buf2, sizeof(buf2)));
@@ -7071,8 +7069,6 @@ static int vni_cmp(const void **a, const void **b)
 void bgp_config_write_evpn_info(struct vty *vty, struct bgp *bgp, afi_t afi,
                                safi_t safi)
 {
-       char buf2[INET6_ADDRSTRLEN];
-
        if (bgp->advertise_all_vni)
                vty_out(vty, "  advertise-all-vni\n");
 
@@ -7217,10 +7213,8 @@ void bgp_config_write_evpn_info(struct vty *vty, struct bgp *bgp, afi_t afi,
                if (bgp->evpn_info->advertise_pip) {
                        if (bgp->evpn_info->pip_ip_static.s_addr
                            != INADDR_ANY) {
-                               vty_out(vty, "  advertise-pip ip %s",
-                                       inet_ntop(AF_INET,
-                                       &bgp->evpn_info->pip_ip_static,
-                                       buf2, INET_ADDRSTRLEN));
+                               vty_out(vty, "  advertise-pip ip %pI4",
+                                       &bgp->evpn_info->pip_ip_static);
                                if (!is_zero_mac(&(
                                            bgp->evpn_info->pip_rmac_static))) {
                                        char buf[ETHER_ADDR_STRLEN];
index 02dcdfcaa37abe1706dda486369bc23e281f5087..626e9803469bd662d326ae244fa8c0d8db4fbd5a 100644 (file)
@@ -338,18 +338,14 @@ void route_vty_out_flowspec(struct vty *vty, const struct prefix *p,
                        local_buff[0] = '\0';
                        if (p->u.prefix_flowspec.family == AF_INET
                            && attr->nexthop.s_addr != INADDR_ANY)
-                               inet_ntop(AF_INET,
-                                         &attr->nexthop.s_addr,
-                                         local_buff,
-                                         INET6_ADDRSTRLEN);
+                               inet_ntop(AF_INET, &attr->nexthop.s_addr,
+                                         local_buff, sizeof(local_buff));
                        else if (p->u.prefix_flowspec.family == AF_INET6 &&
                                 attr->mp_nexthop_len != 0 &&
                                 attr->mp_nexthop_len != BGP_ATTR_NHLEN_IPV4 &&
                                 attr->mp_nexthop_len != BGP_ATTR_NHLEN_VPNV4)
-                               inet_ntop(AF_INET6,
-                                         &attr->mp_nexthop_global,
-                                         local_buff,
-                                         INET6_ADDRSTRLEN);
+                               inet_ntop(AF_INET6, &attr->mp_nexthop_global,
+                                         local_buff, sizeof(local_buff));
                        if (local_buff[0] != '\0')
                                vty_out(vty, "\tNLRI NH %s\n",
                                        local_buff);
index 075350cd2b8e8571faad871a42c7d0f9c5f4d9d1..25a4a1b521ae41b098e5c175133b8482356e6527 100644 (file)
@@ -768,28 +768,22 @@ static void bgp_show_nexthop_paths(struct vty *vty, struct bgp *bgp,
 static void bgp_show_nexthops_detail(struct vty *vty, struct bgp *bgp,
                                     struct bgp_nexthop_cache *bnc)
 {
-       char buf[PREFIX2STR_BUFFER];
        struct nexthop *nexthop;
 
        for (nexthop = bnc->nexthop; nexthop; nexthop = nexthop->next) {
                switch (nexthop->type) {
                case NEXTHOP_TYPE_IPV6:
-                       vty_out(vty, "  gate %s\n",
-                               inet_ntop(AF_INET6, &nexthop->gate.ipv6, buf,
-                                         sizeof(buf)));
+                       vty_out(vty, "  gate %pI6\n", &nexthop->gate.ipv6);
                        break;
                case NEXTHOP_TYPE_IPV6_IFINDEX:
-                       vty_out(vty, "  gate %s, if %s\n",
-                               inet_ntop(AF_INET6, &nexthop->gate.ipv6, buf,
-                                         sizeof(buf)),
+                       vty_out(vty, "  gate %pI6, if %s\n",
+                               &nexthop->gate.ipv6,
                                ifindex2ifname(bnc->ifindex ? bnc->ifindex
                                                            : nexthop->ifindex,
                                               bgp->vrf_id));
                        break;
                case NEXTHOP_TYPE_IPV4:
-                       vty_out(vty, "  gate %s\n",
-                               inet_ntop(AF_INET, &nexthop->gate.ipv4, buf,
-                                         sizeof(buf)));
+                       vty_out(vty, "  gate %pI4\n", &nexthop->gate.ipv4);
                        break;
                case NEXTHOP_TYPE_IFINDEX:
                        vty_out(vty, "  if %s\n",
@@ -798,9 +792,8 @@ static void bgp_show_nexthops_detail(struct vty *vty, struct bgp *bgp,
                                               bgp->vrf_id));
                        break;
                case NEXTHOP_TYPE_IPV4_IFINDEX:
-                       vty_out(vty, "  gate %s, if %s\n",
-                               inet_ntop(AF_INET, &nexthop->gate.ipv4, buf,
-                                         sizeof(buf)),
+                       vty_out(vty, "  gate %pI4, if %s\n",
+                               &nexthop->gate.ipv4,
                                ifindex2ifname(bnc->ifindex ? bnc->ifindex
                                                            : nexthop->ifindex,
                                               bgp->vrf_id));
index b71e19ab330f7ae0b6321448aed9201fcf1fe207..807c4cd5a4a190f4257c9949d5eac344a0e13da4 100644 (file)
@@ -1636,9 +1636,8 @@ void bgp_pbr_print_policy_route(struct bgp_pbr_entry_main *api)
                                ptr_ip = &api->actions[i].u.zr.redirect_ip_v4;
                        else
                                ptr_ip = &api->actions[i].u.zr.redirect_ip_v6;
-                       if (inet_ntop(afi2family(api->afi),
-                                     ptr_ip, local_buff,
-                                     INET6_ADDRSTRLEN) != NULL) {
+                       if (inet_ntop(afi2family(api->afi), ptr_ip, local_buff,
+                                     sizeof(local_buff)) != NULL) {
                                delta = snprintf(ptr, len,
                                          "@redirect ip nh %s", local_buff);
                                len -= delta;
index d6e6fc952f568ba391b141de00843fe619b9ab24..a25ddfe294f9ab3a3c2eda7d97b29cf34c083d48 100644 (file)
@@ -4789,14 +4789,9 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
                    CHECK_FLAG(peer->flags, PEER_FLAG_IS_RFAPI_HD))
                        bgp_path_info_set_flag(dest, new, BGP_PATH_VALID);
                else {
-                       if (BGP_DEBUG(nht, NHT)) {
-                               char buf1[INET6_ADDRSTRLEN];
-                               inet_ntop(AF_INET,
-                                         (const void *)&attr_new->nexthop,
-                                         buf1, INET6_ADDRSTRLEN);
-                               zlog_debug("%s(%s): NH unresolved", __func__,
-                                          buf1);
-                       }
+                       if (BGP_DEBUG(nht, NHT))
+                               zlog_debug("%s(%pI4): NH unresolved", __func__,
+                                          &attr_new->nexthop);
                        bgp_path_info_unset_flag(dest, new, BGP_PATH_VALID);
                }
        } else {
@@ -6296,7 +6291,7 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p,
                                                char buf1[INET6_ADDRSTRLEN];
                                                inet_ntop(p->family,
                                                          &p->u.prefix, buf1,
-                                                         INET6_ADDRSTRLEN);
+                                                         sizeof(buf1));
                                                zlog_debug(
                                                        "%s(%s): Route not in table, not advertising",
                                                        __func__, buf1);
@@ -6346,8 +6341,9 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p,
                else {
                        if (BGP_DEBUG(nht, NHT)) {
                                char buf1[INET6_ADDRSTRLEN];
+
                                inet_ntop(p->family, &p->u.prefix, buf1,
-                                         INET6_ADDRSTRLEN);
+                                         sizeof(buf1));
                                zlog_debug(
                                        "%s(%s): Route not in table, not advertising",
                                        __func__, buf1);
@@ -8910,7 +8906,7 @@ static void route_vty_out_route(struct bgp_dest *dest, const struct prefix *p,
                                struct vty *vty, json_object *json, bool wide)
 {
        int len = 0;
-       char buf[BUFSIZ];
+       char buf[INET6_ADDRSTRLEN];
 
        if (p->family == AF_INET) {
                if (!json) {
@@ -8919,7 +8915,7 @@ static void route_vty_out_route(struct bgp_dest *dest, const struct prefix *p,
                        json_object_string_add(json, "prefix",
                                               inet_ntop(p->family,
                                                         &p->u.prefix, buf,
-                                                        BUFSIZ));
+                                                        sizeof(buf)));
                        json_object_int_add(json, "prefixLen", p->prefixlen);
                        json_object_string_addf(json, "network", "%pFX", p);
                        json_object_int_add(json, "version", dest->version);
@@ -8941,9 +8937,9 @@ static void route_vty_out_route(struct bgp_dest *dest, const struct prefix *p,
                        len = vty_out(vty, "%pFX", p);
                else {
                        json_object_string_add(json, "prefix",
-                                               inet_ntop(p->family,
-                                                       &p->u.prefix, buf,
-                                                       BUFSIZ));
+                                              inet_ntop(p->family,
+                                                        &p->u.prefix, buf,
+                                                        sizeof(buf)));
                        json_object_int_add(json, "prefixLen", p->prefixlen);
                        json_object_string_addf(json, "network", "%pFX", p);
                        json_object_int_add(json, "version", dest->version);
@@ -9212,20 +9208,17 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
         * attr->mp_nexthop_global_in
         */
        if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
-               char buf[BUFSIZ];
                char nexthop[128];
                int af = NEXTHOP_FAMILY(attr->mp_nexthop_len);
 
                switch (af) {
                case AF_INET:
-                       snprintf(nexthop, sizeof(nexthop), "%s",
-                                inet_ntop(af, &attr->mp_nexthop_global_in, buf,
-                                          BUFSIZ));
+                       snprintfrr(nexthop, sizeof(nexthop), "%pI4",
+                                  &attr->mp_nexthop_global_in);
                        break;
                case AF_INET6:
-                       snprintf(nexthop, sizeof(nexthop), "%s",
-                                inet_ntop(af, &attr->mp_nexthop_global, buf,
-                                          BUFSIZ));
+                       snprintfrr(nexthop, sizeof(nexthop), "%pI6",
+                                  &attr->mp_nexthop_global);
                        break;
                default:
                        snprintf(nexthop, sizeof(nexthop), "?");
@@ -9696,13 +9689,8 @@ void route_vty_out_tmp(struct vty *vty, struct bgp_dest *dest,
                                        vty_out(vty, "%-16pI4", &attr->nexthop);
                        } else if (p->family == AF_INET6 ||
                                   BGP_ATTR_MP_NEXTHOP_LEN_IP6(attr)) {
-                               char buf[BUFSIZ];
-
-                               len = vty_out(
-                                       vty, "%s",
-                                       inet_ntop(AF_INET6,
-                                                 &attr->mp_nexthop_global, buf,
-                                                 BUFSIZ));
+                               len = vty_out(vty, "%pI6",
+                                             &attr->mp_nexthop_global);
                                len = wide ? (41 - len) : (16 - len);
                                if (len < 1)
                                        vty_out(vty, "\n%*s", 36, " ");
@@ -10216,7 +10204,6 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
                          json_object *json_paths)
 {
        char buf[INET6_ADDRSTRLEN];
-       char buf1[BUFSIZ];
        char tag_buf[30];
        struct attr *attr = path->attr;
        time_t tbuf;
@@ -10596,10 +10583,7 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
                        if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
                                vty_out(vty, " (%pI4)", &attr->originator_id);
                        else
-                               vty_out(vty, " (%s)",
-                                       inet_ntop(AF_INET,
-                                                 &path->peer->remote_id, buf1,
-                                                 sizeof(buf1)));
+                               vty_out(vty, " (%pI4)", &path->peer->remote_id);
                }
        }
 
@@ -11012,11 +10996,12 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
 
        /* Remote SID */
        if (path->extra && path->extra->num_sids > 0 && safi != SAFI_EVPN) {
-               inet_ntop(AF_INET6, &path->extra->sid[0].sid, buf, sizeof(buf));
                if (json_paths)
-                       json_object_string_add(json_path, "remoteSid", buf);
+                       json_object_string_addf(json_path, "remoteSid", "%pI6",
+                                               &path->extra->sid[0].sid);
                else
-                       vty_out(vty, "      Remote SID: %s\n", buf);
+                       vty_out(vty, "      Remote SID: %pI6\n",
+                               &path->extra->sid[0].sid);
        }
 
        /* Label Index */
@@ -15517,13 +15502,15 @@ static void bgp_config_write_network_evpn(struct vty *vty, struct bgp *bgp,
                        /* "network" configuration display.  */
                        if (p->u.prefix_evpn.route_type == 5) {
                                char local_buf[PREFIX_STRLEN];
+
                                uint8_t family = is_evpn_prefix_ipaddr_v4((
                                                         struct prefix_evpn *)p)
                                                         ? AF_INET
                                                         : AF_INET6;
                                inet_ntop(family,
-                                         &p->u.prefix_evpn.prefix_addr.ip.ip.addr,
-                                         local_buf, PREFIX_STRLEN);
+                                         &p->u.prefix_evpn.prefix_addr.ip.ip
+                                                  .addr,
+                                         local_buf, sizeof(local_buf));
                                snprintf(buf, sizeof(buf), "%s/%u", local_buf,
                                         p->u.prefix_evpn.prefix_addr
                                                 .ip_prefix_length);
index 03f6eb03165a877500c594fee008dc37547aa2b5..1ce2eb435266a6bab6b219887bd3851a88fa80cd 100644 (file)
@@ -4145,7 +4145,7 @@ static void bgp_route_map_process_update(struct bgp *bgp, const char *rmap_name,
                                                safi2str(safi),
                                                inet_ntop(bn_p->family,
                                                          &bn_p->u.prefix, buf,
-                                                         INET6_ADDRSTRLEN));
+                                                         sizeof(buf)));
                                bgp_static_update(bgp, bn_p, bgp_static, afi,
                                                  safi);
                        }
@@ -4197,7 +4197,7 @@ static void bgp_route_map_process_update(struct bgp *bgp, const char *rmap_name,
                                                safi2str(safi),
                                                inet_ntop(bn_p->family,
                                                          &bn_p->u.prefix, buf,
-                                                         INET6_ADDRSTRLEN));
+                                                         sizeof(buf)));
                                bgp_aggregate_route(bgp, bn_p, afi, safi,
                                                    aggregate);
                        }
index 4b17d289684c2ad146e770bda0f814f35b9b5403..80c1980a56e79e99057d7b2dfac134282d8b44fe 100644 (file)
@@ -9884,7 +9884,6 @@ DEFPY (show_bgp_srv6,
        struct listnode *node;
        struct srv6_locator_chunk *chunk;
        struct bgp_srv6_function *func;
-       char buf[256];
 
        bgp = bgp_get_default();
        if (!bgp)
@@ -9903,8 +9902,7 @@ DEFPY (show_bgp_srv6,
 
        vty_out(vty, "functions:\n");
        for (ALL_LIST_ELEMENTS_RO(bgp->srv6_functions, node, func)) {
-               inet_ntop(AF_INET6, &func->sid, buf, sizeof(buf));
-               vty_out(vty, "- sid: %s\n", buf);
+               vty_out(vty, "- sid: %pI6\n", &func->sid);
                vty_out(vty, "  locator: %s\n", func->locator_name);
        }
 
@@ -12850,7 +12848,6 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
                          json_object *json)
 {
        struct bgp *bgp;
-       char buf1[PREFIX2STR_BUFFER];
        char timebuf[BGP_UPTIME_LEN];
        char dn_flag[2];
        afi_t afi;
@@ -13174,11 +13171,8 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
 
                /* BGP Version. */
                vty_out(vty, "  BGP version 4");
-               vty_out(vty, ", remote router ID %s",
-                       inet_ntop(AF_INET, &p->remote_id, buf1, sizeof(buf1)));
-               vty_out(vty, ", local router ID %s\n",
-                       inet_ntop(AF_INET, &bgp->router_id, buf1,
-                                       sizeof(buf1)));
+               vty_out(vty, ", remote router ID %pI4", &p->remote_id);
+               vty_out(vty, ", local router ID %pI4\n", &bgp->router_id);
 
                /* Confederation */
                if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
@@ -14548,15 +14542,11 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, bool use_json,
                                                       "bgpConnection",
                                                       "nonSharedNetwork");
                } else {
-                       vty_out(vty, "Nexthop: %s\n",
-                               inet_ntop(AF_INET, &p->nexthop.v4, buf1,
-                                         sizeof(buf1)));
-                       vty_out(vty, "Nexthop global: %s\n",
-                               inet_ntop(AF_INET6, &p->nexthop.v6_global, buf1,
-                                         sizeof(buf1)));
-                       vty_out(vty, "Nexthop local: %s\n",
-                               inet_ntop(AF_INET6, &p->nexthop.v6_local, buf1,
-                                         sizeof(buf1)));
+                       vty_out(vty, "Nexthop: %pI4\n", &p->nexthop.v4);
+                       vty_out(vty, "Nexthop global: %pI6\n",
+                               &p->nexthop.v6_global);
+                       vty_out(vty, "Nexthop local: %pI6\n",
+                               &p->nexthop.v6_local);
                        vty_out(vty, "BGP connection: %s\n",
                                p->shared_network ? "shared network"
                                                  : "non shared network");
index 2badc25cd8dc76cfbf4f0e70ca51a44ff11aabb6..5ab1a6afa6550df7b123fb200a4353e69c499ceb 100644 (file)
@@ -3682,35 +3682,33 @@ void bgp_zebra_announce_default(struct bgp *bgp, struct nexthop *nh,
 
        /* redirect IP */
        if (afi == AFI_IP && nh->gate.ipv4.s_addr != INADDR_ANY) {
-               char buff[PREFIX_STRLEN];
-
                api_nh->vrf_id = nh->vrf_id;
                api_nh->gate.ipv4 = nh->gate.ipv4;
                api_nh->type = NEXTHOP_TYPE_IPV4;
 
-               inet_ntop(AF_INET, &(nh->gate.ipv4), buff, INET_ADDRSTRLEN);
                if (BGP_DEBUG(zebra, ZEBRA))
-                       zlog_debug("BGP: %s default route to %s table %d (redirect IP)",
-                                 announce ? "adding" : "withdrawing",
-                                 buff, table_id);
+                       zlog_debug(
+                               "BGP: %s default route to %pI4 table %d (redirect IP)",
+                               announce ? "adding" : "withdrawing",
+                               &nh->gate.ipv4, table_id);
+
                zclient_route_send(announce ? ZEBRA_ROUTE_ADD
                                   : ZEBRA_ROUTE_DELETE,
                                   zclient, &api);
        } else if (afi == AFI_IP6 &&
                   memcmp(&nh->gate.ipv6,
                          &in6addr_any, sizeof(struct in6_addr))) {
-               char buff[PREFIX_STRLEN];
-
                api_nh->vrf_id = nh->vrf_id;
                memcpy(&api_nh->gate.ipv6, &nh->gate.ipv6,
                       sizeof(struct in6_addr));
                api_nh->type = NEXTHOP_TYPE_IPV6;
 
-               inet_ntop(AF_INET6, &(nh->gate.ipv6), buff, INET_ADDRSTRLEN);
                if (BGP_DEBUG(zebra, ZEBRA))
-                       zlog_debug("BGP: %s default route to %s table %d (redirect IP)",
-                                 announce ? "adding" : "withdrawing",
-                                 buff, table_id);
+                       zlog_debug(
+                               "BGP: %s default route to %pI6 table %d (redirect IP)",
+                               announce ? "adding" : "withdrawing",
+                               &nh->gate.ipv6, table_id);
+
                zclient_route_send(announce ? ZEBRA_ROUTE_ADD
                                   : ZEBRA_ROUTE_DELETE,
                                   zclient, &api);
index a5d57748b71ac0592d5f7a8be804c4608613caa4..80d0b3e269d4cd663f3f1034acc2459fea4b1a4c 100644 (file)
@@ -1273,13 +1273,15 @@ static int rfapi_open_inner(struct rfapi_descriptor *rfd, struct bgp *bgp,
        }
 
        { /* base code assumes have valid host pointer */
-               char buf[BUFSIZ];
+               char buf[INET6_ADDRSTRLEN];
                buf[0] = 0;
 
                if (rfd->vn_addr.addr_family == AF_INET) {
-                       inet_ntop(AF_INET, &rfd->vn_addr.addr.v4, buf, BUFSIZ);
+                       inet_ntop(AF_INET, &rfd->vn_addr.addr.v4, buf,
+                                 sizeof(buf));
                } else if (rfd->vn_addr.addr_family == AF_INET6) {
-                       inet_ntop(AF_INET6, &rfd->vn_addr.addr.v6, buf, BUFSIZ);
+                       inet_ntop(AF_INET6, &rfd->vn_addr.addr.v6, buf,
+                                 sizeof(buf));
                }
                rfd->peer->host = XSTRDUP(MTYPE_BGP_PEER_HOST, buf);
        }
index 1dd623d3f3f21abb8d10bd08d4a6069c2f27b89b..2aae0bc6167260596e3a08961fb3f40d9addbc4d 100644 (file)
@@ -2908,7 +2908,8 @@ static void rfapiBgpInfoFilteredImportEncap(
 
        vnc_zlog_debug_verbose(
                "%s: entry: %s: prefix %s/%d", __func__, action_str,
-               inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen);
+               inet_ntop(p->family, &p->u.prefix, buf, sizeof(buf)),
+               p->prefixlen);
 
        memset(&p_firstbpi_old, 0, sizeof(p_firstbpi_old));
        memset(&p_firstbpi_new, 0, sizeof(p_firstbpi_new));
index 23f43fa7d3e66271010b3bd7146b362cc454b6f3..719d898e3c99d68d3d6ff141172be4b8a1b22b90 100644 (file)
@@ -411,9 +411,10 @@ void rfapi_vty_out_vncinfo(struct vty *vty, const struct prefix *p,
 
                if (!rfapiGetVncTunnelUnAddr(bpi->attr, &pfx_un)) {
                        char buf[BUFSIZ];
+
                        vty_out(vty, "UN=%s",
                                inet_ntop(pfx_un.family, pfx_un.u.val, buf,
-                                         BUFSIZ));
+                                         sizeof(buf)));
                }
        }
 
@@ -432,11 +433,7 @@ void rfapi_vty_out_vncinfo(struct vty *vty, const struct prefix *p,
                                decode_label(&bpi->extra->label[0]));
 
                if (bpi->extra->num_sids) {
-                       char buf[BUFSIZ];
-
-                       vty_out(vty, " sid=%s",
-                               inet_ntop(AF_INET6, &bpi->extra->sid[0].sid,
-                                         buf, sizeof(buf)));
+                       vty_out(vty, " sid=%pI6", &bpi->extra->sid[0].sid);
 
                        if (bpi->extra->sid[0].loc_block_len != 0) {
                                vty_out(vty, " sid_structure=[%d,%d,%d,%d]",
@@ -466,7 +463,6 @@ void rfapiPrintAttrPtrs(void *stream, struct attr *attr)
        const char *vty_newline;
        struct transit *transit;
        struct cluster_list *cluster;
-       char buf[BUFSIZ];
        struct ecommunity *ecomm;
        struct community *comm;
 
@@ -478,8 +474,7 @@ void rfapiPrintAttrPtrs(void *stream, struct attr *attr)
                return;
 
        /* IPv4 Nexthop */
-       inet_ntop(AF_INET, &attr->nexthop, buf, BUFSIZ);
-       fp(out, "  nexthop=%s%s", buf, HVTYNL);
+       fp(out, "  nexthop=%pI4%s", &attr->nexthop, HVTYNL);
 
        fp(out, "  aspath=%p, refcnt=%d%s", attr->aspath,
           (attr->aspath ? attr->aspath->refcnt : 0), HVTYNL);
@@ -571,15 +566,12 @@ void rfapiPrintBi(void *stream, struct bgp_path_info *bpi)
 
        /* Nexthop */
        if (af == AF_INET) {
-               r = snprintf(p, REMAIN, "%s",
-                            inet_ntop(AF_INET,
-                                      &bpi->attr->mp_nexthop_global_in, buf,
-                                      BUFSIZ));
+               r = snprintfrr(p, REMAIN, "%pI4",
+                              &bpi->attr->mp_nexthop_global_in);
                INCP;
        } else if (af == AF_INET6) {
-               r = snprintf(p, REMAIN, "%s",
-                            inet_ntop(AF_INET6, &bpi->attr->mp_nexthop_global,
-                                      buf, BUFSIZ));
+               r = snprintfrr(p, REMAIN, "%pI6",
+                              &bpi->attr->mp_nexthop_global);
                INCP;
        } else {
                r = snprintf(p, REMAIN, "?");
@@ -590,9 +582,9 @@ void rfapiPrintBi(void *stream, struct bgp_path_info *bpi)
         * VNC tunnel subtlv, if present, contains UN address
         */
        if (!rfapiGetVncTunnelUnAddr(bpi->attr, &pfx_un)) {
-               r = snprintf(
-                       p, REMAIN, " un=%s",
-                       inet_ntop(pfx_un.family, pfx_un.u.val, buf, BUFSIZ));
+               r = snprintf(p, REMAIN, " un=%s",
+                            inet_ntop(pfx_un.family, pfx_un.u.val, buf,
+                                      sizeof(buf)));
                INCP;
        }
 
@@ -719,7 +711,8 @@ char *rfapiMonitorVpn2Str(struct rfapi_monitor_vpn *m, char *buf, int size)
        rc = snprintf(buf, size,
                      "m=%p, next=%p, rfd=%p(vn=%s un=%s), p=%s/%d, node=%p", m,
                      m->next, m->rfd, buf_vn, buf_un,
-                     inet_ntop(m->p.family, &m->p.u.prefix, buf_pfx, BUFSIZ),
+                     inet_ntop(m->p.family, &m->p.u.prefix, buf_pfx,
+                               sizeof(buf_pfx)),
                      m->p.prefixlen, m->node);
        buf[size - 1] = 0;
        if (rc >= size)
@@ -800,9 +793,9 @@ void rfapiShowImportTable(void *stream, const char *label, struct agg_table *rt,
                const struct prefix *p = agg_node_get_prefix(rn);
 
                if (p->family == AF_ETHERNET) {
-                       rfapiEthAddr2Str(&p->u.prefix_eth, buf, BUFSIZ);
+                       rfapiEthAddr2Str(&p->u.prefix_eth, buf, sizeof(buf));
                } else {
-                       inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ);
+                       inet_ntop(p->family, &p->u.prefix, buf, sizeof(buf));
                }
 
                fp(out, "%s/%d @%p #%d%s", buf, p->prefixlen, rn,
@@ -933,7 +926,7 @@ int rfapiShowVncQueries(void *stream, struct prefix *pfx_match)
                                        buf_remain, BUFSIZ);
                                fp(out, " %-15s %-10s\n",
                                   inet_ntop(m->p.family, &m->p.u.prefix,
-                                            buf_pfx, BUFSIZ),
+                                            buf_pfx, sizeof(buf_pfx)),
                                   buf_remain);
                        }
                }
@@ -1052,9 +1045,10 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream,
         * Prefix
         */
        buf_pfx[0] = 0;
-       snprintf(buf_pfx, sizeof(buf_pfx), "%s/%d",
-                rfapi_ntop(p->family, &p->u.prefix, buf_ntop, BUFSIZ),
-                p->prefixlen);
+       snprintf(
+               buf_pfx, sizeof(buf_pfx), "%s/%d",
+               rfapi_ntop(p->family, &p->u.prefix, buf_ntop, sizeof(buf_ntop)),
+               p->prefixlen);
        buf_pfx[BUFSIZ - 1] = 0;
        nlines++;
 
@@ -1065,7 +1059,7 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream,
        if (!rfapiGetUnAddrOfVpnBi(bpi, &pfx_un)) {
                snprintf(buf_un, sizeof(buf_un), "%s",
                         inet_ntop(pfx_un.family, &pfx_un.u.prefix, buf_ntop,
-                                  BUFSIZ));
+                                  sizeof(buf_ntop)));
        }
 
        bgp_attr_extcom_tunnel_type(bpi->attr, &tun_type);
@@ -1079,7 +1073,7 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream,
                 */
                snprintf(buf_un, sizeof(buf_un), "%s",
                         inet_ntop(pfx_vn.family, &pfx_vn.u.prefix, buf_ntop,
-                                  BUFSIZ));
+                                  sizeof(buf_ntop)));
                if (bpi->extra) {
                        uint32_t l = decode_label(&bpi->extra->label[0]);
                        snprintf(buf_vn, sizeof(buf_vn), "Label: %d", l);
@@ -1090,7 +1084,7 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream,
        } else {
                snprintf(buf_vn, sizeof(buf_vn), "%s",
                         inet_ntop(pfx_vn.family, &pfx_vn.u.prefix, buf_ntop,
-                                  BUFSIZ));
+                                  sizeof(buf_ntop)));
        }
        buf_vn[BUFSIZ - 1] = 0;
        buf_un[BUFSIZ - 1] = 0;