Set SOA record TTL as min of TTL/MINIMUM (#2295)

* Set SOA record TTL as min of TTL/MINIMUM

According to
https://tools.ietf.org/html/rfc2308#section-3:

  The TTL of this record is set from the minimum
  of the MINIMUM field of the SOA record and the
  TTL of the SOA itself, and indicates how long a
  resolver may cache the negative answer.

Set the TTL accordingly so as to not always
negative cache SOA records for 300 seconds.

* Inline min func

* Update SOA record tests

* Fix types
This commit is contained in:
stuart nelson 2018-11-16 14:42:49 +01:00 committed by Chris O'Haver
parent 3f6dfba1f0
commit 8dbe1fbee2
9 changed files with 43 additions and 37 deletions

View file

@ -391,7 +391,13 @@ func NS(b ServiceBackend, zone string, state request.Request, opt Options) (reco
// SOA returns a SOA record from the backend.
func SOA(b ServiceBackend, zone string, state request.Request, opt Options) ([]dns.RR, error) {
header := dns.RR_Header{Name: zone, Rrtype: dns.TypeSOA, Ttl: 300, Class: dns.ClassINET}
minTTL := b.MinTTL(state)
ttl := uint32(300)
if minTTL < ttl {
ttl = minTTL
}
header := dns.RR_Header{Name: zone, Rrtype: dns.TypeSOA, Ttl: ttl, Class: dns.ClassINET}
Mbox := hostmaster + "."
Ns := "ns.dns."
@ -407,7 +413,7 @@ func SOA(b ServiceBackend, zone string, state request.Request, opt Options) ([]d
Refresh: 7200,
Retry: 1800,
Expire: 86400,
Minttl: b.MinTTL(state),
Minttl: minTTL,
}
return []dns.RR{soa}, nil
}