]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: add SetEDNSOptionResponseAction
authorSamir Aguiar <sjorgedeaguiar@netskope.com>
Tue, 27 May 2025 15:43:43 +0000 (15:43 +0000)
committerSamir Aguiar <sjorgedeaguiar@netskope.com>
Wed, 28 May 2025 14:49:14 +0000 (14:49 +0000)
pdns/dnsdistdist/dnsdist-actions-factory.cc
pdns/dnsdistdist/dnsdist-console.cc
pdns/dnsdistdist/dnsdist-response-actions-definitions.yml
pdns/dnsdistdist/docs/reference/actions.rst

index 3dacade3b10234c0e052f3191b5d426439d3d2c7..c4806ff7d653db6abb4532426379b289d8f4637a 100644 (file)
@@ -1032,6 +1032,31 @@ private:
   std::string d_data;
 };
 
+class SetEDNSOptionResponseAction : public DNSResponseAction
+{
+public:
+  // this action does not stop the processing
+  SetEDNSOptionResponseAction(uint16_t code, std::string data) :
+    d_code(code), d_data(std::move(data))
+  {
+  }
+
+  DNSResponseAction::Action operator()(DNSResponse* response, std::string* ruleresult) const override
+  {
+    setEDNSOption(*response, d_code, d_data);
+    return Action::None;
+  }
+
+  [[nodiscard]] std::string toString() const override
+  {
+    return "add EDNS Option to response (code=" + std::to_string(d_code) + ")";
+  }
+
+private:
+  uint16_t d_code;
+  std::string d_data;
+};
+
 class SetNoRecurseAction : public DNSAction
 {
 public:
index 8459bb6754833eca48e0341533481f06a6e1a7c8..41bdc52aebb39aedb41688fd09ddcc9b04554abd 100644 (file)
@@ -830,6 +830,7 @@ static const std::vector<dnsdist::console::ConsoleKeyword> s_consoleKeywords{
   {"SetECSPrefixLengthAction", true, "v4, v6", "Set the ECS prefix length. Subsequent rules are processed after this action"},
   {"SetMacAddrAction", true, "option", "Add the source MAC address to the query as EDNS0 option option. This action is currently only supported on Linux. Subsequent rules are processed after this action"},
   {"SetEDNSOptionAction", true, "option, data", "Add arbitrary EDNS option and data to the query. Subsequent rules are processed after this action"},
+  {"SetEDNSOptionResponseAction", true, "option, data", "Add arbitrary EDNS option and data to the response. Subsequent rules are processed after this action"},
   {"SetExtendedDNSErrorAction", true, "infoCode [, extraText]", "Set an Extended DNS Error status that will be added to the response corresponding to the current query. Subsequent rules are processed after this action"},
   {"SetExtendedDNSErrorResponseAction", true, "infoCode [, extraText]", "Set an Extended DNS Error status that will be added to this response. Subsequent rules are processed after this action"},
   {"SetNoRecurseAction", true, "", "strip RD bit from the question, let it go through"},
index 1c9c54a281de777fa0582129de1c59bba4c5788c..ae156bd75d736fe3f221630c1a0f1480e20b75a4 100644 (file)
@@ -172,6 +172,16 @@ The function will be invoked in a per-thread Lua state, without access to the gl
       type: "Vec<ProtoBufMetaConfiguration>"
       default: true
       description: "A list of ``name``=``key`` pairs, for meta-data to be added to Protocol Buffer message"
+- name: "SetEDNSOption"
+  description: "Add arbitrary EDNS option and data to the response. Any existing EDNS content with the same option code will be overwritten. Subsequent rules are processed after this action"
+  skip-rust: true
+  parameters:
+    - name: "code"
+      type: "u32"
+      description: "The EDNS option number"
+    - name: "data"
+      type: "String"
+      description: "The EDNS0 option raw content"
 - name: "SetExtendedDNSError"
   description: "Set an Extended DNS Error status that will be added to the response. Subsequent rules are processed after this action"
   parameters:
index 8b5bdefc13e9be868ff38d6b224a45267e66f344..31b74c2031e30c2dc768c3b932909dce75f7c963 100644 (file)
@@ -593,6 +593,16 @@ The following actions exist.
   :param int option: The EDNS option number
   :param string data: The EDNS0 option raw content
 
+.. function:: SetEDNSOptionResponseAction(option)
+
+  .. versionadded:: 1.9.11
+
+  Add arbitrary EDNS option and data to the response. Any existing EDNS content with the same option code will be overwritten.
+  Subsequent rules are processed after this action.
+
+  :param int option: The EDNS option number
+  :param string data: The EDNS0 option raw content
+
 .. function:: SetExtendedDNSErrorAction(infoCode [, extraText])
 
   .. versionadded:: 1.9.0