From 06802c55546c404c9ecf02f561b9da3fc22c15af Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 26 Aug 2016 12:06:17 +0200 Subject: [PATCH] rec: Fix doc for ComboAddress/Netmask Lua bindings, add missing ones --- docs/markdown/recursor/scripting.md | 22 ++++++++++++++++++++-- pdns/lua-recursor4.cc | 9 ++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/docs/markdown/recursor/scripting.md b/docs/markdown/recursor/scripting.md index 49682cd5b..8e2ac6a2f 100644 --- a/docs/markdown/recursor/scripting.md +++ b/docs/markdown/recursor/scripting.md @@ -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. diff --git a/pdns/lua-recursor4.cc b/pdns/lua-recursor4.cc index 2f2bc05fd..81525eef3 100644 --- a/pdns/lua-recursor4.cc +++ b/pdns/lua-recursor4.cc @@ -263,6 +263,8 @@ RecursorLua4::RecursorLua4(const std::string& fname) return DNSName(boost::get(dom)); }); d_lw->registerFunction("isPartOf", &DNSName::isPartOf); + d_lw->registerFunction("countLabels", &DNSName::countLabels); + d_lw->registerFunction("wirelength", &DNSName::wirelength); d_lw->registerFunction( "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("isIPv4", [](const ComboAddress& ca) { return ca.sin4.sin_family == AF_INET; }); + d_lw->registerFunction("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 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("getNetwork", [](const Netmask& nm) { return nm.getNetwork(); } ); // const reference makes this necessary d_lw->registerFunction("getMaskedNetwork", [](const Netmask& nm) { return nm.getMaskedNetwork(); } ); d_lw->registerFunction("isIpv4", &Netmask::isIpv4); -- 2.40.0