Fix #235: DNS over TLS log messages

This commit is contained in:
Quentin McGaw
2020-09-09 21:44:50 +00:00
parent 443c7e36d7
commit 5b3cbb6906

View File

@@ -141,7 +141,8 @@ func (l *looper) waitForSubsequentStart(ctx context.Context, unboundCancel conte
func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) { func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
wg.Add(1) wg.Add(1)
defer wg.Done() defer wg.Done()
l.fallbackToUnencryptedDNS() const fallback = false
l.useUnencryptedDNS(fallback)
l.waitForFirstStart(ctx) l.waitForFirstStart(ctx)
if ctx.Err() != nil { if ctx.Err() != nil {
return return
@@ -182,7 +183,8 @@ func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
stream, waitFn, err := l.conf.Start(unboundCtx, settings.VerbosityDetailsLevel) stream, waitFn, err := l.conf.Start(unboundCtx, settings.VerbosityDetailsLevel)
if err != nil { if err != nil {
unboundCancel() unboundCancel()
l.fallbackToUnencryptedDNS() const fallback = true
l.useUnencryptedDNS(fallback)
l.logAndWait(ctx, err) l.logAndWait(ctx, err)
continue continue
} }
@@ -195,7 +197,8 @@ func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
} }
if err := l.conf.WaitForUnbound(); err != nil { if err := l.conf.WaitForUnbound(); err != nil {
unboundCancel() unboundCancel()
l.fallbackToUnencryptedDNS() const fallback = true
l.useUnencryptedDNS(fallback)
l.logAndWait(ctx, err) l.logAndWait(ctx, err)
continue continue
} }
@@ -204,6 +207,7 @@ func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
err := waitFn() // blocking err := waitFn() // blocking
waitError <- err waitError <- err
}() }()
l.logger.Info("DNS over TLS is ready")
stayHere := true stayHere := true
for stayHere { for stayHere {
@@ -231,7 +235,8 @@ func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
case err := <-waitError: // unexpected error case err := <-waitError: // unexpected error
close(waitError) close(waitError)
unboundCancel() unboundCancel()
l.fallbackToUnencryptedDNS() const fallback = true
l.useUnencryptedDNS(fallback)
l.logAndWait(ctx, err) l.logAndWait(ctx, err)
stayHere = false stayHere = false
} }
@@ -240,13 +245,17 @@ func (l *looper) Run(ctx context.Context, wg *sync.WaitGroup) {
unboundCancel() unboundCancel()
} }
func (l *looper) fallbackToUnencryptedDNS() { func (l *looper) useUnencryptedDNS(fallback bool) {
settings := l.GetSettings() settings := l.GetSettings()
// Try with user provided plaintext ip address // Try with user provided plaintext ip address
targetIP := settings.PlaintextAddress targetIP := settings.PlaintextAddress
if targetIP != nil { if targetIP != nil {
l.logger.Info("falling back on plaintext DNS at address %s", targetIP) if fallback {
l.logger.Info("falling back on plaintext DNS at address %s", targetIP)
} else {
l.logger.Info("using plaintext DNS at address %s", targetIP)
}
l.conf.UseDNSInternally(targetIP) l.conf.UseDNSInternally(targetIP)
if err := l.conf.UseDNSSystemWide(targetIP, settings.KeepNameserver); err != nil { if err := l.conf.UseDNSSystemWide(targetIP, settings.KeepNameserver); err != nil {
l.logger.Error(err) l.logger.Error(err)