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 !containsRootUpdate && runtime.GOOS == "android" {
if !containsRootUpdate {
for _, existing := range s.dnsMuxMap {
if existing.domain == nbdns.RootZone {
s.addHostRootZone()
@ -809,6 +809,12 @@ func (s *DefaultServer) upstreamCallbacks(
}
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(
s.ctx,
s.wgInterface.Name(),
@ -824,7 +830,7 @@ func (s *DefaultServer) addHostRootZone() {
}
handler.upstreamServers = make([]string, 0)
for k := range s.hostsDNSHolder.get() {
for k := range hostDNSServers {
handler.upstreamServers = append(handler.upstreamServers, k)
}
handler.deactivate = func(error) {}

View File

@ -6,7 +6,6 @@ import (
"net"
"net/netip"
"os"
"runtime"
"strings"
"testing"
"time"
@ -726,10 +725,6 @@ func TestDNSPermanent_updateHostDNS_emptyUpstream(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)
if err != nil {
t.Fatal("failed to initialize wg interface")