From daea8f2bd7972fc98ddc8ab5c014b2431751830b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Tue, 10 Dec 2019 17:08:30 +0100 Subject: [PATCH] daemon/io: use SO_REUSEPORT_LB if available (FreeBSD 12.0+) and don't use SO_REUSEPORT on non-Linux. (Free)BSD has a different meaning for it, which only brings confusion - only the last instance would be getting packets. --- NEWS | 1 + daemon/io.c | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index b84f354d3..0e5757a78 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ Knot Resolver 4.x.y (20yy-mm-dd) Improvements ------------ - logging: control-socket commands don't log unless --verbose (#528) +- use SO_REUSEPORT_LB if available (FreeBSD 12.0+) Knot Resolver 4.3.0 (2019-12-04) diff --git a/daemon/io.c b/daemon/io.c index adcad7170..bca3afe45 100644 --- a/daemon/io.c +++ b/daemon/io.c @@ -112,10 +112,15 @@ int io_bind(const struct sockaddr *addr, int type) int yes = 1; if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes))) return kr_error(errno); -#ifdef SO_REUSEPORT + +#ifdef SO_REUSEPORT_LB + if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT_LB, &yes, sizeof(yes))) + return kr_error(errno); +#elif defined(SO_REUSEPORT) && defined(__linux__) /* different meaning on (Free)BSD */ if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes))) return kr_error(errno); #endif + #ifdef IPV6_V6ONLY if (addr->sa_family == AF_INET6 && setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &yes, sizeof(yes))) -- 2.47.2