]> granicus.if.org Git - pdns/commitdiff
rec: Fix doc for ComboAddress/Netmask Lua bindings, add missing ones
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 26 Aug 2016 10:06:17 +0000 (12:06 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 26 Aug 2016 10:08:31 +0000 (12:08 +0200)
docs/markdown/recursor/scripting.md
pdns/lua-recursor4.cc

index 49682cd5b9645f4212a13665088baaa2a7d7e6d0..8e2ac6a2fd378b08d1f53e06ce1370d07c9de20d 100644 (file)
@@ -268,10 +268,26 @@ To convert an address to human-friendly representation, use `:toString()` or
 `:toStringWithPort()`. To get only the port number, use `:getPort()`.
 
 Other functions that can be called on a ComboAddress are:
+
+ * `isIPv4` - true if the address is an IPv4 address
+ * `isIPv6` - true if the address is an IPv6 address
+ * `getRaw` - returns the bytestring representing the address
+ * `isMappedIPv4` - true if the address is an IPv4 address mapped into an IPv6 one
+ * `mapToIPv4` - if the address is an IPv4 mapped into an IPv6 one, return the corresponding IPv4
+ * `truncate(bits)` - truncate to the supplied number of bits
+
+### Netmask
+IP addresses can be matched against a Netmask object, which can be created with
+`newNetmask("192.0.2.1/24")` and supports the following methods:
+
+ * `empty` - true if the netmask doesn't contain a valid address
+ * `getBits` - the number of bits in the address
+ * `getNetwork` - return a ComboAddress representing the network (no mask applied)
+ * `getMaskedNetwork` - return a ComboAddress representing the network (truncating according to the mask)
  * `isIpv4` - true if the address is an IPv4 address
  * `isIpv6` - true if the address is an IPv6 address
- * `getBits` - the number of bits in the address
- * `getRaw` - returns the bytestring representing the address
+ * `match(str)` - true if the address passed in str matches
+ * `toString` - human-friendly representation
 
 ### DNSName
 DNSNames are passed to various functions, and they sport the following methods:
@@ -280,6 +296,8 @@ DNSNames are passed to various functions, and they sport the following methods:
 * `:isPartOf`: returns true if a is a part of b. So: `newDN("www.powerdns.com"):isPartOf(newDN("CoM."))` returns true
 * `:toString` and `:toStringNoDot`: return a string representation of the name, with or without trailing dot.
 * `:chopOff`: removes the leftmost label from the name, returns true if this succeeded.
+* `:countLabels`: returns the number of labels
+* `:wirelength`: returns the length on the wire
 
 You can compare DNSNames using `:equal` or the `==` operator.
 
index 2f2bc05fd5d3add70c233025da9088ea3879eeeb..81525eef3a06120366dae9f0e0960d4ab792fb29 100644 (file)
@@ -263,6 +263,8 @@ RecursorLua4::RecursorLua4(const std::string& fname)
       return DNSName(boost::get<const DNSName>(dom));
   });
   d_lw->registerFunction("isPartOf", &DNSName::isPartOf);
+  d_lw->registerFunction("countLabels", &DNSName::countLabels);
+  d_lw->registerFunction("wirelength", &DNSName::wirelength);
   d_lw->registerFunction<bool(DNSName::*)(const std::string&)>(
     "equal",
      [](const DNSName& lhs, const std::string& rhs) {
@@ -281,6 +283,11 @@ RecursorLua4::RecursorLua4(const std::string& fname)
       else 
         return string((const char*)&ca.sin6.sin6_addr.s6_addr, 16);
     } );
+  d_lw->registerFunction<bool(ComboAddress::*)()>("isIPv4", [](const ComboAddress& ca) { return ca.sin4.sin_family == AF_INET; });
+  d_lw->registerFunction<bool(ComboAddress::*)()>("isIPv6", [](const ComboAddress& ca) { return ca.sin4.sin_family == AF_INET6; });
+  d_lw->registerFunction("isMappedIPv4", &ComboAddress::isMappedIPv4);
+  d_lw->registerFunction("mapToIPv4", &ComboAddress::mapToIPv4);
+  d_lw->registerFunction("truncate", &ComboAddress::truncate);
 
   d_lw->writeFunction("newCA", [](const std::string& a) { return ComboAddress(a); });
   typedef std::unordered_set<ComboAddress,ComboAddress::addressOnlyHash,ComboAddress::addressOnlyEqual> cas_t;
@@ -317,7 +324,7 @@ RecursorLua4::RecursorLua4(const std::string& fname)
     }
   );
   
-
+  d_lw->writeFunction("newNetmask", [](const string& s) { return Netmask(s); });
   d_lw->registerFunction<ComboAddress(Netmask::*)()>("getNetwork", [](const Netmask& nm) { return nm.getNetwork(); } ); // const reference makes this necessary
   d_lw->registerFunction<ComboAddress(Netmask::*)()>("getMaskedNetwork", [](const Netmask& nm) { return nm.getMaskedNetwork(); } );
   d_lw->registerFunction("isIpv4", &Netmask::isIpv4);