sacrebleu-dns/core/handleDnsRequest.go

37 lines
775 B
Go
Raw Permalink Normal View History

2020-12-13 03:01:04 +00:00
package core
2021-01-02 02:34:54 +00:00
import (
"net"
2021-01-02 02:34:54 +00:00
"github.com/miekg/dns"
"github.com/outout14/sacrebleu-dns/utils"
2021-01-02 02:34:54 +00:00
)
2020-12-13 03:01:04 +00:00
//HandleDNSRequest : Handle the DNS request using miekg/dns
2020-12-14 22:20:24 +00:00
//Requires dns.ReponseWriter and dns.Msg args
func HandleDNSRequest(w dns.ResponseWriter, r *dns.Msg, conf *utils.Conf) {
2020-12-13 03:01:04 +00:00
//dns.Msg object
//Will be passed to the parseQuery() function
m := new(dns.Msg)
m.SetReply(r)
2020-12-14 22:20:24 +00:00
m.Compress = false
2020-12-13 03:01:04 +00:00
ip, _, _ := net.SplitHostPort(w.RemoteAddr().String())
2021-01-02 02:34:54 +00:00
if r.Question[0].Qtype == dns.TypeAXFR {
if utils.XfrAllowed(ip, conf) {
parseAXFR(m)
} else {
m := new(dns.Msg)
m.SetRcode(r, dns.RcodeRefused)
w.WriteMsg(m)
}
2021-01-02 02:34:54 +00:00
} else if r.Opcode == dns.OpcodeQuery { //Only respond to dns queries
2020-12-13 03:01:04 +00:00
parseQuery(m)
}
w.WriteMsg(m) //Write the DNS response
2020-12-13 03:01:04 +00:00
}