Commit c9c83971 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

constant for address families

parent 925220ce
......@@ -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
......
......@@ -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,
......
......@@ -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'}},
{
{
......
--[[
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
......
--[[
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 = {...}
......
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