diff --git a/net/tcp/listen.go b/net/tcp/listen.go index 59359609..0175aec9 100644 --- a/net/tcp/listen.go +++ b/net/tcp/listen.go @@ -69,7 +69,7 @@ func (lf *ListenerFactory) NewListener(v *vrf.VRF, laddr *net.TCPAddr, ttl uint8 } if v.Name() != vrf.DefaultVRFName { - err = unix.SetsockoptString(fd, SOL_IP, unix.SO_BINDTODEVICE, v.Name()) + err = bindToDev(fd, v.Name()) if err != nil { unix.Close(fd) return nil, fmt.Errorf("unable to set SO_BINDTODEVICE (%s): %v", v.Name(), err) diff --git a/net/tcp/md5sig.go b/net/tcp/md5sig.go index bd1edb7f..6091d291 100644 --- a/net/tcp/md5sig.go +++ b/net/tcp/md5sig.go @@ -1,3 +1,5 @@ +//go:build linux + package tcp import ( diff --git a/net/tcp/md5sig_stub.go b/net/tcp/md5sig_stub.go new file mode 100644 index 00000000..2558f5cb --- /dev/null +++ b/net/tcp/md5sig_stub.go @@ -0,0 +1,12 @@ +//go:build !linux + +package tcp + +import ( + "fmt" + "net" +) + +func setTCPMD5Option(fd int, addr net.IP, md5secret string) error { + return fmt.Errorf("setting md5 is not supported") +} diff --git a/net/tcp/tcp.go b/net/tcp/tcp.go index 77ea9fd9..117f6931 100644 --- a/net/tcp/tcp.go +++ b/net/tcp/tcp.go @@ -130,7 +130,7 @@ func (c *Conn) SetNoDelay() error { // SetBindToDev sets the SO_BINDTODEVICE option func (c *Conn) SetBindToDev(devName string) error { - return unix.SetsockoptString(c.fd, unix.IPPROTO_TCP, unix.SO_BINDTODEVICE, devName) + return bindToDev(c.fd, devName) } // MockConn is mocked TCP connection diff --git a/net/tcp/tcp_linux.go b/net/tcp/tcp_linux.go new file mode 100644 index 00000000..d46a4406 --- /dev/null +++ b/net/tcp/tcp_linux.go @@ -0,0 +1,10 @@ +//go:build linux + +package tcp + +import "golang.org/x/sys/unix" + +// bindToDev sets the SO_BINDTODEVICE option +func bindToDev(fd int, devName string) error { + return unix.SetsockoptString(fd, unix.IPPROTO_TCP, unix.SO_BINDTODEVICE, devName) +} diff --git a/net/tcp/tcp_stub.go b/net/tcp/tcp_stub.go new file mode 100644 index 00000000..9c978ffa --- /dev/null +++ b/net/tcp/tcp_stub.go @@ -0,0 +1,10 @@ +//go:build !linux + +package tcp + +import "fmt" + +// bindToDev sets the SO_BINDTODEVICE option +func bindToDev(fd int, devName string) error { + return fmt.Errorf("binding to device is not supported") +}