mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-02-23 12:42:27 +08:00
fix: geoip wrong matching logic in fallback-filter
https://github.com/MetaCubeX/mihomo/issues/1478
This commit is contained in:
parent
4fecf68b8b
commit
a96f72ade4
@ -1473,7 +1473,7 @@ func parseDNS(rawCfg *RawConfig, hosts *trie.DomainTrie[resolver.HostValue], rul
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("load GeoIP dns fallback filter error, %w", err)
|
return nil, fmt.Errorf("load GeoIP dns fallback filter error, %w", err)
|
||||||
}
|
}
|
||||||
dnsCfg.FallbackIPFilter = append(dnsCfg.FallbackIPFilter, matcher)
|
dnsCfg.FallbackIPFilter = append(dnsCfg.FallbackIPFilter, matcher.DnsFallbackFilter())
|
||||||
}
|
}
|
||||||
if len(cfg.FallbackFilter.IPCIDR) > 0 {
|
if len(cfg.FallbackFilter.IPCIDR) > 0 {
|
||||||
cidrSet := cidr.NewIpCidrSet()
|
cidrSet := cidr.NewIpCidrSet()
|
||||||
|
@ -22,7 +22,6 @@ type GEOIP struct {
|
|||||||
adapter string
|
adapter string
|
||||||
noResolveIP bool
|
noResolveIP bool
|
||||||
isSourceIP bool
|
isSourceIP bool
|
||||||
geodata bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ C.Rule = (*GEOIP)(nil)
|
var _ C.Rule = (*GEOIP)(nil)
|
||||||
@ -115,6 +114,36 @@ func (g *GEOIP) MatchIp(ip netip.Addr) bool {
|
|||||||
return slices.Contains(codes, g.country)
|
return slices.Contains(codes, g.country)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MatchIp implements C.IpMatcher
|
||||||
|
func (g dnsFallbackFilter) MatchIp(ip netip.Addr) bool {
|
||||||
|
if !ip.IsValid() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if g.isLan(ip) { // compatible with original behavior
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if C.GeodataMode {
|
||||||
|
matcher, err := g.getIPMatcher()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return !matcher.Match(ip)
|
||||||
|
}
|
||||||
|
|
||||||
|
codes := mmdb.IPInstance().LookupCode(ip.AsSlice())
|
||||||
|
return !slices.Contains(codes, g.country)
|
||||||
|
}
|
||||||
|
|
||||||
|
type dnsFallbackFilter struct {
|
||||||
|
*GEOIP
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *GEOIP) DnsFallbackFilter() C.IpMatcher { // for dns.fallback-filter.geoip
|
||||||
|
return dnsFallbackFilter{GEOIP: g}
|
||||||
|
}
|
||||||
|
|
||||||
func (g *GEOIP) isLan(ip netip.Addr) bool {
|
func (g *GEOIP) isLan(ip netip.Addr) bool {
|
||||||
return ip.IsPrivate() ||
|
return ip.IsPrivate() ||
|
||||||
ip.IsUnspecified() ||
|
ip.IsUnspecified() ||
|
||||||
|
Loading…
Reference in New Issue
Block a user