From: Wouter Wijngaards Date: Mon, 19 Nov 2018 09:36:27 +0000 (+0000) Subject: - Support SO_REUSEPORT_LB in FreeBSD 12 with the so-reuseport: yes X-Git-Tag: release-1.8.2rc1~32 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=069b0b8c90802310bd92c9bad5baed77c8770018;p=thirdparty%2Funbound.git - Support SO_REUSEPORT_LB in FreeBSD 12 with the so-reuseport: yes option in unbound.conf. git-svn-id: file:///svn/unbound/trunk@4960 be551aaa-1e26-0410-a405-d3ace91eadb9 --- diff --git a/doc/Changelog b/doc/Changelog index ffdeb93e7..38ca195cd 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -1,4 +1,8 @@ -6 November 2018: +19 November 2018: Wouter + - Support SO_REUSEPORT_LB in FreeBSD 12 with the so-reuseport: yes + option in unbound.conf. + +6 November 2018: Ralph - Bugfix min-client-subnet-ipv6 25 October 2018: Ralph diff --git a/services/listen_dnsport.c b/services/listen_dnsport.c index a2fb89067..efc0c3e18 100644 --- a/services/listen_dnsport.c +++ b/services/listen_dnsport.c @@ -247,6 +247,26 @@ create_udp_sock(int family, int socktype, struct sockaddr* addr, } #endif /* SO_REUSEADDR */ #ifdef SO_REUSEPORT +# ifdef SO_REUSEPORT_LB + /* on FreeBSD 12 we have SO_REUSEPORT_LB that does loadbalance + * like SO_REUSEPORT on Linux. This is what the users want + * with the config option in unbound.conf; if we actually + * need local address and port reuse they'll also need to + * have SO_REUSEPORT set for them, assume it was _LB they want. + */ + if (reuseport && *reuseport && + setsockopt(s, SOL_SOCKET, SO_REUSEPORT_LB, (void*)&on, + (socklen_t)sizeof(on)) < 0) { +#ifdef ENOPROTOOPT + if(errno != ENOPROTOOPT || verbosity >= 3) + log_warn("setsockopt(.. SO_REUSEPORT_LB ..) failed: %s", + strerror(errno)); +#endif + /* this option is not essential, we can continue */ + *reuseport = 0; + } +# else /* no SO_REUSEPORT_LB */ + /* try to set SO_REUSEPORT so that incoming * queries are distributed evenly among the receiving threads. * Each thread must have its own socket bound to the same port, @@ -263,6 +283,7 @@ create_udp_sock(int family, int socktype, struct sockaddr* addr, /* this option is not essential, we can continue */ *reuseport = 0; } +# endif /* SO_REUSEPORT_LB */ #else (void)reuseport; #endif /* defined(SO_REUSEPORT) */