From: Remi Gacogne Date: Wed, 9 Jun 2021 10:07:42 +0000 (+0200) Subject: dnsdist: Fix an tx ID endianess issue for DoH -> truncated UDP -> TCP X-Git-Tag: dnsdist-1.7.0-alpha1~45^2~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ac88d69894a4bc54bb93ff9519aca424e58b6f9;p=thirdparty%2Fpdns.git dnsdist: Fix an tx ID endianess issue for DoH -> truncated UDP -> TCP --- diff --git a/pdns/dnsdist-idstate.hh b/pdns/dnsdist-idstate.hh index 76afc52df8..5d991042fd 100644 --- a/pdns/dnsdist-idstate.hh +++ b/pdns/dnsdist-idstate.hh @@ -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 diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index cb40ce90da..7673eaacc6 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -586,7 +586,7 @@ static void handleQuery(std::shared_ptr& state, cons IDState ids; setIDStateFromDNSQuestion(ids, dq, std::move(qname)); - ids.origID = ntohs(dh->id); + ids.origID = dh->id; prependSizeToTCPQuery(state->d_buffer, 0); diff --git a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc index 560a26ebdb..41a5b47318 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc +++ b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc @@ -67,8 +67,8 @@ IOState TCPConnectionToBackend::sendQuery(std::shared_ptrincQueries(); conn->d_currentPos = 0; - DEBUGLOG("adding a pending response for ID "<d_currentQuery.d_idstate.origID<<" and QNAME "<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 "<d_currentQuery.d_idstate.origID)<<" and QNAME "<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; diff --git a/pdns/dnsdistdist/doh.cc b/pdns/dnsdistdist/doh.cc index a2d7ef3a46..fae4dbbe73 100644 --- a/pdns/dnsdistdist/doh.cc +++ b/pdns/dnsdistdist/doh.cc @@ -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(du->query.data() + du->proxyProtocolPayloadSize); - queryDH->id = htons(du->ids.origID); + queryDH->id = du->ids.origID; auto cpq = std::make_unique(du); diff --git a/regression-tests.dnsdist/test_DOH.py b/regression-tests.dnsdist/test_DOH.py index 64439f8899..1685065fc2 100644 --- a/regression-tests.dnsdist/test_DOH.py +++ b/regression-tests.dnsdist/test_DOH.py @@ -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,