diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-03-31 12:06:45 +0300 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-03-31 19:07:51 +0300 |
commit | 8d1004410f11f0c67fd296b75abe3f8738437334 (patch) | |
tree | fac675464f5e839173e50eeed558a239c08ecf41 | |
parent | 217b5319f8adb7d979c17fa7eff34f0f7fa14a3f (diff) | |
download | awall-8d1004410f11f0c67fd296b75abe3f8738437334.tar.bz2 awall-8d1004410f11f0c67fd296b75abe3f8738437334.tar.xz |
super function for accessing methods of parent class
-rw-r--r-- | awall/model.lua | 4 | ||||
-rw-r--r-- | awall/modules/filter.lua | 6 | ||||
-rw-r--r-- | awall/modules/log.lua | 10 | ||||
-rw-r--r-- | awall/modules/mark.lua | 11 | ||||
-rw-r--r-- | awall/modules/nat.lua | 10 | ||||
-rw-r--r-- | awall/modules/notrack.lua | 2 | ||||
-rw-r--r-- | awall/modules/tproxy.lua | 6 | ||||
-rw-r--r-- | awall/object.lua | 17 |
8 files changed, 41 insertions, 25 deletions
diff --git a/awall/model.lua b/awall/model.lua index 9de7aae..0897108 100644 --- a/awall/model.lua +++ b/awall/model.lua @@ -103,7 +103,7 @@ fwzone = Zone() IPSet = class(ConfigObject) function IPSet:init(...) - ConfigObject.init(self, ...) + IPSet.super(self):init(...) if not self.type then self:error('Type not defined') end @@ -126,7 +126,7 @@ Rule = class(ConfigObject) function Rule:init(...) - ConfigObject.init(self, ...) + Rule.super(self):init(...) self.newchains = {} diff --git a/awall/modules/filter.lua b/awall/modules/filter.lua index aa0959a..e878d8f 100644 --- a/awall/modules/filter.lua +++ b/awall/modules/filter.lua @@ -42,7 +42,7 @@ function RelatedRule:target() return 'ACCEPT' end local Filter = model.class(model.Rule) function Filter:init(...) - model.Rule.init(self, ...) + Filter.super(self):init(...) if not self.action then self.action = 'accept' end @@ -65,7 +65,7 @@ function Filter:init(...) end function Filter:destoptfrags() - local ofrags = model.Rule.destoptfrags(self) + local ofrags = Filter.super(self):destoptfrags() if not self.dnat then return ofrags end ofrags = combinations(ofrags, {{family='inet6'}}) @@ -129,7 +129,7 @@ function Filter:trules() extrarules('no-track') end - extend(res, model.Rule.trules(self)) + extend(res, Filter.super(self):trules()) if self.action == 'accept' then local nr = #res diff --git a/awall/modules/log.lua b/awall/modules/log.lua index b204f74..2ece446 100644 --- a/awall/modules/log.lua +++ b/awall/modules/log.lua @@ -8,8 +8,6 @@ See LICENSE file for license details module(..., package.seeall) local model = require('awall.model') -local Rule = model.Rule - local combinations = require('awall.optfrag').combinations @@ -80,17 +78,19 @@ function Log.get(rule, spec, default) end -local LogRule = model.class(Rule) +local LogRule = model.class(model.Rule) function LogRule:init(...) - Rule.init(self, ...) + LogRule.super(self):init(...) self.log = Log.get(self, self.log, true) end function LogRule:position() return 'prepend' end function LogRule:servoptfrags() - return combinations(Rule.servoptfrags(self), {self.log:matchofrag()}) + return combinations( + LogRule.super(self):servoptfrags(), {self.log:matchofrag()} + ) end function LogRule:target() return self.log:target() end diff --git a/awall/modules/mark.lua b/awall/modules/mark.lua index 1d0e65d..43122d9 100644 --- a/awall/modules/mark.lua +++ b/awall/modules/mark.lua @@ -17,7 +17,7 @@ local util = require('awall.util') local MarkRule = class(model.Rule) function MarkRule:init(...) - model.Rule.init(self, ...) + MarkRule.super(self):init(...) if not self.mark then self:error('Mark not specified') end end @@ -32,14 +32,15 @@ function RouteTrackRule:target() return self:newchain('mark') end function RouteTrackRule:servoptfrags() return combinations( - MarkRule.servoptfrags(self), - {{opts='-m mark --mark 0'}} + RouteTrackRule.super(self):servoptfrags(), {{opts='-m mark --mark 0'}} ) end function RouteTrackRule:extraoptfrags() - return {{chain=self:target(), target=MarkRule.target(self)}, - {chain=self:target(), target='CONNMARK --save-mark'}} + return { + {chain=self:target(), target=RouteTrackRule.super(self).target()}, + {chain=self:target(), target='CONNMARK --save-mark'} + } end diff --git a/awall/modules/nat.lua b/awall/modules/nat.lua index 760a424..6f696d4 100644 --- a/awall/modules/nat.lua +++ b/awall/modules/nat.lua @@ -17,7 +17,7 @@ local NATRule = model.class(model.Rule) -- alpine v2.4 compatibility function NATRule:init(...) - model.Rule.init(self, ...) + NATRule.super(self):init(...) local attrs = {['ip-range']='to-addr', ['port-range']='to-port'} for old, new in pairs(attrs) do if not self[new] and self[old] then @@ -29,7 +29,7 @@ end function NATRule:trules() local res = {} - for i, ofrags in ipairs(model.Rule.trules(self)) do + for i, ofrags in ipairs(NATRule.super(self):trules()) do if not awall.util.contains(self.params.chains, ofrags.chain) then self:error('Inappropriate zone definitions for a '..self.params.target..' rule') end @@ -41,7 +41,7 @@ end function NATRule:table() return 'nat' end function NATRule:target() - local target = model.Rule.target(self) + local target = NATRule.super(self):target() if not target then local addr = self['to-addr'] @@ -61,7 +61,7 @@ end local DNATRule = model.class(NATRule) function DNATRule:init(...) - NATRule.init(self, ...) + DNATRule.super(self):init(...) self.params = {forbidif='out', subject='destination', chains={'INPUT', 'PREROUTING'}, target='DNAT', deftarget='REDIRECT'} @@ -71,7 +71,7 @@ end local SNATRule = model.class(NATRule) function SNATRule:init(...) - NATRule.init(self, ...) + SNATRule.super(self):init(...) self.params = {forbidif='in', subject='source', chains={'OUTPUT', 'POSTROUTING'}, target='SNAT', deftarget='MASQUERADE'} diff --git a/awall/modules/notrack.lua b/awall/modules/notrack.lua index 0a2d402..ba9fa72 100644 --- a/awall/modules/notrack.lua +++ b/awall/modules/notrack.lua @@ -17,7 +17,7 @@ local NoTrackRule = model.class(model.Rule) function NoTrackRule:table() return 'raw' end function NoTrackRule:target() - return model.Rule.target(self) or 'CT --notrack' + return NoTrackRule.super(self):target() or 'CT --notrack' end diff --git a/awall/modules/tproxy.lua b/awall/modules/tproxy.lua index 8a79131..8ea8893 100644 --- a/awall/modules/tproxy.lua +++ b/awall/modules/tproxy.lua @@ -8,8 +8,6 @@ See LICENSE file for license details module(..., package.seeall) local model = require('awall.model') -local Rule = model.Rule - local combinations = require('awall.optfrag').combinations local util = require('awall.util') @@ -18,10 +16,10 @@ local list = util.list local listpairs = util.listpairs -local TProxyRule = model.class(Rule) +local TProxyRule = model.class(model.Rule) function TProxyRule:init(...) - Rule.init(self, ...) + TProxyRule.super(self):init(...) if not self['in'] then self:error('Ingress zone must be specified') end if contains(list(self['in']), model.fwzone) then diff --git a/awall/object.lua b/awall/object.lua index 64cccfe..a9a5d5d 100644 --- a/awall/object.lua +++ b/awall/object.lua @@ -10,6 +10,23 @@ module(..., package.seeall) function class(base) local cls = {} + function cls.super(obj) + return setmetatable( + {}, + { + __index=function(t, k) + local v = base[k] + if type(v) ~= 'function' then return v end + return function(...) + local arg = {...} + arg[1] = obj + return v(unpack(arg)) + end + end + } + ) + end + function cls:morph(...) setmetatable(self, {__index = cls}) self:init(...) |