-/* $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 <mydecay@openbeer.it>
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
{
extern char *__progname;
- fprintf(stderr, "usage: %s command [argument ...]\n", __progname);
+ fprintf(stderr, "usage: %s [-s socket] command [argument ...]\n",
+ __progname);
exit(1);
}
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 */
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");
-/* $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 <henning@openbsd.org>
void control_close(int);
int
-control_init(void)
+control_init(char *path)
{
struct sockaddr_un sun;
int fd;
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);
}
}
void
-control_cleanup(void)
+control_cleanup(char *path)
{
event_del(&control_state.ev);
event_del(&control_state.evt);
- unlink(RIPD_SOCKET);
+ unlink(path);
}
/* ARGSUSED */
-/* $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 <henning@openbsd.org>
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_ */
-/* $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 <mydecay@openbeer.it>
{
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);
}
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;
case 'n':
opts |= RIPD_OPT_NOACTION;
break;
+ case 's':
+ sockname = optarg;
+ break;
case 'v':
if (opts & RIPD_OPT_VERBOSE)
opts |= RIPD_OPT_VERBOSE2;
/* 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)
if_del(i);
}
- control_cleanup();
+ control_cleanup(conf->csock);
kr_shutdown();
do {
-/* $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 <norby@openbsd.org>
int rip_socket;
int redistribute;
u_int rdomain;
+ char *csock;
};
/* kroute */
-/* $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 <mydecay@openbeer.it>
}
/* 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;