From: Samir Aguiar Date: Sat, 17 May 2025 19:40:09 +0000 (+0000) Subject: Patch 5: support setting NSID option (SNA-20345) X-Git-Tag: dnsdist-1.9.11~8^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=700b14b956b196233000a6ff62c76b81f9deb26b;p=thirdparty%2Fpdns.git Patch 5: support setting NSID option (SNA-20345) To ease debugging behind anycast, add support to dnsdist for returning an identifier of the POP that is handling the request. This commit introduces a new ``SetEDNSOptionResponseAction`` action that works similarly to ``SetEDNSOptionAction``, but that can be used for responses. Example: addResponseAction( EDNSOptionRule(EDNSOptionCode.NSID), SetEDNSOptionResponseAction(EDNSOptionCode.NSID, "foobar") ) In the above, the NSID option will be set when the question has this bit set. Note that it will override what is sent by the DNS server. --- diff --git a/pdns/dnsdist-lua-actions.cc b/pdns/dnsdist-lua-actions.cc index c963434f25..f5cd99aa11 100644 --- a/pdns/dnsdist-lua-actions.cc +++ b/pdns/dnsdist-lua-actions.cc @@ -1101,6 +1101,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 (code=" + std::to_string(d_code) + ")"; + } + +private: + uint16_t d_code; + std::string d_data; +}; + class SetNoRecurseAction : public DNSAction { public: @@ -1856,7 +1881,6 @@ private: std::optional d_exportExtendedErrorsToMeta{std::nullopt}; bool d_includeCNAME; }; - #endif /* DISABLE_PROTOBUF */ class DropResponseAction : public DNSResponseAction @@ -2510,6 +2534,10 @@ void setupLuaActions(LuaContext& luaCtx) return std::shared_ptr(new SetEDNSOptionAction(code, data)); }); + luaCtx.writeFunction("SetEDNSOptionResponseAction", [](int code, const std::string& data) { + return std::shared_ptr(new SetEDNSOptionResponseAction(code, data)); + }); + luaCtx.writeFunction("PoolAction", [](const std::string& poolname, boost::optional stopProcessing) { return std::shared_ptr(new PoolAction(poolname, stopProcessing ? *stopProcessing : true)); });