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()
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 = {}
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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'}
......
......@@ -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
......
......@@ -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
......
......@@ -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(...)
......
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