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"
|
"github.com/miekg/dns"
|
||||||
|
|
||||||
"git.happydns.org/happydns/model"
|
"git.happydns.org/happydns/model"
|
||||||
|
"git.happydns.org/happydns/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CNAME struct {
|
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) {
|
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{
|
rrs = append(rrs, &dns.CNAME{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Name: domain,
|
Name: domain,
|
||||||
|
@ -65,7 +61,7 @@ func (s *CNAME) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR)
|
||||||
Class: dns.ClassINET,
|
Class: dns.ClassINET,
|
||||||
Ttl: ttl,
|
Ttl: ttl,
|
||||||
},
|
},
|
||||||
Target: target,
|
Target: utils.DomainFQDN(s.Target, origin),
|
||||||
})
|
})
|
||||||
return
|
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) {
|
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{
|
rrs = append(rrs, &dns.CNAME{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Name: s.SubDomain + "." + domain,
|
Name: s.SubDomain + "." + domain,
|
||||||
|
@ -96,7 +87,7 @@ func (s *SpecialCNAME) GenRRs(domain string, ttl uint32, origin string) (rrs []d
|
||||||
Class: dns.ClassINET,
|
Class: dns.ClassINET,
|
||||||
Ttl: ttl,
|
Ttl: ttl,
|
||||||
},
|
},
|
||||||
Target: target,
|
Target: utils.DomainFQDN(s.Target, origin),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ import (
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
|
||||||
"git.happydns.org/happydns/model"
|
"git.happydns.org/happydns/model"
|
||||||
|
"git.happydns.org/happydns/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DS struct {
|
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) {
|
func (s *Delegation) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR) {
|
||||||
for _, ns := range s.NameServers {
|
for _, ns := range s.NameServers {
|
||||||
if ns[len(ns)-1] != '.' {
|
|
||||||
ns += origin
|
|
||||||
}
|
|
||||||
|
|
||||||
rrs = append(rrs, &dns.NS{
|
rrs = append(rrs, &dns.NS{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Name: domain,
|
Name: domain,
|
||||||
|
@ -77,7 +74,7 @@ func (s *Delegation) GenRRs(domain string, ttl uint32, origin string) (rrs []dns
|
||||||
Class: dns.ClassINET,
|
Class: dns.ClassINET,
|
||||||
Ttl: ttl,
|
Ttl: ttl,
|
||||||
},
|
},
|
||||||
Ns: ns,
|
Ns: utils.DomainFQDN(ns, origin),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for _, ds := range s.DS {
|
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) {
|
func (s *EMail) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR) {
|
||||||
if len(s.MX) > 0 {
|
if len(s.MX) > 0 {
|
||||||
for _, mx := range s.MX {
|
for _, mx := range s.MX {
|
||||||
target := mx.Target
|
|
||||||
if target[len(target)-1] != '.' {
|
|
||||||
target += origin
|
|
||||||
}
|
|
||||||
|
|
||||||
rrs = append(rrs, &dns.MX{
|
rrs = append(rrs, &dns.MX{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Name: domain,
|
Name: domain,
|
||||||
|
@ -188,7 +183,7 @@ func (s *EMail) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR)
|
||||||
Class: dns.ClassINET,
|
Class: dns.ClassINET,
|
||||||
Ttl: ttl,
|
Ttl: ttl,
|
||||||
},
|
},
|
||||||
Mx: target,
|
Mx: utils.DomainFQDN(mx.Target, origin),
|
||||||
Preference: mx.Preference,
|
Preference: mx.Preference,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ import (
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
|
||||||
"git.happydns.org/happydns/model"
|
"git.happydns.org/happydns/model"
|
||||||
|
"git.happydns.org/happydns/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Origin struct {
|
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) {
|
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{
|
rrs = append(rrs, &dns.SOA{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Name: domain,
|
Name: domain,
|
||||||
|
@ -81,8 +74,8 @@ func (s *Origin) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR)
|
||||||
Class: dns.ClassINET,
|
Class: dns.ClassINET,
|
||||||
Ttl: ttl,
|
Ttl: ttl,
|
||||||
},
|
},
|
||||||
Ns: ns,
|
Ns: utils.DomainFQDN(s.Ns, origin),
|
||||||
Mbox: mbox,
|
Mbox: utils.DomainFQDN(s.Mbox, origin),
|
||||||
Serial: s.Serial,
|
Serial: s.Serial,
|
||||||
Refresh: uint32(s.Refresh.Seconds()),
|
Refresh: uint32(s.Refresh.Seconds()),
|
||||||
Retry: uint32(s.Retry.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()),
|
Minttl: uint32(s.Negttl.Seconds()),
|
||||||
})
|
})
|
||||||
for _, ns := range s.NameServers {
|
for _, ns := range s.NameServers {
|
||||||
if ns[len(ns)-1] != '.' {
|
|
||||||
ns += origin
|
|
||||||
}
|
|
||||||
|
|
||||||
rrs = append(rrs, &dns.NS{
|
rrs = append(rrs, &dns.NS{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Name: domain,
|
Name: domain,
|
||||||
|
@ -101,7 +90,7 @@ func (s *Origin) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR)
|
||||||
Class: dns.ClassINET,
|
Class: dns.ClassINET,
|
||||||
Ttl: ttl,
|
Ttl: ttl,
|
||||||
},
|
},
|
||||||
Ns: ns,
|
Ns: utils.DomainFQDN(ns, origin),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
@ -39,6 +39,7 @@ import (
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
|
||||||
"git.happydns.org/happydns/model"
|
"git.happydns.org/happydns/model"
|
||||||
|
"git.happydns.org/happydns/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SRV struct {
|
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) {
|
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{
|
rrs = append(rrs, &dns.SRV{
|
||||||
Hdr: dns.RR_Header{
|
Hdr: dns.RR_Header{
|
||||||
Name: domain,
|
Name: domain,
|
||||||
|
@ -72,7 +68,7 @@ func (s *SRV) GenRRs(domain string, ttl uint32, origin string) (rrs []dns.RR) {
|
||||||
Priority: s.Priority,
|
Priority: s.Priority,
|
||||||
Weight: s.Weight,
|
Weight: s.Weight,
|
||||||
Port: s.Port,
|
Port: s.Port,
|
||||||
Target: target,
|
Target: utils.DomainFQDN(s.Target, origin),
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
12
utils/dns.go
12
utils/dns.go
|
@ -67,3 +67,15 @@ func IsDNSSECType(rrtype uint16) bool {
|
||||||
rrtype == dns.TypeDNSKEY ||
|
rrtype == dns.TypeDNSKEY ||
|
||||||
rrtype == dns.TypeRRSIG
|
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