mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-30 22:15:20 +00:00
Add SO_REUSEPORT and SO_INCOMING_CPU helper functions
The setting of SO_REUSE**** and SO_INCOMING_CPU have been moved into a separate helper functions.
This commit is contained in:
@@ -65,8 +65,8 @@ isc_nm_listenudp(isc_nm_t *mgr, isc_nmiface_t *iface, isc_nm_recv_cb_t cb,
|
||||
nsock->extrahandlesize = extrahandlesize;
|
||||
|
||||
for (size_t i = 0; i < mgr->nworkers; i++) {
|
||||
isc_result_t result;
|
||||
uint16_t family = iface->addr.type.sa.sa_family;
|
||||
int res = 0;
|
||||
|
||||
isc__netievent_udplisten_t *ievent = NULL;
|
||||
isc_nmsocket_t *csock = &nsock->children[i];
|
||||
@@ -82,46 +82,16 @@ isc_nm_listenudp(isc_nm_t *mgr, isc_nmiface_t *iface, isc_nm_recv_cb_t cb,
|
||||
csock->fd = socket(family, SOCK_DGRAM, 0);
|
||||
RUNTIME_CHECK(csock->fd >= 0);
|
||||
|
||||
/*
|
||||
* This is SO_REUSE**** hell:
|
||||
*
|
||||
* Generally, the SO_REUSEADDR socket option allows reuse of
|
||||
* local addresses. On Windows, it also allows a socket to
|
||||
* forcibly bind to a port in use by another socket.
|
||||
*
|
||||
* On Linux, SO_REUSEPORT socket option allows sockets to be
|
||||
* bound to an identical socket address. For UDP sockets, the
|
||||
* use of this option can provide better distribution of
|
||||
* incoming datagrams to multiple processes (or threads) as
|
||||
* compared to the traditional technique of having multiple
|
||||
* processes compete to receive datagrams on the same socket.
|
||||
*
|
||||
* On FreeBSD, the same thing is achieved with SO_REUSEPORT_LB.
|
||||
*
|
||||
*/
|
||||
#if defined(SO_REUSEADDR)
|
||||
res = setsockopt(csock->fd, SOL_SOCKET, SO_REUSEADDR,
|
||||
&(int){ 1 }, sizeof(int));
|
||||
RUNTIME_CHECK(res == 0);
|
||||
#endif
|
||||
#if defined(SO_REUSEPORT_LB)
|
||||
res = setsockopt(csock->fd, SOL_SOCKET, SO_REUSEPORT_LB,
|
||||
&(int){ 1 }, sizeof(int));
|
||||
RUNTIME_CHECK(res == 0);
|
||||
#elif defined(SO_REUSEPORT)
|
||||
res = setsockopt(csock->fd, SOL_SOCKET, SO_REUSEPORT,
|
||||
&(int){ 1 }, sizeof(int));
|
||||
RUNTIME_CHECK(res == 0);
|
||||
#endif
|
||||
result = isc__nm_socket_reuseport(csock->fd);
|
||||
RUNTIME_CHECK(result == ISC_R_SUCCESS ||
|
||||
result == ISC_R_NOTIMPLEMENTED);
|
||||
|
||||
#ifdef SO_INCOMING_CPU
|
||||
/* We don't check for the result, because SO_INCOMING_CPU can be
|
||||
* available without the setter on Linux kernel version 4.4, and
|
||||
* setting SO_INCOMING_CPU is just an optimization.
|
||||
*/
|
||||
(void)setsockopt(csock->fd, SOL_SOCKET, SO_INCOMING_CPU,
|
||||
&(int){ 1 }, sizeof(int));
|
||||
#endif
|
||||
(void)isc__nm_socket_incoming_cpu(csock->fd);
|
||||
|
||||
ievent = isc__nm_get_ievent(mgr, netievent_udplisten);
|
||||
ievent->sock = csock;
|
||||
isc__nm_enqueue_ievent(&mgr->workers[i],
|
||||
|
Reference in New Issue
Block a user