Cache Plugin: return non-fixed TTL for cached entries (refactor)
This commit is contained in:
parent
2a6a1852f1
commit
65dfa8ecca
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ func (plugin *PluginCacheResponse) Eval(pluginsState *PluginsState, msg *dns.Msg
|
|||
}
|
||||
plugin.cachedResponses.cache.Add(cacheKey, cachedResponse)
|
||||
|
||||
updateTTL(msg, cachedResponse.expiration)
|
||||
updateTTL(msg, cachedResponse.expiration)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ func (plugin *PluginCache) Eval(pluginsState *PluginsState, msg *dns.Msg) error
|
|||
return nil
|
||||
}
|
||||
|
||||
updateTTL(&cached.msg, cached.expiration)
|
||||
updateTTL(&cached.msg, cached.expiration)
|
||||
|
||||
synth := cached.msg
|
||||
synth.Id = msg.Id
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue