From 4de8e88cbb1a8bfad9a49a15a92a6baa8d847904 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Sun, 25 Jun 2023 23:44:21 +0300 Subject: [PATCH] ldpd: Stop and free synchronous Zebra client on destroy Signed-off-by: Donatas Abraitis --- ldpd/lde.c | 64 --------------------------------------------- ldpd/lde.h | 2 ++ ldpd/ldp_zebra.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 64 deletions(-) diff --git a/ldpd/lde.c b/ldpd/lde.c index 806bab6a213b..8242dd9c2699 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -86,9 +86,6 @@ static struct zebra_privs_t lde_privs = static struct list *label_chunk_list; static struct listnode *current_label_chunk; -/* Synchronous zclient to request labels */ -static struct zclient *zclient_sync; - /* SIGINT / SIGTERM handler. */ static void sigint(void) @@ -2120,67 +2117,6 @@ lde_address_list_free(struct lde_nbr *ln) free(lde_addr); } -/* - * Event callback used to retry the label-manager sync zapi session. - */ -static void zclient_sync_retry(struct event *thread) -{ - zclient_sync_init(); -} - -/* - * Initialize and open a synchronous zapi session. This is used by label chunk - * management code, which acquires and releases blocks of labels from the - * zebra label-manager module. - */ -static void zclient_sync_init(void) -{ - struct zclient_options options = zclient_options_default; - - options.synchronous = true; - - /* Initialize special zclient for synchronous message exchanges. */ - zclient_sync = zclient_new(master, &options, NULL, 0); - zclient_sync->sock = -1; - zclient_sync->redist_default = ZEBRA_ROUTE_LDP; - zclient_sync->session_id = 1; /* Distinguish from main session */ - zclient_sync->privs = &lde_privs; - - if (zclient_socket_connect(zclient_sync) < 0) { - log_warnx("Error connecting synchronous zclient!"); - goto retry; - } - /* make socket non-blocking */ - sock_set_nonblock(zclient_sync->sock); - - /* Send hello to notify zebra this is a synchronous client */ - if (zclient_send_hello(zclient_sync) == ZCLIENT_SEND_FAILURE) { - log_warnx("Error sending hello for synchronous zclient!"); - goto retry; - } - - /* Connect to label manager */ - if (lm_label_manager_connect(zclient_sync, 0) != 0) { - log_warnx("Error connecting to label manager!"); - goto retry; - } - - /* Finish label-manager init once the LM session is running */ - lde_label_list_init(); - - return; - -retry: - - /* Discard failed zclient object */ - zclient_stop(zclient_sync); - zclient_free(zclient_sync); - zclient_sync = NULL; - - /* Retry using a timer */ - event_add_timer(master, zclient_sync_retry, NULL, 1, NULL); -} - static void lde_del_label_chunk(void *val) { diff --git a/ldpd/lde.h b/ldpd/lde.h index 2688b6a86bcb..2ff3c1b00b0f 100644 --- a/ldpd/lde.h +++ b/ldpd/lde.h @@ -251,4 +251,6 @@ int l2vpn_pw_status_update(struct zapi_pw_status *); void l2vpn_pw_ctl(pid_t); void l2vpn_binding_ctl(pid_t); +extern struct zclient *zclient_sync; + #endif /* _LDE_H_ */ diff --git a/ldpd/ldp_zebra.c b/ldpd/ldp_zebra.c index 2010829035a1..2bc420038cd8 100644 --- a/ldpd/ldp_zebra.c +++ b/ldpd/ldp_zebra.c @@ -39,6 +39,9 @@ static int ldp_zebra_opaque_msg_handler(ZAPI_CALLBACK_ARGS); static void ldp_sync_zebra_init(void); static struct zclient *zclient; +/* Synchronous zclient to request labels */ +struct zclient *zclient_sync; +extern struct zebra_privs_t lde_privs; static bool zebra_registered = false; static void @@ -696,6 +699,67 @@ void ldp_zebra_init(struct event_loop *master) access_list_delete_hook(ldp_zebra_filter_update); } +/* + * Event callback used to retry the label-manager sync zapi session. + */ +static void zclient_sync_retry(struct event *thread) +{ + zclient_sync_init(); +} + +/* + * Initialize and open a synchronous zapi session. This is used by label chunk + * management code, which acquires and releases blocks of labels from the + * zebra label-manager module. + */ +static void zclient_sync_init(void) +{ + struct zclient_options options = zclient_options_default; + + options.synchronous = true; + + /* Initialize special zclient for synchronous message exchanges. */ + zclient_sync = zclient_new(master, &options, NULL, 0); + zclient_sync->sock = -1; + zclient_sync->redist_default = ZEBRA_ROUTE_LDP; + zclient_sync->session_id = 1; /* Distinguish from main session */ + zclient_sync->privs = &lde_privs; + + if (zclient_socket_connect(zclient_sync) < 0) { + log_warnx("Error connecting synchronous zclient!"); + goto retry; + } + /* make socket non-blocking */ + sock_set_nonblock(zclient_sync->sock); + + /* Send hello to notify zebra this is a synchronous client */ + if (zclient_send_hello(zclient_sync) == ZCLIENT_SEND_FAILURE) { + log_warnx("Error sending hello for synchronous zclient!"); + goto retry; + } + + /* Connect to label manager */ + if (lm_label_manager_connect(zclient_sync, 0) != 0) { + log_warnx("Error connecting to label manager!"); + goto retry; + } + + /* Finish label-manager init once the LM session is running */ + lde_label_list_init(); + + return; + +retry: + + /* Discard failed zclient object */ + zclient_stop(zclient_sync); + zclient_free(zclient_sync); + zclient_sync = NULL; + + /* Retry using a timer */ + event_add_timer(master, zclient_sync_retry, NULL, 1, NULL); +} + void ldp_zebra_destroy(void) { @@ -703,4 +767,7 @@ ldp_zebra_destroy(void) zclient_stop(zclient); zclient_free(zclient); zclient = NULL; + zclient_stop(zclient_sync); + zclient_free(zclient_sync); + zclient_sync = NULL; }