chore: code cleanup

This commit is contained in:
wwqgtxx
2023-10-11 22:54:19 +08:00
parent 0dc6a726c1
commit 129283066f
14 changed files with 97 additions and 106 deletions

View File

@@ -3,6 +3,8 @@ package inbound
import (
"net"
"net/netip"
C "github.com/Dreamacro/clash/constant"
)
var skipAuthPrefixes []netip.Prefix
@@ -16,9 +18,25 @@ func SkipAuthPrefixes() []netip.Prefix {
}
func SkipAuthRemoteAddr(addr net.Addr) bool {
if addrPort := parseAddr(addr); addrPort.IsValid() {
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(addrPort.Addr().Unmap()) {
if prefix.Contains(addr.Unmap()) {
return true
}
}