diff --git a/dnscrypt-proxy/plugins.go b/dnscrypt-proxy/plugins.go index adce6fc8..f9507d2d 100644 --- a/dnscrypt-proxy/plugins.go +++ b/dnscrypt-proxy/plugins.go @@ -226,6 +226,7 @@ type Plugin interface { func NewPluginsState(proxy *Proxy, clientProto string, clientAddr *net.Addr, start time.Time) PluginsState { return PluginsState{ action: PluginsActionForward, + returnCode: PluginsReturnCodeForward, maxPayloadSize: MaxDNSUDPPacketSize - ResponseOverhead, clientProto: clientProto, clientAddr: clientAddr, diff --git a/dnscrypt-proxy/proxy.go b/dnscrypt-proxy/proxy.go index 3cbdf2ce..eb5382e9 100644 --- a/dnscrypt-proxy/proxy.go +++ b/dnscrypt-proxy/proxy.go @@ -442,23 +442,19 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str if len(query) < MinDNSPacketSize || len(query) > MaxDNSPacketSize { return } + if pluginsState.action == PluginsActionDrop { + pluginsState.returnCode = PluginsReturnCodeDrop + pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals) + return + } var err error - if pluginsState.action != PluginsActionForward { - if pluginsState.synthResponse != nil { - response, err = pluginsState.synthResponse.PackBuffer(response) - if err != nil { - pluginsState.returnCode = PluginsReturnCodeParseError - pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals) - return - } - } - if pluginsState.action == PluginsActionDrop { - pluginsState.returnCode = PluginsReturnCodeDrop + if pluginsState.synthResponse != nil { + response, err = pluginsState.synthResponse.PackBuffer(response) + if err != nil { + pluginsState.returnCode = PluginsReturnCodeParseError pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals) return } - } else { - pluginsState.returnCode = PluginsReturnCodeForward } if len(response) == 0 && serverInfo != nil { var ttl *uint32 @@ -533,6 +529,19 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str serverInfo.noticeFailure(proxy) return } + if pluginsState.action == PluginsActionDrop { + pluginsState.returnCode = PluginsReturnCodeDrop + pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals) + return + } + if pluginsState.synthResponse != nil { + response, err = pluginsState.synthResponse.PackBuffer(response) + if err != nil { + pluginsState.returnCode = PluginsReturnCodeParseError + pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals) + return + } + } if rcode := Rcode(response); rcode == dns.RcodeServerFailure { // SERVFAIL dlog.Infof("Server [%v] returned temporary error code [%v] -- Upstream server may be experiencing connectivity issues", serverInfo.Name, rcode) serverInfo.noticeFailure(proxy)