]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dns: update counters 788/head
authorVictor Julien <victor@inliniac.net>
Tue, 21 Jan 2014 13:18:37 +0000 (14:18 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 21 Jan 2014 13:21:17 +0000 (14:21 +0100)
This patch updates the DNS counters from the main AppLayer entry
functions. Due to the limited scope of AppLayerThreadCtx some of
the logic had to be implemented in app-layer.c, where it doesn't
belong.

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

index 4b6062828b65732a37c40825d34bf4ebf74997a5..976fa7b6422fc5560bec27c5449b6227a54afb29 100644 (file)
@@ -95,6 +95,13 @@ int DNSCheckMemcap(uint32_t want, DNSState *state) {
     return 0;
 }
 
+void DNSMemcapGetCounters(uint64_t *memuse, uint64_t *memcap_state,
+                          uint64_t *memcap_global)
+{
+    *memuse = SC_ATOMIC_GET(dns_memuse);
+    *memcap_state = SC_ATOMIC_GET(dns_memcap_state);
+    *memcap_global = SC_ATOMIC_GET(dns_memcap_global);
+}
 
 SCEnumCharMap dns_decoder_event_table[ ] = {
     { "UNSOLLICITED_RESPONSE",      DNS_DECODER_EVENT_UNSOLLICITED_RESPONSE, },
index d0ecf7b9f8bc7f34c67e57b9ef2b94d53cdb614c..62532123f28b55baf349132c5c8be795ac587579 100644 (file)
@@ -169,6 +169,8 @@ 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);
 
 void RegisterDNSParsers(void);
 void DNSParserTests(void);
index 1ca58896bd8d36848d111f8330de5b63361887c8..5bdf0da46f6324d064872d362ddcdbb14c115cee 100644 (file)
@@ -41,7 +41,9 @@
 #include "util-profiling.h"
 #include "util-validate.h"
 #include "decode-events.h"
+
 #include "app-layer-htp-mem.h"
+#include "app-layer-dns-common.h"
 
 /**
  * \brief This is for the app layer in general and it contains per thread
@@ -68,6 +70,22 @@ 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);
+
+    SCPerfCounterSetUI64(app_tctx->counter_dns_memuse,
+                         tv->sc_perf_pca, memuse);
+    SCPerfCounterSetUI64(app_tctx->counter_dns_memcap_state,
+                         tv->sc_perf_pca, memcap_state);
+    SCPerfCounterSetUI64(app_tctx->counter_dns_memcap_global,
+                         tv->sc_perf_pca, memcap_global);
+}
+
 /***** L7 layer dispatchers *****/
 
 int AppLayerHandleTCPData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
@@ -347,7 +365,10 @@ int AppLayerHandleTCPData(ThreadVars *tv, TcpReassemblyThreadCtx *ra_ctx,
     }
 
     /** \fixme a bit hacky but will be improved in 2.1 */
-    HTPMemuseCounter(tv, ra_ctx);
+    if (*alproto == ALPROTO_HTTP)
+        HTPMemuseCounter(tv, ra_ctx);
+    else if (*alproto == ALPROTO_DNS)
+        DNSUpdateCounters(tv, app_tctx);
     goto end;
  failure:
     r = -1;
@@ -372,6 +393,7 @@ int AppLayerHandleUdp(ThreadVars *tv, AppLayerThreadCtx *tctx, Packet *p, Flow *
     SCEnter();
 
     int r = 0;
+    AppProto alproto;
 
     FLOWLOCK_WRLOCK(f);
 
@@ -426,9 +448,13 @@ 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);
 }