From: Feng Lu <[email protected]>

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 <[email protected]>
Reviewed-by: Alain Ritoux <[email protected]>
Signed-off-by: Nicolas Dichtel <[email protected]>
---
 bgpd/bgp_main.c          | 8 ++++----
 bgpd/bgp_zebra.c         | 3 ---
 isisd/isis_circuit.c     | 1 -
 isisd/isis_main.c        | 2 ++
 lib/vrf.c                | 5 +++++
 ospf6d/ospf6_main.c      | 5 +++--
 ospfd/ospf_interface.c   | 1 -
 ospfd/ospf_main.c        | 2 ++
 pimd/pim_iface.c         | 5 -----
 pimd/pim_iface.h         | 2 --
 pimd/pim_main.c          | 2 ++
 pimd/pimd.c              | 3 ++-
 ripd/rip_interface.c     | 1 -
 ripd/rip_main.c          | 2 ++
 ripngd/ripng_interface.c | 2 +-
 ripngd/ripng_main.c      | 2 ++
 zebra/interface.c        | 1 -
 zebra/test_main.c        | 1 -
 18 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
index 5026b5eaa4be..ad4de7989f0b 100644
--- a/bgpd/bgp_main.c
+++ b/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 ();
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index 8ae7f465b040..13f71de949e7 100644
--- a/bgpd/bgp_zebra.c
+++ b/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);
 }
diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c
index fdff819cac3d..2ef43ccfd584 100644
--- a/isisd/isis_circuit.c
+++ b/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);
 
diff --git a/isisd/isis_main.c b/isisd/isis_main.c
index 283b7eaae030..60ecb754adc6 100644
--- a/isisd/isis_main.c
+++ b/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 ();
diff --git a/lib/vrf.c b/lib/vrf.c
index 3ccbb99617e1..51f9e3795b8b 100644
--- a/lib/vrf.c
+++ b/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 ();
 }
 
diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c
index 4f6d9e514008..1afe84a733af 100644
--- a/ospf6d/ospf6_main.c
+++ b/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 ();
 
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index 0f02cc821a52..07c3fe35eeda 100644
--- a/ospfd/ospf_interface.c
+++ b/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);
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index 96dfd5799ecf..826fc983396f 100644
--- a/ospfd/ospf_main.c
+++ b/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 ();
diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c
index ecf9ef6bcb11..dc3e9a2bb682 100644
--- a/pimd/pim_iface.c
+++ b/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) {
diff --git a/pimd/pim_iface.h b/pimd/pim_iface.h
index 4b06b9ff2ec5..8806fdd93924 100644
--- a/pimd/pim_iface.h
+++ b/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);
diff --git a/pimd/pim_main.c b/pimd/pim_main.c
index b57f881131b8..63dd6364834c 100644
--- a/pimd/pim_main.c
+++ b/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();
 
diff --git a/pimd/pimd.c b/pimd/pimd.c
index 855defcc7863..78c3ff5d0d6a 100644
--- a/pimd/pimd.c
+++ b/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();
 }
diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c
index 35685a75b74c..f26ef48a20e7 100644
--- a/ripd/rip_interface.c
+++ b/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);
   
diff --git a/ripd/rip_main.c b/ripd/rip_main.c
index e81e61b80351..95b1f6d4a5cd 100644
--- a/ripd/rip_main.c
+++ b/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 ();
diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c
index 358846346909..c7865d1e9bf9 100644
--- a/ripngd/ripng_interface.c
+++ b/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);
 
diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c
index acc980ded9f6..d8f2241128cb 100644
--- a/ripngd/ripng_main.c
+++ b/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 ();
diff --git a/zebra/interface.c b/zebra/interface.c
index 4938fa1b9015..ba1848d36a7b 100644
--- a/zebra/interface.c
+++ b/zebra/interface.c
@@ -1635,7 +1635,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);
   
diff --git a/zebra/test_main.c b/zebra/test_main.c
index a92cd6189651..aad616f7f62d 100644
--- a/zebra/test_main.c
+++ b/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 ();
-- 
2.2.2


_______________________________________________
Quagga-dev mailing list
[email protected]
https://lists.quagga.net/mailman/listinfo/quagga-dev

Reply via email to