Commit 8d100441 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

super function for accessing methods of parent class

parent 217b5319
...@@ -103,7 +103,7 @@ fwzone = Zone() ...@@ -103,7 +103,7 @@ fwzone = Zone()
IPSet = class(ConfigObject) IPSet = class(ConfigObject)
function IPSet:init(...) function IPSet:init(...)
ConfigObject.init(self, ...) IPSet.super(self):init(...)
if not self.type then self:error('Type not defined') end if not self.type then self:error('Type not defined') end
...@@ -126,7 +126,7 @@ Rule = class(ConfigObject) ...@@ -126,7 +126,7 @@ Rule = class(ConfigObject)
function Rule:init(...) function Rule:init(...)
ConfigObject.init(self, ...) Rule.super(self):init(...)
self.newchains = {} self.newchains = {}
......
...@@ -42,7 +42,7 @@ function RelatedRule:target() return 'ACCEPT' end ...@@ -42,7 +42,7 @@ function RelatedRule:target() return 'ACCEPT' end
local Filter = model.class(model.Rule) local Filter = model.class(model.Rule)
function Filter:init(...) function Filter:init(...)
model.Rule.init(self, ...) Filter.super(self):init(...)
if not self.action then self.action = 'accept' end if not self.action then self.action = 'accept' end
...@@ -65,7 +65,7 @@ function Filter:init(...) ...@@ -65,7 +65,7 @@ function Filter:init(...)
end end
function Filter:destoptfrags() function Filter:destoptfrags()
local ofrags = model.Rule.destoptfrags(self) local ofrags = Filter.super(self):destoptfrags()
if not self.dnat then return ofrags end if not self.dnat then return ofrags end
ofrags = combinations(ofrags, {{family='inet6'}}) ofrags = combinations(ofrags, {{family='inet6'}})
...@@ -129,7 +129,7 @@ function Filter:trules() ...@@ -129,7 +129,7 @@ function Filter:trules()
extrarules('no-track') extrarules('no-track')
end end
extend(res, model.Rule.trules(self)) extend(res, Filter.super(self):trules())
if self.action == 'accept' then if self.action == 'accept' then
local nr = #res local nr = #res
......
...@@ -8,8 +8,6 @@ See LICENSE file for license details ...@@ -8,8 +8,6 @@ See LICENSE file for license details
module(..., package.seeall) module(..., package.seeall)
local model = require('awall.model') local model = require('awall.model')
local Rule = model.Rule
local combinations = require('awall.optfrag').combinations local combinations = require('awall.optfrag').combinations
...@@ -80,17 +78,19 @@ function Log.get(rule, spec, default) ...@@ -80,17 +78,19 @@ function Log.get(rule, spec, default)
end end
local LogRule = model.class(Rule) local LogRule = model.class(model.Rule)
function LogRule:init(...) function LogRule:init(...)
Rule.init(self, ...) LogRule.super(self):init(...)
self.log = Log.get(self, self.log, true) self.log = Log.get(self, self.log, true)
end end
function LogRule:position() return 'prepend' end function LogRule:position() return 'prepend' end
function LogRule:servoptfrags() function LogRule:servoptfrags()
return combinations(Rule.servoptfrags(self), {self.log:matchofrag()}) return combinations(
LogRule.super(self):servoptfrags(), {self.log:matchofrag()}
)
end end
function LogRule:target() return self.log:target() end function LogRule:target() return self.log:target() end
......
...@@ -17,7 +17,7 @@ local util = require('awall.util') ...@@ -17,7 +17,7 @@ local util = require('awall.util')
local MarkRule = class(model.Rule) local MarkRule = class(model.Rule)
function MarkRule:init(...) function MarkRule:init(...)
model.Rule.init(self, ...) MarkRule.super(self):init(...)
if not self.mark then self:error('Mark not specified') end if not self.mark then self:error('Mark not specified') end
end end
...@@ -32,14 +32,15 @@ function RouteTrackRule:target() return self:newchain('mark') end ...@@ -32,14 +32,15 @@ function RouteTrackRule:target() return self:newchain('mark') end
function RouteTrackRule:servoptfrags() function RouteTrackRule:servoptfrags()
return combinations( return combinations(
MarkRule.servoptfrags(self), RouteTrackRule.super(self):servoptfrags(), {{opts='-m mark --mark 0'}}
{{opts='-m mark --mark 0'}}
) )
end end
function RouteTrackRule:extraoptfrags() function RouteTrackRule:extraoptfrags()
return {{chain=self:target(), target=MarkRule.target(self)}, return {
{chain=self:target(), target='CONNMARK --save-mark'}} {chain=self:target(), target=RouteTrackRule.super(self).target()},
{chain=self:target(), target='CONNMARK --save-mark'}
}
end end
......
...@@ -17,7 +17,7 @@ local NATRule = model.class(model.Rule) ...@@ -17,7 +17,7 @@ local NATRule = model.class(model.Rule)
-- alpine v2.4 compatibility -- alpine v2.4 compatibility
function NATRule:init(...) function NATRule:init(...)
model.Rule.init(self, ...) NATRule.super(self):init(...)
local attrs = {['ip-range']='to-addr', ['port-range']='to-port'} local attrs = {['ip-range']='to-addr', ['port-range']='to-port'}
for old, new in pairs(attrs) do for old, new in pairs(attrs) do
if not self[new] and self[old] then if not self[new] and self[old] then
...@@ -29,7 +29,7 @@ end ...@@ -29,7 +29,7 @@ end
function NATRule:trules() function NATRule:trules()
local res = {} 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 if not awall.util.contains(self.params.chains, ofrags.chain) then
self:error('Inappropriate zone definitions for a '..self.params.target..' rule') self:error('Inappropriate zone definitions for a '..self.params.target..' rule')
end end
...@@ -41,7 +41,7 @@ end ...@@ -41,7 +41,7 @@ end
function NATRule:table() return 'nat' end function NATRule:table() return 'nat' end
function NATRule:target() function NATRule:target()
local target = model.Rule.target(self) local target = NATRule.super(self):target()
if not target then if not target then
local addr = self['to-addr'] local addr = self['to-addr']
...@@ -61,7 +61,7 @@ end ...@@ -61,7 +61,7 @@ end
local DNATRule = model.class(NATRule) local DNATRule = model.class(NATRule)
function DNATRule:init(...) function DNATRule:init(...)
NATRule.init(self, ...) DNATRule.super(self):init(...)
self.params = {forbidif='out', subject='destination', self.params = {forbidif='out', subject='destination',
chains={'INPUT', 'PREROUTING'}, chains={'INPUT', 'PREROUTING'},
target='DNAT', deftarget='REDIRECT'} target='DNAT', deftarget='REDIRECT'}
...@@ -71,7 +71,7 @@ end ...@@ -71,7 +71,7 @@ end
local SNATRule = model.class(NATRule) local SNATRule = model.class(NATRule)
function SNATRule:init(...) function SNATRule:init(...)
NATRule.init(self, ...) SNATRule.super(self):init(...)
self.params = {forbidif='in', subject='source', self.params = {forbidif='in', subject='source',
chains={'OUTPUT', 'POSTROUTING'}, chains={'OUTPUT', 'POSTROUTING'},
target='SNAT', deftarget='MASQUERADE'} target='SNAT', deftarget='MASQUERADE'}
......
...@@ -17,7 +17,7 @@ local NoTrackRule = model.class(model.Rule) ...@@ -17,7 +17,7 @@ local NoTrackRule = model.class(model.Rule)
function NoTrackRule:table() return 'raw' end function NoTrackRule:table() return 'raw' end
function NoTrackRule:target() function NoTrackRule:target()
return model.Rule.target(self) or 'CT --notrack' return NoTrackRule.super(self):target() or 'CT --notrack'
end end
......
...@@ -8,8 +8,6 @@ See LICENSE file for license details ...@@ -8,8 +8,6 @@ See LICENSE file for license details
module(..., package.seeall) module(..., package.seeall)
local model = require('awall.model') local model = require('awall.model')
local Rule = model.Rule
local combinations = require('awall.optfrag').combinations local combinations = require('awall.optfrag').combinations
local util = require('awall.util') local util = require('awall.util')
...@@ -18,10 +16,10 @@ local list = util.list ...@@ -18,10 +16,10 @@ local list = util.list
local listpairs = util.listpairs local listpairs = util.listpairs
local TProxyRule = model.class(Rule) local TProxyRule = model.class(model.Rule)
function TProxyRule:init(...) function TProxyRule:init(...)
Rule.init(self, ...) TProxyRule.super(self):init(...)
if not self['in'] then self:error('Ingress zone must be specified') end if not self['in'] then self:error('Ingress zone must be specified') end
if contains(list(self['in']), model.fwzone) then if contains(list(self['in']), model.fwzone) then
......
...@@ -10,6 +10,23 @@ module(..., package.seeall) ...@@ -10,6 +10,23 @@ module(..., package.seeall)
function class(base) function class(base)
local cls = {} 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(...) function cls:morph(...)
setmetatable(self, {__index = cls}) setmetatable(self, {__index = cls})
self:init(...) self:init(...)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment