diff --git a/ex/fksd/TODO b/ex/fksd/TODO index 78768b2f..adcb1684 100644 --- a/ex/fksd/TODO +++ b/ex/fksd/TODO @@ -1,5 +1,4 @@ * wildcard -* cname (redo query with rhs?) * locking r/w or copy-on-write in radix * check message length * ds handling in serve() diff --git a/ex/fksd/serve.go b/ex/fksd/serve.go index 031cd1e3..aa165d94 100644 --- a/ex/fksd/serve.go +++ b/ex/fksd/serve.go @@ -2,6 +2,7 @@ package main import ( "dns" + "strings" ) // Create skeleton edns opt RR from the query and @@ -21,8 +22,7 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) { panic("fksd: no zone") } logPrintf("[zone %s] incoming %s %s %d from %s\n", z.Origin, req.Question[0].Name, dns.Rr_str[req.Question[0].Qtype], req.MsgHdr.Id, w.RemoteAddr()) - // if we find something with NonAuth = true, it means - // we need to return referral + // if we find something with NonAuth = true, it means we need to return referral nss := z.Predecessor(req.Question[0].Name) m := new(dns.Msg) if nss != nil && nss.NonAuth { @@ -48,16 +48,25 @@ func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) { return } - // Wildcards...? // If we don't have the name return NXDOMAIN node := z.Find(req.Question[0].Name) if node == nil { + if z.Wildcard > 0 { + lx := dns.SplitLabels(req.Question[0].Name) + wc := "*." + strings.Join(lx[1:], ".") + node = z.Find(wc) + if node != nil { + goto Wildcard + } + } m.SetRcode(req, dns.RcodeNameError) ednsFromRequest(req, m) w.Write(m) return } + Wildcard: + // We have the name it isn't a referral, but it may that // we still have NSs for this name. If we have nss and they // are NonAuth true return those. diff --git a/ex/fksd/z/miek.nl.db b/ex/fksd/z/miek.nl.db index c12cbe8d..e5f0c403 100644 --- a/ex/fksd/z/miek.nl.db +++ b/ex/fksd/z/miek.nl.db @@ -55,3 +55,4 @@ a1.sub IN A 127.0.0.1 a2.sub IN A 127.0.0.1 a1.sub IN AAAA ::1 a2.sub IN AAAA ::1 +*.w.miek.nl. IN TXT "wildcard" diff --git a/zone.go b/zone.go index cecc84f5..b9975f74 100644 --- a/zone.go +++ b/zone.go @@ -10,6 +10,7 @@ import ( // Zone represents a DNS zone. type Zone struct { Origin string // Origin of the zone + Wildcard int // Whenever we see a wildcard name, this is incremented *radix.Radix // Zone data } @@ -59,6 +60,10 @@ func (z *Zone) Insert(r RR) error { key := toRadixName(r.Header().Name) zd := z.Radix.Find(key) if zd == nil { + // Check if its a wildcard name + if len(r.Header().Name) > 1 && r.Header().Name[0] == '*' && r.Header().Name[1] == '.' { + z.Wildcard++ + } zd := new(ZoneData) zd.Name = r.Header().Name zd.RR = make(map[uint16][]RR) @@ -97,6 +102,7 @@ func (z *Zone) Insert(r RR) error { // RemoveName removeRRset ?? func (z *Zone) Remove(r RR) error { + // Wildcards return nil }