From b74388503329e3388b07acd8029254382d64764c Mon Sep 17 00:00:00 2001 From: Kaarle Ritvanen Date: Tue, 24 Dec 2019 17:11:05 +0200 Subject: Config: methods for option fragment interpretation --- awall/init.lua | 16 ++++++++++------ awall/model.lua | 6 +++--- awall/optfrag.lua | 9 +-------- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/awall/init.lua b/awall/init.lua index 804bdd7..605099b 100644 --- a/awall/init.lua +++ b/awall/init.lua @@ -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') diff --git a/awall/model.lua b/awall/model.lua index bf09402..bc3deb2 100644 --- a/awall/model.lua +++ b/awall/model.lua @@ -1,6 +1,6 @@ --[[ 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 diff --git a/awall/optfrag.lua b/awall/optfrag.lua index f63cb3f..055c950 100644 --- a/awall/optfrag.lua +++ b/awall/optfrag.lua @@ -1,6 +1,6 @@ --[[ 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 -- cgit v1.2.3