2020-10-08 16:14:07 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/miekg/dns"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (mydns *handler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
|
|
|
|
go incrementStats("TotalQueries", 1)
|
|
|
|
|
|
|
|
remIP, _, e := net.SplitHostPort(w.RemoteAddr().String())
|
|
|
|
if e != nil {
|
2021-01-11 18:04:34 -05:00
|
|
|
go incrementStats("CLIENT ERROR: "+remIP, 1)
|
|
|
|
} else {
|
2020-10-08 16:14:07 -04:00
|
|
|
go incrementStats("CLIENT: "+remIP, 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
msg := dns.Msg{}
|
|
|
|
msg.SetReply(r)
|
|
|
|
|
2021-01-11 18:04:34 -05:00
|
|
|
config := "default" // TODO: get config from client IP & timetable
|
|
|
|
|
2020-10-08 16:14:07 -04:00
|
|
|
switch r.Question[0].Qtype {
|
|
|
|
case dns.TypeA:
|
|
|
|
msg.Authoritative = true
|
|
|
|
domain := msg.Question[0].Name
|
|
|
|
fqdn := strings.TrimRight(domain, ".")
|
|
|
|
|
2021-01-11 18:04:34 -05:00
|
|
|
if domainInKillfile(fqdn, config) {
|
2020-10-08 16:14:07 -04:00
|
|
|
go incrementStats("Killed", 1)
|
|
|
|
|
|
|
|
msg.Answer = append(msg.Answer, &dns.A{
|
|
|
|
Hdr: dns.RR_Header{Name: domain, Rrtype: dns.TypeA, Class: dns.ClassINET, Ttl: 60},
|
|
|
|
A: net.ParseIP(ZabovAddBL),
|
|
|
|
})
|
|
|
|
} else {
|
2021-01-11 18:04:34 -05:00
|
|
|
ret := ForwardQuery(r, config)
|
2020-10-08 16:14:07 -04:00
|
|
|
w.WriteMsg(ret)
|
|
|
|
}
|
|
|
|
default:
|
2021-01-11 18:04:34 -05:00
|
|
|
ret := ForwardQuery(r, config)
|
2020-10-08 16:14:07 -04:00
|
|
|
w.WriteMsg(ret)
|
|
|
|
}
|
|
|
|
w.WriteMsg(&msg)
|
|
|
|
|
|
|
|
}
|