Skip to content

Commit

Permalink
ldpd: use a timer instead of sleeping in LM init
Browse files Browse the repository at this point in the history
Stop sleeping if synchronous label-manager zapi session
has trouble during init: retry using a timer instead. Move
initial label-block request to a point where the LM zapi
session is known to be running.

Signed-off-by: Mark Stapp <mjs@voltanet.io>
  • Loading branch information
Mark Stapp committed Apr 22, 2020
1 parent 0f90b81 commit 4b747fa
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions ldpd/lde.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ lde_init(struct ldpd_init *init)
frr_zclient_addr(&zclient_addr, &zclient_addr_len,
init->zclient_serv_path);
zclient_sync_init(init->instance);
lde_label_list_init();
}

static void
Expand Down Expand Up @@ -1746,9 +1745,19 @@ lde_address_list_free(struct lde_nbr *ln)
free(lde_addr);
}

static int zclient_sync_retry(struct thread *thread)
{
unsigned short instance = (intptr_t)THREAD_ARG(thread);

zclient_sync_init(instance);

return 0;
}

static void zclient_sync_init(unsigned short instance)
{
struct zclient_options options = zclient_options_default;

options.synchronous = true;

/* Initialize special zclient for synchronous message exchanges. */
Expand All @@ -1759,24 +1768,40 @@ static void zclient_sync_init(unsigned short instance)
zclient_sync->session_id = 1; /* Distinguish from main session */
zclient_sync->privs = &lde_privs;

while (zclient_socket_connect(zclient_sync) < 0) {
if (zclient_socket_connect(zclient_sync) < 0) {
log_warnx("Error connecting synchronous zclient!");
sleep(1);
goto retry;
}
/* make socket non-blocking */
sock_set_nonblock(zclient_sync->sock);

/* Send hello to notify zebra this is a synchronous client */
while (zclient_send_hello(zclient_sync) < 0) {
if (zclient_send_hello(zclient_sync) < 0) {
log_warnx("Error sending hello for synchronous zclient!");
sleep(1);
goto retry;
}

/* Connect to label manager */
while (lm_label_manager_connect(zclient_sync, 0) != 0) {
if (lm_label_manager_connect(zclient_sync, 0) != 0) {
log_warnx("Error connecting to label manager!");
sleep(1);
goto retry;
}

/* Finish 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 */
thread_add_timer(master, zclient_sync_retry,
(void *)(intptr_t)instance, 1, NULL);
}

static void
Expand Down

0 comments on commit 4b747fa

Please sign in to comment.