From d50a9ad90a529ef9c41f34afd1650ce20220569f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Vavru=C5=A1a?= <marek.vavrusa@nic.cz>
Date: Wed, 18 Feb 2015 11:20:14 +0100
Subject: [PATCH] daemon: servfail queries without RD=1

---
 daemon/layer/query.c | 13 ++++++++++++-
 daemon/worker.c      |  2 +-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/daemon/layer/query.c b/daemon/layer/query.c
index 927af0660..5dce26a95 100644
--- a/daemon/layer/query.c
+++ b/daemon/layer/query.c
@@ -44,6 +44,11 @@ static int input_query(knot_layer_t *ctx, knot_pkt_t *pkt)
 		return KNOT_NS_PROC_NOOP; /* Ignore. */
 	}
 
+	/* No authoritative service. */
+	if (!knot_wire_get_rd(pkt->wire)) {
+		return KNOT_NS_PROC_FAIL;
+	}
+
 	return KNOT_NS_PROC_FULL;
 }
 
@@ -64,6 +69,12 @@ static int output_answer(knot_layer_t *ctx, knot_pkt_t *pkt)
 	return KNOT_NS_PROC_DONE;
 }
 
+static int output_error(knot_layer_t *ctx, knot_pkt_t *pkt)
+{
+	knot_wire_set_rcode(pkt->wire, KNOT_RCODE_SERVFAIL);
+	return KNOT_NS_PROC_DONE;
+}
+
 /*! \brief Module implementation. */
 static const knot_layer_api_t LAYER_QUERY_MODULE = {
 	&begin,
@@ -71,7 +82,7 @@ static const knot_layer_api_t LAYER_QUERY_MODULE = {
 	&reset,
 	&input_query,
 	&output_answer,
-	NULL
+	&output_error
 };
 
 const knot_layer_api_t *layer_query_module(void)
diff --git a/daemon/worker.c b/daemon/worker.c
index 4a3665534..4d0e351b8 100644
--- a/daemon/worker.c
+++ b/daemon/worker.c
@@ -81,7 +81,7 @@ int worker_exec(struct worker_ctx *worker, knot_pkt_t *answer, knot_pkt_t *query
 	int state = knot_layer_in(&proc, query);
 
 	/* Build an answer. */
-	if (state == KNOT_NS_PROC_FULL) {
+	if (state & (KNOT_NS_PROC_FULL|KNOT_NS_PROC_FAIL)) {
 		knot_pkt_init_response(answer, query);
 		state = knot_layer_out(&proc, answer);
 	}
-- 
GitLab