1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

BIND: Improve SOA serial number handling (#651)

* github.com/miekg/dns
* Greatly simplify the logic for handling serial numbers. Related code was all over the place. Now it is abstracted into one testable method makeSoa. This simplifies code in many other places.
* Update docs/_providers/bind.md: Edit old text. Add SOA description.
* SOA records are now treated like any other record internally. You still can't specify them in dnsconfig.js, but that's by design.
* The URL for issue 491 was wrong in many places
* BIND: Clarify GENERATE_ZONEFILE message
This commit is contained in:
Tom Limoncelli
2020-02-23 13:58:49 -05:00
committed by GitHub
parent 3c41a39252
commit 9812ecd9ff
60 changed files with 708 additions and 254 deletions

View File

@@ -42,28 +42,20 @@ func (rc *RecordConfig) String() string {
// Conversions
// RRstoRCs converts []dns.RR to []RecordConfigs.
func RRstoRCs(rrs []dns.RR, origin string, replaceSerial uint32) Records {
func RRstoRCs(rrs []dns.RR, origin string) Records {
rcs := make(Records, 0, len(rrs))
var x uint32
for _, r := range rrs {
var rc RecordConfig
//fmt.Printf("CONVERT: %+v\n", r)
rc, x = RRtoRC(r, origin, replaceSerial)
replaceSerial = x
rc = RRtoRC(r, origin)
rcs = append(rcs, &rc)
}
return rcs
}
// RRtoRC converts dns.RR to RecordConfig
func RRtoRC(rr dns.RR, origin string, replaceSerial uint32) (RecordConfig, uint32) {
func RRtoRC(rr dns.RR, origin string) RecordConfig {
// Convert's dns.RR into our native data type (RecordConfig).
// Records are translated directly with no changes.
// If it is an SOA for the apex domain and
// replaceSerial != 0, change the serial to replaceSerial.
// WARNING(tlim): This assumes SOAs do not have serial=0.
// If one is found, we replace it with serial=1.
var oldSerial, newSerial uint32
header := rr.Header()
rc := new(RecordConfig)
rc.Type = dns.TypeToString[header.Rrtype]
@@ -88,20 +80,7 @@ func RRtoRC(rr dns.RR, origin string, replaceSerial uint32) (RecordConfig, uint3
case *dns.NAPTR:
panicInvalid(rc.SetTargetNAPTR(v.Order, v.Preference, v.Flags, v.Service, v.Regexp, v.Replacement))
case *dns.SOA:
oldSerial = v.Serial
if oldSerial == 0 {
// For SOA records, we never return a 0 serial number.
oldSerial = 1
}
newSerial = v.Serial
if rc.GetLabel() == "@" && replaceSerial != 0 {
newSerial = replaceSerial
}
panicInvalid(rc.SetTarget(
fmt.Sprintf("%v %v %v %v %v %v %v",
v.Ns, v.Mbox, newSerial, v.Refresh, v.Retry, v.Expire, v.Minttl),
))
// FIXME(tlim): SOA should be handled by splitting out the fields.
panicInvalid(rc.SetTargetSOA(v.Ns, v.Mbox, v.Serial, v.Refresh, v.Retry, v.Expire, v.Minttl))
case *dns.SRV:
panicInvalid(rc.SetTargetSRV(v.Priority, v.Weight, v.Port, v.Target))
case *dns.SSHFP:
@@ -113,7 +92,7 @@ func RRtoRC(rr dns.RR, origin string, replaceSerial uint32) (RecordConfig, uint3
default:
log.Fatalf("rrToRecord: Unimplemented zone record type=%s (%v)\n", rc.Type, rr)
}
return *rc, oldSerial
return *rc
}
func panicInvalid(err error) {