]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
counters: make DNS counters globals
authorVictor Julien <victor@inliniac.net>
Tue, 26 May 2015 17:36:59 +0000 (19:36 +0200)
committerVictor Julien <victor@inliniac.net>
Wed, 27 May 2015 12:14:47 +0000 (14:14 +0200)
src/app-layer-dns-common.c
src/app-layer-dns-common.h
src/app-layer-dns-udp.c
src/app-layer.c

index b7d40425442287936e4dffb8813ec37db6fccbb5..a11daa1eb026037a2db81b843933753df372a41e 100644 (file)
@@ -103,12 +103,22 @@ int DNSCheckMemcap(uint32_t want, DNSState *state)
     return 0;
 }
 
-void DNSMemcapGetCounters(uint64_t *memuse, uint64_t *memcap_state,
-                          uint64_t *memcap_global)
+uint64_t DNSMemcapGetMemuseCounter(void)
 {
-    *memuse = SC_ATOMIC_GET(dns_memuse);
-    *memcap_state = SC_ATOMIC_GET(dns_memcap_state);
-    *memcap_global = SC_ATOMIC_GET(dns_memcap_global);
+    uint64_t x = SC_ATOMIC_GET(dns_memuse);
+    return x;
+}
+
+uint64_t DNSMemcapGetMemcapStateCounter(void)
+{
+    uint64_t x = SC_ATOMIC_GET(dns_memcap_state);
+    return x;
+}
+
+uint64_t DNSMemcapGetMemcapGlobalCounter(void)
+{
+    uint64_t x = SC_ATOMIC_GET(dns_memcap_global);
+    return x;
 }
 
 SCEnumCharMap dns_decoder_event_table[ ] = {
index 203b2908e6d5b8e11dd037dd709f77e6b8b05e44..c19795268a4b6d42203d738a9a4c4287f0056234 100644 (file)
@@ -206,8 +206,9 @@ void DNSConfigSetGlobalMemcap(uint64_t value);
 void DNSIncrMemcap(uint32_t size, DNSState *state);
 void DNSDecrMemcap(uint32_t size, DNSState *state);
 int DNSCheckMemcap(uint32_t want, DNSState *state);
-void DNSMemcapGetCounters(uint64_t *memuse, uint64_t *memcap_state,
-                          uint64_t *memcap_global);
+uint64_t DNSMemcapGetMemuseCounter(void);
+uint64_t DNSMemcapGetMemcapStateCounter(void);
+uint64_t DNSMemcapGetMemcapGlobalCounter(void);
 
 void RegisterDNSParsers(void);
 void DNSParserTests(void);
index eb87849c5211d10df3b39cf38ba13888ba6fc5a1..3e533ba75ff20a739e35c246ecdece1c186e6f3f 100644 (file)
@@ -358,6 +358,10 @@ void RegisterDNSUDPParsers(void)
 {
     char *proto_name = "dns";
 
+    StatsRegisterGlobalCounter("dns.memuse", DNSMemcapGetMemuseCounter);
+    StatsRegisterGlobalCounter("dns.memcap_state", DNSMemcapGetMemcapStateCounter);
+    StatsRegisterGlobalCounter("dns.memcap_global", DNSMemcapGetMemcapGlobalCounter);
+
     /** DNS */
     if (AppLayerProtoDetectConfProtoDetectionEnabled("udp", proto_name)) {
         AppLayerProtoDetectRegisterProtocol(ALPROTO_DNS, proto_name);
index 5cb18e1c38ae007f10cd3ee4b6c3c557ea890c7f..0e6818fd00064c223b85585053dfd994ce991080 100644 (file)
@@ -55,10 +55,6 @@ 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;
@@ -70,19 +66,6 @@ struct AppLayerThreadCtx_ {
 #endif
 };
 
-/** \todo move this into the DNS code. Problem is that there we can't
- *        access AppLayerThreadCtx internals. */
-static void DNSUpdateCounters(ThreadVars *tv, AppLayerThreadCtx *app_tctx)
-{
-    uint64_t memuse = 0, memcap_state = 0, memcap_global = 0;
-
-    DNSMemcapGetCounters(&memuse, &memcap_state, &memcap_global);
-
-    StatsSetUI64(tv, app_tctx->counter_dns_memuse, memuse);
-    StatsSetUI64(tv, app_tctx->counter_dns_memcap_state, memcap_state);
-    StatsSetUI64(tv, app_tctx->counter_dns_memcap_global, memcap_global);
-}
-
 /***** L7 layer dispatchers *****/
 
 static void DisableAppLayer(Flow *f)
@@ -434,9 +417,6 @@ int AppLayerHandleTCPData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
         }
     }
 
-    /** \fixme a bit hacky but will be improved in 2.1 */
-    if (*alproto == ALPROTO_DNS)
-        DNSUpdateCounters(tv, app_tctx);
     goto end;
  failure:
     r = -1;
@@ -461,7 +441,6 @@ int AppLayerHandleUdp(ThreadVars *tv, AppLayerThreadCtx *tctx, Packet *p, Flow *
     SCEnter();
 
     int r = 0;
-    AppProto alproto;
 
     FLOWLOCK_WRLOCK(f);
 
@@ -516,13 +495,10 @@ int AppLayerHandleUdp(ThreadVars *tv, AppLayerThreadCtx *tctx, Packet *p, Flow *
                        "for l7");
         }
     }
-    alproto = f->alproto;
 
     FLOWLOCK_UNLOCK(f);
     PACKET_PROFILING_APP_STORE(tctx, p);
 
-    if (alproto == ALPROTO_DNS)
-        DNSUpdateCounters(tv, tctx);
     SCReturnInt(r);
 }
 
@@ -599,13 +575,6 @@ 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 = StatsRegisterCounter("dns.memuse", tv);
-        app_tctx->counter_dns_memcap_state = StatsRegisterCounter("dns.memcap_state", tv);
-        app_tctx->counter_dns_memcap_global = StatsRegisterCounter("dns.memcap_global", tv);
-    }
-
     goto done;
  error:
     AppLayerDestroyCtxThread(app_tctx);