You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Kv map[string]int
|
|
|
|
|
|
|
|
type UpstreamServer struct {
|
|
|
|
domains Kv
|
|
|
|
Proto string
|
|
|
|
Addr string
|
|
|
|
client *dns.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func (srv *UpstreamServer) match(d string) bool {
|
|
|
|
if srv.domains == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
s := strings.Split(strings.Trim(d, "."), ".")
|
|
|
|
for i := 0; i < len(s); i++ {
|
|
|
|
s1 := strings.Join(s[i:], ".")
|
|
|
|
if _, ok := srv.domains[s1]; ok {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (srv *UpstreamServer) query(req *dns.Msg) (*dns.Msg, error) {
|
|
|
|
res, _, err := srv.client.Exchange(req, srv.Addr)
|
|
|
|
return res, err
|
|
|
|
}
|