]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Patch 5: support setting NSID option (SNA-20345)
authorSamir Aguiar <sjorgedeaguiar@netskope.com>
Sat, 17 May 2025 19:40:09 +0000 (19:40 +0000)
committerSamir Aguiar <sjorgedeaguiar@netskope.com>
Thu, 5 Jun 2025 14:40:08 +0000 (14:40 +0000)
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.

pdns/dnsdist-lua-actions.cc

index c963434f25462d21ad24ff6df0611970560a7194..f5cd99aa118f6fb63fa9519857ebb5bc8d1b2a41 100644 (file)
@@ -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<std::string> 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<DNSAction>(new SetEDNSOptionAction(code, data));
   });
 
+  luaCtx.writeFunction("SetEDNSOptionResponseAction", [](int code, const std::string& data) {
+    return std::shared_ptr<DNSResponseAction>(new SetEDNSOptionResponseAction(code, data));
+  });
+
   luaCtx.writeFunction("PoolAction", [](const std::string& poolname, boost::optional<bool> stopProcessing) {
     return std::shared_ptr<DNSAction>(new PoolAction(poolname, stopProcessing ? *stopProcessing : true));
   });