add PTR
This commit is contained in:
parent
480554d313
commit
108e2448fe
|
@ -312,6 +312,44 @@ func srvEqual(a, b []SRV) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
type PTR struct {
|
||||
Ttl int `json:"ttl"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
// Equal determines if the record is equal
|
||||
func (a PTR) Equal(b PTR) bool {
|
||||
return a.Ttl == b.Ttl && a.Name == b.Name
|
||||
}
|
||||
|
||||
func (a PTR) TTL() (uint32, bool) {
|
||||
if a.Ttl >= 0 {
|
||||
return uint32(a.Ttl), true
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
|
||||
func ptrEqual(a, b []PTR) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
c := 0
|
||||
for _, ax := range a {
|
||||
for _, bx := range b {
|
||||
if ax.Name == bx.Name {
|
||||
if !ax.Equal(bx) {
|
||||
return false
|
||||
}
|
||||
c++
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(a) != c {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
type CAA struct {
|
||||
Ttl int `json:"ttl"`
|
||||
Flag uint8 `json:"flag"`
|
||||
|
|
|
@ -34,6 +34,7 @@ type Records struct {
|
|||
NS []NS `json:"NS,omitempty"`
|
||||
MX []MX `json:"MX,omitempty"`
|
||||
SRV []SRV `json:"SRV,omitempty"`
|
||||
PTR []PTR `json:"PTR,omitempty"`
|
||||
CAA []CAA `json:"CAA,omitempty"`
|
||||
}
|
||||
|
||||
|
@ -140,6 +141,10 @@ func (z Zone) Equal(zone Zone) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
if !ptrEqual(rec.PTR, r2.PTR) {
|
||||
return false
|
||||
}
|
||||
|
||||
if !caaEqual(rec.CAA, r2.CAA) {
|
||||
return false
|
||||
}
|
||||
|
@ -174,6 +179,8 @@ func (z *Zone) Add(loc string, record Record) {
|
|||
z.addNs(loc, record.(NS))
|
||||
case SRV:
|
||||
z.addSrv(loc, record.(SRV))
|
||||
case PTR:
|
||||
z.addPtr(loc, record.(PTR))
|
||||
case CAA:
|
||||
z.addCaa(loc, record.(CAA))
|
||||
default:
|
||||
|
@ -264,6 +271,17 @@ func (z *Zone) addSrv(loc string, rec SRV) {
|
|||
z.Locations[loc] = r
|
||||
}
|
||||
|
||||
func (z Zone) addPtr(loc string, rec PTR) {
|
||||
r := z.getOrAddLocation(loc)
|
||||
if r.PTR == nil {
|
||||
r.PTR = make([]PTR, 1)
|
||||
r.PTR[0] = rec
|
||||
} else {
|
||||
r.PTR = append(r.PTR, rec)
|
||||
}
|
||||
z.Locations[loc] = r
|
||||
}
|
||||
|
||||
func (z *Zone) addCaa(loc string, rec CAA) {
|
||||
r := z.getOrAddLocation(loc)
|
||||
if r.CAA == nil {
|
||||
|
@ -359,6 +377,11 @@ func (z Zone) String() (str string) {
|
|||
spacedLoc(loc, maxL), r.Ttl, r.Priority, r.Weight, r.Port, r.Target))
|
||||
checkError(i, err)
|
||||
}
|
||||
for _, r := range z.Locations[k].PTR {
|
||||
i, err = sb.WriteString(fmt.Sprintf("%s%d IN SRV %s\n",
|
||||
spacedLoc(loc, maxL), r.Ttl, r.Name))
|
||||
checkError(i, err)
|
||||
}
|
||||
for _, r := range z.Locations[k].CAA {
|
||||
i, err = sb.WriteString(fmt.Sprintf("%s%d IN CAA %d %s %s\n",
|
||||
spacedLoc(loc, maxL), r.Ttl, r.Flag, r.Tag, r.Value))
|
||||
|
|
21
redis.go
21
redis.go
|
@ -221,6 +221,21 @@ func (redis *Redis) SRV(name string, z *record.Zone, record *record.Records, zon
|
|||
return
|
||||
}
|
||||
|
||||
func (redis *Redis) PTR(name string, z *record.Zone, record *record.Records, zones []string) (answers, extras []dns.RR) {
|
||||
for _, ptr := range record.PTR {
|
||||
if len(ptr.Name) == 0 {
|
||||
continue
|
||||
}
|
||||
r := new(dns.PTR)
|
||||
r.Hdr = dns.RR_Header{Name: dns.Fqdn(name), Rrtype: dns.TypePTR,
|
||||
Class: dns.ClassINET, Ttl: redis.ttl(ptr.Ttl)}
|
||||
r.Ptr = ptr.Name
|
||||
answers = append(answers, r)
|
||||
extras = append(extras, redis.getExtras(ptr.Name, z, zones)...)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (redis *Redis) CAA(name string, _ *record.Zone, record *record.Records) (answers, extras []dns.RR) {
|
||||
if record == nil {
|
||||
return
|
||||
|
@ -283,6 +298,10 @@ func (redis *Redis) AXFR(z *record.Zone, zones []string) (records []dns.RR) {
|
|||
answers = append(answers, as...)
|
||||
extras = append(extras, xs...)
|
||||
|
||||
as, xs = redis.PTR(fqdnKey, z, zoneRecords, zones)
|
||||
answers = append(answers, as...)
|
||||
extras = append(extras, xs...)
|
||||
|
||||
as, xs = redis.TXT(fqdnKey, z, zoneRecords)
|
||||
answers = append(answers, as...)
|
||||
extras = append(extras, xs...)
|
||||
|
@ -331,7 +350,7 @@ func (redis *Redis) fillExtras(name string, z *record.Zone, location string) []d
|
|||
)
|
||||
|
||||
zoneRecords = redis.LoadZoneRecords(location, z)
|
||||
zoneRecords.MakeFqdn(z.Name)
|
||||
zoneRecords.MakeFqdn(z.Name)
|
||||
|
||||
if zoneRecords == nil {
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue