mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
BIND: Simplify serial number generation (#652)
* The old algorithm was very complex for no good reason. * The new algorithm is simply: Use yymmdd00 or (previous serial number +1) whichever is bigger.
This commit is contained in:
@@ -3,7 +3,6 @@ package bind
|
||||
import (
|
||||
"log"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -20,36 +19,20 @@ func generateSerial(oldSerial uint32) uint32 {
|
||||
// At no time will a serial number == 0 be returned.
|
||||
|
||||
original := oldSerial
|
||||
oldSerialStr := strconv.FormatUint(uint64(oldSerial), 10)
|
||||
var newSerial uint32
|
||||
|
||||
// Make draft new serial number:
|
||||
today := nowFunc().UTC()
|
||||
todayStr := today.Format("20060102")
|
||||
version := uint32(1)
|
||||
todayNum, err := strconv.ParseUint(todayStr, 10, 32)
|
||||
if err != nil {
|
||||
log.Fatalf("new serial won't fit in 32 bits: %v", err)
|
||||
}
|
||||
draft := uint32(todayNum)*100 + version
|
||||
draft := uint32(todayNum * 100)
|
||||
|
||||
method := "none" // Used only in debugging.
|
||||
if oldSerial > draft {
|
||||
// If old_serial was really slow, upgrade to new yyyymmddvv standard:
|
||||
method = "o>d"
|
||||
newSerial = oldSerial + 1
|
||||
newSerial = oldSerial + 1
|
||||
} else if oldSerial == draft {
|
||||
// Edge case: increment old serial:
|
||||
method = "o=d"
|
||||
newSerial = draft + 1
|
||||
} else if len(oldSerialStr) != 10 {
|
||||
// If old_serial is wrong number of digits, upgrade to yyyymmddvv standard:
|
||||
method = "len!=10"
|
||||
newSerial = draft
|
||||
} else if strings.HasPrefix(oldSerialStr, todayStr) {
|
||||
// If old_serial just needs to be incremented:
|
||||
method = "prefix"
|
||||
if oldSerial >= draft {
|
||||
method = "o>=d"
|
||||
newSerial = oldSerial + 1
|
||||
} else {
|
||||
// First serial number to be requested today:
|
||||
|
Reference in New Issue
Block a user