From 3dabc7963b54117b3500aa119ed08250b19e2639 Mon Sep 17 00:00:00 2001 From: jca Date: Tue, 2 Aug 2016 16:05:32 +0000 Subject: [PATCH] Allow specifying an alternate socket path. This allows one to run multiple ripd instances, for example to serve multiple rdomains. Diff from Nima GHOTBI, ok claudio@ florian@ benno@ --- usr.sbin/ripctl/ripctl.c | 27 ++++++++++++++++++++++----- usr.sbin/ripd/control.c | 20 ++++++++++---------- usr.sbin/ripd/control.h | 6 +++--- usr.sbin/ripd/ripd.c | 15 +++++++++++---- usr.sbin/ripd/ripd.h | 3 ++- usr.sbin/ripd/ripe.c | 4 ++-- 6 files changed, 50 insertions(+), 25 deletions(-) diff --git a/usr.sbin/ripctl/ripctl.c b/usr.sbin/ripctl/ripctl.c index cd0a8bcf4b6..051f9cb206f 100644 --- a/usr.sbin/ripctl/ripctl.c +++ b/usr.sbin/ripctl/ripctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ripctl.c,v 1.16 2015/12/05 13:13:47 claudio Exp $ +/* $OpenBSD: ripctl.c,v 1.17 2016/08/02 16:05:32 jca Exp $ * * Copyright (c) 2006 Michele Marchetto * Copyright (c) 2005 Claudio Jeker @@ -59,7 +59,8 @@ usage(void) { extern char *__progname; - fprintf(stderr, "usage: %s command [argument ...]\n", __progname); + fprintf(stderr, "usage: %s [-s socket] command [argument ...]\n", + __progname); exit(1); } @@ -73,9 +74,25 @@ main(int argc, char *argv[]) int ctl_sock; int done = 0, verbose = 0; int n; + int ch; + char *sockname = RIPD_SOCKET; + + while ((ch = getopt(argc, argv, "s:")) != -1) { + switch (ch) { + case 's': + sockname = optarg; + break; + default: + usage(); + /* NOTREACHED */ + } + } + + argc -= optind; + argv += optind; /* parse options */ - if ((res = parse(argc - 1, argv + 1)) == NULL) + if ((res = parse(argc, argv)) == NULL) exit(1); /* connect to ripd control socket */ @@ -84,9 +101,9 @@ main(int argc, char *argv[]) bzero(&sun, sizeof(sun)); sun.sun_family = AF_UNIX; - strlcpy(sun.sun_path, RIPD_SOCKET, sizeof(sun.sun_path)); + strlcpy(sun.sun_path, sockname, sizeof(sun.sun_path)); if (connect(ctl_sock, (struct sockaddr *)&sun, sizeof(sun)) == -1) - err(1, "connect: %s", RIPD_SOCKET); + err(1, "connect: %s", sockname); if (pledge("stdio", NULL) == -1) err(1, "pledge"); diff --git a/usr.sbin/ripd/control.c b/usr.sbin/ripd/control.c index c39aa1b2228..1d6cc4821de 100644 --- a/usr.sbin/ripd/control.c +++ b/usr.sbin/ripd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.22 2015/12/05 13:13:47 claudio Exp $ */ +/* $OpenBSD: control.c,v 1.23 2016/08/02 16:05:32 jca Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -39,7 +39,7 @@ struct ctl_conn *control_connbypid(pid_t); void control_close(int); int -control_init(void) +control_init(char *path) { struct sockaddr_un sun; int fd; @@ -53,28 +53,28 @@ control_init(void) bzero(&sun, sizeof(sun)); sun.sun_family = AF_UNIX; - strlcpy(sun.sun_path, RIPD_SOCKET, sizeof(sun.sun_path)); + strlcpy(sun.sun_path, path, sizeof(sun.sun_path)); - if (unlink(RIPD_SOCKET) == -1) + if (unlink(path) == -1) if (errno != ENOENT) { - log_warn("control_init: unlink %s", RIPD_SOCKET); + log_warn("control_init: unlink %s", path); close(fd); return (-1); } old_umask = umask(S_IXUSR|S_IXGRP|S_IWOTH|S_IROTH|S_IXOTH); if (bind(fd, (struct sockaddr *)&sun, sizeof(sun)) == -1) { - log_warn("control_init: bind: %s", RIPD_SOCKET); + log_warn("control_init: bind: %s", path); close(fd); umask(old_umask); return (-1); } umask(old_umask); - if (chmod(RIPD_SOCKET, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) { + if (chmod(path, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) == -1) { log_warn("control_init: chmod"); close(fd); - (void)unlink(RIPD_SOCKET); + (void)unlink(path); return (-1); } @@ -101,11 +101,11 @@ control_listen(void) } void -control_cleanup(void) +control_cleanup(char *path) { event_del(&control_state.ev); event_del(&control_state.evt); - unlink(RIPD_SOCKET); + unlink(path); } /* ARGSUSED */ diff --git a/usr.sbin/ripd/control.h b/usr.sbin/ripd/control.h index 67306ac4820..98df4ee5645 100644 --- a/usr.sbin/ripd/control.h +++ b/usr.sbin/ripd/control.h @@ -1,4 +1,4 @@ -/* $OpenBSD: control.h,v 1.4 2015/02/09 12:13:42 claudio Exp $ */ +/* $OpenBSD: control.h,v 1.5 2016/08/02 16:05:32 jca Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -34,11 +34,11 @@ struct ctl_conn { struct imsgev iev; }; -int control_init(void); +int control_init(char *); int control_listen(void); void control_accept(int, short, void *); void control_dispatch_imsg(int, short, void *); int control_imsg_relay(struct imsg *); -void control_cleanup(void); +void control_cleanup(char *); #endif /* _CONTROL_H_ */ diff --git a/usr.sbin/ripd/ripd.c b/usr.sbin/ripd/ripd.c index da0d8f3f702..1ffaf95146e 100644 --- a/usr.sbin/ripd/ripd.c +++ b/usr.sbin/ripd/ripd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ripd.c,v 1.27 2016/02/02 17:51:11 sthen Exp $ */ +/* $OpenBSD: ripd.c,v 1.28 2016/08/02 16:05:32 jca Exp $ */ /* * Copyright (c) 2006 Michele Marchetto @@ -70,7 +70,8 @@ usage(void) { extern char *__progname; - fprintf(stderr, "usage: %s [-dnv] [-D macro=value] [-f file]\n", + fprintf(stderr, + "usage: %s [-dnv] [-D macro=value] [-f file] [-s socket]\n", __progname); exit(1); } @@ -122,15 +123,17 @@ main(int argc, char *argv[]) int ch; int opts = 0; char *conffile; + char *sockname; size_t len; conffile = CONF_FILE; ripd_process = PROC_MAIN; + sockname = RIPD_SOCKET; log_init(1); /* log to stderr until daemonized */ log_verbose(1); - while ((ch = getopt(argc, argv, "cdD:f:nv")) != -1) { + while ((ch = getopt(argc, argv, "cdD:f:ns:v")) != -1) { switch (ch) { case 'c': opts |= RIPD_OPT_FORCE_DEMOTE; @@ -149,6 +152,9 @@ main(int argc, char *argv[]) case 'n': opts |= RIPD_OPT_NOACTION; break; + case 's': + sockname = optarg; + break; case 'v': if (opts & RIPD_OPT_VERBOSE) opts |= RIPD_OPT_VERBOSE2; @@ -182,6 +188,7 @@ main(int argc, char *argv[]) /* parse config file */ if ((conf = parse_config(conffile, opts)) == NULL ) exit(1); + conf->csock = sockname; if (conf->opts & RIPD_OPT_NOACTION) { if (conf->opts & RIPD_OPT_VERBOSE) @@ -287,7 +294,7 @@ ripd_shutdown(void) if_del(i); } - control_cleanup(); + control_cleanup(conf->csock); kr_shutdown(); do { diff --git a/usr.sbin/ripd/ripd.h b/usr.sbin/ripd/ripd.h index acaa5cc69b7..b5ed21592c4 100644 --- a/usr.sbin/ripd/ripd.h +++ b/usr.sbin/ripd/ripd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ripd.h,v 1.22 2015/09/27 17:32:36 stsp Exp $ */ +/* $OpenBSD: ripd.h,v 1.23 2016/08/02 16:05:32 jca Exp $ */ /* * Copyright (c) 2004 Esben Norby @@ -239,6 +239,7 @@ struct ripd_conf { int rip_socket; int redistribute; u_int rdomain; + char *csock; }; /* kroute */ diff --git a/usr.sbin/ripd/ripe.c b/usr.sbin/ripd/ripe.c index 48d6aae1f26..36d91c435f0 100644 --- a/usr.sbin/ripd/ripe.c +++ b/usr.sbin/ripd/ripe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ripe.c,v 1.19 2015/12/05 13:13:47 claudio Exp $ */ +/* $OpenBSD: ripe.c,v 1.20 2016/08/02 16:05:32 jca Exp $ */ /* * Copyright (c) 2006 Michele Marchetto @@ -85,7 +85,7 @@ ripe(struct ripd_conf *xconf, int pipe_parent2ripe[2], int pipe_ripe2rde[2], } /* create ripd control socket outside chroot */ - if (control_init() == -1) + if (control_init(xconf->csock) == -1) fatalx("control socket setup failed"); addr.sin_family = AF_INET; -- 2.20.1