mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 20:37:40 +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
1453c7c8c2
commit
abcdbcba64
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 {
|
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)
|
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"
|
const useInterfaceName = runtime.GOOS == "linux" || runtime.GOOS == "android"
|
||||||
|
|
||||||
func BindToInterface0(finder InterfaceFinder, conn syscall.RawConn, network string, address string, interfaceName string, interfaceIndex int) error {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
if interfaceName == "" && interfaceIndex == -1 {
|
if addr := M.ParseSocksaddr(address).Addr; addr.IsValid() && N.IsVirtual(addr) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if interfaceName != "" && useInterfaceName || interfaceIndex != -1 && !useInterfaceName {
|
if interfaceName != "" && useInterfaceName || interfaceIndex != -1 && !useInterfaceName {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue