diff --git a/include/Flow.h b/include/Flow.h index fd71badb51..c8db0fa0e0 100644 --- a/include/Flow.h +++ b/include/Flow.h @@ -166,7 +166,7 @@ class Flow : public GenericHashEntry { struct timeval c2sFirstGoodputTime; float rttSec, applLatencyMsec; - InterarrivalStats cli2srvPktTime, srv2cliPktTime; + InterarrivalStats *cli2srvPktTime, *srv2cliPktTime; /* Counter values at last host update */ struct { @@ -211,7 +211,7 @@ class Flow : public GenericHashEntry { bool checkTor(char *hostname); void setBittorrentHash(char *hash); bool isLowGoodput(); - void updatePacketStats(InterarrivalStats *stats, const struct timeval *when); + static void updatePacketStats(InterarrivalStats *stats, const struct timeval *when); void dumpPacketStats(lua_State* vm, bool cli2srv_direction); bool isReadyToBeMarkedAsIdle(); bool isBlacklistedFlow() const; @@ -466,9 +466,9 @@ class Flow : public GenericHashEntry { inline float getCli2SrvMaxThpt() { return(rttSec ? ((float)(cli2srv_window*8)/rttSec) : 0); } inline float getSrv2CliMaxThpt() { return(rttSec ? ((float)(srv2cli_window*8)/rttSec) : 0); } - inline InterarrivalStats* getCli2SrvIATStats() { return(&cli2srvPktTime); } - inline InterarrivalStats* getSrv2CliIATStats() { return(&srv2cliPktTime); } - + inline InterarrivalStats* getCli2SrvIATStats() const { return cli2srvPktTime; } + inline InterarrivalStats* getSrv2CliIATStats() const { return srv2cliPktTime; } + bool isIdleFlow(); inline bool isTCPEstablished() const { return (!isTCPClosed() && !isTCPReset() && ((src2dst_tcp_flags & (TH_SYN | TH_ACK)) == (TH_SYN | TH_ACK)) diff --git a/scripts/lua/flow_details.lua b/scripts/lua/flow_details.lua index b4dc2914d1..26a8f28e2e 100644 --- a/scripts/lua/flow_details.lua +++ b/scripts/lua/flow_details.lua @@ -585,7 +585,6 @@ print [[ if(flow == nil) then print('
'..i18n("flow_details.flow_cannot_be_found_message")..' '.. purgedErrorString()..'
') else - if isAdministrator() then if(_POST["drop_flow_policy"] == "true") then interface.dropFlowTraffic(tonumber(flow_key)) @@ -630,7 +629,7 @@ else print(i18n("flow_details.ssl_old_protocol_version")) end end - + if(ifstats.inline) then if(flow["verdict.pass"]) then print('
') @@ -792,8 +791,8 @@ else print(""..i18n("flow_details.application_latency")..""..msToTime(flow["tcp.appl_latency"]).."\n") end - if(not string.starts(ifname, "nf:")) then - if((flow["cli2srv.packets"] > 1) and (flow["interarrival.cli2srv"]["max"] > 0)) then + if(not string.starts(ifname, "nf:")) then + if flow["cli2srv.packets"] > 1 and flow["interarrival.cli2srv"] and flow["interarrival.cli2srv"]["max"] > 0 then print(""..i18n("flow_details.packet_inter_arrival_time")..""..i18n("client").." "..i18n("server")..": ") diff --git a/src/Flow.cpp b/src/Flow.cpp index b1a80d00e3..6bc1951c5a 100644 --- a/src/Flow.cpp +++ b/src/Flow.cpp @@ -155,6 +155,15 @@ Flow::Flow(NetworkInterface *_iface, if(!iface->isPacketInterface()) last_update_time.tv_sec = (long)first_seen; + if(iface->isPacketInterface() && !iface->isSampledTraffic()) { + cli2srvPktTime = new (std::nothrow) InterarrivalStats(); + srv2cliPktTime = new (std::nothrow) InterarrivalStats(); + } else { + cli2srvPktTime = NULL; + srv2cliPktTime = NULL; + } + + #ifdef NTOPNG_PRO #ifndef HAVE_NEDGE trafficProfile = NULL; @@ -237,6 +246,9 @@ Flow::~Flow() { if(cli_ebpf) delete cli_ebpf; if(srv_ebpf) delete srv_ebpf; + if(cli2srvPktTime) delete cli2srvPktTime; + if(srv2cliPktTime) delete srv2cliPktTime; + if(isHTTP()) { if(protos.http.last_method) free(protos.http.last_method); if(protos.http.last_url) free(protos.http.last_url); @@ -2589,7 +2601,8 @@ bool Flow::update_partial_traffic_stats_db_dump() { /* *************************************** */ void Flow::updatePacketStats(InterarrivalStats *stats, const struct timeval *when) { - stats->updatePacketStats((struct timeval*)when); + if(stats) + stats->updatePacketStats((struct timeval*)when); } /* *************************************** */ @@ -2597,18 +2610,20 @@ void Flow::updatePacketStats(InterarrivalStats *stats, const struct timeval *whe void Flow::dumpPacketStats(lua_State* vm, bool cli2srv_direction) { InterarrivalStats *s = cli2srv_direction ? getCli2SrvIATStats() : getSrv2CliIATStats(); - lua_newtable(vm); + if(s) { + lua_newtable(vm); - lua_push_float_table_entry(vm, "min", (float)s->getMin()); - lua_push_float_table_entry(vm, "max", (float)s->getMax()); - lua_push_float_table_entry(vm, "avg", s->getAvg()); - lua_push_float_table_entry(vm, "stddev", s->getStdDev()); + lua_push_uint64_table_entry(vm, "min", s->getMin()); + lua_push_uint64_table_entry(vm, "max", s->getMax()); + lua_push_float_table_entry(vm, "avg", s->getAvg()); + lua_push_float_table_entry(vm, "stddev", s->getStdDev()); - // ntop->getTrace()->traceEvent(TRACE_NORMAL, "%u / %.1f / %u", s->getMin(), s->getAvg(), s->getMax()); + // ntop->getTrace()->traceEvent(TRACE_NORMAL, "%u / %.1f / %u", s->getMin(), s->getAvg(), s->getMax()); - lua_pushstring(vm, cli2srv_direction ? "interarrival.cli2srv" : "interarrival.srv2cli"); - lua_insert(vm, -2); - lua_settable(vm, -3); + lua_pushstring(vm, cli2srv_direction ? "interarrival.cli2srv" : "interarrival.srv2cli"); + lua_insert(vm, -2); + lua_settable(vm, -3); + } } /* *************************************** */