From 66f764ce7b9d4d310df918f9ed671ebab9338bd5 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 21 Jan 2014 13:22:48 +0100 Subject: [PATCH] dns: register counters Register dns memory counters. Keep track of memcap reached conditions, and increment counters for those. --- src/app-layer-dns-common.c | 16 +++++++++++++--- src/app-layer.c | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/app-layer-dns-common.c b/src/app-layer-dns-common.c index 59ce879290..4b6062828b 100644 --- a/src/app-layer-dns-common.c +++ b/src/app-layer-dns-common.c @@ -50,10 +50,16 @@ void DNSConfigSetStateMemcap(uint32_t value) { dns_config.state_memcap = value; } -SC_ATOMIC_DECLARE(uint64_t, dns_memuse); +SC_ATOMIC_DECLARE(uint64_t, dns_memuse); /**< byte counter of current memuse */ +SC_ATOMIC_DECLARE(uint64_t, dns_memcap_state); /**< counts number of 'rejects' */ +SC_ATOMIC_DECLARE(uint64_t, dns_memcap_global); /**< counts number of 'rejects' */ + void DNSConfigSetGlobalMemcap(uint64_t value) { dns_config.global_memcap = value; + SC_ATOMIC_INIT(dns_memuse); + SC_ATOMIC_INIT(dns_memcap_state); + SC_ATOMIC_INIT(dns_memcap_global); } void DNSIncrMemcap(uint32_t size, DNSState *state) { @@ -75,12 +81,16 @@ void DNSDecrMemcap(uint32_t size, DNSState *state) { int DNSCheckMemcap(uint32_t want, DNSState *state) { if (state != NULL) { - if (state->memuse + want > dns_config.state_memcap) + if (state->memuse + want > dns_config.state_memcap) { + SC_ATOMIC_ADD(dns_memcap_state, 1); return -1; + } } - if (SC_ATOMIC_GET(dns_memuse) + (uint64_t)want > dns_config.global_memcap) + if (SC_ATOMIC_GET(dns_memuse) + (uint64_t)want > dns_config.global_memcap) { + SC_ATOMIC_ADD(dns_memcap_global, 1); return -2; + } return 0; } diff --git a/src/app-layer.c b/src/app-layer.c index b6d64c112e..1ca58896bd 100644 --- a/src/app-layer.c +++ b/src/app-layer.c @@ -53,6 +53,10 @@ struct AppLayerThreadCtx_ { /* App layer parser thread context, from AppLayerParserThreadCtxAlloc(). */ AppLayerParserThreadCtx *alp_tctx; + uint16_t counter_dns_memuse; + uint16_t counter_dns_memcap_state; + uint16_t counter_dns_memcap_global; + #ifdef PROFILING uint64_t ticks_start; uint64_t ticks_end; @@ -499,6 +503,16 @@ AppLayerThreadCtx *AppLayerGetCtxThread(ThreadVars *tv) if ((app_tctx->alp_tctx = AppLayerParserThreadCtxAlloc()) == NULL) goto error; + /* tv is allowed to be NULL in unittests */ + if (tv != NULL) { + app_tctx->counter_dns_memuse = SCPerfTVRegisterCounter("dns.memuse", tv, + SC_PERF_TYPE_UINT64, "NULL"); + app_tctx->counter_dns_memcap_state = SCPerfTVRegisterCounter("dns.memcap_state", tv, + SC_PERF_TYPE_UINT64, "NULL"); + app_tctx->counter_dns_memcap_global = SCPerfTVRegisterCounter("dns.memcap_global", tv, + SC_PERF_TYPE_UINT64, "NULL"); + } + goto done; error: AppLayerDestroyCtxThread(app_tctx);