Skip to content

Commit

Permalink
Remove three nested if conditions
Browse files Browse the repository at this point in the history
Signed-off-by: SriHarshaBS001 <SriHarshaBS009@gmail.com>
  • Loading branch information
SriHarsha001 committed Sep 7, 2023
1 parent a7dc3db commit a89212e
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions plugin/pkg/proxy/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,16 @@ func (p *Proxy) Connect(ctx context.Context, state request.Request, opts Options
for {
ret, err = pc.c.ReadMsg()
if err != nil {
// If TLS has been configured, then actual protocol used is TCP.
if p.transport.transportTypeFromConn(pc) == typeUDP {
if ret != nil && (state.Req.Id == ret.Id) && p.transport.transportTypeFromConn(pc) == typeUDP && shouldTruncateResponse(err) {
// For UDP, if the error is an overflow, we probably have an upstream misbehaving in some way.
// (e.g. sending >512 byte responses without an eDNS0 OPT RR).
// Instead of returning an error, return an empty response with TC bit set. This will make the
// client retry over TCP (if that's supported) or at least receive a clean
// error. The connection is still good so we break before the close.

// Only if response message id matches the request message id - check for truncation and truncate response.
if ret != nil && (state.Req.Id == ret.Id) {
// Check if the response should be truncated based on the error.
if shouldTruncateResponse(err) {
// Truncate the response.
ret = truncateResponse(ret)
break
}
}
// Truncate the response.
ret = truncateResponse(ret)
break
}

pc.c.Close() // not giving it back
Expand Down

0 comments on commit a89212e

Please sign in to comment.