]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: add a count to track the number of query restarts
authorOliver Chen <oliver.chen@nokia-sbell.com>
Mon, 16 Jun 2025 00:52:24 +0000 (00:52 +0000)
committerOliver Chen <oliver.chen@nokia-sbell.com>
Mon, 16 Jun 2025 00:52:24 +0000 (00:52 +0000)
pdns/dnsdistdist/dnsdist-idstate.hh
pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc
pdns/dnsdistdist/dnsdist-lua-ffi-interface.h
pdns/dnsdistdist/dnsdist-lua-ffi.cc
pdns/dnsdistdist/docs/reference/dq.rst
pdns/dnsdistdist/test-dnsdist-lua-ffi.cc

index a829d3589b4920840ee77f4bcf4896fd28b4093f..86db2dcbc2ee8f389513cf9414f719c753882491 100644 (file)
@@ -168,6 +168,7 @@ struct InternalQueryState
   uint16_t cacheFlags{0}; // DNS flags as sent to the backend // 2
   uint16_t udpPayloadSize{0}; // Max UDP payload size from the query // 2
   dnsdist::Protocol protocol; // 1
+  uint8_t restartCount{0}; // 1
   bool ednsAdded{false};
   bool ecsAdded{false};
   bool skipCache{false};
index 049b88a5c18c84c61a5a22f3145c1e5c60fe9750..280fd82e404b595972dff7d0f28be85510ed473d 100644 (file)
@@ -656,6 +656,7 @@ void setupLuaBindingsDNSQuestion([[maybe_unused]] LuaContext& luaCtx)
     dnsResponse.asynchronous = true;
     dnsResponse.getMutableData() = *dnsResponse.ids.d_packet;
     dnsResponse.ids.d_proxyProtocolPayloadSize = 0;
+    dnsResponse.ids.restartCount++;
     auto query = dnsdist::getInternalQueryFromDQ(dnsResponse, false);
     return dnsdist::queueQueryResumptionEvent(std::move(query));
   });
@@ -667,5 +668,9 @@ void setupLuaBindingsDNSQuestion([[maybe_unused]] LuaContext& luaCtx)
   luaCtx.registerFunction<bool (DNSResponse::*)()>("getStaleCacheHit", [](DNSResponse& dnsResponse) {
     return dnsResponse.ids.staleCacheHit;
   });
+
+  luaCtx.registerFunction<uint8_t (DNSResponse::*)()>("getRestartCount", [](DNSResponse& dnsResponse) {
+    return dnsResponse.ids.restartCount;
+  });
 #endif /* DISABLE_NON_FFI_DQ_BINDINGS */
 }
index 6feb6d9051463f4cbed0d68bce005c8efbb51704..b818054b94095b6d2b5c2edb66295aacee04bf39 100644 (file)
@@ -163,6 +163,7 @@ void dnsdist_ffi_dnsresponse_set_max_returned_ttl(dnsdist_ffi_dnsresponse_t* dr,
 void dnsdist_ffi_dnsresponse_clear_records_type(dnsdist_ffi_dnsresponse_t* dr, uint16_t qtype) __attribute__ ((visibility ("default")));
 bool dnsdist_ffi_dnsresponse_rebase(dnsdist_ffi_dnsresponse_t* dr, const char* initialName, size_t initialNameSize) __attribute__ ((visibility ("default")));
 bool dnsdist_ffi_dnsresponse_get_stale_cache_hit(const dnsdist_ffi_dnsresponse_t* dnsResponse) __attribute__ ((visibility ("default")));
+uint8_t dnsdist_ffi_dnsresponse_get_restart_count(const dnsdist_ffi_dnsresponse_t* dnsResponse) __attribute__ ((visibility ("default")));
 
 bool dnsdist_ffi_dnsquestion_set_async(dnsdist_ffi_dnsquestion_t* dq, uint16_t asyncID, uint16_t queryID, uint32_t timeoutMs) __attribute__ ((visibility ("default")));
 bool dnsdist_ffi_dnsresponse_set_async(dnsdist_ffi_dnsquestion_t* dq, uint16_t asyncID, uint16_t queryID, uint32_t timeoutMs) __attribute__ ((visibility ("default")));
index d8b20f8c77da4a50fcf656d0ff014951821bf27c..33ed5ea6920247c15d25bbf63f24bbca04d3f952 100644 (file)
@@ -845,6 +845,11 @@ bool dnsdist_ffi_dnsresponse_get_stale_cache_hit(const dnsdist_ffi_dnsresponse_t
   return dnsResponse->dr->ids.staleCacheHit;
 }
 
+uint8_t dnsdist_ffi_dnsresponse_get_restart_count(const dnsdist_ffi_dnsresponse_t* dnsResponse)
+{
+  return dnsResponse->dr->ids.restartCount;
+}
+
 bool dnsdist_ffi_dnsquestion_set_async(dnsdist_ffi_dnsquestion_t* dq, uint16_t asyncID, uint16_t queryID, uint32_t timeoutMs)
 {
   try {
index 08cb362330d00a38698cadeb2e0a60e9772838b8..9be06bbb593286370b5dcf9c704c53baf05097d8 100644 (file)
@@ -450,6 +450,12 @@ DNSResponse object
 
     Get the indicator of whether the cache lookup hit a stale entry.
 
+  .. method:: DNSResponse:getRestartCount() -> uint8_t
+
+    .. versionadded:: 2.0.0
+
+    Get the current restart count, useful when the number of restart attempts is to be checked.
+
   .. method:: DNSResponse:editTTLs(func)
 
     The function ``func`` is invoked for every entry in the answer, authority and additional section.
index 7504f0787c3d230510323d41c95099ca5fdf4c8c..b4b2333a3c4efe4c2d34423dc85386b9eb6b4507 100644 (file)
@@ -449,6 +449,10 @@ BOOST_AUTO_TEST_CASE(test_Response)
   {
     BOOST_CHECK_EQUAL(dnsdist_ffi_dnsresponse_get_stale_cache_hit(&lightDR), false);
   }
+
+  {
+    BOOST_CHECK_EQUAL(dnsdist_ffi_dnsresponse_get_restart_count(&lightDR), 0);
+  }
 }
 
 BOOST_AUTO_TEST_CASE(test_Server)