diff options
Diffstat (limited to 'plugin/hosts/hosts.go')
-rw-r--r-- | plugin/hosts/hosts.go | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/plugin/hosts/hosts.go b/plugin/hosts/hosts.go index 8650053c0..54b090b4d 100644 --- a/plugin/hosts/hosts.go +++ b/plugin/hosts/hosts.go @@ -31,7 +31,7 @@ func (h Hosts) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) ( if zone == "" { // PTR zones don't need to be specified in Origins if state.Type() != "PTR" { - // If this doesn't match we need to fall through regardless of h.Fallthrough + // if this doesn't match we need to fall through regardless of h.Fallthrough return plugin.NextOrFailure(h.Name(), h.Next, ctx, w, r) } } @@ -89,7 +89,6 @@ func (h Hosts) otherRecordsExist(qtype uint16, qname string) bool { } } return false - } // Name implements the plugin.Handle interface. @@ -97,39 +96,36 @@ func (h Hosts) Name() string { return "hosts" } // a takes a slice of net.IPs and returns a slice of A RRs. func a(zone string, ttl uint32, ips []net.IP) []dns.RR { - answers := []dns.RR{} - for _, ip := range ips { + answers := make([]dns.RR, len(ips)) + for i, ip := range ips { r := new(dns.A) - r.Hdr = dns.RR_Header{Name: zone, Rrtype: dns.TypeA, - Class: dns.ClassINET, Ttl: ttl} + r.Hdr = dns.RR_Header{Name: zone, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: ttl} r.A = ip - answers = append(answers, r) + answers[i] = r } return answers } // aaaa takes a slice of net.IPs and returns a slice of AAAA RRs. func aaaa(zone string, ttl uint32, ips []net.IP) []dns.RR { - answers := []dns.RR{} - for _, ip := range ips { + answers := make([]dns.RR, len(ips)) + for i, ip := range ips { r := new(dns.AAAA) - r.Hdr = dns.RR_Header{Name: zone, Rrtype: dns.TypeAAAA, - Class: dns.ClassINET, Ttl: ttl} + r.Hdr = dns.RR_Header{Name: zone, Rrtype: dns.TypeAAAA, Class: dns.ClassINET, Ttl: ttl} r.AAAA = ip - answers = append(answers, r) + answers[i] = r } return answers } // ptr takes a slice of host names and filters out the ones that aren't in Origins, if specified, and returns a slice of PTR RRs. func (h *Hosts) ptr(zone string, ttl uint32, names []string) []dns.RR { - answers := []dns.RR{} - for _, n := range names { + answers := make([]dns.RR, len(names)) + for i, n := range names { r := new(dns.PTR) - r.Hdr = dns.RR_Header{Name: zone, Rrtype: dns.TypePTR, - Class: dns.ClassINET, Ttl: ttl} + r.Hdr = dns.RR_Header{Name: zone, Rrtype: dns.TypePTR, Class: dns.ClassINET, Ttl: ttl} r.Ptr = dns.Fqdn(n) - answers = append(answers, r) + answers[i] = r } return answers } |