Commit ae381965 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

iptables: isbuiltin function

parent b46f8664
......@@ -31,7 +31,7 @@ local families = {
}
}
M.builtin = {
local builtin = {
filter={'FORWARD', 'INPUT', 'OUTPUT'},
mangle={'FORWARD', 'INPUT', 'OUTPUT', 'POSTROUTING', 'PREROUTING'},
nat={'INPUT', 'OUTPUT', 'POSTROUTING', 'PREROUTING'},
......@@ -56,6 +56,8 @@ end
function M.isenabled() return #actfamilies() > 0 end
function M.isbuiltin(tbl, chain) return util.contains(builtin[tbl], chain) end
local BaseIPTables = class()
......@@ -124,7 +126,7 @@ function M.IPTables:dumpfile(family, iptfile)
local chains = tables[tbl]
for _, chain in sortedkeys(chains) do
local policy = '-'
if util.contains(M.builtin[tbl], chain) then
if M.isbuiltin(tbl, chain) then
policy = tbl == 'filter' and 'DROP' or 'ACCEPT'
end
iptfile:write(':'..chain..' '..policy..' [0:0]\n')
......@@ -170,8 +172,8 @@ function M.flush()
local empty = M.IPTables()
for _, family in pairs(actfamilies()) do
for tbl in io.lines(families[family].procfile) do
if M.builtin[tbl] then
for _, chain in ipairs(M.builtin[tbl]) do
if builtin[tbl] then
for _, chain in ipairs(builtin[tbl]) do
empty.config[family][tbl][chain] = {}
end
else printmsg('Warning: not flushing unknown table: '..tbl) end
......
......@@ -12,7 +12,7 @@ local loadclass = require('awall').loadclass
M.class = require('awall.class')
local FAMILIES = require('awall.family').ALL
local resolvelist = require('awall.host').resolvelist
local builtin = require('awall.iptables').builtin
local isbuiltin = require('awall.iptables').isbuiltin
local optfrag = require('awall.optfrag')
local combinations = optfrag.combinations
......@@ -619,10 +619,7 @@ function M.Rule:convertchains(ofrags)
local res = {}
for _, ofrag in ipairs(ofrags) do
if contains(builtin[self:table()], ofrag.chain) then
table.insert(res, ofrag)
if isbuiltin(self:table(), ofrag.chain) then table.insert(res, ofrag)
else
local ofs, recursive
if ofrag.chain == 'PREROUTING' then
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment