From 405a6f699d7b059ee86121886d01f58fc75e37b3 Mon Sep 17 00:00:00 2001 From: Quentin McGaw Date: Mon, 23 Mar 2026 13:40:27 +0000 Subject: [PATCH] hotfix(dns): always run and use built-in DNS server - start DNS server before healthcheck - do not fallback to plaintext anymore - allow to use plain addresses with a port different than 53, system-wide - do not wait for the DNS server and rely on healtcheck only --- internal/dns/plaintext.go | 37 ------------------------------------- internal/dns/run.go | 7 ------- internal/dns/setup.go | 7 ------- internal/vpn/tunnelup.go | 4 ++-- 4 files changed, 2 insertions(+), 53 deletions(-) delete mode 100644 internal/dns/plaintext.go diff --git a/internal/dns/plaintext.go b/internal/dns/plaintext.go deleted file mode 100644 index 728a4b99..00000000 --- a/internal/dns/plaintext.go +++ /dev/null @@ -1,37 +0,0 @@ -package dns - -import ( - "net/netip" - "time" - - "github.com/qdm12/dns/v2/pkg/nameserver" -) - -func (l *Loop) useUnencryptedDNS(fallback bool) { - settings := l.GetSettings() - - targetIP := settings.GetFirstPlaintextIPv4() - - if fallback { - l.logger.Info("falling back on plaintext DNS at address " + targetIP.String()) - } else { - l.logger.Info("using plaintext DNS at address " + targetIP.String()) - } - - const dialTimeout = 3 * time.Second - const defaultDNSPort = 53 - settingsInternalDNS := nameserver.SettingsInternalDNS{ - AddrPort: netip.AddrPortFrom(targetIP, defaultDNSPort), - Timeout: dialTimeout, - } - nameserver.UseDNSInternally(settingsInternalDNS) - - settingsSystemWide := nameserver.SettingsSystemDNS{ - IPs: []netip.Addr{targetIP}, - ResolvPath: l.resolvConf, - } - err := nameserver.UseDNSSystemWide(settingsSystemWide) - if err != nil { - l.logger.Error(err.Error()) - } -} diff --git a/internal/dns/run.go b/internal/dns/run.go index 068a8097..7f509168 100644 --- a/internal/dns/run.go +++ b/internal/dns/run.go @@ -18,9 +18,6 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) { return } - const fallback = false - l.useUnencryptedDNS(fallback) - select { case <-l.start: case <-ctx.Done(): @@ -83,8 +80,6 @@ func (l *Loop) runWait(ctx context.Context, runError <-chan error) (exitLoop boo case <-l.stop: l.userTrigger = true l.logger.Info("stopping") - const fallback = false - l.useUnencryptedDNS(fallback) l.stopServer() l.stopped <- struct{}{} case <-l.start: @@ -93,8 +88,6 @@ func (l *Loop) runWait(ctx context.Context, runError <-chan error) (exitLoop boo return false case err := <-runError: // unexpected error l.statusManager.SetStatus(constants.Crashed) - const fallback = true - l.useUnencryptedDNS(fallback) l.logAndWait(ctx, err) return false } diff --git a/internal/dns/setup.go b/internal/dns/setup.go index 8e83de3c..4776f0fd 100644 --- a/internal/dns/setup.go +++ b/internal/dns/setup.go @@ -4,7 +4,6 @@ import ( "context" "fmt" - "github.com/qdm12/dns/v2/pkg/check" "github.com/qdm12/dns/v2/pkg/middlewares/filter/update" "github.com/qdm12/dns/v2/pkg/nameserver" "github.com/qdm12/dns/v2/pkg/server" @@ -44,11 +43,5 @@ func (l *Loop) setupServer(ctx context.Context, settings settings.DNS) (runError l.logger.Error(err.Error()) } - err = check.WaitForDNS(ctx, check.Settings{}) - if err != nil { - l.stopServer() - return nil, err - } - return runError, nil } diff --git a/internal/vpn/tunnelup.go b/internal/vpn/tunnelup.go index 372345d1..0465ed56 100644 --- a/internal/vpn/tunnelup.go +++ b/internal/vpn/tunnelup.go @@ -76,6 +76,8 @@ func (l *Loop) onTunnelUp(ctx, loopCtx context.Context, data tunnelUpData) { } } + _, _ = l.dnsLooper.ApplyStatus(ctx, constants.Running) + icmpTargetIPs := l.healthSettings.ICMPTargetIPs if len(icmpTargetIPs) == 1 && icmpTargetIPs[0].IsUnspecified() { icmpTargetIPs = []netip.Addr{data.serverIP} @@ -101,8 +103,6 @@ func (l *Loop) onTunnelUp(ctx, loopCtx context.Context, data tunnelUpData) { // to start monitoring health and auto-healing. go l.collectHealthErrors(ctx, loopCtx, healthErrCh) - _, _ = l.dnsLooper.ApplyStatus(ctx, constants.Running) - err = l.publicip.RunOnce(ctx) if err != nil { l.logger.Error("getting public IP address information: " + err.Error())