]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/rfapi/rfapi_import.c
*: conform with COMMUNITY.md formatting rules, via 'make indent'
[mirror_frr.git] / bgpd / rfapi / rfapi_import.c
index 87c4509c49fae623fdcdb901aa5749187388077b..c7d64bf1edecb24efb780e66cf30785675ecf856 100644 (file)
@@ -41,6 +41,7 @@
 #include "bgpd/bgp_route.h"
 #include "bgpd/bgp_mplsvpn.h" /* prefix_rd2str() */
 #include "bgpd/bgp_vnc_types.h"
+#include "bgpd/bgp_rd.h"
 
 #include "bgpd/rfapi/rfapi.h"
 #include "bgpd/rfapi/bgp_rfapi_cfg.h"
@@ -520,7 +521,7 @@ static struct bgp_info *rfapiBgpInfoCreate(struct attr *attr, struct peer *peer,
                rfapi_time(&new->extra->vnc.import.create_time);
        }
        if (label)
-               encode_label(*label, &new->extra->label);
+               encode_label(*label, &new->extra->label[0]);
        new->type = type;
        new->sub_type = sub_type;
        new->peer = peer;
@@ -645,10 +646,9 @@ rfapiMonitorMoveShorter(struct route_node *original_vpn_node, int lockoffset)
 
 #if DEBUG_MONITOR_MOVE_SHORTER
        {
-               char buf[BUFSIZ];
+               char buf[PREFIX_STRLEN];
 
-               prefix2str(&original_vpn_node->p, buf, BUFSIZ);
-               buf[BUFSIZ - 1] = 0;
+               prefix2str(&original_vpn_node->p, buf, sizeof(buf));
                vnc_zlog_debug_verbose("%s: called with node pfx=%s", __func__,
                                       buf);
        }
@@ -779,10 +779,9 @@ rfapiMonitorMoveShorter(struct route_node *original_vpn_node, int lockoffset)
 
 #if DEBUG_MONITOR_MOVE_SHORTER
        {
-               char buf[BUFSIZ];
+               char buf[PREFIX_STRLEN];
 
-               prefix2str(&par->p, buf, BUFSIZ);
-               buf[BUFSIZ - 1] = 0;
+               prefix2str(&par->p, buf, sizeof(buf));
                vnc_zlog_debug_verbose("%s: moved to node pfx=%s", __func__,
                                       buf);
        }
@@ -1084,9 +1083,8 @@ int rfapiEcommunityGetEthernetTag(struct ecommunity *ecom, uint16_t *tag_id)
                                } else if (encode == ECOMMUNITY_ENCODE_AS) {
                                        as = (*p++ << 8);
                                        as |= (*p++);
-                                       p +=
-                                               2; /* skip next two, tag/vid
-                                                     always in lowest bytes */
+                                       p += 2; /* skip next two, tag/vid
+                                                  always in lowest bytes */
                                }
                                if (as == bgp->as) {
                                        *tag_id = *p++ << 8;
@@ -1222,8 +1220,7 @@ static int rfapiVpnBiSamePtUn(struct bgp_info *bi1, struct bgp_info *bi2)
 
        switch (pfx_un1.family) {
        case AF_INET:
-               if (!IPV4_ADDR_SAME(&pfx_un1.u.prefix4,
-                                   &pfx_un2.u.prefix4))
+               if (!IPV4_ADDR_SAME(&pfx_un1.u.prefix4, &pfx_un2.u.prefix4))
                        return 0;
                break;
        case AF_INET6:
@@ -1339,7 +1336,7 @@ rfapiRouteInfo2NextHopEntry(struct rfapi_ip_prefix *rprefix,
                vo->v.l2addr.local_nve_id = bi->extra->vnc.import.rd.val[1];
 
                /* label comes from MP_REACH_NLRI label */
-               vo->v.l2addr.label = decode_label(&bi->extra->label);
+               vo->v.l2addr.label = decode_label(&bi->extra->label[0]);
 
                new->vn_options = vo;
 
@@ -1594,10 +1591,9 @@ static int rfapiNhlAddNodeRoutes(
                }
                if (!skiplist_search(seen_nexthops, &pfx_vn, NULL)) {
 #if DEBUG_RETURNED_NHL
-                       char buf[BUFSIZ];
+                       char buf[PREFIX_STRLEN];
 
-                       prefix2str(&pfx_vn, buf, BUFSIZ);
-                       buf[BUFSIZ - 1] = 0; /* guarantee NUL-terminated */
+                       prefix2str(&pfx_vn, buf, sizeof(buf));
                        vnc_zlog_debug_verbose(
                                "%s: already put VN/nexthop %s, skip", __func__,
                                buf);
@@ -1760,10 +1756,9 @@ struct rfapi_next_hop_entry *rfapiRouteNode2NextHopList(
 
 #if DEBUG_RETURNED_NHL
        {
-               char buf[BUFSIZ];
+               char buf[PREFIX_STRLEN];
 
-               prefix2str(&rn->p, buf, BUFSIZ);
-               buf[BUFSIZ - 1] = 0;
+               prefix2str(&rn->p, buf, sizeof(buf));
                vnc_zlog_debug_verbose("%s: called with node pfx=%s", __func__,
                                       buf);
        }
@@ -2136,10 +2131,12 @@ static void rfapiItBiIndexAdd(struct route_node *rn, /* Import table VPN node */
        assert(bi->extra);
 
        {
-               char buf[BUFSIZ];
-               prefix_rd2str(&bi->extra->vnc.import.rd, buf, BUFSIZ);
+               char buf[RD_ADDRSTRLEN];
+
                vnc_zlog_debug_verbose("%s: bi %p, peer %p, rd %s", __func__,
-                                      bi, bi->peer, buf);
+                                      bi, bi->peer,
+                                      prefix_rd2str(&bi->extra->vnc.import.rd,
+                                                    buf, sizeof(buf)));
        }
 
        sl = RFAPI_RDINDEX_W_ALLOC(rn);
@@ -2173,18 +2170,15 @@ static void rfapiItBiIndexDump(struct route_node *rn)
        for (rc = skiplist_next(sl, (void **)&k, (void **)&v, &cursor); !rc;
             rc = skiplist_next(sl, (void **)&k, (void **)&v, &cursor)) {
 
-               char buf[BUFSIZ];
-               char buf_aux_pfx[BUFSIZ];
+               char buf[RD_ADDRSTRLEN];
+               char buf_aux_pfx[PREFIX_STRLEN];
 
-               prefix_rd2str(&k->extra->vnc.import.rd, buf, BUFSIZ);
-               buf_aux_pfx[0] = 0;
+               prefix_rd2str(&k->extra->vnc.import.rd, buf, sizeof(buf));
                if (k->extra->vnc.import.aux_prefix.family) {
                        prefix2str(&k->extra->vnc.import.aux_prefix,
-                                  buf_aux_pfx, BUFSIZ);
-               } else {
-                       strncpy(buf_aux_pfx, "(none)", BUFSIZ);
-                       buf_aux_pfx[BUFSIZ - 1] = 0;
-               }
+                                  buf_aux_pfx, sizeof(buf_aux_pfx));
+               } else
+                       strncpy(buf_aux_pfx, "(none)", PREFIX_STRLEN);
 
                vnc_zlog_debug_verbose("bi %p, peer %p, rd %s, aux_prefix %s",
                                       k, k->peer, buf, buf_aux_pfx);
@@ -2208,19 +2202,19 @@ static struct bgp_info *rfapiItBiIndexSearch(
 
 #if DEBUG_BI_SEARCH
        {
-               char buf[BUFSIZ];
-               char buf_aux_pfx[BUFSIZ];
+               char buf[RD_ADDRSTRLEN];
+               char buf_aux_pfx[PREFIX_STRLEN];
 
-               prefix_rd2str(prd, buf, BUFSIZ);
                if (aux_prefix) {
-                       prefix2str(aux_prefix, buf_aux_pfx, BUFSIZ);
-               } else {
-                       strncpy(buf_aux_pfx, "(nil)", BUFSIZ - 1);
-                       buf_aux_pfx[BUFSIZ - 1] = 0;
-               }
+                       prefix2str(aux_prefix, buf_aux_pfx,
+                                  sizeof(buf_aux_pfx));
+               } else
+                       strncpy(buf_aux_pfx, "(nil)", sizeof(buf_aux_pfx));
 
                vnc_zlog_debug_verbose("%s want prd=%s, peer=%p, aux_prefix=%s",
-                                      __func__, buf, peer, buf_aux_pfx);
+                                      __func__,
+                                      prefix_rd2str(prd, buf, sizeof(buf)),
+                                      peer, buf_aux_pfx);
                rfapiItBiIndexDump(rn);
        }
 #endif
@@ -2235,12 +2229,14 @@ static struct bgp_info *rfapiItBiIndexSearch(
                     bi_result = bi_result->next) {
 #if DEBUG_BI_SEARCH
                        {
-                               char buf[BUFSIZ];
-                               prefix_rd2str(&bi_result->extra->vnc.import.rd,
-                                             buf, BUFSIZ);
+                               char buf[RD_ADDRSTRLEN];
+
                                vnc_zlog_debug_verbose(
                                        "%s: bi has prd=%s, peer=%p", __func__,
-                                       buf, bi_result->peer);
+                                       prefix_rd2str(&bi_result->extra->vnc
+                                                              .import.rd,
+                                                     buf, sizeof(buf)),
+                                       bi_result->peer);
                        }
 #endif
                        if (peer == bi_result->peer
@@ -2303,10 +2299,12 @@ static void rfapiItBiIndexDel(struct route_node *rn, /* Import table VPN node */
        int rc;
 
        {
-               char buf[BUFSIZ];
-               prefix_rd2str(&bi->extra->vnc.import.rd, buf, BUFSIZ);
+               char buf[RD_ADDRSTRLEN];
+
                vnc_zlog_debug_verbose("%s: bi %p, peer %p, rd %s", __func__,
-                                      bi, bi->peer, buf);
+                                      bi, bi->peer,
+                                      prefix_rd2str(&bi->extra->vnc.import.rd,
+                                                    buf, sizeof(buf)));
        }
 
        sl = RFAPI_RDINDEX(rn);
@@ -3671,9 +3669,9 @@ void rfapiBgpInfoFilteredImportVPN(
                rfapiCopyUnEncap2VPN(ern->info, info_new);
                route_unlock_node(ern); /* undo lock in route_note_match */
        } else {
-               char buf[BUFSIZ];
+               char buf[PREFIX_STRLEN];
+
                prefix2str(&vn_prefix, buf, sizeof(buf));
-               buf[BUFSIZ - 1] = 0;
                /* Not a big deal, just means VPN route got here first */
                vnc_zlog_debug_verbose("%s: no encap route for vn addr %s",
                                       __func__, buf);
@@ -4242,7 +4240,7 @@ static void rfapiBgpTableFilteredImport(struct bgp *bgp,
 
                                        if (bi->extra)
                                                label = decode_label(
-                                                       &bi->extra->label);
+                                                       &bi->extra->label[0]);
                                        (*rfapiBgpInfoFilteredImportFunction(
                                                safi))(
                                                it, /* which import table */
@@ -4433,10 +4431,10 @@ static void rfapiDeleteRemotePrefixesIt(
 
 #if DEBUG_L2_EXTRA
        {
-               char buf_pfx[BUFSIZ];
+               char buf_pfx[PREFIX_STRLEN];
 
                if (p) {
-                       prefix2str(p, buf_pfx, BUFSIZ);
+                       prefix2str(p, buf_pfx, sizeof(buf_pfx));
                } else {
                        buf_pfx[0] = '*';
                        buf_pfx[1] = 0;
@@ -4469,11 +4467,11 @@ static void rfapiDeleteRemotePrefixesIt(
                        struct bgp_info *next;
 
                        if (VNC_DEBUG(IMPORT_DEL_REMOTE)) {
-                               char p1line[BUFSIZ];
-                               char p2line[BUFSIZ];
+                               char p1line[PREFIX_STRLEN];
+                               char p2line[PREFIX_STRLEN];
 
-                               prefix2str(p, p1line, BUFSIZ);
-                               prefix2str(&rn->p, p2line, BUFSIZ);
+                               prefix2str(p, p1line, sizeof(p1line));
+                               prefix2str(&rn->p, p2line, sizeof(p2line));
                                vnc_zlog_debug_any("%s: want %s, have %s",
                                                   __func__, p1line, p2line);
                        }
@@ -4482,8 +4480,9 @@ static void rfapiDeleteRemotePrefixesIt(
                                continue;
 
                        {
-                               char buf_pfx[BUFSIZ];
-                               prefix2str(&rn->p, buf_pfx, BUFSIZ);
+                               char buf_pfx[PREFIX_STRLEN];
+
+                               prefix2str(&rn->p, buf_pfx, sizeof(buf_pfx));
                                vnc_zlog_debug_verbose("%s: rn pfx=%s",
                                                       __func__, buf_pfx);
                        }