mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-04 20:37:40 +03:00
Fix bind control
This commit is contained in:
parent
b12b8b7fd2
commit
7209937cc2
2 changed files with 14 additions and 1 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue