diff options
-rw-r--r-- | awall/model.lua | 40 | ||||
-rw-r--r-- | awall/modules/nat.lua | 12 | ||||
-rw-r--r-- | awall/object.lua | 32 |
3 files changed, 51 insertions, 33 deletions
diff --git a/awall/model.lua b/awall/model.lua index 28e34db..d0b6914 100644 --- a/awall/model.lua +++ b/awall/model.lua @@ -10,44 +10,28 @@ module(..., package.seeall) require 'awall' require 'awall.host' require 'awall.util' +require 'awall.object' require 'awall.optfrag' local util = awall.util local combinations = awall.optfrag.combinations +class = awall.object.class -function class(base) - local cls = {} - local mt = {__index = cls} - if base then setmetatable(cls, {__index = base}) end +ConfigObject = class(awall.object.Object) - function cls.new(...) - local inst = arg[1] and arg[1] or {} - cls.morph(inst) - return inst +function ConfigObject:init(context) + if context then + self.context = context + self.root = context.input end - - function cls:morph(context) - setmetatable(self, mt) - - if context then - self.context = context - self.root = context.input - end - - self:init() - end - - return cls end -Object = class() -function Object:init() end -function Object:trules() return {} end +function ConfigObject:trules() return {} end -Zone = class(Object) +Zone = class(ConfigObject) function Zone:optfrags(dir) local iopt, aopt, iprop, aprop @@ -80,10 +64,12 @@ end fwzone = Zone.new() -Rule = class(Object) +Rule = class(ConfigObject) + +function Rule:init(context) + ConfigObject.init(self, context) -function Rule:init() for i, prop in ipairs({'in', 'out'}) do self[prop] = self[prop] and util.maplist(self[prop], function(z) diff --git a/awall/modules/nat.lua b/awall/modules/nat.lua index 6d44eaf..d1cfc2d 100644 --- a/awall/modules/nat.lua +++ b/awall/modules/nat.lua @@ -16,8 +16,8 @@ local util = awall.util local NATRule = model.class(model.Rule) -function NATRule:init() - model.Rule.init(self) +function NATRule:init(context) + model.Rule.init(self, context) if util.contains({self['in'], self.out}, fwzone) then error('NAT rules not allowed for firewall zone') end @@ -53,8 +53,8 @@ end local DNATRule = model.class(NATRule) -function DNATRule:init() - NATRule.init(self) +function DNATRule:init(context) + NATRule.init(self, context) self.params = {forbidif='out', subject='destination', chain='PREROUTING', target='DNAT'} end @@ -62,8 +62,8 @@ end local SNATRule = model.class(NATRule) -function SNATRule:init() - NATRule.init(self) +function SNATRule:init(context) + NATRule.init(self, context) self.params = {forbidif='in', subject='source', chain='POSTROUTING', target='SNAT'} end diff --git a/awall/object.lua b/awall/object.lua new file mode 100644 index 0000000..23ee081 --- /dev/null +++ b/awall/object.lua @@ -0,0 +1,32 @@ +--[[ +Class model with inheritance and morphing support for Alpine Wall +Copyright (C) 2012 Kaarle Ritvanen +Licensed under the terms of GPL2 +]]-- + + +module(..., package.seeall) + +function class(base) + local cls = {} + local mt = {__index = cls} + + if base then setmetatable(cls, {__index = base}) end + + function cls.new(...) + local inst = arg[1] and arg[1] or {} + cls.morph(inst) + return inst + end + + function cls:morph(...) + setmetatable(self, mt) + self:init(unpack(arg)) + end + + return cls +end + +Object = class() + +function Object:init(...) end |