Commit 429f47bc authored by Vladimír Čunát's avatar Vladimír Čunát Committed by Ondřej Surý

modules/dnstap: nitpicks

parent b5851775
......@@ -75,7 +75,6 @@ endif
# check for fstrm and protobuf for dnstap
ifeq ($(HAS_libfstrm)|$(HAS_libprotobuf-c),yes|yes)
BUILD_CFLAGS += -DENABLE_DNSTAP
ENABLE_DNSTAP := yes
endif
......
......@@ -107,6 +107,7 @@ struct kr_request {
const struct sockaddr *dst_addr;
const knot_pkt_t *packet;
const knot_rrset_t *opt;
_Bool tcp;
} qsource;
struct {
unsigned int rtt;
......
......@@ -234,7 +234,8 @@ The project can be built with code coverage tracking using the ``COVERAGE=1`` va
Running unit and integration tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The unit tests require cmocka_ and are executed with ``make check``.
The unit tests require cmocka_ and are executed by ``make check``.
Tests for the dnstap module need go and are executed by ``make ckeck-dnstap``.
The integration tests use Deckard, the `DNS test harness <deckard>`_.
......
......@@ -133,7 +133,7 @@ struct kr_request {
const struct sockaddr *dst_addr;
const knot_pkt_t *packet;
const knot_rrset_t *opt;
bool tcp; /* true if the query is on tcp */
bool tcp; /**< true if the request is on tcp; only meaningful if (dst_addr) */
} qsource;
struct {
unsigned rtt; /**< Current upstream RTT */
......
......@@ -102,10 +102,10 @@ static void set_address(const struct sockaddr *sockaddr,
/* dnstap_log prepares dnstap message and sent it to fstrm */
static int dnstap_log(kr_layer_t *ctx) {
struct kr_request *req = ctx->req;
struct kr_module *module = ctx->api->data;
struct kr_rplan *rplan = &req->rplan;
struct dnstap_data *dnstap_dt = module->data;
const struct kr_request *req = ctx->req;
const struct kr_module *module = ctx->api->data;
const struct kr_rplan *rplan = &req->rplan;
const struct dnstap_data *dnstap_dt = module->data;
/* check if we have a valid iothread */
if (!dnstap_dt->iothread || !dnstap_dt->ioq) {
......@@ -126,13 +126,6 @@ static int dnstap_log(kr_layer_t *ctx) {
/* Only handling response */
m.type = DNSTAP__MESSAGE__TYPE__RESOLVER_RESPONSE;
if (req->qsource.tcp) {
m.socket_protocol = DNSTAP__SOCKET_PROTOCOL__TCP;
} else {
m.socket_protocol = DNSTAP__SOCKET_PROTOCOL__UDP;
}
m.has_socket_protocol = true;
if (req->qsource.addr) {
set_address(req->qsource.addr,
&m.query_address,
......@@ -142,6 +135,13 @@ static int dnstap_log(kr_layer_t *ctx) {
}
if (req->qsource.dst_addr) {
if (req->qsource.tcp) {
m.socket_protocol = DNSTAP__SOCKET_PROTOCOL__TCP;
} else {
m.socket_protocol = DNSTAP__SOCKET_PROTOCOL__UDP;
}
m.has_socket_protocol = true;
set_address(req->qsource.dst_addr,
&m.response_address,
&m.has_response_address,
......@@ -303,17 +303,6 @@ static int find_string(const JsonNode *node, char **val, size_t len) {
return kr_ok();
}
/* find_int copies json int into val
* node must be of type JSON_NUMBER */
static int find_int(const JsonNode *node, int *val) {
if (!node || !node->key || !val) {
return kr_error(EINVAL);
}
assert(node->tag == JSON_NUMBER);
*val = node->number_;
return kr_ok();
}
/* find_bool returns bool from json */
static bool find_bool(const JsonNode *node) {
if (!node || !node->key) {
......
......@@ -6,12 +6,12 @@ CONFIG := $(DNSTAP_PATH)/config
CMD := daemon/kresd
ZONES := "fake1.localdomain,fake2.localdomain,fake3.localdomain"
TIMEOUT := 60s
check-dnstap:
check-dnstap: daemon
@echo "Checking dnstap functionality"
GOPATH=$(GOPATH) go get -u github.com/FiloSottile/gvt
cd $(DNSTAP_PATH) && $(GOPATH)/bin/gvt restore
GOPATH=$(GOPATH) go install $(DNSTAP_TEST)
$(GOPATH)/bin/$(DNSTAP_TEST) -c $(CONFIG) -cmd $(CMD) -q $(ZONES) -t $(TIMEOUT)
$(GOPATH)/bin/$(DNSTAP_TEST) -c $(CONFIG) -cmd $(CMD) -q $(ZONES) -t $(TIMEOUT)
clean-dnstap:
rm -rf $(GOPATH)/bin $(GOPATH)/pkg
......
......@@ -29,6 +29,6 @@ deckard: check-integration
# Targets
tests: check-unit
tests-clean: $(foreach test,$(tests_BIN),$(test)-clean) mock_cmodule-clean
tests-clean: $(foreach test,$(tests_BIN),$(test)-clean) mock_cmodule-clean clean-dnstap
.PHONY: tests tests-clean check-integration deckard
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment