]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
http: make http.memuse a global counter
authorVictor Julien <victor@inliniac.net>
Thu, 8 Jan 2015 00:44:18 +0000 (01:44 +0100)
committerVictor Julien <victor@inliniac.net>
Wed, 27 May 2015 12:14:47 +0000 (14:14 +0200)
http.memcap as well.

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

index f024ef9aa496f64c3e9b9d09ce06b0fd9a605f0d..c4f94e826ee723b59d6ee83a6222c5f19a80ee9e 100644 (file)
@@ -78,14 +78,18 @@ void HTPDecrMemuse(uint64_t size)
     return;
 }
 
-void HTPMemuseCounter(ThreadVars *tv,  TcpReassemblyThreadCtx *trt)
+uint64_t HTPMemuseGlobalCounter(void)
 {
     uint64_t tmpval = SC_ATOMIC_GET(htp_memuse);
-    StatsSetUI64(tv, trt->counter_htp_memuse, tmpval);
-    tmpval = SC_ATOMIC_GET(htp_memcap);
-    StatsSetUI64(tv, trt->counter_htp_memcap, tmpval);
-    return;
+    return tmpval;
 }
+
+uint64_t HTPMemcapGlobalCounter(void)
+{
+    uint64_t tmpval = SC_ATOMIC_GET(htp_memcap);
+    return tmpval;
+}
+
 /**
  *  \brief Check if alloc'ing "size" would mean we're over memcap
  *
index 54b21f5d27d5bf06090fcb88fe8c2b929808d035..44b50f5c084896f380b458c06de4355d6f490ac0 100644 (file)
@@ -22,5 +22,5 @@ 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);
+uint64_t HTPMemuseGlobalCounter(void);
+uint64_t HTPMemcapGlobalCounter(void);
index 2ded474ed99a579e86783cf3a4589336fd7a4913..fc8c564ced802e7681fadc81aab6817ce8e01df4 100644 (file)
@@ -38,6 +38,7 @@
 #include "debug.h"
 #include "decode.h"
 #include "threads.h"
+#include "counters.h"
 
 #include "util-print.h"
 #include "util-pool.h"
@@ -2546,6 +2547,9 @@ void HTPConfigure(void)
         HTPConfigSetDefaultsPhase2(s->name, htprec);
     }
 
+    StatsRegisterGlobalCounter("http.memuse", HTPMemuseGlobalCounter);
+    StatsRegisterGlobalCounter("http.memcap", HTPMemcapGlobalCounter);
+
     SCReturn;
 }
 
index bc6e986adb443654020529241086a20ca735e227..5cb18e1c38ae007f10cd3ee4b6c3c557ea890c7f 100644 (file)
@@ -435,9 +435,7 @@ int AppLayerHandleTCPData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
     }
 
     /** \fixme a bit hacky but will be improved in 2.1 */
-    if (*alproto == ALPROTO_HTTP)
-        HTPMemuseCounter(tv, ra_ctx);
-    else if (*alproto == ALPROTO_DNS)
+    if (*alproto == ALPROTO_DNS)
         DNSUpdateCounters(tv, app_tctx);
     goto end;
  failure:
index c5e926fc9c9104379f68e11180c2374f3f633505..b6e798ce0be6932f472167febfbde60b3e93bedb 100644 (file)
@@ -59,11 +59,6 @@ typedef struct TcpReassemblyThreadCtx_ {
     uint16_t counter_tcp_stream_depth;
     /** 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;
-    /* number of allocation failed due to memcap when handling HTTP protocol */
-    uint16_t counter_htp_memcap;
 #ifdef DEBUG
     uint64_t fp1;
     uint64_t fp2;
index 6e08f8195872de9bb2f563ea01dc55da0f92543e..d5f90c8fbb601107da7dd8e442691876f778cba9 100644 (file)
@@ -65,6 +65,7 @@
 #include "app-layer.h"
 #include "app-layer-parser.h"
 #include "app-layer-protos.h"
+#include "app-layer-htp-mem.h"
 
 #include "util-host-os-info.h"
 #include "util-privs.h"
@@ -5092,9 +5093,6 @@ TmEcode StreamTcpThreadInit(ThreadVars *tv, void *initdata, void **data)
     stt->ra_ctx->counter_tcp_segment_memcap = StatsRegisterCounter("tcp.segment_memcap_drop", tv);
     stt->ra_ctx->counter_tcp_stream_depth = StatsRegisterCounter("tcp.stream_depth_reached", tv);
     stt->ra_ctx->counter_tcp_reass_gap = StatsRegisterCounter("tcp.reassembly_gap", tv);
-    /** \fixme Find a better place in 2.1 as it is linked with app layer */
-    stt->ra_ctx->counter_htp_memuse = StatsRegisterCounter("http.memuse", tv);
-    stt->ra_ctx->counter_htp_memcap = StatsRegisterCounter("http.memcap", tv);
 
     SCLogDebug("StreamTcp thread specific ctx online at %p, reassembly ctx %p",
                 stt, stt->ra_ctx);