Merge from remote branch

This commit is contained in:
yaling888 2021-11-11 00:54:43 +08:00
commit a412745314
2 changed files with 19 additions and 5 deletions

View file

@ -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 { switch network {
case "tcp4", "udp4": 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": 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
} }
} }

View file

@ -25,9 +25,16 @@ func bindControl(ifaceName string, chain controlFn) controlFn {
} }
} }
return c.Control(func(fd uintptr) { var innerErr error
unix.BindToDevice(int(fd), ifaceName) err = c.Control(func(fd uintptr) {
innerErr = unix.BindToDevice(int(fd), ifaceName)
}) })
if innerErr != nil {
err = innerErr
}
return
} }
} }