Skip to content

Commit

Permalink
zebra: separate zebra ZAPI server open and accept
Browse files Browse the repository at this point in the history
Separate zebra's ZAPI server socket handling into two phases:
an early phase that opens the socket, and a later phase that
starts listening for client connections.

Signed-off-by: Mark Stapp <[email protected]>
  • Loading branch information
Mark Stapp committed Oct 30, 2024
1 parent 1668f32 commit 0da248f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
3 changes: 3 additions & 0 deletions zebra/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ int main(int argc, char **argv)
zebra_if_init();
zebra_debug_init();

/* Open Zebra API server socket */
zserv_open(zserv_path);

/*
* Initialize NS( and implicitly the VRF module), and make kernel
* routing socket. */
Expand Down
23 changes: 20 additions & 3 deletions zebra/zserv.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,12 @@ void zserv_close(void)
pthread_mutex_destroy(&client_mutex);
}

void zserv_start(char *path)

/*
* Open zebra's ZAPI listener socket. This is done early during startup,
* before zebra is ready to listen and accept client connections.
*/
void zserv_open(const char *path)
{
int ret;
mode_t old_mask;
Expand Down Expand Up @@ -973,6 +978,20 @@ void zserv_start(char *path)
path, safe_strerror(errno));
close(zsock);
zsock = -1;
}

umask(old_mask);
}

/*
* Start listening for ZAPI client connections.
*/
void zserv_start(const char *path)
{
int ret;

if (zsock <= 0) {
flog_err_sys(EC_LIB_SOCKET, "Zserv socket open failed");
return;
}

Expand All @@ -986,8 +1005,6 @@ void zserv_start(char *path)
return;
}

umask(old_mask);

zserv_event(NULL, ZSERV_ACCEPT);
}

Expand Down
15 changes: 12 additions & 3 deletions zebra/zserv.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,16 +255,25 @@ extern void zserv_init(void);
*/
extern void zserv_close(void);

/*
* Open Zebra API server socket.
*
* Create and open the server socket.
*
* path
* where to place the Unix domain socket
*/
extern void zserv_open(const char *path);

/*
* Start Zebra API server.
*
* Allocates resources, creates the server socket and begins listening on the
* socket.
* Allocates resources and begins listening on the server socket.
*
* path
* where to place the Unix domain socket
*/
extern void zserv_start(char *path);
extern void zserv_start(const char *path);

/*
* Send a message to a connected Zebra API client.
Expand Down

0 comments on commit 0da248f

Please sign in to comment.