sacrebleu-dns/core/handleDnsRequest.go

37 lines
775 B
Go
Raw Normal View History

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