Avoid unneeded DNS packet unpacking

This commit is contained in:
Frank Denis 2019-12-23 11:37:45 +01:00
parent adb6dac420
commit c27d41faa0
4 changed files with 16 additions and 23 deletions

View file

@ -243,7 +243,7 @@ func NewPluginsState(proxy *Proxy, clientProto string, clientAddr *net.Addr, sta
}
}
func (pluginsState *PluginsState) ApplyQueryPlugins(pluginsGlobals *PluginsGlobals, packet []byte, serverName string) ([]byte, error) {
func (pluginsState *PluginsState) ApplyQueryPlugins(pluginsGlobals *PluginsGlobals, packet []byte, serverName string, needsEDNS0Padding bool) ([]byte, error) {
pluginsState.serverName = serverName
msg := dns.Msg{}
if err := msg.Unpack(packet); err != nil {
@ -280,6 +280,12 @@ func (pluginsState *PluginsState) ApplyQueryPlugins(pluginsGlobals *PluginsGloba
if err != nil {
return packet, err
}
if needsEDNS0Padding && pluginsState.action == PluginsActionContinue {
padLen := 63 - (len(packet2)+63)&63
if paddedPacket2, _ := addEDNS0PaddingIfNoneFound(&msg, packet2, padLen); paddedPacket2 != nil {
return paddedPacket2, nil
}
}
return packet2, nil
}