From a6d6b5bd7975229fd95f501a05f3d71555164595 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Fri, 3 Nov 2017 14:28:55 +0200 Subject: Log: simplify structure --- awall/modules/filter.lua | 7 ++++--- awall/modules/log.lua | 32 ++++++++++---------------------- 2 files changed, 14 insertions(+), 25 deletions(-) diff --git a/awall/modules/filter.lua b/awall/modules/filter.lua index c4ea0eb..8633a3d 100644 --- a/awall/modules/filter.lua +++ b/awall/modules/filter.lua @@ -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 diff --git a/awall/modules/log.lua b/awall/modules/log.lua index cac900d..e3cd84e 100644 --- a/awall/modules/log.lua +++ b/awall/modules/log.lua @@ -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={ -- cgit v1.2.3