Fix: dns cache behavior
This commit is contained in:
28
dns/util.go
28
dns/util.go
@ -79,11 +79,31 @@ func (e EnhancedMode) String() string {
|
||||
}
|
||||
|
||||
func putMsgToCache(c *cache.Cache, key string, msg *D.Msg) {
|
||||
if len(msg.Answer) == 0 {
|
||||
log.Debugln("[DNS] answer length is zero: %#v", msg)
|
||||
var ttl time.Duration
|
||||
if len(msg.Answer) != 0 {
|
||||
ttl = time.Duration(msg.Answer[0].Header().Ttl) * time.Second
|
||||
} else if len(msg.Ns) != 0 {
|
||||
ttl = time.Duration(msg.Ns[0].Header().Ttl) * time.Second
|
||||
} else if len(msg.Extra) != 0 {
|
||||
ttl = time.Duration(msg.Extra[0].Header().Ttl) * time.Second
|
||||
} else {
|
||||
log.Debugln("[DNS] response msg error: %#v", msg)
|
||||
return
|
||||
}
|
||||
|
||||
ttl := time.Duration(msg.Answer[0].Header().Ttl) * time.Second
|
||||
c.Put(key, msg, ttl)
|
||||
c.Put(key, msg.Copy(), ttl)
|
||||
}
|
||||
|
||||
func setMsgTTL(msg *D.Msg, ttl uint32) {
|
||||
for _, answer := range msg.Answer {
|
||||
answer.Header().Ttl = ttl
|
||||
}
|
||||
|
||||
for _, ns := range msg.Ns {
|
||||
ns.Header().Ttl = ttl
|
||||
}
|
||||
|
||||
for _, extra := range msg.Extra {
|
||||
extra.Header().Ttl = ttl
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user