Fix as212 server

This commit is contained in:
Miek Gieben 2013-06-22 21:40:19 +01:00
parent 93c0500dce
commit baa7ca4a82
3 changed files with 38 additions and 43 deletions

View File

@ -12,6 +12,7 @@ import (
"log"
"os"
"os/signal"
"runtime"
"syscall"
)
@ -45,6 +46,17 @@ func NewRR(s string) dns.RR {
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU()*2 + 1)
for z, rr := range zones {
rrx := rr.(*dns.SOA) // Some foo needed to created actual RR, on the not a reference
dns.HandleFunc(z, func(w dns.ResponseWriter, r *dns.Msg) {
m := new(dns.Msg)
m.SetReply(r)
m.Authoritative = true
m.Ns = []dns.RR{rrx}
w.WriteMsg(m)
})
}
go func() {
err := dns.ListenAndServe(":8053", "tcp", nil)
if err != nil {
@ -57,18 +69,8 @@ func main() {
log.Fatal("Failed to set tcp listener %s\n", err.Error())
}
}()
for z, rr := range zones {
dns.HandleFunc(z, func(w dns.ResponseWriter, r *dns.Msg) {
m := new(dns.Msg)
m.SetReply(r)
m.Authoritative = true
m.Ns = []dns.RR{rr}
w.WriteMsg(m)
})
}
sig := make(chan os.Signal)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
for {
select {
case s := <-sig:

View File

@ -39,6 +39,7 @@ import (
"net"
"os"
"os/signal"
"runtime"
"runtime/pprof"
"strconv"
"strings"
@ -160,6 +161,7 @@ func serve(net, name, secret string) {
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU()*2 + 1)
cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
printf = flag.Bool("print", false, "print replies")
compress = flag.Bool("compress", false, "compress replies")

View File

@ -167,15 +167,11 @@ func ListenAndServe(addr string, network string, handler Handler) error {
func (mux *ServeMux) match(q string, t uint16) Handler {
mux.m.RLock()
defer mux.m.RUnlock()
var (
handler Handler
lastdot int = -1
lastbyte byte
seendot bool = true
)
for i := 0; i < len(q); i++ {
if seendot {
if h, ok := mux.z[q[lastdot+1:]]; ok {
var handler Handler
off := 0
end := false
for {
if h, ok := mux.z[q[off:]]; ok {
if t != TypeDS {
return h
} else {
@ -183,15 +179,10 @@ func (mux *ServeMux) match(q string, t uint16) Handler {
handler = h
}
}
off, end = NextLabel(q, off)
if end {
break
}
if q[i] == '.' && lastbyte != '\\' {
lastdot = i
seendot = true
} else {
seendot = false
}
lastbyte = q[i]
}
// Wildcard match, if we have found nothing try the root zone as a last resort.
if h, ok := mux.z["."]; ok {