From: Eric Leblond Date: Mon, 30 Dec 2013 16:29:46 +0000 (+0100) Subject: htp layer: add memory cap counter X-Git-Tag: suricata-2.0rc1~230 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4d6b48ea9ed4660111dd3100bc245584a1d99ba1;p=thirdparty%2Fsuricata.git htp layer: add memory cap counter This patch adds a memcap counter for HTP memory usage. Counter is increased each time an allocation is not done due to the memcap. --- diff --git a/src/app-layer-htp-mem.c b/src/app-layer-htp-mem.c index ca300c81ff..f553f5ab23 100644 --- a/src/app-layer-htp-mem.c +++ b/src/app-layer-htp-mem.c @@ -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; } diff --git a/src/stream-tcp-reassemble.h b/src/stream-tcp-reassemble.h index 5ae43960e0..888a050330 100644 --- a/src/stream-tcp-reassemble.h +++ b/src/stream-tcp-reassemble.h @@ -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 diff --git a/src/stream-tcp.c b/src/stream-tcp.c index f8a8947a4d..97178d66b1 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -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);