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 <miek@miek.nl>

* Remove setting options when m is EDNS0 record

Assume upstream set them correctly or a plugin.

Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
Miek Gieben 2018-12-10 19:43:46 +00:00 committed by GitHub
parent 9abbf4a4a0
commit fed307bfce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -192,15 +192,13 @@ func (r *Request) Size() int {
} }
// SizeAndDo adds an OPT record that the reflects the intent from request. // 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 { func (r *Request) SizeAndDo(m *dns.Msg) bool {
o := r.Req.IsEdns0() o := r.Req.IsEdns0()
if o == nil { if o == nil {
return false return false
} }
odo := o.Do()
if mo := m.IsEdns0(); mo != nil { if mo := m.IsEdns0(); mo != nil {
mo.Hdr.Name = "." mo.Hdr.Name = "."
mo.Hdr.Rrtype = dns.TypeOPT mo.Hdr.Rrtype = dns.TypeOPT
@ -208,16 +206,15 @@ func (r *Request) SizeAndDo(m *dns.Msg) bool {
mo.SetUDPSize(o.UDPSize()) mo.SetUDPSize(o.UDPSize())
mo.Hdr.Ttl &= 0xff00 // clear flags mo.Hdr.Ttl &= 0xff00 // clear flags
if len(o.Option) > 0 { // Assume if the message m has options set, they are OK and represent what an upstream can do.
o.Option = supportedOptions(o.Option)
}
if odo { if o.Do() {
mo.SetDo() mo.SetDo()
} }
return true return true
} }
// Reuse the request's OPT record and tack it to m.
o.Hdr.Name = "." o.Hdr.Name = "."
o.Hdr.Rrtype = dns.TypeOPT o.Hdr.Rrtype = dns.TypeOPT
o.SetVersion(0) o.SetVersion(0)
@ -227,9 +224,6 @@ func (r *Request) SizeAndDo(m *dns.Msg) bool {
o.Option = supportedOptions(o.Option) o.Option = supportedOptions(o.Option)
} }
if odo {
o.SetDo()
}
m.Extra = append(m.Extra, o) m.Extra = append(m.Extra, o)
return true return true
} }