Commit 75607a95 authored by Marek Vavrusa's avatar Marek Vavrusa

Split packet processing API from name-server.h to libknot/processing

parent c7874a03
...@@ -113,10 +113,10 @@ src/knot/nameserver/ixfr.c ...@@ -113,10 +113,10 @@ src/knot/nameserver/ixfr.c
src/knot/nameserver/ixfr.h src/knot/nameserver/ixfr.h
src/knot/nameserver/name-server.c src/knot/nameserver/name-server.c
src/knot/nameserver/name-server.h src/knot/nameserver/name-server.h
src/knot/nameserver/ns_proc_query.c
src/knot/nameserver/ns_proc_query.h
src/knot/nameserver/nsec_proofs.c src/knot/nameserver/nsec_proofs.c
src/knot/nameserver/nsec_proofs.h src/knot/nameserver/nsec_proofs.h
src/knot/nameserver/process_query.c
src/knot/nameserver/process_query.h
src/knot/nameserver/update.c src/knot/nameserver/update.c
src/knot/nameserver/update.h src/knot/nameserver/update.h
src/knot/other/debug.h src/knot/other/debug.h
...@@ -205,6 +205,8 @@ src/libknot/packet/compr.h ...@@ -205,6 +205,8 @@ src/libknot/packet/compr.h
src/libknot/packet/pkt.c src/libknot/packet/pkt.c
src/libknot/packet/pkt.h src/libknot/packet/pkt.h
src/libknot/packet/wire.h src/libknot/packet/wire.h
src/libknot/processing/process.c
src/libknot/processing/process.h
src/libknot/rdata.h src/libknot/rdata.h
src/libknot/rrset-dump.c src/libknot/rrset-dump.c
src/libknot/rrset-dump.h src/libknot/rrset-dump.h
...@@ -284,8 +286,8 @@ tests/fdset.c ...@@ -284,8 +286,8 @@ tests/fdset.c
tests/hattrie.c tests/hattrie.c
tests/hhash.c tests/hhash.c
tests/journal.c tests/journal.c
tests/ns.c
tests/pkt.c tests/pkt.c
tests/process_query.c
tests/rrl.c tests/rrl.c
tests/rrset.c tests/rrset.c
tests/runtests.c tests/runtests.c
......
...@@ -113,6 +113,8 @@ libknot_la_SOURCES = \ ...@@ -113,6 +113,8 @@ libknot_la_SOURCES = \
libknot/packet/compr.c \ libknot/packet/compr.c \
libknot/packet/compr.h \ libknot/packet/compr.h \
libknot/packet/wire.h \ libknot/packet/wire.h \
libknot/processing/process.c \
libknot/processing/process.h \
libknot/dname.c \ libknot/dname.c \
libknot/consts.h \ libknot/consts.h \
libknot/edns.h \ libknot/edns.h \
...@@ -240,8 +242,8 @@ libknotd_la_SOURCES = \ ...@@ -240,8 +242,8 @@ libknotd_la_SOURCES = \
knot/nameserver/ixfr.h \ knot/nameserver/ixfr.h \
knot/nameserver/name-server.c \ knot/nameserver/name-server.c \
knot/nameserver/name-server.h \ knot/nameserver/name-server.h \
knot/nameserver/ns_proc_query.c \ knot/nameserver/process_query.c \
knot/nameserver/ns_proc_query.h \ knot/nameserver/process_query.h \
knot/nameserver/nsec_proofs.c \ knot/nameserver/nsec_proofs.c \
knot/nameserver/nsec_proofs.h \ knot/nameserver/nsec_proofs.h \
knot/nameserver/update.c \ knot/nameserver/update.c \
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "knot/nameserver/axfr.h" #include "knot/nameserver/axfr.h"
#include "knot/nameserver/internet.h" #include "knot/nameserver/internet.h"
#include "knot/nameserver/ns_proc_query.h" #include "knot/nameserver/process_query.h"
#include "libknot/util/debug.h" #include "libknot/util/debug.h"
#include "common/descriptor.h" #include "common/descriptor.h"
#include "common/lists.h" #include "common/lists.h"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include "knot/nameserver/internet.h" #include "knot/nameserver/internet.h"
#include "knot/nameserver/nsec_proofs.h" #include "knot/nameserver/nsec_proofs.h"
#include "knot/nameserver/ns_proc_query.h" #include "knot/nameserver/process_query.h"
#include "libknot/common.h" #include "libknot/common.h"
#include "libknot/rdata.h" #include "libknot/rdata.h"
#include "libknot/util/debug.h" #include "libknot/util/debug.h"
......
...@@ -67,10 +67,10 @@ int internet_answer(knot_pkt_t *resp, struct query_data *qdata); ...@@ -67,10 +67,10 @@ int internet_answer(knot_pkt_t *resp, struct query_data *qdata);
/*! \brief Require authentication. */ /*! \brief Require authentication. */
#define NS_NEED_AUTH(acl, qdata) \ #define NS_NEED_AUTH(acl, qdata) \
if (!ns_proc_query_acl_check((acl), (qdata))) { \ if (!process_query_acl_check((acl), (qdata))) { \
return NS_PROC_FAIL; \ return NS_PROC_FAIL; \
} else { \ } else { \
if (ns_proc_query_verify(qdata) != KNOT_EOK) { \ if (process_query_verify(qdata) != KNOT_EOK) { \
return NS_PROC_FAIL; \ return NS_PROC_FAIL; \
} \ } \
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
#include "knot/nameserver/ixfr.h" #include "knot/nameserver/ixfr.h"
#include "knot/nameserver/axfr.h" #include "knot/nameserver/axfr.h"
#include "knot/nameserver/internet.h" #include "knot/nameserver/internet.h"
#include "knot/nameserver/ns_proc_query.h" #include "knot/nameserver/process_query.h"
#include "libknot/util/debug.h" #include "libknot/util/debug.h"
#include "libknot/rdata.h" #include "libknot/rdata.h"
#include "knot/server/zones.h" #include "knot/server/zones.h"
......
...@@ -484,99 +484,3 @@ void knot_ns_destroy(knot_nameserver_t **nameserver) ...@@ -484,99 +484,3 @@ void knot_ns_destroy(knot_nameserver_t **nameserver)
free(*nameserver); free(*nameserver);
*nameserver = NULL; *nameserver = NULL;
} }
/* State -> string translation table. */
#ifdef KNOT_NS_DEBUG
#define NS_STATE_STR(x) _state_table[x]
static const char* _state_table[] = {
[NS_PROC_NOOP] = "NOOP",
[NS_PROC_MORE] = "MORE",
[NS_PROC_FULL] = "FULL",
[NS_PROC_DONE] = "DONE",
[NS_PROC_FAIL] = "FAIL"
};
#endif /* KNOT_NS_DEBUG */
int ns_proc_begin(ns_proc_context_t *ctx, void *module_param, const ns_proc_module_t *module)
{
/* Only in inoperable state. */
if (ctx->state != NS_PROC_NOOP) {
return NS_PROC_NOOP;
}
#ifdef KNOT_NS_DEBUG
/* Check module API. */
assert(module->begin);
assert(module->in);
assert(module->out);
assert(module->err);
assert(module->reset);
assert(module->finish);
#endif /* KNOT_NS_DEBUG */
ctx->module = module;
ctx->state = module->begin(ctx, module_param);
dbg_ns("%s -> %s\n", __func__, NS_STATE_STR(ctx->state));
return ctx->state;
}
int ns_proc_reset(ns_proc_context_t *ctx)
{
ctx->state = ctx->module->reset(ctx);
dbg_ns("%s -> %s\n", __func__, NS_STATE_STR(ctx->state));
return ctx->state;
}
int ns_proc_finish(ns_proc_context_t *ctx)
{
/* Only in operable state. */
if (ctx->state == NS_PROC_NOOP) {
return NS_PROC_NOOP;
}
ctx->state = ctx->module->finish(ctx);
dbg_ns("%s -> %s\n", __func__, NS_STATE_STR(ctx->state));
return ctx->state;
}
int ns_proc_in(const uint8_t *wire, uint16_t wire_len, ns_proc_context_t *ctx)
{
/* Only if expecting data. */
if (ctx->state != NS_PROC_MORE) {
return NS_PROC_NOOP;
}
knot_pkt_t *pkt = knot_pkt_new((uint8_t *)wire, wire_len, &ctx->mm);
knot_pkt_parse(pkt, 0);
ctx->state = ctx->module->in(pkt, ctx);
dbg_ns("%s -> %s\n", __func__, NS_STATE_STR(ctx->state));
return ctx->state;
}
int ns_proc_out(uint8_t *wire, uint16_t *wire_len, ns_proc_context_t *ctx)
{
knot_pkt_t *pkt = knot_pkt_new(wire, *wire_len, &ctx->mm);
switch(ctx->state) {
case NS_PROC_FULL: ctx->state = ctx->module->out(pkt, ctx); break;
case NS_PROC_FAIL: ctx->state = ctx->module->err(pkt, ctx); break;
default:
assert(0); /* Improper use. */
knot_pkt_free(&pkt);
return NS_PROC_NOOP;
}
/* Accept only finished result. */
if (ctx->state != NS_PROC_FAIL) {
*wire_len = pkt->size;
} else {
*wire_len = 0;
}
knot_pkt_free(&pkt);
dbg_ns("%s -> %s\n", __func__, NS_STATE_STR(ctx->state));
return ctx->state;
}
...@@ -296,116 +296,6 @@ int knot_ns_tsig_required(int packet_nr); ...@@ -296,116 +296,6 @@ int knot_ns_tsig_required(int packet_nr);
*/ */
void knot_ns_destroy(knot_nameserver_t **nameserver); void knot_ns_destroy(knot_nameserver_t **nameserver);
/* ^^^
* NG processing API below, everything upwards should be slowly moved to appropriate
* files or removed.
*/
/*! \brief Main packet processing states.
* Each state describes the current machine processing step
* and determines readiness for next action.
*/
enum ns_proc_state {
NS_PROC_NOOP = 0, /* N/A */
NS_PROC_MORE = 1 << 0, /* More input data. */
NS_PROC_FULL = 1 << 1, /* Has output data. */
NS_PROC_DONE = 1 << 2, /* Finished. */
NS_PROC_FAIL = 1 << 3 /* Error. */
};
/* Forward declarations. */
struct ns_proc_module;
/*! \brief Packte processing context. */
typedef struct ns_proc_context
{
int state;
mm_ctx_t mm;
uint16_t type;
knot_nameserver_t *ns;
void *data;
/* Module implementation. */
const struct ns_proc_module *module;
} ns_proc_context_t;
/*! \brief Packet processing module API. */
typedef struct ns_proc_module {
int (*begin)(ns_proc_context_t *ctx, void *module_param);
int (*reset)(ns_proc_context_t *ctx);
int (*finish)(ns_proc_context_t *ctx);
int (*in)(knot_pkt_t *pkt, ns_proc_context_t *ctx);
int (*out)(knot_pkt_t *pkt, ns_proc_context_t *ctx);
int (*err)(knot_pkt_t *pkt, ns_proc_context_t *ctx);
} ns_proc_module_t;
/*! \brief Packet signing context.
* \todo This should be later moved to TSIG files when refactoring. */
typedef struct ns_sign_context {
knot_tsig_key_t *tsig_key;
uint8_t *tsig_buf;
uint8_t *tsig_digest;
size_t tsig_buflen;
size_t tsig_digestlen;
uint8_t tsig_runlen;
uint64_t tsig_time_signed;
size_t pkt_count;
} ns_sign_context_t;
/*!
* \brief Initialize packet processing context.
*
* Allowed from states: NOOP
*
* \param ctx Context.
* \param module_param Parameters for given module.
* \param module Module API.
* \return (module specific state)
*/
int ns_proc_begin(ns_proc_context_t *ctx, void *module_param, const ns_proc_module_t *module);
/*!
* \brief Reset current packet processing context.
* \param ctx Context.
* \return (module specific state)
*/
int ns_proc_reset(ns_proc_context_t *ctx);
/*!
* \brief Finish and close packet processing context.
*
* Allowed from states: MORE, FULL, DONE, FAIL
*
* \param ctx Context.
* \return (module specific state)
*/
int ns_proc_finish(ns_proc_context_t *ctx);
/*!
* \brief Input more data into packet processing.
*
* Allowed from states: MORE
*
* \param wire Source data.
* \param wire_len Source data length.
* \param ctx Context.
* \return (module specific state)
*/
int ns_proc_in(const uint8_t *wire, uint16_t wire_len, ns_proc_context_t *ctx);
/*!
* \brief Write out output from packet processing.
*
* Allowed from states: FULL, FAIL
*
* \param wire Destination.
* \param wire_len Destination length.
* \param ctx Context.
* \return (module specific state)
*/
int ns_proc_out(uint8_t *wire, uint16_t *wire_len, ns_proc_context_t *ctx);
#endif /* _KNOTNAME_SERVER_H_ */ #endif /* _KNOTNAME_SERVER_H_ */
/*! @} */ /*! @} */
#include <config.h> #include <config.h>
#include "knot/nameserver/nsec_proofs.h" #include "knot/nameserver/nsec_proofs.h"
#include "knot/nameserver/ns_proc_query.h" #include "knot/nameserver/process_query.h"
#include "libknot/common.h" #include "libknot/common.h"
#include "libknot/rdata.h" #include "libknot/rdata.h"
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#include <stdio.h> #include <stdio.h>
#include <urcu.h> #include <urcu.h>
#include "knot/nameserver/ns_proc_query.h" #include "knot/nameserver/process_query.h"
#include "libknot/consts.h" #include "libknot/consts.h"
#include "libknot/util/debug.h" #include "libknot/util/debug.h"
#include "libknot/common.h" #include "libknot/common.h"
...@@ -23,38 +23,38 @@ ...@@ -23,38 +23,38 @@
/* Forward decls. */ /* Forward decls. */
static const knot_zone_t *answer_zone_find(const knot_pkt_t *pkt, knot_zonedb_t *zonedb); static const knot_zone_t *answer_zone_find(const knot_pkt_t *pkt, knot_zonedb_t *zonedb);
static int prepare_answer(const knot_pkt_t *query, knot_pkt_t *resp, ns_proc_context_t *ctx); static int prepare_answer(const knot_pkt_t *query, knot_pkt_t *resp, knot_process_t *ctx);
static int query_internet(knot_pkt_t *pkt, ns_proc_context_t *ctx); static int query_internet(knot_pkt_t *pkt, knot_process_t *ctx);
static int query_chaos(knot_pkt_t *pkt, ns_proc_context_t *ctx); static int query_chaos(knot_pkt_t *pkt, knot_process_t *ctx);
static int ratelimit_apply(int state, knot_pkt_t *pkt, ns_proc_context_t *ctx); static int ratelimit_apply(int state, knot_pkt_t *pkt, knot_process_t *ctx);
/*! \brief Module implementation. */ /*! \brief Module implementation. */
const ns_proc_module_t _ns_proc_query = { const knot_process_module_t _process_query = {
&ns_proc_query_begin, &process_query_begin,
&ns_proc_query_reset, &process_query_reset,
&ns_proc_query_finish, &process_query_finish,
&ns_proc_query_in, &process_query_in,
&ns_proc_query_out, &process_query_out,
&ns_proc_query_err &process_query_err
}; };
/*! \brief Accessor to query-specific data. */ /*! \brief Accessor to query-specific data. */
#define QUERY_DATA(ctx) ((struct query_data *)(ctx)->data) #define QUERY_DATA(ctx) ((struct query_data *)(ctx)->data)
/*! \brief Reinitialize query data structure. */ /*! \brief Reinitialize query data structure. */
static void query_data_init(ns_proc_context_t *ctx, void *module_param) static void query_data_init(knot_process_t *ctx, void *module_param)
{ {
/* Initialize persistent data. */ /* Initialize persistent data. */
struct query_data *data = QUERY_DATA(ctx); struct query_data *data = QUERY_DATA(ctx);
memset(data, 0, sizeof(struct query_data)); memset(data, 0, sizeof(struct query_data));
data->mm = &ctx->mm; data->mm = &ctx->mm;
data->param = (struct ns_proc_query_param*)module_param; data->param = (struct process_query_param*)module_param;
/* Initialize list. */ /* Initialize list. */
init_list(&data->wildcards); init_list(&data->wildcards);
} }
int ns_proc_query_begin(ns_proc_context_t *ctx, void *module_param) int process_query_begin(knot_process_t *ctx, void *module_param)
{ {
/* Initialize context. */ /* Initialize context. */
assert(ctx); assert(ctx);
...@@ -68,13 +68,13 @@ int ns_proc_query_begin(ns_proc_context_t *ctx, void *module_param) ...@@ -68,13 +68,13 @@ int ns_proc_query_begin(ns_proc_context_t *ctx, void *module_param)
return NS_PROC_MORE; return NS_PROC_MORE;
} }
int ns_proc_query_reset(ns_proc_context_t *ctx) int process_query_reset(knot_process_t *ctx)
{ {
assert(ctx); assert(ctx);
struct query_data *qdata = QUERY_DATA(ctx); struct query_data *qdata = QUERY_DATA(ctx);
/* Remember persistent parameters. */ /* Remember persistent parameters. */
struct ns_proc_query_param *module_param = qdata->param; struct process_query_param *module_param = qdata->param;
/* Free allocated data. */ /* Free allocated data. */
knot_pkt_free(&qdata->query); knot_pkt_free(&qdata->query);
...@@ -89,15 +89,15 @@ int ns_proc_query_reset(ns_proc_context_t *ctx) ...@@ -89,15 +89,15 @@ int ns_proc_query_reset(ns_proc_context_t *ctx)
/* Await packet. */ /* Await packet. */
return NS_PROC_MORE; return NS_PROC_MORE;
} }
int ns_proc_query_finish(ns_proc_context_t *ctx) int process_query_finish(knot_process_t *ctx)
{ {
ns_proc_query_reset(ctx); process_query_reset(ctx);
ctx->mm.free(ctx->data); ctx->mm.free(ctx->data);
ctx->data = NULL; ctx->data = NULL;
return NS_PROC_NOOP; return NS_PROC_NOOP;
} }
int ns_proc_query_in(knot_pkt_t *pkt, ns_proc_context_t *ctx) int process_query_in(knot_pkt_t *pkt, knot_process_t *ctx)
{ {
assert(pkt && ctx); assert(pkt && ctx);
struct query_data *qdata = QUERY_DATA(ctx); struct query_data *qdata = QUERY_DATA(ctx);
...@@ -122,7 +122,7 @@ int ns_proc_query_in(knot_pkt_t *pkt, ns_proc_context_t *ctx) ...@@ -122,7 +122,7 @@ int ns_proc_query_in(knot_pkt_t *pkt, ns_proc_context_t *ctx)
return NS_PROC_FULL; return NS_PROC_FULL;
} }
int ns_proc_query_out(knot_pkt_t *pkt, ns_proc_context_t *ctx) int process_query_out(knot_pkt_t *pkt, knot_process_t *ctx)
{ {
assert(pkt && ctx); assert(pkt && ctx);
struct query_data *qdata = QUERY_DATA(ctx); struct query_data *qdata = QUERY_DATA(ctx);
...@@ -178,7 +178,7 @@ int ns_proc_query_out(knot_pkt_t *pkt, ns_proc_context_t *ctx) ...@@ -178,7 +178,7 @@ int ns_proc_query_out(knot_pkt_t *pkt, ns_proc_context_t *ctx)
/* Transaction security (if applicable). */ /* Transaction security (if applicable). */
if (next_state == NS_PROC_DONE || next_state == NS_PROC_FULL) { if (next_state == NS_PROC_DONE || next_state == NS_PROC_FULL) {
if (ns_proc_query_sign_response(pkt, qdata) != KNOT_EOK) { if (process_query_sign_response(pkt, qdata) != KNOT_EOK) {
next_state = NS_PROC_FAIL; next_state = NS_PROC_FAIL;
} }
} }
...@@ -192,7 +192,7 @@ finish: ...@@ -192,7 +192,7 @@ finish:
return next_state; return next_state;
} }
int ns_proc_query_err(knot_pkt_t *pkt, ns_proc_context_t *ctx) int process_query_err(knot_pkt_t *pkt, knot_process_t *ctx)
{ {
assert(pkt && ctx); assert(pkt && ctx);
struct query_data *qdata = QUERY_DATA(ctx); struct query_data *qdata = QUERY_DATA(ctx);
...@@ -214,14 +214,14 @@ int ns_proc_query_err(knot_pkt_t *pkt, ns_proc_context_t *ctx) ...@@ -214,14 +214,14 @@ int ns_proc_query_err(knot_pkt_t *pkt, ns_proc_context_t *ctx)
knot_wire_set_rcode(pkt->wire, qdata->rcode); knot_wire_set_rcode(pkt->wire, qdata->rcode);
/* Transaction security (if applicable). */ /* Transaction security (if applicable). */
if (ns_proc_query_sign_response(pkt, qdata) != KNOT_EOK) { if (process_query_sign_response(pkt, qdata) != KNOT_EOK) {
return NS_PROC_FAIL; return NS_PROC_FAIL;
} }
return NS_PROC_DONE; return NS_PROC_DONE;
} }
bool ns_proc_query_acl_check(acl_t *acl, struct query_data *qdata) bool process_query_acl_check(acl_t *acl, struct query_data *qdata)
{ {
knot_pkt_t *query = qdata->query; knot_pkt_t *query = qdata->query;
const sockaddr_t *query_source = &qdata->param->query_source; const sockaddr_t *query_source = &qdata->param->query_source;
...@@ -253,10 +253,10 @@ bool ns_proc_query_acl_check(acl_t *acl, struct query_data *qdata) ...@@ -253,10 +253,10 @@ bool ns_proc_query_acl_check(acl_t *acl, struct query_data *qdata)
return true; return true;
} }
int ns_proc_query_verify(struct query_data *qdata) int process_query_verify(struct query_data *qdata)
{ {
knot_pkt_t *query = qdata->query; knot_pkt_t *query = qdata->query;
ns_sign_context_t *ctx = &qdata->sign; knot_sign_context_t *ctx = &qdata->sign;
/* NOKEY => no verification. */ /* NOKEY => no verification. */
if (query->tsig_rr == NULL) { if (query->tsig_rr == NULL) {
...@@ -303,11 +303,11 @@ int ns_proc_query_verify(struct query_data *qdata) ...@@ -303,11 +303,11 @@ int ns_proc_query_verify(struct query_data *qdata)
return ret; return ret;
} }
int ns_proc_query_sign_response(knot_pkt_t *pkt, struct query_data *qdata) int process_query_sign_response(knot_pkt_t *pkt, struct query_data *qdata)
{ {
int ret = KNOT_EOK; int ret = KNOT_EOK;
knot_pkt_t *query = qdata->query; knot_pkt_t *query = qdata->query;
ns_sign_context_t *ctx = &qdata->sign; knot_sign_context_t *ctx = &qdata->sign;
/* KEY provided and verified TSIG or BADTIME allows signing. */ /* KEY provided and verified TSIG or BADTIME allows signing. */
if (ctx->tsig_key != NULL && knot_tsig_can_sign(qdata->rcode_tsig)) { if (ctx->tsig_key != NULL && knot_tsig_can_sign(qdata->rcode_tsig)) {
...@@ -358,9 +358,10 @@ fail: ...@@ -358,9 +358,10 @@ fail:
/*! /*!
* \brief Create a response for a given query in the INTERNET class. * \brief Create a response for a given query in the INTERNET class.
*/ */
static int query_internet(knot_pkt_t *pkt, ns_proc_context_t *ctx) static int query_internet(knot_pkt_t *pkt, knot_process_t *ctx)
{ {
struct query_data *data = QUERY_DATA(ctx); struct query_data *data = QUERY_DATA(ctx);
knot_nameserver_t *ns = data->param->ns;
int next_state = NS_PROC_FAIL; int next_state = NS_PROC_FAIL;
dbg_ns("%s(%p, %p, pkt_type=%u)\n", __func__, pkt, ctx, data->packet_type); dbg_ns("%s(%p, %p, pkt_type=%u)\n", __func__, pkt, ctx, data->packet_type);
...@@ -369,16 +370,16 @@ static int query_internet(knot_pkt_t *pkt, ns_proc_context_t *ctx) ...@@ -369,16 +370,16 @@ static int query_internet(knot_pkt_t *pkt, ns_proc_context_t *ctx)
next_state = internet_answer(pkt, data); next_state = internet_answer(pkt, data);
break; break;
case KNOT_QUERY_NOTIFY: case KNOT_QUERY_NOTIFY:
next_state = internet_notify(pkt, ctx->ns, data); next_state = internet_notify(pkt, ns, data);
break; break;
case KNOT_QUERY_AXFR: case KNOT_QUERY_AXFR:
next_state = axfr_answer(pkt, ctx->ns, data); next_state = axfr_answer(pkt, ns, data);
break; break;
case KNOT_QUERY_IXFR: case KNOT_QUERY_IXFR:
next_state = ixfr_answer(pkt, ctx->ns, data); next_state = ixfr_answer(pkt, ns, data);
break; break;
case KNOT_QUERY_UPDATE: case KNOT_QUERY_UPDATE:
next_state = update_answer(pkt, ctx->ns, data); next_state = update_answer(pkt, ns, data);
break; break;
default: default:
/* Nothing else is supported. */ /* Nothing else is supported. */
...@@ -393,11 +394,11 @@ static int query_internet(knot_pkt_t *pkt, ns_proc_context_t *ctx) ...@@ -393,11 +394,11 @@ static int query_internet(knot_pkt_t *pkt, ns_proc_context_t *ctx)
/*! /*!
* \brief Apply rate limit. * \brief Apply rate limit.
*/ */
static int ratelimit_apply(int state, knot_pkt_t *pkt, ns_proc_context_t *ctx) static int ratelimit_apply(int state, knot_pkt_t *pkt, knot_process_t *ctx)
{ {
/* Check if rate limiting applies. */ /* Check if rate limiting applies. */
struct query_data *qdata = QUERY_DATA(ctx); struct query_data *qdata = QUERY_DATA(ctx);
server_t *server = (server_t *)ctx->ns->data; server_t *server = (server_t *)qdata->param->ns->data;
if (server->rrl == NULL) { if (server->rrl == NULL) {
return state; return state;
} }
...@@ -417,7 +418,7 @@ static int ratelimit_apply(int state, knot_pkt_t *pkt, ns_proc_context_t *ctx) ...@@ -417,7 +418,7 @@ static int ratelimit_apply(int state, knot_pkt_t *pkt, ns_proc_context_t *ctx)
/* Now it is slip or drop. */ /* Now it is slip or drop. */
if (rrl_slip_roll(conf()->rrl_slip)) { if (rrl_slip_roll(conf()->rrl_slip)) {
/* Answer slips. */ /* Answer slips. */
if (ns_proc_query_err(pkt, ctx) != KNOT_EOK) { if (process_query_err(pkt, ctx) != KNOT_EOK) {
return NS_PROC_FAIL; return NS_PROC_FAIL;
} }
knot_wire_set_tc(pkt->wire); knot_wire_set_tc(pkt->wire);
...@@ -432,7 +433,7 @@ static int ratelimit_apply(int state, knot_pkt_t *pkt, ns_proc_context_t *ctx) ...@@ -432,7 +433,7 @@ static int ratelimit_apply(int state, knot_pkt_t *pkt, ns_proc_context_t *ctx)
/*! /*!
* \brief Create a response for a given query in the CHAOS class. * \brief Create a response for a given query in the CHAOS class.
*/ */
static int query_chaos(knot_pkt_t *pkt, ns_proc_context_t *ctx) static int query_chaos(knot_pkt_t *pkt, knot_process_t *ctx)
{ {
dbg_ns("%s(%p, %p)\n", __func__, pkt, ctx); dbg_ns("%s(%p, %p)\n", __func__, pkt, ctx);
struct query_data *data = QUERY_DATA(ctx); struct query_data *data = QUERY_DATA(ctx);
...@@ -443,7 +444,7 @@ static int query_chaos(knot_pkt_t *pkt, ns_proc_context_t *ctx) ...@@ -443,7 +444,7 @@ static int query_chaos(knot_pkt_t *pkt, ns_proc_context_t *ctx)
return NS_PROC_FAIL; return NS_PROC_FAIL;
} }
data->rcode = knot_chaos_answer(pkt, ctx->ns); data->rcode = knot_chaos_answer(pkt, data->param->ns);
if (data->rcode != KNOT_RCODE_NOERROR) { if (data->rcode != KNOT_RCODE_NOERROR) {
dbg_ns("%s: failed with RCODE=%d\n", __func__, data->rcode); dbg_ns("%s: failed with RCODE=%d\n", __func__, data->rcode);
return NS_PROC_FAIL; return NS_PROC_FAIL;
...@@ -487,7 +488,7 @@ static const knot_zone_t *answer_zone_find(const knot_pkt_t *pkt, knot_zonedb_t ...@@ -487,7 +488,7 @@ static const knot_zone_t *answer_zone_find(const knot_pkt_t *pkt, knot_zonedb_t
} }
/*! \brief Initialize response, sizes and find zone from which we're going to answer. */ /*! \brief Initialize response, sizes and find zone from which we're going to answer. */
static int prepare_answer(const knot_pkt_t *query, knot_pkt_t *resp, ns_proc_context_t *ctx) static int prepare_answer(const knot_pkt_t *query, knot_pkt_t *resp, knot_process_t *ctx)
{ {
int ret = knot_pkt_init_response(resp, query); int ret = knot_pkt_init_response(resp, query);
if (ret != KNOT_EOK) { if (ret != KNOT_EOK) {
...@@ -499,6 +500,7 @@ static int prepare_answer(const knot_pkt_t *query, knot_pkt_t *resp, ns_proc_con ...@@ -499,6 +500,7 @@ static int prepare_answer(const knot_pkt_t *query, knot_pkt_t *resp, ns_proc_con