summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Stapp <mjs.ietf@gmail.com>2024-12-04 11:40:30 -0500
committerGitHub <noreply@github.com>2024-12-04 11:40:30 -0500
commit1d8c0479253abf8d1bc622dbc9b177b5cad4d52b (patch)
tree8be324feddba3e9c2f57f33a9cc26221806b035f
parentebefd4e74fc6fe0bc69161367abf4049838eb512 (diff)
parent6f677fcb0c000d1331ce86eb573a3c02d040f9b4 (diff)
Merge pull request #17561 from FRRouting/mergify/bp/stable/9.1/pr-17313
zebra: separate zebra ZAPI server open and accept (backport #17313)
-rw-r--r--zebra/main.c3
-rw-r--r--zebra/zserv.c32
-rw-r--r--zebra/zserv.h15
3 files changed, 45 insertions, 5 deletions
diff --git a/zebra/main.c b/zebra/main.c
index 0b9df2b698..24b2f3e9d6 100644
--- a/zebra/main.c
+++ b/zebra/main.c
@@ -418,6 +418,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 2db228b158..d45e33899f 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 90aa4d53f4..c6ad902339 100644
--- a/zebra/zserv.h
+++ b/zebra/zserv.h
@@ -255,15 +255,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.