Make return value explicit

This commit is contained in:
Frank Denis 2021-09-25 20:09:29 +02:00
parent d82021b545
commit b7704a05c5
1 changed files with 20 additions and 20 deletions

View File

@ -572,10 +572,10 @@ func (proxy *Proxy) clientsCountDec() {
}
}
func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string, query []byte, clientAddr *net.Addr, clientPc net.Conn, start time.Time, onlyCached bool) (response []byte) {
response = nil
func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string, query []byte, clientAddr *net.Addr, clientPc net.Conn, start time.Time, onlyCached bool) []byte {
var response []byte = nil
if len(query) < MinDNSPacketSize {
return
return response
}
pluginsState := NewPluginsState(proxy, clientProto, clientAddr, serverProto, start)
serverName := "-"
@ -587,12 +587,12 @@ func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string,
}
query, _ = pluginsState.ApplyQueryPlugins(&proxy.pluginsGlobals, query, needsEDNS0Padding)
if len(query) < MinDNSPacketSize || len(query) > MaxDNSPacketSize {
return
return response
}
if pluginsState.action == PluginsActionDrop {
pluginsState.returnCode = PluginsReturnCodeDrop
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
return
return response
}
var err error
if pluginsState.synthResponse != nil {
@ -600,12 +600,12 @@ func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string,
if err != nil {
pluginsState.returnCode = PluginsReturnCodeParseError
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
return
return response
}
}
if onlyCached {
if len(response) == 0 {
return
return response
}
serverInfo = nil
}
@ -622,7 +622,7 @@ func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string,
if err != nil {
pluginsState.returnCode = PluginsReturnCodeParseError
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
return
return response
}
serverInfo.noticeBegin(proxy)
if serverProto == "udp" {
@ -640,7 +640,7 @@ func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string,
if err != nil {
pluginsState.returnCode = PluginsReturnCodeParseError
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
return
return response
}
response, err = proxy.exchangeWithTCPServer(serverInfo, sharedKey, encryptedQuery, clientNonce)
}
@ -661,7 +661,7 @@ func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string,
}
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
serverInfo.noticeFailure(proxy)
return
return response
}
} else if serverInfo.Proto == stamps.StampProtoTypeDoH {
tid := TransactionID(query)
@ -680,7 +680,7 @@ func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string,
pluginsState.returnCode = PluginsReturnCodeNetworkError
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
serverInfo.noticeFailure(proxy)
return
return response
}
if response == nil {
response = serverResponse
@ -691,7 +691,7 @@ func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string,
} else if serverInfo.Proto == stamps.StampProtoTypeODoHTarget {
tid := TransactionID(query)
if len(serverInfo.odohTargetConfigs) == 0 {
return
return response
}
target := serverInfo.odohTargetConfigs[rand.Intn(len(serverInfo.odohTargetConfigs))]
odohQuery, err := target.encryptQuery(query)
@ -738,7 +738,7 @@ func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string,
pluginsState.returnCode = PluginsReturnCodeNetworkError
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
serverInfo.noticeFailure(proxy)
return
return response
}
} else {
dlog.Fatal("Unsupported protocol")
@ -747,26 +747,26 @@ func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string,
pluginsState.returnCode = PluginsReturnCodeParseError
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
serverInfo.noticeFailure(proxy)
return
return response
}
response, err = pluginsState.ApplyResponsePlugins(&proxy.pluginsGlobals, response, ttl)
if err != nil {
pluginsState.returnCode = PluginsReturnCodeParseError
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
serverInfo.noticeFailure(proxy)
return
return response
}
if pluginsState.action == PluginsActionDrop {
pluginsState.returnCode = PluginsReturnCodeDrop
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
return
return response
}
if pluginsState.synthResponse != nil {
response, err = pluginsState.synthResponse.PackBuffer(response)
if err != nil {
pluginsState.returnCode = PluginsReturnCodeParseError
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
return
return response
}
}
if rcode := Rcode(response); rcode == dns.RcodeServerFailure { // SERVFAIL
@ -790,7 +790,7 @@ func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string,
if serverInfo != nil {
serverInfo.noticeFailure(proxy)
}
return
return response
}
if clientProto == "udp" {
if len(response) > pluginsState.maxUnencryptedUDPSafePayloadSize {
@ -798,7 +798,7 @@ func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string,
if err != nil {
pluginsState.returnCode = PluginsReturnCodeParseError
pluginsState.ApplyLoggingPlugins(&proxy.pluginsGlobals)
return
return response
}
}
clientPc.(net.PacketConn).WriteTo(response, *clientAddr)
@ -815,7 +815,7 @@ func (proxy *Proxy) processIncomingQuery(clientProto string, serverProto string,
if serverInfo != nil {
serverInfo.noticeFailure(proxy)
}
return
return response
}
if clientPc != nil {
clientPc.Write(response)