]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: factorize bgp_table_cleanup()
authorLouis Scalbert <louis.scalbert@6wind.com>
Fri, 7 Feb 2025 10:27:13 +0000 (11:27 +0100)
committerLouis Scalbert <louis.scalbert@6wind.com>
Thu, 13 Feb 2025 14:59:06 +0000 (15:59 +0100)
Factorize bgp_table_cleanup(). Cosmetic change. It will help adding
AFI / SAFI in the future.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
bgpd/bgp_route.c

index 2cda03f81b23d98f543a8571105ee89ec99f3229..c125252c3466928f9497f32e59dd692a7a450155 100644 (file)
@@ -6719,58 +6719,28 @@ static void bgp_cleanup_table(struct bgp *bgp, struct bgp_table *table,
 /* Delete all kernel routes. */
 void bgp_cleanup_routes(struct bgp *bgp)
 {
+       safi_t safi;
        afi_t afi;
        struct bgp_dest *dest;
        struct bgp_table *table;
 
-       for (afi = AFI_IP; afi < AFI_MAX; ++afi) {
-               if (afi == AFI_L2VPN)
+       FOREACH_AFI_SAFI (afi, safi) {
+               if (safi != SAFI_MPLS_VPN && safi != SAFI_ENCAP && safi != SAFI_EVPN) {
+                       bgp_cleanup_table(bgp, bgp->rib[afi][safi], afi, safi);
                        continue;
-               bgp_cleanup_table(bgp, bgp->rib[afi][SAFI_UNICAST], afi,
-                                 SAFI_UNICAST);
+               }
+
                /*
                 * VPN and ENCAP and EVPN tables are two-level (RD is top level)
                 */
-               if (afi != AFI_L2VPN) {
-                       safi_t safi;
-                       safi = SAFI_MPLS_VPN;
-                       if (!IS_BGP_INSTANCE_HIDDEN(bgp)) {
-                               for (dest = bgp_table_top(bgp->rib[afi][safi]);
-                                    dest; dest = bgp_route_next(dest)) {
-                                       table = bgp_dest_get_bgp_table_info(
-                                               dest);
-                                       if (table != NULL) {
-                                               bgp_cleanup_table(bgp, table,
-                                                                 afi, safi);
-                                               bgp_table_finish(&table);
-                                               bgp_dest_set_bgp_table_info(dest,
-                                                                           NULL);
-                                               dest = bgp_dest_unlock_node(
-                                                       dest);
-                                               assert(dest);
-                                       }
-                               }
-                       }
-                       safi = SAFI_ENCAP;
-                       for (dest = bgp_table_top(bgp->rib[afi][safi]); dest;
-                            dest = bgp_route_next(dest)) {
-                               table = bgp_dest_get_bgp_table_info(dest);
-                               if (table != NULL) {
-                                       bgp_cleanup_table(bgp, table, afi, safi);
-                                       bgp_table_finish(&table);
-                                       bgp_dest_set_bgp_table_info(dest, NULL);
-                                       dest = bgp_dest_unlock_node(dest);
+               if (safi != SAFI_MPLS_VPN && IS_BGP_INSTANCE_HIDDEN(bgp))
+                       continue;
 
-                                       assert(dest);
-                               }
-                       }
-               }
-       }
-       for (dest = bgp_table_top(bgp->rib[AFI_L2VPN][SAFI_EVPN]); dest;
-            dest = bgp_route_next(dest)) {
-               table = bgp_dest_get_bgp_table_info(dest);
-               if (table != NULL) {
-                       bgp_cleanup_table(bgp, table, afi, SAFI_EVPN);
+               for (dest = bgp_table_top(bgp->rib[afi][safi]); dest; dest = bgp_route_next(dest)) {
+                       table = bgp_dest_get_bgp_table_info(dest);
+                       if (!table)
+                               continue;
+                       bgp_cleanup_table(bgp, table, afi, safi);
                        bgp_table_finish(&table);
                        bgp_dest_set_bgp_table_info(dest, NULL);
                        dest = bgp_dest_unlock_node(dest);