all: leaking queries to OS resolver instead of SRVFAIL

So it would work in more general case than just captive portal network,
which ctrld have supported recently.

Uses who may want no leaking behavior can use a config to turn off this
feature.
This commit is contained in:
Cuong Manh Le
2024-09-23 18:27:14 +07:00
committed by Cuong Manh Le
parent cfe1209d61
commit 3e388c2857
6 changed files with 69 additions and 53 deletions
+16 -4
View File
@@ -107,9 +107,9 @@ type prog struct {
loopMu sync.Mutex
loop map[string]bool
captivePortalMu sync.Mutex
captivePortalCheckWasRun bool
captivePortalDetected atomic.Bool
leakingQueryMu sync.Mutex
leakingQueryWasRun bool
leakingQuery atomic.Bool
started chan struct{}
onStartedDone chan struct{}
@@ -685,7 +685,7 @@ func (p *prog) dnsWatchdog(iface *net.Interface, nameservers []string, allIfaces
mainLog.Load().Debug().Msg("stop dns watchdog")
return
case <-ticker.C:
if p.captivePortalDetected.Load() {
if p.leakingQuery.Load() {
return
}
if dnsChanged(iface, ns) {
@@ -742,6 +742,18 @@ func (p *prog) resetDNS() {
}
}
// leakOnUpstreamFailure reports whether ctrld should leak query to OS resolver when failed to connect all upstreams.
func (p *prog) leakOnUpstreamFailure() bool {
if ptr := p.cfg.Service.LeakOnUpstreamFailure; ptr != nil {
return *ptr
}
// Default is false on routers, since this leaking is only useful for devices that move between networks.
if router.Name() != "" {
return false
}
return true
}
func randomLocalIP() string {
n := rand.Intn(254-2) + 2
return fmt.Sprintf("127.0.0.%d", n)