diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2012-09-03 07:43:29 +0000 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2012-09-03 07:43:29 +0000 |
commit | b8bd8ddf4afa637c005fb9c16c14aced4e278444 (patch) | |
tree | b0d5e2229cd95b195b720660ad6bb33934146843 | |
parent | f73c11061609a0c1678f51834cbd2e7ccb85a59a (diff) | |
download | awall-b8bd8ddf4afa637c005fb9c16c14aced4e278444.tar.bz2 awall-b8bd8ddf4afa637c005fb9c16c14aced4e278444.tar.xz |
generalize awall.optfrag.combinations to accept variable number of arguments
-rw-r--r-- | awall/modules/filter.lua | 4 | ||||
-rw-r--r-- | awall/optfrag.lua | 16 |
2 files changed, 11 insertions, 9 deletions
diff --git a/awall/modules/filter.lua b/awall/modules/filter.lua index be391f7..a37e497 100644 --- a/awall/modules/filter.lua +++ b/awall/modules/filter.lua @@ -192,8 +192,8 @@ for i, chain in ipairs({'INPUT', 'OUTPUT'}) do {chain=chain, opts='-'..string.lower(string.sub(chain, 1, 1))..' lo'}) end -defrules.pre = combinations(combinations(dar, - {{table='filter', target='ACCEPT'}}), +defrules.pre = combinations(dar, + {{table='filter', target='ACCEPT'}}, {{family='inet'}, {family='inet6'}}) defrules['post-filter'] = combinations({{family='inet6', diff --git a/awall/optfrag.lua b/awall/optfrag.lua index 97d8cc8..abd2b89 100644 --- a/awall/optfrag.lua +++ b/awall/optfrag.lua @@ -7,12 +7,14 @@ Licensed under the terms of GPL2 module(..., package.seeall) -function combinations(of1, of2) - if not of1 then - if not of2 then return nil end - return of2 - end - if not of2 then return of1 end +function combinations(of1, ...) + if #arg == 0 then return of1 end + + if not of1 then return combinations(unpack(arg)) end + + local of2 = arg[1] + table.remove(arg, 1) + if not of2 then return combinations(of1, unpack(arg)) end local res = {} for i, x in ipairs(of1) do @@ -44,7 +46,7 @@ function combinations(of1, of2) end end - return res + return combinations(res, unpack(arg)) end function location(of) return of.family..'/'..of.table..'/'..of.chain end |