mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-03 02:23:59 +00:00
45 lines
812 B
Go
45 lines
812 B
Go
package inbound
|
|
|
|
import (
|
|
"net"
|
|
"net/netip"
|
|
|
|
C "github.com/Dreamacro/clash/constant"
|
|
)
|
|
|
|
var skipAuthPrefixes []netip.Prefix
|
|
|
|
func SetSkipAuthPrefixes(prefixes []netip.Prefix) {
|
|
skipAuthPrefixes = prefixes
|
|
}
|
|
|
|
func SkipAuthPrefixes() []netip.Prefix {
|
|
return skipAuthPrefixes
|
|
}
|
|
|
|
func SkipAuthRemoteAddr(addr net.Addr) bool {
|
|
m := C.Metadata{}
|
|
if err := m.SetRemoteAddr(addr); err != nil {
|
|
return false
|
|
}
|
|
return skipAuth(m.AddrPort().Addr())
|
|
}
|
|
|
|
func SkipAuthRemoteAddress(addr string) bool {
|
|
m := C.Metadata{}
|
|
if err := m.SetRemoteAddress(addr); err != nil {
|
|
return false
|
|
}
|
|
return skipAuth(m.AddrPort().Addr())
|
|
}
|
|
|
|
func skipAuth(addr netip.Addr) bool {
|
|
if addr.IsValid() {
|
|
for _, prefix := range skipAuthPrefixes {
|
|
if prefix.Contains(addr.Unmap()) {
|
|
return true
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|