Commit 380590e5 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

host: resolvelist function

parent 70aeb9f1
--[[
Host address resolver for Alpine Wall
Copyright (C) 2012-2014 Kaarle Ritvanen
Copyright (C) 2012-2017 Kaarle Ritvanen
See LICENSE file for license details
]]--
local familypatterns = {inet='%d[%.%d/]+',
inet6='[:%x/]+',
domain='[%a-][%.%w-]*'}
local M = {}
local util = require('awall.util')
local familypatterns = {
inet='%d[%.%d/]+', inet6='[:%x/]+', domain='[%a-][%.%w-]*'
}
local function getfamily(addr, context)
for k, v in pairs(familypatterns) do
......@@ -18,7 +23,7 @@ end
local dnscache = {}
return function(host, context)
function M.resolve(host, context)
local family = getfamily(host, context)
if family == 'domain' then
......@@ -52,3 +57,14 @@ return function(host, context)
return {{family, host}}
end
function M.resolvelist(list, context)
local res = {}
for _, host in util.listpairs(list) do
util.extend(res, M.resolve(host, context))
end
return ipairs(res)
end
return M
......@@ -10,7 +10,7 @@ local M = {}
local loadclass = require('awall').loadclass
M.class = require('awall.class')
local resolve = require('awall.host')
local resolvelist = require('awall.host').resolvelist
local builtin = require('awall.iptables').builtin
local optfrag = require('awall.optfrag')
......@@ -125,13 +125,11 @@ function M.Zone:optfrags(dir)
local aopts = nil
if self.addr then
aopts = {}
for i, hostdef in listpairs(self.addr) do
for i, addr in ipairs(resolve(hostdef, self)) do
table.insert(
aopts,
{family=addr[1], [aprop]=addr[2], match='-'..aopt..' '..addr[2]}
)
end
for _, addr in resolvelist(self.addr) do
table.insert(
aopts,
{family=addr[1], [aprop]=addr[2], match='-'..aopt..' '..addr[2]}
)
end
end
......
......@@ -6,7 +6,7 @@ See LICENSE file for license details
local loadclass = require('awall').loadclass
local resolve = require('awall.host')
local resolve = require('awall.host').resolve
local model = require('awall.model')
local class = model.class
......
......@@ -5,7 +5,7 @@ See LICENSE file for license details
]]--
local resolve = require('awall.host')
local resolvelist = require('awall.host').resolvelist
local model = require('awall.model')
local class = model.class
......@@ -85,12 +85,8 @@ function Log:optfrags()
)
end
for _, hostdef in util.listpairs(self.mirror) do
for _, addr in ipairs(resolve(hostdef, self)) do
table.insert(
targets, {family=addr[1], target='TEE --gateway '..addr[2]}
)
end
for _, addr in resolvelist(self.mirror) do
table.insert(targets, {family=addr[1], target='TEE --gateway '..addr[2]})
end
return combinations(ofrags, targets)
......
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