]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: separate zebra ZAPI server open and accept
authorMark Stapp <mjs@cisco.com>
Wed, 30 Oct 2024 15:02:17 +0000 (11:02 -0400)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Tue, 3 Dec 2024 20:27:25 +0000 (20:27 +0000)
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)

zebra/main.c
zebra/zserv.c
zebra/zserv.h

index 8cac3649167584b2631409c272da363a659e6be2..2365ed0e113f2b3c867f62de81e4a4ebd9e9fa9f 100644 (file)
@@ -445,6 +445,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. */
index 27668534ee99e2af25d6abcda8ffb479736385ed..d879d311b4b1c3d4f055048f690629eededc505a 100644 (file)
@@ -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;
@@ -925,9 +926,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;
@@ -969,6 +977,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;
        }
 
@@ -982,7 +1010,7 @@ void zserv_start(char *path)
                return;
        }
 
-       umask(old_mask);
+       started_p = true;
 
        zserv_event(NULL, ZSERV_ACCEPT);
 }
index 57d673060fe75bd6284a53b6db44e41a4ec3dfc0..d21a380b4d1637108aa8f360efcc63a3c6af35d7 100644 (file)
@@ -253,16 +253,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.