]> git.proxmox.com Git - mirror_frr.git/commitdiff
*: Make assignment from RB_ROOT in while loop work better
authorDonald Sharp <sharpd@cumulusnetworks.com>
Sun, 18 Feb 2018 00:02:55 +0000 (19:02 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 23 Feb 2018 12:08:36 +0000 (07:08 -0500)
Fix up the assignment of the variable = RB_ROOT inside of
while loop patter we were using.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
15 files changed:
ldpd/interface.c
ldpd/l2vpn.c
ldpd/lde.c
ldpd/lde_lib.c
ldpd/ldp_vty_conf.c
ldpd/ldpd.c
ldpd/ldpe.c
ldpd/neighbor.c
lib/if.c
lib/ns.c
lib/vrf.c
pimd/pim_iface.c
pimd/pim_ifchannel.c
zebra/zebra_ns.c
zebra/zebra_pw.c

index bbcea9f553495904a1513279b8a9e750bbe29538..b25be43a5c398f244d15589403a2d723fa97f343 100644 (file)
@@ -306,8 +306,11 @@ if_reset(struct iface *iface, int af)
        ia = iface_af_get(iface, af);
        if_stop_hello_timer(ia);
 
-       while ((adj = RB_ROOT(ia_adj_head, &ia->adj_tree)) != NULL)
+       while (!RB_EMPTY(ia_adj_head, &ia->adj_tree)) {
+               adj = RB_ROOT(ia_adj_head, &ia->adj_tree);
+
                adj_del(adj, S_SHUTDOWN);
+       }
 
        /* try to cleanup */
        switch (af) {
index f638d6a65bbbbf4ef064272214603230ead2fcdb..1cfeae30927315d747ab027fbf70b21d668ec85b 100644 (file)
@@ -76,16 +76,21 @@ l2vpn_del(struct l2vpn *l2vpn)
        struct l2vpn_if         *lif;
        struct l2vpn_pw         *pw;
 
-       while ((lif = RB_ROOT(l2vpn_if_head, &l2vpn->if_tree)) != NULL) {
+       while (!RB_EMPTY(l2vpn_if_head, &l2vpn->if_tree)) {
+               lif = RB_ROOT(l2vpn_if_head, &l2vpn->if_tree);
+
                RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif);
                free(lif);
        }
-       while ((pw = RB_ROOT(l2vpn_pw_head, &l2vpn->pw_tree)) != NULL) {
+       while (!RB_EMPTY(l2vpn_pw_head, &l2vpn->pw_tree)) {
+               pw = RB_ROOT(l2vpn_pw_head, &l2vpn->pw_tree);
+
                RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw);
                free(pw);
        }
-       while ((pw = RB_ROOT(l2vpn_pw_head,
-           &l2vpn->pw_inactive_tree)) != NULL) {
+       while (!RB_EMPTY(l2vpn_pw_head, &l2vpn->pw_inactive_tree)) {
+               pw = RB_ROOT(l2vpn_pw_head, &l2vpn->pw_inactive_tree);
+
                RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
                free(pw);
        }
index a70b97d06b129c6b86fa2394ba235827af6f8c6c..5aa53fd39e01dbec2653b13dc513417b671719d1 100644 (file)
@@ -1324,8 +1324,11 @@ lde_nbr_clear(void)
 {
        struct lde_nbr  *ln;
 
-        while ((ln = RB_ROOT(nbr_tree, &lde_nbrs)) != NULL)
+       while (!RB_EMPTY(nbr_tree, &lde_nbrs)) {
+               ln = RB_ROOT(nbr_tree, &lde_nbrs);
+
                lde_nbr_del(ln);
+       }
 }
 
 static void
index 18c8c0a1229a31894ca97e5aef71015affa10500..28e455c7a58fc7009c64e6b96a0d9f76ed4d872d 100644 (file)
@@ -129,7 +129,9 @@ fec_clear(struct fec_tree *fh, void (*free_cb)(void *))
 {
        struct fec      *f;
 
-       while ((f = RB_ROOT(fec_tree, fh)) != NULL) {
+       while (!RB_EMPTY(fec_tree, fh)) {
+               f = RB_ROOT(fec_tree, fh);
+
                fec_remove(fh, f);
                free_cb(f);
        }
index 76c602afbb126b6ed05662d45d1cc3658f6880af..382b00688440d854285b66b10e0bd75479f5b87a 100644 (file)
@@ -1475,18 +1475,23 @@ l2vpn_del_api(struct ldpd_conf *conf, struct l2vpn *l2vpn)
        struct l2vpn_if         *lif;
        struct l2vpn_pw         *pw;
 
-       while ((lif = RB_ROOT(l2vpn_if_head, &l2vpn->if_tree)) != NULL) {
+       while (!RB_EMPTY(l2vpn_if_head, &l2vpn->if_tree)) {
+               lif = RB_ROOT(l2vpn_if_head, &l2vpn->if_tree);
+
                QOBJ_UNREG(lif);
                RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif);
                free(lif);
        }
-       while ((pw = RB_ROOT(l2vpn_pw_head, &l2vpn->pw_tree)) != NULL) {
+       while (!RB_EMPTY(l2vpn_pw_head, &l2vpn->pw_tree)) {
+               pw = RB_ROOT(l2vpn_pw_head, &l2vpn->pw_tree);
+
                QOBJ_UNREG(pw);
                RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw);
                free(pw);
        }
-       while ((pw = RB_ROOT(l2vpn_pw_head,
-           &l2vpn->pw_inactive_tree)) != NULL) {
+       while (!RB_EMPTY(l2vpn_pw_head, &l2vpn->pw_inactive_tree)) {
+               pw = RB_ROOT(l2vpn_pw_head, &l2vpn->pw_inactive_tree);
+
                QOBJ_UNREG(pw);
                RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
                free(pw);
index 12aeb1fff32afaa46f01a6b685fe9833e5dc4c0e..255febeb60344b676093a3eb6ad561e665940456 100644 (file)
@@ -1066,13 +1066,17 @@ ldp_config_reset_main(struct ldpd_conf *conf)
        struct iface            *iface;
        struct nbr_params       *nbrp;
 
-       while ((iface = RB_ROOT(iface_head, &conf->iface_tree)) != NULL) {
+       while (!RB_EMPTY(iface_head, &conf->iface_tree)) {
+               iface = RB_ROOT(iface_head, &conf->iface_tree);
+
                QOBJ_UNREG(iface);
                RB_REMOVE(iface_head, &conf->iface_tree, iface);
                free(iface);
        }
 
-       while ((nbrp = RB_ROOT(nbrp_head, &conf->nbrp_tree)) != NULL) {
+       while (!RB_EMPTY(nbrp_head, &conf->nbrp_tree)) {
+               nbrp = RB_ROOT(nbrp_head, &conf->nbrp_tree);
+
                QOBJ_UNREG(nbrp);
                RB_REMOVE(nbrp_head, &conf->nbrp_tree, nbrp);
                free(nbrp);
@@ -1128,20 +1132,25 @@ ldp_config_reset_l2vpns(struct ldpd_conf *conf)
        struct l2vpn_if         *lif;
        struct l2vpn_pw         *pw;
 
-       while ((l2vpn = RB_ROOT(l2vpn_head, &conf->l2vpn_tree)) != NULL) {
-               while ((lif = RB_ROOT(l2vpn_if_head,
-                   &l2vpn->if_tree)) != NULL) {
+       while (!RB_EMPTY(l2vpn_head, &conf->l2vpn_tree)) {
+               l2vpn = RB_ROOT(l2vpn_head, &conf->l2vpn_tree);
+               while (!RB_EMPTY(l2vpn_if_head, &l2vpn->if_tree)) {
+                       lif = RB_ROOT(l2vpn_if_head, &l2vpn->if_tree);
+
                        QOBJ_UNREG(lif);
                        RB_REMOVE(l2vpn_if_head, &l2vpn->if_tree, lif);
                        free(lif);
                }
-               while ((pw = RB_ROOT(l2vpn_pw_head, &l2vpn->pw_tree)) != NULL) {
+               while (!RB_EMPTY(l2vpn_pw_head, &l2vpn->pw_tree)) {
+                       pw = RB_ROOT(l2vpn_pw_head, &l2vpn->pw_tree);
+
                        QOBJ_UNREG(pw);
                        RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_tree, pw);
                        free(pw);
                }
-               while ((pw = RB_ROOT(l2vpn_pw_head,
-                   &l2vpn->pw_inactive_tree)) != NULL) {
+               while (!RB_EMPTY(l2vpn_pw_head, &l2vpn->pw_inactive_tree)) {
+                       pw = RB_ROOT(l2vpn_pw_head, &l2vpn->pw_inactive_tree);
+
                        QOBJ_UNREG(pw);
                        RB_REMOVE(l2vpn_pw_head, &l2vpn->pw_inactive_tree, pw);
                        free(pw);
@@ -1160,19 +1169,27 @@ ldp_clear_config(struct ldpd_conf *xconf)
        struct nbr_params       *nbrp;
        struct l2vpn            *l2vpn;
 
-       while ((iface = RB_ROOT(iface_head, &xconf->iface_tree)) != NULL) {
+       while (!RB_EMPTY(iface_head, &xconf->iface_tree)) {
+               iface = RB_ROOT(iface_head, &xconf->iface_tree);
+
                RB_REMOVE(iface_head, &xconf->iface_tree, iface);
                free(iface);
        }
-       while ((tnbr = RB_ROOT(tnbr_head, &xconf->tnbr_tree)) != NULL) {
+       while (!RB_EMPTY(tnbr_head, &xconf->tnbr_tree)) {
+               tnbr = RB_ROOT(tnbr_head, &xconf->tnbr_tree);
+
                RB_REMOVE(tnbr_head, &xconf->tnbr_tree, tnbr);
                free(tnbr);
        }
-       while ((nbrp = RB_ROOT(nbrp_head, &xconf->nbrp_tree)) != NULL) {
+       while (!RB_EMPTY(nbrp_head, &xconf->nbrp_tree)) {
+               nbrp = RB_ROOT(nbrp_head, &xconf->nbrp_tree);
+
                RB_REMOVE(nbrp_head, &xconf->nbrp_tree, nbrp);
                free(nbrp);
        }
-       while ((l2vpn = RB_ROOT(l2vpn_head, &xconf->l2vpn_tree)) != NULL) {
+       while (!RB_EMPTY(l2vpn_head, &xconf->l2vpn_tree)) {
+               l2vpn = RB_ROOT(l2vpn_head, &xconf->l2vpn_tree);
+
                RB_REMOVE(l2vpn_head, &xconf->l2vpn_tree, l2vpn);
                l2vpn_del(l2vpn);
        }
index 9d00bcd2b6a40eab0514eb6ff98ab38808902b8f..56af76d94eba7aa640f8b48497b9eced5c48bbb3 100644 (file)
@@ -219,8 +219,11 @@ ldpe_shutdown(void)
                assert(if_addr != LIST_FIRST(&global.addr_list));
                free(if_addr);
        }
-       while ((adj = RB_ROOT(global_adj_head, &global.adj_tree)) != NULL)
+       while (!RB_EMPTY(global_adj_head, &global.adj_tree)) {
+               adj = RB_ROOT(global_adj_head, &global.adj_tree);
+
                adj_del(adj, S_SHUTDOWN);
+       }
 
        /* clean up */
        if (iev_lde)
index 39860a185981d0492ed88466d60f2e176a249ce6..1c3f650dff3baede6f9fb730b862d3603106f1ad 100644 (file)
@@ -316,7 +316,9 @@ nbr_del(struct nbr *nbr)
        mapping_list_clr(&nbr->release_list);
        mapping_list_clr(&nbr->abortreq_list);
 
-       while ((adj = RB_ROOT(nbr_adj_head, &nbr->adj_tree)) != NULL) {
+       while (!RB_EMPTY(nbr_adj_head, &nbr->adj_tree)) {
+               adj = RB_ROOT(nbr_adj_head, &nbr->adj_tree);
+
                adj->nbr = NULL;
                RB_REMOVE(nbr_adj_head, &nbr->adj_tree, adj);
        }
index 7866ddb8c446ffa08711d59dc4ce7b1b69c87e32..12d123a8fae033867bc29a3c68e1383d6292b7d0 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -1064,7 +1064,7 @@ ifaddr_ipv4_lookup (struct in_addr *addr, ifindex_t ifindex)
       rn = route_node_lookup (ifaddr_ipv4_table, (struct prefix *) &p);
       if (! rn)
        return NULL;
-      
+
       ifp = rn->info;
       route_unlock_node (rn);
       return ifp;
@@ -1078,7 +1078,9 @@ void if_terminate(struct vrf *vrf)
 {
        struct interface *ifp;
 
-       while ((ifp = RB_ROOT(if_name_head, &vrf->ifaces_by_name)) != NULL) {
+       while (!RB_EMPTY(if_name_head, &vrf->ifaces_by_name)) {
+               ifp = RB_ROOT(if_name_head, &vrf->ifaces_by_name);
+
                if (ifp->node) {
                        ifp->node->info = NULL;
                        route_unlock_node(ifp->node);
index fdf93d074291b9413633a7c9dd5607b1c6d49a39..0b2a3bec78d42d18f8da949623b4f8cf9c505434 100644 (file)
--- a/lib/ns.c
+++ b/lib/ns.c
@@ -424,8 +424,11 @@ void ns_terminate(void)
 {
        struct ns *ns;
 
-       while ((ns = RB_ROOT(ns_head, &ns_tree)) != NULL)
+       while (!RB_EMPTY(ns_head, &ns_tree)) {
+               ns = RB_ROOT(ns_head, &ns_tree);
+
                ns_delete(ns);
+       }
 }
 
 /* Create a socket for the NS. */
index 2e15fa2f5c2c0c884b99cd6f2fdc0b68d3e1ab79..02946df2bc9b6cd82eae4f93c6a4fae4c92d20e2 100644 (file)
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -419,12 +419,17 @@ void vrf_terminate(void)
                zlog_debug("%s: Shutting down vrf subsystem",
                           __PRETTY_FUNCTION__);
 
-       while ((vrf = RB_ROOT(vrf_id_head, &vrfs_by_id)) != NULL) {
+       while (!RB_EMPTY(vrf_id_head, &vrfs_by_id)) {
+               vrf = RB_ROOT(vrf_id_head, &vrfs_by_id);
+
                /* Clear configured flag and invoke delete. */
                UNSET_FLAG(vrf->status, VRF_CONFIGURED);
                vrf_delete(vrf);
        }
-       while ((vrf = RB_ROOT(vrf_name_head, &vrfs_by_name)) != NULL) {
+
+       while (!RB_EMPTY(vrf_name_head, &vrfs_by_name)) {
+               vrf = RB_ROOT(vrf_name_head, &vrfs_by_name);
+
                /* Clear configured flag and invoke delete. */
                UNSET_FLAG(vrf->status, VRF_CONFIGURED);
                vrf_delete(vrf);
index f02cf7ed31c4555688646f64cb570e68268841cf..a807c69c600db53667835def78e2ab28f801cbf0 100644 (file)
@@ -85,9 +85,11 @@ static void *if_list_clean(struct pim_interface *pim_ifp)
        if (pim_ifp->sec_addr_list)
                list_delete_and_null(&pim_ifp->sec_addr_list);
 
-       while ((ch = RB_ROOT(pim_ifchannel_rb,
-                            &pim_ifp->ifchannel_rb)) != NULL)
+       while (!RB_EMPTY(pim_ifchannel_rb, &pim_ifp->ifchannel_rb)) {
+               ch = RB_ROOT(pim_ifchannel_rb, &pim_ifp->ifchannel_rb);
+
                pim_ifchannel_delete(ch);
+       }
 
        XFREE(MTYPE_PIM_INTERFACE, pim_ifp);
 
@@ -250,9 +252,11 @@ void pim_if_delete(struct interface *ifp)
        if (pim_ifp->boundary_oil_plist)
                XFREE(MTYPE_PIM_INTERFACE, pim_ifp->boundary_oil_plist);
 
-       while ((ch = RB_ROOT(pim_ifchannel_rb,
-                            &pim_ifp->ifchannel_rb)) != NULL)
+       while (!RB_EMPTY(pim_ifchannel_rb, &pim_ifp->ifchannel_rb)) {
+               ch = RB_ROOT(pim_ifchannel_rb, &pim_ifp->ifchannel_rb);
+
                pim_ifchannel_delete(ch);
+       }
 
        XFREE(MTYPE_PIM_INTERFACE, pim_ifp);
 
index 7d3b783adf63569ce3e6119edfa7dbfece5a7c38..4d564e504693720c16e54a4be626d4f5e9115796 100644 (file)
@@ -211,8 +211,9 @@ void pim_ifchannel_delete_all(struct interface *ifp)
        if (!pim_ifp)
                return;
 
-       while ((ch = RB_ROOT(pim_ifchannel_rb,
-                            &pim_ifp->ifchannel_rb)) != NULL) {
+       while (!RB_EMPTY(pim_ifchannel_rb, &pim_ifp->ifchannel_rb)) {
+               ch = RB_ROOT(pim_ifchannel_rb, &pim_ifp->ifchannel_rb);
+
                pim_ifchannel_delete(ch);
        }
 }
index ac724a3299bc715787ec6dd98be854b03976f6fe..e8bdadee509f88a686bb99dfb3033b19cd556eda 100644 (file)
@@ -77,13 +77,13 @@ int zebra_ns_enable(ns_id_t ns_id, void **info)
 struct route_table *zebra_ns_find_table(struct zebra_ns *zns,
                                        uint32_t tableid, afi_t afi)
 {
-       struct zebra_ns_tables finder;
-       struct zebra_ns_tables *znst;
+       struct zebra_ns_table finder;
+       struct zebra_ns_table *znst;
 
        memset(&finder, 0, sizeof(finder));
        finder.afi = afi;
        finder.tableid = tableid;
-       znst = RB_FIND(zebra_ns_tables_head, &zns->ns_tables, &finder);
+       znst = RB_FIND(zebra_ns_table_head, &zns->ns_tables, &finder);
 
        if (znst)
                return znst->table;
@@ -141,8 +141,9 @@ int zebra_ns_disable(ns_id_t ns_id, void **info)
        struct zebra_ns_table *znst;
        struct zebra_ns *zns = (struct zebra_ns *)(*info);
 
-       while ((znst = RB_ROOT(zebra_ns_table_head, &zns->ns_tables))
-              != NULL) {
+       while (!RB_EMPTY(zebra_ns_table_head, &zns->ns_tables)) {
+               znst = RB_ROOT(zebra_ns_table_head, &zns->ns_tables);
+
                RB_REMOVE(zebra_ns_table_head, &zns->ns_tables, znst);
                znst = zebra_ns_free_table(znst);
        }
index bbd01a759e9e71358fb78ccd842b76a496894b6e..96bee36be6eaba3de0e7c8b211f79b10b5ed8ebe 100644 (file)
@@ -294,8 +294,11 @@ void zebra_pw_exit(struct zebra_vrf *zvrf)
 {
        struct zebra_pw *pw;
 
-       while ((pw = RB_ROOT(zebra_pw_head, &zvrf->pseudowires)) != NULL)
+       while (!RB_EMPTY(zebra_pw_head, &zvrf->pseudowires)) {
+               pw = RB_ROOT(zebra_pw_head, &zvrf->pseudowires);
+
                zebra_pw_del(zvrf, pw);
+       }
 }
 
 DEFUN_NOSH (pseudowire_if,