Commit 6e5fc5f5 authored by Kaarle Ritvanen's avatar Kaarle Ritvanen
Browse files

statistical packet logging

fixes #1587
parent b5629593
......@@ -39,16 +39,32 @@ function Log:optfrag()
local mode = self.mode or 'log'
if not optmap[mode] then self:error('Invalid logging mode: '..mode) end
local selector, opts
for i, sel in ipairs{'every', 'limit', 'probability'} do
local value = self[sel]
if value then
if selector then
self:error('Cannot combine '..sel..' with '..selector)
selector = sel
if sel == 'every' then
opts = '-m statistic --mode nth --every '..value..' --packet 0'
elseif sel == 'limit' then
opts = '-m limit --limit '..value..'/second'
elseif sel == 'probability' then
opts = '-m statistic --mode random --probability '..value
else assert(false) end
local target = string.upper(mode)
for s, t in pairs(optmap[mode]) do
if self[s] then target = target..' --'..mode..'-'..t..' '..self[s] end
return {
opts=self.limit and '-m limit --limit '..self.limit..'/second',
return {opts=opts, target=target}
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