From: slowr Date: Tue, 8 Jun 2021 15:50:24 +0000 (+0200) Subject: code cleanup X-Git-Tag: dnsdist-1.7.0-alpha1~124^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1db2e022b10313b532dfb1e1ce4941592e8a1bcb;p=thirdparty%2Fpdns.git code cleanup --- diff --git a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc index f6163439ae..cb76fa6fa1 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc +++ b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc @@ -483,49 +483,8 @@ IOState TCPConnectionToBackend::handleResponse(std::shared_ptr(response.d_buffer.data()), response.d_buffer.size()); - if (parser.d_header.rcode != 0U) { - done = true; - } - else { - for (const auto& record : parser.d_answers) { - if (record.first.d_class != QClass::IN || - record.first.d_type != QType::SOA) { - continue; - } - auto unknownContent = getRR(record.first); - if (!unknownContent) { - continue; - } - auto raw = unknownContent->getRawContent(); - auto serial = getSerialFromRawSOAContent(raw); - - ++d_clientConn->d_xfrSerialCount; - if (d_clientConn->d_xfrMasterSerial == 0) { - // store the first SOA in our client's connection metadata - ++d_clientConn->d_xfrMasterSerialCount; - d_clientConn->d_xfrMasterSerial = serial; - } else if (d_clientConn->d_xfrMasterSerial == serial) { - ++d_clientConn->d_xfrMasterSerialCount; - // figure out if it's end when receiving master's SOA again - if (d_clientConn->d_xfrSerialCount == 2) { - // if there are only two SOA records marks a finished AXFR - done = true; - } - if (d_clientConn->d_xfrMasterSerialCount == 3) { - // receiving master's SOA 3 times marks a finished IXFR - done = true; - } - } - } - } - } - catch (const MOADNSException& e) { - DEBUGLOG("Exception when parsing TCPResponse to DNS: " << e.what()); - /* ponder what to do here, shall we close the connection? */ - } + done = isXFRFinished(response, clientConn); clientConn->handleXFRResponse(clientConn, now, std::move(response)); if (done) { @@ -632,3 +591,52 @@ bool TCPConnectionToBackend::matchesTLVs(const std::unique_ptr& clientConn) +{ + bool done = false; + try { + MOADNSParser parser(true, reinterpret_cast(response.d_buffer.data()), response.d_buffer.size()); + if (parser.d_header.rcode != 0U) { + done = true; + } + else { + for (const auto& record : parser.d_answers) { + if (record.first.d_class != QClass::IN || record.first.d_type != QType::SOA) { + continue; + } + + auto unknownContent = getRR(record.first); + if (!unknownContent) { + continue; + } + auto raw = unknownContent->getRawContent(); + auto serial = getSerialFromRawSOAContent(raw); + + ++clientConn->d_xfrSerialCount; + if (clientConn->d_xfrMasterSerial == 0) { + // store the first SOA in our client's connection metadata + ++clientConn->d_xfrMasterSerialCount; + clientConn->d_xfrMasterSerial = serial; + } + else if (clientConn->d_xfrMasterSerial == serial) { + ++clientConn->d_xfrMasterSerialCount; + // figure out if it's end when receiving master's SOA again + if (clientConn->d_xfrSerialCount == 2) { + // if there are only two SOA records marks a finished AXFR + done = true; + } + if (clientConn->d_xfrMasterSerialCount == 3) { + // receiving master's SOA 3 times marks a finished IXFR + done = true; + } + } + } + } + } + catch (const MOADNSException& e) { + DEBUGLOG("Exception when parsing TCPResponse to DNS: " << e.what()); + /* ponder what to do here, shall we close the connection? */ + } + return done; +} diff --git a/pdns/dnsdistdist/dnsdist-tcp-downstream.hh b/pdns/dnsdistdist/dnsdist-tcp-downstream.hh index 61a0397923..f9d26e5180 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-downstream.hh +++ b/pdns/dnsdistdist/dnsdist-tcp-downstream.hh @@ -191,6 +191,7 @@ private: static void handleIOCallback(int fd, FDMultiplexer::funcparam_t& param); static IOState queueNextQuery(std::shared_ptr& conn); static IOState sendQuery(std::shared_ptr& conn, const struct timeval& now); + static bool isXFRFinished(const TCPResponse& response, const shared_ptr& clientConn); IOState handleResponse(std::shared_ptr& conn, const struct timeval& now); uint16_t getQueryIdFromResponse(); diff --git a/pdns/dnsdistdist/dnsdist-tcp-upstream.hh b/pdns/dnsdistdist/dnsdist-tcp-upstream.hh index b54b3eb630..6ab94f028f 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-upstream.hh +++ b/pdns/dnsdistdist/dnsdist-tcp-upstream.hh @@ -203,13 +203,13 @@ public: size_t d_proxyProtocolNeed{0}; size_t d_queriesCount{0}; size_t d_currentQueriesCount{0}; + uint32_t d_xfrMasterSerial{0}; + uint32_t d_xfrSerialCount{0}; + uint8_t d_xfrMasterSerialCount{0}; uint16_t d_querySize{0}; State d_state{State::doingHandshake}; bool d_isXFR{false}; bool d_proxyProtocolPayloadHasTLV{false}; bool d_lastIOBlocked{false}; bool d_hadErrors{false}; - uint32_t d_xfrMasterSerial{0}; - uint32_t d_xfrSerialCount{0}; - uint8_t d_xfrMasterSerialCount{0}; };