]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: move `clearExisting` from EDNSError flag to a separate object
authorEnsar Sarajčić <dev@ensarsarajcic.com>
Mon, 29 Dec 2025 18:27:23 +0000 (19:27 +0100)
committerEnsar Sarajčić <dev@ensarsarajcic.com>
Mon, 29 Dec 2025 18:27:23 +0000 (19:27 +0100)
Signed-off-by: Ensar Sarajčić <dev@ensarsarajcic.com>
pdns/dnsdistdist/dnsdist-actions-factory.cc
pdns/dnsdistdist/dnsdist-edns.hh
pdns/dnsdistdist/dnsdist-idstate.hh
pdns/dnsdistdist/dnsdist-lua-bindings-dnsquestion.cc
pdns/dnsdistdist/dnsdist-lua-ffi.cc
pdns/dnsdistdist/dnsdist-tcp.cc
pdns/dnsdistdist/dnsdist.cc
pdns/ednsextendederror.hh

index 4a7b02f99ff92862a131bfde79a1d9c132a4ab5e..f8d39b1bb0e2337d945612d2504349520a4a7632 100644 (file)
@@ -2395,8 +2395,8 @@ public:
   // this action does not stop the processing
   SetExtendedDNSErrorAction(uint16_t infoCode, const std::string& extraText, bool clearExistingEntries)
   {
-    d_ede.infoCode = infoCode;
-    d_ede.extraText = extraText;
+    d_ede.error.infoCode = infoCode;
+    d_ede.error.extraText = extraText;
     d_ede.clearExisting = clearExistingEntries;
   }
 
@@ -2404,11 +2404,11 @@ public:
   {
     (void)ruleresult;
     if (d_ede.clearExisting) {
-      dnsQuestion->ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({d_ede}));
+      dnsQuestion->ids.d_extendedErrors = std::make_unique<std::vector<edns::SetExtendedDNSErrorOperation>>(std::initializer_list<edns::SetExtendedDNSErrorOperation>({d_ede}));
     }
     else {
       if (!dnsQuestion->ids.d_extendedErrors) {
-        dnsQuestion->ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({d_ede}));
+        dnsQuestion->ids.d_extendedErrors = std::make_unique<std::vector<edns::SetExtendedDNSErrorOperation>>(std::initializer_list<edns::SetExtendedDNSErrorOperation>({d_ede}));
       }
       else {
         dnsQuestion->ids.d_extendedErrors->emplace_back(d_ede);
@@ -2420,11 +2420,11 @@ public:
 
   [[nodiscard]] std::string toString() const override
   {
-    return "set EDNS Extended DNS Error to " + std::to_string(d_ede.infoCode) + (d_ede.extraText.empty() ? std::string() : std::string(": \"") + d_ede.extraText + std::string("\""));
+    return "set EDNS Extended DNS Error to " + std::to_string(d_ede.error.infoCode) + (d_ede.error.extraText.empty() ? std::string() : std::string(": \"") + d_ede.error.extraText + std::string("\""));
   }
 
 private:
-  EDNSExtendedError d_ede;
+  edns::SetExtendedDNSErrorOperation d_ede;
 };
 
 class SetExtendedDNSErrorResponseAction : public DNSResponseAction
@@ -2433,8 +2433,8 @@ public:
   // this action does not stop the processing
   SetExtendedDNSErrorResponseAction(uint16_t infoCode, const std::string& extraText, bool clearExistingEntries)
   {
-    d_ede.infoCode = infoCode;
-    d_ede.extraText = extraText;
+    d_ede.error.infoCode = infoCode;
+    d_ede.error.extraText = extraText;
     d_ede.clearExisting = clearExistingEntries;
   }
 
@@ -2442,11 +2442,11 @@ public:
   {
     (void)ruleresult;
     if (d_ede.clearExisting) {
-      dnsResponse->ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({d_ede}));
+      dnsResponse->ids.d_extendedErrors = std::make_unique<std::vector<edns::SetExtendedDNSErrorOperation>>(std::initializer_list<edns::SetExtendedDNSErrorOperation>({d_ede}));
     }
     else {
       if (!dnsResponse->ids.d_extendedErrors) {
-        dnsResponse->ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({d_ede}));
+        dnsResponse->ids.d_extendedErrors = std::make_unique<std::vector<edns::SetExtendedDNSErrorOperation>>(std::initializer_list<edns::SetExtendedDNSErrorOperation>({d_ede}));
       }
       else {
         dnsResponse->ids.d_extendedErrors->emplace_back(d_ede);
@@ -2458,11 +2458,11 @@ public:
 
   [[nodiscard]] std::string toString() const override
   {
-    return "set EDNS Extended DNS Error to " + std::to_string(d_ede.infoCode) + (d_ede.extraText.empty() ? std::string() : std::string(": \"") + d_ede.extraText + std::string("\""));
+    return "set EDNS Extended DNS Error to " + std::to_string(d_ede.error.infoCode) + (d_ede.error.extraText.empty() ? std::string() : std::string(": \"") + d_ede.error.extraText + std::string("\""));
   }
 
 private:
-  EDNSExtendedError d_ede;
+  edns::SetExtendedDNSErrorOperation d_ede;
 };
 
 class LimitTTLResponseAction : public DNSResponseAction, public boost::noncopyable
index 1fdb9b5adc772cc4fb01b5a3ff11270e3afabbdb..cb518b20697abe690862176b405268092f420dc5 100644 (file)
 #include <string>
 #include <utility>
 
+#include "ednsextendederror.hh"
 #include "noinitvector.hh"
 
 namespace dnsdist::edns
 {
+struct SetExtendedDNSErrorOperation
+{
+  EDNSExtendedError error;
+  bool clearExisting = true;
+};
+
 std::pair<std::optional<uint16_t>, std::optional<std::string>> getExtendedDNSError(const PacketBuffer& packet);
 bool addExtendedDNSError(PacketBuffer& packet, size_t maximumPacketSize, uint16_t code, const std::string& extraStatus, bool clearExisting);
 }
index c8db1305c45e705674d0061371b2af4c9c7300cd..c6937af7c356c51d3bd11c68441d6d05627bd328 100644 (file)
@@ -33,6 +33,7 @@
 #include "config.h"
 #include "dnscrypt.hh"
 #include "dnsdist-configuration.hh"
+#include "dnsdist-edns.hh"
 #include "dnsname.hh"
 #include "dnsdist-protocols.hh"
 #include "ednsextendederror.hh"
@@ -203,7 +204,7 @@ public:
 #ifndef DISABLE_PROTOBUF
   std::vector<std::pair<std::string, std::shared_ptr<RemoteLoggerInterface>>> delayedResponseMsgs;
 #endif
-  std::unique_ptr<std::vector<EDNSExtendedError>> d_extendedErrors{nullptr};
+  std::unique_ptr<std::vector<dnsdist::edns::SetExtendedDNSErrorOperation>> d_extendedErrors{nullptr};
   std::optional<uint32_t> tempFailureTTL{std::nullopt}; // 8
   ClientState* cs{nullptr}; // 8
   std::unique_ptr<DOHUnitInterface> du; // 8
index 7835b3e5089f123dd5e568bf9d40c393035e096e..ae04d5f679600fbd6c50d151e3de7d1ab8bf69e5 100644 (file)
@@ -19,6 +19,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
+#include "dnsdist-edns.hh"
 #include "dnsdist.hh"
 #include "dnsdist-async.hh"
 #include "dnsdist-dnsparser.hh"
@@ -319,23 +320,23 @@ void setupLuaBindingsDNSQuestion([[maybe_unused]] LuaContext& luaCtx)
   });
 
   luaCtx.registerFunction<void (DNSQuestion::*)(uint16_t infoCode, const std::optional<std::string>& extraText, const std::optional<bool> clearExistingEntries)>("setExtendedDNSError", [](DNSQuestion& dnsQuestion, uint16_t infoCode, const std::optional<std::string>& extraText, const std::optional<bool> clearExistingEntries) {
-    EDNSExtendedError ede;
-    ede.infoCode = infoCode;
+    dnsdist::edns::SetExtendedDNSErrorOperation ede;
+    ede.error.infoCode = infoCode;
     if (extraText) {
-      ede.extraText = *extraText;
+      ede.error.extraText = *extraText;
     }
-    if (clearExistingEntries.value_or(true)) {
-      dnsQuestion.ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({ede}));
+    ede.clearExisting = clearExistingEntries.value_or(true);
+    if (ede.clearExisting) {
+      dnsQuestion.ids.d_extendedErrors = std::make_unique<std::vector<dnsdist::edns::SetExtendedDNSErrorOperation>>(std::initializer_list<dnsdist::edns::SetExtendedDNSErrorOperation>({ede}));
     }
     else {
       if (!dnsQuestion.ids.d_extendedErrors) {
-        dnsQuestion.ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({ede}));
+        dnsQuestion.ids.d_extendedErrors = std::make_unique<std::vector<dnsdist::edns::SetExtendedDNSErrorOperation>>(std::initializer_list<dnsdist::edns::SetExtendedDNSErrorOperation>({ede}));
       }
       else {
         dnsQuestion.ids.d_extendedErrors->emplace_back(ede);
       }
     }
-    dnsQuestion.ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({ede}));
   });
 
   luaCtx.registerFunction<bool (DNSQuestion::*)(uint16_t asyncID, uint16_t queryID, uint32_t timeoutMs)>("suspend", [](DNSQuestion& dnsQuestion, uint16_t asyncID, uint16_t queryID, uint32_t timeoutMs) {
@@ -694,17 +695,18 @@ void setupLuaBindingsDNSQuestion([[maybe_unused]] LuaContext& luaCtx)
   });
 
   luaCtx.registerFunction<void (DNSResponse::*)(uint16_t infoCode, const std::optional<std::string>& extraText, const std::optional<bool> clearExistingEntries)>("setExtendedDNSError", [](DNSResponse& dnsResponse, uint16_t infoCode, const std::optional<std::string>& extraText, const std::optional<bool> clearExistingEntries) {
-    EDNSExtendedError ede;
-    ede.infoCode = infoCode;
+    dnsdist::edns::SetExtendedDNSErrorOperation ede;
+    ede.error.infoCode = infoCode;
     if (extraText) {
-      ede.extraText = *extraText;
+      ede.error.extraText = *extraText;
     }
-    if (clearExistingEntries.value_or(true)) {
-      dnsResponse.ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({ede}));
+    ede.clearExisting = clearExistingEntries.value_or(true);
+    if (ede.clearExisting) {
+      dnsResponse.ids.d_extendedErrors = std::make_unique<std::vector<dnsdist::edns::SetExtendedDNSErrorOperation>>(std::initializer_list<dnsdist::edns::SetExtendedDNSErrorOperation>({ede}));
     }
     else {
       if (!dnsResponse.ids.d_extendedErrors) {
-        dnsResponse.ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({ede}));
+        dnsResponse.ids.d_extendedErrors = std::make_unique<std::vector<dnsdist::edns::SetExtendedDNSErrorOperation>>(std::initializer_list<dnsdist::edns::SetExtendedDNSErrorOperation>({ede}));
       }
       else {
         dnsResponse.ids.d_extendedErrors->emplace_back(ede);
index 053273370e9fc66630b9b890c7ac95cb16f3c749..9d741c496909ca81f053aa9c23e9c633325ec325 100644 (file)
@@ -26,6 +26,7 @@
 #include "dnsdist-dynblocks.hh"
 #include "dnsdist-ecs.hh"
 #include "dnsdist-lua-ffi.hh"
+#include "dnsdist-edns.hh"
 #include "dnsdist-mac-address.hh"
 #include "dnsdist-metrics.hh"
 #include "dnsdist-lua-network.hh"
@@ -534,24 +535,25 @@ void dnsdist_ffi_dnsquestion_set_http_response([[maybe_unused]] dnsdist_ffi_dnsq
 
 void dnsdist_ffi_dnsquestion_set_extended_dns_error(dnsdist_ffi_dnsquestion_t* dnsQuestion, uint16_t infoCode, const char* extraText, size_t extraTextSize)
 {
-  EDNSExtendedError ede;
-  ede.infoCode = infoCode;
+  dnsdist::edns::SetExtendedDNSErrorOperation ede;
+  ede.error.infoCode = infoCode;
   if (extraText != nullptr && extraTextSize > 0) {
-    ede.extraText = std::string(extraText, extraTextSize);
+    ede.error.extraText = std::string(extraText, extraTextSize);
   }
-  dnsQuestion->dq->ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({ede}));
+  ede.clearExisting = true;
+  dnsQuestion->dq->ids.d_extendedErrors = std::make_unique<std::vector<dnsdist::edns::SetExtendedDNSErrorOperation>>(std::initializer_list<dnsdist::edns::SetExtendedDNSErrorOperation>({ede}));
 }
 
 void dnsdist_ffi_dnsquestion_add_extended_dns_error(dnsdist_ffi_dnsquestion_t* dnsQuestion, uint16_t infoCode, const char* extraText, size_t extraTextSize)
 {
-  EDNSExtendedError ede;
-  ede.infoCode = infoCode;
+  dnsdist::edns::SetExtendedDNSErrorOperation ede;
+  ede.error.infoCode = infoCode;
   if (extraText != nullptr && extraTextSize > 0) {
-    ede.extraText = std::string(extraText, extraTextSize);
+    ede.error.extraText = std::string(extraText, extraTextSize);
   }
   ede.clearExisting = false;
   if (!dnsQuestion->dq->ids.d_extendedErrors) {
-    dnsQuestion->dq->ids.d_extendedErrors = std::make_unique<std::vector<EDNSExtendedError>>(std::initializer_list<EDNSExtendedError>({ede}));
+    dnsQuestion->dq->ids.d_extendedErrors = std::make_unique<std::vector<dnsdist::edns::SetExtendedDNSErrorOperation>>(std::initializer_list<dnsdist::edns::SetExtendedDNSErrorOperation>({ede}));
   }
   else {
     dnsQuestion->dq->ids.d_extendedErrors->emplace_back(ede);
index b65fe109abf5351083722455617c82e391d721be..295d4fa8cb7726dfd98bd5a982ef29396576da9f 100644 (file)
@@ -1396,7 +1396,7 @@ static bool processXFRResponse(DNSResponse& dnsResponse)
 
   if (dnsResponse.ids.d_extendedErrors) {
     for (auto ede : *dnsResponse.ids.d_extendedErrors) {
-      dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.infoCode, ede.extraText, ede.clearExisting);
+      dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.error.infoCode, ede.error.extraText, ede.clearExisting);
     }
   }
 
index 602bcaf4ce77b732fb6ee15d20fb6b117bce3d38..72dc95191d7504f1a657ac353602785526ea3ccd 100644 (file)
@@ -567,7 +567,7 @@ bool processResponseAfterRules(PacketBuffer& response, DNSResponse& dnsResponse,
 
   if (dnsResponse.ids.d_extendedErrors) {
     for (auto ede : *dnsResponse.ids.d_extendedErrors) {
-      dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.infoCode, ede.extraText, ede.clearExisting);
+      dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.error.infoCode, ede.error.extraText, ede.clearExisting);
     }
   }
 
@@ -1407,7 +1407,7 @@ static bool prepareOutgoingResponse([[maybe_unused]] const ClientState& clientSt
 
   if (dnsResponse.ids.d_extendedErrors) {
     for (auto ede : *dnsResponse.ids.d_extendedErrors) {
-      dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.infoCode, ede.extraText, ede.clearExisting);
+      dnsdist::edns::addExtendedDNSError(dnsResponse.getMutableData(), dnsResponse.getMaximumSize(), ede.error.infoCode, ede.error.extraText, ede.clearExisting);
     }
   }
 
index 216c9733e789e0a789d91f9672f760b897be6339..7c067a0f52100dbca0dde1716ba308982c258ee5 100644 (file)
@@ -61,7 +61,6 @@ struct EDNSExtendedError
   };
   uint16_t infoCode;
   std::string extraText;
-  bool clearExisting = true;
 };
 
 bool getEDNSExtendedErrorOptFromString(const char* option, unsigned int len, EDNSExtendedError& eee);