]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Only reuse an existing TCP connection if the same server was selected
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 4 Mar 2020 13:03:32 +0000 (14:03 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 17 Mar 2020 13:12:56 +0000 (14:12 +0100)
pdns/dnsdist-tcp.cc

index 32f3279151726d1bab67da750aa69855abbe401b..4ae3199e086126eac2646308a77a22d5789a9fac 100644 (file)
@@ -186,6 +186,14 @@ public:
     return true;
   }
 
+  bool matches(const std::shared_ptr<DownstreamState>& ds) const
+  {
+    if (!ds || !d_ds) {
+      return false;
+    }
+    return ds == d_ds;
+  }
+
 private:
   std::unique_ptr<Socket> d_socket{nullptr};
   std::shared_ptr<DownstreamState> d_ds{nullptr};
@@ -953,7 +961,7 @@ static void handleQuery(std::shared_ptr<IncomingTCPConnectionState>& state, stru
       state->d_proxyProtocolPayloadHasTLV = dq.proxyProtocolValues && !dq.proxyProtocolValues->empty();
     }
 
-    if (state->d_downstreamConnection && !state->d_proxyProtocolPayloadHasTLV) {
+    if (state->d_downstreamConnection && !state->d_proxyProtocolPayloadHasTLV && state->d_downstreamConnection->matches(state->d_ds)) {
       /* we have an existing connection, on which we already sent a Proxy Protocol header with no values
          (in the previous query had TLV values we would have reset the connection afterwards),
          so let's reuse it as long as we still don't have any values */