From 3087c54a155faa2649ab72a92e5a901275d8bffd Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Tue, 23 Apr 2019 19:26:51 +0300 Subject: [PATCH 1/2] - app: don't print filter update error messages on first launch before DNS server is set up --- filter.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/filter.go b/filter.go index e6e43334..1a4671b2 100644 --- a/filter.go +++ b/filter.go @@ -178,6 +178,10 @@ func periodicallyRefreshFilters() { func refreshFiltersIfNecessary(force bool) int { var updateFilters []filter + if config.firstRun { + return 0 + } + config.RLock() for i := range config.Filters { f := &config.Filters[i] // otherwise we will be operating on a copy From 528c1a72cac331f08de5fdee4538529c70dff1bb Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Tue, 23 Apr 2019 19:37:14 +0300 Subject: [PATCH 2/2] - use 127.0.0.1 as a resolver address when DNS binding address is 0.0.0.0 --- dns.go | 6 +++++- helpers.go | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dns.go b/dns.go index b135babf..c37f9770 100644 --- a/dns.go +++ b/dns.go @@ -50,7 +50,11 @@ func generateServerConfig() dnsforward.ServerConfig { FilteringConfig: config.DNS.FilteringConfig, Filters: filters, } - newconfig.ResolverAddress = fmt.Sprintf("%s:%d", config.DNS.BindHost, config.DNS.Port) + bindhost := config.DNS.BindHost + if config.DNS.BindHost == "0.0.0.0" { + bindhost = "127.0.0.1" + } + newconfig.ResolverAddress = fmt.Sprintf("%s:%d", bindhost, config.DNS.Port) if config.TLS.Enabled { newconfig.TLSConfig = config.TLS.TLSConfig diff --git a/helpers.go b/helpers.go index e4bb0d10..33cf7a62 100644 --- a/helpers.go +++ b/helpers.go @@ -323,7 +323,11 @@ func customDialContext(ctx context.Context, network, addr string) (net.Conn, err return con, err } - resolverAddr := fmt.Sprintf("%s:%d", config.DNS.BindHost, config.DNS.Port) + bindhost := config.DNS.BindHost + if config.DNS.BindHost == "0.0.0.0" { + bindhost = "127.0.0.1" + } + resolverAddr := fmt.Sprintf("%s:%d", bindhost, config.DNS.Port) r := upstream.NewResolver(resolverAddr, 30*time.Second) addrs, e := r.LookupIPAddr(ctx, host) log.Tracef("LookupIPAddr: %s: %v", host, addrs)