Commit aaececd5 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen

Limit: maskmode method

parent 29f66aa1
......@@ -696,19 +696,27 @@ function M.Limit:init(...)
for _, family in ipairs{'inet', 'inet6'} do
setdefault(self.mask, family, util.copy(self.mask))
for _, attr in ipairs{'src', 'dest'} do
local mask = setdefault(
setdefault(
self.mask[family],
attr,
({src=({inet=32, inet6=128})[family], dest=0})[attr]
)
if mask > 0 then
self.mask[family].mode =
self.mask[family].mode and true or {attr, mask}
end
end
end
end
function M.Limit:maskmode(family)
local res
for _, attr in ipairs{'src', 'dest'} do
local mask = self.mask[family][attr]
if mask > 0 then
if res then return end
res = {attr, mask}
end
end
if res then return table.unpack(res) end
end
function M.Limit:rate() return self.count / self.interval end
function M.Limit:intrate() return math.ceil(self:rate()) end
......
......@@ -39,9 +39,10 @@ function FilterLimit:recentofrags(name)
local sofs = {}
for _, family in ipairs{'inet', 'inet6'} do
if type(self.mask[family].mode) ~= 'table' then return end
local attr, len = self:maskmode(family)
if not attr then return end
local mask = ''
local attr, len = table.unpack(self.mask[family].mode)
if family == 'inet' then
local octet
......
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