]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: add -N/--pathspace option
authorDavid Lamparter <equinox@opensourcerouting.org>
Sun, 27 Aug 2017 19:03:12 +0000 (21:03 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Mon, 28 Aug 2017 21:50:42 +0000 (23:50 +0200)
This allows running the daemons inside of Linux network namespaces
without messing with an additional mount/fs namespace (or a ton of
options).

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
lib/libfrr.c
lib/libfrr.h

index 9944fdd1e163ad6ab8bad34a3f43efb95ede36dd..3e2e0082234b395d8e860bf6175822f46cb8b275 100644 (file)
@@ -101,13 +101,15 @@ static const struct optspec os_always = {
 static const struct option lo_cfg_pid_dry[] = {
        {"pid_file", required_argument, NULL, 'i'},
        {"config_file", required_argument, NULL, 'f'},
+       {"pathspace", required_argument, NULL, 'N'},
        {"dryrun", no_argument, NULL, 'C'},
        {"terminal", no_argument, NULL, 't'},
        {NULL}};
 static const struct optspec os_cfg_pid_dry = {
-       "f:i:Ct",
+       "f:i:CtN:",
        "  -f, --config_file  Set configuration file name\n"
        "  -i, --pid_file     Set process identifier file name\n"
+       "  -N, --pathspace    Insert prefix into config & socket paths\n"
        "  -C, --dryrun       Check configuration for validity and exit\n"
        "  -t, --terminal     Open terminal session on stdio\n"
        "  -d -t              Daemonize after terminal session ends\n",
@@ -351,6 +353,23 @@ static int frr_opt(int opt)
                        return 1;
                di->config_file = optarg;
                break;
+       case 'N':
+               if (di->flags & FRR_NO_CFG_PID_DRY)
+                       return 1;
+               if (di->pathspace) {
+                       fprintf(stderr,
+                               "-N/--pathspace option specified more than once!\n");
+                       errors++;
+                       break;
+               }
+               if (strchr(optarg, '/') || strchr(optarg, '.')) {
+                       fprintf(stderr,
+                               "slashes or dots are not permitted in the --pathspace option.\n");
+                       errors++;
+                       break;
+               }
+               di->pathspace = optarg;
+               break;
        case 'C':
                if (di->flags & FRR_NO_CFG_PID_DRY)
                        return 1;
@@ -500,14 +519,25 @@ struct thread_master *frr_init(void)
        struct option_chain *oc;
        struct frrmod_runtime *module;
        char moderr[256];
+       char p_instance[16] = "", p_pathspace[256] = "";
        const char *dir;
        dir = di->module_path ? di->module_path : frr_moduledir;
 
        srandom(time(NULL));
 
-       if (di->instance)
+       if (di->instance) {
                snprintf(frr_protonameinst, sizeof(frr_protonameinst), "%s[%u]",
                         di->logname, di->instance);
+               snprintf(p_instance, sizeof(p_instance), "-%d", di->instance);
+       }
+       if (di->pathspace)
+               snprintf(p_pathspace, sizeof(p_pathspace), "/%s",
+                        di->pathspace);
+
+       snprintf(config_default, sizeof(config_default), "%s%s/%s%s.conf",
+                frr_sysconfdir, p_pathspace, di->name, p_instance);
+       snprintf(pidfile_default, sizeof(pidfile_default), "%s%s/%s%s.pid",
+                frr_vtydir, p_pathspace, di->name, p_instance);
 
        zprivs_preinit(di->privs);
 
@@ -695,14 +725,6 @@ void frr_config_fork(void)
 {
        hook_call(frr_late_init, master);
 
-       if (di->instance) {
-               snprintf(config_default, sizeof(config_default),
-                        "%s/%s-%d.conf", frr_sysconfdir, di->name,
-                        di->instance);
-               snprintf(pidfile_default, sizeof(pidfile_default),
-                        "%s/%s-%d.pid", frr_vtydir, di->name, di->instance);
-       }
-
        vty_read_config(di->config_file, config_default);
 
        /* Don't start execution if we are in dry-run mode */
@@ -723,7 +745,13 @@ void frr_vty_serv(void)
         * (not currently set anywhere) */
        if (!di->vty_path) {
                const char *dir;
-               dir = di->vty_sock_path ? di->vty_sock_path : frr_vtydir;
+               char defvtydir[256];
+
+               snprintf(defvtydir, sizeof(defvtydir), "%s%s%s", frr_vtydir,
+                        di->pathspace ? "/" : "",
+                        di->pathspace ? di->pathspace : "");
+
+               dir = di->vty_sock_path ? di->vty_sock_path : defvtydir;
 
                if (di->instance)
                        snprintf(vtypath_default, sizeof(vtypath_default),
index f7d69eecb3fbe004f8df52210fdc64d68cb5f0cb..fe6c46670a3c6b312cb83fcd59b535a0d7f3c623 100644 (file)
@@ -54,6 +54,7 @@ struct frr_daemon_info {
        const char *pid_file;
        const char *vty_path;
        const char *module_path;
+       const char *pathspace;
 
        const char *proghelp;
        void (*printhelp)(FILE *target);