aboutsummaryrefslogtreecommitdiff
path: root/plugin/pkg/dnsutil/ttl.go
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/pkg/dnsutil/ttl.go')
-rw-r--r--plugin/pkg/dnsutil/ttl.go38
1 files changed, 9 insertions, 29 deletions
diff --git a/plugin/pkg/dnsutil/ttl.go b/plugin/pkg/dnsutil/ttl.go
index e969fa8a6..e2b26526d 100644
--- a/plugin/pkg/dnsutil/ttl.go
+++ b/plugin/pkg/dnsutil/ttl.go
@@ -14,34 +14,21 @@ func MinimalTTL(m *dns.Msg, mt response.Type) time.Duration {
return MinimalDefaultTTL
}
- // No data to examine, return a short ttl as a fail safe.
- if len(m.Answer)+len(m.Ns)+len(m.Extra) == 0 {
+ // No records or OPT is the only record, return a short ttl as a fail safe.
+ if len(m.Answer)+len(m.Ns) == 0 &&
+ (len(m.Extra) == 0 || (len(m.Extra) == 1 && m.Extra[0].Header().Rrtype == dns.TypeOPT)) {
return MinimalDefaultTTL
}
minTTL := MaximumDefaulTTL
for _, r := range m.Answer {
- switch mt {
- case response.NameError, response.NoData:
- if r.Header().Rrtype == dns.TypeSOA {
- minTTL = time.Duration(r.(*dns.SOA).Minttl) * time.Second
- }
- case response.NoError, response.Delegation:
- if r.Header().Ttl < uint32(minTTL.Seconds()) {
- minTTL = time.Duration(r.Header().Ttl) * time.Second
- }
+ if r.Header().Ttl < uint32(minTTL.Seconds()) {
+ minTTL = time.Duration(r.Header().Ttl) * time.Second
}
}
for _, r := range m.Ns {
- switch mt {
- case response.NameError, response.NoData:
- if r.Header().Rrtype == dns.TypeSOA {
- minTTL = time.Duration(r.(*dns.SOA).Minttl) * time.Second
- }
- case response.NoError, response.Delegation:
- if r.Header().Ttl < uint32(minTTL.Seconds()) {
- minTTL = time.Duration(r.Header().Ttl) * time.Second
- }
+ if r.Header().Ttl < uint32(minTTL.Seconds()) {
+ minTTL = time.Duration(r.Header().Ttl) * time.Second
}
}
@@ -50,15 +37,8 @@ func MinimalTTL(m *dns.Msg, mt response.Type) time.Duration {
// OPT records use TTL field for extended rcode and flags
continue
}
- switch mt {
- case response.NameError, response.NoData:
- if r.Header().Rrtype == dns.TypeSOA {
- minTTL = time.Duration(r.(*dns.SOA).Minttl) * time.Second
- }
- case response.NoError, response.Delegation:
- if r.Header().Ttl < uint32(minTTL.Seconds()) {
- minTTL = time.Duration(r.Header().Ttl) * time.Second
- }
+ if r.Header().Ttl < uint32(minTTL.Seconds()) {
+ minTTL = time.Duration(r.Header().Ttl) * time.Second
}
}
return minTTL