Skip to content

Commit

Permalink
ldpd: Stop and free synchronous Zebra client on destroy
Browse files Browse the repository at this point in the history
Signed-off-by: Donatas Abraitis <[email protected]>
  • Loading branch information
ton31337 committed Jun 25, 2023
1 parent 356d0ec commit 4de8e88
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 64 deletions.
64 changes: 0 additions & 64 deletions ldpd/lde.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 2 additions & 0 deletions ldpd/lde.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_ */
67 changes: 67 additions & 0 deletions ldpd/ldp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -696,11 +699,75 @@ 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)
{
ldp_zebra_opaque_unregister();
zclient_stop(zclient);
zclient_free(zclient);
zclient = NULL;
zclient_stop(zclient_sync);
zclient_free(zclient_sync);
zclient_sync = NULL;
}

0 comments on commit 4de8e88

Please sign in to comment.