]> git.proxmox.com Git - mirror_frr.git/commitdiff
ldpd: add ctl_socket cli option to override the compiled-in location for the control...
authorRenato Westphal <renato@opensourcerouting.org>
Tue, 24 Jan 2017 17:31:40 +0000 (00:31 +0700)
committerMartin Winter <mwinter@opensourcerouting.org>
Wed, 25 Jan 2017 17:44:42 +0000 (00:44 +0700)
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ldpd/control.c
ldpd/ldp_vty_exec.c
ldpd/ldpd.c
ldpd/ldpd.h
ldpd/ldpe.c
ldpd/ldpe.h

index ba303cc12cdf62694b4f555589f27e1b1e8eea3e..8a2280be07bf54ae36e0d1bb91655a635415bb53 100644 (file)
@@ -51,28 +51,28 @@ control_init(void)
 
        memset(&s_un, 0, sizeof(s_un));
        s_un.sun_family = AF_UNIX;
-       strlcpy(s_un.sun_path, LDPD_SOCKET, sizeof(s_un.sun_path));
+       strlcpy(s_un.sun_path, ctl_sock_path, sizeof(s_un.sun_path));
 
-       if (unlink(LDPD_SOCKET) == -1)
+       if (unlink(ctl_sock_path) == -1)
                if (errno != ENOENT) {
-                       log_warn("%s: unlink %s", __func__, LDPD_SOCKET);
+                       log_warn("%s: unlink %s", __func__, ctl_sock_path);
                        close(fd);
                        return (-1);
                }
 
        old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH);
        if (bind(fd, (struct sockaddr *)&s_un, sizeof(s_un)) == -1) {
-               log_warn("%s: bind: %s", __func__, LDPD_SOCKET);
+               log_warn("%s: bind: %s", __func__, ctl_sock_path);
                close(fd);
                umask(old_umask);
                return (-1);
        }
        umask(old_umask);
 
-       if (chmod(LDPD_SOCKET, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) {
+       if (chmod(ctl_sock_path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) {
                log_warn("%s: chmod", __func__);
                close(fd);
-               (void)unlink(LDPD_SOCKET);
+               (void)unlink(ctl_sock_path);
                return (-1);
        }
 
@@ -97,7 +97,7 @@ control_cleanup(void)
 {
        accept_del(control_fd);
        close(control_fd);
-       unlink(LDPD_SOCKET);
+       unlink(ctl_sock_path);
 }
 
 /* ARGSUSED */
index a57cf3c3f6b7bf6ff16d539d274431160de17d06..a9138be2f2491035d66bfbc2884829e0dd81485e 100644 (file)
@@ -405,9 +405,9 @@ ldp_vty_connect(struct imsgbuf *ibuf)
 
        memset(&s_un, 0, sizeof(s_un));
        s_un.sun_family = AF_UNIX;
-       strlcpy(s_un.sun_path, LDPD_SOCKET, sizeof(s_un.sun_path));
+       strlcpy(s_un.sun_path, ctl_sock_path, sizeof(s_un.sun_path));
        if (connect(ctl_sock, (struct sockaddr *)&s_un, sizeof(s_un)) == -1) {
-               log_warn("%s: connect: %s", __func__, LDPD_SOCKET);
+               log_warn("%s: connect: %s", __func__, ctl_sock_path);
                close(ctl_sock);
                return (-1);
        }
index 5d0e79aec7d409d346f093aaaf91f3e0499b2e0e..40726ba0bb8fb84d0a572e2cc429880f58bfb1d5 100644 (file)
@@ -43,7 +43,7 @@
 
 static void             ldpd_shutdown(void);
 static pid_t            start_child(enum ldpd_process, char *, int,
-                           const char *, const char *);
+                           const char *, const char *, const char *);
 static int              main_dispatch_ldpe(struct thread *);
 static int              main_dispatch_lde(struct thread *);
 static int              main_imsg_send_ipc_sockets(struct imsgbuf *,
@@ -118,8 +118,12 @@ struct zebra_privs_t ldpd_privs =
 /* VTY Socket prefix */
 char vty_sock_path[MAXPATHLEN] = LDP_VTYSH_PATH;
 
+/* CTL Socket path */
+char ctl_sock_path[MAXPATHLEN] = LDPD_SOCKET;
+
 /* LDPd options. */
 #define OPTION_VTYSOCK 1000
+#define OPTION_CTLSOCK 1001
 static struct option longopts[] =
 {
        { "daemon",      no_argument,       NULL, 'd'},
@@ -131,6 +135,7 @@ static struct option longopts[] =
        { "vty_addr",    required_argument, NULL, 'A'},
        { "vty_port",    required_argument, NULL, 'P'},
        { "vty_socket",  required_argument, NULL, OPTION_VTYSOCK},
+       { "ctl_socket",  required_argument, NULL, OPTION_CTLSOCK},
        { "user",        required_argument, NULL, 'u'},
        { "group",       required_argument, NULL, 'g'},
        { "version",     no_argument,       NULL, 'v'},
@@ -154,6 +159,7 @@ Daemon which manages LDP.\n\n\
 -A, --vty_addr     Set vty's bind address\n\
 -P, --vty_port     Set vty's port number\n\
     --vty_socket   Override vty socket path\n\
+    --ctl_socket   Override ctl socket path\n\
 -u, --user         User to run as\n\
 -g, --group        Group to run as\n\
 -v, --version      Print program version\n\
@@ -219,6 +225,8 @@ main(int argc, char *argv[])
        char                    *vty_addr = NULL;
        int                      vty_port = LDP_VTY_PORT;
        char                    *vty_sock_name;
+       char                    *ctl_sock_custom_path = NULL;
+       char                    *ctl_sock_name;
        int                      daemon_mode = 0;
        const char              *user = NULL;
        const char              *group = NULL;
@@ -282,6 +290,25 @@ main(int argc, char *argv[])
                case OPTION_VTYSOCK:
                        set_socket_path(vty_sock_path, LDP_VTYSH_PATH, optarg, sizeof (vty_sock_path));
                        break;
+               case OPTION_CTLSOCK:
+                       ctl_sock_name = strrchr(LDPD_SOCKET, '/');
+                       if (ctl_sock_name)
+                               /* skip '/' */
+                               ctl_sock_name++;
+                       else
+                               /*
+                                * LDPD_SOCKET configured as relative path
+                                * during config? Should really never happen for
+                                * sensible config
+                                */
+                               ctl_sock_name = (char *)LDPD_SOCKET;
+                       ctl_sock_custom_path = optarg;
+                       strlcpy(ctl_sock_path, ctl_sock_custom_path,
+                           sizeof(ctl_sock_path));
+                       strlcat(ctl_sock_path, "/", sizeof(ctl_sock_path));
+                       strlcat(ctl_sock_path, ctl_sock_name,
+                           sizeof(ctl_sock_path));
+                       break;
                case 'u':
                        user = optarg;
                        break;
@@ -328,7 +355,7 @@ main(int argc, char *argv[])
        if (lflag)
                lde(user, group);
        else if (eflag)
-               ldpe(user, group);
+               ldpe(user, group, ctl_sock_path);
 
        master = thread_master_create();
 
@@ -370,9 +397,9 @@ main(int argc, char *argv[])
 
        /* start children */
        lde_pid = start_child(PROC_LDE_ENGINE, saved_argv0,
-           pipe_parent2lde[1], user, group);
+           pipe_parent2lde[1], user, group, ctl_sock_custom_path);
        ldpe_pid = start_child(PROC_LDP_ENGINE, saved_argv0,
-           pipe_parent2ldpe[1], user, group);
+           pipe_parent2ldpe[1], user, group, ctl_sock_custom_path);
 
        /* drop privileges */
        if (user)
@@ -468,9 +495,9 @@ ldpd_shutdown(void)
 
 static pid_t
 start_child(enum ldpd_process p, char *argv0, int fd, const char *user,
-    const char *group)
+    const char *group, const char *ctl_sock_custom_path)
 {
-       char    *argv[7];
+       char    *argv[9];
        int      argc = 0;
        pid_t    pid;
 
@@ -506,6 +533,10 @@ start_child(enum ldpd_process p, char *argv0, int fd, const char *user,
                argv[argc++] = (char *)"-g";
                argv[argc++] = (char *)group;
        }
+       if (ctl_sock_custom_path) {
+               argv[argc++] = (char *)"--ctl_socket";
+               argv[argc++] = (char *)ctl_sock_custom_path;
+       }
        argv[argc++] = NULL;
 
        execvp(argv0, argv);
index 630b192489d2625d9a758fb8fbfc6c9cfb316459..e58d8e4852c5706336e97562e9b0ced2c48cc99d 100644 (file)
@@ -672,6 +672,7 @@ int          sock_set_ipv6_mcast_loop(int);
 
 /* quagga */
 extern struct thread_master    *master;
+extern char                     ctl_sock_path[MAXPATHLEN];
 
 /* ldp_zebra.c */
 void           ldp_zebra_init(struct thread_master *);
index 37a3d79a289a47328d03b1e87404e78840f70a62..0d0fe5c9e92ab271fc78339f03c9738d83ccce3f 100644 (file)
@@ -99,7 +99,7 @@ static struct quagga_signal_t ldpe_signals[] =
 
 /* label distribution protocol engine */
 void
-ldpe(const char *user, const char *group)
+ldpe(const char *user, const char *group, const char *ctl_path)
 {
        struct thread            thread;
 
@@ -128,6 +128,7 @@ ldpe(const char *user, const char *group)
                ldpe_privs.group = group;
        zprivs_init(&ldpe_privs);
 
+       strlcpy(ctl_sock_path, ctl_path, sizeof(ctl_sock_path));
        if (control_init() == -1)
                fatalx("control socket setup failed");
 
index aab1a7fd9b918cebf6f4f90fb7ee79ff675776b2..da90c7cad777593480c5429da5704d199c1f7efe 100644 (file)
@@ -183,7 +183,7 @@ int  tlv_decode_fec_elm(struct nbr *, struct ldp_msg *, char *,
            uint16_t, struct map *);
 
 /* ldpe.c */
-void            ldpe(const char *, const char *);
+void            ldpe(const char *, const char *, const char *);
 int             ldpe_imsg_compose_parent(int, pid_t, void *,
                    uint16_t);
 int             ldpe_imsg_compose_lde(int, uint32_t, pid_t, void *,