From db9f12ee516bcb2c8513f1755bc278979d055813 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Mon, 15 Dec 2014 17:42:56 +0100 Subject: [PATCH] flow: add flow.tcp_reuse counter This replaces the tcp.reused_ssn counter. The flow engine now enforces the TCP flow reuse logic. The counter is incremented only when the flow is timed out, so after the "tcp closed" timeout expired for a flow. --- src/flow-manager.c | 12 ++++++++++-- src/stream-tcp.c | 3 --- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/flow-manager.c b/src/flow-manager.c index 217681c609..3bfa477a4a 100644 --- a/src/flow-manager.c +++ b/src/flow-manager.c @@ -93,6 +93,7 @@ typedef struct FlowTimeoutCounters_ { uint32_t new; uint32_t est; uint32_t clo; + uint32_t tcp_reuse; } FlowTimeoutCounters; /** @@ -306,6 +307,9 @@ static uint32_t FlowManagerHashRowTimeout(Flow *f, struct timeval *ts, f->hnext = NULL; f->hprev = NULL; + if (f->flags & FLOW_TCP_REUSED) + counters->tcp_reuse++; + if (state == FLOW_STATE_NEW) f->flow_end_flags |= FLOW_END_FLAG_STATE_NEW; else if (state == FLOW_STATE_ESTABLISHED) @@ -491,6 +495,7 @@ typedef struct FlowManagerThreadData_ { uint16_t flow_mgr_spare; uint16_t flow_emerg_mode_enter; uint16_t flow_emerg_mode_over; + uint16_t flow_tcp_reuse; } FlowManagerThreadData; static TmEcode FlowManagerThreadInit(ThreadVars *t, void *initdata, void **data) @@ -535,6 +540,8 @@ static TmEcode FlowManagerThreadInit(ThreadVars *t, void *initdata, void **data) SC_PERF_TYPE_UINT64, "NULL"); ftd->flow_emerg_mode_over = SCPerfTVRegisterCounter("flow.emerg_mode_over", t, SC_PERF_TYPE_UINT64, "NULL"); + ftd->flow_tcp_reuse = SCPerfTVRegisterCounter("flow.tcp_reuse", t, + SC_PERF_TYPE_UINT64, "NULL"); PacketPoolInit(); return TM_ECODE_OK; @@ -619,7 +626,7 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data) FlowUpdateSpareFlows(); /* try to time out flows */ - FlowTimeoutCounters counters = { 0, 0, 0, }; + FlowTimeoutCounters counters = { 0, 0, 0, 0, }; FlowTimeoutHash(&ts, 0 /* check all */, ftd->min, ftd->max, &counters); @@ -640,6 +647,7 @@ static TmEcode FlowManager(ThreadVars *th_v, void *thread_data) SCPerfCounterAddUI64(ftd->flow_mgr_cnt_est, th_v->sc_perf_pca, (uint64_t)counters.est); long long unsigned int flow_memuse = SC_ATOMIC_GET(flow_memuse); SCPerfCounterSetUI64(ftd->flow_mgr_memuse, th_v->sc_perf_pca, (uint64_t)flow_memuse); + SCPerfCounterAddUI64(ftd->flow_tcp_reuse, th_v->sc_perf_pca, (uint64_t)counters.tcp_reuse); uint32_t len = 0; FQLOCK_LOCK(&flow_spare_q); @@ -1254,7 +1262,7 @@ static int FlowMgrTest05 (void) struct timeval ts; TimeGet(&ts); /* try to time out flows */ - FlowTimeoutCounters counters = { 0, 0, 0, }; + FlowTimeoutCounters counters = { 0, 0, 0, 0, }; FlowTimeoutHash(&ts, 0 /* check all */, 0, flow_config.hash_size, &counters); if (flow_recycle_q.len > 0) { diff --git a/src/stream-tcp.c b/src/stream-tcp.c index 77d9b09a91..6f339ae13e 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -4751,9 +4751,6 @@ TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data) stt->counter_tcp_no_flow = SCPerfTVRegisterCounter("tcp.no_flow", tv, SC_PERF_TYPE_UINT64, "NULL"); - stt->counter_tcp_reused_ssn = SCPerfTVRegisterCounter("tcp.reused_ssn", tv, - SC_PERF_TYPE_UINT64, - "NULL"); stt->counter_tcp_memuse = SCPerfTVRegisterCounter("tcp.memuse", tv, SC_PERF_TYPE_UINT64, "NULL");