summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2012-08-24 11:51:12 +0000
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2012-08-24 11:51:12 +0000
commitfef090cc803e7cc7bbce04fbf5787fea169f8114 (patch)
tree4470f04d8001a70828beb255dbbd321d53f8f5a4
parent3c8aeafcb4ea4f334ca58503f5f0444134902373 (diff)
downloadawall-fef090cc803e7cc7bbce04fbf5787fea169f8114.tar.bz2
awall-fef090cc803e7cc7bbce04fbf5787fea169f8114.tar.xz
generic function for joining tables to a string
-rw-r--r--awall/model.lua19
-rw-r--r--awall/util.lua9
2 files changed, 17 insertions, 11 deletions
diff --git a/awall/model.lua b/awall/model.lua
index c722c94..5ed9d68 100644
--- a/awall/model.lua
+++ b/awall/model.lua
@@ -237,11 +237,7 @@ function Rule:servoptfrags()
if len == 1 then
opts = opts..' --dport '..plist[1]
elseif len > 1 then
- opts = opts..' -m multiport --dports '
- for i, port in ipairs(plist) do
- if i > 1 then opts = opts..',' end
- opts = opts..port
- end
+ opts = opts..' -m multiport --dports '..util.join(plist, ',')
end
table.insert(res, {opts=opts})
@@ -315,12 +311,13 @@ function Rule:trules()
end
local setopts = '-m set --match-set '..ipset.name..' '
- for i, arg in util.listpairs(ipset.args) do
- if i > 1 then setopts = setopts..',' end
- if arg == 'in' then setopts = setopts..'src'
- elseif arg == 'out' then setopts = setopts..'dst'
- else self:error('Invalid set direction argument') end
- end
+ setopts = setopts..util.join(util.map(util.list(ipset.args),
+ function(a)
+ if a == 'in' then return 'src' end
+ if a == 'out' then return 'dst' end
+ self:error('Invalid set direction argument')
+ end),
+ ',')
table.insert(ipsetofrags, {family=setdef.family, opts=setopts})
end
res = combinations(res, ipsetofrags)
diff --git a/awall/util.lua b/awall/util.lua
index dad057e..3479124 100644
--- a/awall/util.lua
+++ b/awall/util.lua
@@ -7,6 +7,15 @@ Licensed under the terms of GPL2
module(..., package.seeall)
+function join(var, sep)
+ local res = ''
+ for i, s in listpairs(var) do
+ if i > 1 then res = res..sep end
+ res = res..s
+ end
+ return res
+end
+
function list(var)
if not var then return {} end
if type(var) ~= 'table' then return {var} end