Refactor usage of relative domain during zone export
This commit is contained in:
parent
c646dad897
commit
211df3cdae
@ -38,6 +38,7 @@ import (
|
||||
"github.com/miekg/dns"
|
||||
|
||||
"git.happydns.org/happydns/model"
|
||||
"git.happydns.org/happydns/utils"
|
||||
)
|
||||
|
||||
type CNAME struct {
|
||||
@ -53,11 +54,6 @@ func (s *CNAME) GenComment(origin string) string {
|
||||
}
|
||||
|
||||
func (s *CNAME) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR) {
|
||||
target := s.Target
|
||||
if target[len(target)-1] != '.' {
|
||||
target += origin
|
||||
}
|
||||
|
||||
rrs = append(rrs, &dns.CNAME{
|
||||
Hdr: dns.RR_Header{
|
||||
Name: domain,
|
||||
@ -65,7 +61,7 @@ func (s *CNAME) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR)
|
||||
Class: dns.ClassINET,
|
||||
Ttl: ttl,
|
||||
},
|
||||
Target: target,
|
||||
Target: utils.DomainFQDN(s.Target, origin),
|
||||
})
|
||||
return
|
||||
}
|
||||
@ -84,11 +80,6 @@ func (s *SpecialCNAME) GenComment(origin string) string {
|
||||
}
|
||||
|
||||
func (s *SpecialCNAME) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR) {
|
||||
target := s.Target
|
||||
if target[len(target)-1] != '.' {
|
||||
target += origin
|
||||
}
|
||||
|
||||
rrs = append(rrs, &dns.CNAME{
|
||||
Hdr: dns.RR_Header{
|
||||
Name: s.SubDomain + "." + domain,
|
||||
@ -96,7 +87,7 @@ func (s *SpecialCNAME) GenRRs(domain string, ttl uint32, origin string) (rrs []d
|
||||
Class: dns.ClassINET,
|
||||
Ttl: ttl,
|
||||
},
|
||||
Target: target,
|
||||
Target: utils.DomainFQDN(s.Target, origin),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import (
|
||||
"github.com/miekg/dns"
|
||||
|
||||
"git.happydns.org/happydns/model"
|
||||
"git.happydns.org/happydns/utils"
|
||||
)
|
||||
|
||||
type DS struct {
|
||||
@ -66,10 +67,6 @@ func (s *Delegation) GenComment(origin string) string {
|
||||
|
||||
func (s *Delegation) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR) {
|
||||
for _, ns := range s.NameServers {
|
||||
if ns[len(ns)-1] != '.' {
|
||||
ns += origin
|
||||
}
|
||||
|
||||
rrs = append(rrs, &dns.NS{
|
||||
Hdr: dns.RR_Header{
|
||||
Name: domain,
|
||||
@ -77,7 +74,7 @@ func (s *Delegation) GenRRs(domain string, ttl uint32, origin string) (rrs []dns
|
||||
Class: dns.ClassINET,
|
||||
Ttl: ttl,
|
||||
},
|
||||
Ns: ns,
|
||||
Ns: utils.DomainFQDN(ns, origin),
|
||||
})
|
||||
}
|
||||
for _, ds := range s.DS {
|
||||
|
@ -176,11 +176,6 @@ func (s *EMail) GenComment(origin string) string {
|
||||
func (s *EMail) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR) {
|
||||
if len(s.MX) > 0 {
|
||||
for _, mx := range s.MX {
|
||||
target := mx.Target
|
||||
if target[len(target)-1] != '.' {
|
||||
target += origin
|
||||
}
|
||||
|
||||
rrs = append(rrs, &dns.MX{
|
||||
Hdr: dns.RR_Header{
|
||||
Name: domain,
|
||||
@ -188,7 +183,7 @@ func (s *EMail) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR)
|
||||
Class: dns.ClassINET,
|
||||
Ttl: ttl,
|
||||
},
|
||||
Mx: target,
|
||||
Mx: utils.DomainFQDN(mx.Target, origin),
|
||||
Preference: mx.Preference,
|
||||
})
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ import (
|
||||
"github.com/miekg/dns"
|
||||
|
||||
"git.happydns.org/happydns/model"
|
||||
"git.happydns.org/happydns/utils"
|
||||
)
|
||||
|
||||
type Origin struct {
|
||||
@ -66,14 +67,6 @@ func (s *Origin) GenComment(origin string) string {
|
||||
}
|
||||
|
||||
func (s *Origin) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR) {
|
||||
ns := s.Ns
|
||||
if ns[len(ns)-1] != '.' {
|
||||
ns += origin
|
||||
}
|
||||
mbox := s.Mbox
|
||||
if mbox[len(mbox)-1] != '.' {
|
||||
mbox += origin
|
||||
}
|
||||
rrs = append(rrs, &dns.SOA{
|
||||
Hdr: dns.RR_Header{
|
||||
Name: domain,
|
||||
@ -81,8 +74,8 @@ func (s *Origin) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR)
|
||||
Class: dns.ClassINET,
|
||||
Ttl: ttl,
|
||||
},
|
||||
Ns: ns,
|
||||
Mbox: mbox,
|
||||
Ns: utils.DomainFQDN(s.Ns, origin),
|
||||
Mbox: utils.DomainFQDN(s.Mbox, origin),
|
||||
Serial: s.Serial,
|
||||
Refresh: uint32(s.Refresh.Seconds()),
|
||||
Retry: uint32(s.Retry.Seconds()),
|
||||
@ -90,10 +83,6 @@ func (s *Origin) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR)
|
||||
Minttl: uint32(s.Negttl.Seconds()),
|
||||
})
|
||||
for _, ns := range s.NameServers {
|
||||
if ns[len(ns)-1] != '.' {
|
||||
ns += origin
|
||||
}
|
||||
|
||||
rrs = append(rrs, &dns.NS{
|
||||
Hdr: dns.RR_Header{
|
||||
Name: domain,
|
||||
@ -101,7 +90,7 @@ func (s *Origin) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR)
|
||||
Class: dns.ClassINET,
|
||||
Ttl: ttl,
|
||||
},
|
||||
Ns: ns,
|
||||
Ns: utils.DomainFQDN(ns, origin),
|
||||
})
|
||||
}
|
||||
return
|
||||
|
@ -39,6 +39,7 @@ import (
|
||||
"github.com/miekg/dns"
|
||||
|
||||
"git.happydns.org/happydns/model"
|
||||
"git.happydns.org/happydns/utils"
|
||||
)
|
||||
|
||||
type SRV struct {
|
||||
@ -57,11 +58,6 @@ func (s *SRV) GenComment(origin string) string {
|
||||
}
|
||||
|
||||
func (s *SRV) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR) {
|
||||
target := s.Target
|
||||
if target[len(target)-1] != '.' {
|
||||
target += origin
|
||||
}
|
||||
|
||||
rrs = append(rrs, &dns.SRV{
|
||||
Hdr: dns.RR_Header{
|
||||
Name: domain,
|
||||
@ -72,7 +68,7 @@ func (s *SRV) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR) {
|
||||
Priority: s.Priority,
|
||||
Weight: s.Weight,
|
||||
Port: s.Port,
|
||||
Target: target,
|
||||
Target: utils.DomainFQDN(s.Target, origin),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
12
utils/dns.go
12
utils/dns.go
@ -67,3 +67,15 @@ func IsDNSSECType(rrtype uint16) bool {
|
||||
rrtype == dns.TypeDNSKEY ||
|
||||
rrtype == dns.TypeRRSIG
|
||||
}
|
||||
|
||||
// DomainFQDN normalizes the domain by adding the origin if it is relative (not
|
||||
// ended by .).
|
||||
func DomainFQDN(subdomain string, origin string) string {
|
||||
if subdomain == "" || subdomain[len(subdomain)-1] == '.' {
|
||||
return subdomain
|
||||
} else if subdomain == "@" {
|
||||
return origin
|
||||
} else {
|
||||
return subdomain + "." + origin
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user