EDNS0 unknown flags handling (#313)

Fix the unknown flags handling when receiving such message. We should
zero out all of the Z bits in the OPT record before returning.

Current behavior:

    dig +norec +noad +ednsflags=0x80 soa miek.nl @deb.atoom.net
    ...
    ; EDNS: version: 0, flags:; MBZ: 0080 , udp: 4096

New:

    dig +norec +noad +ednsflags=0x80 soa miek.nl @localhost -p 2053
    ...
    ; EDNS: version: 0, flags:; udp: 4096

Take care no to overwrite the Do bit.

We still accept *all* EDNS option; I do not consider that a bug in
itself.

Fixes #306
This commit is contained in:
Miek Gieben
2016-10-02 17:23:25 +01:00
committed by GitHub
parent 4096c4906d
commit 560f11d148

View File

@@ -19,9 +19,9 @@ type Request struct {
// Cache size after first call to Size or Do.
size int
do int // 0: not, 1: true: 2: false
// TODO(miek): opt record itself as well.
// TODO(miek): opt record itself as well?
// Cache name as (lowercase) well
// Cache lowercase qname.
name string
}
@@ -135,19 +135,31 @@ func (r *Request) SizeAndDo(m *dns.Msg) bool {
if o == nil {
return false
}
o.Hdr.Name = "."
o.Hdr.Rrtype = dns.TypeOPT
o.SetVersion(0)
odo := o.Do()
if mo := m.IsEdns0(); mo != nil {
mo.Hdr.Name = "."
mo.Hdr.Rrtype = dns.TypeOPT
mo.SetVersion(0)
mo.SetUDPSize(o.UDPSize())
if o.Do() {
mo.Hdr.Ttl &= 0xff00 // clear flags
if odo {
mo.SetDo()
}
return true
}
o.Hdr.Name = "."
o.Hdr.Rrtype = dns.TypeOPT
o.SetVersion(0)
o.Hdr.Ttl &= 0xff00 // clear flags
if odo {
o.SetDo()
}
m.Extra = append(m.Extra, o)
return true
}