mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-05-27 12:52:27 +02:00
all: guarding against DNS forwarding loop
Based on how dnsmasq "--dns-loop-detect" mechanism. See: https://thekelleys.org.uk/dnsmasq/docs/dnsmasq-man.html
This commit is contained in:
committed by
Cuong Manh Le
parent
511c4e696f
commit
a9959a6f3d
@@ -59,6 +59,9 @@ type prog struct {
|
||||
um *upstreamMonitor
|
||||
router router.Router
|
||||
|
||||
loopMu sync.Mutex
|
||||
loop map[string]bool
|
||||
|
||||
started chan struct{}
|
||||
onStartedDone chan struct{}
|
||||
onStarted []func()
|
||||
@@ -91,6 +94,7 @@ func (p *prog) run() {
|
||||
numListeners := len(p.cfg.Listener)
|
||||
p.started = make(chan struct{}, numListeners)
|
||||
p.onStartedDone = make(chan struct{})
|
||||
p.loop = make(map[string]bool)
|
||||
if p.cfg.Service.CacheEnable {
|
||||
cacher, err := dnscache.NewLRUCache(p.cfg.Service.CacheSize)
|
||||
if err != nil {
|
||||
@@ -174,8 +178,13 @@ func (p *prog) run() {
|
||||
for _, f := range p.onStarted {
|
||||
f()
|
||||
}
|
||||
// Check for possible DNS loop.
|
||||
p.checkDnsLoop()
|
||||
close(p.onStartedDone)
|
||||
|
||||
// Start check DNS loop ticker.
|
||||
go p.checkDnsLoopTicker()
|
||||
|
||||
// Stop writing log to unix socket.
|
||||
consoleWriter.Out = os.Stdout
|
||||
initLoggingWithBackup(false)
|
||||
|
||||
Reference in New Issue
Block a user