Browse Source

Remove minimum TTL for NS records

geodns adopted a seemingly arbitrary minimum TTL for NS records
of 86400 seconds (one day). I can find no reason for this in the
RFCs. Setting a lower TTL is useful e.g. when NS records are
to be changed, for instance removal of a nameserver. This patch
removes this arbitrary limit.

This also removes a peculiarity where TTL on NS records would
not default to the label TTL but would default to the zone TTL.
Now TTL on NS records defaults to the label TTL but not the
zone TTL. This is because it's not possible to the set the
TTL on an RR basis.

Signed-off-by: Alex Bligh <[email protected]>
Alex Bligh 10 years ago
parent
commit
a79702ee31
2 changed files with 14 additions and 8 deletions
  1. 1 1
      zone.go
  2. 13 7
      zones.go

+ 1 - 1
zone.go

@@ -126,7 +126,7 @@ func (z *Zone) AddLabel(k string) *Label {
 	z.Labels[k] = new(Label)
 	label := z.Labels[k]
 	label.Label = k
-	label.Ttl = z.Options.Ttl
+	label.Ttl = 0 // replaced later
 	label.MaxHosts = z.Options.MaxHosts
 
 	label.Records = make(map[uint16]Records)

+ 13 - 7
zones.go

@@ -442,9 +442,6 @@ func setupZoneData(data map[string]interface{}, Zone *Zone) {
 
 				case dns.TypeNS:
 					rec := records[rType][i]
-					if h.Ttl < 86400 {
-						h.Ttl = 86400
-					}
 
 					var ns string
 
@@ -551,10 +548,19 @@ func setupZoneData(data map[string]interface{}, Zone *Zone) {
 				}
 			}
 		}
-		if Zone.Labels[k].Ttl > 0 {
-			for _, records := range Zone.Labels[k].Records {
-				for _, r := range records {
-					r.RR.Header().Ttl = uint32(Zone.Labels[k].Ttl)
+		for _, records := range Zone.Labels[k].Records {
+			for _, r := range records {
+				var defaultTtl uint32 = 86400
+				if r.RR.Header().Rrtype != dns.TypeNS {
+					// NS records have special treatment. If they are not specified, they default to 86400 rather than
+					// defaulting to the zone ttl option. The label TTL option always works though
+					defaultTtl = uint32(Zone.Options.Ttl)
+				}
+				if Zone.Labels[k].Ttl > 0 {
+					defaultTtl = uint32(Zone.Labels[k].Ttl)
+				}
+				if r.RR.Header().Ttl == 0 {
+					r.RR.Header().Ttl = defaultTtl
 				}
 			}
 		}