Skip to content
Snippets Groups Projects
Verified Commit cce5657a authored by Tomas Krizek's avatar Tomas Krizek
Browse files

pcap/limit-clients: remove duration option

parent 265134f2
No related branches found
No related tags found
1 merge request!24dnsjit pcap processing scripts
......@@ -3,9 +3,8 @@
-- limit-clients.lua: randomize which clients (IPs) will be included in output
--
-- Every unique IP (client) has the given chance to appear in the output file.
-- If a client appears, all of its packets remain intact (up to the specified
-- duration). If a client doesn't appear in the output, none of its packets
-- will.
-- If a client appears, all of its packets remain intact. If a client doesn't
-- appear in the output, none of its packets will.
--
-- This script can only scale-down (limit) the number of clients, i.e. the
-- chance must be in range 0 to 1.
......@@ -19,7 +18,6 @@ local log = require("dnsjit.core.log").new("extract-clients.lua")
local getopt = require("dnsjit.lib.getopt").new({
{ "r", "read", "", "input file to read", "?" },
{ "w", "write", "", "output file to write", "?" },
{ "d", "duration", 0, "duration of output (in seconds, 0 means entire file)", "?" },
{ "l", "limit", 1.0, "chance for each client to appear, 0 to 1", "?" },
{ "", "seed", 0, "seed for RNG", "?" },
})
......@@ -34,7 +32,6 @@ local args = {}
getopt:parse()
args.read = getopt:val("r")
args.write = getopt:val("w")
args.duration = getopt:val("d")
args.limit = getopt:val("l")
args.seed = getopt:val("seed")
......@@ -45,11 +42,6 @@ if getopt:val("help") then
end
-- Check arguments
if args.duration < 0 then
log:fatal("duration can't be negative")
elseif args.duration == 0 then
args.duration = math.huge
end
if args.limit <= 0 then
log:fatal("limit must be greater than 0")
elseif args.limit > 1 then
......@@ -75,7 +67,7 @@ if args.write ~= "" then
if output:open(args.write, LINKTYPE, SNAPLEN) ~= 0 then
log:fatal("failed to open chunk file " .. args.write)
else
log:notice("wiring output PCAP: " .. args.write)
log:notice("writing output PCAP: " .. args.write)
end
else
getopt:usage()
......@@ -85,7 +77,6 @@ local write, writectx = output:receive()
local clients = {}
local n_present = 0
local now_ms, since_ms, until_ms
local obj, obj_pcap_in, obj_ip, obj_pl, src_ip, ip_len, present
......@@ -103,14 +94,6 @@ while true do
obj_pl = obj:cast_to(object.PAYLOAD)
obj_pcap_in = obj:cast_to(object.PCAP)
if obj_ip ~= nil and obj_pl ~= nil and obj_pcap_in ~= nil then
now_ms = tonumber(obj_pcap_in.ts.sec) * 1e3 + tonumber(obj_pcap_in.ts.nsec) * 1e-6
if until_ms == nil then
since_ms = now_ms
until_ms = now_ms + args.duration * 1e3
elseif now_ms >= until_ms then
break
end
src_ip = ffi.string(obj_ip.src, ip_len)
present = clients[src_ip]
if present == nil then
......@@ -127,9 +110,4 @@ while true do
end
end
local duration_s = (now_ms - since_ms) / 1e3
log:info(string.format(" since_ms: %d", since_ms))
log:info(string.format(" until_ms: %d", now_ms))
log:info(string.format(" duration_s: %.3f", duration_s))
log:info(string.format(" number of clients: %d", n_present))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment