From: Victor Julien Date: Tue, 21 Jan 2014 13:18:37 +0000 (+0100) Subject: dns: update counters X-Git-Tag: suricata-2.0rc1~177 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F788%2Fhead;p=thirdparty%2Fsuricata.git dns: update counters 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. --- diff --git a/src/app-layer-dns-common.c b/src/app-layer-dns-common.c index 4b6062828b..976fa7b642 100644 --- a/src/app-layer-dns-common.c +++ b/src/app-layer-dns-common.c @@ -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, }, diff --git a/src/app-layer-dns-common.h b/src/app-layer-dns-common.h index d0ecf7b9f8..62532123f2 100644 --- a/src/app-layer-dns-common.h +++ b/src/app-layer-dns-common.h @@ -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); diff --git a/src/app-layer.c b/src/app-layer.c index 1ca58896bd..5bdf0da46f 100644 --- a/src/app-layer.c +++ b/src/app-layer.c @@ -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); }