]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
htp layer: add memory cap counter
authorEric Leblond <eric@regit.org>
Mon, 30 Dec 2013 16:29:46 +0000 (17:29 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 10 Jan 2014 14:24:00 +0000 (15:24 +0100)
This patch adds a memcap counter for HTP memory usage. Counter
is increased each time an allocation is not done due to the memcap.

src/app-layer-htp-mem.c
src/stream-tcp-reassemble.h
src/stream-tcp.c

index ca300c81ffa1dc1fbe5672432e7894cce710eb0d..f553f5ab239dbc84ce79a5f75b4b35e826a7d3a9 100644 (file)
@@ -41,6 +41,7 @@
 uint64_t htp_config_memcap = 0;
 
 SC_ATOMIC_DECLARE(uint64_t, htp_memuse);
+SC_ATOMIC_DECLARE(uint64_t, htp_memcap);
 
 void HTPParseMemcap()
 {
@@ -75,8 +76,10 @@ void HTPDecrMemuse(uint64_t size)
 
 void HTPMemuseCounter(ThreadVars *tv,  TcpReassemblyThreadCtx *trt)
 {
-    uint64_t memusecopy = SC_ATOMIC_GET(htp_memuse);
-    SCPerfCounterSetUI64(trt->counter_htp_memuse, tv->sc_perf_pca, memusecopy);
+    uint64_t tmpval = SC_ATOMIC_GET(htp_memuse);
+    SCPerfCounterSetUI64(trt->counter_htp_memuse, tv->sc_perf_pca, tmpval);
+    tmpval = SC_ATOMIC_GET(htp_memcap);
+    SCPerfCounterSetUI64(trt->counter_htp_memcap, tv->sc_perf_pca, tmpval);
     return;
 }
 /**
@@ -89,6 +92,7 @@ int HTPCheckMemcap(uint64_t size)
 {
     if (htp_config_memcap == 0 || size + SC_ATOMIC_GET(htp_memuse) <= htp_config_memcap)
         return 1;
+    (void) SC_ATOMIC_ADD(htp_memcap, 1);
     return 0;
 }
 
index 5ae43960e0f3e46bc49ac8f7d977370f4ec407da..888a050330c0505a94c217802e1554742be4c56c 100644 (file)
@@ -65,6 +65,8 @@ typedef struct TcpReassemblyThreadCtx_ {
     /** account memory usage by suricata to handle HTTP protocol (not counting
      * libhtp memory usage)*/
     uint16_t counter_htp_memuse;
+    /* number of allocation failed due to memcap when handling HTTP protocol */
+    uint16_t counter_htp_memcap;
 } TcpReassemblyThreadCtx;
 
 #define OS_POLICY_DEFAULT   OS_POLICY_BSD
index f8a8947a4d6c847bbfca2669d485ba284e15f607..97178d66b1eb74b1328e84c542e25b4067439650 100644 (file)
@@ -4563,6 +4563,9 @@ TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data)
     stt->ra_ctx->counter_htp_memuse = SCPerfTVRegisterCounter("http.memuse", tv,
                                                         SC_PERF_TYPE_UINT64,
                                                         "NULL");
+    stt->ra_ctx->counter_htp_memcap = SCPerfTVRegisterCounter("http.memcap", tv,
+                                                        SC_PERF_TYPE_UINT64,
+                                                        "NULL");
 
     SCLogDebug("StreamTcp thread specific ctx online at %p, reassembly ctx %p",
                 stt, stt->ra_ctx);