From: Samir Aguiar Date: Tue, 27 May 2025 15:43:43 +0000 (+0000) Subject: dnsdist: add SetEDNSOptionResponseAction X-Git-Tag: dnsdist-2.0.0-beta1~47^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=61f1b7cb77b225a2f8ce4a39be77003f61e88c20;p=thirdparty%2Fpdns.git dnsdist: add SetEDNSOptionResponseAction --- diff --git a/pdns/dnsdistdist/dnsdist-actions-factory.cc b/pdns/dnsdistdist/dnsdist-actions-factory.cc index 3dacade3b1..c4806ff7d6 100644 --- a/pdns/dnsdistdist/dnsdist-actions-factory.cc +++ b/pdns/dnsdistdist/dnsdist-actions-factory.cc @@ -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: diff --git a/pdns/dnsdistdist/dnsdist-console.cc b/pdns/dnsdistdist/dnsdist-console.cc index 8459bb6754..41bdc52aeb 100644 --- a/pdns/dnsdistdist/dnsdist-console.cc +++ b/pdns/dnsdistdist/dnsdist-console.cc @@ -830,6 +830,7 @@ static const std::vector 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"}, diff --git a/pdns/dnsdistdist/dnsdist-response-actions-definitions.yml b/pdns/dnsdistdist/dnsdist-response-actions-definitions.yml index 1c9c54a281..ae156bd75d 100644 --- a/pdns/dnsdistdist/dnsdist-response-actions-definitions.yml +++ b/pdns/dnsdistdist/dnsdist-response-actions-definitions.yml @@ -172,6 +172,16 @@ The function will be invoked in a per-thread Lua state, without access to the gl type: "Vec" 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: diff --git a/pdns/dnsdistdist/docs/reference/actions.rst b/pdns/dnsdistdist/docs/reference/actions.rst index 8b5bdefc13..31b74c2031 100644 --- a/pdns/dnsdistdist/docs/reference/actions.rst +++ b/pdns/dnsdistdist/docs/reference/actions.rst @@ -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