diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2017-10-11 16:38:07 +0300 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2017-10-18 13:33:45 +0300 |
commit | 73aff0f63b4aa93fc954ad4302e833df317bc8aa (patch) | |
tree | ecc6b4a4884cab1dbccdbde366a180b6dfb432cc | |
parent | be16233e26bde7d351765c17b516abee5d89e49c (diff) | |
download | awall-73aff0f63b4aa93fc954ad4302e833df317bc8aa.tar.bz2 awall-73aff0f63b4aa93fc954ad4302e833df317bc8aa.tar.xz |
Rule: make convertchain a method
-rw-r--r-- | awall/model.lua | 76 |
1 files changed, 36 insertions, 40 deletions
diff --git a/awall/model.lua b/awall/model.lua index 64aec6b..5fd214e 100644 --- a/awall/model.lua +++ b/awall/model.lua @@ -590,46 +590,8 @@ function M.Rule:trules() setdefault(ofrag, 'target', custom or self:target()) end - local tbl = self:table() - - local function convertchains(ofrags) - local res = {} - - for i, ofrag in ipairs(ofrags) do - - if contains(builtin[tbl], ofrag.chain) then table.insert(res, ofrag) - else - local ofs, recursive - if ofrag.chain == 'PREROUTING' then - ofs = {{chain='FORWARD'}, {chain='INPUT'}} - elseif ofrag.chain == 'POSTROUTING' then - ofs = {{chain='FORWARD'}, {chain='OUTPUT'}} - recursive = true - elseif ofrag.chain == 'INPUT' then - ofs = { - {match='-m addrtype --dst-type LOCAL', chain='PREROUTING'} - } - elseif ofrag.chain == 'FORWARD' then - ofs = { - {match='-m addrtype ! --dst-type LOCAL', chain='PREROUTING'} - } - end - - if ofs then - ofrag.chain = nil - ofs = combinations(ofs, {ofrag}) - if recursive then ofs = convertchains(ofs) end - extend(res, ofs) - - else table.insert(res, ofrag) end - end - end - - return res - end - - ofrags = convertchains(ffilter(ofrags)) - tag(ofrags, 'table', tbl, false) + ofrags = self:convertchains(ffilter(ofrags)) + tag(ofrags, 'table', self:table(), false) local function checkzof(ofrag, dir, chains) if ofrag[dir] and contains(chains, ofrag.chain) then @@ -667,6 +629,40 @@ function M.Rule:trulefilter(rule) return true end function M.Rule:extratrules(rules) return {} end +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) + + else + local ofs, recursive + if ofrag.chain == 'PREROUTING' then + ofs = {{chain='FORWARD'}, {chain='INPUT'}} + elseif ofrag.chain == 'POSTROUTING' then + ofs = {{chain='FORWARD'}, {chain='OUTPUT'}} + recursive = true + elseif ofrag.chain == 'INPUT' then + ofs = {{match='-m addrtype --dst-type LOCAL', chain='PREROUTING'}} + elseif ofrag.chain == 'FORWARD' then + ofs = {{match='-m addrtype ! --dst-type LOCAL', chain='PREROUTING'}} + end + + if ofs then + ofrag.chain = nil + ofs = combinations(ofs, {ofrag}) + if recursive then ofs = self:convertchains(ofs) end + extend(res, ofs) + + else table.insert(res, ofrag) end + end + end + + return res +end + function M.Rule:extrarules(label, cls, options) local params = {} |