Commit a937a184 authored by Frank Denis's avatar Frank Denis

Try to preserve edns0 options in client queries

parent fdc2f3c4
......@@ -26,12 +26,13 @@ func (plugin *PluginGetSetPayloadSize) Reload() error {
func (plugin *PluginGetSetPayloadSize) Eval(pluginsState *PluginsState, msg *dns.Msg) error {
pluginsState.originalMaxPayloadSize = 512 - ResponseOverhead
opt := msg.IsEdns0()
edns0 := msg.IsEdns0()
dnssec := false
if opt != nil {
pluginsState.originalMaxPayloadSize = Min(int(opt.UDPSize())-ResponseOverhead, pluginsState.originalMaxPayloadSize)
dnssec = opt.Do()
if edns0 != nil {
pluginsState.originalMaxPayloadSize = Min(int(edns0.UDPSize())-ResponseOverhead, pluginsState.originalMaxPayloadSize)
dnssec = edns0.Do()
}
var options *[]dns.EDNS0
pluginsState.dnssec = dnssec
pluginsState.maxPayloadSize = Min(MaxDNSUDPPacketSize-ResponseOverhead, Max(pluginsState.originalMaxPayloadSize, pluginsState.maxPayloadSize))
if pluginsState.maxPayloadSize > 512 {
......@@ -39,10 +40,20 @@ func (plugin *PluginGetSetPayloadSize) Eval(pluginsState *PluginsState, msg *dns
for _, extra := range msg.Extra {
if extra.Header().Rrtype != dns.TypeOPT {
extra2 = append(extra2, extra)
} else if xoptions := &extra.(*dns.OPT).Option; len(*xoptions) > 0 && options == nil {
options = xoptions
}
}
msg.Extra = extra2
msg.SetEdns0(uint16(pluginsState.maxPayloadSize), dnssec)
if options != nil {
for _, extra := range msg.Extra {
if extra.Header().Rrtype == dns.TypeOPT {
extra.(*dns.OPT).Option = *options
break
}
}
}
}
return nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment