mirror of
https://github.com/MetaCubeX/Clash.Meta.git
synced 2025-04-11 04:50:56 +00:00
fix(dns): fix proxy nesting
This commit is contained in:
parent
09d5715826
commit
f213cd678f
1 changed files with 27 additions and 11 deletions
|
@ -24,22 +24,38 @@ type ruleMatcher struct {
|
|||
func (r *ruleMatcher) MatchDomain(domain string) bool {
|
||||
typ, found := cache.Get(domain)
|
||||
if !found {
|
||||
p, _, err := tunnel.ResolveMetadata(
|
||||
&C.Metadata{
|
||||
NetWork: C.TCP,
|
||||
Type: C.INNER, // avoid process lookup
|
||||
Host: domain,
|
||||
DstIP: netip.AddrFrom4([4]byte{}), // avoid dns lookup
|
||||
},
|
||||
)
|
||||
meta := &C.Metadata{
|
||||
NetWork: C.TCP,
|
||||
Type: C.INNER, // avoid process lookup
|
||||
Host: domain,
|
||||
DstIP: netip.AddrFrom4([4]byte{}), // avoid dns lookup
|
||||
}
|
||||
p, _, err := tunnel.ResolveMetadata(meta)
|
||||
if err != nil {
|
||||
log.Warnln("[DNS] ruleMatcher: match(%s) got err %v", domain, err.Error())
|
||||
return false
|
||||
}
|
||||
log.Debugln("[DNS] ruleMatcher: match(%s) -> %s", domain, p.Type().String())
|
||||
cache.Set(domain, p.Type())
|
||||
typ = p.Type()
|
||||
// parse multi-layer nesting
|
||||
adapter := p
|
||||
for {
|
||||
next := adapter.Unwrap(meta, false)
|
||||
if next != nil {
|
||||
adapter = next
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
typ = adapter.Type()
|
||||
cache.Set(domain, typ)
|
||||
}
|
||||
ret := ruleMatch(typ, r)
|
||||
log.Debugln("[DNS] ruleMatcher: domain(%s, %s) rule(%s), match: %v",
|
||||
domain, typ.String(), r.typ, ret)
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func ruleMatch(typ C.AdapterType, r *ruleMatcher) bool {
|
||||
switch typ {
|
||||
case C.Direct, C.Compatible:
|
||||
if r.typ == "direct" {
|
||||
|
|
Loading…
Add table
Reference in a new issue