Fixes for predecessor

This commit is contained in:
Miek Gieben 2012-08-05 05:35:30 +02:00
parent 74cb343482
commit 0a28fb5c6a
3 changed files with 37 additions and 4 deletions

View File

@ -26,6 +26,9 @@ func main() {
log.Fatal("Huh %s\n", e.Error())
}
dns.HandleFunc(*o, func(w dns.ResponseWriter, req *dns.Msg) { serve(w, req, Z[dns.Fqdn(*o)]) })
// dns.HandleFunc("nl.", func(w dns.ResponseWriter, req *dns.Msg) { serve(w, req, Z["nl."]) })
// dns.HandleFunc(".", func(w dns.ResponseWriter, req *dns.Msg) { serve(w, req, Z["."]) })
go func() {
err := dns.ListenAndServe(":8053", "udp", nil)
if err != nil {

View File

@ -7,7 +7,7 @@ import (
func serve(w dns.ResponseWriter, req *dns.Msg, z *dns.Zone) {
if *l {
log.Printf("fks: incoming %s %s %d\n", req.Question[0].Name, dns.Rr_str[req.Question[0].Qtype], req.MsgHdr.Id)
log.Printf("fks: [zone %s] incoming %s %s %d\n", z.Origin, req.Question[0].Name, dns.Rr_str[req.Question[0].Qtype], req.MsgHdr.Id)
}
// Referral
// if we find something with NonAuth = true, it means

View File

@ -9,6 +9,7 @@ package dns
import (
"io"
"net"
"strings"
"time"
)
@ -96,11 +97,11 @@ func ListenAndServeTsig(addr string, network string, handler Handler, tsig map[s
return server.ListenAndServe()
}
func (mux *ServeMux) match(zone string) Handler {
// Maybe use a radix tree here too...?
func (mux *ServeMux) match(zone string, t uint16) Handler {
var h Handler
var n = 0
for k, v := range mux.m {
println(string(k)) // DEBUG
if !zoneMatch(k, zone) {
continue
}
@ -109,6 +110,35 @@ func (mux *ServeMux) match(zone string) Handler {
h = v
}
}
// Zone has been found
if t != TypeDS {
return h
}
// Uberhack: if we are matching DS records, we chop of the
// first label. This way we will not match the zone
// but the first parent.
// Check if we also are authoritative for the parent
// TODO(mg): second time we 'range' the map
// TODO(mg): root check
var p Handler
xs := SplitLabels(zone)
zone = Fqdn(strings.Join(xs[1:], "."))
println(zone)
n = 0
for k, v := range mux.m {
if !zoneMatch(k, zone) {
continue
}
if p == nil || len(k) > n {
n = len(k)
p = v
}
}
if p != nil {
println("returning p")
return p
}
return h
}
@ -139,7 +169,7 @@ func (mux *ServeMux) HandleRemove(pattern string) {
// a parent zone is sought.
// 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)
h := mux.match(request.Question[0].Name, request.Question[0].Qtype)
if h == nil {
h = FailedHandler()
}