diff options
author | David Hill <dhill@cvs.openbsd.org> | 2010-12-20 12:38:07 +0000 |
---|---|---|
committer | David Hill <dhill@cvs.openbsd.org> | 2010-12-20 12:38:07 +0000 |
commit | ecb4daee14e47548495ed38d99fdf8cbff47936a (patch) | |
tree | c7f05db6a4bd40388308d2b379efdecf9808a703 /usr.sbin/relayd | |
parent | 4f022912df8425de7efe628a8c58fd8b18108cd2 (diff) |
Only set SO_REUSEPORT for listening ports.
Fixes "Address already in use" errors seen on high load.
OK reyk@ pyr@
Diffstat (limited to 'usr.sbin/relayd')
-rw-r--r-- | usr.sbin/relayd/check_tcp.c | 7 | ||||
-rw-r--r-- | usr.sbin/relayd/relay.c | 19 |
2 files changed, 12 insertions, 14 deletions
diff --git a/usr.sbin/relayd/check_tcp.c b/usr.sbin/relayd/check_tcp.c index c7ea204b438..11cd66a21f5 100644 --- a/usr.sbin/relayd/check_tcp.c +++ b/usr.sbin/relayd/check_tcp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: check_tcp.c,v 1.38 2010/11/30 14:38:45 reyk Exp $ */ +/* $OpenBSD: check_tcp.c,v 1.39 2010/12/20 12:38:06 dhill Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@openbsd.org> @@ -50,7 +50,6 @@ void check_tcp(struct ctl_tcp_event *cte) { int s; - int type; socklen_t len; struct timeval tv; struct linger lng; @@ -81,10 +80,6 @@ check_tcp(struct ctl_tcp_event *cte) if (setsockopt(s, SOL_SOCKET, SO_LINGER, &lng, sizeof(lng)) == -1) goto bad; - type = 1; - if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &type, sizeof(type)) == -1) - goto bad; - if (cte->host->conf.ttl > 0) { if (setsockopt(s, IPPROTO_IP, IP_TTL, &cte->host->conf.ttl, sizeof(int)) == -1) diff --git a/usr.sbin/relayd/relay.c b/usr.sbin/relayd/relay.c index 9fb699f8436..51a22f2f331 100644 --- a/usr.sbin/relayd/relay.c +++ b/usr.sbin/relayd/relay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: relay.c,v 1.127 2010/11/30 14:49:14 reyk Exp $ */ +/* $OpenBSD: relay.c,v 1.128 2010/12/20 12:38:06 dhill Exp $ */ /* * Copyright (c) 2006, 2007, 2008 Reyk Floeter <reyk@openbsd.org> @@ -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 *ss, in_port_t port) 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; @@ -640,9 +640,12 @@ relay_socket(struct sockaddr_storage *ss, in_port_t port, bzero(&lng, sizeof(lng)); 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) - goto bad; + if (reuseport) { + val = 1; + if (setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &val, + sizeof(int)) == -1) + goto bad; + } if (fcntl(s, F_SETFL, O_NONBLOCK) == -1) goto bad; if (proto->tcpflags & TCPFLAG_BUFSIZ) { @@ -708,7 +711,7 @@ relay_socket_connect(struct sockaddr_storage *ss, in_port_t port, { 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 +732,7 @@ relay_socket_listen(struct sockaddr_storage *ss, in_port_t port, { 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) |