2012-07-14 20:01:52 +00:00
|
|
|
package dns
|
|
|
|
|
|
|
|
// A structure for handling zone data
|
|
|
|
|
|
|
|
import (
|
2012-07-15 16:11:17 +00:00
|
|
|
"github.com/miekg/radix"
|
2012-07-14 20:01:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Zone struct {
|
2012-07-15 16:11:17 +00:00
|
|
|
Name string // Name of the zone
|
|
|
|
*radix.Radix // Zone data
|
2012-07-14 20:01:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type ZoneData struct {
|
2012-07-15 16:11:17 +00:00
|
|
|
Name string // Domain name for this node
|
|
|
|
RR map[uint16][]RR // Map of the RR type to the RR
|
|
|
|
Signatures []*RR_RRSIG // DNSSEC signatures
|
|
|
|
Glue bool // True if the A and AAAA record are glue
|
2012-07-14 20:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New ...
|
|
|
|
func New(name string) *Zone {
|
|
|
|
z := new(Zone)
|
|
|
|
z.Name = name
|
2012-07-15 16:11:17 +00:00
|
|
|
z.Radix = radix.New()
|
2012-07-14 20:54:49 +00:00
|
|
|
return z
|
|
|
|
}
|
|
|
|
|
|
|
|
func (z *Zone) Insert(r RR) {
|
2012-07-15 16:11:17 +00:00
|
|
|
zd := z.Radix.Find(r.Header().Name)
|
|
|
|
if zd == nil {
|
|
|
|
zd := new(ZoneData)
|
|
|
|
zd.Name = r.Header().Name
|
|
|
|
switch t := r.Header().Rrtype; t {
|
|
|
|
case TypeRRSIG:
|
|
|
|
zd.Signatures = append(zd.Signatures, r.(*RR_RRSIG))
|
|
|
|
default:
|
|
|
|
zd.RR[t] = append(zd.RR[t], r)
|
|
|
|
}
|
2012-07-15 16:13:24 +00:00
|
|
|
z.Radix.Insert(r.Header().Name)
|
2012-07-15 16:11:17 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
switch t := r.Header().Rrtype; t {
|
|
|
|
case TypeRRSIG:
|
|
|
|
zd.(*ZoneData).Signatures = append(zd.(*ZoneData).Signatures, r.(*RR_RRSIG))
|
|
|
|
default:
|
|
|
|
zd.(*ZoneData).RR[t] = append(zd.(*ZoneData).RR[t], r)
|
|
|
|
}
|
|
|
|
// TODO(mg): Glue
|
|
|
|
return
|
2012-07-14 20:54:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (z *Zone) Remove(r RR) {
|
|
|
|
|
2012-07-14 20:01:52 +00:00
|
|
|
}
|