]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dns: register counters
authorVictor Julien <victor@inliniac.net>
Tue, 21 Jan 2014 12:22:48 +0000 (13:22 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 21 Jan 2014 13:20:16 +0000 (14:20 +0100)
Register dns memory counters.
Keep track of memcap reached conditions, and increment counters for
those.

src/app-layer-dns-common.c
src/app-layer.c

index 59ce8792903e0c8c662572f91956a51ea2dd41f3..4b6062828b65732a37c40825d34bf4ebf74997a5 100644 (file)
@@ -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;
 }
index b6d64c112e2c61406c82269172facdcf423b3330..1ca58896bd8d36848d111f8330de5b63361887c8 100644 (file)
@@ -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);