Do the payload size check after the TXT and base32 checks.

That way we can respond with NXDOMAIN rather than FORMERR to more of the
random queries that arrive.
This commit is contained in:
David Fifield
2020-04-19 00:59:04 -06:00
parent 04e1295e52
commit 59f03791df
+11 -12
View File
@@ -283,18 +283,6 @@ func responseFor(query *dns.Message, domain dns.Name) (*dns.Message, turbotunnel
resp.Flags |= 0x0400 // AA = 1
}
// We require clients to support EDNS(0) with a minimum payload size;
// otherwise we would have to set a small KCP MTU (only around 200
// bytes). https://tools.ietf.org/html/rfc6891#section-7 "If there is a
// problem with processing the OPT record itself, such as an option
// value that is badly formatted or that includes out-of-range values, a
// FORMERR MUST be returned."
if payloadSize < maxUDPPayload {
resp.Flags |= dns.RcodeFormatError
log.Printf("FORMERR: EDNS payload size %d is too small (minimum %d)", payloadSize, maxUDPPayload)
return resp, clientID, nil
}
if resp.Flags&0x0400 == 0 { // AA
// Not a name we are authoritative for.
resp.Flags |= dns.RcodeNameError
@@ -331,6 +319,17 @@ func responseFor(query *dns.Message, domain dns.Name) (*dns.Message, turbotunnel
return resp, clientID, nil
}
// We require clients to support EDNS(0) with a minimum payload size;
// otherwise we would have to set a small KCP MTU (only around 200
// bytes). https://tools.ietf.org/html/rfc6891#section-7 "If there is a
// problem with processing the OPT record itself, such as an option
// value that is badly formatted or that includes out-of-range values, a
// FORMERR MUST be returned."
if payloadSize < maxUDPPayload {
resp.Flags |= dns.RcodeFormatError
return resp, clientID, nil
}
return resp, clientID, payload[len(clientID):]
}