forked from loweel/zabov
- BUG FIX: IP Groups: blank timetable was not allowed; timetable & cfg con now be blank or undefined
- FIX: enable response compression by default to be compatible with bogus DNS clients not understanding responses split to multiple UDP packets (FIX failure of Amazon PrimeVideo on LG WebOS) - new conf-specific setting "cache": allows disabling cache on configuration basis (default: cache is enabled) - updated documentation - added more debug logsremotes/1680050961956510080/tmp_refs/heads/master
parent
4007fd9eea
commit
e5b8fbe53c
18
01.conf.go
18
01.conf.go
|
@ -113,6 +113,11 @@ func init() {
|
||||||
conf.ZabovAddBL = net.ParseIP(confRaw["blackholeip"].(string))
|
conf.ZabovAddBL = net.ParseIP(confRaw["blackholeip"].(string))
|
||||||
conf.ZabovHostsFile = confRaw["hostsfile"].(string)
|
conf.ZabovHostsFile = confRaw["hostsfile"].(string)
|
||||||
|
|
||||||
|
if confRaw["cache"] != nil {
|
||||||
|
conf.ZabovCache = confRaw["cache"].(bool)
|
||||||
|
} else {
|
||||||
|
conf.ZabovCache = true
|
||||||
|
}
|
||||||
conf.ZabovDNSArray = fileByLines(conf.ZabovUpDNS)
|
conf.ZabovDNSArray = fileByLines(conf.ZabovUpDNS)
|
||||||
ZabovConfigs[name] = &conf
|
ZabovConfigs[name] = &conf
|
||||||
|
|
||||||
|
@ -219,8 +224,16 @@ func init() {
|
||||||
}
|
}
|
||||||
groupStruct.ips = append(groupStruct.ips, ip)
|
groupStruct.ips = append(groupStruct.ips, ip)
|
||||||
}
|
}
|
||||||
|
if groupMap["cfg"] != nil {
|
||||||
groupStruct.cfg = groupMap["cfg"].(string)
|
groupStruct.cfg = groupMap["cfg"].(string)
|
||||||
|
}
|
||||||
|
if groupMap["timetable"] != nil {
|
||||||
groupStruct.timetable = groupMap["timetable"].(string)
|
groupStruct.timetable = groupMap["timetable"].(string)
|
||||||
|
}
|
||||||
|
if len(groupStruct.cfg) == 0 && len(groupStruct.timetable) == 0 {
|
||||||
|
log.Println("ip group error: specify cfg or timetable")
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
if len(groupStruct.cfg) > 0 {
|
if len(groupStruct.cfg) > 0 {
|
||||||
refConfig, ok := ZabovConfigs[groupStruct.cfg]
|
refConfig, ok := ZabovConfigs[groupStruct.cfg]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -229,14 +242,17 @@ func init() {
|
||||||
} else {
|
} else {
|
||||||
refConfig.references++
|
refConfig.references++
|
||||||
}
|
}
|
||||||
}
|
|
||||||
fmt.Println("cfg:", groupStruct.cfg)
|
fmt.Println("cfg:", groupStruct.cfg)
|
||||||
|
}
|
||||||
|
if len(groupStruct.timetable) > 0 {
|
||||||
fmt.Println("timetable:", groupStruct.timetable)
|
fmt.Println("timetable:", groupStruct.timetable)
|
||||||
_, ok := ZabovTimetables[groupStruct.timetable]
|
_, ok := ZabovTimetables[groupStruct.timetable]
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Println("inexistent timetable:", groupStruct.timetable)
|
log.Println("inexistent timetable:", groupStruct.timetable)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ZabovIPGroups = append(ZabovIPGroups, groupStruct)
|
ZabovIPGroups = append(ZabovIPGroups, groupStruct)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
19
README.md
19
README.md
|
@ -62,7 +62,8 @@ Minimal config file should look like:
|
||||||
"singlefilters":"./urls-domains.txt",
|
"singlefilters":"./urls-domains.txt",
|
||||||
"doublefilters":"./urls-hosts.txt",
|
"doublefilters":"./urls-hosts.txt",
|
||||||
"blackholeip":"127.0.0.1",
|
"blackholeip":"127.0.0.1",
|
||||||
"hostsfile":"./urls-local.txt"
|
"hostsfile":"./urls-local.txt",
|
||||||
|
"cache":true
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +85,7 @@ configs:
|
||||||
- doublefilters: name of the file, for blacklists following the "doublefilter" schema.(one URL per line)
|
- doublefilters: name of the file, for blacklists following the "doublefilter" schema.(one URL per line)
|
||||||
- blackholeip: IP address to return when the IP is banned. This is because you may want to avoid MX issues, mail loops on localhost, or you have a web server running on localhost
|
- blackholeip: IP address to return when the IP is banned. This is because you may want to avoid MX issues, mail loops on localhost, or you have a web server running on localhost
|
||||||
- hostsfile: path where you keep your local blacklistfile : this is in the format "singlefilter", meaning one domain per line, unlike hosts file.
|
- hostsfile: path where you keep your local blacklistfile : this is in the format "singlefilter", meaning one domain per line, unlike hosts file.
|
||||||
|
- cache: if set to false disable the cache for this configuration. Boolean, defaults true
|
||||||
|
|
||||||
Advanced configuration includes support for multiple configurations based on IP Source and timetables:
|
Advanced configuration includes support for multiple configurations based on IP Source and timetables:
|
||||||
<pre>
|
<pre>
|
||||||
|
@ -104,6 +105,7 @@ Advanced configuration includes support for multiple configurations based on IP
|
||||||
},
|
},
|
||||||
"ipaliases":{
|
"ipaliases":{
|
||||||
"pc8":"192.168.178.29",
|
"pc8":"192.168.178.29",
|
||||||
|
"lg-tv":"192.168.178.10",
|
||||||
"localhost":"127.0.0.1"
|
"localhost":"127.0.0.1"
|
||||||
},
|
},
|
||||||
"ipgroups":[
|
"ipgroups":[
|
||||||
|
@ -111,6 +113,11 @@ Advanced configuration includes support for multiple configurations based on IP
|
||||||
"ips":["localhost", "::1", "192.168.178.30", "192.168.178.31", "pc8"],
|
"ips":["localhost", "::1", "192.168.178.30", "192.168.178.31", "pc8"],
|
||||||
"cfg":"",
|
"cfg":"",
|
||||||
"timetable":"tt_children"
|
"timetable":"tt_children"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ips":["lg-tv"],
|
||||||
|
"cfg":"tv",
|
||||||
|
"timetable":""
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"timetables":{
|
"timetables":{
|
||||||
|
@ -146,6 +153,14 @@ Advanced configuration includes support for multiple configurations based on IP
|
||||||
"doublefilters":"./urls-hosts-restricted.txt",
|
"doublefilters":"./urls-hosts-restricted.txt",
|
||||||
"blackholeip":"127.0.0.1",
|
"blackholeip":"127.0.0.1",
|
||||||
"hostsfile":"./urls-local.txt"
|
"hostsfile":"./urls-local.txt"
|
||||||
|
},
|
||||||
|
"tv":{
|
||||||
|
"upstream":"./dns-upstream.txt",
|
||||||
|
"singlefilters":"",
|
||||||
|
"doublefilters":"",
|
||||||
|
"blackholeip":"127.0.0.1",
|
||||||
|
"hostsfile":"",
|
||||||
|
"cache":false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
@ -14,7 +15,9 @@ import (
|
||||||
//first server to answer wins
|
//first server to answer wins
|
||||||
//accepts config name to select the UP DNS source list
|
//accepts config name to select the UP DNS source list
|
||||||
func ForwardQuery(query *dns.Msg, config string, nocache bool) *dns.Msg {
|
func ForwardQuery(query *dns.Msg, config string, nocache bool) *dns.Msg {
|
||||||
|
if ZabovDebug {
|
||||||
|
log.Println("ForwardQuery: nocache", nocache)
|
||||||
|
}
|
||||||
go incrementStats("ForwardQueries", 1)
|
go incrementStats("ForwardQueries", 1)
|
||||||
|
|
||||||
r := new(dns.Msg)
|
r := new(dns.Msg)
|
||||||
|
@ -29,6 +32,10 @@ func ForwardQuery(query *dns.Msg, config string, nocache bool) *dns.Msg {
|
||||||
go incrementStats("CacheHit", 1)
|
go incrementStats("CacheHit", 1)
|
||||||
cached.SetReply(query)
|
cached.SetReply(query)
|
||||||
cached.Authoritative = true
|
cached.Authoritative = true
|
||||||
|
if ZabovDebug {
|
||||||
|
log.Println("ForwardQuery: CacheHit")
|
||||||
|
}
|
||||||
|
cached.Compress = true
|
||||||
return cached
|
return cached
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -60,7 +67,12 @@ func ForwardQuery(query *dns.Msg, config string, nocache bool) *dns.Msg {
|
||||||
go incrementStats(d, 1)
|
go incrementStats(d, 1)
|
||||||
in.SetReply(query)
|
in.SetReply(query)
|
||||||
in.Authoritative = true
|
in.Authoritative = true
|
||||||
|
in.Compress = true
|
||||||
go DomainCache(lfqdn, in)
|
go DomainCache(lfqdn, in)
|
||||||
|
if ZabovDebug {
|
||||||
|
log.Println("ForwardQuery: OK!")
|
||||||
|
}
|
||||||
|
|
||||||
return in
|
return in
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,7 +287,7 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
||||||
go logQuery(remIP, fqdn, QType, config, timetable, "killed")
|
go logQuery(remIP, fqdn, QType, config, timetable, "killed")
|
||||||
} else {
|
} else {
|
||||||
go logQuery(remIP, fqdn, QType, config, timetable, "forwarded")
|
go logQuery(remIP, fqdn, QType, config, timetable, "forwarded")
|
||||||
ret := ForwardQuery(r, config, false)
|
ret := ForwardQuery(r, config, !ZabovConfig.ZabovCache)
|
||||||
w.WriteMsg(ret)
|
w.WriteMsg(ret)
|
||||||
}
|
}
|
||||||
case dns.TypePTR:
|
case dns.TypePTR:
|
||||||
|
@ -303,7 +303,7 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
||||||
w.WriteMsg(ret)
|
w.WriteMsg(ret)
|
||||||
go logQuery(remIP, msg.Question[0].Name, QType, config, timetable, "localresponder")
|
go logQuery(remIP, msg.Question[0].Name, QType, config, timetable, "localresponder")
|
||||||
default:
|
default:
|
||||||
ret := ForwardQuery(r, config, false)
|
ret := ForwardQuery(r, config, !ZabovConfig.ZabovCache)
|
||||||
w.WriteMsg(ret)
|
w.WriteMsg(ret)
|
||||||
if len(ZabovDebugDBPath) > 0 {
|
if len(ZabovDebugDBPath) > 0 {
|
||||||
go logQuery(remIP, msg.Question[0].Name, QType, config, timetable, "forwarded")
|
go logQuery(remIP, msg.Question[0].Name, QType, config, timetable, "forwarded")
|
||||||
|
|
1
main.go
1
main.go
|
@ -41,6 +41,7 @@ type ZabovConfig struct {
|
||||||
ZabovHostsFile string // json:hostsfile -> ZabovHostsFile is the file we use to keep our hosts
|
ZabovHostsFile string // json:hostsfile -> ZabovHostsFile is the file we use to keep our hosts
|
||||||
ZabovUpDNS string // json:upstream -> ZabovUpDNS keeps the name of upstream DNSs
|
ZabovUpDNS string // json:upstream -> ZabovUpDNS keeps the name of upstream DNSs
|
||||||
ZabovDNSArray []string // contains all the DNS we mention, parsed from ZabovUpDNS file
|
ZabovDNSArray []string // contains all the DNS we mention, parsed from ZabovUpDNS file
|
||||||
|
ZabovCache bool // allows to disable cache
|
||||||
references int // contains references to this config; if zero, config shall be removed
|
references int // contains references to this config; if zero, config shall be removed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue