From 38da24fe662c4c333d1df12187adc14464fefcb2 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Sun, 7 Jul 2024 11:40:18 +0200 Subject: [PATCH] Change the default serial. --- src/storage.cr | 6 ++++++ src/storage/zone.cr | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/storage.cr b/src/storage.cr index 34efb07..1dfe036 100644 --- a/src/storage.cr +++ b/src/storage.cr @@ -149,6 +149,12 @@ class DNSManager::Storage # Replace domain by the real domain. default_zone.replace_domain domain + # Reset the serial number so it represents the current date. + # This is particularly useful when a zone is deleted then re-used again right after, in this case + # the serial would be a problem since the new zone may not be usable for some time, depending on the + # configuration. + default_zone.reset_serial + # # Actually write data on-disk. # diff --git a/src/storage/zone.cr b/src/storage/zone.cr index b61bd82..f44f9ab 100644 --- a/src/storage/zone.cr +++ b/src/storage/zone.cr @@ -120,6 +120,16 @@ class DNSManager::Storage::Zone @rrtype = "SOA" end + # Sets the serial number to the current date. + def reset_serial + t = Time.local + y = t.year + m = t.month + d = t.day + + @serial = "#{y}#{ "%0.2d" % m}#{ "%0.2d" % d}00".to_u64 + end + def to_s(io : IO) io << "(#{ "%4d" % @rrid }) " io << "#{name} #{ttl} SOA (#{mname} #{rname}\n" @@ -1009,6 +1019,16 @@ class DNSManager::Storage::Zone false end + # Selects the SOA entry then run the `reset_serial` procedure. + def reset_serial + @resources.each do |rr| + case rr + when SOA + rr.reset_serial + end + end + end + # When a new domain is recorded, we load a template which contains a placeholder domain. # `replace_domain` replaces this domain name by the real one in the different (preloaded) RR. # Do not forget the last dot ('.') to get a fully qualified domain name (FQDN).