Merge branch 'master' of ssh://bit.adguard.com:7999/dns/adguard-dns
This commit is contained in:
commit
3454bf9243
31
dns.go
31
dns.go
|
@ -68,6 +68,19 @@ func isRunning() bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func beginAsyncRDNS(ip string) {
|
func beginAsyncRDNS(ip string) {
|
||||||
|
if clientExists(ip) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// add IP to rdnsIP, if not exists
|
||||||
|
dnsctx.rdnsLock.Lock()
|
||||||
|
defer dnsctx.rdnsLock.Unlock()
|
||||||
|
_, ok := dnsctx.rdnsIP[ip]
|
||||||
|
if ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
dnsctx.rdnsIP[ip] = true
|
||||||
|
|
||||||
log.Tracef("Adding %s for rDNS resolve", ip)
|
log.Tracef("Adding %s for rDNS resolve", ip)
|
||||||
select {
|
select {
|
||||||
case dnsctx.rdnsChannel <- ip:
|
case dnsctx.rdnsChannel <- ip:
|
||||||
|
@ -143,19 +156,6 @@ func asyncRDNSLoop() {
|
||||||
func onDNSRequest(d *proxy.DNSContext) {
|
func onDNSRequest(d *proxy.DNSContext) {
|
||||||
if d.Req.Question[0].Qtype == dns.TypeA {
|
if d.Req.Question[0].Qtype == dns.TypeA {
|
||||||
ip, _, _ := net.SplitHostPort(d.Addr.String())
|
ip, _, _ := net.SplitHostPort(d.Addr.String())
|
||||||
if clientExists(ip) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// add IP to rdnsIP, if not exists
|
|
||||||
dnsctx.rdnsLock.Lock()
|
|
||||||
defer dnsctx.rdnsLock.Unlock()
|
|
||||||
_, ok := dnsctx.rdnsIP[ip]
|
|
||||||
if ok {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
dnsctx.rdnsIP[ip] = true
|
|
||||||
|
|
||||||
beginAsyncRDNS(ip)
|
beginAsyncRDNS(ip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,6 +238,11 @@ func startDNSServer() error {
|
||||||
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
|
return errorx.Decorate(err, "Couldn't start forwarding DNS server")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
top := dnsServer.GetStatsTop()
|
||||||
|
for k := range top.Clients {
|
||||||
|
beginAsyncRDNS(k)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue