]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/rfapi/rfapi_rib.c
*: conform with COMMUNITY.md formatting rules, via 'make indent'
[mirror_frr.git] / bgpd / rfapi / rfapi_rib.c
index 0cf5c205a5ffdfab41d4c75dcde9876b0ffd5608..2a8a465b70bfdb47c9c5994a5b880c7d025cf525 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /*
@@ -208,7 +207,7 @@ void rfapiRibCheckCounts(
                }
        }
 
-       if (checkstats && bgp && bgp->rfapi) {
+       if (checkstats && bgp->rfapi) {
                if (t_pfx_active != bgp->rfapi->rib_prefix_count_total) {
                        vnc_zlog_debug_verbose(
                                "%s: actual total pfx count %u != running %u",
@@ -343,7 +342,7 @@ rfapiRibStartTimer(struct rfapi_descriptor *rfd, struct rfapi_info *ri,
 {
        struct thread *t = ri->timer;
        struct rfapi_rib_tcb *tcb = NULL;
-       char buf_prefix[BUFSIZ];
+       char buf_prefix[PREFIX_STRLEN];
 
        if (t) {
                tcb = t->arg;
@@ -364,11 +363,12 @@ rfapiRibStartTimer(struct rfapi_descriptor *rfd, struct rfapi_info *ri,
                UNSET_FLAG(tcb->flags, RFAPI_RIB_TCB_FLAG_DELETED);
        }
 
-       prefix2str(&rn->p, buf_prefix, BUFSIZ);
+       prefix2str(&rn->p, buf_prefix, sizeof(buf_prefix));
        vnc_zlog_debug_verbose("%s: rfd %p pfx %s life %u", __func__, rfd,
                               buf_prefix, ri->lifetime);
-       ri->timer = thread_add_timer(bm->master, rfapiRibExpireTimer, tcb,
-                                    ri->lifetime);
+       ri->timer = NULL;
+       thread_add_timer(bm->master, rfapiRibExpireTimer, tcb, ri->lifetime,
+                        &ri->timer);
        assert(ri->timer);
 }
 
@@ -510,13 +510,13 @@ void rfapiRibClear(struct rfapi_descriptor *rfd)
                                 */
                                if (pn->info) {
                                        if (pn->info != (void *)1) {
-                                               list_delete(
-                                                       (struct list
-                                                                *)(pn->info));
+                                               list_delete_and_null(
+                                                       (struct list *
+                                                                *)(&pn->info));
                                        }
                                        pn->info = NULL;
-                                       route_unlock_node(
-                                               pn); /* linklist or 1 deleted */
+                                       /* linklist or 1 deleted */
+                                       route_unlock_node(pn);
                                }
                        }
                }
@@ -628,8 +628,7 @@ static void rfapiRibBi2Ri(struct bgp_info *bi, struct rfapi_info *ri,
        ri->lifetime = lifetime;
 
        /* This loop based on rfapiRouteInfo2NextHopEntry() */
-       for (pEncap = bi->attr->extra->vnc_subtlvs; pEncap;
-            pEncap = pEncap->next) {
+       for (pEncap = bi->attr->vnc_subtlvs; pEncap; pEncap = pEncap->next) {
                struct bgp_tea_options *hop;
 
                switch (pEncap->type) {
@@ -688,22 +687,18 @@ static void rfapiRibBi2Ri(struct bgp_info *bi, struct rfapi_info *ri,
                /* copy from RD already stored in bi, so we don't need it_node
                 */
                memcpy(&vo->v.l2addr.macaddr, bi->extra->vnc.import.rd.val + 2,
-                      ETHER_ADDR_LEN);
-
-               if (bi->attr && bi->attr->extra) {
-                       (void)rfapiEcommunityGetLNI(
-                               bi->attr->extra->ecommunity,
-                               &vo->v.l2addr.logical_net_id);
-                       (void)rfapiEcommunityGetEthernetTag(
-                               bi->attr->extra->ecommunity,
-                               &vo->v.l2addr.tag_id);
-               }
+                      ETH_ALEN);
+
+               (void)rfapiEcommunityGetLNI(bi->attr->ecommunity,
+                                           &vo->v.l2addr.logical_net_id);
+               (void)rfapiEcommunityGetEthernetTag(bi->attr->ecommunity,
+                                                   &vo->v.l2addr.tag_id);
 
                /* local_nve_id comes from RD */
                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->tag);
+               vo->v.l2addr.label = decode_label(&bi->extra->label[0]);
 
                rfapi_vn_options_free(
                        ri->vn_options); /* maybe free old version */
@@ -713,7 +708,7 @@ static void rfapiRibBi2Ri(struct bgp_info *bi, struct rfapi_info *ri,
        /*
         * If there is an auxiliary IP address (L2 can have it), copy it
         */
-       if (bi && bi->extra && bi->extra->vnc.import.aux_prefix.family) {
+       if (bi->extra && bi->extra->vnc.import.aux_prefix.family) {
                ri->rk.aux_prefix = bi->extra->vnc.import.aux_prefix;
        }
 }
@@ -858,7 +853,7 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd,
        struct list *lPendCost = NULL;
        struct list *delete_list = NULL;
        int printedprefix = 0;
-       char buf_prefix[BUFSIZ];
+       char buf_prefix[PREFIX_STRLEN];
        int rib_node_started_nonempty = 0;
        int sendingsomeroutes = 0;
 
@@ -869,7 +864,7 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd,
 #endif
 
        assert(pn);
-       prefix2str(&pn->p, buf_prefix, BUFSIZ);
+       prefix2str(&pn->p, buf_prefix, sizeof(buf_prefix));
        vnc_zlog_debug_verbose("%s: afi=%d, %s pn->info=%p", __func__, afi,
                               buf_prefix, pn->info);
 
@@ -919,8 +914,8 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd,
                        while (0
                               == skiplist_first(slRibPt, NULL, (void **)&ri)) {
 
-                               char buf[BUFSIZ];
-                               char buf2[BUFSIZ];
+                               char buf[PREFIX_STRLEN];
+                               char buf2[PREFIX_STRLEN];
 
                                listnode_add(delete_list, ri);
                                vnc_zlog_debug_verbose(
@@ -938,8 +933,8 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd,
                                        ri->timer = NULL;
                                }
 
-                               prefix2str(&ri->rk.vn, buf, BUFSIZ);
-                               prefix2str(&ri->un, buf2, BUFSIZ);
+                               prefix2str(&ri->rk.vn, buf, sizeof(buf));
+                               prefix2str(&ri->un, buf2, sizeof(buf2));
                                vnc_zlog_debug_verbose(
                                        "%s:   put dl pfx=%s vn=%s un=%s cost=%d life=%d vn_options=%p",
                                        __func__, buf_prefix, buf, buf2,
@@ -1129,7 +1124,7 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd,
 
                        } else {
 
-                               char buf_rd[BUFSIZ];
+                               char buf_rd[RD_ADDRSTRLEN];
 
                                /* not found: add new route to RIB */
                                ori = rfapi_info_new();
@@ -1408,13 +1403,15 @@ callback:
                                        ri->last_sent_time = rfapi_time(NULL);
 #if DEBUG_RIB_SL_RD
                                        {
-                                               char buf_rd[BUFSIZ];
-                                               prefix_rd2str(&ri->rk.rd,
-                                                             buf_rd,
-                                                             sizeof(buf_rd));
+                                               char buf_rd[RD_ADDRSTRLEN];
+
                                                vnc_zlog_debug_verbose(
                                                        "%s: move route to recently deleted list, rd=%s",
-                                                       __func__, buf_rd);
+                                                       __func__,
+                                                       prefix_rd2str(
+                                                               &ri->rk.rd,
+                                                               buf_rd,
+                                                               sizeof(buf_rd)));
                                        }
 #endif
 
@@ -1437,7 +1434,7 @@ callback:
                }
 
                delete_list->del = (void (*)(void *))rfapi_info_free;
-               list_delete(delete_list);
+               list_delete_and_null(&delete_list);
        }
 
        RFAPI_RIB_CHECK_COUNTS(0, 0);
@@ -1452,7 +1449,7 @@ callback:
                route_unlock_node(pn);
        }
        if (lPendCost) {
-               list_delete(lPendCost);
+               list_delete_and_null(&lPendCost);
                pn->info = NULL;
                route_unlock_node(pn);
        }
@@ -1598,7 +1595,7 @@ void rfapiRibUpdatePendingNode(
        afi_t afi;
        uint32_t queued_flag;
        int count = 0;
-       char buf[BUFSIZ];
+       char buf[PREFIX_STRLEN];
 
        vnc_zlog_debug_verbose("%s: entry", __func__);
 
@@ -1611,7 +1608,7 @@ void rfapiRibUpdatePendingNode(
 
        prefix = &it_node->p;
        afi = family2afi(prefix->family);
-       prefix2str(prefix, buf, BUFSIZ);
+       prefix2str(prefix, buf, sizeof(buf));
        vnc_zlog_debug_verbose("%s: prefix=%s", __func__, buf);
 
        pn = route_node_get(rfd->rib_pending[afi], prefix);
@@ -1636,7 +1633,7 @@ void rfapiRibUpdatePendingNode(
         */
        if (pn->info) {
                if (pn->info != (void *)1) {
-                       list_delete((struct list *)(pn->info));
+                       list_delete_and_null((struct list **)(&pn->info));
                }
                pn->info = NULL;
                route_unlock_node(pn); /* linklist or 1 deleted */
@@ -1671,7 +1668,7 @@ void rfapiRibUpdatePendingNode(
 
                        struct prefix pfx_vn;
 
-                       rfapiRaddr2Qprefix(&rfd->vn_addr, &pfx_vn);
+                       assert(!rfapiRaddr2Qprefix(&rfd->vn_addr, &pfx_vn));
                        if (prefix_same(&pfx_vn, &pfx_nh))
                                continue;
                }
@@ -1766,6 +1763,8 @@ void rfapiRibUpdatePendingNodeSubtree(
        struct route_node *omit_subtree, /* may be NULL */
        uint32_t lifetime)
 {
+       /* FIXME: need to find a better way here to work without sticking our
+        * hands in node->link */
        if (it_node->l_left && (it_node->l_left != omit_subtree)) {
                if (it_node->l_left->info)
                        rfapiRibUpdatePendingNode(bgp, rfd, it, it_node->l_left,
@@ -1815,9 +1814,9 @@ int rfapiRibFTDFilterRecentPrefix(
 
 #if DEBUG_FTD_FILTER_RECENT
        {
-               char buf_pfx[BUFSIZ];
+               char buf_pfx[PREFIX_STRLEN];
 
-               prefix2str(&it_rn->p, buf_pfx, BUFSIZ);
+               prefix2str(&it_rn->p, buf_pfx, sizeof(buf_pfx));
                vnc_zlog_debug_verbose("%s: prefix %s", __func__, buf_pfx);
        }
 #endif
@@ -1979,14 +1978,15 @@ rfapiRibPreload(struct bgp *bgp, struct rfapi_descriptor *rfd,
 
 #if DEBUG_NHL
                {
-                       char str_vn[BUFSIZ];
-                       char str_aux_prefix[BUFSIZ];
+                       char str_vn[PREFIX_STRLEN];
+                       char str_aux_prefix[PREFIX_STRLEN];
 
                        str_vn[0] = 0;
                        str_aux_prefix[0] = 0;
 
-                       prefix2str(&rk.vn, str_vn, BUFSIZ);
-                       prefix2str(&rk.aux_prefix, str_aux_prefix, BUFSIZ);
+                       prefix2str(&rk.vn, str_vn, sizeof(str_vn));
+                       prefix2str(&rk.aux_prefix, str_aux_prefix,
+                                  sizeof(str_aux_prefix));
 
                        if (!rk.aux_prefix.family) {
                        }
@@ -2076,11 +2076,11 @@ rfapiRibPreload(struct bgp *bgp, struct rfapi_descriptor *rfd,
                        route_unlock_node(trn);
 
                {
-                       char str_pfx[BUFSIZ];
-                       char str_pfx_vn[BUFSIZ];
+                       char str_pfx[PREFIX_STRLEN];
+                       char str_pfx_vn[PREFIX_STRLEN];
 
-                       prefix2str(&pfx, str_pfx, BUFSIZ);
-                       prefix2str(&rk.vn, str_pfx_vn, BUFSIZ);
+                       prefix2str(&pfx, str_pfx, sizeof(str_pfx));
+                       prefix2str(&rk.vn, str_pfx_vn, sizeof(str_pfx_vn));
                        vnc_zlog_debug_verbose(
                                "%s:   added pfx=%s nh[vn]=%s, cost=%u, lifetime=%u, allowed=%d",
                                __func__, str_pfx, str_pfx_vn, nhp->prefix.cost,
@@ -2115,9 +2115,9 @@ void rfapiRibPendingDeleteRoute(struct bgp *bgp, struct rfapi_import_table *it,
 {
        struct rfapi_descriptor *rfd;
        struct listnode *node;
-       char buf[BUFSIZ];
+       char buf[PREFIX_STRLEN];
 
-       prefix2str(&it_node->p, buf, BUFSIZ);
+       prefix2str(&it_node->p, buf, sizeof(buf));
        vnc_zlog_debug_verbose("%s: entry, it=%p, afi=%d, it_node=%p, pfx=%s",
                               __func__, it, afi, it_node, buf);
 
@@ -2236,15 +2236,18 @@ void rfapiRibShowResponsesSummary(void *stream)
        struct rfapi_descriptor *rfd;
        struct listnode *node;
 
-
        if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0)
                return;
+       if (!bgp) {
+               fp(out, "Unable to find default BGP instance\n");
+               return;
+       }
 
        fp(out, "%-24s ", "Responses: (Prefixes)");
        fp(out, "%-8s %-8u ", "Active:", bgp->rfapi->rib_prefix_count_total);
        fp(out, "%-8s %-8u",
           "Maximum:", bgp->rfapi->rib_prefix_count_total_max);
-       fp(out, "%s", VTY_NEWLINE);
+       fp(out, "\n");
 
        fp(out, "%-24s ", "           (Updated)");
        fp(out, "%-8s %-8u ",
@@ -2254,7 +2257,7 @@ void rfapiRibShowResponsesSummary(void *stream)
        fp(out, "%-8s %-8u", "Total:",
           bgp->rfapi->stat.count_updated_response_updates
                   + bgp->rfapi->stat.count_updated_response_deletes);
-       fp(out, "%s", VTY_NEWLINE);
+       fp(out, "\n");
 
        fp(out, "%-24s ", "           (NVEs)");
        for (ALL_LIST_ELEMENTS_RO(&bgp->rfapi->descriptors, node, rfd)) {
@@ -2264,7 +2267,7 @@ void rfapiRibShowResponsesSummary(void *stream)
        }
        fp(out, "%-8s %-8u ", "Active:", nves_with_nonempty_ribs);
        fp(out, "%-8s %-8u", "Total:", nves);
-       fp(out, "%s", VTY_NEWLINE);
+       fp(out, "\n");
 }
 
 void rfapiRibShowResponsesSummaryClear(void)
@@ -2288,21 +2291,21 @@ static int print_rib_sl(int (*fp)(void *, const char *, ...), struct vty *vty,
        for (rc = skiplist_next(sl, NULL, (void **)&ri, &cursor); !rc;
             rc = skiplist_next(sl, NULL, (void **)&ri, &cursor)) {
 
-               char str_vn[BUFSIZ];
-               char str_un[BUFSIZ];
+               char str_vn[PREFIX_STRLEN];
+               char str_un[PREFIX_STRLEN];
                char str_lifetime[BUFSIZ];
                char str_age[BUFSIZ];
                char *p;
-               char str_rd[BUFSIZ];
+               char str_rd[RD_ADDRSTRLEN];
 
                ++routes_displayed;
 
-               prefix2str(&ri->rk.vn, str_vn, BUFSIZ);
+               prefix2str(&ri->rk.vn, str_vn, sizeof(str_vn));
                p = index(str_vn, '/');
                if (p)
                        *p = 0;
 
-               prefix2str(&ri->un, str_un, BUFSIZ);
+               prefix2str(&ri->un, str_un, sizeof(str_un));
                p = index(str_un, '/');
                if (p)
                        *p = 0;
@@ -2323,14 +2326,12 @@ static int print_rib_sl(int (*fp)(void *, const char *, ...), struct vty *vty,
 
                str_rd[0] = 0; /* start empty */
 #if DEBUG_RIB_SL_RD
-               str_rd[0] = ' ';
-               prefix_rd2str(&ri->rk.rd, str_rd + 1, BUFSIZ - 1);
+               prefix_rd2str(&ri->rk.rd, str_rd, sizeof(str_rd));
 #endif
 
-               fp(out, " %c %-20s %-15s %-15s %-4u %-8s %-8s%s%s",
+               fp(out, " %c %-20s %-15s %-15s %-4u %-8s %-8s %s\n",
                   deleted ? 'r' : ' ', *printedprefix ? "" : str_pfx, str_vn,
-                  str_un, ri->cost, str_lifetime, str_age, str_rd,
-                  VTY_NEWLINE);
+                  str_un, ri->cost, str_lifetime, str_age, str_rd);
 
                if (!*printedprefix)
                        *printedprefix = 1;
@@ -2351,13 +2352,13 @@ static void rfapiRibShowRibSl(void *stream, struct prefix *pfx,
        const char *vty_newline;
 
        int nhs_displayed = 0;
-       char str_pfx[BUFSIZ];
+       char str_pfx[PREFIX_STRLEN];
        int printedprefix = 0;
 
        if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0)
                return;
 
-       prefix2str(pfx, str_pfx, BUFSIZ);
+       prefix2str(pfx, str_pfx, sizeof(str_pfx));
 
        nhs_displayed +=
                print_rib_sl(fp, vty, out, sl, 0, str_pfx, &printedprefix);
@@ -2389,6 +2390,11 @@ void rfapiRibShowResponses(void *stream, struct prefix *pfx_match,
 
        if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0)
                return;
+       if (!bgp) {
+               fp(out, "Unable to find default BGP instance\n");
+               return;
+       }
+
        /*
         * loop over NVEs
         */
@@ -2412,7 +2418,7 @@ void rfapiRibShowResponses(void *stream, struct prefix *pfx_match,
                             rn = route_next(rn)) {
 
                                struct skiplist *sl;
-                               char str_pfx[BUFSIZ];
+                               char str_pfx[PREFIX_STRLEN];
                                int printedprefix = 0;
 
                                if (!show_removed)
@@ -2437,21 +2443,20 @@ void rfapiRibShowResponses(void *stream, struct prefix *pfx_match,
                                if (!printedheader) {
                                        ++printedheader;
 
-                                       fp(out, "%s[%s]%s", VTY_NEWLINE,
-                                          show_removed ? "Removed" : "Active",
-                                          VTY_NEWLINE);
-                                       fp(out, "%-15s %-15s%s", "Querying VN",
-                                          "Querying UN", VTY_NEWLINE);
+                                       fp(out, "\n[%s]\n",
+                                          show_removed ? "Removed" : "Active");
+                                       fp(out, "%-15s %-15s\n", "Querying VN",
+                                          "Querying UN");
                                        fp(out,
-                                          "   %-20s %-15s %-15s %4s %-8s %-8s%s",
+                                          "   %-20s %-15s %-15s %4s %-8s %-8s\n",
                                           "Prefix", "Registered VN",
                                           "Registered UN", "Cost", "Lifetime",
 #if RFAPI_REGISTRATIONS_REPORT_AGE
-                                          "Age",
+                                          "Age"
 #else
-                                          "Remaining",
+                                          "Remaining"
 #endif
-                                          VTY_NEWLINE);
+                                          );
                                }
                                if (!printednve) {
                                        char str_vn[BUFSIZ];
@@ -2460,16 +2465,15 @@ void rfapiRibShowResponses(void *stream, struct prefix *pfx_match,
                                        ++printednve;
                                        ++nves_displayed;
 
-                                       fp(out, "%-15s %-15s%s",
+                                       fp(out, "%-15s %-15s\n",
                                           rfapiRfapiIpAddr2Str(&rfd->vn_addr,
                                                                str_vn, BUFSIZ),
                                           rfapiRfapiIpAddr2Str(&rfd->un_addr,
-                                                               str_un, BUFSIZ),
-                                          VTY_NEWLINE);
+                                                               str_un,
+                                                               BUFSIZ));
                                }
-                               prefix2str(&rn->p, str_pfx, BUFSIZ);
-                               // fp(out, "  %s%s", buf, VTY_NEWLINE);  /*
-                               // prefix */
+                               prefix2str(&rn->p, str_pfx, sizeof(str_pfx));
+                               // fp(out, "  %s\n", buf);  /* prefix */
 
                                routes_displayed++;
                                nhs_displayed += print_rib_sl(
@@ -2480,7 +2484,7 @@ void rfapiRibShowResponses(void *stream, struct prefix *pfx_match,
        }
 
        if (routes_total) {
-               fp(out, "%s", VTY_NEWLINE);
+               fp(out, "\n");
                fp(out, "Displayed %u NVEs, and %u out of %u %s prefixes",
                   nves_displayed, routes_displayed, routes_total,
                   show_removed ? "removed" : "active");
@@ -2488,6 +2492,6 @@ void rfapiRibShowResponses(void *stream, struct prefix *pfx_match,
                    || nhs_total != routes_total)
                        fp(out, " with %u out of %u next hops", nhs_displayed,
                           nhs_total);
-               fp(out, "%s", VTY_NEWLINE);
+               fp(out, "\n");
        }
 }