summaryrefslogtreecommitdiff
path: root/lib/bfd.c
diff options
context:
space:
mode:
authorRafael Zalamena <rzalamena@opensourcerouting.org>2022-12-02 10:04:40 -0300
committerRafael Zalamena <rzalamena@opensourcerouting.org>2023-01-13 15:32:12 -0300
commit4e35b32ee5f56b5768d6e9ebf275cf0109618fac (patch)
tree347e58ae7145a9e4b03d58bdc9406370281ce0c0 /lib/bfd.c
parentb7ca809d1c1386aed0d4571cfbcd448b9868a298 (diff)
lib: BFD integration clean up function
Implement clean up function to be called on shutdown to make daemon exit clean for valgrind and other memory sanitizers. Signed-off-by: Rafael Zalamena <rzalamena@opensourcerouting.org>
Diffstat (limited to 'lib/bfd.c')
-rw-r--r--lib/bfd.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/bfd.c b/lib/bfd.c
index 1bd31920f0..ae402ec5cb 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -29,6 +29,7 @@
#include "stream.h"
#include "vrf.h"
#include "zclient.h"
+#include "libfrr.h"
#include "table.h"
#include "vty.h"
#include "bfd.h"
@@ -1045,6 +1046,40 @@ int zclient_bfd_session_update(ZAPI_CALLBACK_ARGS)
return 0;
}
+/**
+ * Frees all allocated resources and stops any activity.
+ *
+ * Must be called after every BFD session has been successfully
+ * unconfigured otherwise this function will `free()` any available
+ * session causing existing pointers to dangle.
+ *
+ * This is just a comment, in practice it will be called by the FRR
+ * library late finish hook. \see `bfd_protocol_integration_init`.
+ */
+static int bfd_protocol_integration_finish(void)
+{
+ if (bsglobal.zc == NULL)
+ return 0;
+
+ while (!TAILQ_EMPTY(&bsglobal.bsplist)) {
+ struct bfd_session_params *session =
+ TAILQ_FIRST(&bsglobal.bsplist);
+ bfd_sess_free(&session);
+ }
+
+ /*
+ * BFD source cache is linked to sessions, if all sessions are gone
+ * then the source cache must be empty.
+ */
+ if (!SLIST_EMPTY(&bsglobal.source_list))
+ zlog_warn("BFD integration source cache not empty");
+
+ zclient_stop(bsglobal.nht_zclient);
+ zclient_free(bsglobal.nht_zclient);
+
+ return 0;
+}
+
static zclient_handler *const bfd_nht_handlers[] = {
[ZEBRA_NEXTHOP_UPDATE] = bfd_nht_update,
};
@@ -1076,6 +1111,8 @@ void bfd_protocol_integration_init(struct zclient *zc, struct thread_master *tm)
bsglobal.nht_zclient->zebra_connected = bfd_nht_zclient_connected;
thread_add_timer(tm, bfd_nht_zclient_connect, bsglobal.nht_zclient, 1,
&bsglobal.nht_zclient->t_connect);
+
+ hook_register(frr_fini, bfd_protocol_integration_finish);
}
void bfd_protocol_integration_set_debug(bool enable)