diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2017-10-26 20:13:03 +0300 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2017-11-01 11:18:10 +0200 |
commit | c9c83971e73de65f17a5ffd71ce71c6e15ebec63 (patch) | |
tree | 06c3dfb9ea17443a336ec0bb8773a520874b13b7 | |
parent | 925220ce2ba28161a869b915f78d26321c8dbde7 (diff) | |
download | awall-c9c83971e73de65f17a5ffd71ce71c6e15ebec63.tar.bz2 awall-c9c83971e73de65f17a5ffd71ce71c6e15ebec63.tar.xz |
constant for address families
-rw-r--r-- | awall/model.lua | 22 | ||||
-rw-r--r-- | awall/modules/filter.lua | 5 | ||||
-rw-r--r-- | awall/modules/mark.lua | 6 | ||||
-rw-r--r-- | awall/modules/tproxy.lua | 12 | ||||
-rw-r--r-- | awall/optfrag.lua | 7 |
5 files changed, 32 insertions, 20 deletions
diff --git a/awall/model.lua b/awall/model.lua index e00616d..0a65036 100644 --- a/awall/model.lua +++ b/awall/model.lua @@ -14,6 +14,7 @@ local resolve = require('awall.host') local builtin = require('awall.iptables').builtin local optfrag = require('awall.optfrag') +local FAMILIES = optfrag.FAMILIES local combinations = optfrag.combinations local raise = require('awall.uerror').raise @@ -313,9 +314,11 @@ function M.Rule:servoptfrags() if not self.service then return end - local fports = {inet={}, inet6={}} local res = {} + local fports = {} + map(FAMILIES, function(f) fports[f] = {} end) + for i, serv in ipairs(self.service) do for i, sdef in listpairs(serv) do if contains({'tcp', 'udp'}, sdef.proto) then @@ -618,7 +621,7 @@ function M.Rule:trules() end ofrags = filter( - combinations(ofrags, ffilter({{family='inet'}, {family='inet6'}})), + combinations(ofrags, ffilter(optfrag.FAMILYFRAGS)), function(r) return self:trulefilter(r) end ) @@ -709,7 +712,7 @@ function M.Maskable:init(...) self['src-mask'] = {} self['dest-mask'] = {} if type(self.mask) == 'number' then self.mask = {src=self.mask} end - for _, family in ipairs{'inet', 'inet6'} do + for _, family in ipairs(FAMILIES) do setdefault(self.mask, family, copy(self.mask)) for _, attr in ipairs{'src', 'dest'} do self[attr..'-mask'][family] = self.mask[family][attr] or @@ -728,9 +731,11 @@ function M.Maskable:initmask() for _, addr in ipairs{'src', 'dest'} do local mask = addr..'-mask' if type(self[mask]) ~= 'table' then - self[mask] = {inet=self[mask], inet6=self[mask]} + local m = self[mask] + self[mask] = {} + map(FAMILIES, function(f) self[mask][f] = m end) end - for _, family in ipairs{'inet', 'inet6'} do + for _, family in ipairs(FAMILIES) do local value = self[mask][family] if not value then self[mask][family] = 0 elseif value == true then self[mask][family] = ADDRLEN[family] end @@ -741,7 +746,7 @@ end function M.Maskable:recentmask(name) local res = {} - for _, family in ipairs{'inet', 'inet6'} do + for _, family in ipairs(FAMILIES) do local addr, len for _, a in ipairs{'src', 'dest'} do local mask = self[a..'-mask'][family] @@ -772,7 +777,8 @@ function M.Maskable:recentmask(name) end while #mask % 5 < 4 do mask = mask..'0' end if #mask < 39 then mask = mask..'::' end - end + + else assert(false) end table.insert( res, @@ -816,7 +822,7 @@ function M.Limit:limitofrags(name) local ofrags = {} - for _, family in ipairs{'inet', 'inet6'} do + for _, family in ipairs(FAMILIES) do local keys = {} local maskopts = '' for _, addr in ipairs{'src', 'dest'} do diff --git a/awall/modules/filter.lua b/awall/modules/filter.lua index 2cb5535..c4ea0eb 100644 --- a/awall/modules/filter.lua +++ b/awall/modules/filter.lua @@ -12,7 +12,8 @@ local model = require('awall.model') local class = model.class local Rule = model.Rule -local combinations = require('awall.optfrag').combinations +local optfrag = require('awall.optfrag') +local combinations = optfrag.combinations local util = require('awall.util') local contains = util.contains @@ -442,7 +443,7 @@ local fchains = {{chain='FORWARD'}, {chain='INPUT'}, {chain='OUTPUT'}} local function stateful(config) local res = {} - for i, family in ipairs{'inet', 'inet6'} do + for _, family in ipairs(optfrag.FAMILIES) do local er = combinations( fchains, diff --git a/awall/modules/mark.lua b/awall/modules/mark.lua index a61d8e7..ed6a417 100644 --- a/awall/modules/mark.lua +++ b/awall/modules/mark.lua @@ -8,7 +8,9 @@ See LICENSE file for license details local model = require('awall.model') local class = model.class -local combinations = require('awall.optfrag').combinations +local optfrag = require('awall.optfrag') +local combinations = optfrag.combinations + local list = require('awall.util').list @@ -38,7 +40,7 @@ end local function restoremark(config) if list(config['route-track'])[1] then return combinations( - {{family='inet'}, {family='inet6'}}, + optfrag.FAMILYFRAGS, {{chain='OUTPUT'}, {chain='PREROUTING'}}, { { diff --git a/awall/modules/tproxy.lua b/awall/modules/tproxy.lua index 5831f3b..69ec9d6 100644 --- a/awall/modules/tproxy.lua +++ b/awall/modules/tproxy.lua @@ -1,12 +1,14 @@ --[[ Transparent proxy module for Alpine Wall -Copyright (C) 2012-2016 Kaarle Ritvanen +Copyright (C) 2012-2017 Kaarle Ritvanen See LICENSE file for license details ]]-- local model = require('awall.model') -local combinations = require('awall.optfrag').combinations + +local optfrag = require('awall.optfrag') +local combinations = optfrag.combinations local util = require('awall.util') local contains = util.contains @@ -57,11 +59,7 @@ local function divert(config) ofrags, {chain='PREROUTING', match='-m socket', target='divert'} ) - return combinations( - {{family='inet'}, {family='inet6'}}, - {{table='mangle'}}, - ofrags - ) + return combinations(optfrag.FAMILYFRAGS, {{table='mangle'}}, ofrags) end end diff --git a/awall/optfrag.lua b/awall/optfrag.lua index cedf42f..b01672f 100644 --- a/awall/optfrag.lua +++ b/awall/optfrag.lua @@ -1,12 +1,17 @@ --[[ Option fragment module for Alpine Wall -Copyright (C) 2012-2016 Kaarle Ritvanen +Copyright (C) 2012-2017 Kaarle Ritvanen See LICENSE file for license details ]]-- local M = {} +M.FAMILIES = {'inet', 'inet6'} +M.FAMILYFRAGS = require('awall.util').map( + M.FAMILIES, function(f) return {family=f} end +) + function M.combinations(of1, ...) local arg = {...} |