Overwrite the server name only when we need to send an upstream query
This commit is contained in:
parent
c17637c026
commit
19647e03a6
|
@ -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
|
||||
|
|
|
@ -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" {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue