]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
chore(dnsdist): stop boost::optional to std::optional conversions in generated code
authorPieter Lexis <pieter.lexis@powerdns.com>
Thu, 13 Nov 2025 12:55:27 +0000 (13:55 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Fri, 28 Nov 2025 12:39:35 +0000 (13:39 +0100)
pdns/dnsdistdist/dnsdist-actions-definitions.yml
pdns/dnsdistdist/dnsdist-lua-actions.cc
pdns/dnsdistdist/dnsdist-lua-rules.cc
pdns/dnsdistdist/dnsdist-response-actions-definitions.yml
pdns/dnsdistdist/dnsdist-rules-generator.py

index 055dac87effac3fe528e8edfd24e5e2c01519894..a9ea1c3ca690fa807978a6c177bbb926ae74fd92 100644 (file)
@@ -118,32 +118,32 @@ Subsequent rules are processed after this action"
     - name: "file_name"
       type: "String"
       default: ""
-      cpp-optional: false
+      optional: false
       description: "File to log to. Set to an empty string to log to the normal stdout log, this only works when ``-v`` is set on the command line"
     - name: "binary"
       type: "bool"
       default: "true"
-      cpp-optional: false
+      optional: false
       description: "Whether to do binary logging"
     - name: "append"
       type: "bool"
       default: "false"
-      cpp-optional: false
+      optional: false
       description: "Whether to append to an existing file"
     - name: "buffered"
       type: "bool"
       default: "false"
-      cpp-optional: false
+      optional: false
       description: "Whether to use buffered I/O"
     - name: "verbose_only"
       type: "bool"
       default: "true"
-      cpp-optional: false
+      optional: false
       description: "Whether to log only in verbose mode when logging to stdout"
     - name: "include_timestamp"
       type: "bool"
       default: "false"
-      cpp-optional: false
+      optional: false
       description: "Whether to include a timestamp for every entry"
 - name: "lua"
   description: "Invoke a Lua function that accepts a :class:`DNSQuestion`. The function should return a :ref:`DNSAction`. If the Lua code fails, ``ServFail`` is returned"
@@ -230,7 +230,7 @@ The function will be invoked in a per-thread Lua state, without access to the gl
     - name: "stop_processing"
       type: "bool"
       default: "true"
-      cpp-optional: false
+      optional: false
       description: "Whether subsequent rules should be executed after this one"
 - name: "QPS"
   description: "Drop a packet if it does exceed the ``limit`` queries per second limit. Letting the subsequent rules apply otherwise"
@@ -250,7 +250,7 @@ The function will be invoked in a per-thread Lua state, without access to the gl
     - name: "stop_processing"
       type: "bool"
       default: "true"
-      cpp-optional: false
+      optional: false
       description: "Whether subsequent rules should be executed after this one"
 - name: "RCode"
   description: "Reply immediately by turning the query into a response with the specified rcode"
@@ -332,7 +332,7 @@ are processed after this action"
       type: "String"
       default: ""
       description: "The IPv6 netmask, if any"
-      cpp-optional: false
+      optional: false
 - name: "SetECSOverride"
   description: "Whether an existing EDNS Client Subnet value should be overridden (true) or not (false). Subsequent rules are processed after this action"
   parameters:
@@ -357,7 +357,7 @@ are processed after this action"
     - name: "extra_text"
       type: "String"
       default: ""
-      cpp-optional: false
+      optional: false
       description: "The optional EDNS Extended DNS Error extra text"
 - name: "SetMacAddr"
   description: "Add the source MAC address to the query as an EDNS0 option. This action is currently only supported on Linux. Subsequent rules are processed after this action"
@@ -420,7 +420,7 @@ are processed after this action"
     - name: "reason"
       type: "String"
       default: ""
-      cpp-optional: false
+      optional: false
       description: "The SNMP trap reason"
 - name: "Spoof"
   description: "Forge a response with the specified IPv4 (for an A query) or IPv6 (for an AAAA) addresses. If you specify multiple addresses, all that match the query type (A, AAAA or ANY) will get spoofed in"
index f79ec1b480d611ddb691af76d38c9b353593cb4c..73a2ed4d23c1bc03b1c43a66b3c4be9dc89235cf 100644 (file)
@@ -54,12 +54,6 @@ static std::vector<T> convertLuaArrayToRegular(const LuaArray<T>& luaArray)
   return out;
 }
 
-template <class T>
-std::optional<T> boostToStandardOptional(const std::optional<T>& boostOpt)
-{
-  return boostOpt ? *boostOpt : std::optional<T>();
-}
-
 // NOLINTNEXTLINE(readability-function-cognitive-complexity): this function declares Lua bindings, even with a good refactoring it will likely blow up the threshold
 void setupLuaActions(LuaContext& luaCtx)
 {
index 30d5f0db82420d98a17b9a23465327b81f989a3d..23144e75298c331d83aa6341c28499c5ea38f889 100644 (file)
@@ -360,12 +360,6 @@ std::shared_ptr<DNSRule> qnameSuffixRule(const boost::variant<const SuffixMatchN
   const auto& smn = *boost::get<const SuffixMatchNode&>(&names);
   return std::shared_ptr<DNSRule>(new SuffixMatchNodeRule(smn, quiet ? *quiet : false));
 }
-
-template <class T>
-std::optional<T> boostToStandardOptional(const std::optional<T>& boostOpt)
-{
-  return boostOpt ? *boostOpt : std::optional<T>();
-}
 }
 
 void setupLuaRuleChainsManagement(LuaContext& luaCtx)
index f9959dfe0844c471079ae361f2514c1e7fa8f894..ff07440188e150acb8e23ca6faebfcb9fa0243e6 100644 (file)
@@ -65,27 +65,27 @@ Subsequent rules are processed after this action"
     - name: "file_name"
       type: "String"
       default: ""
-      cpp-optional: false
+      optional: false
       description: "File to log to. Set to an empty string to log to the normal stdout log, this only works when ``-v`` is set on the command line"
     - name: "append"
       type: "bool"
       default: "false"
-      cpp-optional: false
+      optional: false
       description: "Whether to append to an existing file"
     - name: "buffered"
       type: "bool"
       default: "false"
-      cpp-optional: false
+      optional: false
       description: "Whether to use buffered I/O"
     - name: "verbose_only"
       type: "bool"
       default: "true"
-      cpp-optional: false
+      optional: false
       description: "Whether to log only in verbose mode when logging to stdout"
     - name: "include_timestamp"
       type: "bool"
       default: "false"
-      cpp-optional: false
+      optional: false
       description: "Whether to include a timestamp for every entry"
 - name: "lua"
   description: "Invoke a Lua function that accepts a :class:`DNSResponse`. The function should return a :ref:`DNSResponseAction`. If the Lua code fails, ``ServFail`` is returned"
@@ -201,7 +201,7 @@ The function will be invoked in a per-thread Lua state, without access to the gl
     - name: "extra_text"
       type: "String"
       default: ""
-      cpp-optional: false
+      optional: false
       description: "The optional EDNS Extended DNS Error extra text"
 - name: "SetMaxReturnedTTL"
   description: "Cap the TTLs of the response to the given maximum, but only after inserting the response into the packet cache with the initial TTL values"
@@ -249,7 +249,7 @@ The function will be invoked in a per-thread Lua state, without access to the gl
     - name: "reason"
       type: "String"
       default: ""
-      cpp-optional: false
+      optional: false
       description: "The SNMP trap reason"
 - name: "TC"
   description: "Truncate an existing answer, to force the client to TCP. Only applied to answers that will be sent to the client over TCP. In addition to the TC bit being set, all records are removed from the answer, authority and additional sections"
index 885ad23205960e03eb9061036379d68bc554843a..be46a338585ea1dedcfa451de36762eaa8532de0 100644 (file)
@@ -97,8 +97,8 @@ def get_cpp_parameters_definition(parameters, lua_interface):
         if 'default' in parameter:
             if lua_interface:
                 ptype = type_to_cpp(parameter['type'], lua_interface, True)
-                ptype = f'boost::optional<{ptype}>'
-            elif not 'cpp-optional' in parameter or parameter['cpp-optional']:
+                ptype = f'std::optional<{ptype}>'
+            elif not 'optional' in parameter or parameter['optional']:
                 ptype = type_to_cpp(parameter['type'], lua_interface, True)
                 ptype = f'std::optional<{ptype}>'
         if len(output) > 0:
@@ -117,17 +117,12 @@ def get_cpp_parameters(parameters, lua_interface):
             output += f'{pname}'
             continue
 
-        cpp_optional = not 'cpp-optional' in parameter or parameter['cpp-optional']
-        if lua_interface and not cpp_optional:
+        optional = not 'optional' in parameter or parameter['optional']
+        if lua_interface and not optional:
             # We are the Lua binding, and the factory does not handle optional values
             # -> pass the value if any, and the default otherwise
             default = parameter['default']
-        elif lua_interface and cpp_optional:
-            # we are the Lua binding, the factory does handle optional values,
-            # -> boost::optional to std::optional
-            output += f'boostToStandardOptional({pname})'
-            continue
-        elif not lua_interface and cpp_optional:
+        elif not lua_interface and optional:
             # We are the C++ factory and we do handle optional values
             # -> pass the value if any, and the default otherwise
             default = parameter['default']