Browse Source

*: call if_init()/if_terminate() from vrf_init()/vrf_terminate()

Later, an interface will belong to a specific VRF, and the interface
initialization will be a part of the VRF initialization. So now call
if_init() from vrf_init(), and if_terminate() from vrf_terminate().

Daemons have the according changes:
- if if_init() was called or "iflist" was initialized, now call
  vrf_init() instead;
- if if_terminate() was called or "iflist" was destroyed, now call
  vrf_terminate() instead.

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>
Feng Lu 5 years ago
parent
commit
126215c123

+ 4 - 4
bgpd/bgp_main.c

@@ -36,6 +36,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 #include "filter.h"
 #include "plist.h"
 #include "stream.h"
+#include "vrf.h"
 
 #include "bgpd/bgpd.h"
 #include "bgpd/bgp_attr.h"
@@ -248,17 +249,14 @@ bgp_exit (int status)
   /* reverse bgp_zebra_init/if_init */
   if (retain_mode)
     if_add_hook (IF_DELETE_HOOK, NULL);
-  for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp))
+  for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp))
     {
       struct listnode *c_node, *c_nnode;
       struct connected *c;
 
       for (ALL_LIST_ELEMENTS (ifp->connected, c_node, c_nnode, c))
         bgp_connected_delete (c);
-
-      if_delete (ifp);
     }
-  list_free (iflist);
 
   /* reverse bgp_attr_init */
   bgp_attr_finish ();
@@ -293,6 +291,7 @@ bgp_exit (int status)
   /* reverse community_list_init */
   community_list_terminate (bgp_clist);
 
+  vrf_terminate ();
   cmd_terminate ();
   vty_terminate ();
   if (zclient)
@@ -427,6 +426,7 @@ main (int argc, char **argv)
   cmd_init (1);
   vty_init (master);
   memory_init ();
+  vrf_init ();
 
   /* BGP related initialization.  */
   bgp_init ();

+ 0 - 3
bgpd/bgp_zebra.c

@@ -1096,8 +1096,5 @@ bgp_zebra_init (void)
   zclient->ipv6_route_delete = zebra_read_ipv6;
 #endif /* HAVE_IPV6 */
 
-  /* Interface related init. */
-  if_init ();
-
   bgp_nexthop_buf = stream_new(BGP_NEXTHOP_BUF_SIZE);
 }

+ 0 - 1
isisd/isis_circuit.c

@@ -2739,7 +2739,6 @@ void
 isis_circuit_init ()
 {
   /* Initialize Zebra interface data structure */
-  if_init ();
   if_add_hook (IF_NEW_HOOK, isis_if_new_hook);
   if_add_hook (IF_DELETE_HOOK, isis_if_delete_hook);
 

+ 2 - 0
isisd/isis_main.c

@@ -35,6 +35,7 @@
 #include "sigevent.h"
 #include "filter.h"
 #include "zclient.h"
+#include "vrf.h"
 
 #include "isisd/dict.h"
 #include "include-netbsd/iso.h"
@@ -330,6 +331,7 @@ main (int argc, char **argv, char **envp)
   vty_init (master);
   memory_init ();
   access_list_init();
+  vrf_init ();
   isis_init ();
   isis_circuit_init ();
   isis_spf_cmds_init ();

+ 5 - 0
lib/vrf.c

@@ -22,6 +22,7 @@
 
 #include <zebra.h>
 
+#include "if.h"
 #include "vrf.h"
 #include "prefix.h"
 #include "table.h"
@@ -249,6 +250,8 @@ vrf_init (void)
 
   /* Set the default VRF name. */
   default_vrf->name = XSTRDUP (MTYPE_VRF_NAME, "Default-IP-Routing-Table");
+
+  if_init ();
 }
 
 /* Terminate VRF module. */
@@ -264,5 +267,7 @@ vrf_terminate (void)
 
   route_table_finish (vrf_table);
   vrf_table = NULL;
+
+  if_terminate ();
 }
 

+ 3 - 2
ospf6d/ospf6_main.c

@@ -35,6 +35,7 @@
 #include "privs.h"
 #include "sigevent.h"
 #include "zclient.h"
+#include "vrf.h"
 
 #include "ospf6d.h"
 #include "ospf6_top.h"
@@ -150,7 +151,7 @@ ospf6_exit (int status)
   ospf6_asbr_terminate ();
   ospf6_lsa_terminate ();
 
-  if_terminate ();
+  vrf_terminate ();
   vty_terminate ();
   cmd_terminate ();
 
@@ -318,7 +319,7 @@ main (int argc, char *argv[], char *envp[])
   cmd_init (1);
   vty_init (master);
   memory_init ();
-  if_init ();
+  vrf_init ();
   access_list_init ();
   prefix_list_init ();
 

+ 0 - 1
ospfd/ospf_interface.c

@@ -1254,7 +1254,6 @@ void
 ospf_if_init ()
 {
   /* Initialize Zebra interface data structure. */
-  if_init ();
   om->iflist = iflist;
   if_add_hook (IF_NEW_HOOK, ospf_if_new_hook);
   if_add_hook (IF_DELETE_HOOK, ospf_if_delete_hook);

+ 2 - 0
ospfd/ospf_main.c

@@ -39,6 +39,7 @@
 #include "privs.h"
 #include "sigevent.h"
 #include "zclient.h"
+#include "vrf.h"
 
 #include "ospfd/ospfd.h"
 #include "ospfd/ospf_interface.h"
@@ -290,6 +291,7 @@ main (int argc, char **argv)
   debug_init ();
   vty_init (master);
   memory_init ();
+  vrf_init ();
 
   access_list_init ();
   prefix_list_init ();

+ 0 - 5
pimd/pim_iface.c

@@ -43,11 +43,6 @@
 
 static void pim_if_igmp_join_del_all(struct interface *ifp);
 
-void pim_if_init()
-{
-  if_init();
-}
-
 static void *if_list_clean(struct pim_interface *pim_ifp)
 {
   if (pim_ifp->igmp_join_list) {

+ 0 - 2
pimd/pim_iface.h

@@ -108,8 +108,6 @@ struct pim_interface {
   ((pim_ifp)->pim_hello_period * 7 / 2) : \
   ((pim_ifp)->pim_default_holdtime))
 
-void pim_if_init(void);
-
 struct pim_interface *pim_if_new(struct interface *ifp, int igmp, int pim);
 void                  pim_if_delete(struct interface *ifp);
 void pim_if_addr_add(struct connected *ifc);

+ 2 - 0
pimd/pim_main.c

@@ -31,6 +31,7 @@
 #include <signal.h>
 
 #include "memory.h"
+#include "vrf.h"
 #include "filter.h"
 #include "vty.h"
 #include "sigevent.h"
@@ -203,6 +204,7 @@ int main(int argc, char** argv, char** envp) {
   cmd_init(1);
   vty_init(master);
   memory_init();
+  vrf_init();
   access_list_init();
   pim_init();
 

+ 2 - 1
pimd/pimd.c

@@ -24,6 +24,7 @@
 
 #include "log.h"
 #include "memory.h"
+#include "vrf.h"
 
 #include "pimd.h"
 #include "pim_cmd.h"
@@ -130,12 +131,12 @@ void pim_init()
   qpim_infinite_assert_metric.route_metric      = PIM_ASSERT_ROUTE_METRIC_MAX;
   qpim_infinite_assert_metric.ip_address        = qpim_inaddr_any;
 
-  pim_if_init();
   pim_cmd_init();
   pim_ssmpingd_init();
 }
 
 void pim_terminate()
 {
+  vrf_terminate();
   pim_free();
 }

+ 0 - 1
ripd/rip_interface.c

@@ -2055,7 +2055,6 @@ void
 rip_if_init (void)
 {
   /* Default initial size of interface vector. */
-  if_init();
   if_add_hook (IF_NEW_HOOK, rip_interface_new_hook);
   if_add_hook (IF_DELETE_HOOK, rip_interface_delete_hook);
   

+ 2 - 0
ripd/rip_main.c

@@ -33,6 +33,7 @@
 #include "privs.h"
 #include "sigevent.h"
 #include "zclient.h"
+#include "vrf.h"
 
 #include "ripd/ripd.h"
 
@@ -280,6 +281,7 @@ main (int argc, char **argv)
   vty_init (master);
   memory_init ();
   keychain_init ();
+  vrf_init ();
 
   /* RIP related initialization. */
   rip_init ();

+ 1 - 1
ripngd/ripng_interface.c

@@ -35,6 +35,7 @@
 #include "table.h"
 #include "thread.h"
 #include "privs.h"
+#include "vrf.h"
 
 #include "ripngd/ripngd.h"
 #include "ripngd/ripng_debug.h"
@@ -1177,7 +1178,6 @@ void
 ripng_if_init ()
 {
   /* Interface initialize. */
-  iflist = list_new ();
   if_add_hook (IF_NEW_HOOK, ripng_if_new_hook);
   if_add_hook (IF_DELETE_HOOK, ripng_if_delete_hook);
 

+ 2 - 0
ripngd/ripng_main.c

@@ -34,6 +34,7 @@
 #include "if.h"
 #include "privs.h"
 #include "sigevent.h"
+#include "vrf.h"
 
 #include "ripngd/ripngd.h"
 
@@ -276,6 +277,7 @@ main (int argc, char **argv)
   cmd_init (1);
   vty_init (master);
   memory_init ();
+  vrf_init ();
 
   /* RIPngd inits. */
   ripng_init ();

+ 0 - 1
zebra/interface.c

@@ -1634,7 +1634,6 @@ void
 zebra_if_init (void)
 {
   /* Initialize interface and new hook. */
-  if_init ();
   if_add_hook (IF_NEW_HOOK, if_zebra_new_hook);
   if_add_hook (IF_DELETE_HOOK, if_zebra_delete_hook);
   

+ 0 - 1
zebra/test_main.c

@@ -308,7 +308,6 @@ main (int argc, char **argv)
   cmd_init (1);
   vty_init (zebrad.master);
   memory_init ();
-  if_init();
   zebra_debug_init ();
   zebra_if_init ();
   test_cmd_init ();