Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/tcp: don't use MD5 signature and bind to device on non-Linux OS #444

Merged
merged 1 commit into from
Jul 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion net/tcp/listen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions net/tcp/md5sig.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build linux

package tcp

import (
Expand Down
12 changes: 12 additions & 0 deletions net/tcp/md5sig_stub.go
Original file line number Diff line number Diff line change
@@ -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")
}
2 changes: 1 addition & 1 deletion net/tcp/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions net/tcp/tcp_linux.go
Original file line number Diff line number Diff line change
@@ -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)
}
10 changes: 10 additions & 0 deletions net/tcp/tcp_stub.go
Original file line number Diff line number Diff line change
@@ -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")
}
Loading