diff --git a/ex/fks/serve.go b/ex/fks/serve.go index c4073fcb..ce22f6b4 100644 --- a/ex/fks/serve.go +++ b/ex/fks/serve.go @@ -7,10 +7,24 @@ import ( func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) { // See RFC 1035... - m := new(dns.Msg) - m.SetRcode(req, dns.RcodeNameError) + m := new(dns.Msg) + 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: // look up name -> yes, continue, no -> nxdomain node := z.Find(req.Question[0].Name) @@ -21,6 +35,9 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) { return } 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? // Name found, look for type, yes, answer, no if rrs, ok := node.RR[req.Question[0].Qtype]; ok { diff --git a/zone.go b/zone.go index 076d29d0..efb3babf 100644 --- a/zone.go +++ b/zone.go @@ -97,16 +97,22 @@ func (z *Zone) Remove(r RR) error { return nil } -// Find search the zone data and returns a node or nil when -// nothing is found. +// Find wraps radix.Find. func (z *Zone) Find(s string) *ZoneData { - if z.Radix == nil { - println("huh nil") - return nil - } zd := z.Radix.Find(toRadixName(s)) if zd == nil { return nil } 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) +}