Commit 3418c536 authored by Marek Vavruša's avatar Marek Vavruša

lib: pop query after the iteration step

parent c37b3015
......@@ -228,8 +228,6 @@ static int process_authority(knot_pkt_t *pkt, struct kr_layer_param *param)
static int process_additional(knot_pkt_t *pkt, struct kr_layer_param *param)
{
struct kr_query *query = kr_rplan_current(param->rplan);
/* Attempt to find glue for current nameserver. */
const knot_pktsection_t *ar = knot_pkt_section(pkt, KNOT_ADDITIONAL);
for (unsigned i = 0; i < ar->count; ++i) {
......@@ -243,6 +241,27 @@ static int process_additional(knot_pkt_t *pkt, struct kr_layer_param *param)
return KNOT_NS_PROC_DONE;
}
static void finalize_answer(knot_pkt_t *pkt, struct kr_layer_param *param)
{
/* Finalize header */
knot_pkt_t *answer = param->answer;
knot_wire_set_rcode(answer->wire, knot_wire_get_rcode(pkt->wire));
/* Fill in SOA if negative response */
knot_pkt_begin(answer, KNOT_AUTHORITY);
int pkt_class = response_classify(pkt);
if (pkt_class & (PKT_NXDOMAIN|PKT_NODATA)) {
const knot_pktsection_t *ns = knot_pkt_section(pkt, KNOT_AUTHORITY);
for (unsigned i = 0; i < ns->count; ++i) {
const knot_rrset_t *rr = knot_pkt_rr(ns, i);
if (rr->type == KNOT_RRTYPE_SOA) {
rr_update_answer(rr, 0, param);
break;
}
}
}
}
static int process_answer(knot_pkt_t *pkt, struct kr_layer_param *param)
{
struct kr_query *query = kr_rplan_current(param->rplan);
......@@ -274,38 +293,17 @@ static int process_answer(knot_pkt_t *pkt, struct kr_layer_param *param)
/* Follow canonical name as next SNAME. */
if (cname != query->sname) {
(void) kr_rplan_push(param->rplan, query->parent, cname, query->sclass, query->stype);
} else {
if (query->parent == NULL) {
finalize_answer(pkt, param);
}
}
/* Either way it resolves current query. */
kr_rplan_pop(param->rplan, query);
query->resolved = true;
return KNOT_NS_PROC_DONE;
}
static void finalize_answer(knot_pkt_t *pkt, struct kr_layer_param *param)
{
knot_pkt_t *answer = param->answer;
/* Finalize header */
knot_wire_set_rcode(answer->wire, knot_wire_get_rcode(pkt->wire));
/* Finalize authority */
knot_pkt_begin(answer, KNOT_AUTHORITY);
/* Fill in SOA if negative response */
int pkt_class = response_classify(pkt);
if (pkt_class & (PKT_NXDOMAIN|PKT_NODATA)) {
const knot_pktsection_t *ns = knot_pkt_section(pkt, KNOT_AUTHORITY);
for (unsigned i = 0; i < ns->count; ++i) {
const knot_rrset_t *rr = knot_pkt_rr(ns, i);
if (rr->type == KNOT_RRTYPE_SOA) {
rr_update_answer(rr, 0, param);
break;
}
}
}
}
/*! \brief Error handling, RFC1034 5.3.3, 4d. */
static int resolve_error(knot_pkt_t *pkt, struct kr_layer_param *param)
{
......@@ -380,7 +378,7 @@ static int resolve(knot_layer_t *ctx, knot_pkt_t *pkt)
assert(pkt && ctx);
struct kr_layer_param *param = ctx->data;
struct kr_query *query = kr_rplan_current(param->rplan);
if (query == NULL) {
if (query == NULL || query->resolved) {
return ctx->state;
}
......@@ -431,11 +429,6 @@ static int resolve(knot_layer_t *ctx, knot_pkt_t *pkt)
break;
}
/* If resolved, finalize answer. */
if (kr_rplan_empty(param->rplan)) {
finalize_answer(pkt, param);
}
return state;
}
......
......@@ -127,6 +127,11 @@ static int iterate(struct knot_requestor *requestor, struct kr_layer_param *para
cur->flags &= ~QUERY_TCP;
}
/* Pop query if resolved. */
if (cur->resolved) {
kr_rplan_pop(rplan, cur);
}
return ret;
}
......
......@@ -27,7 +27,7 @@
#include "lib/zonecut.h"
/* Query flags */
enum {
enum kr_query_flag {
QUERY_NO_MINIMIZE = 1 << 0, /*!< Don't minimize QNAME. */
QUERY_TCP = 1 << 1 /*!< Use TCP for this query. */
};
......@@ -41,6 +41,7 @@ struct kr_query {
struct kr_zonecut zone_cut;
struct timeval timestamp;
knot_dname_t *sname;
bool resolved;
uint16_t stype;
uint16_t sclass;
uint16_t id;
......
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