From fd780ffdb62d48a3ce085e0614ebd983afa78d20 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Thu, 19 Jul 2012 05:28:26 +0000 Subject: consistent chain names in level 5 dump --- awall/model.lua | 18 +++++++++++++----- awall/modules/filter.lua | 3 +-- awall/modules/mark.lua | 7 +------ 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/awall/model.lua b/awall/model.lua index 2813d8b..4fff0b3 100644 --- a/awall/model.lua +++ b/awall/model.lua @@ -89,6 +89,8 @@ Rule = class(ConfigObject) function Rule:init(...) ConfigObject.init(self, unpack(arg)) + self.newchains = {} + for i, prop in ipairs({'in', 'out'}) do self[prop] = self[prop] and util.maplist(self[prop], function(z) @@ -368,14 +370,20 @@ end function Rule:extraoptfrags() return {} end -function Rule:newchain(base) +function Rule:newchain(key) + if self.newchains[key] then return self.newchains[key] end + if not self.context.lastid then self.context.lastid = {} end local lastid = self.context.lastid - if self.label then base = base..'-'..self.label end - if not lastid[base] then lastid[base] = -1 end - lastid[base] = lastid[base] + 1 - return base..'-'..lastid[base] + local res = key + if self.label then res = res..'-'..self.label end + if not lastid[res] then lastid[res] = -1 end + lastid[res] = lastid[res] + 1 + res = res..'-'..lastid[res] + + self.newchains[key] = res + return res end diff --git a/awall/modules/filter.lua b/awall/modules/filter.lua index b851234..5da8f91 100644 --- a/awall/modules/filter.lua +++ b/awall/modules/filter.lua @@ -95,8 +95,7 @@ end function Filter:target() if not self:limit() then return model.Rule.target(self) end - if not self['limit-target'] then self['limit-target'] = self:newchain('limit') end - return self['limit-target'] + return self:newchain('limit') end function Filter:extraoptfrags() diff --git a/awall/modules/mark.lua b/awall/modules/mark.lua index 1122ab4..bdc469c 100644 --- a/awall/modules/mark.lua +++ b/awall/modules/mark.lua @@ -26,12 +26,7 @@ end local RouteTrackRule = model.class(MarkRule) -function RouteTrackRule:target() - if not self['mark-target'] then - self['mark-target'] = self:newchain('mark') - end - return self['mark-target'] -end +function RouteTrackRule:target() return self:newchain('mark') end function RouteTrackRule:servoptfrags() return awall.optfrag.combinations(MarkRule.servoptfrags(self), -- cgit v1.2.3