dns/zone.go

64 lines
1.4 KiB
Go
Raw Normal View History

2012-07-14 20:01:52 +00:00
package dns
// A structure for handling zone data
import (
2012-07-15 18:23:53 +00:00
"github.com/sauerbraten/radix"
2012-07-14 20:01:52 +00:00
)
2012-07-15 21:15:04 +00:00
// Zone represents a DNS zone.
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-15 21:15:04 +00:00
// soa parameters in here TODO(mg)
2012-07-14 20:01:52 +00:00
}
2012-07-15 21:15:04 +00:00
// ZoneData holds all the RR belonging to Name.
// TODO(mg): uitbreiden
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 ...
2012-07-15 17:16:39 +00:00
func NewZone(name string) *Zone {
2012-07-14 20:54:49 +00:00
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
}
2012-07-15 21:15:04 +00:00
// Insert inserts an RR into the zone. Overwrites.
2012-07-14 20:54:49 +00:00
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
2012-07-15 17:16:39 +00:00
zd.RR = make(map[uint16][]RR)
zd.Signatures = make([]*RR_RRSIG, 0)
2012-07-15 16:11:17 +00:00
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:16:20 +00:00
z.Radix.Insert(r.Header().Name, zd)
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
}