A simple nameserver, doesnt do referals yet
This commit is contained in:
parent
051ceaa454
commit
d0641c7cb9
|
@ -21,15 +21,26 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) {
|
|||
w.Write(m)
|
||||
return
|
||||
}
|
||||
apex := z.Find(z.Origin)
|
||||
// Referral?
|
||||
// Name found, look for type, yes, answer, no
|
||||
if rrs, ok := node.RR[req.Question[0].Qtype] {
|
||||
// rrs match name and type
|
||||
if rrs, ok := node.RR[req.Question[0].Qtype]; ok {
|
||||
// Need to look at class to but... no
|
||||
// create answer
|
||||
m := new(dns.Msg)
|
||||
m.SetReply(req)
|
||||
m.Answer = rrs
|
||||
// auth section
|
||||
m.Ns = apex.RR[dns.TypeNS]
|
||||
w.Write(m)
|
||||
return
|
||||
} else {
|
||||
// nodate reply
|
||||
// soa in auth section
|
||||
m := new(dns.Msg)
|
||||
m.SetReply(req)
|
||||
m.Ns = apex.RR[dns.TypeSOA]
|
||||
w.Write(m)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
w.Write(m)
|
||||
}
|
||||
|
|
16
zone.go
16
zone.go
|
@ -15,15 +15,13 @@ type Zone struct {
|
|||
|
||||
// ZoneData holds all the RRs having their ownername equal to Name.
|
||||
type ZoneData struct {
|
||||
Name string // Domain name for this node
|
||||
RR map[uint16][]RR // Map of the RR type to the RR
|
||||
// DNSSEC signatures for the RRsets
|
||||
Signatures []*RR_RRSIG
|
||||
Name string // Domain name for this node
|
||||
RR map[uint16][]RR // Map of the RR type to the RR
|
||||
Signatures map[uint16][]*RR_RRSIG // DNSSEC signatures for the RRs, stored under type covered
|
||||
// Always false, except for NSsets that differ from z.Origin
|
||||
NonAuth bool
|
||||
}
|
||||
|
||||
|
||||
// toRadixName reverses a domainname so that when we store it in the radix tree
|
||||
// we preserve the nsec ordering of the zone (this idea was stolen from NSD).
|
||||
// each label is also lowercased.
|
||||
|
@ -61,10 +59,11 @@ func (z *Zone) Insert(r RR) error {
|
|||
zd := new(ZoneData)
|
||||
zd.Name = r.Header().Name
|
||||
zd.RR = make(map[uint16][]RR)
|
||||
zd.Signatures = make([]*RR_RRSIG, 0)
|
||||
zd.Signatures = make(map[uint16][]*RR_RRSIG)
|
||||
switch t := r.Header().Rrtype; t {
|
||||
case TypeRRSIG:
|
||||
zd.Signatures = append(zd.Signatures, r.(*RR_RRSIG))
|
||||
sigtype := r.(*RR_RRSIG).TypeCovered
|
||||
zd.Signatures[sigtype] = append(zd.Signatures[sigtype], r.(*RR_RRSIG))
|
||||
case TypeNS:
|
||||
// NS records with other names than z.Origin are non-auth
|
||||
if r.Header().Name != z.Origin {
|
||||
|
@ -80,7 +79,8 @@ func (z *Zone) Insert(r RR) error {
|
|||
// Name already there
|
||||
switch t := r.Header().Rrtype; t {
|
||||
case TypeRRSIG:
|
||||
zd.Value.(*ZoneData).Signatures = append(zd.Value.(*ZoneData).Signatures, r.(*RR_RRSIG))
|
||||
sigtype := r.(*RR_RRSIG).TypeCovered
|
||||
zd.Value.(*ZoneData).Signatures[sigtype] = append(zd.Value.(*ZoneData).Signatures[sigtype], r.(*RR_RRSIG))
|
||||
case TypeNS:
|
||||
if r.Header().Name != z.Origin {
|
||||
zd.Value.(*ZoneData).NonAuth = true
|
||||
|
|
Loading…
Reference in New Issue