Do not modify the TTL stored in the cache when getting a reply from the cache

This commit is contained in:
Alvaro Saurin committed 2015-04-09 16:17:24 +02:00
1 parent 6f545a4296
commit 2474adb2c5
1 file changed
+10 -8
+10 -8
View File
@@ -93,31 +93,33 @@ func (e *cacheEntry) getReply(request *dns.Msg, maxLen int, now time.Time) (*dns
} }
if e.ReplyLen >= maxLen { if e.ReplyLen >= maxLen {
Debug.Printf("[cache] returning truncated reponse: %d > %d", e.ReplyLen, maxLen) Debug.Printf("[cache msgid %d] returning truncated reponse: %d > %d", request.MsgHdr.Id, e.ReplyLen, maxLen)
return makeTruncatedReply(request), nil return makeTruncatedReply(request), nil
} }
// create a copy of the reply, with values for this particular query // create a copy of the reply, with values for this particular query
reply := e.reply reply := e.reply.Copy()
reply.SetReply(request) reply.SetReply(request)
reply.Rcode = e.reply.Rcode
reply.Authoritative = true
// adjust the TTLs // adjust the TTLs
passedSecs := uint32(now.Sub(e.putTime).Seconds()) passedSecs := uint32(now.Sub(e.putTime).Seconds())
for _, rr := range reply.Answer { for _, rr := range reply.Answer {
ttl := rr.Header().Ttl hdr := rr.Header()
ttl := hdr.Ttl
if passedSecs < ttl { if passedSecs < ttl {
rr.Header().Ttl = ttl - passedSecs hdr.Ttl = ttl - passedSecs
} else { } else {
rr.Header().Ttl = 0 return nil, nil // it is expired: do not spend more time and return nil...
} }
} }
reply.Rcode = e.reply.Rcode
reply.Authoritative = true
// shuffle the values, etc... // shuffle the values, etc...
reply.Answer = shuffleAnswers(reply.Answer) reply.Answer = shuffleAnswers(reply.Answer)
return &reply, nil return reply, nil
} }
func (e cacheEntry) hasExpired(now time.Time) bool { func (e cacheEntry) hasExpired(now time.Time) bool {