]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: Save the zvrf in a zvrf_list
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 4 May 2016 00:17:29 +0000 (20:17 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 6 May 2016 14:41:29 +0000 (10:41 -0400)
The zebra vrf needs to be saved in a
zvrf_list so that we can tell when
things start/stop correctly

Ticket: CM-10139
Signed-off-by: Don Slice <dslice@cumulusnetworks.com>
Signed-off-by: Donald Sharp <sharpd@cumulustnetworks.com>
Reviewed-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
zebra/zebra_vrf.c
zebra/zebra_vrf.h

index f76bc98190200d0fede4a460126a587c10d04834..04aa16f71b8c780f78db81186174667488774852 100644 (file)
@@ -31,6 +31,7 @@
 #include "zebra/router-id.h"
 
 extern struct zebra_t zebrad;
+struct list *zvrf_list;
 
 /* VRF information update. */
 static void
@@ -82,10 +83,20 @@ zebra_vrf_new (vrf_id_t vrf_id, const char *name, void **info)
 
   if (! zvrf)
     {
-      zvrf = zebra_vrf_alloc (vrf_id, name);
-      zvrf->zns = zebra_ns_lookup (NS_DEFAULT); /* Point to the global (single) NS */
-      *info = (void *)zvrf;
-      router_id_init (zvrf);
+      zvrf = zebra_vrf_list_lookup_by_name (name);
+      if (!zvrf)
+       {
+         zvrf = zebra_vrf_alloc (vrf_id, name);
+         zvrf->zns = zebra_ns_lookup (NS_DEFAULT); /* Point to the global (single) NS */
+         *info = (void *)zvrf;
+         router_id_init (zvrf);
+         listnode_add_sort (zvrf_list, zvrf);
+       }
+      else
+        {
+          *info = (void *)zvrf;
+         router_id_init (zvrf);
+        }
     }
 
   if (zvrf->vrf_id == VRF_UNKNOWN)
@@ -231,8 +242,9 @@ zebra_vrf_delete (vrf_id_t vrf_id, const char *name, void **info)
   list_delete_all_node (zvrf->rid_all_sorted_list);
   list_delete_all_node (zvrf->rid_lo_sorted_list);
 
-  XFREE (MTYPE_ZEBRA_VRF, zvrf);
+  zvrf->vrf_id = VRF_UNKNOWN;
 
+  *info = NULL;
   return 0;
 }
 
@@ -326,6 +338,22 @@ zebra_vrf_lookup (vrf_id_t vrf_id)
   return vrf_info_lookup (vrf_id);
 }
 
+/* Lookup the zvrf in the zvrf_list. */
+struct zebra_vrf *
+zebra_vrf_list_lookup_by_name (const char *name)
+{
+  struct listnode *node;
+  struct zebra_vrf *zvrf;
+
+  if (name)
+    for (ALL_LIST_ELEMENTS_RO (zvrf_list, node, zvrf))
+      {
+        if (strcmp(name, zvrf->name) == 0)
+          return zvrf;
+      }
+  return NULL;
+}
+
 /* Lookup the routing table in an enabled VRF. */
 struct route_table *
 zebra_vrf_table (afi_t afi, safi_t safi, vrf_id_t vrf_id)
@@ -399,5 +427,7 @@ zebra_vrf_init (void)
   vrf_add_hook (VRF_DISABLE_HOOK, zebra_vrf_disable);
   vrf_add_hook (VRF_DELETE_HOOK, zebra_vrf_delete);
 
+  zvrf_list = list_new ();
+
   vrf_init ();
 }
index 54f8bdc744b0fbe95a044b0d2a46822aed0774be..e9653410c6971bcbe57480bb3d45aa05a99c2c8b 100644 (file)
@@ -83,6 +83,7 @@ zebra_vrf_table_with_table_id (afi_t afi, safi_t safi,
 extern void zebra_vrf_static_route_interface_fixup (struct interface *ifp);
 extern void zebra_vrf_update_all (struct zserv *client);
 extern struct zebra_vrf *zebra_vrf_lookup (vrf_id_t vrf_id);
+extern struct zebra_vrf *zebra_vrf_list_lookup_by_name (const char *);
 extern struct zebra_vrf *zebra_vrf_alloc (vrf_id_t, const char *);
 extern struct route_table *zebra_vrf_table (afi_t, safi_t, vrf_id_t);
 extern struct route_table *zebra_vrf_static_table (afi_t, safi_t, struct zebra_vrf *zvrf);