From e965df174205e68fc3dd9c403310de192d7a58cc Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Fri, 4 Aug 2023 15:52:34 +0530 Subject: [PATCH] feat: Add support for SO_REUSEPORT_LB option as per freeBSD --- control_unix.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/control_unix.go b/control_unix.go index 4197d1f..f3cd60a 100644 --- a/control_unix.go +++ b/control_unix.go @@ -8,6 +8,9 @@ import ( "golang.org/x/sys/unix" ) +// This value has been taken from https://reviews.freebsd.org/D11003 since this is not yet provided in golang. +const FREEBSD_SO_REUSEPORT_LB = 0x00010000 + func Control(network, address string, c syscall.RawConn) (err error) { controlErr := c.Control(func(fd uintptr) { err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEADDR, 1) @@ -15,6 +18,10 @@ func Control(network, address string, c syscall.RawConn) (err error) { return } err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_REUSEPORT, 1) + if err != nil { + return + } + err = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, FREEBSD_SO_REUSEPORT_LB, 1) }) if controlErr != nil { err = controlErr