From cddbb0f606a0e20eb5ca5e8bef6540f8deedd6e1 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Thu, 8 Jan 2015 01:44:18 +0100 Subject: [PATCH] http: make http.memuse a global counter http.memcap as well. --- src/app-layer-htp-mem.c | 14 +++++++++----- src/app-layer-htp-mem.h | 4 ++-- src/app-layer-htp.c | 4 ++++ src/app-layer.c | 4 +--- src/stream-tcp-reassemble.h | 5 ----- src/stream-tcp.c | 4 +--- 6 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/app-layer-htp-mem.c b/src/app-layer-htp-mem.c index f024ef9aa4..c4f94e826e 100644 --- a/src/app-layer-htp-mem.c +++ b/src/app-layer-htp-mem.c @@ -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 * diff --git a/src/app-layer-htp-mem.h b/src/app-layer-htp-mem.h index 54b21f5d27..44b50f5c08 100644 --- a/src/app-layer-htp-mem.h +++ b/src/app-layer-htp-mem.h @@ -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); diff --git a/src/app-layer-htp.c b/src/app-layer-htp.c index 2ded474ed9..fc8c564ced 100644 --- a/src/app-layer-htp.c +++ b/src/app-layer-htp.c @@ -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; } diff --git a/src/app-layer.c b/src/app-layer.c index bc6e986adb..5cb18e1c38 100644 --- a/src/app-layer.c +++ b/src/app-layer.c @@ -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: diff --git a/src/stream-tcp-reassemble.h b/src/stream-tcp-reassemble.h index c5e926fc9c..b6e798ce0b 100644 --- a/src/stream-tcp-reassemble.h +++ b/src/stream-tcp-reassemble.h @@ -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; diff --git a/src/stream-tcp.c b/src/stream-tcp.c index 6e08f81958..d5f90c8fbb 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -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);