fix: domain match

This commit is contained in:
mzz2017
2023-02-19 14:08:13 +08:00
parent 0d9892fff2
commit a011c2a74c
10 changed files with 411 additions and 63 deletions

View File

@ -372,7 +372,7 @@ func (c *ControlPlane) finishInitDnsUpstreamResolve(raw common.UrlOrEmpty, dnsUp
A: dnsUpstream.Ip4.As4(),
},
}}
if err = c.UpdateDnsCache(fqdn, typ, answers, deadline); err != nil {
if err = c.UpdateDnsCache(dnsUpstream.Hostname, typ, answers, deadline); err != nil {
c = nil
return
}
@ -391,7 +391,7 @@ func (c *ControlPlane) finishInitDnsUpstreamResolve(raw common.UrlOrEmpty, dnsUp
AAAA: dnsUpstream.Ip6.As16(),
},
}}
if err = c.UpdateDnsCache(fqdn, typ, answers, deadline); err != nil {
if err = c.UpdateDnsCache(dnsUpstream.Hostname, typ, answers, deadline); err != nil {
c = nil
return
}

View File

@ -331,12 +331,19 @@ loop:
}
func (c *ControlPlane) UpdateDnsCache(host string, typ dnsmessage.Type, answers []dnsmessage.Resource, deadline time.Time) (err error) {
c.dnsCacheMu.Lock()
fqdn := strings.ToLower(host)
if !strings.HasSuffix(fqdn, ".") {
fqdn += "."
var fqdn string
if strings.HasSuffix(host, ".") {
fqdn = host
host = host[:len(host)-1]
} else {
fqdn = host + "."
}
// Bypass pure IP.
if _, err = netip.ParseAddr(host); err == nil {
return nil
}
cacheKey := fqdn + typ.String()
c.dnsCacheMu.Lock()
cache, ok := c.dnsCache[cacheKey]
if ok {
c.dnsCacheMu.Unlock()