mirror of
https://github.com/wweir/sower.git
synced 2024-04-21 12:42:15 +00:00
change dns solution config
This commit is contained in:
+7
-5
@@ -26,14 +26,14 @@ var (
|
||||
|
||||
conf = struct {
|
||||
Remote struct {
|
||||
Type string `default:"sower" usage:"remote proxy protocol, sower/trojan"`
|
||||
Type string `default:"sower" required:"true" usage:"remote proxy protocol, sower/trojan"`
|
||||
Addr string `required:"true" usage:"remote proxy address, eg: proxy.com"`
|
||||
Password string `required:"true" usage:"remote proxy password"`
|
||||
}
|
||||
|
||||
DNS struct {
|
||||
Disable bool `usage:"disable DNS proxy"`
|
||||
Serve string `usage:"dns server ip, default all, eg: 127.0.0.1"`
|
||||
Serve string `default:"127.0.0.1" required:"true" usage:"dns server ip"`
|
||||
Fallback string `default:"223.5.5.5" usage:"fallback dns server"`
|
||||
}
|
||||
Socks5 struct {
|
||||
@@ -90,7 +90,7 @@ func init() {
|
||||
|
||||
func main() {
|
||||
proxtDial := GenProxyDial(conf.Remote.Type, conf.Remote.Addr, conf.Remote.Password)
|
||||
r := router.NewRouter(conf.DNS.Fallback, conf.Router.Country.MMDB, proxtDial)
|
||||
r := router.NewRouter(conf.DNS.Serve, conf.DNS.Fallback, conf.Router.Country.MMDB, proxtDial)
|
||||
r.SetRules(conf.Router.Block.Rules, conf.Router.Direct.Rules, conf.Router.Proxy.Rules,
|
||||
conf.Router.Country.Rules)
|
||||
|
||||
@@ -112,8 +112,10 @@ func main() {
|
||||
}
|
||||
go ServeHTTPS(lnHTTPS, r)
|
||||
|
||||
log.Info().Msg("DNS proxy started")
|
||||
if err := dns.ListenAndServe(conf.DNS.Serve, "udp", r); err != nil {
|
||||
log.Info().
|
||||
Str("ip", conf.DNS.Serve).
|
||||
Msg("DNS proxy started")
|
||||
if err := dns.ListenAndServe(net.JoinHostPort(conf.DNS.Serve, "53"), "udp", r); err != nil {
|
||||
log.Fatal().Err(err).Msg("serve dns")
|
||||
}
|
||||
}()
|
||||
|
||||
+1
-2
@@ -30,8 +30,7 @@ func (r *Router) ServeDNS(w dns.ResponseWriter, req *dns.Msg) {
|
||||
case r.directRule.Match(domain):
|
||||
|
||||
case r.proxyRule.Match(domain):
|
||||
host, _, _ := net.SplitHostPort(w.LocalAddr().String())
|
||||
w.WriteMsg(r.dnsProxyA(domain, net.ParseIP(host), req))
|
||||
w.WriteMsg(r.dnsProxyA(domain, r.dns.serveIP, req))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -33,6 +33,7 @@ type Router struct {
|
||||
|
||||
dns struct {
|
||||
fallbackDNS string
|
||||
serveIP net.IP
|
||||
dns.Client
|
||||
connCh chan *dns.Conn
|
||||
}
|
||||
@@ -43,12 +44,13 @@ type Router struct {
|
||||
}
|
||||
}
|
||||
|
||||
func NewRouter(fallbackDNS, mmdbFile string, proxyDial ProxyDialFn) *Router {
|
||||
func NewRouter(serveIP, fallbackDNS, mmdbFile string, proxyDial ProxyDialFn) *Router {
|
||||
r := Router{
|
||||
ProxyDial: proxyDial,
|
||||
cache: mem.New(time.Hour), // TODO: config
|
||||
}
|
||||
|
||||
r.dns.serveIP = net.ParseIP(serveIP)
|
||||
r.dns.fallbackDNS = fallbackDNS
|
||||
r.dns.connCh = make(chan *dns.Conn, 1)
|
||||
go r.dialDNSConn()
|
||||
|
||||
Reference in New Issue
Block a user