From 499beb7344220523e3c070c1f87ad4ee0abb34cf Mon Sep 17 00:00:00 2001 From: Dreamacro <8615343+Dreamacro@users.noreply.github.com> Date: Wed, 10 Nov 2021 22:19:11 +0800 Subject: [PATCH] Fix: bind iface should throw control error --- component/dialer/bind_darwin.go | 13 ++++++++++--- component/dialer/bind_linux.go | 11 +++++++++-- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/component/dialer/bind_darwin.go b/component/dialer/bind_darwin.go index b3ae9d81..bf51b305 100644 --- a/component/dialer/bind_darwin.go +++ b/component/dialer/bind_darwin.go @@ -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 } } diff --git a/component/dialer/bind_linux.go b/component/dialer/bind_linux.go index ae772a71..97d37cfa 100644 --- a/component/dialer/bind_linux.go +++ b/component/dialer/bind_linux.go @@ -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 } }