mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2025-01-12 10:27:57 +08:00
9812ecd9ff
* 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
54 lines
1.4 KiB
Go
54 lines
1.4 KiB
Go
package bind
|
|
|
|
import (
|
|
"github.com/StackExchange/dnscontrol/v2/models"
|
|
)
|
|
|
|
func makeSoa(origin string, defSoa *SoaInfo, existing, desired *models.RecordConfig) (*models.RecordConfig, uint32) {
|
|
// Create a SOA record. Take data from desired, existing, default,
|
|
// or hardcoded defaults.
|
|
soaRec := models.RecordConfig{}
|
|
soaRec.SetLabel("@", origin)
|
|
soaRec.TTL = models.DefaultTTL
|
|
|
|
if defSoa == nil {
|
|
defSoa = &SoaInfo{}
|
|
}
|
|
if existing == nil {
|
|
existing = &models.RecordConfig{}
|
|
}
|
|
|
|
if desired == nil {
|
|
desired = &models.RecordConfig{}
|
|
}
|
|
|
|
soaRec.SetTargetSOA(
|
|
firstNonNull(desired.GetTargetField(), existing.GetTargetField(), defSoa.Ns, "DEFAULT_NOT_SET."),
|
|
firstNonNull(desired.SoaMbox, existing.SoaMbox, defSoa.Mbox, "DEFAULT_NOT_SET."),
|
|
firstNonZero(desired.SoaSerial, existing.SoaSerial, defSoa.Serial, 1),
|
|
firstNonZero(desired.SoaRefresh, existing.SoaRefresh, defSoa.Refresh, 3600),
|
|
firstNonZero(desired.SoaRetry, existing.SoaRetry, defSoa.Retry, 600),
|
|
firstNonZero(desired.SoaExpire, existing.SoaExpire, defSoa.Expire, 604800),
|
|
firstNonZero(desired.SoaMinttl, existing.SoaMinttl, defSoa.Minttl, 1440),
|
|
)
|
|
|
|
return &soaRec, generateSerial(soaRec.SoaSerial)
|
|
}
|
|
|
|
func firstNonNull(items ...string) string {
|
|
for _, item := range items {
|
|
if item != "" {
|
|
return item
|
|
}
|
|
}
|
|
return "FAIL"
|
|
}
|
|
|
|
func firstNonZero(items ...uint32) uint32 {
|
|
for _, item := range items {
|
|
if item != 0 {
|
|
return item
|
|
}
|
|
}
|
|
return 999
|
|
}
|