mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2024-12-26 00:02:34 +01:00
Plugins can now access the client IP. Useful for logging and ACLs.
This commit is contained in:
parent
5e252372d5
commit
fee0a42dec
@ -128,7 +128,8 @@ func (proxy *Proxy) tcpListener(listenAddr *net.TCPAddr) error {
|
|||||||
if err != nil || len(packet) < MinDNSPacketSize {
|
if err != nil || len(packet) < MinDNSPacketSize {
|
||||||
return
|
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 {
|
if len(query) < MinDNSPacketSize || serverInfo == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
pluginsState := NewPluginsState(proxy, clientProto)
|
pluginsState := NewPluginsState(proxy, clientProto, clientAddr)
|
||||||
query, _ = pluginsState.ApplyQueryPlugins(query)
|
query, _ = pluginsState.ApplyQueryPlugins(query)
|
||||||
var response []byte
|
var response []byte
|
||||||
var err error
|
var err error
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"crypto/sha512"
|
"crypto/sha512"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -26,7 +27,8 @@ type PluginsState struct {
|
|||||||
action PluginsAction
|
action PluginsAction
|
||||||
originalMaxPayloadSize int
|
originalMaxPayloadSize int
|
||||||
maxPayloadSize int
|
maxPayloadSize int
|
||||||
proto string
|
clientProto string
|
||||||
|
clientAddr *net.Addr
|
||||||
queryPlugins *[]Plugin
|
queryPlugins *[]Plugin
|
||||||
responsePlugins *[]Plugin
|
responsePlugins *[]Plugin
|
||||||
synthResponse *dns.Msg
|
synthResponse *dns.Msg
|
||||||
@ -43,7 +45,7 @@ type Plugin interface {
|
|||||||
Eval(pluginsState *PluginsState, msg *dns.Msg) error
|
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{}
|
queryPlugins := &[]Plugin{}
|
||||||
if proxy.pluginBlockIPv6 {
|
if proxy.pluginBlockIPv6 {
|
||||||
*queryPlugins = append(*queryPlugins, Plugin(new(PluginBlockIPv6)))
|
*queryPlugins = append(*queryPlugins, Plugin(new(PluginBlockIPv6)))
|
||||||
@ -63,7 +65,8 @@ func NewPluginsState(proxy *Proxy, proto string) PluginsState {
|
|||||||
maxPayloadSize: MaxDNSUDPPacketSize - ResponseOverhead,
|
maxPayloadSize: MaxDNSUDPPacketSize - ResponseOverhead,
|
||||||
queryPlugins: queryPlugins,
|
queryPlugins: queryPlugins,
|
||||||
responsePlugins: responsePlugins,
|
responsePlugins: responsePlugins,
|
||||||
proto: proto,
|
clientProto: clientProto,
|
||||||
|
clientAddr: clientAddr,
|
||||||
cacheSize: proxy.cacheSize,
|
cacheSize: proxy.cacheSize,
|
||||||
cacheNegTTL: proxy.cacheNegTTL,
|
cacheNegTTL: proxy.cacheNegTTL,
|
||||||
cacheMinTTL: proxy.cacheMinTTL,
|
cacheMinTTL: proxy.cacheMinTTL,
|
||||||
|
Loading…
Reference in New Issue
Block a user