From fb58749c58e07d819743e8cb1a31dce56423d91a Mon Sep 17 00:00:00 2001 From: bloved Date: Sun, 24 Jan 2021 10:51:01 +0100 Subject: [PATCH] - network down is ignored if the selected configuration is local responder --- 01.conf.go | 7 +++++-- dns_client.go | 3 ++- dns_handler.go | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/01.conf.go b/01.conf.go index c0d788e..e3060d2 100644 --- a/01.conf.go +++ b/01.conf.go @@ -13,10 +13,13 @@ import ( "github.com/miekg/dns" ) +var localresponderConfigName string + type stringarray []string type urlsMap map[string]stringarray func init() { + localresponderConfigName = "__localresponder__" var MyConfRaw interface{} file, err := ioutil.ReadFile("config.json") @@ -248,7 +251,7 @@ func init() { } //************************ - // Local responser section + // Local responder section //************************ if MyConf["localresponder"] != nil { localresponder := MyConf["localresponder"].(map[string]interface{}) @@ -258,7 +261,7 @@ func init() { ZabovLocalResponder = localresponder["responder"].(string) if len(ZabovLocalResponder) > 0 { local := ZabovConfig{ZabovDNSArray: []string{ZabovLocalResponder}, references: 1} - ZabovConfigs["__localresponder__"] = &local + ZabovConfigs[localresponderConfigName] = &local fmt.Println("ZabovLocalResponder:", ZabovLocalResponder) } } diff --git a/dns_client.go b/dns_client.go index a6c7849..a9707f4 100644 --- a/dns_client.go +++ b/dns_client.go @@ -42,7 +42,8 @@ func ForwardQuery(query *dns.Msg, config string, nocache bool) *dns.Msg { for { // round robin with retry - if !NetworkUp { + // local responder should always be available also if no internet connection + if !NetworkUp && localresponderConfigName != config { time.Sleep(10 * time.Second) go incrementStats("Network Problems ", 1) continue diff --git a/dns_handler.go b/dns_handler.go index 12c6801..c7e0353 100644 --- a/dns_handler.go +++ b/dns_handler.go @@ -269,7 +269,7 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) { if len(ZabovLocalResponder) > 0 { if !strings.Contains(fqdn, ".") || (len(ZabovLocalDomain) > 0 && strings.HasSuffix(fqdn, ZabovLocalDomain)) { - config = "__localresponder__" + config = localresponderConfigName ret := ForwardQuery(r, config, true) w.WriteMsg(ret) go logQuery(remIP, fqdn, QType, config, timetable, "localresponder") @@ -297,7 +297,7 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) { if len(ZabovLocalResponder) > 0 { // if set use local responder for reverse lookup (suffix ".in-addr.arpa.") - config = "__localresponder__" + config = localresponderConfigName } ret := ForwardQuery(r, config, true) w.WriteMsg(ret)