mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-12-22 15:47:59 +08:00
fix: process IPv6 Link-Local address (#1657)
Some checks failed
Trigger CMFA Update / trigger-CMFA-update (push) Failing after 8s
Some checks failed
Trigger CMFA Update / trigger-CMFA-update (push) Failing after 8s
This commit is contained in:
parent
25b3c86d31
commit
80e4eaad14
@ -34,12 +34,5 @@ func SkipAuthRemoteAddress(addr string) bool {
|
||||
}
|
||||
|
||||
func skipAuth(addr netip.Addr) bool {
|
||||
if addr.IsValid() {
|
||||
for _, prefix := range skipAuthPrefixes {
|
||||
if prefix.Contains(addr.Unmap()) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
return prefixesContains(skipAuthPrefixes, addr)
|
||||
}
|
||||
|
@ -31,27 +31,17 @@ func IsRemoteAddrDisAllowed(addr net.Addr) bool {
|
||||
if err := m.SetRemoteAddr(addr); err != nil {
|
||||
return false
|
||||
}
|
||||
return isAllowed(m.AddrPort().Addr().Unmap()) && !isDisAllowed(m.AddrPort().Addr().Unmap())
|
||||
ipAddr := m.AddrPort().Addr()
|
||||
if ipAddr.IsValid() {
|
||||
return isAllowed(ipAddr) && !isDisAllowed(ipAddr)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func isAllowed(addr netip.Addr) bool {
|
||||
if addr.IsValid() {
|
||||
for _, prefix := range lanAllowedIPs {
|
||||
if prefix.Contains(addr) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
return prefixesContains(lanAllowedIPs, addr)
|
||||
}
|
||||
|
||||
func isDisAllowed(addr netip.Addr) bool {
|
||||
if addr.IsValid() {
|
||||
for _, prefix := range lanDisAllowedIPs {
|
||||
if prefix.Contains(addr) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
return prefixesContains(lanDisAllowedIPs, addr)
|
||||
}
|
||||
|
@ -61,3 +61,19 @@ func parseHTTPAddr(request *http.Request) *C.Metadata {
|
||||
|
||||
return metadata
|
||||
}
|
||||
|
||||
func prefixesContains(prefixes []netip.Prefix, addr netip.Addr) bool {
|
||||
if len(prefixes) == 0 {
|
||||
return false
|
||||
}
|
||||
if !addr.IsValid() {
|
||||
return false
|
||||
}
|
||||
addr = addr.Unmap().WithZone("") // netip.Prefix.Contains returns false if ip has an IPv6 zone
|
||||
for _, prefix := range prefixes {
|
||||
if prefix.Contains(addr) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ func (i *IPCIDR) Match(metadata *C.Metadata) (bool, string) {
|
||||
if i.isSourceIP {
|
||||
ip = metadata.SrcIP
|
||||
}
|
||||
return ip.IsValid() && i.ipnet.Contains(ip), i.adapter
|
||||
return ip.IsValid() && i.ipnet.Contains(ip.WithZone("")), i.adapter
|
||||
}
|
||||
|
||||
func (i *IPCIDR) Adapter() string {
|
||||
|
Loading…
Reference in New Issue
Block a user