]> git.puffer.fish Git - mirror/frr.git/commitdiff
ospf6d: Have ospf6d cleanup when it terminates normally
authorTom Goff <thomas.goff@boeing.com>
Wed, 10 Nov 2010 21:01:41 +0000 (13:01 -0800)
committerDenis Ovsienko <infrastation@yandex.ru>
Mon, 2 Jan 2012 15:50:41 +0000 (19:50 +0400)
A clean exit makes it easier to use memory debuggers.

* ospf6_asbr.c: (ospf6_asbr_terminate) Add a function to do route map
  cleanup.
* ospf6_lsa.c: (ospf6_lsa_terminate) Add a function to cleanup the lsa
  handler vector.
* ospf6_main.c: (ospf6_exit) Add an function that causes ospf6d to
  gracefully exit.
* ospf6_message.c: (ospf6_message_terminate) Add a function that frees
  the send and receive buffers.
* ospf6_top.c: (ospf6_delete) Enable the ospf6_delete() function.
  Disable ospf6 before freeing everything.

Signed-off-by: Vyacheslav Trushkin <me@dogonthesun.net>
Conflicts:

ospf6d/ospf6_lsa.h

ospf6d/ospf6_asbr.c
ospf6d/ospf6_asbr.h
ospf6d/ospf6_lsa.c
ospf6d/ospf6_lsa.h
ospf6d/ospf6_main.c
ospf6d/ospf6_message.c
ospf6d/ospf6_message.h
ospf6d/ospf6_top.c
ospf6d/ospf6_top.h

index bc05dc279df0f51c4c33d9911ac4492e78665eb8..ae0a286d54da9be0d283c4586ed3bfa25903f8df 100644 (file)
@@ -1275,6 +1275,11 @@ ospf6_asbr_init (void)
   install_element (OSPF6_NODE, &no_ospf6_redistribute_cmd);
 }
 
+void
+ospf6_asbr_terminate (void)
+{
+  route_map_finish ();
+}
 
 DEFUN (debug_ospf6_asbr,
        debug_ospf6_asbr_cmd,
index 5f072cffcb0d68064494f399d5a64ead8d7a3175..72e491432a17588ba53b9b1e94010e48050bd86a 100644 (file)
@@ -89,6 +89,7 @@ extern void ospf6_asbr_redistribute_remove (int type, int ifindex,
 extern int ospf6_redistribute_config_write (struct vty *vty);
 
 extern void ospf6_asbr_init (void);
+extern void ospf6_asbr_terminate (void);
 
 extern int config_write_ospf6_debug_asbr (struct vty *vty);
 extern void install_element_ospf6_debug_asbr (void);
index a9545c332db9595329512371c8dd2a1a8f1d24f5..e65752d8cd19a8d8154ae1693e17e87861653a8f 100644 (file)
@@ -722,6 +722,11 @@ ospf6_lsa_init (void)
   ospf6_install_lsa_handler (&unknown_handler);
 }
 
+void
+ospf6_lsa_terminate (void)
+{
+  vector_free (ospf6_lsa_handler_vector);
+}
 \f
 static char *
 ospf6_lsa_handler_name (struct ospf6_lsa_handler *h)
index 13b8990018bf9b83f3bcae63166e9affe1688b94..7d93f5cbac12b0c4d900e57972b9965c816e8b9e 100644 (file)
@@ -244,6 +244,7 @@ extern void ospf6_install_lsa_handler (struct ospf6_lsa_handler *handler);
 extern struct ospf6_lsa_handler *ospf6_get_lsa_handler (u_int16_t type);
 
 extern void ospf6_lsa_init (void);
+extern void ospf6_lsa_terminate (void);
 
 extern int config_write_ospf6_debug_lsa (struct vty *vty);
 extern void install_element_ospf6_debug_lsa (void);
index 8444d90f6c20352af0689d28e3497d865a018521..65fcb597a56a3269b6e24916fed597c23122d095 100644 (file)
@@ -131,6 +131,35 @@ Report bugs to zebra@zebra.org\n", progname);
   exit (status);
 }
 
+static void
+ospf6_exit (int status)
+{
+  extern struct ospf6 *ospf6;
+  extern struct zclient *zclient;
+
+  if (ospf6)
+    ospf6_delete (ospf6);
+
+  ospf6_message_terminate ();
+  ospf6_asbr_terminate ();
+  ospf6_lsa_terminate ();
+
+  if_terminate ();
+  vty_terminate ();
+  cmd_terminate ();
+
+  if (zclient)
+    zclient_free (zclient);
+
+  if (master)
+    thread_master_free (master);
+
+  if (zlog_default)
+    closezlog (zlog_default);
+
+  exit (status);
+}
+
 /* SIGHUP handler. */
 static void 
 sighup (void)
@@ -143,7 +172,7 @@ static void
 sigint (void)
 {
   zlog_notice ("Terminating on signal SIGINT");
-  exit (0);
+  ospf6_exit (0);
 }
 
 /* SIGTERM handler. */
@@ -151,7 +180,7 @@ static void
 sigterm (void)
 {
   zlog_notice ("Terminating on signal SIGTERM");
-  exit (0);
+  ospf6_exit (0);
 }
 
 /* SIGUSR1 handler. */
@@ -325,7 +354,7 @@ main (int argc, char *argv[], char *envp[])
   zlog_warn ("Thread failed");
 
   /* Not reached. */
-  exit (0);
+  ospf6_exit (0);
 }
 
 
index 8179fc14ea30e6de6f26c373c8e5d10a8c9d91db..aaee4d20214132523e375a781061f8fb6b5819d8 100644 (file)
@@ -1504,6 +1504,24 @@ ospf6_iobuf_size (unsigned int size)
   return iobuflen;
 }
 
+void
+ospf6_message_terminate (void)
+{
+  if (recvbuf)
+    {
+      XFREE (MTYPE_OSPF6_MESSAGE, recvbuf);
+      recvbuf = NULL;
+    }
+
+  if (sendbuf)
+    {
+      XFREE (MTYPE_OSPF6_MESSAGE, sendbuf);
+      sendbuf = NULL;
+    }
+
+  iobuflen = 0;
+}
+
 int
 ospf6_receive (struct thread *thread)
 {
index 87a7cfebcc9ffc8ea69e5946dc9e71226f3da756..b085a9673b33bc48ec232f26ee49c3618ce5892f 100644 (file)
@@ -123,6 +123,7 @@ extern void ospf6_lsupdate_print (struct ospf6_header *);
 extern void ospf6_lsack_print (struct ospf6_header *);
 
 extern int ospf6_iobuf_size (unsigned int size);
+extern void ospf6_message_terminate (void);
 extern int ospf6_receive (struct thread *thread);
 
 extern int ospf6_hello_send (struct thread *thread);
index 38f94d7b96fe5743d48779662548ba477326d2c6..df856b4cf2b69eb63d77dd8582cdc0ec65ebcba0 100644 (file)
@@ -51,6 +51,8 @@
 /* global ospf6d variable */
 struct ospf6 *ospf6;
 
+static void ospf6_disable (struct ospf6 *o);
+
 static void
 ospf6_top_lsdb_hook_add (struct ospf6_lsa *lsa)
 {
@@ -143,15 +145,17 @@ ospf6_create (void)
   return o;
 }
 
-#if 0
-static void
+void
 ospf6_delete (struct ospf6 *o)
 {
   struct listnode *node, *nnode;
   struct ospf6_area *oa;
 
+  ospf6_disable (ospf6);
+
   for (ALL_LIST_ELEMENTS (o->area_list, node, nnode, oa))
     ospf6_area_delete (oa);
+  list_delete (o->area_list);
 
   ospf6_lsdb_delete (o->lsdb);
   ospf6_lsdb_delete (o->lsdb_self);
@@ -164,7 +168,6 @@ ospf6_delete (struct ospf6 *o)
 
   XFREE (MTYPE_OSPF6_TOP, o);
 }
-#endif
 
 static void
 ospf6_enable (struct ospf6 *o)
index ba485f9ea461d0b439886efe3fe0031c316806bd..4b2d2c3efce4df2f479ecddbaebbb9f5f7034223 100644 (file)
@@ -69,6 +69,7 @@ extern struct ospf6 *ospf6;
 
 /* prototypes */
 extern void ospf6_top_init (void);
+extern void ospf6_delete (struct ospf6 *o);
 
 extern void ospf6_maxage_remove (struct ospf6 *o);