From: Daniel Salzman Date: Mon, 28 Jan 2019 16:10:32 +0000 (+0100) Subject: net: add support for FreeBSD's SO_REUSEPORT_LB X-Git-Tag: v2.8.0~82 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=370efcaef97c528b516bac2dca19cd1c1fb131ce;p=thirdparty%2Fknot-dns.git net: add support for FreeBSD's SO_REUSEPORT_LB --- diff --git a/configure.ac b/configure.ac index cba5cf209f..ded8f7871e 100644 --- a/configure.ac +++ b/configure.ac @@ -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 - ] - )]) - -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 + ])], + [*], [enable_reuseport=no] + )], + [yes], [AC_CHECK_DECL([$reuseport_opt], [], + [AC_MSG_ERROR([SO_REUSEPORT(_LB) not supported.])], + [#include + ])], + [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} diff --git a/src/contrib/net.c b/src/contrib/net.c index e21461b830..5bc0178430 100644 --- a/src/contrib/net.c +++ b/src/contrib/net.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 CZ.NIC, z.s.p.o. +/* Copyright (C) 2019 CZ.NIC, z.s.p.o. 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