From 94cb73d96cf7ec2ddaf0f56e4b4ed2cad1323925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= Date: Mon, 29 Apr 2019 19:29:09 +0200 Subject: [PATCH] Use SO_REUSEPORT_LB on FreeBSD if available --- lib/isc/unix/socket.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index 1e35842006..58fa29e3db 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -4475,6 +4475,13 @@ isc_socket_bind(isc_socket_t *sock0, const isc_sockaddr_t *sockaddr, UNEXPECTED_ERROR(__FILE__, __LINE__, "setsockopt(%d) failed", sock->fd); } +#if defined(__FreeBSD_kernel__) && defined(SO_REUSEPORT_LB) + if (setsockopt(sock->fd, SOL_SOCKET, SO_REUSEPORT_LB, + (void *)&on, sizeof(on)) < 0) + { + UNEXPECTED_ERROR(__FILE__, __LINE__, + "setsockopt(%d) failed", sock->fd); + } #elif defined(__linux__) && defined(SO_REUSEPORT) if (setsockopt(sock->fd, SOL_SOCKET, SO_REUSEPORT, (void *)&on, sizeof(on)) < 0) @@ -5334,7 +5341,8 @@ init_hasreuseport() { * We only want to use it on Linux, if it's available. On BSD we want to dup() * sockets instead of re-binding them. */ -#if defined(SO_REUSEPORT) && defined(__linux__) +#if (defined(SO_REUSEPORT) && defined(__linux__)) || \ + (defined(SO_REUSEPORT_LB) && defined(__FreeBSD_kernel__)) int sock, yes = 1; sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { @@ -5348,8 +5356,13 @@ init_hasreuseport() { { close(sock); return; +#if defined(__FreeBSD_kernel__) + } else if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT_LB, + (void *)&yes, sizeof(yes)) < 0) +#else } else if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (void *)&yes, sizeof(yes)) < 0) +#endif { close(sock); return;