Skip to content

Commit

Permalink
Fix: bind iface should throw control error
Browse files Browse the repository at this point in the history
  • Loading branch information
Dreamacro committed Nov 10, 2021
1 parent c9be614 commit 499beb7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
13 changes: 10 additions & 3 deletions component/dialer/bind_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,21 @@ func bindControl(ifaceIdx int, chain controlFn) controlFn {
}
}

return c.Control(func(fd uintptr) {
var innerErr error
err = c.Control(func(fd uintptr) {
switch network {
case "tcp4", "udp4":
unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_BOUND_IF, ifaceIdx)
innerErr = unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_BOUND_IF, ifaceIdx)
case "tcp6", "udp6":
unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_BOUND_IF, ifaceIdx)
innerErr = unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_BOUND_IF, ifaceIdx)
}
})

if innerErr != nil {
err = innerErr
}

return
}
}

Expand Down
11 changes: 9 additions & 2 deletions component/dialer/bind_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,16 @@ func bindControl(ifaceName string, chain controlFn) controlFn {
}
}

return c.Control(func(fd uintptr) {
unix.BindToDevice(int(fd), ifaceName)
var innerErr error
err = c.Control(func(fd uintptr) {
innerErr = unix.BindToDevice(int(fd), ifaceName)
})

if innerErr != nil {
err = innerErr
}

return
}
}

Expand Down

0 comments on commit 499beb7

Please sign in to comment.