2021-03-26 15:46:30 +01:00
|
|
|
// +build !e2e_testing
|
|
|
|
|
2019-11-19 18:00:20 +01:00
|
|
|
package nebula
|
|
|
|
|
|
|
|
// Darwin support is primarily implemented in udp_generic, besides NewListenConfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewListenConfig(multi bool) net.ListenConfig {
|
|
|
|
return net.ListenConfig{
|
|
|
|
Control: func(network, address string, c syscall.RawConn) error {
|
|
|
|
if multi {
|
|
|
|
var controlErr error
|
|
|
|
err := c.Control(func(fd uintptr) {
|
|
|
|
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1); err != nil {
|
|
|
|
controlErr = fmt.Errorf("SO_REUSEPORT failed: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if controlErr != nil {
|
|
|
|
return controlErr
|
|
|
|
}
|
|
|
|
}
|
2021-03-19 02:37:24 +01:00
|
|
|
|
2019-11-19 18:00:20 +01:00
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-06-30 20:48:58 +02:00
|
|
|
|
|
|
|
func (u *udpConn) Rebind() error {
|
|
|
|
file, err := u.File()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-03-19 02:37:24 +01:00
|
|
|
return syscall.SetsockoptInt(int(file.Fd()), unix.IPPROTO_IPV6, unix.IPV6_BOUND_IF, 0)
|
2020-06-30 20:48:58 +02:00
|
|
|
}
|