X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci.git;a=blobdiff_plain;f=modules%2Fluci-base%2Fluasrc%2Fsys%2Fiptparser.lua;h=7ff665e7af427778a3fc8cb2c661c4b4bc928aeb;hp=2b81e0ee3893e7eca71022c9bc7792caecd32ffe;hb=5180a5bb8bcab18e06d25dbe94ba3f5e37e66248;hpb=84346cd178ca0740817edc6f81d8f90e7bc6e00c diff --git a/modules/luci-base/luasrc/sys/iptparser.lua b/modules/luci-base/luasrc/sys/iptparser.lua index 2b81e0ee3..7ff665e7a 100644 --- a/modules/luci-base/luasrc/sys/iptparser.lua +++ b/modules/luci-base/luasrc/sys/iptparser.lua @@ -19,6 +19,8 @@ luci.util = require "luci.util" luci.sys = require "luci.sys" luci.ip = require "luci.ip" +local pcall = pcall +local io = require "io" local tonumber, ipairs, table = tonumber, ipairs, table module("luci.sys.iptparser") @@ -29,20 +31,43 @@ function IptParser.__init__( self, family ) self._family = (tonumber(family) == 6) and 6 or 4 self._rules = { } self._chains = { } + self._tables = { } + + local t = self._tables + local s = self:_supported_tables(self._family) + + if s.filter then t[#t+1] = "filter" end + if s.nat then t[#t+1] = "nat" end + if s.mangle then t[#t+1] = "mangle" end + if s.raw then t[#t+1] = "raw" end if self._family == 4 then self._nulladdr = "0.0.0.0/0" - self._tables = { "filter", "nat", "mangle", "raw" } self._command = "iptables -t %s --line-numbers -nxvL" else self._nulladdr = "::/0" - self._tables = { "filter", "mangle", "raw" } self._command = "ip6tables -t %s --line-numbers -nxvL" end self:_parse_rules() end +function IptParser._supported_tables( self, family ) + local tables = { } + local ok, lines = pcall(io.lines, + (family == 6) and "/proc/net/ip6_tables_names" + or "/proc/net/ip_tables_names") + + if ok and lines then + local line + for line in lines do + tables[line] = true + end + end + + return tables +end + -- search criteria as only argument. If args is nil or an empty table then all -- rules will be returned. --