diff options
Diffstat (limited to 'pkg/server/sockopt_linux.go')
-rw-r--r-- | pkg/server/sockopt_linux.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/pkg/server/sockopt_linux.go b/pkg/server/sockopt_linux.go index 31df8397..203087ab 100644 --- a/pkg/server/sockopt_linux.go +++ b/pkg/server/sockopt_linux.go @@ -103,7 +103,7 @@ func setTCPMinTTLSockopt(conn *net.TCPConn, ttl int) error { return setsockOptInt(sc, level, name, ttl) } -func dialerControl(network, address string, c syscall.RawConn, ttl, minTtl uint8, password string) error { +func dialerControl(network, address string, c syscall.RawConn, ttl, minTtl uint8, password string, bindInterface string) error { family := syscall.AF_INET raddr, _ := net.ResolveTCPAddr("tcp", address) if raddr.IP.To4() == nil { @@ -161,5 +161,15 @@ func dialerControl(network, address string, c syscall.RawConn, ttl, minTtl uint8 return sockerr } } + if bindInterface != "" { + if err := c.Control(func(fd uintptr) { + sockerr = os.NewSyscallError("setsockopt", syscall.SetsockoptString(int(fd), syscall.SOL_SOCKET, syscall.SO_BINDTODEVICE, bindInterface)) + }); err != nil { + return err + } + if sockerr != nil { + return sockerr + } + } return nil } |