Fix bind control

This commit is contained in:
世界 2022-09-26 13:49:00 +08:00
parent b12b8b7fd2
commit 7209937cc2
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
2 changed files with 14 additions and 1 deletions

View file

@ -25,7 +25,7 @@ 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.IsPublicAddr(addr) {
if addr := M.ParseSocksaddr(address).Addr; addr.IsValid() && N.IsVirtual(addr) {
return nil
}
if interfaceName == "" && interfaceIndex == -1 {
@ -46,5 +46,14 @@ func BindToInterface0(finder InterfaceFinder, conn syscall.RawConn, network stri
if err != nil {
return err
}
if useInterfaceName {
if interfaceName == "" {
return nil
}
} else {
if interfaceIndex == -1 {
return nil
}
}
return bindToInterface(conn, network, address, interfaceName, interfaceIndex)
}

View file

@ -20,6 +20,10 @@ func IsPublicAddr(addr netip.Addr) bool {
return !(addr.IsPrivate() || addr.IsLoopback() || addr.IsMulticast() || addr.IsLinkLocalUnicast() || addr.IsInterfaceLocalMulticast())
}
func IsVirtual(addr netip.Addr) bool {
return addr.IsLoopback() || addr.IsMulticast() || addr.IsInterfaceLocalMulticast()
}
func LocalPublicAddrs() ([]netip.Addr, error) {
publicAddrs, err := LocalAddrs()
if err != nil {