From fed307bfce18f01dba969a328eddcce339f660a5 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 10 Dec 2018 19:43:46 +0000 Subject: [PATCH] core: edns0 tweaks (#2385) * core: edns0 tweaks Per comment thread in https://github.com/coredns/coredns/pull/2357 which spotted a bug; updated the code and added some comments. This function should probably be redone as some point or made obsolete. Signed-off-by: Miek Gieben * Remove setting options when m is EDNS0 record Assume upstream set them correctly or a plugin. Signed-off-by: Miek Gieben --- request/request.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/request/request.go b/request/request.go index 52bf8629b..6134fc99d 100644 --- a/request/request.go +++ b/request/request.go @@ -192,15 +192,13 @@ func (r *Request) Size() int { } // SizeAndDo adds an OPT record that the reflects the intent from request. -// The returned bool indicated if an record was found and normalised. +// The returned bool indicates if an record was found and normalised. func (r *Request) SizeAndDo(m *dns.Msg) bool { o := r.Req.IsEdns0() if o == nil { return false } - odo := o.Do() - if mo := m.IsEdns0(); mo != nil { mo.Hdr.Name = "." mo.Hdr.Rrtype = dns.TypeOPT @@ -208,16 +206,15 @@ func (r *Request) SizeAndDo(m *dns.Msg) bool { mo.SetUDPSize(o.UDPSize()) mo.Hdr.Ttl &= 0xff00 // clear flags - if len(o.Option) > 0 { - o.Option = supportedOptions(o.Option) - } + // Assume if the message m has options set, they are OK and represent what an upstream can do. - if odo { + if o.Do() { mo.SetDo() } return true } + // Reuse the request's OPT record and tack it to m. o.Hdr.Name = "." o.Hdr.Rrtype = dns.TypeOPT o.SetVersion(0) @@ -227,9 +224,6 @@ func (r *Request) SizeAndDo(m *dns.Msg) bool { o.Option = supportedOptions(o.Option) } - if odo { - o.SetDo() - } m.Extra = append(m.Extra, o) return true }