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.
pull/788/head
Victor Julien 12 years ago
parent 66f764ce7b
commit 9a21a2f64b

@ -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, },

@ -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);

@ -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);
}

Loading…
Cancel
Save