summaryrefslogtreecommitdiff
path: root/zebra/zserv.c
diff options
context:
space:
mode:
authorJafar Al-Gharaibeh <jafar@atcorp.com>2024-12-03 14:26:09 -0600
committerGitHub <noreply@github.com>2024-12-03 14:26:09 -0600
commit71f9899bc4686bf211ba069fbce8045d61ba8e4c (patch)
treee1982aa760373e0576112fc3f9e7c35daebabbb1 /zebra/zserv.c
parente9c9db0122ec29d7d97d11d93d14e2b04efe191a (diff)
parent506097a1b96974c261411edd25330ceaf90fa3db (diff)
Merge pull request #17313 from mjstapp/zserv_open_unpriv
zebra: separate zebra ZAPI server open and accept
Diffstat (limited to 'zebra/zserv.c')
-rw-r--r--zebra/zserv.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/zebra/zserv.c b/zebra/zserv.c
index 07e3996643..d6c017d259 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;
@@ -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;
@@ -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;
}
@@ -986,7 +1014,7 @@ void zserv_start(char *path)
return;
}
- umask(old_mask);
+ started_p = true;
zserv_event(NULL, ZSERV_ACCEPT);
}