Discussion:
Alternative control socket location in ripd
(too old to reply)
Jeremie Courreges-Anglas
2016-07-31 16:27:06 UTC
Permalink
Hi everyone
In one of our projects we had to run multiple instances of ripd on
different rdomains so I made a patch to add "-s" argument to ripd and
ripctl to let the user change control socket path from /var/run/ripd.sock
Sounds like a valuable addition, but your patch is mangled (whitespace
issue it seems). Please send a patch that applies.
diff -Naur BASE/usr.sbin/ripd/control.c usr.sbin/ripd/control.c
--- BASE/usr.sbin/ripd/control.c 2015-12-05 15:13:47.000000000 +0200
+++ usr.sbin/ripd/control.c 2016-07-14 14:42:36.545519411 +0300
@@ -39,7 +39,7 @@
void control_close(int);
int
-control_init(void)
+control_init(char *path)
{
struct sockaddr_un sun;
int fd;
@@ -53,28 +53,28 @@
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 @@
}
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 -Naur BASE/usr.sbin/ripd/control.h usr.sbin/ripd/control.h
--- BASE/usr.sbin/ripd/control.h 2015-02-09 14:13:42.000000000 +0200
+++ usr.sbin/ripd/control.h 2016-07-14 14:42:48.209546392 +0300
@@ -34,11 +34,11 @@
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_ */
--- BASE/usr.sbin/ripd/ripd.c 2016-02-02 19:51:11.000000000 +0200
+++ usr.sbin/ripd/ripd.c 2016-07-14 14:55:51.175415748 +0300
@@ -70,7 +70,7 @@
{
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 +122,16 @@
int ch;
int opts = 0;
char *conffile;
+ char *sockname;
size_t len;
-
+ sockname = RIPD_SOCKET;
conffile = CONF_FILE;
ripd_process = PROC_MAIN;
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) {
opts |= RIPD_OPT_FORCE_DEMOTE;
@@ -149,6 +150,9 @@
opts |= RIPD_OPT_NOACTION;
break;
+ sockname = optarg;
+ break;
if (opts & RIPD_OPT_VERBOSE)
opts |= RIPD_OPT_VERBOSE2;
@@ -182,6 +185,7 @@
/* 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 +291,7 @@
if_del(i);
}
- control_cleanup();
+ control_cleanup(conf->csock);
kr_shutdown();
do {
diff -Naur BASE/usr.sbin/ripd/ripd.h usr.sbin/ripd/ripd.h
--- BASE/usr.sbin/ripd/ripd.h 2015-09-27 20:32:36.000000000 +0300
+++ usr.sbin/ripd/ripd.h 2016-07-14 14:46:50.582113056 +0300
@@ -239,6 +239,7 @@
int rip_socket;
int redistribute;
u_int rdomain;
+ char *csock;
};
/* kroute */
diff -Naur BASE/usr.sbin/ripd/ripe.c usr.sbin/ripd/ripe.c
--- BASE/usr.sbin/ripd/ripe.c 2015-12-05 15:13:47.000000000 +0200
+++ usr.sbin/ripd/ripe.c 2016-07-14 14:52:29.370923477 +0300
@@ -85,7 +85,7 @@
}
/* 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;
diff -Naur BASE/usr.sbin/ripctl/ripctl.c usr.sbin/ripctl/ripctl.c
--- BASE/usr.sbin/ripctl/ripctl.c 2015-12-05 15:13:47.000000000 +0200
+++ usr.sbin/ripctl/ripctl.c 2016-07-14 15:10:32.053488404 +0300
@@ -59,7 +59,7 @@
{
extern char *__progname;
- fprintf(stderr, "usage: %s command [argument ...]\n", __progname);
+ fprintf(stderr, "usage: %s [-s socket] command [argument ...]\n",
__progname);
exit(1);
}
@@ -73,6 +73,20 @@
int ctl_sock;
int done = 0, verbose = 0;
int n;
+ int ch;
+ char *sockname;
+ sockname = RIPD_SOCKET;
+
+ while ((ch = getopt(argc, argv, "s:")) != -1) {
+ switch (ch) {
+ sockname = optarg;
+ argc-= 2;
+ argv+= 2;
+ break;
+ }
+ }
+
/* parse options */
if ((res = parse(argc - 1, argv + 1)) == NULL)
@@ -84,9 +98,9 @@
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");
--
jca | PGP: 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
Nima GHOTBI
2016-08-02 08:19:57 UTC
Permalink
please try the attachments
Post by Jeremie Courreges-Anglas
Hi everyone
In one of our projects we had to run multiple instances of ripd on
different rdomains so I made a patch to add "-s" argument to ripd and
ripctl to let the user change control socket path from /var/run/ripd.sock
Sounds like a valuable addition, but your patch is mangled (whitespace
issue it seems). Please send a patch that applies.
diff -Naur BASE/usr.sbin/ripd/control.c usr.sbin/ripd/control.c
--- BASE/usr.sbin/ripd/control.c 2015-12-05 15:13:47.000000000 +0200
+++ usr.sbin/ripd/control.c 2016-07-14 14:42:36.545519411 +0300
@@ -39,7 +39,7 @@
void control_close(int);
int
-control_init(void)
+control_init(char *path)
{
struct sockaddr_un sun;
int fd;
@@ -53,28 +53,28 @@
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 @@
}
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 -Naur BASE/usr.sbin/ripd/control.h usr.sbin/ripd/control.h
--- BASE/usr.sbin/ripd/control.h 2015-02-09 14:13:42.000000000 +0200
+++ usr.sbin/ripd/control.h 2016-07-14 14:42:48.209546392 +0300
@@ -34,11 +34,11 @@
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_ */
--- BASE/usr.sbin/ripd/ripd.c 2016-02-02 19:51:11.000000000 +0200
+++ usr.sbin/ripd/ripd.c 2016-07-14 14:55:51.175415748 +0300
@@ -70,7 +70,7 @@
{
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 +122,16 @@
int ch;
int opts = 0;
char *conffile;
+ char *sockname;
size_t len;
-
+ sockname = RIPD_SOCKET;
conffile = CONF_FILE;
ripd_process = PROC_MAIN;
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) {
opts |= RIPD_OPT_FORCE_DEMOTE;
@@ -149,6 +150,9 @@
opts |= RIPD_OPT_NOACTION;
break;
+ sockname = optarg;
+ break;
if (opts & RIPD_OPT_VERBOSE)
opts |= RIPD_OPT_VERBOSE2;
@@ -182,6 +185,7 @@
/* 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 +291,7 @@
if_del(i);
}
- control_cleanup();
+ control_cleanup(conf->csock);
kr_shutdown();
do {
diff -Naur BASE/usr.sbin/ripd/ripd.h usr.sbin/ripd/ripd.h
--- BASE/usr.sbin/ripd/ripd.h 2015-09-27 20:32:36.000000000 +0300
+++ usr.sbin/ripd/ripd.h 2016-07-14 14:46:50.582113056 +0300
@@ -239,6 +239,7 @@
int rip_socket;
int redistribute;
u_int rdomain;
+ char *csock;
};
/* kroute */
diff -Naur BASE/usr.sbin/ripd/ripe.c usr.sbin/ripd/ripe.c
--- BASE/usr.sbin/ripd/ripe.c 2015-12-05 15:13:47.000000000 +0200
+++ usr.sbin/ripd/ripe.c 2016-07-14 14:52:29.370923477 +0300
@@ -85,7 +85,7 @@
}
/* 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;
diff -Naur BASE/usr.sbin/ripctl/ripctl.c usr.sbin/ripctl/ripctl.c
--- BASE/usr.sbin/ripctl/ripctl.c 2015-12-05 15:13:47.000000000 +0200
+++ usr.sbin/ripctl/ripctl.c 2016-07-14 15:10:32.053488404 +0300
@@ -59,7 +59,7 @@
{
extern char *__progname;
- fprintf(stderr, "usage: %s command [argument ...]\n", __progname);
+ fprintf(stderr, "usage: %s [-s socket] command [argument ...]\n",
__progname);
exit(1);
}
@@ -73,6 +73,20 @@
int ctl_sock;
int done = 0, verbose = 0;
int n;
+ int ch;
+ char *sockname;
+ sockname = RIPD_SOCKET;
+
+ while ((ch = getopt(argc, argv, "s:")) != -1) {
+ switch (ch) {
+ sockname = optarg;
+ argc-= 2;
+ argv+= 2;
+ break;
+ }
+ }
+
/* parse options */
if ((res = parse(argc - 1, argv + 1)) == NULL)
@@ -84,9 +98,9 @@
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");
--
jca | PGP: 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
Jeremie Courreges-Anglas
2016-08-02 11:48:11 UTC
Permalink
Post by Nima GHOTBI
please try the attachments
Hi everyone
In one of our projects we had to run multiple instances of ripd on
different rdomains so I made a patch to add "-s" argument to ripd and
ripctl to let the user change control socket path from /var/run/ripd.sock
Here's an updated diff that fixes whitespace and tries to match ospfd
a bit more closely.

Comments / oks?


Index: usr.sbin/ripd/control.c
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/control.c,v
retrieving revision 1.22
diff -u -p -r1.22 control.c
--- usr.sbin/ripd/control.c 5 Dec 2015 13:13:47 -0000 1.22
+++ usr.sbin/ripd/control.c 2 Aug 2016 11:35:57 -0000
@@ -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 */
Index: usr.sbin/ripd/control.h
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/control.h,v
retrieving revision 1.4
diff -u -p -r1.4 control.h
--- usr.sbin/ripd/control.h 9 Feb 2015 12:13:42 -0000 1.4
+++ usr.sbin/ripd/control.h 2 Aug 2016 11:34:44 -0000
@@ -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_ */
Index: usr.sbin/ripd/ripd.c
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/ripd.c,v
retrieving revision 1.27
diff -u -p -r1.27 ripd.c
--- usr.sbin/ripd/ripd.c 2 Feb 2016 17:51:11 -0000 1.27
+++ usr.sbin/ripd/ripd.c 2 Aug 2016 11:44:24 -0000
@@ -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 {
Index: usr.sbin/ripd/ripd.h
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/ripd.h,v
retrieving revision 1.22
diff -u -p -r1.22 ripd.h
--- usr.sbin/ripd/ripd.h 27 Sep 2015 17:32:36 -0000 1.22
+++ usr.sbin/ripd/ripd.h 2 Aug 2016 10:14:46 -0000
@@ -239,6 +239,7 @@ struct ripd_conf {
int rip_socket;
int redistribute;
u_int rdomain;
+ char *csock;
};

/* kroute */
Index: usr.sbin/ripd/ripe.c
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/ripe.c,v
retrieving revision 1.19
diff -u -p -r1.19 ripe.c
--- usr.sbin/ripd/ripe.c 5 Dec 2015 13:13:47 -0000 1.19
+++ usr.sbin/ripd/ripe.c 2 Aug 2016 10:14:46 -0000
@@ -85,7 +85,7 @@ ripe(struct ripd_conf *xconf, int pipe_p
}

/* 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;
Index: usr.sbin/ripctl/ripctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/ripctl/ripctl.c,v
retrieving revision 1.16
diff -u -p -r1.16 ripctl.c
--- usr.sbin/ripctl/ripctl.c 5 Dec 2015 13:13:47 -0000 1.16
+++ usr.sbin/ripctl/ripctl.c 2 Aug 2016 11:37:40 -0000
@@ -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");
--
jca | PGP: 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
Claudio Jeker
2016-08-02 13:08:18 UTC
Permalink
Post by Jeremie Courreges-Anglas
Post by Nima GHOTBI
please try the attachments
Hi everyone
In one of our projects we had to run multiple instances of ripd on
different rdomains so I made a patch to add "-s" argument to ripd and
ripctl to let the user change control socket path from /var/run/ripd.sock
Here's an updated diff that fixes whitespace and tries to match ospfd
a bit more closely.
Comments / oks?
Reads good to me. I think this is a worth addition to ripd.
Post by Jeremie Courreges-Anglas
Index: usr.sbin/ripd/control.c
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/control.c,v
retrieving revision 1.22
diff -u -p -r1.22 control.c
--- usr.sbin/ripd/control.c 5 Dec 2015 13:13:47 -0000 1.22
+++ usr.sbin/ripd/control.c 2 Aug 2016 11:35:57 -0000
@@ -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 */
Index: usr.sbin/ripd/control.h
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/control.h,v
retrieving revision 1.4
diff -u -p -r1.4 control.h
--- usr.sbin/ripd/control.h 9 Feb 2015 12:13:42 -0000 1.4
+++ usr.sbin/ripd/control.h 2 Aug 2016 11:34:44 -0000
@@ -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_ */
Index: usr.sbin/ripd/ripd.c
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/ripd.c,v
retrieving revision 1.27
diff -u -p -r1.27 ripd.c
--- usr.sbin/ripd/ripd.c 2 Feb 2016 17:51:11 -0000 1.27
+++ usr.sbin/ripd/ripd.c 2 Aug 2016 11:44:24 -0000
@@ -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) {
opts |= RIPD_OPT_FORCE_DEMOTE;
@@ -149,6 +152,9 @@ main(int argc, char *argv[])
opts |= RIPD_OPT_NOACTION;
break;
+ sockname = optarg;
+ break;
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 {
Index: usr.sbin/ripd/ripd.h
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/ripd.h,v
retrieving revision 1.22
diff -u -p -r1.22 ripd.h
--- usr.sbin/ripd/ripd.h 27 Sep 2015 17:32:36 -0000 1.22
+++ usr.sbin/ripd/ripd.h 2 Aug 2016 10:14:46 -0000
@@ -239,6 +239,7 @@ struct ripd_conf {
int rip_socket;
int redistribute;
u_int rdomain;
+ char *csock;
};
/* kroute */
Index: usr.sbin/ripd/ripe.c
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/ripe.c,v
retrieving revision 1.19
diff -u -p -r1.19 ripe.c
--- usr.sbin/ripd/ripe.c 5 Dec 2015 13:13:47 -0000 1.19
+++ usr.sbin/ripd/ripe.c 2 Aug 2016 10:14:46 -0000
@@ -85,7 +85,7 @@ ripe(struct ripd_conf *xconf, int pipe_p
}
/* 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;
Index: usr.sbin/ripctl/ripctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/ripctl/ripctl.c,v
retrieving revision 1.16
diff -u -p -r1.16 ripctl.c
--- usr.sbin/ripctl/ripctl.c 5 Dec 2015 13:13:47 -0000 1.16
+++ usr.sbin/ripctl/ripctl.c 2 Aug 2016 11:37:40 -0000
@@ -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) {
+ sockname = optarg;
+ break;
+ 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");
--
jca | PGP: 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
--
:wq Claudio
Sebastian Benoit
2016-08-02 15:45:04 UTC
Permalink
Post by Jeremie Courreges-Anglas
Post by Nima GHOTBI
please try the attachments
Hi everyone
In one of our projects we had to run multiple instances of ripd on
different rdomains so I made a patch to add "-s" argument to ripd and
ripctl to let the user change control socket path from /var/run/ripd.sock
Here's an updated diff that fixes whitespace and tries to match ospfd
a bit more closely.
Comments / oks?
Index: usr.sbin/ripd/control.c
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/control.c,v
retrieving revision 1.22
diff -u -p -r1.22 control.c
--- usr.sbin/ripd/control.c 5 Dec 2015 13:13:47 -0000 1.22
+++ usr.sbin/ripd/control.c 2 Aug 2016 11:35:57 -0000
@@ -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 */
Index: usr.sbin/ripd/control.h
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/control.h,v
retrieving revision 1.4
diff -u -p -r1.4 control.h
--- usr.sbin/ripd/control.h 9 Feb 2015 12:13:42 -0000 1.4
+++ usr.sbin/ripd/control.h 2 Aug 2016 11:34:44 -0000
@@ -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_ */
Index: usr.sbin/ripd/ripd.c
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/ripd.c,v
retrieving revision 1.27
diff -u -p -r1.27 ripd.c
--- usr.sbin/ripd/ripd.c 2 Feb 2016 17:51:11 -0000 1.27
+++ usr.sbin/ripd/ripd.c 2 Aug 2016 11:44:24 -0000
@@ -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) {
opts |= RIPD_OPT_FORCE_DEMOTE;
@@ -149,6 +152,9 @@ main(int argc, char *argv[])
opts |= RIPD_OPT_NOACTION;
break;
+ sockname = optarg;
+ break;
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 {
Index: usr.sbin/ripd/ripd.h
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/ripd.h,v
retrieving revision 1.22
diff -u -p -r1.22 ripd.h
--- usr.sbin/ripd/ripd.h 27 Sep 2015 17:32:36 -0000 1.22
+++ usr.sbin/ripd/ripd.h 2 Aug 2016 10:14:46 -0000
@@ -239,6 +239,7 @@ struct ripd_conf {
int rip_socket;
int redistribute;
u_int rdomain;
+ char *csock;
};
/* kroute */
Index: usr.sbin/ripd/ripe.c
===================================================================
RCS file: /cvs/src/usr.sbin/ripd/ripe.c,v
retrieving revision 1.19
diff -u -p -r1.19 ripe.c
--- usr.sbin/ripd/ripe.c 5 Dec 2015 13:13:47 -0000 1.19
+++ usr.sbin/ripd/ripe.c 2 Aug 2016 10:14:46 -0000
@@ -85,7 +85,7 @@ ripe(struct ripd_conf *xconf, int pipe_p
}
/* 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;
Index: usr.sbin/ripctl/ripctl.c
===================================================================
RCS file: /cvs/src/usr.sbin/ripctl/ripctl.c,v
retrieving revision 1.16
diff -u -p -r1.16 ripctl.c
--- usr.sbin/ripctl/ripctl.c 5 Dec 2015 13:13:47 -0000 1.16
+++ usr.sbin/ripctl/ripctl.c 2 Aug 2016 11:37:40 -0000
@@ -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) {
+ sockname = optarg;
+ break;
+ 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");
--
jca | PGP: 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
--
Jeremie Courreges-Anglas
2016-08-02 16:10:00 UTC
Permalink
Committed, thanks.
--
jca | PGP: 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE
Loading...