I can think of two cases where we got this wrong:
- the query was initially assigned to a backend using the proxy protocol
payload, then later restarted and assigned to a backend not using it.
The proxy protocol payload size was then kept from the first assignment.
- we failed to actually prepend the proxy protocol payload but the payload
size was updated.
Both cases could cause a corrupted payload to be sent, or an exception to
be raised if the size of the proxy protocol payload was larger than the
size of the initial query.
(cherry picked from commit
8768b9176dafc793fc3f0867c2d8964eb65378f0)
bool doh = dnsQuestion.ids.du != nullptr;
bool failed = false;
+ dnsQuestion.ids.d_proxyProtocolPayloadSize = 0;
if (downstream->d_config.useProxyProtocol) {
try {
- addProxyProtocol(dnsQuestion, &dnsQuestion.ids.d_proxyProtocolPayloadSize);
+ size_t proxyProtocolPayloadSize = 0;
+ if (addProxyProtocol(dnsQuestion, &proxyProtocolPayloadSize)) {
+ dnsQuestion.ids.d_proxyProtocolPayloadSize = proxyProtocolPayloadSize;
+ }
}
catch (const std::exception& e) {
vinfolog("Adding proxy protocol payload to %s query from %s failed: %s", (dnsQuestion.ids.du ? "DoH" : ""), dnsQuestion.ids.origDest.toStringWithPort(), e.what());
return addProxyProtocol(dq.getMutableData(), payload);
}
-bool addProxyProtocol(DNSQuestion& dq, size_t* payloadSize)
+bool addProxyProtocol(DNSQuestion& dnsQuestion, size_t* proxyProtocolPayloadSize)
{
- auto payload = getProxyProtocolPayload(dq);
- if (payloadSize != nullptr) {
- *payloadSize = payload.size();
+ auto payload = getProxyProtocolPayload(dnsQuestion);
+ size_t payloadSize = payload.size();
+
+ if (!addProxyProtocol(dnsQuestion, payload)) {
+ return false;
}
- return addProxyProtocol(dq, payload);
+ if (proxyProtocolPayloadSize != nullptr) {
+ *proxyProtocolPayloadSize = payloadSize;
+ }
+ return true;
}
bool addProxyProtocol(PacketBuffer& buffer, const std::string& payload)
std::string getProxyProtocolPayload(const DNSQuestion& dq);
-bool addProxyProtocol(DNSQuestion& dq, size_t* proxyProtocolPayloadSize = nullptr);
+bool addProxyProtocol(DNSQuestion& dnsQuestion, size_t* proxyProtocolPayloadSize = nullptr);
bool addProxyProtocol(DNSQuestion& dq, const std::string& payload);
bool addProxyProtocol(PacketBuffer& buffer, const std::string& payload);
bool addProxyProtocol(PacketBuffer& buffer, bool tcp, const ComboAddress& source, const ComboAddress& destination, const std::vector<ProxyProtocolValue>& values);