]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow: add flow.tcp_reuse counter
authorVictor Julien <victor@inliniac.net>
Mon, 15 Dec 2014 16:42:56 +0000 (17:42 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 18 Feb 2015 08:18:42 +0000 (09:18 +0100)
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
src/stream-tcp.c

index 217681c609bc7372c9a97580b39ce62cf337dd0c..3bfa477a4a6ae76e0b5ab63b191504ce28503210 100644 (file)
@@ -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) {
index 77d9b09a91b8a004750f0bb5532aa8a997061a21..6f339ae13ef1b4336badcdc3fb8382801ac3fba0 100644 (file)
@@ -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");