Commit a6d6b5bd authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

Log: simplify structure

parent ce3ac0b5
......@@ -179,8 +179,9 @@ end
function LoggingRule:combinelog(ofrags, log, action, target)
local actions = self:actofrags(log, target)
return actions[1] and
self:combine(ofrags, actions, 'log'..action, log and log:target()) or
ofrags
self:combine(
ofrags, actions, 'log'..action, log and #log:optfrags() > 0
) or ofrags
end
function LoggingRule:mangleoptfrags(ofrags)
......@@ -416,7 +417,7 @@ function Filter:mangleoptfrags(ofrags)
if ft then
extend(ofs, self:actofrags(self.log))
nxt = target
elseif sofs and not (pl and pl:target()) then nxt = false end
elseif sofs and not (pl and #pl:optfrags() > 0) then nxt = false end
extend(ofs, combinations(sofs, self:actofrags(pl, nxt)))
else
......
......@@ -22,7 +22,10 @@ end
local Log = class(model.ConfigObject)
function Log:matchofrags()
function Log:optfrags()
local mode = self.mode or 'log'
if mode == 'none' then return {} end
local selector, ofrags
for i, sel in ipairs{'every', 'limit', 'probability'} do
......@@ -45,14 +48,6 @@ function Log:matchofrags()
end
end
if self.mode == 'ulog' then
ofrags = combinations({{family='inet'}}, ofrags)
end
return ofrags
end
function Log:target()
local optmap = {
log={level='level', prefix='prefix'},
nflog={
......@@ -68,25 +63,20 @@ function Log:target()
threshold='qthreshold'
}
}
local mode = self.mode or 'log'
if mode == 'none' then return end
if not optmap[mode] then self:error('Invalid logging mode: '..mode) end
local res = mode:upper()
local target = mode:upper()
for s, t in pairs(optmap[mode]) do
local value = self[s]
if value then
if s == 'prefix' then value = util.quote(value) end
res = res..' --'..mode..'-'..t..' '..value
target = target..' --'..mode..'-'..t..' '..value
end
end
return res
end
function Log:optfrags()
local target = self:target()
return combinations(self:matchofrags(), {target and {target=target}})
return combinations(
ofrags, {{family=mode == 'ulog' and 'inet' or nil, target=target}}
)
end
function Log.get(rule, spec, default)
......@@ -107,11 +97,9 @@ end
function LogRule:position() return 'prepend' end
function LogRule:mangleoptfrags(ofrags)
return combinations(ofrags, self.log:matchofrags())
return combinations(ofrags, self.log:optfrags())
end
function LogRule:target() return self.log:target() end
return {
export={
......
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