Implemented trick to avoid processing the packet twice
This commit is contained in:
+16
-7
@@ -86,7 +86,7 @@ function slen(str)
|
|||||||
local i = 1
|
local i = 1
|
||||||
local len = 0
|
local len = 0
|
||||||
local zero = string.char(0)
|
local zero = string.char(0)
|
||||||
|
|
||||||
for i = 1, 16 do
|
for i = 1, 16 do
|
||||||
local c = str:sub(i,i)
|
local c = str:sub(i,i)
|
||||||
|
|
||||||
@@ -94,14 +94,23 @@ function slen(str)
|
|||||||
len = len + 1
|
len = len + 1
|
||||||
else
|
else
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return(str:sub(1, len))
|
return(str:sub(1, len))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- the dissector function callback
|
-- the dissector function callback
|
||||||
|
local num_pkts = 0
|
||||||
|
|
||||||
function ndpi_proto.dissector(tvb, pinfo, tree)
|
function ndpi_proto.dissector(tvb, pinfo, tree)
|
||||||
|
num_pkts = num_pkts + 1
|
||||||
|
|
||||||
|
-- Wireshark dissects the packet twice. We ignore the first
|
||||||
|
-- run as on that step the packet is still undecoded
|
||||||
|
-- The trick below avoids to process the packet twice
|
||||||
|
if(num_pkts < pinfo.number) then return end
|
||||||
|
|
||||||
local pktlen = tvb:len()
|
local pktlen = tvb:len()
|
||||||
local eth_trailer = f_eth_trailer()
|
local eth_trailer = f_eth_trailer()
|
||||||
local magic = tostring(tvb(pktlen-28,4))
|
local magic = tostring(tvb(pktlen-28,4))
|
||||||
@@ -126,22 +135,22 @@ function ndpi_proto.dissector(tvb, pinfo, tree)
|
|||||||
|
|
||||||
if(compute_flows_stats) then
|
if(compute_flows_stats) then
|
||||||
ndpikey = tostring(slen(name_str))
|
ndpikey = tostring(slen(name_str))
|
||||||
|
|
||||||
if(ndpi_protos[ndpikey] == nil) then ndpi_protos[ndpikey] = 0 end
|
if(ndpi_protos[ndpikey] == nil) then ndpi_protos[ndpikey] = 0 end
|
||||||
ndpi_protos[ndpikey] = ndpi_protos[ndpikey] + pinfo.len
|
ndpi_protos[ndpikey] = ndpi_protos[ndpikey] + pinfo.len
|
||||||
|
|
||||||
srckey = tostring(pinfo.src)
|
srckey = tostring(pinfo.src)
|
||||||
dstkey = tostring(pinfo.dst)
|
dstkey = tostring(pinfo.dst)
|
||||||
|
|
||||||
flowkey = srckey.." / "..dstkey.." ["..ndpikey.."]"
|
flowkey = srckey.." / "..dstkey.." ["..ndpikey.."]"
|
||||||
if(ndpi_flows[flowkey] == nil) then
|
if(ndpi_flows[flowkey] == nil) then
|
||||||
ndpi_flows[flowkey] = 0
|
ndpi_flows[flowkey] = 0
|
||||||
num_ndpi_flows = num_ndpi_flows + 1
|
num_ndpi_flows = num_ndpi_flows + 1
|
||||||
|
|
||||||
if(num_ndpi_flows > max_num_flows) then
|
if(num_ndpi_flows > max_num_flows) then
|
||||||
-- We need to harvest the flow with least packets beside this new one
|
-- We need to harvest the flow with least packets beside this new one
|
||||||
local tot_removed = 0
|
local tot_removed = 0
|
||||||
|
|
||||||
for k,v in pairsByValues(ndpi_flows, asc) do
|
for k,v in pairsByValues(ndpi_flows, asc) do
|
||||||
if(k ~= flowkey) then
|
if(k ~= flowkey) then
|
||||||
table.remove(ndpi_flows, k)
|
table.remove(ndpi_flows, k)
|
||||||
|
|||||||
Reference in New Issue
Block a user