Commit 2099ff7d authored by Daniel Salzman's avatar Daniel Salzman

nameserver: merge duplicate answer functions

parent 7e67c73f
......@@ -21,7 +21,6 @@
#include "knot/conf/tools.h"
#include "knot/common/log.h"
#include "knot/nameserver/query_module.h"
#include "knot/nameserver/internet.h"
#include "libknot/libknot.h"
#include "libknot/yparser/ypformat.h"
#include "libknot/yparser/yptrafo.h"
......@@ -375,10 +374,12 @@ void conf_activate_modules(
val = conf_default_get(conf, C_GLOBAL_MODULE);
}
// Check if a module is configured at all.
if (val.code == KNOT_ENOENT) {
switch (val.code) {
case KNOT_EOK:
break;
case KNOT_ENOENT: // Check if a module is configured at all.
return;
} else if (val.code != KNOT_EOK) {
default:
ret = val.code;
goto activate_error;
}
......@@ -390,11 +391,6 @@ void conf_activate_modules(
goto activate_error;
}
if (zone_name != NULL) {
// Only supported zone class is now IN.
internet_query_plan(*query_plan);
}
// Initialize query modules list.
init_list(query_modules);
......
......@@ -737,12 +737,19 @@ int ns_put_rr(knot_pkt_t *pkt, const knot_rrset_t *rr,
return KNOT_STATE_FAIL; \
}
static int default_answer(knot_pkt_t *response, struct query_data *qdata)
static int answer_query(struct query_plan *plan, knot_pkt_t *response, struct query_data *qdata)
{
int state = BEGIN;
struct query_plan *global_plan = conf()->query_plan;
struct query_step *step = NULL;
/* Before query processing code. */
if (plan != NULL) {
WALK_LIST(step, plan->stage[QPLAN_BEGIN]) {
SOLVE_STEP(step->process, state, step->ctx);
}
}
/* Resolve ANSWER. */
knot_pkt_begin(response, KNOT_ANSWER);
if (global_plan != NULL) {
......@@ -752,6 +759,11 @@ static int default_answer(knot_pkt_t *response, struct query_data *qdata)
}
SOLVE_STEP(solve_answer, state, NULL);
SOLVE_STEP(solve_answer_dnssec, state, NULL);
if (plan != NULL) {
WALK_LIST(step, plan->stage[QPLAN_ANSWER]) {
SOLVE_STEP(step->process, state, step->ctx);
}
}
/* Resolve AUTHORITY. */
knot_pkt_begin(response, KNOT_AUTHORITY);
......@@ -762,6 +774,11 @@ static int default_answer(knot_pkt_t *response, struct query_data *qdata)
}
SOLVE_STEP(solve_authority, state, NULL);
SOLVE_STEP(solve_authority_dnssec, state, NULL);
if (plan != NULL) {
WALK_LIST(step, plan->stage[QPLAN_AUTHORITY]) {
SOLVE_STEP(step->process, state, step->ctx);
}
}
/* Resolve ADDITIONAL. */
knot_pkt_begin(response, KNOT_ADDITIONAL);
......@@ -772,40 +789,17 @@ static int default_answer(knot_pkt_t *response, struct query_data *qdata)
}
SOLVE_STEP(solve_additional, state, NULL);
SOLVE_STEP(solve_additional_dnssec, state, NULL);
/* Write resulting RCODE. */
knot_wire_set_rcode(response->wire, qdata->rcode);
return KNOT_STATE_DONE;
}
static int planned_answer(struct query_plan *plan, knot_pkt_t *response, struct query_data *qdata)
{
int state = BEGIN;
struct query_plan *global_plan = conf()->query_plan;
struct query_step *step = NULL;
/* Before query processing code. */
WALK_LIST(step, plan->stage[QPLAN_BEGIN]) {
SOLVE_STEP(step->process, state, step->ctx);
}
/* Begin processing. */
for (int section = KNOT_ANSWER; section <= KNOT_ADDITIONAL; ++section) {
knot_pkt_begin(response, section);
if (global_plan != NULL) {
WALK_LIST(step, global_plan->stage[QPLAN_STAGE + section]) {
SOLVE_STEP(step->process, state, step->ctx);
}
}
WALK_LIST(step, plan->stage[QPLAN_STAGE + section]) {
if (plan != NULL) {
WALK_LIST(step, plan->stage[QPLAN_ADDITIONAL]) {
SOLVE_STEP(step->process, state, step->ctx);
}
}
/* After query processing code. */
WALK_LIST(step, plan->stage[QPLAN_END]) {
SOLVE_STEP(step->process, state, step->ctx);
if (plan != NULL) {
WALK_LIST(step, plan->stage[QPLAN_END]) {
SOLVE_STEP(step->process, state, step->ctx);
}
}
/* Write resulting RCODE. */
......@@ -839,24 +833,7 @@ int internet_process_query(knot_pkt_t *response, struct query_data *qdata)
/* Get answer to QNAME. */
qdata->name = knot_pkt_qname(qdata->query);
/* If the zone doesn't have a query plan, go for fast default. */
if (qdata->zone->query_plan == NULL) {
return default_answer(response, qdata);
}
return planned_answer(qdata->zone->query_plan, response, qdata);
}
int internet_query_plan(struct query_plan *plan)
{
query_plan_step(plan, QPLAN_ANSWER, solve_answer, NULL);
query_plan_step(plan, QPLAN_ANSWER, solve_answer_dnssec, NULL);
query_plan_step(plan, QPLAN_AUTHORITY, solve_authority, NULL);
query_plan_step(plan, QPLAN_AUTHORITY, solve_authority_dnssec, NULL);
query_plan_step(plan, QPLAN_ADDITIONAL, solve_additional, NULL);
query_plan_step(plan, QPLAN_ADDITIONAL, solve_additional_dnssec, NULL);
return KNOT_EOK;
return answer_query(qdata->zone->query_plan, response, qdata);
}
#include "knot/nameserver/log.h"
......
/* Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -53,13 +53,6 @@ enum {
*/
int internet_process_query(knot_pkt_t *resp, struct query_data *qdata);
/*!
* \brief Initialize query plan for IN class zone.
* \param plan
* \return
*/
int internet_query_plan(struct query_plan *plan);
/*!
* \brief Process answer in an IN class zone.
*
......
......@@ -494,8 +494,7 @@ static int process_query_out(knot_layer_t *ctx, knot_pkt_t *pkt)
* Preprocessing.
*/
int ret = prepare_answer(query, pkt, ctx);
if (ret != KNOT_EOK) {
if (prepare_answer(query, pkt, ctx) != KNOT_EOK) {
next_state = KNOT_STATE_FAIL;
goto finish;
}
......@@ -538,8 +537,7 @@ static int process_query_out(knot_layer_t *ctx, knot_pkt_t *pkt)
}
/* Put OPT RR to the additional section. */
ret = answer_edns_put(pkt, qdata);
if (ret != KNOT_EOK) {
if (answer_edns_put(pkt, qdata) != KNOT_EOK) {
next_state = KNOT_STATE_FAIL;
goto finish;
}
......
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