dns-log: log requests even when there is no response

The JSON logger had already been updated to handle
transactions without a response. Apply the same logic
to the older dns-log where a logger is registered
for each direction.

Fixes issue 2012.
pull/2534/head
Jason Ish 10 years ago committed by Victor Julien
parent d8b5bf9bc6
commit 21bbac5648

@ -165,8 +165,8 @@ static void LogAnswer(LogDnsLogThread *aft, char *timebuf, char *srcip, char *ds
SCMutexUnlock(&hlog->file_ctx->fp_mutex); SCMutexUnlock(&hlog->file_ctx->fp_mutex);
} }
static int LogDnsLogger(ThreadVars *tv, void *data, const Packet *p, Flow *f, static int LogDnsLogger(ThreadVars *tv, void *data, const Packet *p,
void *state, void *tx, uint64_t tx_id) Flow *f, void *state, void *tx, uint64_t tx_id, uint8_t direction)
{ {
LogDnsLogThread *aft = (LogDnsLogThread *)data; LogDnsLogThread *aft = (LogDnsLogThread *)data;
DNSTransaction *dns_tx = (DNSTransaction *)tx; DNSTransaction *dns_tx = (DNSTransaction *)tx;
@ -214,24 +214,26 @@ static int LogDnsLogger(ThreadVars *tv, void *data, const Packet *p, Flow *f,
dp = p->sp; dp = p->sp;
} }
DNSQueryEntry *query = NULL; if (direction == STREAM_TOSERVER) {
TAILQ_FOREACH(query, &dns_tx->query_list, next) { DNSQueryEntry *query = NULL;
LogQuery(aft, timebuf, dstip, srcip, dp, sp, dns_tx, query); TAILQ_FOREACH(query, &dns_tx->query_list, next) {
} LogQuery(aft, timebuf, dstip, srcip, dp, sp, dns_tx, query);
}
if (dns_tx->rcode) } else if (direction == STREAM_TOCLIENT) {
LogAnswer(aft, timebuf, srcip, dstip, sp, dp, dns_tx, NULL); if (dns_tx->rcode)
if (dns_tx->recursion_desired) LogAnswer(aft, timebuf, srcip, dstip, sp, dp, dns_tx, NULL);
LogAnswer(aft, timebuf, srcip, dstip, sp, dp, dns_tx, NULL); if (dns_tx->recursion_desired)
LogAnswer(aft, timebuf, srcip, dstip, sp, dp, dns_tx, NULL);
DNSAnswerEntry *entry = NULL;
TAILQ_FOREACH(entry, &dns_tx->answer_list, next) { DNSAnswerEntry *entry = NULL;
LogAnswer(aft, timebuf, srcip, dstip, sp, dp, dns_tx, entry); TAILQ_FOREACH(entry, &dns_tx->answer_list, next) {
} LogAnswer(aft, timebuf, srcip, dstip, sp, dp, dns_tx, entry);
}
entry = NULL; entry = NULL;
TAILQ_FOREACH(entry, &dns_tx->authority_list, next) { TAILQ_FOREACH(entry, &dns_tx->authority_list, next) {
LogAnswer(aft, timebuf, srcip, dstip, sp, dp, dns_tx, entry); LogAnswer(aft, timebuf, srcip, dstip, sp, dp, dns_tx, entry);
}
} }
aft->dns_cnt++; aft->dns_cnt++;
@ -239,6 +241,18 @@ end:
return 0; return 0;
} }
static int LogDnsRequestLogger(ThreadVars *tv, void *data, const Packet *p,
Flow *f, void *state, void *tx, uint64_t tx_id)
{
return LogDnsLogger(tv, data, p, f, state, tx, tx_id, STREAM_TOSERVER);
}
static int LogDnsResponseLogger(ThreadVars *tv, void *data, const Packet *p,
Flow *f, void *state, void *tx, uint64_t tx_id)
{
return LogDnsLogger(tv, data, p, f, state, tx, tx_id, STREAM_TOCLIENT);
}
static TmEcode LogDnsLogThreadInit(ThreadVars *t, void *initdata, void **data) static TmEcode LogDnsLogThreadInit(ThreadVars *t, void *initdata, void **data)
{ {
LogDnsLogThread *aft = SCMalloc(sizeof(LogDnsLogThread)); LogDnsLogThread *aft = SCMalloc(sizeof(LogDnsLogThread));
@ -346,9 +360,15 @@ static OutputCtx *LogDnsLogInitCtx(ConfNode *conf)
void LogDnsLogRegister (void) void LogDnsLogRegister (void)
{ {
OutputRegisterTxModule(LOGGER_DNS, MODULE_NAME, "dns-log", LogDnsLogInitCtx, /* Request logger. */
ALPROTO_DNS, LogDnsLogger, LogDnsLogThreadInit, LogDnsLogThreadDeinit, OutputRegisterTxModuleWithProgress(LOGGER_DNS, MODULE_NAME, "dns-log",
LogDnsLogExitPrintStats); LogDnsLogInitCtx, ALPROTO_DNS, LogDnsRequestLogger, 0, 1,
LogDnsLogThreadInit, LogDnsLogThreadDeinit, LogDnsLogExitPrintStats);
/* Response logger. */
OutputRegisterTxModuleWithProgress(LOGGER_DNS, MODULE_NAME, "dns-log",
LogDnsLogInitCtx, ALPROTO_DNS, LogDnsResponseLogger, 1, 1,
LogDnsLogThreadInit, LogDnsLogThreadDeinit, LogDnsLogExitPrintStats);
/* enable the logger for the app layer */ /* enable the logger for the app layer */
SCLogDebug("registered %s", MODULE_NAME); SCLogDebug("registered %s", MODULE_NAME);

Loading…
Cancel
Save