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" "log"
"os" "os"
"os/signal" "os/signal"
"runtime"
"syscall" "syscall"
) )
@ -45,6 +46,17 @@ func NewRR(s string) dns.RR {
} }
func main() { 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() { go func() {
err := dns.ListenAndServe(":8053", "tcp", nil) err := dns.ListenAndServe(":8053", "tcp", nil)
if err != nil { if err != nil {
@ -57,18 +69,8 @@ func main() {
log.Fatal("Failed to set tcp listener %s\n", err.Error()) 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) sig := make(chan os.Signal)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
for { for {
select { select {
case s := <-sig: case s := <-sig:

View File

@ -39,6 +39,7 @@ import (
"net" "net"
"os" "os"
"os/signal" "os/signal"
"runtime"
"runtime/pprof" "runtime/pprof"
"strconv" "strconv"
"strings" "strings"
@ -160,6 +161,7 @@ func serve(net, name, secret string) {
} }
func main() { func main() {
runtime.GOMAXPROCS(runtime.NumCPU()*2 + 1)
cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file") cpuprofile := flag.String("cpuprofile", "", "write cpu profile to file")
printf = flag.Bool("print", false, "print replies") printf = flag.Bool("print", false, "print replies")
compress = flag.Bool("compress", false, "compress 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 { func (mux *ServeMux) match(q string, t uint16) Handler {
mux.m.RLock() mux.m.RLock()
defer mux.m.RUnlock() defer mux.m.RUnlock()
var ( var handler Handler
handler Handler off := 0
lastdot int = -1 end := false
lastbyte byte for {
seendot bool = true if h, ok := mux.z[q[off:]]; ok {
)
for i := 0; i < len(q); i++ {
if seendot {
if h, ok := mux.z[q[lastdot+1:]]; ok {
if t != TypeDS { if t != TypeDS {
return h return h
} else { } else {
@ -183,15 +179,10 @@ func (mux *ServeMux) match(q string, t uint16) Handler {
handler = h 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. // Wildcard match, if we have found nothing try the root zone as a last resort.
if h, ok := mux.z["."]; ok { if h, ok := mux.z["."]; ok {