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"
)
func serve(w dns.ResponseWriter, req *dns.Msg, z *Zones) {
// for DS go to the parent...? TODO(mg)
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
func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) {
// nil
}

View File

@ -6,7 +6,6 @@ import (
"flag"
"log"
"os"
"radix"
)
var (
@ -14,14 +13,8 @@ var (
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.
func (z *Zones) addZone(origin, file string) error {
func addZone(zones map[string]*dns.Zone, origin, file string) error {
origin = dns.Fqdn(origin)
z1 := dns.NewZone(origin)
if z1 == nil {
@ -31,14 +24,13 @@ func (z *Zones) addZone(origin, file string) error {
if e != nil {
return e
}
for rr := range dns.ParseZone(f, origin, file) {
// TODO(mg): blab something about the error?
if rr.Error == nil {
z1.Insert(rr.RR)
}
}
z.Radix.Insert(origin, z1)
zones[origin] = z1
return nil
}
@ -51,11 +43,9 @@ func main() {
if *o == "" {
log.Fatal("no origin")
}
Z := new(Zones)
Z.Radix = radix.New()
Z.addZone(*o, *z)
dns.HandleFunc(*o, func(w dns.ResponseWriter, req *dns.Msg) { serve(w, req, Z) })
// NX domain?? TODO(mg)
Z := make(map[string]*dns.Zone)
addZone(Z, *o, *z)
dns.HandleFunc(*o, func(w dns.ResponseWriter, req *dns.Msg) { serve(w, req, Z[*o]) })
go func() {
err := dns.ListenAndServe(":8053", "udp", nil)
if err != nil {

View File

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