Fix delegations

This commit is contained in:
Miek Gieben 2012-08-04 11:56:57 -07:00
parent d4c5036377
commit fba7b11981
2 changed files with 32 additions and 9 deletions

View File

@ -7,10 +7,24 @@ import (
func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) { func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) {
// See RFC 1035... // See RFC 1035...
m := new(dns.Msg) m := new(dns.Msg)
m.SetRcode(req, dns.RcodeNameError) m.SetRcode(req, dns.RcodeNameError)
log.Printf("incoming %s\n", req.Question[0].Name) log.Printf("incoming %s %d\n", req.Question[0].Name, req.Question[0].Qtype)
// Check for referral
// if we find something with NonAuth = true, it means
// we need to return referaal
nss := z.Predecessor(req.Question[0].Name)
if nss.NonAuth {
m := new(dns.Msg)
m.SetReply(req)
m.Ns = nss.RR[dns.TypeNS]
// lookup the a records for additional, only when
// in baliwick
w.Write(m)
return
}
// For now: // For now:
// look up name -> yes, continue, no -> nxdomain // look up name -> yes, continue, no -> nxdomain
node := z.Find(req.Question[0].Name) node := z.Find(req.Question[0].Name)
@ -21,6 +35,9 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) {
return return
} }
apex := z.Find(z.Origin) apex := z.Find(z.Origin)
log.Println("Upper zone", nss.Name)
log.Println("It auth value", nss.NonAuth)
// Referral need support from the radix tree, successor? // Referral need support from the radix tree, successor?
// Name found, look for type, yes, answer, no // Name found, look for type, yes, answer, no
if rrs, ok := node.RR[req.Question[0].Qtype]; ok { if rrs, ok := node.RR[req.Question[0].Qtype]; ok {

18
zone.go
View File

@ -97,16 +97,22 @@ func (z *Zone) Remove(r RR) error {
return nil return nil
} }
// Find search the zone data and returns a node or nil when // Find wraps radix.Find.
// nothing is found.
func (z *Zone) Find(s string) *ZoneData { func (z *Zone) Find(s string) *ZoneData {
if z.Radix == nil {
println("huh nil")
return nil
}
zd := z.Radix.Find(toRadixName(s)) zd := z.Radix.Find(toRadixName(s))
if zd == nil { if zd == nil {
return nil return nil
} }
return zd.Value.(*ZoneData) return zd.Value.(*ZoneData)
} }
// Predecessor wraps radix.Predecessor.
func (z *Zone) Predecessor(s string) *ZoneData {
println("looking for", toRadixName(s))
zd := z.Radix.Predecessor(toRadixName(s))
if zd == nil {
return nil
}
println("Found", zd.Key())
return zd.Value.(*ZoneData)
}