Skip to content

Commit ef9c052

Browse files
authored
Merge pull request #75 from CESNET/fix_flow_export_reason
FIXED export reason
2 parents a622a76 + dd61280 commit ef9c052

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

storage/cache.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ int NHTFlowCache::put_pkt(Packet &pkt)
429429
}
430430
} else {
431431
if (pkt.ts.tv_sec - flow->m_flow.time_last.tv_sec >= m_inactive) {
432-
m_flow_table[flow_index]->m_flow.end_reason = FLOW_END_INACTIVE;
432+
m_flow_table[flow_index]->m_flow.end_reason = get_export_reason(flow->m_flow);
433433
plugins_pre_export(flow->m_flow);
434434
export_flow(flow_index);
435435
#ifdef FLOW_CACHE_STATS
@@ -466,11 +466,21 @@ int NHTFlowCache::put_pkt(Packet &pkt)
466466
return 0;
467467
}
468468

469+
uint8_t NHTFlowCache::get_export_reason(Flow &flow)
470+
{
471+
if ((flow.src_tcp_flags | flow.dst_tcp_flags) & (0x01 | 0x04)) {
472+
// When FIN or RST is set, TCP connection ended naturally
473+
return FLOW_END_EOF;
474+
} else {
475+
return FLOW_END_INACTIVE;
476+
}
477+
}
478+
469479
void NHTFlowCache::export_expired(time_t ts)
470480
{
471481
for (decltype(m_timeout_idx) i = m_timeout_idx; i < m_timeout_idx + m_line_new_idx; i++) {
472482
if (!m_flow_table[i]->is_empty() && ts - m_flow_table[i]->m_flow.time_last.tv_sec >= m_inactive) {
473-
m_flow_table[i]->m_flow.end_reason = FLOW_END_INACTIVE;
483+
m_flow_table[i]->m_flow.end_reason = get_export_reason(m_flow_table[i]->m_flow);
474484
plugins_pre_export(m_flow_table[i]->m_flow);
475485
export_flow(i);
476486
#ifdef FLOW_CACHE_STATS

storage/cache.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ class NHTFlowCache : public StoragePlugin
199199
void flush(Packet &pkt, size_t flow_index, int ret, bool source_flow);
200200
bool create_hash_key(Packet &pkt);
201201
void export_flow(size_t index);
202+
static uint8_t get_export_reason(Flow &flow);
202203
void finish();
203204

204205
#ifdef FLOW_CACHE_STATS

0 commit comments

Comments
 (0)