]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add more DNSName and SuffixMatchNode Lua bindings 11698/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 15 Jun 2022 12:16:35 +0000 (14:16 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Wed, 15 Jun 2022 13:43:11 +0000 (15:43 +0200)
pdns/dnsdist-lua-bindings.cc
pdns/dnsdistdist/docs/reference/config.rst
pdns/dnsdistdist/docs/reference/dnsname.rst

index 74e73294006eeeecba71cec0c2492328cdcc88b4..f43b02a7adf420ce67a3646e2089c89e5c79aff9 100644 (file)
@@ -242,8 +242,10 @@ void setupLuaBindings(LuaContext& luaCtx, bool client)
   luaCtx.registerFunction<size_t(DNSName::*)()const>("wirelength", [](const DNSName& name) { return name.wirelength(); });
   luaCtx.registerFunction<string(DNSName::*)()const>("tostring", [](const DNSName&dn ) { return dn.toString(); });
   luaCtx.registerFunction<string(DNSName::*)()const>("toString", [](const DNSName&dn ) { return dn.toString(); });
+  luaCtx.registerFunction<string(DNSName::*)()const>("toStringNoDot", [](const DNSName&dn ) { return dn.toStringNoDot(); });
   luaCtx.registerFunction<string(DNSName::*)()const>("__tostring", [](const DNSName&dn ) { return dn.toString(); });
   luaCtx.registerFunction<string(DNSName::*)()const>("toDNSString", [](const DNSName&dn ) { return dn.toDNSString(); });
+  luaCtx.registerFunction<DNSName(DNSName::*)(const DNSName&)const>("makeRelative", [](const DNSName& dn, const DNSName& to) { return dn.makeRelative(to); });
   luaCtx.writeFunction("newDNSName", [](const std::string& name) { return DNSName(name); });
   luaCtx.writeFunction("newDNSNameFromRaw", [](const std::string& name) { return DNSName(name.c_str(), name.size(), 0, false); });
   luaCtx.writeFunction("newSuffixMatchNode", []() { return SuffixMatchNode(); });
@@ -317,7 +319,15 @@ void setupLuaBindings(LuaContext& luaCtx, bool client)
       }
   });
 
-  luaCtx.registerFunction("check",(bool (SuffixMatchNode::*)(const DNSName&) const) &SuffixMatchNode::check);
+  luaCtx.registerFunction("check", (bool (SuffixMatchNode::*)(const DNSName&) const) &SuffixMatchNode::check);
+  luaCtx.registerFunction<boost::optional<DNSName> (SuffixMatchNode::*)(const DNSName&) const>("getBestMatch", [](const SuffixMatchNode& smn, const DNSName& needle) {
+    boost::optional<DNSName> result{boost::none};
+    auto res = smn.getBestMatch(needle);
+    if (res) {
+      result = *res;
+    }
+    return result;
+  });
 #endif /* DISABLE_SUFFIX_MATCH_BINDINGS */
 
 #ifndef DISABLE_NETMASK_BINDINGS
index 2b3f6774394c7250d922aece27d0869d011b3fff..0b548086b95d115624d042eea2c5bb421657f994 100644 (file)
@@ -1590,6 +1590,20 @@ If you are looking for exact name matching, your might want to consider using a
     :param string name: The suffix to add to the set.
     :param table name: The suffixes to add to the set. Elements of the table should be of the same type, either DNSName or string.
 
+  .. method:: SuffixMatchNode:check(name) -> bool
+
+    Return true if the given name is a sub-domain of one of those in the set, and false otherwise.
+
+    :param DNSName name: The name to test against the set.
+
+  .. method:: SuffixMatchNode:getBestMatch(name) -> DNSName
+
+    .. versionadded:: 1.8.0
+
+    Returns the best match for the supplied name, or nil if there was no match.
+
+    :param DNSName name: The name to look up.
+
   .. method:: SuffixMatchNode:remove(name)
 
     .. versionadded:: 1.5.0
@@ -1600,12 +1614,6 @@ If you are looking for exact name matching, your might want to consider using a
     :param string name: The suffix to remove from the set.
     :param table name: The suffixes to remove from the set. Elements of the table should be of the same type, either DNSName or string.
 
-  .. method:: SuffixMatchNode:check(name) -> bool
-
-    Return true if the given name is a sub-domain of one of those in the set, and false otherwise.
-
-    :param DNSName name: The name to test against the set.
-
 Outgoing TLS tickets cache management
 -------------------------------------
 
index 6bb13099cd2de36b71d4bc5e26862239365db45b..01b894299a08655e94cf12f46e76418089412dba 100644 (file)
@@ -50,6 +50,17 @@ Functions and methods of a ``DNSName``
 
     :param DNSName name: The name to check against
 
+  .. method:: DNSName:makeRelative(name) -> DNSName
+
+    .. versionadded:: 1.8.0
+
+    Provided that the current name is part of the supplied name, returns a new DNSName
+    composed only of the labels that are below the supplied name (ie making www.powerdns.com
+    relative to powerdns.com would return only wwww)
+    Otherwise an empty (unset) DNSName is returned.
+
+    :param DNSName name: The name to make us relative against
+
   .. method:: DNSName:toDNSString() -> string
 
     Returns a wire format form of the DNSName, suitable for usage in :func:`SpoofRawAction`.
@@ -59,6 +70,12 @@ Functions and methods of a ``DNSName``
 
     Returns a human-readable form of the DNSName.
 
+  .. method:: DNSName:toStringNoDot() -> string
+
+    .. versionadded:: 1.8.0
+
+    Returns a human-readable form of the DNSName, without the trailing dot.
+
   .. method:: DNSName:wirelength() -> int
 
     Returns the length in bytes of the DNSName as it would be on the wire.