From b28ebbd3c2af13deb92c14e82864f00a0dc16d37 Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Wed, 11 Oct 2017 18:10:14 +0300 Subject: [PATCH] Rule.convertchains: eliminate side effects --- awall/model.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/awall/model.lua b/awall/model.lua index 5fd214e..107a6ac 100644 --- a/awall/model.lua +++ b/awall/model.lua @@ -20,6 +20,7 @@ local raise = require('awall.uerror').raise local util = require('awall.util') local contains = util.contains +local copy = util.copy local extend = util.extend local filter = util.filter local join = util.join @@ -440,8 +441,9 @@ function M.Rule:combine(ofs1, ofs2, key, unique) local chain = self:uniqueid(key) local function setvar(name) return function(of) - setdefault(of, name, chain) - return of + local res = copy(of) + setdefault(res, name, chain) + return res end end @@ -651,8 +653,9 @@ function M.Rule:convertchains(ofrags) end if ofs then - ofrag.chain = nil - ofs = combinations(ofs, {ofrag}) + local of = copy(ofrag) + of.chain = nil + ofs = combinations(ofs, {of}) if recursive then ofs = self:convertchains(ofs) end extend(res, ofs) @@ -696,7 +699,7 @@ function M.Maskable:init(...) self['dest-mask'] = {} if type(self.mask) == 'number' then self.mask = {src=self.mask} end for _, family in ipairs{'inet', 'inet6'} do - setdefault(self.mask, family, util.copy(self.mask)) + setdefault(self.mask, family, copy(self.mask)) for _, attr in ipairs{'src', 'dest'} do self[attr..'-mask'][family] = self.mask[family][attr] or ({src=({inet=32, inet6=128})[family], dest=0})[attr] -- 2.26.2