Truncated response over UDP -> immediately retry over TCP

This reduces latency, because when the client retries, or if the
query padding was large enough, we can reply from the cache or
even immediately.
This commit is contained in:
Frank Denis 2019-10-12 20:55:59 +02:00
parent 99e56a400f
commit 20f48edc25
1 changed files with 4 additions and 0 deletions

View File

@ -376,6 +376,10 @@ func (proxy *Proxy) processIncomingQuery(serverInfo *ServerInfo, clientProto str
serverInfo.noticeBegin(proxy)
if serverProto == "udp" {
response, err = proxy.exchangeWithUDPServer(serverInfo, sharedKey, encryptedQuery, clientNonce)
if err == nil && len(response) >= MinDNSPacketSize && response[2]&0x02 == 0x02 {
dlog.Debug("Truncated response over UDP, retrying over TCP")
response, err = proxy.exchangeWithTCPServer(serverInfo, sharedKey, encryptedQuery, clientNonce)
}
} else {
response, err = proxy.exchangeWithTCPServer(serverInfo, sharedKey, encryptedQuery, clientNonce)
}