]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
flow: counters for total number of flows 2698/head
authorVictor Julien <victor@inliniac.net>
Fri, 5 May 2017 13:24:45 +0000 (15:24 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 9 May 2017 08:50:05 +0000 (10:50 +0200)
flow.tcp
flow.udp
flow.icmpv4
flow.icmpv6

src/decode.c
src/decode.h
src/flow-hash.c
src/flow-worker.c

index 35d41053ae4317fa381a4cae2b363f5e22f269c5..3c128edacd8068a84c41d7e8ba1d746d75e659d9 100644 (file)
@@ -430,6 +430,11 @@ void DecodeRegisterPerfCounters(DecodeThreadVars *dtv, ThreadVars *tv)
     dtv->counter_erspan = StatsRegisterMaxCounter("decoder.erspan", tv);
     dtv->counter_flow_memcap = StatsRegisterCounter("flow.memcap", tv);
 
+    dtv->counter_flow_tcp = StatsRegisterCounter("flow.tcp", tv);
+    dtv->counter_flow_udp = StatsRegisterCounter("flow.udp", tv);
+    dtv->counter_flow_icmp4 = StatsRegisterCounter("flow.icmpv4", tv);
+    dtv->counter_flow_icmp6 = StatsRegisterCounter("flow.icmpv6", tv);
+
     dtv->counter_defrag_ipv4_fragments =
         StatsRegisterCounter("defrag.ipv4.fragments", tv);
     dtv->counter_defrag_ipv4_reassembled =
index 2d2c48c64ea31084209077908310c008ac54cad8..92ae217c828d49346dd548fba406e40d9c534b2d 100644 (file)
@@ -665,6 +665,11 @@ typedef struct DecodeThreadVars_
 
     uint16_t counter_flow_memcap;
 
+    uint16_t counter_flow_tcp;
+    uint16_t counter_flow_udp;
+    uint16_t counter_flow_icmp4;
+    uint16_t counter_flow_icmp6;
+
      uint16_t counter_invalid_events[DECODE_EVENT_PACKET_MAX];
     /* thread data for flow logging api: only used at forced
      * flow recycle during lookups */
index 89c1940b33e40e94d1b7aa15b3950bcf139f153a..ff4d634f4e2e783bad01d3902a52a73bbf261ad2 100644 (file)
@@ -339,6 +339,31 @@ static inline int FlowCreateCheck(const Packet *p)
     return 1;
 }
 
+static inline void FlowUpdateCounter(ThreadVars *tv, DecodeThreadVars *dtv,
+        uint8_t proto)
+{
+#ifdef UNITTESTS
+    if (tv && dtv) {
+#endif
+        switch (proto){
+            case IPPROTO_UDP:
+                StatsIncr(tv, dtv->counter_flow_udp);
+                break;
+            case IPPROTO_TCP:
+                StatsIncr(tv, dtv->counter_flow_tcp);
+                break;
+            case IPPROTO_ICMP:
+                StatsIncr(tv, dtv->counter_flow_icmp4);
+                break;
+            case IPPROTO_ICMPV6:
+                StatsIncr(tv, dtv->counter_flow_icmp6);
+                break;
+        }
+#ifdef UNITTESTS
+    }
+#endif
+}
+
 /**
  *  \brief Get a new flow
  *
@@ -406,6 +431,7 @@ static Flow *FlowGetNew(ThreadVars *tv, DecodeThreadVars *dtv, const Packet *p)
     }
 
     FLOWLOCK_WRLOCK(f);
+    FlowUpdateCounter(tv, dtv, p->proto);
     return f;
 }
 
index d83eb843a680c301efe564ff5145b6d730ffd543..456720c2dc0561eca5b26b94e941ecfefc1a3bcb 100644 (file)
@@ -119,6 +119,7 @@ static TmEcode FlowWorkerThreadInit(ThreadVars *tv, const void *initdata, void *
         return TM_ECODE_FAILED;
     }
 
+    DecodeRegisterPerfCounters(fw->dtv, tv);
     AppLayerRegisterThreadCounters(tv);
 
     /* setup pq for stream end pkts */