2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Merge branch '1003-SO_REUSEPORT-tweaks' into 'master'

Resolve "socket.c error 'SO_REUSEPORT' undeclared"

Closes #1003

See merge request isc-projects/bind9!1884
This commit is contained in:
Ondřej Surý
2019-05-17 01:37:48 -04:00

View File

@@ -4475,12 +4475,21 @@ 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)
{
UNEXPECTED_ERROR(__FILE__, __LINE__,
"setsockopt(%d) failed", sock->fd);
}
#endif
/* Press on... */
}
#ifdef AF_UNIX
@@ -5332,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) {
@@ -5346,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;