From: Remi Gacogne Date: Thu, 11 Jun 2026 09:10:15 +0000 (+0200) Subject: dnsdist: Add "ByName" support for YAML actions X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7843863d90ab71e5a41bf64d978888817c0a8741;p=thirdparty%2Fpdns.git dnsdist: Add "ByName" support for YAML actions Signed-off-by: Remi Gacogne --- diff --git a/pdns/dnsdistdist/dnsdist-actions-definitions.yml b/pdns/dnsdistdist/dnsdist-actions-definitions.yml index 3fa2d3bbcd..f530f3e4ce 100644 --- a/pdns/dnsdistdist/dnsdist-actions-definitions.yml +++ b/pdns/dnsdistdist/dnsdist-actions-definitions.yml @@ -1,6 +1,16 @@ --- - name: "allow" description: "Let these packets go through" +- name: "ByName" + skip-cpp: true + skip-rust: true + no-lua-equivalent: true + description: "References an already declared action by its name" + version_added: 2.2.0 + parameters: + - name: "action_name" + type: "String" + descripton: "The action name" - name: "continue" description: "Execute the specified action and override its return with None, making it possible to continue the processing. Subsequent rules are processed after this action" skip-cpp: true diff --git a/pdns/dnsdistdist/dnsdist-configuration-yaml.cc b/pdns/dnsdistdist/dnsdist-configuration-yaml.cc index 19b164ec27..13ef7a4a00 100644 --- a/pdns/dnsdistdist/dnsdist-configuration-yaml.cc +++ b/pdns/dnsdistdist/dnsdist-configuration-yaml.cc @@ -2125,6 +2125,24 @@ std::shared_ptr getByNameSelector(const ByNameSelectorConfiguration return ptr; } +std::shared_ptr getByNameAction(const ByNameActionConfiguration& config) +{ + auto ptr = dnsdist::configuration::yaml::getRegisteredTypeByName(config.action_name); + if (!ptr) { + throw std::runtime_error("Unable to find an action named " + std::string(config.action_name)); + } + return ptr; +} + +std::shared_ptr getByNameResponseAction(const ByNameResponseActionConfiguration& config) +{ + auto ptr = dnsdist::configuration::yaml::getRegisteredTypeByName(config.action_name); + if (!ptr) { + throw std::runtime_error("Unable to find an action named " + std::string(config.action_name)); + } + return ptr; +} + #include "dnsdist-rust-bridge-actions-generated-body.hh" #include "dnsdist-rust-bridge-selectors-generated-body.hh" } diff --git a/pdns/dnsdistdist/dnsdist-response-actions-definitions.yml b/pdns/dnsdistdist/dnsdist-response-actions-definitions.yml index b4c9aa5a0d..2dd48e8ad3 100644 --- a/pdns/dnsdistdist/dnsdist-response-actions-definitions.yml +++ b/pdns/dnsdistdist/dnsdist-response-actions-definitions.yml @@ -1,6 +1,16 @@ --- - name: "allow" description: "Let these packets go through." +- name: "ByName" + skip-cpp: true + skip-rust: true + no-lua-equivalent: true + description: "References an already declared action by its name" + version_added: 2.2.0 + parameters: + - name: "action_name" + type: "String" + descripton: "The action name" - name: "ClearRecordTypes" description: "Removes given type(s) records from the response. Beware you can accidentally turn the answer into a NODATA response without a SOA record in the additional section in which case you may want to use NegativeAndSOAAction() to generate an answer, see example below. Subsequent rules are processed after this action." skip-cpp: true diff --git a/regression-tests.dnsdist/test_Yaml.py b/regression-tests.dnsdist/test_Yaml.py index 7307077759..8e737a44b7 100644 --- a/regression-tests.dnsdist/test_Yaml.py +++ b/regression-tests.dnsdist/test_Yaml.py @@ -76,6 +76,23 @@ query_rules: action: type: "Pool" pool_name: "tcp-pool" + - name: "reply notimp to notimp1" + selector: + type: "QNameSet" + qnames: + - "notimp1.yaml.test.powerdns.com." + action: + name: "reply-with-notimp" + type: "RCode" + rcode: "NotImp" + - name: "reply notimp to notimp2" + selector: + type: "QNameSet" + qnames: + - "notimp2.yaml.test.powerdns.com." + action: + type: "ByName" + action_name: "reply-with-notimp" response_rules: - name: "inline RD=0 TCP gets cleared" @@ -193,6 +210,17 @@ response_rules: self.assertEqual(receivedQuery, query) self.assertEqual(receivedResponse, response) + def testActionByName(self): + """ + Yaml: Action by name + """ + for name in ["notimp1.yaml.test.powerdns.com.", "notimp2.yaml.test.powerdns.com."]: + query = dns.message.make_query(name, "A", "IN") + query.flags &= ~dns.flags.RD + response = dns.message.make_response(query) + response.set_rcode(dns.rcode.NOTIMP) + (_, receivedResponse) = self.sendUDPQuery(query, response=None, useQueue=False) + self.assertEqual(receivedResponse, response) class TestMixingYamlWithLua(DNSDistTest): _yaml_config_template = """---