From f1175ba9314200821a47dcffab1fd01c18ee701f Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Mon, 22 Apr 2019 18:04:56 +0000 Subject: [PATCH] vrrpd: gracefully shutdown on SIGTERM / SIGINT Handle kill signals by gracefully destroying all of our VRRP instances. If any of them are in Master state, send an advert with 0 priority to notify Backup routers we are going down. Signed-off-by: Quentin Young --- vrrpd/vrrp.c | 18 ++++++++++++++++++ vrrpd/vrrp.h | 8 ++++++++ vrrpd/vrrp_main.c | 4 +++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/vrrpd/vrrp.c b/vrrpd/vrrp.c index f98b230c62..7b66492c11 100644 --- a/vrrpd/vrrp.c +++ b/vrrpd/vrrp.c @@ -2354,3 +2354,21 @@ void vrrp_init(void) "VRRP virtual router hash"); vrf_init(NULL, NULL, NULL, NULL, NULL); } + +void vrrp_fini(void) +{ + /* Destroy all instances */ + struct list *vrs = hash_to_list(vrrp_vrouters_hash); + + struct listnode *ln; + struct vrrp_vrouter *vr; + + for (ALL_LIST_ELEMENTS_RO(vrs, ln, vr)) { + vrrp_vrouter_destroy(vr); + } + + list_delete(&vrs); + + hash_clean(vrrp_vrouters_hash, NULL); + hash_free(vrrp_vrouters_hash); +} diff --git a/vrrpd/vrrp.h b/vrrpd/vrrp.h index ee2a8249a5..fd4901fe22 100644 --- a/vrrpd/vrrp.h +++ b/vrrpd/vrrp.h @@ -265,6 +265,14 @@ struct vrrp_vrouter { */ void vrrp_init(void); +/* + * Destroy all VRRP instances and gracefully shutdown. + * + * For instances in Master state, VRRP advertisements with 0 priority will be + * sent if possible to notify Backup routers that we are going away. + */ +void vrrp_fini(void); + /* Creation and destruction ------------------------------------------------ */ diff --git a/vrrpd/vrrp_main.c b/vrrpd/vrrp_main.c index d6a43be8e8..98b907d013 100644 --- a/vrrpd/vrrp_main.c +++ b/vrrpd/vrrp_main.c @@ -69,10 +69,12 @@ static void sighup(void) } /* SIGINT / SIGTERM handler. */ -static void sigint(void) +static void __attribute__((noreturn)) sigint(void) { zlog_notice("Terminating on signal"); + vrrp_fini(); + exit(0); } -- 2.39.5