+--- Find the names of all chains within the given table name.
+-- @param table String containing the table name
+-- @return Table of chain names in the order they occur.
+function IptParser.chains( self, table )
+ local lookup = { }
+ local chains = { }
+ for _, r in ipairs(self:find({table=table})) do
+ if not lookup[r.chain] then
+ lookup[r.chain] = true
+ chains[#chains+1] = r.chain
+ end
+ end
+ return chains
+end
+
+
+--- Return the given firewall chain within the given table name.
+-- @param table String containing the table name
+-- @param chain String containing the chain name
+-- @return Table containing the fields "policy", "packets", "bytes"
+-- and "rules". The "rules" field is a table of rule tables.
+function IptParser.chain( self, table, chain )
+ return self._chains[table:lower()] and self._chains[table:lower()][chain]
+end
+
+
+--- Test whether the given target points to a custom chain.
+-- @param target String containing the target action
+-- @return Boolean indicating whether target is a custom chain.
+function IptParser.is_custom_target( self, target )
+ for _, r in ipairs(self._rules) do
+ if r.chain == target then
+ return true
+ end
+ end
+ return false
+end
+
+
+-- [internal] Parse address according to family.
+function IptParser._parse_addr( self, addr )
+ if self._family == 4 then
+ return luci.ip.IPv4(addr)
+ else
+ return luci.ip.IPv6(addr)
+ end
+end
+