]> git.proxmox.com Git - mirror_frr.git/commitdiff
zebra: add hooks upon enabling / disabling a VRF
authorFeng Lu <lu.feng@6wind.com>
Fri, 22 May 2015 09:40:09 +0000 (11:40 +0200)
committerVipin Kumar <vipin@cumulusnetworks.com>
Fri, 30 Oct 2015 07:32:56 +0000 (00:32 -0700)
zebra_vrf_enable() is the callback for VRF_ENABLE_HOOK.
It presently needs do nothing.

zebra_vrf_disable() is the callback for VRF_DISABLE_HOOK.
It presently withdraws routes, shuts down interfaces, and
clears the router-id candidates in that VRF.

Signed-off-by: Feng Lu <lu.feng@6wind.com>
Reviewed-by: Alain Ritoux <alain.ritoux@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Acked-by: Vincent JARDIN <vincent.jardin@6wind.com>
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
zebra/main.c
zebra/rib.h
zebra/test_main.c
zebra/zebra_rib.c

index 95a0e438e82d95a358756dabe7f7387998aa765b..22471d3d01e55bc00b6e9a46050dca44ab05aaa9 100644 (file)
@@ -230,11 +230,51 @@ zebra_vrf_new (vrf_id_t vrf_id, void **info)
   return 0;
 }
 
+/* Callback upon enabling a VRF. */
+static int
+zebra_vrf_enable (vrf_id_t vrf_id, void **info)
+{
+  struct zebra_vrf *zvrf = (struct zebra_vrf *) (*info);
+
+  assert (zvrf);
+
+  return 0;
+}
+
+/* Callback upon disabling a VRF. */
+static int
+zebra_vrf_disable (vrf_id_t vrf_id, void **info)
+{
+  struct zebra_vrf *zvrf = (struct zebra_vrf *) (*info);
+  struct listnode *list_node;
+  struct interface *ifp;
+
+  assert (zvrf);
+
+  rib_close_table (zvrf->table[AFI_IP][SAFI_UNICAST]);
+  rib_close_table (zvrf->table[AFI_IP6][SAFI_UNICAST]);
+
+  for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), list_node, ifp))
+    {
+      int operative = if_is_operative (ifp);
+      UNSET_FLAG (ifp->flags, IFF_UP);
+      if (operative)
+        if_down (ifp);
+    }
+
+  list_delete_all_node (zvrf->rid_all_sorted_list);
+  list_delete_all_node (zvrf->rid_lo_sorted_list);
+
+  return 0;
+}
+
 /* Zebra VRF initialization. */
 static void
 zebra_vrf_init (void)
 {
   vrf_add_hook (VRF_NEW_HOOK, zebra_vrf_new);
+  vrf_add_hook (VRF_ENABLE_HOOK, zebra_vrf_enable);
+  vrf_add_hook (VRF_DISABLE_HOOK, zebra_vrf_disable);
   vrf_init ();
 }
 
index ddc6a49dcd0aa060665d369e94ed6bc79e5bf7c2..60a39d4727f2231f9036dfa9b9334d3fa6af5da9 100644 (file)
@@ -438,6 +438,7 @@ extern void rib_update (vrf_id_t);
 extern void rib_update_static (vrf_id_t);
 extern void rib_weed_tables (void);
 extern void rib_sweep_route (void);
+extern void rib_close_table (struct route_table *);
 extern void rib_close (void);
 extern void rib_init (void);
 extern unsigned long rib_score_proto (u_char proto, u_short instance);
index 0013506b9bf4997ab4f29a7ed1dcca825f6d15b2..9b83b642d4be15dc0e0e1b31f0ca116293f5b466 100644 (file)
@@ -217,11 +217,48 @@ zebra_vrf_new (vrf_id_t vrf_id, void **info)
   return 0;
 }
 
+/* Callback upon enabling a VRF. */
+static int
+zebra_vrf_enable (vrf_id_t vrf_id, void **info)
+{
+  struct zebra_vrf *zvrf = (struct zebra_vrf *) (*info);
+
+  assert (zvrf);
+
+  return 0;
+}
+
+/* Callback upon disabling a VRF. */
+static int
+zebra_vrf_disable (vrf_id_t vrf_id, void **info)
+{
+  struct zebra_vrf *zvrf = (struct zebra_vrf *) (*info);
+  struct listnode *list_node;
+  struct interface *ifp;
+
+  assert (zvrf);
+
+  rib_close_table (zvrf->table[AFI_IP][SAFI_UNICAST]);
+  rib_close_table (zvrf->table[AFI_IP6][SAFI_UNICAST]);
+
+  for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), list_node, ifp))
+    {
+      int operative = if_is_operative (ifp);
+      UNSET_FLAG (ifp->flags, IFF_UP);
+      if (operative)
+        if_down (ifp);
+    }
+
+  return 0;
+}
+
 /* Zebra VRF initialization. */
 static void
 zebra_vrf_init (void)
 {
   vrf_add_hook (VRF_NEW_HOOK, zebra_vrf_new);
+  vrf_add_hook (VRF_ENABLE_HOOK, zebra_vrf_enable);
+  vrf_add_hook (VRF_DISABLE_HOOK, zebra_vrf_disable);
   vrf_init ();
 }
 
index 2b94c6a7c67c0c306c6999cc7b8a2439336aa827..ee7abc432ca53f80aa9e19ba20fbde33bff76354 100644 (file)
@@ -3954,7 +3954,7 @@ rib_score_proto (u_char proto, u_short instance)
 }
 
 /* Close RIB and clean up kernel routes. */
-static void
+void
 rib_close_table (struct route_table *table)
 {
   struct route_node *rn;