diff --git a/socket.c b/socket.c index 0a24879..3c1ffd3 100644 --- a/socket.c +++ b/socket.c @@ -342,6 +342,14 @@ bind_ip_address(int sock_fd, IPSockAddr *addr, int flags) if (addr->port > 0 && !SCK_SetIntOption(sock_fd, SOL_SOCKET, SO_REUSEADDR, 1)) ; +#if defined(LINUX) && defined(SO_REUSEPORT) + /* Allow multiple instances to bind to the same port in order to enable load + balancing. Don't enable this option on non-Linux systems as it has + a slightly different meaning there (with some important implications). */ + if (addr->port > 0 && !SCK_SetIntOption(sock_fd, SOL_SOCKET, SO_REUSEPORT, 1)) + ; +#endif + #ifdef IP_FREEBIND /* Allow binding to an address that doesn't exist yet */ if (!SCK_SetIntOption(sock_fd, IPPROTO_IP, IP_FREEBIND, 1)) diff --git a/sys_linux.c b/sys_linux.c index 09b96a9..1f08e64 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -523,6 +523,9 @@ SYS_Linux_EnableSystemCallFilter(int level, SYS_SystemCallContext context) { SOL_IPV6, IPV6_V6ONLY }, { SOL_IPV6, IPV6_RECVPKTINFO }, #endif { SOL_SOCKET, SO_BROADCAST }, { SOL_SOCKET, SO_REUSEADDR }, +#ifdef SO_REUSEPORT + { SOL_SOCKET, SO_REUSEPORT }, +#endif { SOL_SOCKET, SO_TIMESTAMP }, { SOL_SOCKET, SO_TIMESTAMPNS }, #ifdef HAVE_LINUX_TIMESTAMPING { SOL_SOCKET, SO_SELECT_ERR_QUEUE }, { SOL_SOCKET, SO_TIMESTAMPING },