]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Handle named rcodes in all YAML configuration items
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 10 Jul 2025 13:31:54 +0000 (15:31 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 10 Jul 2025 13:34:57 +0000 (15:34 +0200)
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
pdns/dnsdistdist/dnsdist-actions-definitions.yml
pdns/dnsdistdist/dnsdist-rules-generator.py
pdns/dnsdistdist/dnsdist-rust-lib/dnsdist-settings-generator.py
pdns/dnsdistdist/dnsdist-selectors-definitions.yml
pdns/dnsdistdist/docs/upgrade_guide.rst
regression-tests.dnsdist/test_DOH.py
regression-tests.dnsdist/test_DOH3.py
regression-tests.dnsdist/test_DOQ.py
regression-tests.dnsdist/test_Yaml.py

index dd6073fae28659107e4be605c5dbef7757f29364..32e36556bfcaca5a1c3b1a82a8912a43e8bde73a 100644 (file)
@@ -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"
index c62922651c5eac0a08720d77118fae9a0e0ad006..f627a9959a2f454efc128dba41bbae0196bba39f 100644 (file)
@@ -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):
index 15c3a1e50081d57c456e95d6420bb7f3fa69d2e0..74b9b6a9c1ad4bf0e26c000875bc10b9b52d917b 100644 (file)
@@ -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
 
index 2fb005499cfa61ae91a1e2e17b6ae127fbd16037..b957f42984997505c81f113a69eac1e85a0ad817 100644 (file)
@@ -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"
index b33aeeb69b37295f06322c582e552fbd3ae3f92a..941850016cca9bb5619a01bc6c424e40d36fc2c2 100644 (file)
@@ -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
 --------------
 
index e9da4d46cfcc19b60c77b9c605050a5ae284b35c..b07a5875c5035c751bd55ef2b53c9770289e3961 100644 (file)
@@ -816,7 +816,7 @@ query_rules:
       qname: "refused.doh.tests.powerdns.com."
     action:
       type: "RCode"
-      rcode: 5
+      rcode: "Refused"
   - name: "Spoof"
     selector:
       type: "QName"
index 7957fe860731aca033a9cac26db6378ff47896eb..d7f2c75c7b5ad7686688fbb0802b8a8385cfbc4a 100644 (file)
@@ -258,7 +258,7 @@ query_rules:
       qname: "refused.doq.tests.powerdns.com."
     action:
       type: "RCode"
-      rcode: 5
+      rcode: "Refused"
   - name: "Spoof"
     selector:
       type: "QName"
index 98d7711761c39330ee73cf8b3f3640a71691784a..7d7aacc681b969fdf9b596e44d3812545b5a7d74 100644 (file)
@@ -96,7 +96,7 @@ query_rules:
       qname: "refused.doq.tests.powerdns.com."
     action:
       type: "RCode"
-      rcode: 5
+      rcode: "5"
   - name: "Spoof"
     selector:
       type: "QName"
index 1abed07c2f87bf0d6661e08d7d0c38a35458929f..4e4e79f653a72fb32f29eb841c2fde6d7b6cdebc 100644 (file)
@@ -218,7 +218,7 @@ query_rules:
         - "refused.yaml-lua-mix.test.powerdns.com."
     action:
       type: "RCode"
-      rcode: 5
+      rcode: "Refused"
 
 """
     _dnsDistPort = pickAvailablePort()