]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
net: add support for FreeBSD's SO_REUSEPORT_LB
authorDaniel Salzman <daniel.salzman@nic.cz>
Mon, 28 Jan 2019 16:10:32 +0000 (17:10 +0100)
committerDaniel Salzman <daniel.salzman@nic.cz>
Wed, 30 Jan 2019 12:21:01 +0000 (13:21 +0100)
configure.ac
src/contrib/net.c

index cba5cf209f5d5d97c02c20eee2cfb0af4176a387..ded8f7871ea1a75f84ae4309b475e95519b26db9 100644 (file)
@@ -187,37 +187,38 @@ AS_CASE([$enable_recvmmsg],
 AS_IF([test "$enable_recvmmsg" = yes],[
    AC_DEFINE([ENABLE_RECVMMSG], [1], [Use recvmmsg().])])
 
+# Reuseport support
+AS_CASE([$host_os],
+  [freebsd*], [reuseport_opt=SO_REUSEPORT_LB],
+  [*], [reuseport_opt=SO_REUSEPORT],
+)
+
 AC_ARG_ENABLE([reuseport],
-    AS_HELP_STRING([--enable-reuseport=auto|yes|no], [enable Linux SO_REUSEPORT support [default=auto]]),
-    [enable_reuseport="$enableval"], [enable_reuseport=auto])
-
-AC_DEFUN([CHECK_REUSEPORT], [
-  AC_CHECK_DECL(
-    [SO_REUSEPORT],
-    [$1],
-    [$2],
-    [
-    #include <sys/socket.h>
-    ]
-  )])
-
-AS_IF([test "$enable_reuseport" != no], [
-  AS_CASE([$enable_reuseport],
-    [auto],[
-      AS_CASE([$host_os],
-        [linux*], [CHECK_REUSEPORT([enable_reuseport=yes], [enable_reuseport=no])],
-        [*], [enable_reuseport=no]
-      )],
-    [yes],[
-      AS_CASE([$host_os],
-        [linux*], [CHECK_REUSEPORT([enable_reuseport=yes], [AC_MSG_ERROR([SO_REUSEPORT support not detected.])])],
-        [*], [AC_MSG_ERROR(["SO_REUSEPORT not supported on $host_os."])]
-      )],
-    [*], [AC_MSG_ERROR([Invalid value of --enable-reuseport.])]
-  )])
+  AS_HELP_STRING([--enable-reuseport=auto|yes|no],
+                 [enable SO_REUSEPORT(_LB) support [default=auto]]),
+  [], [enable_reuseport=auto]
+)
+
+AS_CASE([$enable_reuseport],
+  [auto], [
+    AS_CASE([$host_os],
+      [freebsd*|linux*], [AC_CHECK_DECL([$reuseport_opt],
+                                        [enable_reuseport=yes],
+                                        [enable_reuseport=no],
+                                        [#include <sys/socket.h>
+                                        ])],
+      [*], [enable_reuseport=no]
+    )],
+  [yes], [AC_CHECK_DECL([$reuseport_opt], [],
+                        [AC_MSG_ERROR([SO_REUSEPORT(_LB) not supported.])],
+                        [#include <sys/socket.h>
+                        ])],
+  [no], [],
+  [*], [AC_MSG_ERROR([Invalid value of --enable-reuseport.])]
+)
 
 AS_IF([test "$enable_reuseport" = yes],[
-   AC_DEFINE([ENABLE_REUSEPORT], [1], [Use SO_REUSEPORT.])])
+   AC_DEFINE([ENABLE_REUSEPORT], [1], [Use SO_REUSEPORT(_LB).])])
 
 #########################################
 # Dependencies needed for Knot DNS daemon
@@ -673,14 +674,14 @@ result_msg_base="  Knot DNS $VERSION
     Knot DNS documentation: ${enable_documentation}
 
     Use recvmmsg:           ${enable_recvmmsg}
-    Use SO_REUSEPORT:       ${enable_reuseport}
+    Use SO_REUSEPORT(_LB):  ${enable_reuseport}
     Memory allocator:       ${with_memory_allocator}
     Fast zone parser:       ${enable_fastparser}
     Utilities with IDN:     ${with_libidn}
     Utilities with Dnstap:  ${enable_dnstap}
     MaxMind DB support:     ${enable_maxminddb}
     Systemd integration:    ${enable_systemd}
-    POSIX capabilities      ${enable_cap_ng}
+    POSIX capabilities:     ${enable_cap_ng}
     PKCS #11 support:       ${enable_pkcs11}
     Ed25519 support:        ${enable_ed25519}
     Code coverage:          ${enable_code_coverage}
index e21461b83030877b4ab5a974a2b75eeb388e608c..5bc0178430b5fa40032d1deb6bfdad29ebcfa988 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2019 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -145,7 +145,11 @@ static int enable_nonlocal(int sock, int family)
 static int enable_reuseport(int sock)
 {
 #ifdef ENABLE_REUSEPORT
+#  if defined(__FreeBSD__)
+       return sockopt_enable(sock, SOL_SOCKET, SO_REUSEPORT_LB);
+#  else
        return sockopt_enable(sock, SOL_SOCKET, SO_REUSEPORT);
+#  endif
 #else
        return KNOT_ENOTSUP;
 #endif