|
|
@ -1,6 +1,7 @@
|
|
|
|
package main
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"errors"
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
@ -14,7 +15,7 @@ type routers struct {
|
|
|
|
cache *cache
|
|
|
|
cache *cache
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (r routers) checkBlacklist(m *dns.Msg) bool {
|
|
|
|
func (r *routers) checkBlacklist(m *dns.Msg) bool {
|
|
|
|
if m.Rcode != dns.RcodeSuccess {
|
|
|
|
if m.Rcode != dns.RcodeSuccess {
|
|
|
|
// not success, not in blacklist
|
|
|
|
// not success, not in blacklist
|
|
|
|
return false
|
|
|
|
return false
|
|
|
@ -37,7 +38,7 @@ func (r routers) checkBlacklist(m *dns.Msg) bool {
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (r routers) query(m *dns.Msg, servers []addr) (*dns.Msg, error) {
|
|
|
|
func (r *routers) query(m *dns.Msg, servers []addr) (*dns.Msg, error) {
|
|
|
|
var up *dns.Client
|
|
|
|
var up *dns.Client
|
|
|
|
var lastErr error
|
|
|
|
var lastErr error
|
|
|
|
|
|
|
|
|
|
|
@ -74,12 +75,17 @@ func (r routers) query(m *dns.Msg, servers []addr) (*dns.Msg, error) {
|
|
|
|
lastErr = err
|
|
|
|
lastErr = err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if lastErr == nil {
|
|
|
|
|
|
|
|
// this happens when ip in blacklist
|
|
|
|
|
|
|
|
lastErr = errors.New("timeout")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// return last error
|
|
|
|
// return last error
|
|
|
|
return nil, lastErr
|
|
|
|
return nil, lastErr
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ServeDNS implements dns.Handler interface
|
|
|
|
// ServeDNS implements dns.Handler interface
|
|
|
|
func (r routers) ServeDNS(w dns.ResponseWriter, m *dns.Msg) {
|
|
|
|
func (r *routers) ServeDNS(w dns.ResponseWriter, m *dns.Msg) {
|
|
|
|
domain := m.Question[0].Name
|
|
|
|
domain := m.Question[0].Name
|
|
|
|
d := strings.Trim(domain, ".")
|
|
|
|
d := strings.Trim(domain, ".")
|
|
|
|
for _, rule := range r.c.Rules {
|
|
|
|
for _, rule := range r.c.Rules {
|
|
|
|