From: Remi Gacogne Date: Thu, 10 Jul 2025 13:31:54 +0000 (+0200) Subject: dnsdist: Handle named rcodes in all YAML configuration items X-Git-Tag: rec-5.4.0-alpha0~36^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d442fb9443d7b89afd95f3f56e85d62931217841;p=thirdparty%2Fpdns.git dnsdist: Handle named rcodes in all YAML configuration items Signed-off-by: Remi Gacogne --- diff --git a/pdns/dnsdistdist/dnsdist-actions-definitions.yml b/pdns/dnsdistdist/dnsdist-actions-definitions.yml index dd6073fae2..32e36556bf 100644 --- a/pdns/dnsdistdist/dnsdist-actions-definitions.yml +++ b/pdns/dnsdistdist/dnsdist-actions-definitions.yml @@ -55,7 +55,8 @@ skip-cpp: true parameters: - name: "rcode" - type: "u8" + type: "RCode" + rust-type: "String" description: "The RCODE to respond with" - name: "vars" type: "ResponseConfig" @@ -256,7 +257,8 @@ The function will be invoked in a per-thread Lua state, without access to the gl skip-cpp: true parameters: - name: "rcode" - type: "u8" + type: "RCode" + rust-type: "String" description: "The response code" - name: "vars" type: "ResponseConfig" diff --git a/pdns/dnsdistdist/dnsdist-rules-generator.py b/pdns/dnsdistdist/dnsdist-rules-generator.py index c62922651c..f627a9959a 100644 --- a/pdns/dnsdistdist/dnsdist-rules-generator.py +++ b/pdns/dnsdistdist/dnsdist-rules-generator.py @@ -66,6 +66,8 @@ def type_to_cpp(type_str, lua_interface, inside_container=False): if inside_container: return 'std::string' return 'const std::string&' + if type_str == 'RCode': + return 'uint8_t' return type_str def get_cpp_object_name(name, is_class=True): diff --git a/pdns/dnsdistdist/dnsdist-rust-lib/dnsdist-settings-generator.py b/pdns/dnsdistdist/dnsdist-rust-lib/dnsdist-settings-generator.py index 15c3a1e500..74b9b6a9c1 100644 --- a/pdns/dnsdistdist/dnsdist-rust-lib/dnsdist-settings-generator.py +++ b/pdns/dnsdistdist/dnsdist-rust-lib/dnsdist-settings-generator.py @@ -498,6 +498,8 @@ def get_cpp_parameters(struct_name, parameters, skip_name): field = f'convertSVCRecordParameters({field})' elif ptype == 'SOAParams': field = f'convertSOAParams({field})' + elif ptype == 'RCode': + field = f'dnsdist::configuration::yaml::strToRCode("{struct_name}", "{name}", {field})' output += field return output diff --git a/pdns/dnsdistdist/dnsdist-selectors-definitions.yml b/pdns/dnsdistdist/dnsdist-selectors-definitions.yml index 2fb005499c..b957f42984 100644 --- a/pdns/dnsdistdist/dnsdist-selectors-definitions.yml +++ b/pdns/dnsdistdist/dnsdist-selectors-definitions.yml @@ -44,7 +44,8 @@ description: "Matches queries or responses with the specified rcode. The full 16bit RCode will be matched. If no EDNS OPT RR is present, the upper 12 bits are treated as 0" parameters: - name: "rcode" - type: "u64" + type: "RCode" + rust-type: "String" description: "The full 16bit RCode will be matched. If no EDNS OPT RR is present, the upper 12 bits are treated as 0" - name: "HTTPHeader" description: "Matches DNS over HTTPS queries with a HTTP header name whose content matches the supplied regular expression. It is necessary to set the ``keepIncomingHeaders`` to :func:`addDOHLocal()` to use this rule" @@ -347,7 +348,8 @@ Set the ``source`` parameter to ``false`` to match against destination address i description: "Matches queries or responses with the specified rcode" parameters: - name: "rcode" - type: "u64" + type: "RCode" + rust-type: "String" description: "The response code, as a numerical value" - name: "RD" description: "Matches queries with the RD flag set" diff --git a/pdns/dnsdistdist/docs/upgrade_guide.rst b/pdns/dnsdistdist/docs/upgrade_guide.rst index b33aeeb69b..941850016c 100644 --- a/pdns/dnsdistdist/docs/upgrade_guide.rst +++ b/pdns/dnsdistdist/docs/upgrade_guide.rst @@ -1,6 +1,11 @@ Upgrade Guide ============= +2.0.x to 2.1.0 +-------------- + +Since 2.1.0, ``rcode``s in the ``YAML`` configuration can be specified either by their case-insensitive names (e.g. ``refused``), or by their numerical values (e.g. ``"5"``). Unfortunately in some contexts (:func:`RCodeRule`, :func:`ERCodeRule`, :func:`RCodeAction` and :func:`ERCodeAction`) this has a the side-effect that a numerical value (``5``) is no longer accepted and has to be converted to a string (``"5"``). + 1.9.x to 2.0.0 -------------- diff --git a/regression-tests.dnsdist/test_DOH.py b/regression-tests.dnsdist/test_DOH.py index e9da4d46cf..b07a5875c5 100644 --- a/regression-tests.dnsdist/test_DOH.py +++ b/regression-tests.dnsdist/test_DOH.py @@ -816,7 +816,7 @@ query_rules: qname: "refused.doh.tests.powerdns.com." action: type: "RCode" - rcode: 5 + rcode: "Refused" - name: "Spoof" selector: type: "QName" diff --git a/regression-tests.dnsdist/test_DOH3.py b/regression-tests.dnsdist/test_DOH3.py index 7957fe8607..d7f2c75c7b 100644 --- a/regression-tests.dnsdist/test_DOH3.py +++ b/regression-tests.dnsdist/test_DOH3.py @@ -258,7 +258,7 @@ query_rules: qname: "refused.doq.tests.powerdns.com." action: type: "RCode" - rcode: 5 + rcode: "Refused" - name: "Spoof" selector: type: "QName" diff --git a/regression-tests.dnsdist/test_DOQ.py b/regression-tests.dnsdist/test_DOQ.py index 98d7711761..7d7aacc681 100644 --- a/regression-tests.dnsdist/test_DOQ.py +++ b/regression-tests.dnsdist/test_DOQ.py @@ -96,7 +96,7 @@ query_rules: qname: "refused.doq.tests.powerdns.com." action: type: "RCode" - rcode: 5 + rcode: "5" - name: "Spoof" selector: type: "QName" diff --git a/regression-tests.dnsdist/test_Yaml.py b/regression-tests.dnsdist/test_Yaml.py index 1abed07c2f..4e4e79f653 100644 --- a/regression-tests.dnsdist/test_Yaml.py +++ b/regression-tests.dnsdist/test_Yaml.py @@ -218,7 +218,7 @@ query_rules: - "refused.yaml-lua-mix.test.powerdns.com." action: type: "RCode" - rcode: 5 + rcode: "Refused" """ _dnsDistPort = pickAvailablePort()