Check for empty nameserver list

This commit is contained in:
Viktor Liu 2025-06-12 23:14:35 +02:00
parent 806447db7a
commit 137370de05
2 changed files with 8 additions and 7 deletions

View File

@ -716,7 +716,7 @@ func (s *DefaultServer) updateMux(muxUpdates []handlerWrapper) {
} }
// If there's no root update and we had a root handler, restore it // If there's no root update and we had a root handler, restore it
if !containsRootUpdate && runtime.GOOS == "android" { if !containsRootUpdate {
for _, existing := range s.dnsMuxMap { for _, existing := range s.dnsMuxMap {
if existing.domain == nbdns.RootZone { if existing.domain == nbdns.RootZone {
s.addHostRootZone() s.addHostRootZone()
@ -809,6 +809,12 @@ func (s *DefaultServer) upstreamCallbacks(
} }
func (s *DefaultServer) addHostRootZone() { func (s *DefaultServer) addHostRootZone() {
hostDNSServers := s.hostsDNSHolder.get()
if len(hostDNSServers) == 0 {
log.Debug("no host DNS servers available, skipping root zone handler creation")
return
}
handler, err := newUpstreamResolver( handler, err := newUpstreamResolver(
s.ctx, s.ctx,
s.wgInterface.Name(), s.wgInterface.Name(),
@ -824,7 +830,7 @@ func (s *DefaultServer) addHostRootZone() {
} }
handler.upstreamServers = make([]string, 0) handler.upstreamServers = make([]string, 0)
for k := range s.hostsDNSHolder.get() { for k := range hostDNSServers {
handler.upstreamServers = append(handler.upstreamServers, k) handler.upstreamServers = append(handler.upstreamServers, k)
} }
handler.deactivate = func(error) {} handler.deactivate = func(error) {}

View File

@ -6,7 +6,6 @@ import (
"net" "net"
"net/netip" "net/netip"
"os" "os"
"runtime"
"strings" "strings"
"testing" "testing"
"time" "time"
@ -726,10 +725,6 @@ func TestDNSPermanent_updateHostDNS_emptyUpstream(t *testing.T) {
} }
func TestDNSPermanent_updateUpstream(t *testing.T) { func TestDNSPermanent_updateUpstream(t *testing.T) {
if runtime.GOOS != "android" {
t.Skip("This test is only for Android")
}
wgIFace, err := createWgInterfaceWithBind(t) wgIFace, err := createWgInterfaceWithBind(t)
if err != nil { if err != nil {
t.Fatal("failed to initialize wg interface") t.Fatal("failed to initialize wg interface")