diff --git a/dnscrypt-proxy/main.go b/dnscrypt-proxy/main.go index 203f2428..4e363581 100644 --- a/dnscrypt-proxy/main.go +++ b/dnscrypt-proxy/main.go @@ -128,7 +128,8 @@ func (proxy *Proxy) tcpListener(listenAddr *net.TCPAddr) error { if err != nil || len(packet) < MinDNSPacketSize { return } - proxy.processIncomingQuery(proxy.serversInfo.getOne(), "tcp", "tcp", packet, nil, clientPc) + clientAddr := clientPc.RemoteAddr() + proxy.processIncomingQuery(proxy.serversInfo.getOne(), "tcp", "tcp", packet, &clientAddr, clientPc) }() } }() @@ -176,7 +177,7 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str if len(query) < MinDNSPacketSize || serverInfo == nil { return } - pluginsState := NewPluginsState(proxy, clientProto) + pluginsState := NewPluginsState(proxy, clientProto, clientAddr) query, _ = pluginsState.ApplyQueryPlugins(query) var response []byte var err error diff --git a/dnscrypt-proxy/plugins.go b/dnscrypt-proxy/plugins.go index d1c0e91a..06de5133 100644 --- a/dnscrypt-proxy/plugins.go +++ b/dnscrypt-proxy/plugins.go @@ -4,6 +4,7 @@ import ( "crypto/sha512" "encoding/binary" "errors" + "net" "sync" "time" @@ -26,7 +27,8 @@ type PluginsState struct { action PluginsAction originalMaxPayloadSize int maxPayloadSize int - proto string + clientProto string + clientAddr *net.Addr queryPlugins *[]Plugin responsePlugins *[]Plugin synthResponse *dns.Msg @@ -43,7 +45,7 @@ type Plugin interface { Eval(pluginsState *PluginsState, msg *dns.Msg) error } -func NewPluginsState(proxy *Proxy, proto string) PluginsState { +func NewPluginsState(proxy *Proxy, clientProto string, clientAddr *net.Addr) PluginsState { queryPlugins := &[]Plugin{} if proxy.pluginBlockIPv6 { *queryPlugins = append(*queryPlugins, Plugin(new(PluginBlockIPv6))) @@ -63,7 +65,8 @@ func NewPluginsState(proxy *Proxy, proto string) PluginsState { maxPayloadSize: MaxDNSUDPPacketSize - ResponseOverhead, queryPlugins: queryPlugins, responsePlugins: responsePlugins, - proto: proto, + clientProto: clientProto, + clientAddr: clientAddr, cacheSize: proxy.cacheSize, cacheNegTTL: proxy.cacheNegTTL, cacheMinTTL: proxy.cacheMinTTL,