]> git.proxmox.com Git - mirror_frr.git/commitdiff
bfdd: clean-up bfd clients data on shutdown
authorRafael Zalamena <rzalamena@opensourcerouting.org>
Wed, 25 Jul 2018 16:39:58 +0000 (13:39 -0300)
committerRafael Zalamena <rzalamena@opensourcerouting.org>
Wed, 8 Aug 2018 21:25:08 +0000 (18:25 -0300)
On `zebra` / `bfdd` shutdown we now clean up all client data to avoid
memory leaks (ghost clients). This also prevents 'slow' shutdown on
`zebra` sparing us from seeing some rare topotests shutdown failures
(signal handler getting stopped by signal).

Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
bfdd/ptm_adapter.c
zebra/zebra_ptm.c

index b2c6b8e2d054a08f189e60aa587f8b011274debc..ca44be6541acb6d3958722c4ef1ce4a5e0d12d4c 100644 (file)
@@ -64,6 +64,7 @@ static int _ptm_msg_read(struct stream *msg, int command,
 static struct ptm_client *pc_lookup(uint32_t pid);
 static struct ptm_client *pc_new(uint32_t pid);
 static void pc_free(struct ptm_client *pc);
+static void pc_free_all(void);
 static struct ptm_client_notification *pcn_new(struct ptm_client *pc,
                                               struct bfd_session *bs);
 static struct ptm_client_notification *pcn_lookup(struct ptm_client *pc,
@@ -553,6 +554,9 @@ static void bfdd_zebra_connected(struct zclient *zc)
 {
        struct stream *msg = zc->obuf;
 
+       /* Clean-up and free ptm clients data memory. */
+       pc_free_all();
+
        /*
         * The replay is an empty message just to trigger client daemons
         * configuration replay.
@@ -585,6 +589,9 @@ void bfdd_zclient_init(struct zebra_privs_t *bfdd_priv)
 void bfdd_zclient_stop(void)
 {
        zclient_stop(zclient);
+
+       /* Clean-up and free ptm clients data memory. */
+       pc_free_all();
 }
 
 
@@ -641,6 +648,16 @@ static void pc_free(struct ptm_client *pc)
        XFREE(MTYPE_BFDD_CONTROL, pc);
 }
 
+static void pc_free_all(void)
+{
+       struct ptm_client *pc;
+
+       while (!TAILQ_EMPTY(&pcqueue)) {
+               pc = TAILQ_FIRST(&pcqueue);
+               pc_free(pc);
+       }
+}
+
 static struct ptm_client_notification *pcn_new(struct ptm_client *pc,
                                               struct bfd_session *bs)
 {
index 76e427570b81af26c59a512b87c9be967f4efb55..cc2d5d411dd54b7ae685fb1913ab1cfe80e5dec5 100644 (file)
@@ -1175,6 +1175,7 @@ DEFINE_MTYPE_STATIC(ZEBRA, ZEBRA_PTM_BFD_PROCESS,
 static struct ptm_process *pp_new(pid_t pid, struct zserv *zs);
 static struct ptm_process *pp_lookup_byzs(struct zserv *zs);
 static void pp_free(struct ptm_process *pp);
+static void pp_free_all(void);
 
 static void zebra_ptm_send_bfdd(struct stream *msg);
 static void zebra_ptm_send_clients(struct stream *msg);
@@ -1239,6 +1240,16 @@ static void pp_free(struct ptm_process *pp)
        XFREE(MTYPE_ZEBRA_PTM_BFD_PROCESS, pp);
 }
 
+static void pp_free_all(void)
+{
+       struct ptm_process *pp;
+
+       while (!TAILQ_EMPTY(&ppqueue)) {
+               pp = TAILQ_FIRST(&ppqueue);
+               pp_free(pp);
+       }
+}
+
 
 /*
  * Use the FRR's internal daemon implementation.
@@ -1385,6 +1396,13 @@ void zebra_ptm_init(void)
        hook_register(zserv_client_close, _zebra_ptm_bfd_client_deregister);
 }
 
+void zebra_ptm_finish(void)
+{
+       /* Remove the client disconnect hook and free all memory. */
+       hook_unregister(zserv_client_close, _zebra_ptm_bfd_client_deregister);
+       pp_free_all();
+}
+
 
 /*
  * Message handling.
@@ -1528,10 +1546,6 @@ void zebra_ptm_bfd_dst_replay(ZAPI_HANDLER_ARGS)
 /*
  * Unused functions.
  */
-void zebra_ptm_finish(void)
-{
-       /* NOTHING */
-}
 void zebra_ptm_if_init(struct zebra_if *zifp __attribute__((__unused__)))
 {
        /* NOTHING */