github.com/metacubex/mihomo@v1.18.5/adapter/inbound/auth.go (about) 1 package inbound 2 3 import ( 4 "net" 5 "net/netip" 6 7 C "github.com/metacubex/mihomo/constant" 8 ) 9 10 var skipAuthPrefixes []netip.Prefix 11 12 func SetSkipAuthPrefixes(prefixes []netip.Prefix) { 13 skipAuthPrefixes = prefixes 14 } 15 16 func SkipAuthPrefixes() []netip.Prefix { 17 return skipAuthPrefixes 18 } 19 20 func SkipAuthRemoteAddr(addr net.Addr) bool { 21 m := C.Metadata{} 22 if err := m.SetRemoteAddr(addr); err != nil { 23 return false 24 } 25 return skipAuth(m.AddrPort().Addr()) 26 } 27 28 func SkipAuthRemoteAddress(addr string) bool { 29 m := C.Metadata{} 30 if err := m.SetRemoteAddress(addr); err != nil { 31 return false 32 } 33 return skipAuth(m.AddrPort().Addr()) 34 } 35 36 func skipAuth(addr netip.Addr) bool { 37 if addr.IsValid() { 38 for _, prefix := range skipAuthPrefixes { 39 if prefix.Contains(addr.Unmap()) { 40 return true 41 } 42 } 43 } 44 return false 45 }