aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2015-05-21 12:31:44 +0300
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2015-05-21 12:31:44 +0300
commitf9ea97f87470bbd3425b7448a136065d1d31ce6f (patch)
tree825e3367d500727a89fd3fb720b22bfdc1385aa4
parentecd55c78f72045204a2d16fbaa65a61f1a6a4587 (diff)
downloadawall-1.2.4.tar.bz2
awall-1.2.4.tar.xz
long limit intervalsv1.2.4
-rw-r--r--awall/model.lua25
-rw-r--r--awall/modules/filter.lua4
2 files changed, 20 insertions, 9 deletions
diff --git a/awall/model.lua b/awall/model.lua
index 46d70d1..c4ac0ac 100644
--- a/awall/model.lua
+++ b/awall/model.lua
@@ -1,6 +1,6 @@
--[[
Base data model for Alpine Wall
-Copyright (C) 2012-2014 Kaarle Ritvanen
+Copyright (C) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
]]--
@@ -601,10 +601,22 @@ function M.Limit:init(...)
end
end
-function M.Limit:rate() return math.ceil(self.count / self.interval) end
+function M.Limit:rate() return self.count / self.interval end
+
+function M.Limit:intrate() return math.ceil(self:rate()) end
function M.Limit:limitofrags(name)
local rate = self:rate()
+ local unit
+ for _, quantum in ipairs{
+ {1, 'second'}, {60, 'minute'}, {60, 'hour'}, {24, 'day'}
+ } do
+ rate = rate * quantum[1]
+ unit = quantum[2]
+ if rate >= 1 then break end
+ end
+ rate = math.ceil(rate)..'/'..unit
+
local ofrags = {}
for _, family in ipairs{'inet', 'inet6'} do
@@ -624,11 +636,10 @@ function M.Limit:limitofrags(name)
{
family=family,
opts=keys[1] and
- '-m hashlimit --hashlimit-upto '..rate..
- '/second --hashlimit-burst '..rate..' --hashlimit-mode '..
- table.concat(keys, ',')..maskopts..' --hashlimit-name '..
- (name or self:uniqueid()) or
- '-m limit --limit '..rate..'/second'
+ '-m hashlimit --hashlimit-upto '..rate..' --hashlimit-burst '..
+ self:intrate()..' --hashlimit-mode '..table.concat(keys, ',')..
+ maskopts..' --hashlimit-name '..(name or self:uniqueid()) or
+ '-m limit --limit '..rate
}
)
end
diff --git a/awall/modules/filter.lua b/awall/modules/filter.lua
index 00ccb15..6bf7438 100644
--- a/awall/modules/filter.lua
+++ b/awall/modules/filter.lua
@@ -1,6 +1,6 @@
--[[
Filter module for Alpine Wall
-Copyright (C) 2012-2014 Kaarle Ritvanen
+Copyright (C) 2012-2015 Kaarle Ritvanen
See LICENSE file for license details
]]--
@@ -29,7 +29,7 @@ function FilterLimit:recentofrags(name)
local interval = self.interval
if count > RECENT_MAX_COUNT then
- count = self:rate()
+ count = self:intrate()
interval = 1
end