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)
|
w.Write(m)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
apex := z.Find(z.Origin)
|
||||||
// Referral?
|
// Referral?
|
||||||
// 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] {
|
if rrs, ok := node.RR[req.Question[0].Qtype]; ok {
|
||||||
// rrs match name and type
|
|
||||||
// Need to look at class to but... no
|
// 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)
|
w.Write(m)
|
||||||
}
|
}
|
||||||
|
|
12
zone.go
12
zone.go
|
@ -17,13 +17,11 @@ type Zone struct {
|
||||||
type ZoneData struct {
|
type ZoneData struct {
|
||||||
Name string // Domain name for this node
|
Name string // Domain name for this node
|
||||||
RR map[uint16][]RR // Map of the RR type to the RR
|
RR map[uint16][]RR // Map of the RR type to the RR
|
||||||
// DNSSEC signatures for the RRsets
|
Signatures map[uint16][]*RR_RRSIG // DNSSEC signatures for the RRs, stored under type covered
|
||||||
Signatures []*RR_RRSIG
|
|
||||||
// Always false, except for NSsets that differ from z.Origin
|
// Always false, except for NSsets that differ from z.Origin
|
||||||
NonAuth bool
|
NonAuth bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// toRadixName reverses a domainname so that when we store it in the radix tree
|
// 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).
|
// we preserve the nsec ordering of the zone (this idea was stolen from NSD).
|
||||||
// each label is also lowercased.
|
// each label is also lowercased.
|
||||||
|
@ -61,10 +59,11 @@ func (z *Zone) Insert(r RR) error {
|
||||||
zd := new(ZoneData)
|
zd := new(ZoneData)
|
||||||
zd.Name = r.Header().Name
|
zd.Name = r.Header().Name
|
||||||
zd.RR = make(map[uint16][]RR)
|
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 {
|
switch t := r.Header().Rrtype; t {
|
||||||
case TypeRRSIG:
|
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:
|
case TypeNS:
|
||||||
// NS records with other names than z.Origin are non-auth
|
// NS records with other names than z.Origin are non-auth
|
||||||
if r.Header().Name != z.Origin {
|
if r.Header().Name != z.Origin {
|
||||||
|
@ -80,7 +79,8 @@ func (z *Zone) Insert(r RR) error {
|
||||||
// Name already there
|
// Name already there
|
||||||
switch t := r.Header().Rrtype; t {
|
switch t := r.Header().Rrtype; t {
|
||||||
case TypeRRSIG:
|
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:
|
case TypeNS:
|
||||||
if r.Header().Name != z.Origin {
|
if r.Header().Name != z.Origin {
|
||||||
zd.Value.(*ZoneData).NonAuth = true
|
zd.Value.(*ZoneData).NonAuth = true
|
||||||
|
|
Loading…
Reference in New Issue