github.com/slackhq/nebula@v1.9.0/udp/udp_bsd.go (about) 1 //go:build (openbsd || freebsd) && !e2e_testing 2 // +build openbsd freebsd 3 // +build !e2e_testing 4 5 package udp 6 7 // FreeBSD support is primarily implemented in udp_generic, besides NewListenConfig 8 9 import ( 10 "fmt" 11 "net" 12 "syscall" 13 14 "github.com/sirupsen/logrus" 15 "golang.org/x/sys/unix" 16 ) 17 18 func NewListener(l *logrus.Logger, ip net.IP, port int, multi bool, batch int) (Conn, error) { 19 return NewGenericListener(l, ip, port, multi, batch) 20 } 21 22 func NewListenConfig(multi bool) net.ListenConfig { 23 return net.ListenConfig{ 24 Control: func(network, address string, c syscall.RawConn) error { 25 if multi { 26 var controlErr error 27 err := c.Control(func(fd uintptr) { 28 if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil { 29 controlErr = fmt.Errorf("SO_REUSEPORT failed: %v", err) 30 return 31 } 32 }) 33 if err != nil { 34 return err 35 } 36 if controlErr != nil { 37 return controlErr 38 } 39 } 40 return nil 41 }, 42 } 43 } 44 45 func (u *GenericConn) Rebind() error { 46 return nil 47 }