* move "dnsctx" to "config"
This commit is contained in:
parent
af21a5f17b
commit
6701e9ce06
|
@ -70,6 +70,7 @@ type configuration struct {
|
||||||
versionCheckJSON []byte
|
versionCheckJSON []byte
|
||||||
versionCheckLastTime time.Time
|
versionCheckLastTime time.Time
|
||||||
|
|
||||||
|
dnsctx dnsContext
|
||||||
dnsServer *dnsforward.Server
|
dnsServer *dnsforward.Server
|
||||||
dhcpServer dhcpd.Server
|
dhcpServer dhcpd.Server
|
||||||
httpServer *http.Server
|
httpServer *http.Server
|
||||||
|
|
28
home/dns.go
28
home/dns.go
|
@ -30,8 +30,6 @@ type dnsContext struct {
|
||||||
upstream upstream.Upstream // Upstream object for our own DNS server
|
upstream upstream.Upstream // Upstream object for our own DNS server
|
||||||
}
|
}
|
||||||
|
|
||||||
var dnsctx dnsContext
|
|
||||||
|
|
||||||
// initDNSServer creates an instance of the dnsforward.Server
|
// initDNSServer creates an instance of the dnsforward.Server
|
||||||
// Please note that we must do it even if we don't start it
|
// Please note that we must do it even if we don't start it
|
||||||
// so that we had access to the query log and the stats
|
// so that we had access to the query log and the stats
|
||||||
|
@ -51,13 +49,13 @@ func initDNSServer(baseDir string) {
|
||||||
opts := upstream.Options{
|
opts := upstream.Options{
|
||||||
Timeout: rdnsTimeout,
|
Timeout: rdnsTimeout,
|
||||||
}
|
}
|
||||||
dnsctx.upstream, err = upstream.AddressToUpstream(resolverAddress, opts)
|
config.dnsctx.upstream, err = upstream.AddressToUpstream(resolverAddress, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("upstream.AddressToUpstream: %s", err)
|
log.Error("upstream.AddressToUpstream: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dnsctx.rdnsIP = make(map[string]bool)
|
config.dnsctx.rdnsIP = make(map[string]bool)
|
||||||
dnsctx.rdnsChannel = make(chan string, 256)
|
config.dnsctx.rdnsChannel = make(chan string, 256)
|
||||||
go asyncRDNSLoop()
|
go asyncRDNSLoop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,17 +69,17 @@ func beginAsyncRDNS(ip string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add IP to rdnsIP, if not exists
|
// add IP to rdnsIP, if not exists
|
||||||
dnsctx.rdnsLock.Lock()
|
config.dnsctx.rdnsLock.Lock()
|
||||||
defer dnsctx.rdnsLock.Unlock()
|
defer config.dnsctx.rdnsLock.Unlock()
|
||||||
_, ok := dnsctx.rdnsIP[ip]
|
_, ok := config.dnsctx.rdnsIP[ip]
|
||||||
if ok {
|
if ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dnsctx.rdnsIP[ip] = true
|
config.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 config.dnsctx.rdnsChannel <- ip:
|
||||||
//
|
//
|
||||||
default:
|
default:
|
||||||
log.Tracef("rDNS queue is full")
|
log.Tracef("rDNS queue is full")
|
||||||
|
@ -108,7 +106,7 @@ func resolveRDNS(ip string) string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := dnsctx.upstream.Exchange(&req)
|
resp, err := config.dnsctx.upstream.Exchange(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error while making an rDNS lookup for %s: %s", ip, err)
|
log.Error("Error while making an rDNS lookup for %s: %s", ip, err)
|
||||||
return ""
|
return ""
|
||||||
|
@ -136,16 +134,16 @@ func resolveRDNS(ip string) string {
|
||||||
func asyncRDNSLoop() {
|
func asyncRDNSLoop() {
|
||||||
for {
|
for {
|
||||||
var ip string
|
var ip string
|
||||||
ip = <-dnsctx.rdnsChannel
|
ip = <-config.dnsctx.rdnsChannel
|
||||||
|
|
||||||
host := resolveRDNS(ip)
|
host := resolveRDNS(ip)
|
||||||
if len(host) == 0 {
|
if len(host) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
dnsctx.rdnsLock.Lock()
|
config.dnsctx.rdnsLock.Lock()
|
||||||
delete(dnsctx.rdnsIP, ip)
|
delete(config.dnsctx.rdnsIP, ip)
|
||||||
dnsctx.rdnsLock.Unlock()
|
config.dnsctx.rdnsLock.Unlock()
|
||||||
|
|
||||||
_, _ = config.clients.AddHost(ip, host, ClientSourceRDNS)
|
_, _ = config.clients.AddHost(ip, host, ClientSourceRDNS)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue