Commit b7438850 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

Config: methods for option fragment interpretation

parent ead91fd9
......@@ -11,10 +11,7 @@ local class = require('awall.class')
local resolve = require('awall.dependency')
local IPSet = require('awall.ipset')
local IPTables = require('awall.iptables').IPTables
local optfrag = require('awall.optfrag')
local combinations = optfrag.combinations
local combinations = require('awall.optfrag').combinations
M.PolicySet = require('awall.policy')
local util = require('awall.util')
......@@ -88,7 +85,7 @@ function M.Config:init(policyconfig)
local function insertrules(trules, obj)
for _, trule in ipairs(trules) do
local t = self.iptables.config[trule.family][trule.table][trule.chain]
local opts = optfrag.command(trule)
local opts = self:ofragcmd(trule)
if trule.target then
local acfrag = {
......@@ -96,7 +93,7 @@ function M.Config:init(policyconfig)
table=trule.table,
chain=trule.target
}
local key = optfrag.location(acfrag)
local key = self:ofragloc(acfrag)
if not actions[key] then
actions[key] = true
if stringy.startswith(trule.target, 'custom:') then
......@@ -153,6 +150,13 @@ function M.Config:init(policyconfig)
self.ipset = IPSet(self.objects.ipset)
end
function M.Config:ofragloc(of) return of.family..'/'..of.table..'/'..of.chain end
function M.Config:ofragcmd(of)
return (of.match and of.match..' ' or '')..
(of.target and '-j '..of.target or '')
end
function M.Config:print()
self.ipset:print()
io.write('\n')
......
--[[
Base data model for Alpine Wall
Copyright (C) 2012-2019 Kaarle Ritvanen
Copyright (C) 2012-2020 Kaarle Ritvanen
See LICENSE file for license details
]]--
......@@ -100,9 +100,9 @@ function M.ConfigObject:trules() return {} end
function M.ConfigObject:info()
local rules = {}
for _, trule in ipairs(self:trules()) do
local loc = optfrag.location(trule)
local loc = self.context:ofragloc(trule)
table.insert(
setdefault(rules, loc, {}), {' '..loc, optfrag.command(trule)}
setdefault(rules, loc, {}), {' '..loc, self.context:ofragcmd(trule)}
)
end
......
--[[
Option fragment module for Alpine Wall
Copyright (C) 2012-2019 Kaarle Ritvanen
Copyright (C) 2012-2020 Kaarle Ritvanen
See LICENSE file for license details
]]--
......@@ -86,11 +86,4 @@ function M.prune(...)
)
end
function M.location(of) return of.family..'/'..of.table..'/'..of.chain end
function M.command(of)
return (of.match and of.match..' ' or '')..
(of.target and '-j '..of.target or '')
end
return M
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