diff options
| author | Shulhan <ms@kilabit.info> | 2023-08-05 15:21:29 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-08-05 15:47:53 +0700 |
| commit | 34d09fcaa210ddd9d8bf8d1754151faeebf4e485 (patch) | |
| tree | 7346e07a168f65f81dd5475816bb1e88119f9a0f /lib/dns/zone.go | |
| parent | bd2ae82e254e203a021c9907e41b41ec0643ad49 (diff) | |
| download | pakakeh.go-34d09fcaa210ddd9d8bf8d1754151faeebf4e485.tar.xz | |
lib/dns: always initialize the Zone SOA record to default values
Previously, if we parse, create, or remove the SOA record from zone, we
assume the SOA records are valid and not touch their values.
In this changes, we set the SOA fields to default values if its not set,
to make the SOA record consistent and valid, in perspective of client.
This changes also export the default OS values for documentation and add
new method NewRDataSOA to simplify creating new SOA record.
Diffstat (limited to 'lib/dns/zone.go')
| -rw-r--r-- | lib/dns/zone.go | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/dns/zone.go b/lib/dns/zone.go index c28ae9e2..59b58619 100644 --- a/lib/dns/zone.go +++ b/lib/dns/zone.go @@ -21,19 +21,18 @@ type Zone struct { Path string `json:"-"` Name string messages []*Message - SOA RDataSOA + SOA *RDataSOA } // NewZone create and initialize new zone. -func NewZone(file, name string) *Zone { - return &Zone{ - Path: file, - Name: name, - SOA: RDataSOA{ - MName: name, - }, +func NewZone(file, name string) (zone *Zone) { + zone = &Zone{ + Path: file, + Name: name, + SOA: NewRDataSOA(name, ``), Records: make(ZoneRecords), } + return zone } // LoadZoneDir load DNS record from zone formatted files in @@ -157,7 +156,9 @@ func (zone *Zone) Add(rr *ResourceRecord) (err error) { if rr.Type == RecordTypeSOA { soa, _ = rr.Value.(*RDataSOA) if soa != nil { - zone.SOA = *soa + var cloneSoa = *soa + zone.SOA = &cloneSoa + zone.SOA.init() } } else { zone.Records.add(rr) @@ -204,9 +205,10 @@ func (zone *Zone) Messages() []*Message { } // Remove a ResourceRecord from zone file. +// If the RR is SOA it will reset the value back to default. func (zone *Zone) Remove(rr *ResourceRecord) (err error) { if rr.Type == RecordTypeSOA { - zone.SOA = RDataSOA{} + zone.SOA = NewRDataSOA(zone.Name, ``) } else { if zone.Records.remove(rr) { err = zone.Save() |
