diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-09-18 10:49:02 +0300 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-09-18 10:49:02 +0300 |
commit | 0e56b133ce4dbe78eecbe910cd18f7ac0ebed137 (patch) | |
tree | e391c852bed4c7d75a6e760e8fd2a48804a67a75 | |
parent | 0bfb89f3dd963afa7995a63f756edff42ddeacd4 (diff) | |
download | awall-0e56b133ce4dbe78eecbe910cd18f7ac0ebed137.tar.bz2 awall-0e56b133ce4dbe78eecbe910cd18f7ac0ebed137.tar.xz |
ConfigObject.create: cache labeled objects
-rw-r--r-- | awall/model.lua | 21 | ||||
-rw-r--r-- | awall/modules/filter.lua | 27 |
2 files changed, 25 insertions, 23 deletions
diff --git a/awall/model.lua b/awall/model.lua index 826971a..f4ed958 100644 --- a/awall/model.lua +++ b/awall/model.lua @@ -37,10 +37,19 @@ function M.ConfigObject:init(context, location) self.root = context.objects end self.location = location + + self.extraobjs = {} self.uniqueids = {} end -function M.ConfigObject:create(cls, params) +function M.ConfigObject:create(cls, params, label, index) + local key + if label then + key = label..(index or '') + local obj = self.extraobjs[key] + if obj then return obj end + end + if type(cls) == 'string' then local name = cls cls = loadclass(cls) @@ -49,11 +58,13 @@ function M.ConfigObject:create(cls, params) end end - if self.label then - params.label = self.label..(params.label and '-'..params.label or '') - end + local lbl = {self.label} + table.insert(lbl, label) + if lbl[1] then params.label = table.concat(lbl, '-') end - return cls.morph(params, self.context, self.location) + local obj = cls.morph(params, self.context, self.location) + if key then self.extraobjs[key] = obj end + return obj end function M.ConfigObject:uniqueid(key) diff --git a/awall/modules/filter.lua b/awall/modules/filter.lua index d6cfd3a..1c78dda 100644 --- a/awall/modules/filter.lua +++ b/awall/modules/filter.lua @@ -108,8 +108,6 @@ function Filter:init(...) end self[limit].log = loadclass('log').get(self, self[limit].log, true) end - - self.extrarules = {} end function Filter:trules() @@ -117,24 +115,17 @@ function Filter:trules() local function extrarules(label, cls, options) options = options or {} - local key = label..(options.index or '') - local obj = self.extrarules[key] - - if not obj then - local params = {label=label} - 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 - obj = self:create(cls, params) - self.extrarules[key] = obj + local params = {} + for i, attr in ipairs( + {'in', 'out', 'src', 'dest', 'dnat', 'ipset', 'ipsec', 'service'} + ) do + params[attr] = (options.src or self)[attr] end - - extend(res, obj:trules()) + util.update(params, options.update) + if options.discard then params[options.discard] = nil end + + extend(res, self:create(cls, params, label, options.index):trules()) end if self.dnat then |