2018-02-23 15:02:05 +00:00
|
|
|
// Package request abstracts a client's request so that all plugins will handle them in an unified way.
|
2016-09-07 11:10:16 +01:00
|
|
|
package request
|
2016-03-18 20:57:35 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net"
|
|
|
|
|
"strings"
|
2016-09-07 11:10:16 +01:00
|
|
|
|
2017-09-14 09:36:06 +01:00
|
|
|
"github.com/coredns/coredns/plugin/pkg/edns"
|
2016-03-18 20:57:35 +00:00
|
|
|
|
|
|
|
|
"github.com/miekg/dns"
|
2018-02-14 15:11:26 -05:00
|
|
|
"golang.org/x/net/context"
|
2016-03-18 20:57:35 +00:00
|
|
|
)
|
|
|
|
|
|
2017-09-14 09:36:06 +01:00
|
|
|
// Request contains some connection state and is useful in plugin.
|
2016-09-07 11:10:16 +01:00
|
|
|
type Request struct {
|
2016-04-04 08:19:06 +01:00
|
|
|
Req *dns.Msg
|
|
|
|
|
W dns.ResponseWriter
|
|
|
|
|
|
2017-08-08 04:23:16 -07:00
|
|
|
// Optional lowercased zone of this query.
|
|
|
|
|
Zone string
|
|
|
|
|
|
2018-02-14 15:11:26 -05:00
|
|
|
Context context.Context
|
|
|
|
|
|
2016-04-26 17:57:11 +01:00
|
|
|
// Cache size after first call to Size or Do.
|
2016-04-04 08:19:06 +01:00
|
|
|
size int
|
2018-03-31 17:22:24 +01:00
|
|
|
do *bool // nil: nothing, otherwise *do value
|
2016-10-02 17:23:25 +01:00
|
|
|
// TODO(miek): opt record itself as well?
|
2016-04-26 17:57:11 +01:00
|
|
|
|
2016-10-02 17:23:25 +01:00
|
|
|
// Cache lowercase qname.
|
2016-04-26 17:57:11 +01:00
|
|
|
name string
|
2016-03-18 20:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-07 11:10:16 +01:00
|
|
|
// NewWithQuestion returns a new request based on the old, but with a new question
|
|
|
|
|
// section in the request.
|
|
|
|
|
func (r *Request) NewWithQuestion(name string, typ uint16) Request {
|
|
|
|
|
req1 := Request{W: r.W, Req: r.Req.Copy()}
|
2017-07-11 18:05:32 -04:00
|
|
|
req1.Req.Question[0] = dns.Question{Name: dns.Fqdn(name), Qclass: dns.ClassINET, Qtype: typ}
|
2016-09-07 11:10:16 +01:00
|
|
|
return req1
|
|
|
|
|
}
|
2016-03-18 20:57:35 +00:00
|
|
|
|
|
|
|
|
// IP gets the (remote) IP address of the client making the request.
|
2016-09-07 11:10:16 +01:00
|
|
|
func (r *Request) IP() string {
|
|
|
|
|
ip, _, err := net.SplitHostPort(r.W.RemoteAddr().String())
|
2016-03-18 20:57:35 +00:00
|
|
|
if err != nil {
|
2016-09-07 11:10:16 +01:00
|
|
|
return r.W.RemoteAddr().String()
|
2016-03-18 20:57:35 +00:00
|
|
|
}
|
|
|
|
|
return ip
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 17:01:19 +01:00
|
|
|
// Port gets the (remote) Port of the client making the request.
|
2016-09-07 11:10:16 +01:00
|
|
|
func (r *Request) Port() string {
|
|
|
|
|
_, port, err := net.SplitHostPort(r.W.RemoteAddr().String())
|
2016-03-18 20:57:35 +00:00
|
|
|
if err != nil {
|
2016-09-07 11:10:16 +01:00
|
|
|
return "0"
|
2016-03-18 20:57:35 +00:00
|
|
|
}
|
2016-09-07 11:10:16 +01:00
|
|
|
return port
|
2016-03-18 20:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-07 07:42:58 +01:00
|
|
|
// RemoteAddr returns the net.Addr of the client that sent the current request.
|
2016-09-07 11:10:16 +01:00
|
|
|
func (r *Request) RemoteAddr() string {
|
|
|
|
|
return r.W.RemoteAddr().String()
|
2016-04-07 07:42:58 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-30 15:54:41 +01:00
|
|
|
// Proto gets the protocol used as the transport. This will be udp or tcp.
|
2016-09-07 11:10:16 +01:00
|
|
|
func (r *Request) Proto() string { return Proto(r.W) }
|
2016-04-30 15:54:41 +01:00
|
|
|
|
|
|
|
|
// Proto gets the protocol used as the transport. This will be udp or tcp.
|
|
|
|
|
func Proto(w dns.ResponseWriter) string {
|
2016-09-21 17:01:19 +01:00
|
|
|
// FIXME(miek): why not a method on Request
|
2016-04-30 15:54:41 +01:00
|
|
|
if _, ok := w.RemoteAddr().(*net.UDPAddr); ok {
|
2016-03-18 20:57:35 +00:00
|
|
|
return "udp"
|
|
|
|
|
}
|
2016-04-30 15:54:41 +01:00
|
|
|
if _, ok := w.RemoteAddr().(*net.TCPAddr); ok {
|
2016-03-18 20:57:35 +00:00
|
|
|
return "tcp"
|
|
|
|
|
}
|
|
|
|
|
return "udp"
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-07 11:10:16 +01:00
|
|
|
// Family returns the family of the transport, 1 for IPv4 and 2 for IPv6.
|
|
|
|
|
func (r *Request) Family() int {
|
2016-03-18 20:57:35 +00:00
|
|
|
var a net.IP
|
2016-09-07 11:10:16 +01:00
|
|
|
ip := r.W.RemoteAddr()
|
2016-03-18 20:57:35 +00:00
|
|
|
if i, ok := ip.(*net.UDPAddr); ok {
|
|
|
|
|
a = i.IP
|
|
|
|
|
}
|
|
|
|
|
if i, ok := ip.(*net.TCPAddr); ok {
|
|
|
|
|
a = i.IP
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if a.To4() != nil {
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
return 2
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-20 21:36:55 +00:00
|
|
|
// Do returns if the request has the DO (DNSSEC OK) bit set.
|
2016-09-07 11:10:16 +01:00
|
|
|
func (r *Request) Do() bool {
|
2018-03-31 17:22:24 +01:00
|
|
|
if r.do != nil {
|
|
|
|
|
return *r.do
|
2016-04-04 08:19:06 +01:00
|
|
|
}
|
|
|
|
|
|
2018-03-31 17:22:24 +01:00
|
|
|
r.do = new(bool)
|
|
|
|
|
|
2016-09-07 11:10:16 +01:00
|
|
|
if o := r.Req.IsEdns0(); o != nil {
|
2018-03-31 17:22:24 +01:00
|
|
|
*r.do = o.Do()
|
|
|
|
|
return *r.do
|
2016-03-20 21:36:55 +00:00
|
|
|
}
|
2018-03-31 17:22:24 +01:00
|
|
|
*r.do = false
|
2016-03-20 21:36:55 +00:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-29 11:02:43 +00:00
|
|
|
// Len returns the length in bytes in the request.
|
|
|
|
|
func (r *Request) Len() int { return r.Req.Len() }
|
|
|
|
|
|
|
|
|
|
// Size returns if buffer size *advertised* in the requests OPT record.
|
2016-03-20 21:36:55 +00:00
|
|
|
// Or when the request was over TCP, we return the maximum allowed size of 64K.
|
2016-09-07 11:10:16 +01:00
|
|
|
func (r *Request) Size() int {
|
|
|
|
|
if r.size != 0 {
|
|
|
|
|
return r.size
|
2016-04-04 08:19:06 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-09 16:17:53 +01:00
|
|
|
size := 0
|
2016-09-07 11:10:16 +01:00
|
|
|
if o := r.Req.IsEdns0(); o != nil {
|
2018-03-31 17:22:24 +01:00
|
|
|
if r.do == nil {
|
|
|
|
|
r.do = new(bool)
|
2016-03-20 21:36:55 +00:00
|
|
|
}
|
2018-03-31 17:22:24 +01:00
|
|
|
*r.do = o.Do()
|
2016-04-09 16:17:53 +01:00
|
|
|
size = int(o.UDPSize())
|
2016-03-20 21:36:55 +00:00
|
|
|
}
|
2018-03-31 17:22:24 +01:00
|
|
|
|
2016-09-07 11:10:16 +01:00
|
|
|
size = edns.Size(r.Proto(), size)
|
|
|
|
|
r.size = size
|
2016-04-09 16:17:53 +01:00
|
|
|
return size
|
2016-03-20 21:36:55 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-07 11:10:16 +01:00
|
|
|
// SizeAndDo adds an OPT record that the reflects the intent from request.
|
2016-04-12 21:30:08 +01:00
|
|
|
// The returned bool indicated if an record was found and normalised.
|
2016-09-07 11:10:16 +01:00
|
|
|
func (r *Request) SizeAndDo(m *dns.Msg) bool {
|
|
|
|
|
o := r.Req.IsEdns0() // TODO(miek): speed this up
|
2016-04-09 16:17:53 +01:00
|
|
|
if o == nil {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2016-10-02 17:23:25 +01:00
|
|
|
|
|
|
|
|
odo := o.Do()
|
|
|
|
|
|
2016-04-12 21:30:08 +01:00
|
|
|
if mo := m.IsEdns0(); mo != nil {
|
|
|
|
|
mo.Hdr.Name = "."
|
|
|
|
|
mo.Hdr.Rrtype = dns.TypeOPT
|
|
|
|
|
mo.SetVersion(0)
|
|
|
|
|
mo.SetUDPSize(o.UDPSize())
|
2016-10-02 17:23:25 +01:00
|
|
|
mo.Hdr.Ttl &= 0xff00 // clear flags
|
|
|
|
|
|
|
|
|
|
if odo {
|
2016-04-12 21:30:08 +01:00
|
|
|
mo.SetDo()
|
|
|
|
|
}
|
|
|
|
|
return true
|
2016-03-25 17:23:06 +00:00
|
|
|
}
|
2016-10-02 17:23:25 +01:00
|
|
|
|
|
|
|
|
o.Hdr.Name = "."
|
|
|
|
|
o.Hdr.Rrtype = dns.TypeOPT
|
|
|
|
|
o.SetVersion(0)
|
|
|
|
|
o.Hdr.Ttl &= 0xff00 // clear flags
|
|
|
|
|
|
|
|
|
|
if odo {
|
|
|
|
|
o.SetDo()
|
|
|
|
|
}
|
2016-04-09 16:17:53 +01:00
|
|
|
m.Extra = append(m.Extra, o)
|
|
|
|
|
return true
|
2016-03-18 20:57:35 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-04 09:10:07 +00:00
|
|
|
// Result is the result of Scrub.
|
2016-03-26 09:26:54 +00:00
|
|
|
type Result int
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
// ScrubIgnored is returned when Scrub did nothing to the message.
|
|
|
|
|
ScrubIgnored Result = iota
|
2018-02-21 21:13:41 +00:00
|
|
|
// ScrubExtra is returned when the reply has been scrubbed by removing RRs from the additional section.
|
|
|
|
|
ScrubExtra
|
|
|
|
|
// ScrubAnswer is returned when the reply has been scrubbed by removing RRs from the answer section.
|
|
|
|
|
ScrubAnswer
|
2016-03-26 09:26:54 +00:00
|
|
|
)
|
|
|
|
|
|
2018-05-01 21:04:06 +01:00
|
|
|
// Scrub scrubs the reply message so that it will fit the client's buffer. It will first
|
|
|
|
|
// check if the reply fits without compression and then *with* compression.
|
|
|
|
|
// Scrub will then use binary search to find a save cut off point in the additional section.
|
2018-02-21 21:13:41 +00:00
|
|
|
// If even *without* the additional section the reply still doesn't fit we
|
|
|
|
|
// repeat this process for the answer section. If we scrub the answer section
|
|
|
|
|
// we set the TC bit on the reply; indicating the client should retry over TCP.
|
|
|
|
|
// Note, the TC bit will be set regardless of protocol, even TCP message will
|
|
|
|
|
// get the bit, the client should then retry with pigeons.
|
2016-09-07 11:10:16 +01:00
|
|
|
func (r *Request) Scrub(reply *dns.Msg) (*dns.Msg, Result) {
|
|
|
|
|
size := r.Size()
|
2018-05-01 21:04:06 +01:00
|
|
|
|
|
|
|
|
reply.Compress = false
|
2018-02-21 21:13:41 +00:00
|
|
|
rl := reply.Len()
|
2018-05-01 21:04:06 +01:00
|
|
|
if size >= rl {
|
|
|
|
|
return reply, ScrubIgnored
|
|
|
|
|
}
|
2018-02-21 21:13:41 +00:00
|
|
|
|
2018-05-01 21:04:06 +01:00
|
|
|
reply.Compress = true
|
|
|
|
|
rl = reply.Len()
|
2018-02-21 21:13:41 +00:00
|
|
|
if size >= rl {
|
2016-03-26 09:26:54 +00:00
|
|
|
return reply, ScrubIgnored
|
|
|
|
|
}
|
2016-04-09 16:17:53 +01:00
|
|
|
|
2018-03-24 11:50:55 +00:00
|
|
|
// Account for the OPT record that gets added in SizeAndDo(), subtract that length.
|
|
|
|
|
sub := 0
|
|
|
|
|
if r.Do() {
|
|
|
|
|
sub = optLen
|
|
|
|
|
}
|
2018-02-21 21:13:41 +00:00
|
|
|
origExtra := reply.Extra
|
2018-03-24 11:50:55 +00:00
|
|
|
re := len(reply.Extra) - sub
|
2018-02-21 21:13:41 +00:00
|
|
|
l, m := 0, 0
|
|
|
|
|
for l < re {
|
|
|
|
|
m = (l + re) / 2
|
|
|
|
|
reply.Extra = origExtra[:m]
|
|
|
|
|
rl = reply.Len()
|
|
|
|
|
if rl < size {
|
|
|
|
|
l = m + 1
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if rl > size {
|
|
|
|
|
re = m - 1
|
|
|
|
|
continue
|
|
|
|
|
}
|
2018-03-23 17:59:06 +01:00
|
|
|
if rl == size {
|
|
|
|
|
break
|
|
|
|
|
}
|
2018-02-21 21:13:41 +00:00
|
|
|
}
|
2018-03-24 11:50:55 +00:00
|
|
|
|
|
|
|
|
// We may come out of this loop with one rotation too many, m makes it too large, but m-1 works.
|
2018-02-21 21:13:41 +00:00
|
|
|
if rl > size && m > 0 {
|
|
|
|
|
reply.Extra = origExtra[:m-1]
|
|
|
|
|
rl = reply.Len()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if rl < size {
|
|
|
|
|
r.SizeAndDo(reply)
|
|
|
|
|
return reply, ScrubExtra
|
2016-03-26 09:26:54 +00:00
|
|
|
}
|
2018-01-24 14:28:26 +01:00
|
|
|
|
2018-02-21 21:13:41 +00:00
|
|
|
origAnswer := reply.Answer
|
|
|
|
|
ra := len(reply.Answer)
|
|
|
|
|
l, m = 0, 0
|
|
|
|
|
for l < ra {
|
|
|
|
|
m = (l + ra) / 2
|
|
|
|
|
reply.Answer = origAnswer[:m]
|
|
|
|
|
rl = reply.Len()
|
|
|
|
|
if rl < size {
|
|
|
|
|
l = m + 1
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if rl > size {
|
|
|
|
|
ra = m - 1
|
|
|
|
|
continue
|
|
|
|
|
}
|
2018-03-23 17:59:06 +01:00
|
|
|
if rl == size {
|
|
|
|
|
break
|
|
|
|
|
}
|
2018-02-21 21:13:41 +00:00
|
|
|
}
|
2018-03-24 11:50:55 +00:00
|
|
|
|
|
|
|
|
// We may come out of this loop with one rotation too many, m makes it too large, but m-1 works.
|
2018-02-21 21:13:41 +00:00
|
|
|
if rl > size && m > 0 {
|
|
|
|
|
reply.Answer = origAnswer[:m-1]
|
|
|
|
|
// No need to recalc length, as we don't use it. We set truncated anyway. Doing
|
|
|
|
|
// this extra m-1 step does make it fit in the client's buffer however.
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-24 11:50:55 +00:00
|
|
|
// It now fits, but Truncated. We can't call sizeAndDo() because that adds a new record (OPT)
|
|
|
|
|
// in the additional section.
|
2016-03-26 09:26:54 +00:00
|
|
|
reply.Truncated = true
|
2018-02-21 21:13:41 +00:00
|
|
|
return reply, ScrubAnswer
|
2016-03-26 09:26:54 +00:00
|
|
|
}
|
|
|
|
|
|
2017-08-31 16:24:11 +02:00
|
|
|
// Type returns the type of the question as a string. If the request is malformed
|
|
|
|
|
// the empty string is returned.
|
|
|
|
|
func (r *Request) Type() string {
|
|
|
|
|
if r.Req == nil {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
if len(r.Req.Question) == 0 {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
2016-03-25 17:23:06 +00:00
|
|
|
|
2017-08-31 16:24:11 +02:00
|
|
|
return dns.Type(r.Req.Question[0].Qtype).String()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// QType returns the type of the question as an uint16. If the request is malformed
|
|
|
|
|
// 0 is returned.
|
|
|
|
|
func (r *Request) QType() uint16 {
|
|
|
|
|
if r.Req == nil {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
if len(r.Req.Question) == 0 {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r.Req.Question[0].Qtype
|
|
|
|
|
}
|
2016-03-18 20:57:35 +00:00
|
|
|
|
|
|
|
|
// Name returns the name of the question in the request. Note
|
Allow debug queries to etcd middleware (#150)
With this you can retreive the raw data that the etcd middleware
used to create the reply. The debug data is put in TXT records
that are stuffed in the CH classs. This is only enabled if you
specify `debug` in the etcd stanza.
You can retrieve it by prefixing your query with 'o-o.debug.'
For instance:
; <<>> DiG 9.10.3-P4-Ubuntu <<>> @localhost -p 1053 SRV o-o.debug.production.*.skydns.local
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 47798
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 3
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;o-o.debug.production.*.skydns.local. IN SRV
;; ANSWER SECTION:
production.*.skydns.local. 154 IN SRV 10 50 8080 service1.example.com.
production.*.skydns.local. 154 IN SRV 10 50 8080 service2.example.com.
;; ADDITIONAL SECTION:
skydns.local.skydns.east.production.rails.1. 154 CH TXT "service1.example.com:8080(10,0,,false)[0,]"
skydns.local.skydns.west.production.rails.2. 154 CH TXT "service2.example.com:8080(10,0,,false)[0,]"
2016-05-22 21:16:26 +01:00
|
|
|
// this name will always have a closing dot and will be lower cased. After a call Name
|
|
|
|
|
// the value will be cached. To clear this caching call Clear.
|
2017-08-31 16:24:11 +02:00
|
|
|
// If the request is malformed the root zone is returned.
|
2016-09-07 11:10:16 +01:00
|
|
|
func (r *Request) Name() string {
|
|
|
|
|
if r.name != "" {
|
|
|
|
|
return r.name
|
2016-04-26 17:57:11 +01:00
|
|
|
}
|
2017-08-31 16:24:11 +02:00
|
|
|
if r.Req == nil {
|
|
|
|
|
r.name = "."
|
|
|
|
|
return "."
|
|
|
|
|
}
|
|
|
|
|
if len(r.Req.Question) == 0 {
|
|
|
|
|
r.name = "."
|
|
|
|
|
return "."
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-07 11:10:16 +01:00
|
|
|
r.name = strings.ToLower(dns.Name(r.Req.Question[0].Name).String())
|
|
|
|
|
return r.name
|
2016-04-26 17:57:11 +01:00
|
|
|
}
|
2016-03-18 20:57:35 +00:00
|
|
|
|
|
|
|
|
// QName returns the name of the question in the request.
|
2017-08-31 16:24:11 +02:00
|
|
|
// If the request is malformed the root zone is returned.
|
|
|
|
|
func (r *Request) QName() string {
|
|
|
|
|
if r.Req == nil {
|
|
|
|
|
return "."
|
|
|
|
|
}
|
|
|
|
|
if len(r.Req.Question) == 0 {
|
|
|
|
|
return "."
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dns.Name(r.Req.Question[0].Name).String()
|
|
|
|
|
}
|
2016-03-18 20:57:35 +00:00
|
|
|
|
|
|
|
|
// Class returns the class of the question in the request.
|
2017-08-31 16:24:11 +02:00
|
|
|
// If the request is malformed the empty string is returned.
|
|
|
|
|
func (r *Request) Class() string {
|
|
|
|
|
if r.Req == nil {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
if len(r.Req.Question) == 0 {
|
|
|
|
|
return ""
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dns.Class(r.Req.Question[0].Qclass).String()
|
|
|
|
|
|
|
|
|
|
}
|
2016-03-18 20:57:35 +00:00
|
|
|
|
|
|
|
|
// QClass returns the class of the question in the request.
|
2017-08-31 16:24:11 +02:00
|
|
|
// If the request is malformed 0 returned.
|
|
|
|
|
func (r *Request) QClass() uint16 {
|
|
|
|
|
if r.Req == nil {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
if len(r.Req.Question) == 0 {
|
|
|
|
|
return 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r.Req.Question[0].Qclass
|
|
|
|
|
|
|
|
|
|
}
|
2016-03-18 20:57:35 +00:00
|
|
|
|
|
|
|
|
// ErrorMessage returns an error message suitable for sending
|
|
|
|
|
// back to the client.
|
2016-09-07 11:10:16 +01:00
|
|
|
func (r *Request) ErrorMessage(rcode int) *dns.Msg {
|
2016-03-18 20:57:35 +00:00
|
|
|
m := new(dns.Msg)
|
2016-09-07 11:10:16 +01:00
|
|
|
m.SetRcode(r.Req, rcode)
|
2016-03-18 20:57:35 +00:00
|
|
|
return m
|
|
|
|
|
}
|
2016-04-04 08:19:06 +01:00
|
|
|
|
2016-09-07 11:10:16 +01:00
|
|
|
// Clear clears all caching from Request s.
|
|
|
|
|
func (r *Request) Clear() {
|
|
|
|
|
r.name = ""
|
2016-04-26 17:57:11 +01:00
|
|
|
}
|
|
|
|
|
|
2018-03-15 08:42:49 +00:00
|
|
|
// Match checks if the reply matches the qname and qtype from the request, it returns
|
|
|
|
|
// false when they don't match.
|
|
|
|
|
func (r *Request) Match(reply *dns.Msg) bool {
|
|
|
|
|
if len(reply.Question) != 1 {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-09 12:35:42 +01:00
|
|
|
if reply.Response == false {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-15 08:42:49 +00:00
|
|
|
if strings.ToLower(reply.Question[0].Name) != r.Name() {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if reply.Question[0].Qtype != r.QType() {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-31 17:22:24 +01:00
|
|
|
const optLen = 12 // OPT record length.
|