Commit b8bd8ddf authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

generalize awall.optfrag.combinations to accept variable number of arguments

parent f73c1106
...@@ -192,8 +192,8 @@ for i, chain in ipairs({'INPUT', 'OUTPUT'}) do ...@@ -192,8 +192,8 @@ for i, chain in ipairs({'INPUT', 'OUTPUT'}) do
{chain=chain, {chain=chain,
opts='-'..string.lower(string.sub(chain, 1, 1))..' lo'}) opts='-'..string.lower(string.sub(chain, 1, 1))..' lo'})
end end
defrules.pre = combinations(combinations(dar, defrules.pre = combinations(dar,
{{table='filter', target='ACCEPT'}}), {{table='filter', target='ACCEPT'}},
{{family='inet'}, {family='inet6'}}) {{family='inet'}, {family='inet6'}})
defrules['post-filter'] = combinations({{family='inet6', defrules['post-filter'] = combinations({{family='inet6',
......
...@@ -7,12 +7,14 @@ Licensed under the terms of GPL2 ...@@ -7,12 +7,14 @@ Licensed under the terms of GPL2
module(..., package.seeall) module(..., package.seeall)
function combinations(of1, of2) function combinations(of1, ...)
if not of1 then if #arg == 0 then return of1 end
if not of2 then return nil end
return of2 if not of1 then return combinations(unpack(arg)) end
end
if not of2 then return of1 end local of2 = arg[1]
table.remove(arg, 1)
if not of2 then return combinations(of1, unpack(arg)) end
local res = {} local res = {}
for i, x in ipairs(of1) do for i, x in ipairs(of1) do
...@@ -44,7 +46,7 @@ function combinations(of1, of2) ...@@ -44,7 +46,7 @@ function combinations(of1, of2)
end end
end end
return res return combinations(res, unpack(arg))
end end
function location(of) return of.family..'/'..of.table..'/'..of.chain end function location(of) return of.family..'/'..of.table..'/'..of.chain end
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