summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsthen <sthen@openbsd.org>2013-03-22 14:25:31 +0000
committersthen <sthen@openbsd.org>2013-03-22 14:25:31 +0000
commitc2ca8945d3d61575fe2fca6a0ab311759a7eeea4 (patch)
tree0ec1c13bdd02639f5ee9dcfeae1159028dc30b9a
parentsync comment typos/whitespace with ospfd (diff)
downloadwireguard-openbsd-c2ca8945d3d61575fe2fca6a0ab311759a7eeea4.tar.xz
wireguard-openbsd-c2ca8945d3d61575fe2fca6a0ab311759a7eeea4.zip
Allow use of an alternative control socket, ported from ospfd. ok claudio@
-rw-r--r--usr.sbin/ospf6ctl/ospf6ctl.815
-rw-r--r--usr.sbin/ospf6ctl/ospf6ctl.c27
-rw-r--r--usr.sbin/ospf6d/control.c21
-rw-r--r--usr.sbin/ospf6d/control.h6
-rw-r--r--usr.sbin/ospf6d/ospf6d.87
-rw-r--r--usr.sbin/ospf6d/ospf6d.c15
-rw-r--r--usr.sbin/ospf6d/ospf6d.h3
-rw-r--r--usr.sbin/ospf6d/ospfe.c4
8 files changed, 69 insertions, 29 deletions
diff --git a/usr.sbin/ospf6ctl/ospf6ctl.8 b/usr.sbin/ospf6ctl/ospf6ctl.8
index 4600ae3e348..0e1afacf86f 100644
--- a/usr.sbin/ospf6ctl/ospf6ctl.8
+++ b/usr.sbin/ospf6ctl/ospf6ctl.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ospf6ctl.8,v 1.7 2010/05/10 18:46:07 sthen Exp $
+.\" $OpenBSD: ospf6ctl.8,v 1.8 2013/03/22 14:25:31 sthen Exp $
.\"
.\" Copyright (c) 2004, 2005, 2007 Esben Norby <norby@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: May 10 2010 $
+.Dd $Mdocdate: March 22 2013 $
.Dt OSPF6CTL 8
.Os
.Sh NAME
@@ -30,6 +30,17 @@ The
program controls the
.Xr ospf6d 8
daemon.
+.Pp
+The following option is available:
+.Bl -tag -width Ds
+.It Fl s Ar socket
+Use
+.Ar socket
+instead of the default
+.Pa /var/run/ospfd.sock
+to communicate with
+.Xr ospfd 8 .
+.El
Commands may be abbreviated to the minimum unambiguous prefix; for example,
.Cm s s
for
diff --git a/usr.sbin/ospf6ctl/ospf6ctl.c b/usr.sbin/ospf6ctl/ospf6ctl.c
index ac8c0b182e3..3653a638da8 100644
--- a/usr.sbin/ospf6ctl/ospf6ctl.c
+++ b/usr.sbin/ospf6ctl/ospf6ctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospf6ctl.c,v 1.36 2011/05/05 15:58:53 claudio Exp $ */
+/* $OpenBSD: ospf6ctl.c,v 1.37 2013/03/22 14:25:31 sthen Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -77,7 +77,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);
}
@@ -91,9 +92,25 @@ main(int argc, char *argv[])
int ctl_sock;
int done = 0, verbose = 0;
int n;
+ int ch;
+ char *sockname;
+
+ sockname = OSPF6D_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 ospf6d control socket */
@@ -102,9 +119,9 @@ main(int argc, char *argv[])
bzero(&sun, sizeof(sun));
sun.sun_family = AF_UNIX;
- strlcpy(sun.sun_path, OSPF6D_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", OSPF6D_SOCKET);
+ err(1, "connect: %s", sockname);
if ((ibuf = malloc(sizeof(struct imsgbuf))) == NULL)
err(1, NULL);
diff --git a/usr.sbin/ospf6d/control.c b/usr.sbin/ospf6d/control.c
index 5404373cfb1..e636938d793 100644
--- a/usr.sbin/ospf6d/control.c
+++ b/usr.sbin/ospf6d/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.19 2013/03/11 17:40:11 deraadt Exp $ */
+/* $OpenBSD: control.c,v 1.20 2013/03/22 14:25:31 sthen Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -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;
@@ -52,28 +52,28 @@ control_init(void)
bzero(&sun, sizeof(sun));
sun.sun_family = AF_UNIX;
- strlcpy(sun.sun_path, OSPF6D_SOCKET, sizeof(sun.sun_path));
+ strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
- if (unlink(OSPF6D_SOCKET) == -1)
+ if (unlink(path) == -1)
if (errno != ENOENT) {
- log_warn("control_init: unlink %s", OSPF6D_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", OSPF6D_SOCKET);
+ log_warn("control_init: bind: %s", path);
close(fd);
umask(old_umask);
return (-1);
}
umask(old_umask);
- if (chmod(OSPF6D_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(OSPF6D_SOCKET);
+ (void)unlink(path);
return (-1);
}
@@ -100,11 +100,12 @@ control_listen(void)
}
void
-control_cleanup(void)
+control_cleanup(char *path)
{
event_del(&control_state.ev);
event_del(&control_state.evt);
- unlink(OSPF6D_SOCKET);
+ if (path)
+ unlink(path);
}
/* ARGSUSED */
diff --git a/usr.sbin/ospf6d/control.h b/usr.sbin/ospf6d/control.h
index d552d3e1b67..939520faec1 100644
--- a/usr.sbin/ospf6d/control.h
+++ b/usr.sbin/ospf6d/control.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.h,v 1.3 2012/04/10 07:56:50 deraadt Exp $ */
+/* $OpenBSD: control.h,v 1.4 2013/03/22 14:25:31 sthen Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -39,12 +39,12 @@ 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 *);
void session_socket_blockmode(int, enum blockmodes);
diff --git a/usr.sbin/ospf6d/ospf6d.8 b/usr.sbin/ospf6d/ospf6d.8
index 5de6a58a643..cb3fad889c2 100644
--- a/usr.sbin/ospf6d/ospf6d.8
+++ b/usr.sbin/ospf6d/ospf6d.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ospf6d.8,v 1.14 2012/09/26 16:19:44 jmc Exp $
+.\" $OpenBSD: ospf6d.8,v 1.15 2013/03/22 14:25:31 sthen Exp $
.\"
.\" Copyright (c) 2004, 2005, 2007 Esben Norby <norby@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: September 26 2012 $
+.Dd $Mdocdate: March 22 2013 $
.Dt OSPF6D 8
.Os
.Sh NAME
@@ -25,6 +25,7 @@
.Op Fl dnv
.Op Fl D Ar macro Ns = Ns Ar value
.Op Fl f Ar file
+.Op Fl s Ar socket
.Sh DESCRIPTION
.Nm
is an Open Shortest Path First
@@ -145,6 +146,8 @@ Specify an alternative configuration file.
.It Fl n
Configtest mode.
Only check the configuration file for validity.
+.it Fl s Ar socket
+Use an alternate location for the default control socket.
.It Fl v
Produce more verbose output.
.El
diff --git a/usr.sbin/ospf6d/ospf6d.c b/usr.sbin/ospf6d/ospf6d.c
index 5583c50479d..40d221a1611 100644
--- a/usr.sbin/ospf6d/ospf6d.c
+++ b/usr.sbin/ospf6d/ospf6d.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospf6d.c,v 1.22 2011/08/20 19:02:28 sthen Exp $ */
+/* $OpenBSD: ospf6d.c,v 1.23 2013/03/22 14:25:31 sthen Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -116,7 +116,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);
}
@@ -130,14 +131,16 @@ main(int argc, char *argv[])
int ipforwarding;
int mib[4];
size_t len;
+ char *sockname;
conffile = CONF_FILE;
ospfd_process = PROC_MAIN;
+ sockname = OSPF6D_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:s:nv")) != -1) {
switch (ch) {
case 'c':
opts |= OSPFD_OPT_FORCE_DEMOTE;
@@ -156,6 +159,9 @@ main(int argc, char *argv[])
case 'n':
opts |= OSPFD_OPT_NOACTION;
break;
+ case 's':
+ sockname = optarg;
+ break;
case 'v':
if (opts & OSPFD_OPT_VERBOSE)
opts |= OSPFD_OPT_VERBOSE2;
@@ -193,6 +199,7 @@ main(int argc, char *argv[])
/* parse config file */
if ((ospfd_conf = parse_config(conffile, opts)) == NULL )
exit(1);
+ ospfd_conf->csock = sockname;
if (ospfd_conf->opts & OSPFD_OPT_NOACTION) {
if (ospfd_conf->opts & OSPFD_OPT_VERBOSE)
@@ -300,7 +307,7 @@ ospfd_shutdown(void)
if (rde_pid)
kill(rde_pid, SIGTERM);
- control_cleanup();
+ control_cleanup(ospfd_conf->csock);
kr_shutdown();
carp_demote_shutdown();
diff --git a/usr.sbin/ospf6d/ospf6d.h b/usr.sbin/ospf6d/ospf6d.h
index 77e9ebf5373..48fec773e76 100644
--- a/usr.sbin/ospf6d/ospf6d.h
+++ b/usr.sbin/ospf6d/ospf6d.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospf6d.h,v 1.26 2013/01/14 14:39:38 florian Exp $ */
+/* $OpenBSD: ospf6d.h,v 1.27 2013/03/22 14:25:31 sthen Exp $ */
/*
* Copyright (c) 2004, 2007 Esben Norby <norby@openbsd.org>
@@ -375,6 +375,7 @@ struct ospfd_conf {
int flags;
u_int8_t border;
u_int8_t redistribute;
+ char *csock;
};
/* kroute */
diff --git a/usr.sbin/ospf6d/ospfe.c b/usr.sbin/ospf6d/ospfe.c
index b66747d104a..679e046c596 100644
--- a/usr.sbin/ospf6d/ospfe.c
+++ b/usr.sbin/ospf6d/ospfe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ospfe.c,v 1.39 2013/03/22 12:14:42 sthen Exp $ */
+/* $OpenBSD: ospfe.c,v 1.40 2013/03/22 14:25:31 sthen Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -90,7 +90,7 @@ ospfe(struct ospfd_conf *xconf, int pipe_parent2ospfe[2], int pipe_ospfe2rde[2],
}
/* create ospfd control socket outside chroot */
- if (control_init() == -1)
+ if (control_init(xconf->csock) == -1)
fatalx("control socket setup failed");
/* create the raw ip socket */