diff options
author | Hitoshi Irino <irino@sfc.wide.ad.jp> | 2019-06-24 00:39:22 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2019-07-02 11:40:22 +0900 |
commit | 2f5a4d59cb8d494bcf1a64d45d84bcd8fd4a7f06 (patch) | |
tree | 130afc174fe85d32abe3ad4994aecec3461ffcc4 /pkg/server/sockopt_linux.go | |
parent | 9f936065a907639661eca3924f0a8f09d94abbfe (diff) |
BGP connection on a speecified interface (including which is associated VRF) using syscall SO_BINDTODEVICE
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 } |