From 9b4e4fbcb970ce2da476e6b92eab07875bc01459 Mon Sep 17 00:00:00 2001 From: bloved Date: Mon, 25 Jan 2021 17:00:34 +0100 Subject: [PATCH] - optimization: blackholeip is parsed only once at startup --- 01.conf.go | 2 +- dns_handler.go | 2 +- main.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/01.conf.go b/01.conf.go index e3060d2..35b3cb3 100644 --- a/01.conf.go +++ b/01.conf.go @@ -110,7 +110,7 @@ func init() { conf.ZabovUpDNS = confRaw["upstream"].(string) conf.ZabovSingleBL = confRaw["singlefilters"].(string) conf.ZabovDoubleBL = confRaw["doublefilters"].(string) - conf.ZabovAddBL = confRaw["blackholeip"].(string) + conf.ZabovAddBL = net.ParseIP(confRaw["blackholeip"].(string)) conf.ZabovHostsFile = confRaw["hostsfile"].(string) conf.ZabovDNSArray = fileByLines(conf.ZabovUpDNS) diff --git a/dns_handler.go b/dns_handler.go index c7e0353..8a66673 100644 --- a/dns_handler.go +++ b/dns_handler.go @@ -282,7 +282,7 @@ func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) { msg.Answer = append(msg.Answer, &dns.A{ Hdr: dns.RR_Header{Name: domain, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 60}, - A: net.ParseIP(ZabovConfig.ZabovAddBL), + A: ZabovConfig.ZabovAddBL, }) go logQuery(remIP, fqdn, QType, config, timetable, "killed") } else { diff --git a/main.go b/main.go index 3f778ce..f1de1ab 100644 --- a/main.go +++ b/main.go @@ -37,7 +37,7 @@ type handler struct{} type ZabovConfig struct { ZabovSingleBL string // json:singlefilters -> ZabovSingleBL list of urls returning a file with just names of domains ZabovDoubleBL string // json:doublefilters -> ZabovDoubleBL list of urls returning a file with IPdomain - ZabovAddBL string // json:blackholeip -> ZabovAddBL is the IP we want to send all the clients to. Usually is 127.0.0.1 + ZabovAddBL net.IP // json:blackholeip -> ZabovAddBL is the IP we want to send all the clients to. Usually is 127.0.0.1 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 ZabovDNSArray []string // contains all the DNS we mention, parsed from ZabovUpDNS file