Commit 32c66710 authored by Marek Vavruša's avatar Marek Vavruša

lib/resolve: fix minimized QNAME if zone cut changes

parent 3975c354
......@@ -350,15 +350,8 @@ static int begin(knot_layer_t *ctx, void *module_param)
return reset(ctx);
}
static int prepare_query(knot_layer_t *ctx, knot_pkt_t *pkt)
int kr_make_query(struct kr_query *query, knot_pkt_t *pkt)
{
assert(pkt && ctx);
struct kr_request *req = ctx->data;
struct kr_query *query = kr_rplan_current(&req->rplan);
if (!query || ctx->state & (KNOT_STATE_DONE|KNOT_STATE_FAIL)) {
return ctx->state;
}
/* Minimize QNAME (if possible). */
uint16_t qtype = query->stype;
const knot_dname_t *qname = minimized_qname(query, &qtype);
......@@ -367,12 +360,30 @@ static int prepare_query(knot_layer_t *ctx, knot_pkt_t *pkt)
knot_pkt_clear(pkt);
int ret = knot_pkt_put_question(pkt, qname, query->sclass, qtype);
if (ret != KNOT_EOK) {
return KNOT_STATE_FAIL;
return ret;
}
/* Query built, expect answer. */
query->id = isaac_next_uint(&ISAAC, UINT16_MAX);
knot_wire_set_id(pkt->wire, query->id);
return kr_ok();
}
static int prepare_query(knot_layer_t *ctx, knot_pkt_t *pkt)
{
assert(pkt && ctx);
struct kr_request *req = ctx->data;
struct kr_query *query = kr_rplan_current(&req->rplan);
if (!query || ctx->state & (KNOT_STATE_DONE|KNOT_STATE_FAIL)) {
return ctx->state;
}
/* Make query */
int ret = kr_make_query(query, pkt);
if (ret != 0) {
return KNOT_STATE_FAIL;
}
return KNOT_STATE_CONSUME;
}
......
......@@ -31,5 +31,8 @@ enum {
/** Classify response by type. */
int kr_response_classify(knot_pkt_t *pkt);
/** Make next iterative query. */
int kr_make_query(struct kr_query *query, knot_pkt_t *pkt);
/* Processing module implementation. */
const knot_layer_api_t *iterate_layer(struct kr_module *module);
......@@ -22,9 +22,10 @@
#include <libknot/descriptor.h>
#include <libknot/internal/net.h>
#include "lib/resolve.h"
#include "lib/layer.h"
#include "lib/rplan.h"
#include "lib/resolve.h"
#include "lib/layer/iterate.h"
#define DEBUG_MSG(fmt...) QRDEBUG(kr_rplan_current(rplan), "resl", fmt)
......@@ -439,6 +440,12 @@ int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *t
if (qry->flags & QUERY_AWAIT_CUT) {
ns_fetch_cut(qry, request);
qry->flags &= ~QUERY_AWAIT_CUT;
/* Update minimized QNAME if zone cut changed */
if (qry->zone_cut.name[0] != '\0' && !(qry->flags & QUERY_NO_MINIMIZE)) {
if (kr_make_query(qry, packet) != 0) {
return KNOT_STATE_FAIL;
}
}
}
ns_election:
......
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