diff --git a/go.sum b/go.sum index 95e8194..b1d54e1 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,8 @@ +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/miekg/dns v1.1.62 h1:cN8OuEF1/x5Rq6Np+h1epln8OiyPWV+lROx9LxcGgIQ= github.com/miekg/dns v1.1.62/go.mod h1:mvDlcItzm+br7MToIKqkglaGhlFMHJ9DTNNWONWXbNQ= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0= golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= @@ -8,5 +11,8 @@ golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0= +golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA= golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c= diff --git a/service.go b/service.go index 4c2531a..b496532 100644 --- a/service.go +++ b/service.go @@ -481,9 +481,18 @@ func (service *Service) ResolveReverse(ip string) ([]string, bool) { func (service *Service) ResolveAll(name string) (ResolveAllResult, bool) { record, ok := service.findRecord(name) if !ok { + if normalizeName(name) == service.ZoneApex() && service.ZoneApex() != "" { + return ResolveAllResult{ + NS: []string{"ns." + service.ZoneApex()}, + }, true + } return ResolveAllResult{}, false } - return resolveResult(record), true + result := resolveResult(record) + if normalizeName(name) == service.ZoneApex() && service.ZoneApex() != "" && len(result.NS) == 0 { + result.NS = []string{"ns." + service.ZoneApex()} + } + return result, true } func (service *Service) Health() map[string]any { diff --git a/service_test.go b/service_test.go index 9bb1a6a..6a92599 100644 --- a/service_test.go +++ b/service_test.go @@ -1136,6 +1136,27 @@ func TestServiceServeAnswersNSForDerivedZoneApexWithoutExactRecord(t *testing.T) } } +func TestServiceResolveAllSynthesizesNSForDerivedZoneApex(t *testing.T) { + service := NewService(ServiceOptions{ + Records: map[string]NameRecords{ + "gateway.charon.lthn": { + A: []string{"10.10.10.10"}, + }, + "node.charon.lthn": { + AAAA: []string{"2600:1f1c:7f0:4f01::2"}, + }, + }, + }) + + result, ok := service.ResolveAll("charon.lthn") + if !ok { + t.Fatal("expected derived zone apex to resolve") + } + if len(result.NS) != 1 || result.NS[0] != "ns.charon.lthn" { + t.Fatalf("expected synthesized apex NS, got %#v", result.NS) + } +} + func TestServiceServeReturnsNXDOMAINWhenMissing(t *testing.T) { service := NewService(ServiceOptions{})