Skip to content
Snippets Groups Projects
Commit 2bcb1930 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

dnstap: proof of concept query log (moreless)

parent 3d09bec3
No related branches found
No related tags found
No related merge requests found
......@@ -318,6 +318,7 @@ knsec3hash_LDADD = libknotus.la libknots.la libknot.la
if HAVE_DNSTAP
kdig_LDADD += dnstap/libdnstap.la
khost_LDADD += dnstap/libdnstap.la
libknotd_la_LIBADD += dnstap/libdnstap.la
endif
# Create storage and run-time directories
......
......@@ -17,6 +17,9 @@
#include "knot/modules/dnstap.h"
#include "knot/nameserver/query_module.h"
#include "knot/nameserver/process_query.h"
#include "dnstap/dnstap.pb-c.h"
#include "dnstap/writer.h"
#include "dnstap/message.h"
#include "common/descriptor.h"
/* Defines. */
......@@ -29,9 +32,19 @@ static int dnstap_query_log(int state, knot_pkt_t *pkt, struct query_data *qdata
}
char *qname = knot_dname_to_str(knot_pkt_qname(pkt));
MODULE_ERR("query_log: %s\n", qname);
MODULE_ERR("query_log: %s (%u qdcount)\n", qname, knot_wire_get_qdcount(pkt->wire));
free(qname);
struct timeval tv;
gettimeofday(&tv, NULL);
Dnstap__Message msg;
memset(&msg, 0, sizeof(Dnstap__Message));
dt_message_fill(&msg, DNSTAP__MESSAGE__TYPE__AUTH_QUERY,
(const struct sockaddr *)qdata->param->query_source, IPPROTO_UDP,
pkt->wire, pkt->size, &tv, NULL);
/* deal with it later (ret) */
dt_writer_write(ctx, (const ProtobufCMessage *)&msg);
return state;
}
......@@ -45,6 +58,16 @@ static int dnstap_answer_log(int state, knot_pkt_t *pkt, struct query_data *qdat
MODULE_ERR("answer_log: %s (%u ancount)\n", qname, knot_wire_get_ancount(pkt->wire));
free(qname);
struct timeval tv;
gettimeofday(&tv, NULL);
Dnstap__Message msg;
memset(&msg, 0, sizeof(Dnstap__Message));
dt_message_fill(&msg, DNSTAP__MESSAGE__TYPE__AUTH_RESPONSE,
(const struct sockaddr *)qdata->param->query_source, IPPROTO_UDP,
pkt->wire, pkt->size, NULL, &tv);
/* deal with it later (ret) */
dt_writer_write(ctx, (const ProtobufCMessage *)&msg);
return state;
}
......@@ -52,7 +75,7 @@ int dnstap_load(struct query_plan *plan, struct query_module *self)
{
/* Save in query module, it takes ownership from now on. */
self->ctx = 0x1;
self->ctx = dt_writer_create(self->param, "something");
query_plan_step(plan, QPLAN_BEGIN, dnstap_query_log, self->ctx);
query_plan_step(plan, QPLAN_END, dnstap_answer_log, self->ctx);
......@@ -62,5 +85,7 @@ int dnstap_load(struct query_plan *plan, struct query_module *self)
int dnstap_unload(struct query_module *self)
{
dt_writer_free(self->ctx);
self->ctx = NULL;
return KNOT_EOK;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment