Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zebra: separate zebra ZAPI server open and accept #17313

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions zebra/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,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
32 changes: 30 additions & 2 deletions zebra/zserv.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ extern struct zebra_privs_t zserv_privs;

/* The listener socket for clients connecting to us */
static int zsock;
static bool started_p;

/* The lock that protects access to zapi client objects */
static pthread_mutex_t client_mutex;
Expand Down Expand Up @@ -929,9 +930,16 @@ void zserv_close(void)

/* Free client list's mutex */
pthread_mutex_destroy(&client_mutex);

started_p = false;
}

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 +981,26 @@ 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;

/* This may be called more than once during startup - potentially once
* per netns - but only do this work once.
*/
if (started_p)
return;

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

Expand All @@ -986,7 +1014,7 @@ void zserv_start(char *path)
return;
}

umask(old_mask);
started_p = true;

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
Loading