The DNSName object
------------------
-
-.. class:: DNSName
-
- A ``DNSName`` object represents a name in the DNS.
- It is returned by several functions and has several functions to programmatically interact with it.
+The PowerDNS Recursor's Lua engine has the notion of a :class:`DNSName`, an object that represents a name in the DNS.
+It is returned by several functions and has several functions to programmatically interact with it.
+:class:`DNSNames <DNSName>` can be compared agains each other using the :meth:`:equal <DNSName:equal>` function or the ``==`` operator.
+As names in the DNS are case-insensitive, ``www.powerdns.com`` is equal to ``Www.PowerDNS.cOM``.
Creating a :class:`DNSName` is done with :func:`newDN()`.
The PowerDNS Recursor will complain loudly if the name is invalid (e.g. too long, dot in the wrong place).
+A small example of the functionality of a :class:`DNSName` is shown below:
+
.. code-block:: lua
myname = newDN("www.example.com")
print(myname:wirelength()) -- prints "17"
name2 = newDN(myname)
name2:chopoff() -- returns true, as 'www' was stripped
+ print(name2:countLabels()) -- prints "2"
if myname:isPartOf(name2) then -- prints "it is"
print('it is')
end
-:class:`DNSNames <DNSName>` can be compared agains each other using the :meth:`:equal <DNSName:equal>` function or the ``==`` operator.
-
.. function:: newDN(name) -> DNSName
Returns the :class:`DNSName` object of ``name``.
:param string name: The name to create a DNSName for
-.. classmethod:: DNSName::chopOff() -> bool
+.. class:: DNSName
+
+ A ``DNSName`` object represents a name in the DNS.
+
+ .. method:: DNSName:chopOff() -> bool
- Removes the left-most label and returns ``true``.
- ``false`` is returned if no label was removed
+ Removes the left-most label and returns ``true``.
+ ``false`` is returned if no label was removed
-.. classmethod:: DNSName:countLabels() -> int
+ .. method:: DNSName:countLabels() -> int
- Returns the number of DNSLabels in the name
+ Returns the number of DNSLabels in the name
-.. classmethod:: DNSName:isPartOf(name) -> bool
+ .. method:: DNSName:equal(name) -> bool
- Returns true if the DNSName is part of the DNS tree of ``name``.
+ Returns true when both names are equal for the DNS, i.e case insensitive.
- .. code-block:: Lua
+ :param DNSName name: The name to compare against.
- newDN("www.powerdns.com"):isPartOf(newDN("CoM.")) -- true
+ .. method:: DNSName:isPartOf(name) -> bool
- :param DNSName name: The name to check against
+ Returns true if the DNSName is part of the DNS tree of ``name``.
-.. classmethod:: DNSName:toString() -> str
- DNSName:toStringNoDot() -> str
+ .. code-block:: Lua
- Returns a human-readable form of the DNSName.
- With or without trailing dot.
+ newDN("www.powerdns.com"):isPartOf(newDN("CoM.")) -- true
-.. classmethod:: DNSName:wirelength -> int
+ :param DNSName name: The name to check against
- Returns the length in bytes of the DNSName as it would be on the wire.
+ .. method:: DNSName:toString() -> str
+ DNSName:toStringNoDot() -> str
+
+ Returns a human-readable form of the DNSName.
+ With or without trailing dot.
+
+ .. method:: DNSName:wirelength() -> int
+
+ Returns the length in bytes of the DNSName as it would be on the wire.
DNS Suffix Match Groups
-----------------------
-The func:`newDS` function creates a "Suffix Match group" that allows fast checking if a :class:`DNSName` is part of a group.
+The :func:`newDS` function creates a "Suffix Match group" that allows fast checking if a :class:`DNSName` is part of a group.
This could e.g. be used to answer questions for known malware domains.
-To check e.g. the ``dq.qname`` against a list:
+To check e.g. the :attr:`dq.qname` against a list:
-.. code-block:: Lua
+.. code-block:: lua
m = newDS()
- m:add({'example.com', 'example.net})
+ m:add({'example.com', 'example.net'})
m:check(dq.qname) -- Would be true is dq.qname is a name in example.com or example.net
.. function:: newDS() -> DNSSuffixMatchGroup
This class represents a group of DNS names that can be used to quickly compare a single :class:`DNSName` against.
-.. classmethod:: DNSSuffixMatchGroup::add(domain)
- DNSSuffixMatchGroup::add(domains)
+ .. method:: DNSSuffixMatchGroup:add(domain)
+ DNSSuffixMatchGroup:add(domains)
- Add one or more domains to the Suffix Match Group.
+ Add one or more domains to the Suffix Match Group.
- :param str domain: A domain name to add
- :param {str} domain: A list of Domains to add
+ :param str domain: A domain name to add
+ :param {str} domain: A list of Domains to add
-.. classmethod:: DNSSuffixMatchGroup:check(domain) -> bool
+ .. method:: DNSSuffixMatchGroup:check(domain) -> bool
- Check ``domain`` against the Suffix Match Group.
- Returns true if it is matched, false otherwise.
+ Check ``domain`` against the Suffix Match Group.
+ Returns true if it is matched, false otherwise.
- :param DNSName domain: The domain name to check
+ :param DNSName domain: The domain name to check
-.. classmethod:: DNSSuffixMatchGroup:toString() -> str
+ .. method:: DNSSuffixMatchGroup:toString() -> str
- Returns a string of the set of suffixes matched by the Suffix Match Group
+ Returns a string of the set of suffixes matched by the Suffix Match Group
.. class:: DNSQuestion
- An object that contains everything about the current query.
+ An object that contains everything about the current query.
+ This object has the following attributes:
-.. attribute:: DNSQuestion.qname
+ .. attribute:: DNSQuestion.qname
- :class:`DNSName` of the name this query is for.
+ :class:`DNSName` of the name this query is for.
-.. attribute:: DNSQuestion.qtype
+ .. attribute:: DNSQuestion.qtype
- Type this query is for as an integer, can be compared against ``pdns.A``, ``pdns.AAAA``.
+ Type this query is for as an integer, can be compared against ``pdns.A``, ``pdns.AAAA``.
-.. attribute:: DNSQuestion.rcode
+ .. attribute:: DNSQuestion.rcode
- current DNS Result Code, which can be overridden, including to several magical values
- The rcode can be set to pdns.DROP to drop the query.
- Other statuses are normal DNS return codes, like ``pdns.NOERROR``, ``pdns.NXDOMAIN`` etc.
+ current DNS Result Code, which can be overridden, including to several magical values
+ The rcode can be set to pdns.DROP to drop the query.
+ Other statuses are normal DNS return codes, like ``pdns.NOERROR``, ``pdns.NXDOMAIN`` etc.
-.. attribute:: DNSQuestion.isTcp
+ .. attribute:: DNSQuestion.isTcp
- Boolean whether the query have been received over TCP.
+ Boolean whether the query have been received over TCP.
-.. attribute:: DNSQuestion.remoteaddr -> ComboAddress
+ .. attribute:: DNSQuestion.remoteaddr
- :class:`ComboAddress` of the requestor.
+ :class:`ComboAddress` of the requestor.
-.. attribute:: DNSQuestion.localaddr -> ComboAddress
+ .. attribute:: DNSQuestion.localaddr
- :class:`ComboAddress` where this query was received on.
+ :class:`ComboAddress` where this query was received on.
-.. attribute:: DNSQuestion.variable
+ .. attribute:: DNSQuestion.variable
- Boolean which, if set, indicates the recursor should not packet cache this answer.
- Honored even when returning false from a hook!
- Important when providing answers that vary over time or based on sender details.
+ Boolean which, if set, indicates the recursor should not packet cache this answer.
+ Honored even when returning false from a hook!
+ Important when providing answers that vary over time or based on sender details.
-.. attribute:: DNSQuestion.followupFunction
+ .. attribute:: DNSQuestion.followupFunction
- String that signals the nameserver to take one an additional action:
+ String that signals the nameserver to take one an additional action:
- - followCNAMERecords: When adding a CNAME to the answer, this tells the recursor to follow that CNAME. See :ref:`CNAME Chain Resolution <cnamechainresolution>`
- - getFakeAAAARecords: Get a fake AAAA record, see :doc:`DNS64 <../dns64>`
- - getFakePTRRecords: Get a fake PTR record, see :doc:`DNS64 <../dns64>`
- - udpQueryResponse: Do a UDP query and call a handler, see :ref:`UDP Query Response <udpqueryresponse>`
+ - followCNAMERecords: When adding a CNAME to the answer, this tells the recursor to follow that CNAME. See :ref:`CNAME Chain Resolution <cnamechainresolution>`
+ - getFakeAAAARecords: Get a fake AAAA record, see :doc:`DNS64 <../dns64>`
+ - getFakePTRRecords: Get a fake PTR record, see :doc:`DNS64 <../dns64>`
+ - udpQueryResponse: Do a UDP query and call a handler, see :ref:`UDP Query Response <udpqueryresponse>`
-.. attribute:: DNSQuestion.appliedPolicy
+ .. attribute:: DNSQuestion.appliedPolicy
The decision that was made by the policy engine, see :ref:`modifyingpolicydecisions`.
-.. attribute:: DNSQuestion.appliedPolicy.policyName
+ .. attribute:: DNSQuestion.appliedPolicy.policyName
- A string with the name of the policy.
- Set by :ref:`policyName <rpz-policyName>` in the :func:`rpzFile` and :func:`rpzMaster` configuration items.
- It is advised to overwrite this when modifying the :attr:`DNSQuestion.appliedPolicy.policyKind`
+ A string with the name of the policy.
+ Set by :ref:`policyName <rpz-policyName>` in the :func:`rpzFile` and :func:`rpzMaster` configuration items.
+ It is advised to overwrite this when modifying the :attr:`DNSQuestion.appliedPolicy.policyKind`
-.. attribute:: DNSQuestion.appliedPolicy.policyAction
+ .. attribute:: DNSQuestion.appliedPolicy.policyAction
- The action taken by the engine
+ The action taken by the engine
-.. attribute:: DNSQuestion.appliedPolicy.policyCustom
+ .. attribute:: DNSQuestion.appliedPolicy.policyCustom
- The CNAME content for the ``pdns.policyactions.Custom`` response, a string
+ The CNAME content for the ``pdns.policyactions.Custom`` response, a string
-.. attribute:: DNSQuestion.appliedPolicy.policyKind
+ .. attribute:: DNSQuestion.appliedPolicy.policyKind
- The kind of policy response, there are several policy kinds:
+ The kind of policy response, there are several policy kinds:
- - ``pdns.policykinds.Custom`` will return a NoError, CNAME answer with the value specified in :attr:`DNSQuestion.appliedPolicy.policyCustom`
- - ``pdns.policykinds.Drop`` will simply cause the query to be dropped
- - ``pdns.policykinds.NoAction`` will continue normal processing of the query
- - ``pdns.policykinds.NODATA`` will return a NoError response with no value in the answer section
- - ``pdns.policykinds.NXDOMAIN`` will return a response with a NXDomain rcode
- - ``pdns.policykinds.Truncate`` will return a NoError, no answer, truncated response over UDP. Normal processing will continue over TCP
+ - ``pdns.policykinds.Custom`` will return a NoError, CNAME answer with the value specified in :attr:`DNSQuestion.appliedPolicy.policyCustom`
+ - ``pdns.policykinds.Drop`` will simply cause the query to be dropped
+ - ``pdns.policykinds.NoAction`` will continue normal processing of the query
+ - ``pdns.policykinds.NODATA`` will return a NoError response with no value in the answer section
+ - ``pdns.policykinds.NXDOMAIN`` will return a response with a NXDomain rcode
+ - ``pdns.policykinds.Truncate`` will return a NoError, no answer, truncated response over UDP. Normal processing will continue over TCP
-.. attribute:: DNSQuestion.appliedPolicy.policyTTL
+ .. attribute:: DNSQuestion.appliedPolicy.policyTTL
- The TTL in seconds for the ``pdns.policyactions.Custom`` response
+ The TTL in seconds for the ``pdns.policyactions.Custom`` response
-.. attribute:: DNSQuestion.wantsRPZ
+ .. attribute:: DNSQuestion.wantsRPZ
- A boolean that indicates the use of the Policy Engine.
- Can be set to ``false`` in ``prerpz`` to disable RPZ for this query.
+ A boolean that indicates the use of the Policy Engine.
+ Can be set to ``false`` in ``prerpz`` to disable RPZ for this query.
-.. attribute:: DNSQuestion.data
+ .. attribute:: DNSQuestion.data
- A Lua object reference that is persistent throughout the lifetime of the :class:`DNSQuestion` object for a single query.
- It can be used to store custom data.
- Most scripts initialise this to an empty table early on so they can store multiple items.
+ A Lua object reference that is persistent throughout the lifetime of the :class:`DNSQuestion` object for a single query.
+ It can be used to store custom data.
+ Most scripts initialise this to an empty table early on so they can store multiple items.
-.. attribute:: DNSQuestion.requestorId str
+ .. attribute:: DNSQuestion.requestorId
- .. versionadded:: 4.1.0
+ .. versionadded:: 4.1.0
- A string that will be used to set the ``requestorId`` field in :doc:`protobuf <../lua-config/protobuf>` messages.
+ A string that will be used to set the ``requestorId`` field in :doc:`protobuf <../lua-config/protobuf>` messages.
-.. attribute:: DNSQuestion.deviceId str
+ .. attribute:: DNSQuestion.deviceId
- .. versionadded:: 4.1.0
+ .. versionadded:: 4.1.0
- A string that will be used to set the ``deviceId`` field in :doc:`protobuf <../lua-config/protobuf>` messages.
+ A string that will be used to set the ``deviceId`` field in :doc:`protobuf <../lua-config/protobuf>` messages.
-.. attribute:: DNSQuestion.udpAnswer -> str
+ .. attribute:: DNSQuestion.udpAnswer
- Answer to the :attr:`udpQuery <DNSQuestion.udpQuery>` when when using the ``udpQueryResponse`` :attr:`followupFunction <DNSQuestion.followupFunction>`.
- Only filled when the call-back function is invoked.
+ Answer to the :attr:`udpQuery <DNSQuestion.udpQuery>` when when using the ``udpQueryResponse`` :attr:`followupFunction <DNSQuestion.followupFunction>`.
+ Only filled when the call-back function is invoked.
-.. attribute:: DNSQuestion.udpQueryDest -> str
+ .. attribute:: DNSQuestion.udpQueryDest
- Destination IP address to send the UDP packet to when using the ``udpQueryResponse`` :attr:`followupFunction <DNSQuestion.followupFunction>`
+ Destination IP address to send the UDP packet to when using the ``udpQueryResponse`` :attr:`followupFunction <DNSQuestion.followupFunction>`
-.. attribute:: DNSQuestion.udpQuery -> str
+ .. attribute:: DNSQuestion.udpQuery
- The content of the UDP payload when using the ``udpQueryResponse`` :attr:`followupFunction <DNSQuestion.followupFunction>`
+ The content of the UDP payload when using the ``udpQueryResponse`` :attr:`followupFunction <DNSQuestion.followupFunction>`
-.. attribute:: DNSQuestion.udpCallback -> str
+ .. attribute:: DNSQuestion.udpCallback
- The name of the callback function that is called when using the ``udpQueryResponse`` :attr:`followupFunction <DNSQuestion.followupFunction>` when an answer is received.
+ The name of the callback function that is called when using the ``udpQueryResponse`` :attr:`followupFunction <DNSQuestion.followupFunction>` when an answer is received.
-.. attribute:: DNSQuestion.validationState
+ .. attribute:: DNSQuestion.validationState
- .. versionadded:: 4.1.0
+ .. versionadded:: 4.1.0
- The result of the DNSSEC validation, accessible from the ``postresolve``, ``nxdomain`` and ``nodata`` hooks.
- Possible states are ``pdns.validationstates.Indeterminate``, ``pdns.validationstates.Bogus``, ``pdns.validationstates.Insecure`` and ``pdns.validationstates.Secure``.
- The result will always be ``pdns.validationstates.Indeterminate`` is validation is disabled or was not requested.
+ The result of the DNSSEC validation, accessible from the ``postresolve``, ``nxdomain`` and ``nodata`` hooks.
+ Possible states are ``pdns.validationstates.Indeterminate``, ``pdns.validationstates.Bogus``, ``pdns.validationstates.Insecure`` and ``pdns.validationstates.Secure``.
+ The result will always be ``pdns.validationstates.Indeterminate`` is validation is disabled or was not requested.
-It also supports the following methods:
+ It also supports the following methods:
-.. classmethod:: DNSQuestion:addAnswer(type, content, [ttl, name])
+ .. method:: DNSQuestion:addAnswer(type, content, [ttl, name])
- Add an answer to the record of ``type`` with ``content``.
+ Add an answer to the record of ``type`` with ``content``.
- :param int type: The type of record to add, can be ``pdns.AAAA`` etc.
- :param str content: The content of the record, will be parsed into wireformat based on the ``type``
- :param int ttl: The TTL in seconds for this record
- :param ??? name: The name of this record, defaults to :attr:`DNSQuestion.qname`
+ :param int type: The type of record to add, can be ``pdns.AAAA`` etc.
+ :param str content: The content of the record, will be parsed into wireformat based on the ``type``
+ :param int ttl: The TTL in seconds for this record
+ :param DNSName name: The name of this record, defaults to :attr:`DNSQuestion.qname`
-.. classmethod:: DNSQuestion:addPolicyTag(tag)
+ .. method:: DNSQuestion:addPolicyTag(tag)
- Add a policy tag.
+ Add a policy tag.
- :param str tag: The tag to add
+ :param str tag: The tag to add
-.. classmethod:: DNSQuestion:discardPolicy(policyname)
+ .. method:: DNSQuestion:discardPolicy(policyname)
- Skip the filtering policy (for example RPZ) named ``policyname`` for this query.
- This is mostly useful in the ``prerpz`` hook.
+ Skip the filtering policy (for example RPZ) named ``policyname`` for this query.
+ This is mostly useful in the ``prerpz`` hook.
- :param str policyname: The name of the policy to ignore.
+ :param str policyname: The name of the policy to ignore.
-.. classmethod:: DNSQuestion:getDH() -> DNSHeader
+ .. method:: DNSQuestion:getDH() -> DNSHeader
- Returns the :class:`DNSHeader` of the query or nil.
+ Returns the :class:`DNSHeader` of the query or nil.
-.. classmethod:: DNSQuestion:getPolicyTags() -> {str}
+ .. method:: DNSQuestion:getPolicyTags() -> {str}
- Get the current policy tags as a table of strings.
+ Get the current policy tags as a table of strings.
-.. classmethod:: DNSQuestion:getRecords() -> {DNSRecord}
+ .. method:: DNSQuestion:getRecords() -> {DNSRecord}
- Get a table of DNS Records in this DNS Question (or answer by now).
+ Get a table of DNS Records in this DNS Question (or answer by now).
-.. classmethod:: DNSQuestion:setPolicyTags(tags)
+ .. method:: DNSQuestion:setPolicyTags(tags)
- Set the policy tags to ``tags``, overwriting any existing policy tags.
+ Set the policy tags to ``tags``, overwriting any existing policy tags.
- :param {str} tags: The policy tags
+ :param {str} tags: The policy tags
-.. classmethod:: DNSQuestion:setRecords(records)
+ .. method:: DNSQuestion:setRecords(records)
- After your edits, update the answers of this question
+ After your edits, update the answers of this question
- :param {DNSRecord} records: The records to put in the packet
+ :param {DNSRecord} records: The records to put in the packet
-.. classmethod:: DNSQuestion:getEDNSFlag(name) -> bool
+ .. method:: DNSQuestion:getEDNSFlag(name) -> bool
- Returns true if the EDNS flag with ``name`` is set in the query.
+ Returns true if the EDNS flag with ``name`` is set in the query.
- :param string name: Name of the flag.
+ :param string name: Name of the flag.
-.. classmethod:: DNSQuestion:getEDNSFlags() -> {str}
+ .. method:: DNSQuestion:getEDNSFlags() -> {str}
- Returns a list of strings with all the EDNS flag mnemonics in the query.
+ Returns a list of strings with all the EDNS flag mnemonics in the query.
-.. classmethod:: DNSQuestion:getEDNSOption(num) -> str
+ .. method:: DNSQuestion:getEDNSOption(num) -> str
- Get the EDNS Option with number ``num`` as a bytestring.
+ Get the EDNS Option with number ``num`` as a bytestring.
-.. classmethod:: DNSQuestion:getEDNSOptions() {str: str}
+ .. method:: DNSQuestion:getEDNSOptions() -> {str: str}
- Get a map of all EDNS Options
+ Get a map of all EDNS Options
-.. classmethod:: DNSQuestion:getEDNSSubnet() -> Netmask
+ .. method:: DNSQuestion:getEDNSSubnet() -> Netmask
- Returns the netmask specified in the EDNSSubnet option, or empty if there was none.
+ Returns the :class:`Netmask` specified in the EDNSSubnet option, or empty if there was none.
-.. classmethod:: DNSQuestion:addPolicyTag(tag)
+ .. method:: DNSQuestion:addPolicyTag(tag)
- Add policyTag ``tag`` to the list of policyTags
+ Add policyTag ``tag`` to the list of policyTags
- :param str tag: The tag to add
-
-.. classmethod:: DNSQuestion:getPolicyTags() -> {str}
-
- Get a list the policyTags for this message.
+ :param str tag: The tag to add
+ .. method:: DNSQuestion:getPolicyTags() -> {str}
+ Get a list the policyTags for this message.
DNSHeader Object
================
represents a header of a DNS message.
-.. classmethod:: DNSHeader:getRD() -> bool
+ .. method:: DNSHeader:getRD() -> bool
- The value of the Recursion Desired bit.
+ The value of the Recursion Desired bit.
-.. classmethod:: DNSHeader:getAA() -> bool
+ .. method:: DNSHeader:getAA() -> bool
- The value of the Authoritative Answer bit.
+ The value of the Authoritative Answer bit.
-.. classmethod:: DNSHeader:getAD() -> bool
+ .. method:: DNSHeader:getAD() -> bool
- The value of the Authenticated Data bit.
+ The value of the Authenticated Data bit.
-.. classmethod:: DNSHeader:getCD() -> bool
+ .. method:: DNSHeader:getCD() -> bool
- The value of the Checking Disabled bit.
+ The value of the Checking Disabled bit.
-.. classmethod:: DNSHeader:getTC() -> bool
+ .. method:: DNSHeader:getTC() -> bool
- The value of the Truncation bit.
+ The value of the Truncation bit.
-.. classmethod:: DNSHeader:getRCODE() -> int
+ .. method:: DNSHeader:getRCODE() -> int
- The Response Code of the query
+ The Response Code of the query
-.. classmethod:: DNSHeader:getOPCODE() -> int
+ .. method:: DNSHeader:getOPCODE() -> int
- The Operation Code of the query
+ The Operation Code of the query
-.. classmethod:: DNSHeader:getID() -> int
+ .. method:: DNSHeader:getID() -> int
- The ID of the query
+ The ID of the query
The EDNSOptionView Class
========================
An object that represents a single EDNS option
-.. attribute:: EDNSOptionView.size -> int
+ .. attribute:: EDNSOptionView.size
- The size in bytes of the EDNS option.
+ The size in bytes of the EDNS option.
-.. classmethod:: EDNSOptionView:getContent() -> str
+ .. method:: EDNSOptionView:getContent()
- Returns a NULL-safe string object of the EDNS option's content
+ Returns a NULL-safe string object of the EDNS option's content
Netmask class
-------------
+The :class:`Netmask` class represents an IP netmask.
-.. class:: Netmask
+.. code-block:: Lua
+
+ mask = newNetmask("192.0.2.1/24")
+ mask:isIPv4() -- true
+ mask:match("192.0.2.8") -- true
+
+.. function:: newNetmask(mask) -> Netmask
- Represents an IP netmask.
- Can be created with
+ Creates a new :class:`Netmask`.
- .. code-block:: Lua
+ :param str mask: The mask to convert.
+
+.. class:: Netmask
- newNetmask("192.0.2.1/24")
+ Represents a netmask.
-.. classmethod:: Netmask:empty() -> bool
+ .. method:: Netmask:empty() -> bool
- True if the netmask doesn't contain a valid address.
+ True if the netmask doesn't contain a valid address.
-.. classmethod:: Netmask:getBits() -> int
+ .. method:: Netmask:getBits() -> int
- The number of bits in the address.
+ The number of bits in the address.
-.. classmethod:: Netmask:getNetwork() -> ComboAddress
+ .. method:: Netmask:getNetwork() -> ComboAddress
- Returns a :class:`ComboAddress` representing the network (no mask applied).
+ Returns a :class:`ComboAddress` representing the network (no mask applied).
-.. classmethod:: Netmask:getMaskedNetwork() -> ComboAddress
+ .. method:: Netmask:getMaskedNetwork() -> ComboAddress
- Returns a :class:`ComboAddress` representing the network (truncating according to the mask).
+ Returns a :class:`ComboAddress` representing the network (truncating according to the mask).
-.. classmethod:: Netmask:isIpv4() -> bool
+ .. method:: Netmask:isIpv4() -> bool
- True if the netmask is an IPv4 netmask.
+ True if the netmask is an IPv4 netmask.
-.. classmethod:: Netmask:isIpv6 -> bool
+ .. method:: Netmask:isIpv6() -> bool
- True if the netmask is an IPv6 netmask.
+ True if the netmask is an IPv6 netmask.
-.. classmethod:: Netmask:match(address) -> bool
+ .. method:: Netmask:match(address) -> bool
- True if the address passed in address matches
+ True if the address passed in address matches
- :param str address: IP Address to match against.
+ :param str address: IP Address to match against.
-.. classmethod:: Netmask:toString() -> str
+ .. method:: Netmask:toString() -> str
- Returns a human-friendly representation.
+ Returns a human-friendly representation.
NetMaskGroup class
------------------
NetMaskGroups are more powerful than plain Netmasks.
+They can be matched against netmasks objects:
-.. class:: NetMaskGroup
+.. code-block:: lua
+
+ nmg = newNMG()
+ nmg:addMask("127.0.0.0/8")
+ nmg:addMasks({"213.244.168.0/24", "130.161.0.0/16"})
+ nmg:addMasks(dofile("bad.ips")) -- contains return {"ip1","ip2"..}
- IP addresses are passed to Lua in native format.
- They can be matched against netmasks objects:
+ if nmg:match(dq.remoteaddr) then
+ print("Intercepting query from ", dq.remoteaddr)
+ end
- .. code-block:: Lua
+Prefixing a mask with ``!`` excludes that mask from matching.
- nmg = newNMG()
- nmg:addMask("127.0.0.0/8")
- nmg:addMasks({"213.244.168.0/24", "130.161.0.0/16"})
- nmg:addMasks(dofile("bad.ips")) -- contains return {"ip1","ip2"..}
+.. function:: newNMG() -> NetMaskGroup
- if nmg:match(dq.remoteaddr) then
- print("Intercepting query from ", dq.remoteaddr)
- end
+ Returns a new, empty :class:`NetMaskGroup`.
+
+.. class:: NetMaskGroup
- Prefixing a mask with ``!`` excludes that mask from matching.
+ IP addresses are passed to Lua in native format.
-.. classmethod:: NetMaskGroup:addMask(mask)
+ .. method:: NetMaskGroup:addMask(mask)
- Adds ``mask`` to the NetMaskGroup.
+ Adds ``mask`` to the NetMaskGroup.
- :param str mask: The mask to add.
+ :param str mask: The mask to add.
-.. classmethod:: NetMaskGroup:addMasks(masks)
+ .. method:: NetMaskGroup:addMasks(masks)
- Adds ``masks`` to the NetMaskGroup.
+ Adds ``masks`` to the NetMaskGroup.
- :param {str} mask: The masks to add.
+ :param {str} mask: The masks to add.
-.. classmethod:: NetMaskGroup:match(address) -> bool
+ .. method:: NetMaskGroup:match(address) -> bool
- Returns true if ``address`` matches any of the masks in the group.
+ Returns true if ``address`` matches any of the masks in the group.
- :param ComboAddress address: The IP addres to match the netmasks against.
+ :param ComboAddress address: The IP addres to match the netmasks against.