|
|
@ -3,7 +3,7 @@ package main
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
"log"
|
|
|
|
//"log"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -30,7 +30,7 @@ func (r *routers) checkBlacklist(m *dns.Msg) bool {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ip != "" && r.c.blacklistIps.has(ip) {
|
|
|
|
if ip != "" && r.c.blacklistIps.has(ip) {
|
|
|
|
log.Printf("%s is in blacklist.\n", ip)
|
|
|
|
//log.Printf("%s is in blacklist.\n", ip)
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -49,7 +49,7 @@ func (r *routers) query(m *dns.Msg, servers []addr) (*dns.Msg, error) {
|
|
|
|
// query cache
|
|
|
|
// query cache
|
|
|
|
m2 := r.cache.get(m)
|
|
|
|
m2 := r.cache.get(m)
|
|
|
|
if m2 != nil {
|
|
|
|
if m2 != nil {
|
|
|
|
log.Printf("query %s, reply from cache\n", m.Question[0].Name)
|
|
|
|
//log.Printf("query %s, reply from cache\n", m.Question[0].Name)
|
|
|
|
m2.Id = m.Id
|
|
|
|
m2.Id = m.Id
|
|
|
|
return m2, nil
|
|
|
|
return m2, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -66,7 +66,7 @@ func (r *routers) query(m *dns.Msg, servers []addr) (*dns.Msg, error) {
|
|
|
|
up = r.udp
|
|
|
|
up = r.udp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.Printf("query %s use %s:%s\n", m.Question[0].Name, srv.network, srv.addr)
|
|
|
|
//log.Printf("query %s use %s:%s\n", m.Question[0].Name, srv.network, srv.addr)
|
|
|
|
|
|
|
|
|
|
|
|
m1, _, err := up.Exchange(m, srv.addr)
|
|
|
|
m1, _, err := up.Exchange(m, srv.addr)
|
|
|
|
if err == nil && !r.checkBlacklist(m) {
|
|
|
|
if err == nil && !r.checkBlacklist(m) {
|
|
|
@ -77,7 +77,7 @@ func (r *routers) query(m *dns.Msg, servers []addr) (*dns.Msg, error) {
|
|
|
|
return m1, err
|
|
|
|
return m1, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.Println(err)
|
|
|
|
//log.Println(err)
|
|
|
|
lastErr = err
|
|
|
|
lastErr = err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -102,7 +102,7 @@ func (r *routers) ServeDNS(w dns.ResponseWriter, m *dns.Msg) {
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.Println(err)
|
|
|
|
//log.Println(err)
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -110,7 +110,7 @@ func (r *routers) ServeDNS(w dns.ResponseWriter, m *dns.Msg) {
|
|
|
|
// no match or failed, fallback to default
|
|
|
|
// no match or failed, fallback to default
|
|
|
|
m1, err := r.query(m, r.c.servers)
|
|
|
|
m1, err := r.query(m, r.c.servers)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
//log.Println(err)
|
|
|
|
dns.HandleFailed(w, m)
|
|
|
|
dns.HandleFailed(w, m)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
w.WriteMsg(m1)
|
|
|
|
w.WriteMsg(m1)
|
|
|
|