mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 06:25:31 +00:00
Use SO_REUSEPORT_LB on FreeBSD if available
This commit is contained in:
@@ -4475,6 +4475,13 @@ isc_socket_bind(isc_socket_t *sock0, const isc_sockaddr_t *sockaddr,
|
|||||||
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
UNEXPECTED_ERROR(__FILE__, __LINE__,
|
||||||
"setsockopt(%d) failed", sock->fd);
|
"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)
|
#elif defined(__linux__) && defined(SO_REUSEPORT)
|
||||||
if (setsockopt(sock->fd, SOL_SOCKET, SO_REUSEPORT,
|
if (setsockopt(sock->fd, SOL_SOCKET, SO_REUSEPORT,
|
||||||
(void *)&on, sizeof(on)) < 0)
|
(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()
|
* We only want to use it on Linux, if it's available. On BSD we want to dup()
|
||||||
* sockets instead of re-binding them.
|
* 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;
|
int sock, yes = 1;
|
||||||
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
@@ -5348,8 +5356,13 @@ init_hasreuseport() {
|
|||||||
{
|
{
|
||||||
close(sock);
|
close(sock);
|
||||||
return;
|
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,
|
} else if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT,
|
||||||
(void *)&yes, sizeof(yes)) < 0)
|
(void *)&yes, sizeof(yes)) < 0)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
close(sock);
|
close(sock);
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user