Commit 7252006e authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

generalize extrarules function

parent f9ea97f8
......@@ -567,6 +567,24 @@ end
function M.Rule:extraoptfrags() return {} end
function M.Rule:extrarules(label, cls, options)
local params = {}
for _, attr in ipairs(
extend(
{'in', 'out', 'src', 'dest', 'ipset', 'ipsec', 'service'},
options.attrs
)
) do
params[attr] = (options.src or self)[attr]
end
util.update(params, options.update)
if options.discard then params[options.discard] = nil end
return self:create(cls, params, label, options.index):trules()
end
M.Limit = M.class(M.ConfigObject)
......
......@@ -213,17 +213,8 @@ function Filter:trules()
local function extrarules(label, cls, options)
options = options or {}
local params = {}
for i, attr in ipairs(
{'in', 'out', 'src', 'dest', 'dnat', 'ipset', 'ipsec', 'service'}
) do
params[attr] = (options.src or self)[attr]
end
util.update(params, options.update)
if options.discard then params[options.discard] = nil end
extend(res, self:create(cls, params, label, options.index):trules())
options.attrs = 'dnat'
extend(res, self:extrarules(label, cls, options))
end
if self.dnat then
......
--[[
Utility module for Alpine Wall
Copyright (C) 2012-2014 Kaarle Ritvanen
Copyright (C) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
]]--
......@@ -72,6 +72,7 @@ end
function M.extend(tbl1, tbl2)
for i, var in M.listpairs(tbl2) do table.insert(tbl1, var) end
return tbl1
end
function M.update(tbl1, tbl2)
......
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