diff --git a/command/agent/dns.go b/command/agent/dns.go index f5f8521679..59d0601c18 100644 --- a/command/agent/dns.go +++ b/command/agent/dns.go @@ -494,18 +494,16 @@ func (d *DNSServer) formatNodeRecord(node *structs.Node, addr, qName string, qTy return records } -// indexRRs creates a map which indexes a given list of RRs by name. NOTE that +// indexRRs populates a map which indexes a given list of RRs by name. NOTE that // the names are all squashed to lower case so we can perform case-insensitive // lookups; the RRs are not modified. -func indexRRs(rrs []dns.RR) map[string]dns.RR { - index := make(map[string]dns.RR, len(rrs)) +func indexRRs(rrs []dns.RR, index map[string]dns.RR) { for _, rr := range rrs { name := strings.ToLower(rr.Header().Name) if _, ok := index[name]; !ok { index[name] = rr } } - return index } // syncExtra takes a DNS response message and sets the extra data to the most @@ -557,7 +555,8 @@ func trimUDPResponse(config *DNSConfig, resp *dns.Msg) (trimmed bool) { // extra data when necessary. var index map[string]dns.RR if hasExtra { - index = indexRRs(resp.Extra) + index = make(map[string]dns.RR, len(resp.Extra)) + indexRRs(resp.Extra, index) } // This cuts UDP responses to a useful but limited number of responses. diff --git a/command/agent/dns_test.go b/command/agent/dns_test.go index 073ba23a10..8d0165d4c1 100644 --- a/command/agent/dns_test.go +++ b/command/agent/dns_test.go @@ -3522,7 +3522,8 @@ func TestDNS_syncExtra(t *testing.T) { }, } - index := indexRRs(resp.Extra) + index := make(map[string]dns.RR) + indexRRs(resp.Extra, index) syncExtra(index, resp) expected := &dns.Msg{