[prev in list] [next in list] [prev in thread] [next in thread] 

List:       quagga-dev
Subject:    [quagga-dev 8356] Re: [PATCH 3/7] ospf6d: Have ospf6d cleanup when
From:       Balaji G <balajig81 () gmail ! com>
Date:       2010-11-16 11:25:17
Message-ID: AANLkTimhsN8MyDtxe-e0sKJZfh7oxD2G-z=K6-vUuo9G () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Applied, Thanks but this requires review from the protocol perspective also
which i cannot comment on.


On Thu, Nov 11, 2010 at 2:31 AM, Tom Goff <thomas.goff@boeing.com> wrote:

> 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: Tom Goff <thomas.goff@boeing.com>
> ---
>  ospf6d/ospf6_asbr.c    |    5 +++++
>  ospf6d/ospf6_asbr.h    |    1 +
>  ospf6d/ospf6_lsa.c     |    5 +++++
>  ospf6d/ospf6_lsa.h     |    1 +
>  ospf6d/ospf6_main.c    |   35 ++++++++++++++++++++++++++++++++---
>  ospf6d/ospf6_message.c |   18 ++++++++++++++++++
>  ospf6d/ospf6_message.h |    1 +
>  ospf6d/ospf6_top.c     |    9 ++++++---
>  ospf6d/ospf6_top.h     |    1 +
>  9 files changed, 70 insertions(+), 6 deletions(-)
>
> diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c
> index 685b147..3efaab4 100644
> --- a/ospf6d/ospf6_asbr.c
> +++ b/ospf6d/ospf6_asbr.c
> @@ -1219,6 +1219,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,
> diff --git a/ospf6d/ospf6_asbr.h b/ospf6d/ospf6_asbr.h
> index 7166aa3..6deb93e 100644
> --- a/ospf6d/ospf6_asbr.h
> +++ b/ospf6d/ospf6_asbr.h
> @@ -79,6 +79,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);
> diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c
> index c1db374..588b946 100644
> --- a/ospf6d/ospf6_lsa.c
> +++ b/ospf6d/ospf6_lsa.c
> @@ -712,6 +712,11 @@ ospf6_lsa_init (void)
>   ospf6_install_lsa_handler (&unknown_handler);
>  }
>
> +void
> +ospf6_lsa_terminate (void)
> +{
> +  vector_free (ospf6_lsa_handler_vector);
> +}
>
>  static char *
>  ospf6_lsa_handler_name (struct ospf6_lsa_handler *h)
> diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h
> index fb0f27c..c1093ca 100644
> --- a/ospf6d/ospf6_lsa.h
> +++ b/ospf6d/ospf6_lsa.h
> @@ -243,6 +243,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 void ospf6_lsa_cmd_init (void);
>
>  extern int config_write_ospf6_debug_lsa (struct vty *vty);
> diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c
> index a7a96a1..800fae4 100644
> --- a/ospf6d/ospf6_main.c
> +++ b/ospf6d/ospf6_main.c
> @@ -124,6 +124,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)
> @@ -136,7 +165,7 @@ static void
>  sigint (void)
>  {
>   zlog_notice ("Terminating on signal SIGINT");
> -  exit (0);
> +  ospf6_exit (0);
>  }
>
>  /* SIGTERM handler. */
> @@ -144,7 +173,7 @@ static void
>  sigterm (void)
>  {
>   zlog_notice ("Terminating on signal SIGTERM");
> -  exit (0);
> +  ospf6_exit (0);
>  }
>
>  /* SIGUSR1 handler. */
> @@ -308,7 +337,7 @@ main (int argc, char *argv[], char *envp[])
>   zlog_warn ("Thread failed");
>
>   /* Not reached. */
> -  exit (0);
> +  ospf6_exit (0);
>  }
>
>
> diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c
> index 790fc0a..d06eba2 100644
> --- a/ospf6d/ospf6_message.c
> +++ b/ospf6d/ospf6_message.c
> @@ -1168,6 +1168,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)
>  {
> diff --git a/ospf6d/ospf6_message.h b/ospf6d/ospf6_message.h
> index ebb6308..c72f0af 100644
> --- a/ospf6d/ospf6_message.h
> +++ b/ospf6d/ospf6_message.h
> @@ -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);
> diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c
> index 8237026..2b65be8 100644
> --- a/ospf6d/ospf6_top.c
> +++ b/ospf6d/ospf6_top.c
> @@ -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)
> diff --git a/ospf6d/ospf6_top.h b/ospf6d/ospf6_top.h
> index ba485f9..4b2d2c3 100644
> --- a/ospf6d/ospf6_top.h
> +++ b/ospf6d/ospf6_top.h
> @@ -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);
>
> --
> 1.7.0.4
>
> _______________________________________________
> Quagga-dev mailing list
> Quagga-dev@lists.quagga.net
> http://lists.quagga.net/mailman/listinfo/quagga-dev
>

[Attachment #5 (text/html)]

<meta http-equiv="content-type" content="text/html; charset=utf-8">Applied, Thanks \
but this requires review from the protocol perspective also which i cannot comment \
on.<div><br><br><div class="gmail_quote">On Thu, Nov 11, 2010 at 2:31 AM, Tom Goff \
<span dir="ltr">&lt;<a \
href="mailto:thomas.goff@boeing.com">thomas.goff@boeing.com</a>&gt;</span> wrote:<br> \
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex;">A clean exit makes it easier to use memory debuggers.<br> \
                <br>
ospf6_asbr.c: (ospf6_asbr_terminate) Add a function to do route map<br>
      cleanup.<br>
<br>
ospf6_lsa.c: (ospf6_lsa_terminate) Add a function to cleanup the lsa<br>
      handler vector.<br>
<br>
ospf6_main.c: (ospf6_exit) Add an function that causes ospf6d to<br>
      gracefully exit.<br>
<br>
ospf6_message.c: (ospf6_message_terminate) Add a function that frees<br>
      the send and receive buffers.<br>
<br>
ospf6_top.c: (ospf6_delete) Enable the ospf6_delete() function.<br>
      Disable ospf6 before freeing everything.<br>
<br>
Signed-off-by: Tom Goff &lt;<a \
                href="mailto:thomas.goff@boeing.com">thomas.goff@boeing.com</a>&gt;<br>
                
---<br>
  ospf6d/ospf6_asbr.c      |      5 +++++<br>
  ospf6d/ospf6_asbr.h      |      1 +<br>
  ospf6d/ospf6_lsa.c       |      5 +++++<br>
  ospf6d/ospf6_lsa.h       |      1 +<br>
  ospf6d/ospf6_main.c      |    35 ++++++++++++++++++++++++++++++++---<br>
  ospf6d/ospf6_message.c |    18 ++++++++++++++++++<br>
  ospf6d/ospf6_message.h |      1 +<br>
  ospf6d/ospf6_top.c       |      9 ++++++---<br>
  ospf6d/ospf6_top.h       |      1 +<br>
  9 files changed, 70 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c<br>
index 685b147..3efaab4 100644<br>
--- a/ospf6d/ospf6_asbr.c<br>
+++ b/ospf6d/ospf6_asbr.c<br>
@@ -1219,6 +1219,11 @@ ospf6_asbr_init (void)<br>
    install_element (OSPF6_NODE, &amp;no_ospf6_redistribute_cmd);<br>
  }<br>
<br>
+void<br>
+ospf6_asbr_terminate (void)<br>
+{<br>
+   route_map_finish ();<br>
+}<br>
<br>
  DEFUN (debug_ospf6_asbr,<br>
            debug_ospf6_asbr_cmd,<br>
diff --git a/ospf6d/ospf6_asbr.h b/ospf6d/ospf6_asbr.h<br>
index 7166aa3..6deb93e 100644<br>
--- a/ospf6d/ospf6_asbr.h<br>
+++ b/ospf6d/ospf6_asbr.h<br>
@@ -79,6 +79,7 @@ extern void ospf6_asbr_redistribute_remove (int type, int \
ifindex,<br>  extern int ospf6_redistribute_config_write (struct vty *vty);<br>
<br>
  extern void ospf6_asbr_init (void);<br>
+extern void ospf6_asbr_terminate (void);<br>
<br>
  extern int config_write_ospf6_debug_asbr (struct vty *vty);<br>
  extern void install_element_ospf6_debug_asbr (void);<br>
diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c<br>
index c1db374..588b946 100644<br>
--- a/ospf6d/ospf6_lsa.c<br>
+++ b/ospf6d/ospf6_lsa.c<br>
@@ -712,6 +712,11 @@ ospf6_lsa_init (void)<br>
    ospf6_install_lsa_handler (&amp;unknown_handler);<br>
  }<br>
<br>
+void<br>
+ospf6_lsa_terminate (void)<br>
+{<br>
+   vector_free (ospf6_lsa_handler_vector);<br>
+}<br>
<br>
  static char *<br>
  ospf6_lsa_handler_name (struct ospf6_lsa_handler *h)<br>
diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h<br>
index fb0f27c..c1093ca 100644<br>
--- a/ospf6d/ospf6_lsa.h<br>
+++ b/ospf6d/ospf6_lsa.h<br>
@@ -243,6 +243,7 @@ extern void ospf6_install_lsa_handler (struct ospf6_lsa_handler \
*handler);<br>  extern struct ospf6_lsa_handler *ospf6_get_lsa_handler (u_int16_t \
type);<br> <br>
  extern void ospf6_lsa_init (void);<br>
+extern void ospf6_lsa_terminate (void);<br>
  extern void ospf6_lsa_cmd_init (void);<br>
<br>
  extern int config_write_ospf6_debug_lsa (struct vty *vty);<br>
diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c<br>
index a7a96a1..800fae4 100644<br>
--- a/ospf6d/ospf6_main.c<br>
+++ b/ospf6d/ospf6_main.c<br>
@@ -124,6 +124,35 @@ Report bugs to <a \
href="mailto:zebra@zebra.org">zebra@zebra.org</a>\n&quot;, progname);<br>  exit \
(status);<br>  }<br>
<br>
+static void<br>
+ospf6_exit (int status)<br>
+{<br>
+   extern struct ospf6 *ospf6;<br>
+   extern struct zclient *zclient;<br>
+<br>
+   if (ospf6)<br>
+      ospf6_delete (ospf6);<br>
+<br>
+   ospf6_message_terminate ();<br>
+   ospf6_asbr_terminate ();<br>
+   ospf6_lsa_terminate ();<br>
+<br>
+   if_terminate ();<br>
+   vty_terminate ();<br>
+   cmd_terminate ();<br>
+<br>
+   if (zclient)<br>
+      zclient_free (zclient);<br>
+<br>
+   if (master)<br>
+      thread_master_free (master);<br>
+<br>
+   if (zlog_default)<br>
+      closezlog (zlog_default);<br>
+<br>
+   exit (status);<br>
+}<br>
+<br>
  /* SIGHUP handler. */<br>
  static void<br>
  sighup (void)<br>
@@ -136,7 +165,7 @@ static void<br>
  sigint (void)<br>
  {<br>
    zlog_notice (&quot;Terminating on signal SIGINT&quot;);<br>
-   exit (0);<br>
+   ospf6_exit (0);<br>
  }<br>
<br>
  /* SIGTERM handler. */<br>
@@ -144,7 +173,7 @@ static void<br>
  sigterm (void)<br>
  {<br>
    zlog_notice (&quot;Terminating on signal SIGTERM&quot;);<br>
-   exit (0);<br>
+   ospf6_exit (0);<br>
  }<br>
<br>
  /* SIGUSR1 handler. */<br>
@@ -308,7 +337,7 @@ main (int argc, char *argv[], char *envp[])<br>
    zlog_warn (&quot;Thread failed&quot;);<br>
<br>
    /* Not reached. */<br>
-   exit (0);<br>
+   ospf6_exit (0);<br>
  }<br>
<br>
<br>
diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c<br>
index 790fc0a..d06eba2 100644<br>
--- a/ospf6d/ospf6_message.c<br>
+++ b/ospf6d/ospf6_message.c<br>
@@ -1168,6 +1168,24 @@ ospf6_iobuf_size (unsigned int size)<br>
    return iobuflen;<br>
  }<br>
<br>
+void<br>
+ospf6_message_terminate (void)<br>
+{<br>
+   if (recvbuf)<br>
+      {<br>
+         XFREE (MTYPE_OSPF6_MESSAGE, recvbuf);<br>
+         recvbuf = NULL;<br>
+      }<br>
+<br>
+   if (sendbuf)<br>
+      {<br>
+         XFREE (MTYPE_OSPF6_MESSAGE, sendbuf);<br>
+         sendbuf = NULL;<br>
+      }<br>
+<br>
+   iobuflen = 0;<br>
+}<br>
+<br>
  int<br>
  ospf6_receive (struct thread *thread)<br>
  {<br>
diff --git a/ospf6d/ospf6_message.h b/ospf6d/ospf6_message.h<br>
index ebb6308..c72f0af 100644<br>
--- a/ospf6d/ospf6_message.h<br>
+++ b/ospf6d/ospf6_message.h<br>
@@ -123,6 +123,7 @@ extern void ospf6_lsupdate_print (struct ospf6_header *);<br>
  extern void ospf6_lsack_print (struct ospf6_header *);<br>
<br>
  extern int ospf6_iobuf_size (unsigned int size);<br>
+extern void ospf6_message_terminate (void);<br>
  extern int ospf6_receive (struct thread *thread);<br>
<br>
  extern int ospf6_hello_send (struct thread *thread);<br>
diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c<br>
index 8237026..2b65be8 100644<br>
--- a/ospf6d/ospf6_top.c<br>
+++ b/ospf6d/ospf6_top.c<br>
@@ -51,6 +51,8 @@<br>
  /* global ospf6d variable */<br>
  struct ospf6 *ospf6;<br>
<br>
+static void ospf6_disable (struct ospf6 *o);<br>
+<br>
  static void<br>
  ospf6_top_lsdb_hook_add (struct ospf6_lsa *lsa)<br>
  {<br>
@@ -143,15 +145,17 @@ ospf6_create (void)<br>
    return o;<br>
  }<br>
<br>
-#if 0<br>
-static void<br>
+void<br>
  ospf6_delete (struct ospf6 *o)<br>
  {<br>
    struct listnode *node, *nnode;<br>
    struct ospf6_area *oa;<br>
<br>
+   ospf6_disable (ospf6);<br>
+<br>
    for (ALL_LIST_ELEMENTS (o-&gt;area_list, node, nnode, oa))<br>
       ospf6_area_delete (oa);<br>
+   list_delete (o-&gt;area_list);<br>
<br>
    ospf6_lsdb_delete (o-&gt;lsdb);<br>
    ospf6_lsdb_delete (o-&gt;lsdb_self);<br>
@@ -164,7 +168,6 @@ ospf6_delete (struct ospf6 *o)<br>
<br>
    XFREE (MTYPE_OSPF6_TOP, o);<br>
  }<br>
-#endif<br>
<br>
  static void<br>
  ospf6_enable (struct ospf6 *o)<br>
diff --git a/ospf6d/ospf6_top.h b/ospf6d/ospf6_top.h<br>
index ba485f9..4b2d2c3 100644<br>
--- a/ospf6d/ospf6_top.h<br>
+++ b/ospf6d/ospf6_top.h<br>
@@ -69,6 +69,7 @@ extern struct ospf6 *ospf6;<br>
<br>
  /* prototypes */<br>
  extern void ospf6_top_init (void);<br>
+extern void ospf6_delete (struct ospf6 *o);<br>
<br>
  extern void ospf6_maxage_remove (struct ospf6 *o);<br>
<font color="#888888"><br>
--<br>
1.7.0.4<br>
<br>
_______________________________________________<br>
Quagga-dev mailing list<br>
<a href="mailto:Quagga-dev@lists.quagga.net">Quagga-dev@lists.quagga.net</a><br>
<a href="http://lists.quagga.net/mailman/listinfo/quagga-dev" \
target="_blank">http://lists.quagga.net/mailman/listinfo/quagga-dev</a><br> \
</font></blockquote></div><br></div>



_______________________________________________
Quagga-dev mailing list
Quagga-dev@lists.quagga.net
http://lists.quagga.net/mailman/listinfo/quagga-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic