mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-06 20:10:11 +02:00
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
This commit is contained in:
@@ -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())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,9 +18,6 @@ func (l *Loop) Run(ctx context.Context, done chan<- struct{}) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const fallback = false
|
|
||||||
l.useUnencryptedDNS(fallback)
|
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-l.start:
|
case <-l.start:
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
@@ -83,8 +80,6 @@ func (l *Loop) runWait(ctx context.Context, runError <-chan error) (exitLoop boo
|
|||||||
case <-l.stop:
|
case <-l.stop:
|
||||||
l.userTrigger = true
|
l.userTrigger = true
|
||||||
l.logger.Info("stopping")
|
l.logger.Info("stopping")
|
||||||
const fallback = false
|
|
||||||
l.useUnencryptedDNS(fallback)
|
|
||||||
l.stopServer()
|
l.stopServer()
|
||||||
l.stopped <- struct{}{}
|
l.stopped <- struct{}{}
|
||||||
case <-l.start:
|
case <-l.start:
|
||||||
@@ -93,8 +88,6 @@ func (l *Loop) runWait(ctx context.Context, runError <-chan error) (exitLoop boo
|
|||||||
return false
|
return false
|
||||||
case err := <-runError: // unexpected error
|
case err := <-runError: // unexpected error
|
||||||
l.statusManager.SetStatus(constants.Crashed)
|
l.statusManager.SetStatus(constants.Crashed)
|
||||||
const fallback = true
|
|
||||||
l.useUnencryptedDNS(fallback)
|
|
||||||
l.logAndWait(ctx, err)
|
l.logAndWait(ctx, err)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/qdm12/dns/v2/pkg/check"
|
|
||||||
"github.com/qdm12/dns/v2/pkg/middlewares/filter/update"
|
"github.com/qdm12/dns/v2/pkg/middlewares/filter/update"
|
||||||
"github.com/qdm12/dns/v2/pkg/nameserver"
|
"github.com/qdm12/dns/v2/pkg/nameserver"
|
||||||
"github.com/qdm12/dns/v2/pkg/server"
|
"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())
|
l.logger.Error(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
err = check.WaitForDNS(ctx, check.Settings{})
|
|
||||||
if err != nil {
|
|
||||||
l.stopServer()
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return runError, nil
|
return runError, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,8 @@ func (l *Loop) onTunnelUp(ctx, loopCtx context.Context, data tunnelUpData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_, _ = l.dnsLooper.ApplyStatus(ctx, constants.Running)
|
||||||
|
|
||||||
icmpTargetIPs := l.healthSettings.ICMPTargetIPs
|
icmpTargetIPs := l.healthSettings.ICMPTargetIPs
|
||||||
if len(icmpTargetIPs) == 1 && icmpTargetIPs[0].IsUnspecified() {
|
if len(icmpTargetIPs) == 1 && icmpTargetIPs[0].IsUnspecified() {
|
||||||
icmpTargetIPs = []netip.Addr{data.serverIP}
|
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.
|
// to start monitoring health and auto-healing.
|
||||||
go l.collectHealthErrors(ctx, loopCtx, healthErrCh)
|
go l.collectHealthErrors(ctx, loopCtx, healthErrCh)
|
||||||
|
|
||||||
_, _ = l.dnsLooper.ApplyStatus(ctx, constants.Running)
|
|
||||||
|
|
||||||
err = l.publicip.RunOnce(ctx)
|
err = l.publicip.RunOnce(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.logger.Error("getting public IP address information: " + err.Error())
|
l.logger.Error("getting public IP address information: " + err.Error())
|
||||||
|
|||||||
Reference in New Issue
Block a user