]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Make `setEDNSOption` usable for responses
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 30 May 2025 09:42:32 +0000 (11:42 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 30 May 2025 09:44:27 +0000 (11:44 +0200)
Without this change dnsdist removed the EDNS payload later in the
processing of the response.

pdns/dnsdistdist/dnsdist-actions-factory.cc
pdns/dnsdistdist/dnsdist-ecs.cc
pdns/dnsdistdist/dnsdist-ecs.hh

index c4806ff7d653db6abb4532426379b289d8f4637a..ec14364129f5c3a2bc4945674adda9e431b7efeb 100644 (file)
@@ -1018,7 +1018,7 @@ public:
   DNSAction::Action operator()(DNSQuestion* dnsquestion, std::string* ruleresult) const override
   {
     (void)ruleresult;
-    setEDNSOption(*dnsquestion, d_code, d_data);
+    setEDNSOption(*dnsquestion, d_code, d_data, true);
     return Action::None;
   }
 
@@ -1041,9 +1041,9 @@ public:
   {
   }
 
-  DNSResponseAction::Action operator()(DNSResponse* response, std::string* ruleresult) const override
+  DNSResponseAction::Action operator()(DNSResponse* response, [[maybe_unused]] std::string* ruleresult) const override
   {
-    setEDNSOption(*response, d_code, d_data);
+    setEDNSOption(*response, d_code, d_data, false);
     return Action::None;
   }
 
index dc6b31cb88dec18710ff5790fb4bb8984562b619..c8cc4f6585f6443a505a70a529f555a3d8666ae3 100644 (file)
@@ -1163,7 +1163,7 @@ bool getEDNS0Record(const PacketBuffer& packet, EDNS0Record& edns0)
   return true;
 }
 
-bool setEDNSOption(DNSQuestion& dnsQuestion, uint16_t ednsCode, const std::string& ednsData)
+bool setEDNSOption(DNSQuestion& dnsQuestion, uint16_t ednsCode, const std::string& ednsData, bool isQuery)
 {
   std::string optRData;
   generateEDNSOption(ednsCode, ednsData, optRData);
@@ -1183,7 +1183,7 @@ bool setEDNSOption(DNSQuestion& dnsQuestion, uint16_t ednsCode, const std::strin
     }
 
     dnsQuestion.getMutableData() = std::move(newContent);
-    if (!dnsQuestion.ids.ednsAdded && ednsAdded) {
+    if (isQuery && !dnsQuestion.ids.ednsAdded && ednsAdded) {
       dnsQuestion.ids.ednsAdded = true;
     }
 
@@ -1196,8 +1196,11 @@ bool setEDNSOption(DNSQuestion& dnsQuestion, uint16_t ednsCode, const std::strin
       header.arcount = htons(1);
       return true;
     });
-    // make sure that any EDNS sent by the backend is removed before forwarding the response to the client
-    dnsQuestion.ids.ednsAdded = true;
+
+    if (isQuery) {
+      // make sure that any EDNS sent by the backend is removed before forwarding the response to the client
+      dnsQuestion.ids.ednsAdded = true;
+    }
   }
 
   return true;
index 0c6a4780ed29e1427099c9316b66d6ea19bb08ca..e48da6d677122bd4aebabb2621e184316f483c6e 100644 (file)
@@ -51,7 +51,7 @@ bool parseEDNSOptions(const DNSQuestion& dnsQuestion);
 bool queryHasEDNS(const DNSQuestion& dnsQuestion);
 bool getEDNS0Record(const PacketBuffer& packet, EDNS0Record& edns0);
 
-bool setEDNSOption(DNSQuestion& dnsQuestion, uint16_t ednsCode, const std::string& data);
+bool setEDNSOption(DNSQuestion& dnsQuestion, uint16_t ednsCode, const std::string& data, bool isQuery = true);
 
 struct InternalQueryState;
 namespace dnsdist