]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Fix an tx ID endianess issue for DoH -> truncated UDP -> TCP
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 9 Jun 2021 10:07:42 +0000 (12:07 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 26 Aug 2021 14:30:28 +0000 (16:30 +0200)
pdns/dnsdist-idstate.hh
pdns/dnsdist-tcp.cc
pdns/dnsdistdist/dnsdist-tcp-downstream.cc
pdns/dnsdistdist/doh.cc
regression-tests.dnsdist/test_DOH.py

index 76afc52df8f39b04783c0378d79cf23f0b87528c..5d991042fda3eba6f65e39ef043b56149c6413df 100644 (file)
@@ -258,6 +258,7 @@ struct IDState
 #endif
   uint16_t qtype{0}; // 2
   uint16_t qclass{0}; // 2
+  // origID is in network-byte order
   uint16_t origID{0}; // 2
   uint16_t origFlags{0}; // 2
   uint16_t cacheFlags{0}; // DNS flags as sent to the backend // 2
index cb40ce90daa8c92fb9df4a1b672b7f5a0a513ac6..7673eaacc6970f268f55b303d73f86d5014e4ba7 100644 (file)
@@ -586,7 +586,7 @@ static void handleQuery(std::shared_ptr<IncomingTCPConnectionState>& state, cons
 
   IDState ids;
   setIDStateFromDNSQuestion(ids, dq, std::move(qname));
-  ids.origID = ntohs(dh->id);
+  ids.origID = dh->id;
 
   prependSizeToTCPQuery(state->d_buffer, 0);
 
index 560a26ebdbab5eaa0a9cccdd8b1b831968fe7acd..41a5b4731875f8374169e358576630741007dabb 100644 (file)
@@ -67,8 +67,8 @@ IOState TCPConnectionToBackend::sendQuery(std::shared_ptr<TCPConnectionToBackend
   conn->incQueries();
   conn->d_currentPos = 0;
 
-  DEBUGLOG("adding a pending response for ID "<<conn->d_currentQuery.d_idstate.origID<<" and QNAME "<<conn->d_currentQuery.d_idstate.qname);
-  conn->d_pendingResponses[conn->d_currentQuery.d_idstate.origID] = std::move(conn->d_currentQuery);
+  DEBUGLOG("adding a pending response for ID "<<ntohs(conn->d_currentQuery.d_idstate.origID)<<" and QNAME "<<conn->d_currentQuery.d_idstate.qname);
+  conn->d_pendingResponses[ntohs(conn->d_currentQuery.d_idstate.origID)] = std::move(conn->d_currentQuery);
   conn->d_currentQuery.d_buffer.clear();
 
   ++conn->d_ds->outstanding;
index a2d7ef3a46345815c7af9ab2d83140ec92d2a05d..fae4dbbe73fc4173f46d7f15ddd4e113e06a3714 100644 (file)
@@ -1291,7 +1291,7 @@ static void on_dnsdist(h2o_socket_t *listener, const char *err)
   if (!du->tcp && du->truncated && du->response.size() > sizeof(dnsheader)) {
     /* restoring the original ID */
     dnsheader* queryDH = reinterpret_cast<struct dnsheader*>(du->query.data() + du->proxyProtocolPayloadSize);
-    queryDH->id = htons(du->ids.origID);
+    queryDH->id = du->ids.origID;
 
     auto cpq = std::make_unique<DoHCrossProtocolQuery>(du);
 
index 64439f8899f9478623b06da844a14d9e754c9c39..1685065fc20804b25a5e9e9e7688b28ad1feffa5 100644 (file)
@@ -999,9 +999,9 @@ class TestDOHWithCache(DNSDistDOHTest):
         # backend, then over TCP
         name = 'truncated-udp.doh-with-cache.tests.powerdns.com.'
         query = dns.message.make_query(name, 'A', 'IN')
-        query.id = 0
+        query.id = 42
         expectedQuery = dns.message.make_query(name, 'A', 'IN', use_edns=True, payload=4096)
-        expectedQuery.id = 0
+        expectedQuery.id = 42
         response = dns.message.make_response(query)
         rrset = dns.rrset.from_text(name,
                                     3600,