Use the more correct SERVAIL instead of REFUSED

This commit is contained in:
Miek Gieben 2012-08-03 08:38:41 -07:00
parent cd0567023f
commit e08a87a991
3 changed files with 15 additions and 33 deletions

View File

@ -4,15 +4,6 @@ import (
"dns" "dns"
) )
func serve(w dns.ResponseWriter, req *dns.Msg, z *Zones) { func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) {
// for DS go to the parent...? TODO(mg) // nil
zone := z.Find(req.Question[0].Name)
if zone == nil {
m := new(dns.Msg)
m.SetRcode(req, dns.RcodeServerFailure)
w.Write(m)
return
}
// Need to look how the algorithm is in rfc1035
} }

View File

@ -6,7 +6,6 @@ import (
"flag" "flag"
"log" "log"
"os" "os"
"radix"
) )
var ( var (
@ -14,14 +13,8 @@ var (
o = flag.String("origin", "", "origin of the zone") o = flag.String("origin", "", "origin of the zone")
) )
// Zones holds all the zones we have. Its only holds
// the zone's name and nothing else.
type Zones struct {
*radix.Radix
}
// Read a zone and add it. // Read a zone and add it.
func (z *Zones) addZone(origin, file string) error { func addZone(zones map[string]*dns.Zone, origin, file string) error {
origin = dns.Fqdn(origin) origin = dns.Fqdn(origin)
z1 := dns.NewZone(origin) z1 := dns.NewZone(origin)
if z1 == nil { if z1 == nil {
@ -31,14 +24,13 @@ func (z *Zones) addZone(origin, file string) error {
if e != nil { if e != nil {
return e return e
} }
for rr := range dns.ParseZone(f, origin, file) { for rr := range dns.ParseZone(f, origin, file) {
// TODO(mg): blab something about the error? // TODO(mg): blab something about the error?
if rr.Error == nil { if rr.Error == nil {
z1.Insert(rr.RR) z1.Insert(rr.RR)
} }
} }
z.Radix.Insert(origin, z1) zones[origin] = z1
return nil return nil
} }
@ -51,11 +43,9 @@ func main() {
if *o == "" { if *o == "" {
log.Fatal("no origin") log.Fatal("no origin")
} }
Z := new(Zones) Z := make(map[string]*dns.Zone)
Z.Radix = radix.New() addZone(Z, *o, *z)
Z.addZone(*o, *z) dns.HandleFunc(*o, func(w dns.ResponseWriter, req *dns.Msg) { serve(w, req, Z[*o]) })
dns.HandleFunc(*o, func(w dns.ResponseWriter, req *dns.Msg) { serve(w, req, Z) })
// NX domain?? TODO(mg)
go func() { go func() {
err := dns.ListenAndServe(":8053", "udp", nil) err := dns.ListenAndServe(":8053", "udp", nil)
if err != nil { if err != nil {

View File

@ -70,16 +70,16 @@ func (f HandlerFunc) ServeDNS(w ResponseWriter, r *Msg) {
f(w, r) f(w, r)
} }
// Refused is a helper handler that returns an answer with // Failed is a helper handler that returns an answer with
// RCODE = refused for every request. // RCODE = servfail for every request.
func Refused(w ResponseWriter, r *Msg) { func Failed(w ResponseWriter, r *Msg) {
m := new(Msg) m := new(Msg)
m.SetRcode(r, RcodeRefused) m.SetRcode(r, RcodeServerFailure)
w.Write(m) w.Write(m)
} }
// RefusedHandler returns HandlerFunc with Refused. // FailedHandler returns HandlerFunc with Failed.
func RefusedHandler() Handler { return HandlerFunc(Refused) } func FailedHandler() Handler { return HandlerFunc(Failed) }
// Start a server on addresss and network speficied. Invoke handler // Start a server on addresss and network speficied. Invoke handler
// for any incoming queries. // for any incoming queries.
@ -135,10 +135,11 @@ func (mux *ServeMux) HandleRemove(pattern string) {
// ServeDNS dispatches the request to the handler whose // ServeDNS dispatches the request to the handler whose
// pattern most closely matches the request message. // pattern most closely matches the request message.
// If no handler is found a standard SERVFAIL message is returned
func (mux *ServeMux) ServeDNS(w ResponseWriter, request *Msg) { func (mux *ServeMux) ServeDNS(w ResponseWriter, request *Msg) {
h := mux.match(request.Question[0].Name) h := mux.match(request.Question[0].Name)
if h == nil { if h == nil {
h = RefusedHandler() h = FailedHandler()
} }
h.ServeDNS(w, request) h.ServeDNS(w, request)
} }