diff options
| author | Mark Stapp <mjs@cisco.com> | 2024-10-30 11:02:17 -0400 |
|---|---|---|
| committer | Mergify <37929162+mergify[bot]@users.noreply.github.com> | 2024-12-03 20:27:50 +0000 |
| commit | 9e67464d77594b59d8d30c3e633bf596fe701752 (patch) | |
| tree | 5019c0f6029c352e1d4398d85af1e35771e3f0e6 /zebra | |
| parent | dafe8e9d46c188449e422b45a7bcbaf7b36c6b58 (diff) | |
zebra: separate zebra ZAPI server open and accept
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 <mjs@cisco.com>
(cherry picked from commit 506097a1b96974c261411edd25330ceaf90fa3db)
Diffstat (limited to 'zebra')
| -rw-r--r-- | zebra/main.c | 3 | ||||
| -rw-r--r-- | zebra/zserv.c | 32 | ||||
| -rw-r--r-- | zebra/zserv.h | 15 |
3 files changed, 45 insertions, 5 deletions
diff --git a/zebra/main.c b/zebra/main.c index 7fcbfa1396..a022017d24 100644 --- a/zebra/main.c +++ b/zebra/main.c @@ -442,6 +442,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. */ diff --git a/zebra/zserv.c b/zebra/zserv.c index 6a64176d98..d7d9f3364c 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -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; @@ -890,9 +891,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; @@ -934,6 +942,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; } @@ -947,7 +975,7 @@ void zserv_start(char *path) return; } - umask(old_mask); + started_p = true; zserv_event(NULL, ZSERV_ACCEPT); } diff --git a/zebra/zserv.h b/zebra/zserv.h index e1c990fb05..57916ab354 100644 --- a/zebra/zserv.h +++ b/zebra/zserv.h @@ -254,15 +254,24 @@ 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. |
