abh / geodns

DNS server with per-client targeted responses
Apache License 2.0
1.37k stars 191 forks source link

A Record Ttl and NS Ttl #118

Open pengyuu opened 4 years ago

pengyuu commented 4 years ago

I try to set NS ttl like this: test.example.com.json

{
    "serial":3,
    "ttl":600,
    "data":{
        "":{
            "ns":{
                "ns1.example.net.":null,
                "ns2.example.net.":null
            },
            "ttl":"300000"
        }
    }
}

but A record ttl:

$ dig  test.example.com

;test.example.com.      IN  A

;; ANSWER SECTION:
test.example.com.   300000  IN  A   192.168.0.1

$ dig ns test.example.com

;; QUESTION SECTION:
;test.example.com.      IN  NS

;; ANSWER SECTION:
test.example.com.   300000  IN  NS  ns1.example.net.
test.example.com.   300000  IN  NS  ns2.example.net.

My expectation is

A Record TTL: 600
NS TTL:300000

so i changed the code:

// /geodns/zones/reader.go#setupZoneData

var defaultTtl uint32 = 86400
if zone.Labels[k].Ttl > 0 {
    defaultTtl = uint32(zone.Labels[k].Ttl)
}
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 r.RR.Header().Ttl == 0 {
    r.RR.Header().Ttl = defaultTtl
}

//old code
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
}

dig result:

$ dig  test.example.com

;; QUESTION SECTION:
;test.example.com.      IN  A

;; ANSWER SECTION:
test.example.com.     600   IN  A   192.168.0.1

$ dig ns test.example.com

;; QUESTION SECTION:
;test.example.com.      IN  NS

;; ANSWER SECTION:
test.example.com.   300000  IN  NS  ns1.example.net.
test.example.com.   300000  IN  NS  ns2.example.net.