diff --git a/dnscrypt-proxy/local-doh.go b/dnscrypt-proxy/local-doh.go index 31a660c6..b1abed22 100644 --- a/dnscrypt-proxy/local-doh.go +++ b/dnscrypt-proxy/local-doh.go @@ -53,7 +53,7 @@ func (handler localDoHHandler) ServeHTTP(writer http.ResponseWriter, request *ht writer.WriteHeader(400) return } - response := proxy.processIncomingQuery(proxy.serversInfo.getOne(), "local_doh", proxy.mainProto, packet, &xClientAddr, nil, start) + response := proxy.processIncomingQuery("local_doh", proxy.mainProto, packet, &xClientAddr, nil, start) if len(response) == 0 { writer.WriteHeader(500) return diff --git a/dnscrypt-proxy/plugin_block_name.go b/dnscrypt-proxy/plugin_block_name.go index 542d6407..0540a146 100644 --- a/dnscrypt-proxy/plugin_block_name.go +++ b/dnscrypt-proxy/plugin_block_name.go @@ -26,6 +26,9 @@ var blockedNames *BlockedNames func (blockedNames *BlockedNames) check(pluginsState *PluginsState, qName string, aliasFor *string) (bool, error) { reject, reason, xweeklyRanges := blockedNames.patternMatcher.Eval(qName) + if aliasFor != nil { + reason = reason + " (alias for [" + *aliasFor + "])" + } var weeklyRanges *WeeklyRanges if xweeklyRanges != nil { weeklyRanges = xweeklyRanges.(*WeeklyRanges) @@ -40,11 +43,6 @@ func (blockedNames *BlockedNames) check(pluginsState *PluginsState, qName string } pluginsState.action = PluginsActionReject pluginsState.returnCode = PluginsReturnCodeReject - if aliasFor != nil { - reason = reason + " (alias for [" + *aliasFor + "])" - } else { - pluginsState.noServed = true - } if blockedNames.logger != nil { var clientIPStr string if pluginsState.clientProto == "udp" { diff --git a/dnscrypt-proxy/plugin_query_log.go b/dnscrypt-proxy/plugin_query_log.go index f14b4e22..d94b4b94 100644 --- a/dnscrypt-proxy/plugin_query_log.go +++ b/dnscrypt-proxy/plugin_query_log.go @@ -63,7 +63,7 @@ func (plugin *PluginQueryLog) Eval(pluginsState *PluginsState, msg *dns.Msg) err } qName := pluginsState.qName - if pluginsState.cacheHit || pluginsState.noServed { + if pluginsState.cacheHit { pluginsState.serverName = "-" } else { switch pluginsState.returnCode { diff --git a/dnscrypt-proxy/plugins.go b/dnscrypt-proxy/plugins.go index 9b502878..f511b9e3 100644 --- a/dnscrypt-proxy/plugins.go +++ b/dnscrypt-proxy/plugins.go @@ -84,7 +84,6 @@ type PluginsState struct { requestStart time.Time requestEnd time.Time cacheHit bool - noServed bool returnCode PluginsReturnCode serverName string } @@ -238,14 +237,14 @@ func NewPluginsState(proxy *Proxy, clientProto string, clientAddr *net.Addr, sta rejectTTL: proxy.rejectTTL, questionMsg: nil, qName: "", + serverName: "-", requestStart: start, maxUnencryptedUDPSafePayloadSize: MaxDNSUDPSafePacketSize, sessionData: make(map[string]interface{}), } } -func (pluginsState *PluginsState) ApplyQueryPlugins(pluginsGlobals *PluginsGlobals, packet []byte, serverName string, needsEDNS0Padding bool) ([]byte, error) { - pluginsState.serverName = serverName +func (pluginsState *PluginsState) ApplyQueryPlugins(pluginsGlobals *PluginsGlobals, packet []byte, needsEDNS0Padding bool) ([]byte, error) { msg := dns.Msg{} if err := msg.Unpack(packet); err != nil { return packet, err diff --git a/dnscrypt-proxy/proxy.go b/dnscrypt-proxy/proxy.go index 56ea1630..6533efa2 100644 --- a/dnscrypt-proxy/proxy.go +++ b/dnscrypt-proxy/proxy.go @@ -269,7 +269,7 @@ func (proxy *Proxy) udpListener(clientPc *net.UDPConn) { return } defer proxy.clientsCountDec() - proxy.processIncomingQuery(proxy.serversInfo.getOne(), "udp", proxy.mainProto, packet, &clientAddr, clientPc, start) + proxy.processIncomingQuery("udp", proxy.mainProto, packet, &clientAddr, clientPc, start) }() } } @@ -307,7 +307,7 @@ func (proxy *Proxy) tcpListener(acceptPc *net.TCPListener) { return } clientAddr := clientPc.RemoteAddr() - proxy.processIncomingQuery(proxy.serversInfo.getOne(), "tcp", "tcp", packet, &clientAddr, clientPc, start) + proxy.processIncomingQuery("tcp", "tcp", packet, &clientAddr, clientPc, start) }() } } @@ -438,18 +438,19 @@ func (proxy *Proxy) clientsCountDec() { } } -func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto string, serverProto string, query []byte, clientAddr *net.Addr, clientPc net.Conn, start time.Time) (response []byte) { +func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string, query []byte, clientAddr *net.Addr, clientPc net.Conn, start time.Time) (response []byte) { if len(query) < MinDNSPacketSize { return } pluginsState := NewPluginsState(proxy, clientProto, clientAddr, start) serverName := "-" needsEDNS0Padding := false + serverInfo := proxy.serversInfo.getOne() if serverInfo != nil { serverName = serverInfo.Name needsEDNS0Padding = (serverInfo.Proto == stamps.StampProtoTypeDoH || serverInfo.Proto == stamps.StampProtoTypeTLS) } - query, _ = pluginsState.ApplyQueryPlugins(&proxy.pluginsGlobals, query, serverName, needsEDNS0Padding) + query, _ = pluginsState.ApplyQueryPlugins(&proxy.pluginsGlobals, query, needsEDNS0Padding) if len(query) < MinDNSPacketSize || len(query) > MaxDNSPacketSize { return } @@ -469,6 +470,7 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str } if len(response) == 0 && serverInfo != nil { var ttl *uint32 + pluginsState.serverName = serverName if serverInfo.Proto == stamps.StampProtoTypeDNSCrypt { sharedKey, encryptedQuery, clientNonce, err := proxy.Encrypt(serverInfo, query, serverProto) if err != nil {