]> git.proxmox.com Git - mirror_frr.git/blobdiff - staticd/static_vrf.c
staticd: kill static_memory.h, use MTYPE_STATIC
[mirror_frr.git] / staticd / static_vrf.c
index abb64aad3f34b04641afe654c1f92b3eb6953ea5..ba1367b877f4175dc553e61ffc64f08b4693de23 100644 (file)
 #include "table.h"
 #include "srcdest_table.h"
 
-#include "static_memory.h"
 #include "static_vrf.h"
 #include "static_routes.h"
 #include "static_zebra.h"
 #include "static_vty.h"
 
-static void zebra_stable_node_cleanup(struct route_table *table,
-                                     struct route_node *node)
-{
-       struct static_route *si, *next;
-
-       if (node->info)
-               for (si = node->info; si; si = next) {
-                       next = si->next;
-                       XFREE(MTYPE_STATIC_ROUTE, si);
-               }
-}
+DEFINE_MTYPE_STATIC(STATIC, STATIC_RTABLE_INFO, "Static Route Table Info");
 
 static struct static_vrf *static_vrf_alloc(void)
 {
        struct route_table *table;
        struct static_vrf *svrf;
+       struct stable_info *info;
        safi_t safi;
        afi_t afi;
 
-       svrf = XCALLOC(MTYPE_TMP, sizeof(struct static_vrf));
+       svrf = XCALLOC(MTYPE_STATIC_RTABLE_INFO, sizeof(struct static_vrf));
 
        for (afi = AFI_IP; afi <= AFI_IP6; afi++) {
                for (safi = SAFI_UNICAST; safi <= SAFI_MULTICAST; safi++) {
@@ -57,6 +47,14 @@ static struct static_vrf *static_vrf_alloc(void)
                                table = srcdest_table_init();
                        else
                                table = route_table_init();
+
+                       info = XCALLOC(MTYPE_STATIC_RTABLE_INFO,
+                                      sizeof(struct stable_info));
+                       info->svrf = svrf;
+                       info->afi = afi;
+                       info->safi = safi;
+                       route_table_set_info(table, info);
+
                        table->cleanup = zebra_stable_node_cleanup;
                        svrf->stable[afi][safi] = table;
                }
@@ -81,12 +79,6 @@ static int static_vrf_enable(struct vrf *vrf)
 
        static_fixup_vrf_ids(vrf->info);
 
-       /*
-        * We may have static routes that are now possible to
-        * insert into the appropriate tables
-        */
-       static_config_install_delayed_routes(vrf->info);
-
        return 0;
 }
 
@@ -102,15 +94,19 @@ static int static_vrf_delete(struct vrf *vrf)
        struct static_vrf *svrf;
        safi_t safi;
        afi_t afi;
+       void *info;
 
        svrf = vrf->info;
        for (afi = AFI_IP; afi <= AFI_IP6; afi++) {
                for (safi = SAFI_UNICAST; safi <= SAFI_MULTICAST; safi++) {
                        table = svrf->stable[afi][safi];
+                       info = route_table_get_info(table);
                        route_table_finish(table);
+                       XFREE(MTYPE_STATIC_RTABLE_INFO, info);
                        svrf->stable[afi][safi] = NULL;
                }
        }
+       XFREE(MTYPE_STATIC_RTABLE_INFO, svrf);
        return 0;
 }
 
@@ -184,14 +180,12 @@ int static_vrf_has_config(struct static_vrf *svrf)
         * NOTE: This is a don't care for the default VRF, but we go through
         * the motions to keep things consistent.
         */
-       for (afi = AFI_IP; afi < AFI_MAX; afi++) {
-               for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) {
-                       table = svrf->stable[afi][safi];
-                       if (!table)
-                               continue;
-                       if (route_table_count(table))
-                               return 1;
-               }
+       FOREACH_AFI_SAFI (afi, safi) {
+               table = svrf->stable[afi][safi];
+               if (!table)
+                       continue;
+               if (route_table_count(table))
+                       return 1;
        }
 
        return 0;
@@ -204,3 +198,8 @@ void static_vrf_init(void)
 
        vrf_cmd_init(static_vrf_config_write, &static_privs);
 }
+
+void static_vrf_terminate(void)
+{
+       vrf_terminate();
+}