Fix as212 server
This commit is contained in:
parent
93c0500dce
commit
baa7ca4a82
|
@ -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:
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Reflect is a small name server which sends back the IP address of its client, the
|
||||
// recursive resolver.
|
||||
// recursive resolver.
|
||||
// When queried for type A (resp. AAAA), it sends back the IPv4 (resp. v6) address.
|
||||
// In the additional section the port number and transport are shown.
|
||||
//
|
||||
//
|
||||
// Basic use pattern:
|
||||
//
|
||||
//
|
||||
// dig @localhost -p 8053 whoami.miek.nl A
|
||||
//
|
||||
// ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2157
|
||||
|
@ -25,9 +25,9 @@
|
|||
// Similar services: whoami.ultradns.net, whoami.akamai.net. Also (but it
|
||||
// is not their normal goal): rs.dns-oarc.net, porttest.dns-oarc.net,
|
||||
// amiopen.openresolvers.org.
|
||||
//
|
||||
//
|
||||
// Original version is from: Stephane Bortzmeyer <stephane+grong@bortzmeyer.org>.
|
||||
//
|
||||
//
|
||||
// Adapted to Go (i.e. completely rewritten) by Miek Gieben <miek@miek.nl>.
|
||||
package main
|
||||
|
||||
|
@ -39,6 +39,7 @@ import (
|
|||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -77,14 +78,14 @@ func handleReflect(w dns.ResponseWriter, r *dns.Msg) {
|
|||
}
|
||||
|
||||
/*
|
||||
if o := r.IsEdns0(); o != nil {
|
||||
for _, s := range o.Option {
|
||||
switch e := s.(type) {
|
||||
case *dns.EDNS0_SUBNET:
|
||||
log.Printf("Edns0 subnet %s", e.Address)
|
||||
if o := r.IsEdns0(); o != nil {
|
||||
for _, s := range o.Option {
|
||||
switch e := s.(type) {
|
||||
case *dns.EDNS0_SUBNET:
|
||||
log.Printf("Edns0 subnet %s", e.Address)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if v4 {
|
||||
|
@ -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")
|
||||
|
|
35
server.go
35
server.go
|
@ -167,31 +167,22 @@ 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 {
|
||||
if t != TypeDS {
|
||||
return h
|
||||
} else {
|
||||
// Continue for DS to see if we have a parent too, if so delegeate to the parent
|
||||
handler = h
|
||||
}
|
||||
var handler Handler
|
||||
off := 0
|
||||
end := false
|
||||
for {
|
||||
if h, ok := mux.z[q[off:]]; ok {
|
||||
if t != TypeDS {
|
||||
return h
|
||||
} else {
|
||||
// Continue for DS to see if we have a parent too, if so delegeate to the parent
|
||||
handler = h
|
||||
}
|
||||
}
|
||||
|
||||
if q[i] == '.' && lastbyte != '\\' {
|
||||
lastdot = i
|
||||
seendot = true
|
||||
} else {
|
||||
seendot = false
|
||||
off, end = NextLabel(q, off)
|
||||
if end {
|
||||
break
|
||||
}
|
||||
lastbyte = q[i]
|
||||
}
|
||||
// Wildcard match, if we have found nothing try the root zone as a last resort.
|
||||
if h, ok := mux.z["."]; ok {
|
||||
|
|
Loading…
Reference in New Issue