Commit 0c4bdcd0 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

custom targets

parent 08529e3f
......@@ -521,24 +521,29 @@ function M.Rule:trules()
end
end
local target
local custom = self:customtarget()
local final = custom or self:target()
local nxt
if combined then
target = self:target()
nxt = final
ofrags = combined
else target = self:uniqueid('address') end
else nxt = self:uniqueid('address') end
tag(ofrags, 'position', self:position())
ofrags = combinations(ofrags, {{target=target}})
ofrags = combinations(ofrags, {{target=nxt}})
if not combined then
extend(
ofrags,
combinations(addrofrags, {{chain=target, target=self:target()}})
)
extend(ofrags, combinations(addrofrags, {{chain=nxt, target=final}}))
end
local function extofrags(new)
if not custom then extend(ofrags, new)
elseif new[1] then self:error('Custom action not allowed here') end
end
extend(ofrags, self:extraoptfrags())
extofrags(self:extraoptfrags())
local tbl = self:table()
......@@ -594,7 +599,16 @@ function M.Rule:trules()
combinations(ofrags, ffilter({{family='inet'}, {family='inet6'}})),
function(r) return self:trulefilter(r) end
)
return extend(ofrags, self:extratrules(ofrags))
extofrags(self:extratrules(ofrags))
return ofrags
end
function M.Rule:customtarget()
if self.action then
local as = self.action:sub(1, 1)
if as == as:upper() then return self.action end
end
end
function M.Rule:extraoptfrags() return {} end
......
......@@ -142,8 +142,15 @@ local LoggingRule = class(TranslatingRule)
function LoggingRule:init(...)
LoggingRule.super(self):init(...)
util.setdefault(self, 'action', 'accept')
local custom = self:customtarget()
if type(self.log) ~= 'table' then
self.log = loadclass('log').get(self, self.log, self.action ~= 'accept')
self.log = loadclass('log').get(
self, self.log, not custom and self.action ~= 'accept'
)
end
if custom and self.log then
self:error('Logging not allowed with custom action: '..self.action)
end
end
......@@ -165,7 +172,9 @@ function LoggingRule:logchain(log, action, target)
end
function LoggingRule:extraoptfrags()
return self:logchain(self.log, self.action, self:actiontarget())
return self.log and
self:logchain(self.log, self.action, self:actiontarget()) or
LoggingRule.super(self):extraoptfrags()
end
......
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