From 4d3d475c27432278769280f55fc85bdacb275890 Mon Sep 17 00:00:00 2001 From: kenshinx Date: Wed, 15 Feb 2017 01:08:08 +0800 Subject: [PATCH] Support for larger UDP DNS responses #30 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As [RFC6891](https://tools.ietf.org/html/rfc6891) define, Extension Mechanisms for DNS(EDNS(0)) can make UDP DNS response packets reach max 65535 bytes and breakthrough the early [RFC1035](‘https://tools.ietf.org/html/rfc1035’) 512 limitation. --- godns.conf | 2 ++ resolver.go | 4 ++++ settings.go | 1 + 3 files changed, 7 insertions(+) diff --git a/godns.conf b/godns.conf index 5a23165..9a5e1d4 100644 --- a/godns.conf +++ b/godns.conf @@ -18,6 +18,8 @@ timeout = 5 # 5 seconds # Match the PR15, https://github.com/kenshinx/godns/pull/15 interval = 200 # 200 milliseconds +setedns0 = false #Support for larger UDP DNS responses + [redis] host = "127.0.0.1" port = 6379 diff --git a/resolver.go b/resolver.go index 2cac6bd..e20b9d8 100644 --- a/resolver.go +++ b/resolver.go @@ -34,6 +34,10 @@ func (r *Resolver) Lookup(net string, req *dns.Msg) (message *dns.Msg, err error WriteTimeout: r.Timeout(), } + if net == "udp" && settings.ResolvConfig.SetEDNS0 { + req = req.SetEdns0(65535, true) + } + qname := req.Question[0].Name res := make(chan *dns.Msg, 1) diff --git a/settings.go b/settings.go index d1a5dfa..2f8d22c 100644 --- a/settings.go +++ b/settings.go @@ -37,6 +37,7 @@ type ResolvSettings struct { ResolvFile string `toml:"resolv-file"` Timeout int Interval int + SetEDNS0 bool } type DNSServerSettings struct {