summaryrefslogtreecommitdiff
path: root/lib/libfrr.c
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2017-08-27 21:03:12 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2017-08-28 23:50:42 +0200
commitd1b4fc1f896b3dea3865869166614e99bad6623a (patch)
treeda5a9559044c74800349146b865c3a17433701d7 /lib/libfrr.c
parent9b8a82496a677e1ec0509f66026f6c3ef4ee3365 (diff)
lib: add -N/--pathspace option
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>
Diffstat (limited to 'lib/libfrr.c')
-rw-r--r--lib/libfrr.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/lib/libfrr.c b/lib/libfrr.c
index 9944fdd1e1..3e2e008223 100644
--- a/lib/libfrr.c
+++ b/lib/libfrr.c
@@ -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),