aboutsummaryrefslogtreecommitdiff
path: root/middleware/edns.go
diff options
context:
space:
mode:
authorGravatar Miek Gieben <miek@miek.nl> 2016-04-09 11:13:04 +0100
committerGravatar Miek Gieben <miek@miek.nl> 2016-04-09 11:13:04 +0100
commitdb3d689a8ac2bec199e5643394ffa779341acde0 (patch)
tree01e8a18adb3bb7c2d6bf73b9ab2964452136e97f /middleware/edns.go
parent16c035731c528f986a93d01b18244cad7d71e725 (diff)
downloadcoredns-db3d689a8ac2bec199e5643394ffa779341acde0.tar.gz
coredns-db3d689a8ac2bec199e5643394ffa779341acde0.tar.zst
coredns-db3d689a8ac2bec199e5643394ffa779341acde0.zip
EDNS: return error on wrong version. (#95)
Split up the previous changes a bit. This PR only returns the expected error when the received packet has the wrong EDNS version. EDNS0 handling in the middleware needs a nicer abstraction, like ReflectEdns() or something.
Diffstat (limited to 'middleware/edns.go')
-rw-r--r--middleware/edns.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/middleware/edns.go b/middleware/edns.go
new file mode 100644
index 000000000..aaab502e0
--- /dev/null
+++ b/middleware/edns.go
@@ -0,0 +1,34 @@
+package middleware
+
+import (
+ "errors"
+
+ "github.com/miekg/dns"
+)
+
+// Edns0Version checks the EDNS version in the request. If error
+// is nil everything is OK and we can invoke the middleware. If non-nil, the
+// returned Msg is valid to be returned to the client (and should). For some
+// reason this response should not contain a question RR in the question section.
+func Edns0Version(req *dns.Msg) (*dns.Msg, error) {
+ opt := req.IsEdns0()
+ if opt == nil {
+ return nil, nil
+ }
+ if opt.Version() == 0 {
+ return nil, nil
+ }
+ m := new(dns.Msg)
+ m.SetReply(req)
+ // zero out question section, wtf.
+ m.Question = nil
+
+ o := new(dns.OPT)
+ o.Hdr.Name = "."
+ o.Hdr.Rrtype = dns.TypeOPT
+ o.SetVersion(0)
+ o.SetExtendedRcode(dns.RcodeBadVers)
+ m.Extra = []dns.RR{o}
+
+ return m, errors.New("EDNS0 BADVERS")
+}