mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-03 11:57:39 +03:00
BindToInterfaceFunc: allow block()/AutoDetectInterfaceFunc() to return error
to avoid Tun traffic loopback, AutoDetectInterfaceFunc() should return error when no valid interface is found
This commit is contained in:
parent
bc044ee31d
commit
3c4a2b06a9
1 changed files with 7 additions and 4 deletions
|
@ -15,9 +15,12 @@ func BindToInterface(finder InterfaceFinder, interfaceName string, interfaceInde
|
|||
}
|
||||
}
|
||||
|
||||
func BindToInterfaceFunc(finder InterfaceFinder, block func(network string, address string) (interfaceName string, interfaceIndex int)) Func {
|
||||
func BindToInterfaceFunc(finder InterfaceFinder, block func(network string, address string) (interfaceName string, interfaceIndex int, err error)) Func {
|
||||
return func(network, address string, conn syscall.RawConn) error {
|
||||
interfaceName, interfaceIndex := block(network, address)
|
||||
interfaceName, interfaceIndex, err := block(network, address)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return BindToInterface0(finder, conn, network, address, interfaceName, interfaceIndex)
|
||||
}
|
||||
}
|
||||
|
@ -25,10 +28,10 @@ func BindToInterfaceFunc(finder InterfaceFinder, block func(network string, addr
|
|||
const useInterfaceName = runtime.GOOS == "linux" || runtime.GOOS == "android"
|
||||
|
||||
func BindToInterface0(finder InterfaceFinder, conn syscall.RawConn, network string, address string, interfaceName string, interfaceIndex int) error {
|
||||
if addr := M.ParseSocksaddr(address).Addr; addr.IsValid() && N.IsVirtual(addr) {
|
||||
if interfaceName == "" && interfaceIndex == -1 {
|
||||
return nil
|
||||
}
|
||||
if interfaceName == "" && interfaceIndex == -1 {
|
||||
if addr := M.ParseSocksaddr(address).Addr; addr.IsValid() && N.IsVirtual(addr) {
|
||||
return nil
|
||||
}
|
||||
if interfaceName != "" && useInterfaceName || interfaceIndex != -1 && !useInterfaceName {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue