- network down is ignored if the selected configuration is local responder

pull/2/head
bloved 2021-01-24 10:51:01 +01:00
parent 0752a7e443
commit b9f17b3c19
3 changed files with 9 additions and 5 deletions

View File

@ -13,10 +13,13 @@ import (
"github.com/miekg/dns" "github.com/miekg/dns"
) )
var localresponderConfigName string
type stringarray []string type stringarray []string
type urlsMap map[string]stringarray type urlsMap map[string]stringarray
func init() { func init() {
localresponderConfigName = "__localresponder__"
var MyConfRaw interface{} var MyConfRaw interface{}
file, err := ioutil.ReadFile("config.json") file, err := ioutil.ReadFile("config.json")
@ -248,7 +251,7 @@ func init() {
} }
//************************ //************************
// Local responser section // Local responder section
//************************ //************************
if MyConf["localresponder"] != nil { if MyConf["localresponder"] != nil {
localresponder := MyConf["localresponder"].(map[string]interface{}) localresponder := MyConf["localresponder"].(map[string]interface{})
@ -258,7 +261,7 @@ func init() {
ZabovLocalResponder = localresponder["responder"].(string) ZabovLocalResponder = localresponder["responder"].(string)
if len(ZabovLocalResponder) > 0 { if len(ZabovLocalResponder) > 0 {
local := ZabovConfig{ZabovDNSArray: []string{ZabovLocalResponder}, references: 1} local := ZabovConfig{ZabovDNSArray: []string{ZabovLocalResponder}, references: 1}
ZabovConfigs["__localresponder__"] = &local ZabovConfigs[localresponderConfigName] = &local
fmt.Println("ZabovLocalResponder:", ZabovLocalResponder) fmt.Println("ZabovLocalResponder:", ZabovLocalResponder)
} }
} }

View File

@ -42,7 +42,8 @@ func ForwardQuery(query *dns.Msg, config string, nocache bool) *dns.Msg {
for { for {
// round robin with retry // 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) time.Sleep(10 * time.Second)
go incrementStats("Network Problems ", 1) go incrementStats("Network Problems ", 1)
continue continue

View File

@ -269,7 +269,7 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
if len(ZabovLocalResponder) > 0 { if len(ZabovLocalResponder) > 0 {
if !strings.Contains(fqdn, ".") || if !strings.Contains(fqdn, ".") ||
(len(ZabovLocalDomain) > 0 && strings.HasSuffix(fqdn, ZabovLocalDomain)) { (len(ZabovLocalDomain) > 0 && strings.HasSuffix(fqdn, ZabovLocalDomain)) {
config = "__localresponder__" config = localresponderConfigName
ret := ForwardQuery(r, config, true) ret := ForwardQuery(r, config, true)
w.WriteMsg(ret) w.WriteMsg(ret)
go logQuery(remIP, fqdn, QType, config, timetable, "localresponder") 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 len(ZabovLocalResponder) > 0 {
// if set use local responder for reverse lookup (suffix ".in-addr.arpa.") // if set use local responder for reverse lookup (suffix ".in-addr.arpa.")
config = "__localresponder__" config = localresponderConfigName
} }
ret := ForwardQuery(r, config, true) ret := ForwardQuery(r, config, true)
w.WriteMsg(ret) w.WriteMsg(ret)