]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
htp layer: add memory usage counter
authorEric Leblond <eric@regit.org>
Mon, 30 Dec 2013 15:14:54 +0000 (16:14 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 10 Jan 2014 14:24:00 +0000 (15:24 +0100)
This patch adds a memory counter for HTP memory usage. As
there is no thread variables available in application layer
the counter has been added to the TCP reassembly thread.

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

index b21e874ced92dd9ee44adfef8793a390d2a09537..ca300c81ffa1dc1fbe5672432e7894cce710eb0d 100644 (file)
@@ -36,6 +36,8 @@
 #include "util-mem.h"
 #include "util-misc.h"
 
+#include "app-layer-htp-mem.h"
+
 uint64_t htp_config_memcap = 0;
 
 SC_ATOMIC_DECLARE(uint64_t, htp_memuse);
@@ -71,6 +73,12 @@ void HTPDecrMemuse(uint64_t size)
     return;
 }
 
+void HTPMemuseCounter(ThreadVars *tv,  TcpReassemblyThreadCtx *trt)
+{
+    uint64_t memusecopy = SC_ATOMIC_GET(htp_memuse);
+    SCPerfCounterSetUI64(trt->counter_htp_memuse, tv->sc_perf_pca, memusecopy);
+    return;
+}
 /**
  *  \brief Check if alloc'ing "size" would mean we're over memcap
  *
index 9cf1f18f403fd995bafd4e2aa52c71e5f98e1af9..54b21f5d27d5bf06090fcb88fe8c2b929808d035 100644 (file)
  * 02110-1301, USA.
  */
 
+#include "stream-tcp-reassemble.h"
+
 void HTPParseMemcap();
 void *HTPMalloc(size_t size);
 void *HTPRealloc(void *ptr, size_t orig_size, size_t size);
 void HTPFree(void *ptr, size_t size);
+
+
+void HTPMemuseCounter(ThreadVars *tv, TcpReassemblyThreadCtx *trt);
index 29d97b8d2e38223e095a18d8b7b22a89083ed2f5..9a63314690b1a333c6eab1115b492620c6f910c6 100644 (file)
@@ -41,6 +41,7 @@
 #include "util-profiling.h"
 #include "util-validate.h"
 #include "decode-events.h"
+#include "app-layer-htp-mem.h"
 
 /**
  * \brief This is for the app layer in general and it contains per thread
@@ -341,6 +342,8 @@ int AppLayerHandleTCPData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
         }
     }
 
+    /** \fixme a bit hacky but will be improved in 2.1 */
+    HTPMemuseCounter(tv, ra_ctx);
     goto end;
  failure:
     r = -1;
index 281a50d5f2570885e8ea8d919823af3c28a12644..5ae43960e0f3e46bc49ac8f7d977370f4ec407da 100644 (file)
@@ -62,6 +62,9 @@ typedef struct TcpReassemblyThreadCtx_ {
     uint16_t counter_tcp_reass_memuse;
     /** count number of streams with a unrecoverable stream gap (missing pkts) */
     uint16_t counter_tcp_reass_gap;
+    /** account memory usage by suricata to handle HTTP protocol (not counting
+     * libhtp memory usage)*/
+    uint16_t counter_htp_memuse;
 } TcpReassemblyThreadCtx;
 
 #define OS_POLICY_DEFAULT   OS_POLICY_BSD
index f004b602c1b0bc2f07944901d47a6c29f017f21d..f8a8947a4d6c847bbfca2669d485ba284e15f607 100644 (file)
@@ -4559,6 +4559,10 @@ TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data)
     stt->ra_ctx->counter_tcp_reass_gap = SCPerfTVRegisterCounter("tcp.reassembly_gap", tv,
                                                         SC_PERF_TYPE_UINT64,
                                                         "NULL");
+    /** \fixme Find a better place in 2.1 as it is linked with app layer */
+    stt->ra_ctx->counter_htp_memuse = SCPerfTVRegisterCounter("http.memuse", tv,
+                                                        SC_PERF_TYPE_UINT64,
+                                                        "NULL");
 
     SCLogDebug("StreamTcp thread specific ctx online at %p, reassembly ctx %p",
                 stt, stt->ra_ctx);