Cache Plugin: return non-fixed TTL for cached entries (refactor)

This commit is contained in:
Amit 2018-02-09 22:11:12 +02:00
parent 2a6a1852f1
commit 65dfa8ecca
3 changed files with 18 additions and 7 deletions

View File

@ -85,22 +85,33 @@ func getMinTTL(msg *dns.Msg, minTTL uint32, maxTTL uint32, negCacheMinTTL uint32
func setMaxTTL(msg *dns.Msg, ttl uint32, force bool) {
for _, rr := range msg.Answer {
if (ttl < rr.Header().Ttl) || force {
if ttl < rr.Header().Ttl {
rr.Header().Ttl = ttl
}
}
for _, rr := range msg.Ns {
if (ttl < rr.Header().Ttl) || force {
if ttl < rr.Header().Ttl {
rr.Header().Ttl = ttl
}
}
for _, rr := range msg.Extra {
if (ttl < rr.Header().Ttl) || force {
if ttl < rr.Header().Ttl {
rr.Header().Ttl = ttl
}
}
}
func updateTTL(msg *dns.Msg, expiration time.Time) {
setMaxTTL(msg, uint32(time.Until(expiration) / time.Second), true)
ttl := uint32(time.Until(expiration) / time.Second)
for _, rr := range msg.Answer {
rr.Header().Ttl = ttl
}
for _, rr := range msg.Ns {
rr.Header().Ttl = ttl
}
for _, rr := range msg.Extra {
rr.Header().Ttl = ttl
}
}

View File

@ -178,7 +178,7 @@ func (pluginsState *PluginsState) ApplyResponsePlugins(pluginsGlobals *PluginsGl
}
pluginsGlobals.RUnlock()
if ttl != nil {
setMaxTTL(&msg, *ttl, false)
setMaxTTL(&msg, *ttl)
}
packet2, err := msg.PackBuffer(packet)
if err != nil {