Nima GHOTBI <[email protected]> writes:

> please try the attachments
>
> On Sun, Jul 31, 2016 at 7:27 PM, Jeremie Courreges-Anglas <[email protected]>
> wrote:
>
>> Nima GHOTBI <[email protected]> writes:
>>
>> > 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

Reply via email to