Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion plugin/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,16 +594,25 @@ func BenchmarkCacheResponse(b *testing.B) {

ctx := context.TODO()

// Add some answers since these need to be duplicated when
// serving a cached response.
answer := []dns.RR{
test.MX("miek.nl. 3601 IN MX 1 aspmx.l.google.com."),
test.MX("miek.nl. 3601 IN MX 10 aspmx2.googlemail.com."),
}
reqs := make([]*dns.Msg, 5)
for i, q := range []string{"example1", "example2", "a", "b", "ddd"} {
reqs[i] = new(dns.Msg)
reqs[i].SetQuestion(q+".example.org.", dns.TypeA)
reqs[i].Answer = answer
}
b.ResetTimer()

rw := &test.ResponseWriter{}
j := 0
for b.Loop() {
req := reqs[j]
c.ServeDNS(ctx, &test.ResponseWriter{}, req)
c.ServeDNS(ctx, rw, req)
j = (j + 1) % 5
}
}
Expand Down
10 changes: 8 additions & 2 deletions plugin/cache/dnssec.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@ import "github.com/miekg/dns"
// If dup is true the RRs in rrs are _copied_ before adjusting their
// TTL and the slice of copied RRs is returned.
func filterRRSlice(rrs []dns.RR, ttl uint32, dup bool) []dns.RR {
n := 0
for _, r := range rrs {
if r.Header().Rrtype != dns.TypeOPT {
n++
}
}
rs := make([]dns.RR, n)
j := 0
rs := make([]dns.RR, len(rrs))
for _, r := range rrs {
if r.Header().Rrtype == dns.TypeOPT {
continue
Expand All @@ -20,5 +26,5 @@ func filterRRSlice(rrs []dns.RR, ttl uint32, dup bool) []dns.RR {
rs[j].Header().Ttl = ttl
j++
}
return rs[:j]
return rs
}
4 changes: 0 additions & 4 deletions plugin/cache/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ func (i *item) toMsg(m *dns.Msg, now time.Time, do bool, ad bool) *dns.Msg {
m1.RecursionAvailable = i.RecursionAvailable
m1.Rcode = i.Rcode

m1.Answer = make([]dns.RR, len(i.Answer))
m1.Ns = make([]dns.RR, len(i.Ns))
m1.Extra = make([]dns.RR, len(i.Extra))

ttl := uint32(i.ttl(now))
m1.Answer = filterRRSlice(i.Answer, ttl, true)
m1.Ns = filterRRSlice(i.Ns, ttl, true)
Expand Down