]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/io: use SO_REUSEPORT_LB if available (FreeBSD 12.0+)
authorVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 10 Dec 2019 16:08:30 +0000 (17:08 +0100)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 11 Dec 2019 10:02:02 +0000 (11:02 +0100)
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
daemon/io.c

diff --git a/NEWS b/NEWS
index b84f354d39dae8b36213c2a3e4ae62ad3e44181a..0e5757a78e97336e1d75b25505b2d7cb1891e82d 100644 (file)
--- 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)
index adcad7170d968dd31184beeca058637243c30d86..bca3afe4559d89e8ce88d4d3f40eaff1c45d7657 100644 (file)
@@ -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)))