SOA RR update: minttl and a few syntax changes.

This commit is contained in:
Philippe Pittoli 2023-06-28 00:55:39 +02:00
parent ae631aa2a8
commit 809b34c571
3 changed files with 30 additions and 23 deletions

View File

@ -20,6 +20,8 @@ Q ?= @
DOMAIN ?= example.com DOMAIN ?= example.com
zone-file: zone-file:
crystal run ./tools/write-zone-file.cr -- $(DOMAIN) crystal run ./tools/write-zone-file.cr -- $(DOMAIN)
zone-basic-template-file:
crystal run ./tools/write-template-zone-file.cr -- $(DOMAIN)
VERBOSITY ?= 4 VERBOSITY ?= 4
run-client-verbosity: run-client-verbosity:

View File

@ -42,7 +42,7 @@ class DNSManager::Storage::Zone
# zone class is omited, it always will be IN in our case. # zone class is omited, it always will be IN in our case.
def initialize(@name, @ttl, @target) def initialize(@name, @ttl, @target)
@rrtype = self.class.name.downcase.gsub /dnsmanager::storage::zone::/, "" @rrtype = self.class.name.upcase.gsub /DNSMANAGER::STORAGE::ZONE::/, ""
end end
def get_errors : Array(Error) def get_errors : Array(Error)
@ -50,7 +50,7 @@ class DNSManager::Storage::Zone
end end
def to_s(io : IO) def to_s(io : IO)
io << "(#{ "%4d" % @rrid }) #{ "%30s" % @name} #{ "%6d" % @ttl} IN #{ "%10s" % @rrtype.upcase} #{ "%30s" % @target}\n" io << "(#{ "%4d" % @rrid }) #{ "%30s" % @name} #{ "%6d" % @ttl} IN #{ "%10s" % @rrtype } #{ "%30s" % @target}\n"
end end
end end
@ -62,19 +62,25 @@ class DNSManager::Storage::Zone
property refresh : UInt64 = 86400 # #seconds before requesting new zone version (master-slave). property refresh : UInt64 = 86400 # #seconds before requesting new zone version (master-slave).
property retry : UInt64 = 7200 # #seconds before retry accessing new data from the master. property retry : UInt64 = 7200 # #seconds before retry accessing new data from the master.
property expire : UInt64 = 3600000 # #seconds slaves should consider master dead. property expire : UInt64 = 3600000 # #seconds slaves should consider master dead.
property minttl : UInt64 = 600 # #seconds slaves should consider master dead.
def initialize(@name, @ttl, @target, def initialize(@name, @ttl, @mname, @rname,
@mname, @rname, @serial = 0.to_u64,
@serial = 0.to_u64, @refresh = 86400.to_u64, @retry = 7200.to_u64, @expire = 3600000.to_u64) @refresh = 86400.to_u64,
@rrtype = "soa" @retry = 7200.to_u64,
@expire = 3600000.to_u64,
@minttl = 600.to_u64)
@target = "" # no use
@rrtype = "SOA"
end end
def to_s(io : IO) def to_s(io : IO)
io << "(#{ "%4d" % @rrid }) #{name} #{ttl} #{target} #{@rrtype.upcase} (#{mname} #{rname}\n" io << "(#{ "%4d" % @rrid }) #{name} #{ttl} IN SOA (#{mname} #{rname}\n"
io << "\t\t#{ "%10d" % serial } ; serial\n" io << "\t\t#{ "%10d" % serial } ; serial\n"
io << "\t\t#{ "%10d" % refresh } ; refresh\n" io << "\t\t#{ "%10d" % refresh } ; refresh\n"
io << "\t\t#{ "%10d" % retry } ; retry\n" io << "\t\t#{ "%10d" % retry } ; retry\n"
io << "\t\t#{ "%10d" % expire } ; expire\n" io << "\t\t#{ "%10d" % expire } ; expire\n"
io << "\t\t#{ "%10d" % minttl } ; minttl\n"
io << "\t)\n" io << "\t)\n"
end end
@ -221,7 +227,7 @@ class DNSManager::Storage::Zone
class MX < ResourceRecord class MX < ResourceRecord
property priority : UInt32 = 10 property priority : UInt32 = 10
def initialize(@name, @ttl, @target, @priority = 10) def initialize(@name, @ttl, @target, @priority = 10)
@rrtype = "mx" @rrtype = "MX"
end end
def to_s(io : IO) def to_s(io : IO)
@ -256,7 +262,7 @@ class DNSManager::Storage::Zone
property priority : UInt32 = 10 property priority : UInt32 = 10
property weight : UInt32 = 10 property weight : UInt32 = 10
def initialize(@name, @ttl, @target, @port, @protocol = "tcp", @priority = 10, @weight = 10) def initialize(@name, @ttl, @target, @port, @protocol = "tcp", @priority = 10, @weight = 10)
@rrtype = "srv" @rrtype = "SRV"
end end
def get_errors : Array(Error) def get_errors : Array(Error)

View File

@ -21,19 +21,18 @@ zone = DSZ.new domain
zone << DSZ::SOA.new "#{domain}.", # name zone << DSZ::SOA.new "#{domain}.", # name
60.to_u32, # TTL 60.to_u32, # TTL
"IN", # target (??)
"ns0.some-example.com.", # Master Name Server for the zone "ns0.some-example.com.", # Master Name Server for the zone
"john\.doe.#{domain}" # admin email address "john\.doe.#{domain}" # admin email address
zone << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns1.some-example.com."
zone << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns0.some-example.com."
zone << DSZ::A.new "www", 600.to_u32, "10.0.0.1" zone << DSZ::A.new "www", 600.to_u32, "10.0.0.1"
zone << DSZ::A.new "www2", 600.to_u32, "10.0.0.2" zone << DSZ::A.new "www2", 600.to_u32, "10.0.0.2"
zone << DSZ::A.new "mail", 300.to_u32, "10.0.0.10" zone << DSZ::A.new "mail", 300.to_u32, "10.0.0.10"
zone << DSZ::CNAME.new "mail2", 600.to_u32, "www" zone << DSZ::CNAME.new "mail2", 600.to_u32, "www"
zone << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns1.some-example.com."
zone << DSZ::NS.new "#{domain}.", 3600.to_u32, "ns0.some-example.com."
zone << DSZ::MX.new "mail", 300.to_u32, "mail", 10 zone << DSZ::MX.new "mail", 300.to_u32, "mail", 10
zone << DSZ::MX.new "mail", 300.to_u32, "mail2", 5 zone << DSZ::MX.new "mail", 300.to_u32, "mail2", 5