The below patch is for those using relayd w/ the relay (not redirect)
function.

If you are seeing "Address already in use errors" with option -d or
performance issues with a lot of traffic, please test and report.

This disables SO_REUSEPORT on connect()'s.

Index: relay.c
===================================================================
RCS file: /cvs/src/usr.sbin/relayd/relay.c,v
retrieving revision 1.127
diff -u -p -r1.127 relay.c
--- relay.c     30 Nov 2010 14:49:14 -0000      1.127
+++ relay.c     17 Dec 2010 19:22:04 -0000
@@ -59,7 +59,7 @@ void           relay_protodebug(struct relay *);
 void            relay_init(void);
 void            relay_launch(void);
 int             relay_socket(struct sockaddr_storage *, in_port_t,
-                   struct protocol *, int);
+                   struct protocol *, int, int);
 int             relay_socket_listen(struct sockaddr_storage *, in_port_t,
                    struct protocol *);
 int             relay_socket_connect(struct sockaddr_storage *, in_port_t,
@@ -622,7 +622,7 @@ relay_socket_af(struct sockaddr_storage 
 
 int
 relay_socket(struct sockaddr_storage *ss, in_port_t port,
-    struct protocol *proto, int fd)
+    struct protocol *proto, int fd, int reuseport)
 {
        int s = -1, val;
        struct linger lng;
@@ -641,7 +641,9 @@ relay_socket(struct sockaddr_storage *ss
        if (setsockopt(s, SOL_SOCKET, SO_LINGER, &lng, sizeof(lng)) == -1)
                goto bad;
        val = 1;
-       if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &val, sizeof(int)) == -1)
+       if (reuseport)
+               if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &val,
+                        sizeof(int)) == -1)
                goto bad;
        if (fcntl(s, F_SETFL, O_NONBLOCK) == -1)
                goto bad;
@@ -708,7 +710,7 @@ relay_socket_connect(struct sockaddr_sto
 {
        int     s;
 
-       if ((s = relay_socket(ss, port, proto, fd)) == -1)
+       if ((s = relay_socket(ss, port, proto, fd, 0)) == -1)
                return (-1);
 
        if (connect(s, (struct sockaddr *)ss, ss->ss_len) == -1) {
@@ -729,7 +731,7 @@ relay_socket_listen(struct sockaddr_stor
 {
        int s;
 
-       if ((s = relay_socket(ss, port, proto, -1)) == -1)
+       if ((s = relay_socket(ss, port, proto, -1, 1)) == -1)
                return (-1);
 
        if (bind(s, (struct sockaddr *)ss, ss->ss_len) == -1)

Reply via email to