From d0641c7cb901f0057c1aed3e4e942d64e1fea44c Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Fri, 3 Aug 2012 15:51:35 -0700 Subject: [PATCH] A simple nameserver, doesnt do referals yet --- ex/fks/serve.go | 23 +++++++++++++++++------ zone.go | 16 ++++++++-------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/ex/fks/serve.go b/ex/fks/serve.go index 1868c0bc..73c0b99e 100644 --- a/ex/fks/serve.go +++ b/ex/fks/serve.go @@ -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) } diff --git a/zone.go b/zone.go index e52f0116..076d29d0 100644 --- a/zone.go +++ b/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