diff --git a/lib/dns/caches.go b/lib/dns/caches.go index b4b15f6c..5a49e762 100644 --- a/lib/dns/caches.go +++ b/lib/dns/caches.go @@ -37,6 +37,9 @@ type Caches struct { // by is domain name. external map[string]*answers + // zone contains internal zones, with its origin as the key. + zone map[string]*Zone + // lru contains list of external answers, ordered by access time in // ascending order (the least recently used, LRU, record will be on // the top). @@ -79,6 +82,7 @@ func (c *Caches) init(pruneDelay, pruneThreshold time.Duration, debug int) { c.internal = make(map[string]*answers) c.external = make(map[string]*answers) + c.zone = make(map[string]*Zone) c.lru = list.New() c.debug = debug @@ -308,6 +312,18 @@ func (c *Caches) InternalPopulateRecords(listRR []*ResourceRecord, from string) return nil } +// InternalPopulateZone populate the internal caches from Zone. +func (c *Caches) InternalPopulateZone(zone *Zone) { + if zone == nil { + return + } + if len(zone.Origin) == 0 { + return + } + c.zone[zone.Origin] = zone + c.InternalPopulate(zone.Messages(), zone.Path) +} + // InternalRemoveNames remove internal caches by domain names. func (c *Caches) InternalRemoveNames(names []string) { var ( diff --git a/lib/dns/zone.go b/lib/dns/zone.go index 052bc132..deed4e70 100644 --- a/lib/dns/zone.go +++ b/lib/dns/zone.go @@ -48,7 +48,7 @@ func NewZone(file, origin string) (zone *Zone) { // LoadZoneDir load DNS record from zone formatted files in // directory "dir". -// On success, it will return map of zone Origin and its content as list +// On success, it will return map of file name and Zone content as list // of Message. // On fail, it will return possible partially parse zone file and an error. func LoadZoneDir(dir string) (zoneFiles map[string]*Zone, err error) { @@ -99,7 +99,7 @@ func LoadZoneDir(dir string) (zoneFiles map[string]*Zone, err error) { return zoneFiles, fmt.Errorf("LoadZoneDir %q: %w", dir, err) } - zoneFiles[zone.Origin] = zone + zoneFiles[name] = zone } err = d.Close()