From abe3005769871d1e93bcb45a36abd4aadc3f2e81 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Sun, 29 Oct 2023 02:25:33 +0000 Subject: [PATCH] dns: sort zones when writing data Signed-off-by: Alejandro Mery --- pkg/dns/record.go | 10 ++++++++++ pkg/dns/write.go | 5 +++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/dns/record.go b/pkg/dns/record.go index 1b9fc51..947a206 100644 --- a/pkg/dns/record.go +++ b/pkg/dns/record.go @@ -175,6 +175,16 @@ func (mgr *Manager) genRegionsSorted() []string { return SortRegions(regions) } +func (mgr *Manager) genZonesSorted() []string { + zones := make([]string, 0, len(mgr.zones)) + for name := range mgr.zones { + zones = append(zones, name) + } + + sort.Strings(zones) + return zones +} + func (mgr *Manager) genAllAddrRecords() []AddrRecord { var out []AddrRecord diff --git a/pkg/dns/write.go b/pkg/dns/write.go index 5fdb05b..b129252 100644 --- a/pkg/dns/write.go +++ b/pkg/dns/write.go @@ -14,12 +14,13 @@ func (mgr *Manager) WriteTo(w io.Writer) (int64, error) { cache := make(map[string][]netip.Addr) // zones - for _, z := range mgr.zones { + for _, zoneName := range mgr.genZonesSorted() { + z := mgr.zones[zoneName] + mgr.writeZoneHosts(&buf, z) // zone alias addrs := mgr.genZoneAddresses(z) - zoneName := z.Name rr := AddrRecord{ Name: mgr.fqdn(zoneName + mgr.suffix),