Commit 452d65ee authored by Lubos Slovak's avatar Lubos Slovak

public-libs: Visibility and prefixes in processing

parent 28e23cfb
......@@ -162,7 +162,8 @@ static void ASORT_PREFIX(sort)(ASORT_ARRAY_ARG uns array_size ASORT_EXTRA_ARGS)
*/
/* Find minimal element which will serve as a barrier */
r = MIN(array_size, ASORT_THRESHOLD);
/*! \todo This requires libknot/common.h!!! Define also in common/ */
r = KNOT_MIN(array_size, ASORT_THRESHOLD);
m = 0;
for (l=1; l<r; l++)
if (ASORT_LT(ASORT_ELT(l),ASORT_ELT(m)))
......
......@@ -31,7 +31,7 @@
static int log_message(int state, const knot_pkt_t *pkt, struct query_data *qdata, void *ctx)
{
if (pkt == NULL || qdata == NULL || ctx == NULL) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
int ret = KNOT_ERROR;
......@@ -63,7 +63,7 @@ static int log_message(int state, const knot_pkt_t *pkt, struct query_data *qdat
protocol,
pkt->wire, pkt->size, &tv, &tv);
if (ret != KNOT_EOK) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
Dnstap__Dnstap dnstap = DNSTAP__DNSTAP__INIT;
dnstap.type = DNSTAP__DNSTAP__TYPE__MESSAGE;
......@@ -74,7 +74,7 @@ static int log_message(int state, const knot_pkt_t *pkt, struct query_data *qdat
size_t size = 0;
dt_pack(&dnstap, &frame, &size);
if (frame == NULL) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
/* Submit a request. */
......@@ -82,7 +82,7 @@ static int log_message(int state, const knot_pkt_t *pkt, struct query_data *qdat
fstrm_free_wrapper, NULL);
if (res != fstrm_res_success) {
free(frame);
state = NS_PROC_FAIL;
state = KNOT_NS_PROC_FAIL;
}
return state;
......@@ -92,7 +92,7 @@ static int log_message(int state, const knot_pkt_t *pkt, struct query_data *qdat
static int dnstap_message_log(int state, knot_pkt_t *pkt, struct query_data *qdata, void *ctx)
{
if (pkt == NULL || qdata == NULL || ctx == NULL) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
return log_message(state, pkt, qdata, ctx);
......
......@@ -111,7 +111,7 @@ static int axfr_query_check(struct query_data *qdata)
/* Check expiration. */
NS_NEED_ZONE_CONTENTS(qdata, KNOT_RCODE_SERVFAIL);
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
}
static int axfr_query_init(struct query_data *qdata)
......@@ -120,7 +120,7 @@ static int axfr_query_init(struct query_data *qdata)
/* Check AXFR query validity. */
int state = axfr_query_check(qdata);
if (state == NS_PROC_FAIL) {
if (state == KNOT_NS_PROC_FAIL) {
if (qdata->rcode == KNOT_RCODE_FORMERR) {
return KNOT_EMALF;
} else {
......@@ -212,7 +212,7 @@ int xfr_process_list(knot_pkt_t *pkt, xfr_put_cb process_item,
int axfr_query_process(knot_pkt_t *pkt, struct query_data *qdata)
{
if (pkt == NULL || qdata == NULL) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
int ret = KNOT_EOK;
......@@ -221,7 +221,7 @@ int axfr_query_process(knot_pkt_t *pkt, struct query_data *qdata)
/* If AXFR is disabled, respond with NOTIMPL. */
if (qdata->param->proc_flags & NS_QUERY_NO_AXFR) {
qdata->rcode = KNOT_RCODE_NOTIMPL;
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
/* Initialize on first call. */
......@@ -231,7 +231,7 @@ int axfr_query_process(knot_pkt_t *pkt, struct query_data *qdata)
if (ret != KNOT_EOK) {
AXFROUT_LOG(LOG_ERR, "failed to start (%s)",
knot_strerror(ret));
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
} else {
AXFROUT_LOG(LOG_INFO, "started, serial %u",
zone_contents_serial(qdata->zone->contents));
......@@ -246,18 +246,18 @@ int axfr_query_process(knot_pkt_t *pkt, struct query_data *qdata)
ret = xfr_process_list(pkt, &axfr_process_node_tree, qdata);
switch(ret) {
case KNOT_ESPACE: /* Couldn't write more, send packet and continue. */
return NS_PROC_FULL; /* Check for more. */
return KNOT_NS_PROC_FULL; /* Check for more. */
case KNOT_EOK: /* Last response. */
gettimeofday(&now, NULL);
AXFROUT_LOG(LOG_INFO,
"finished, %.02f seconds, %u messages, %u bytes",
time_diff(&axfr->proc.tstamp, &now) / 1000.0,
axfr->proc.npkts, axfr->proc.nbytes);
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
break;
default: /* Generic error. */
AXFROUT_LOG(LOG_ERR, "failed (%s)", knot_strerror(ret));
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
}
#undef AXFROUT_LOG
......@@ -359,22 +359,22 @@ static int axfr_answer_packet(knot_pkt_t *pkt, struct xfr_proc *proc)
const knot_rrset_t *rr = &answer->rr[i];
if (rr->type == KNOT_RRTYPE_SOA &&
node_rrtype_exists(zc.z->apex, KNOT_RRTYPE_SOA)) {
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
} else {
int ret = zcreator_step(&zc, rr);
if (ret != KNOT_EOK) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
}
}
return NS_PROC_MORE;
return KNOT_NS_PROC_MORE;
}
int axfr_answer_process(knot_pkt_t *pkt, struct answer_data *adata)
{
if (pkt == NULL || adata == NULL) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
/* Check RCODE. */
......@@ -384,7 +384,7 @@ int axfr_answer_process(knot_pkt_t *pkt, struct answer_data *adata)
if (lut != NULL) {
AXFRIN_LOG(LOG_ERR, "server responded with %s", lut->name);
}
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
/* Initialize processing with first packet. */
......@@ -392,14 +392,14 @@ int axfr_answer_process(knot_pkt_t *pkt, struct answer_data *adata)
NS_NEED_TSIG_SIGNED(&adata->param->tsig_ctx, 0);
if (!zone_transfer_needed(adata->param->zone, pkt)) {
AXFRIN_LOG(LOG_INFO, "zone is up-to-date");
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
}
AXFRIN_LOG(LOG_INFO, "starting");
int ret = axfr_answer_init(adata);
if (ret != KNOT_EOK) {
AXFRIN_LOG(LOG_ERR, "failed (%s)", knot_strerror(ret));
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
} else {
NS_NEED_TSIG_SIGNED(&adata->param->tsig_ctx, 100);
......@@ -407,12 +407,12 @@ int axfr_answer_process(knot_pkt_t *pkt, struct answer_data *adata)
/* Process answer packet. */
int ret = axfr_answer_packet(pkt, (struct xfr_proc *)adata->ext);
if (ret == NS_PROC_DONE) {
if (ret == KNOT_NS_PROC_DONE) {
NS_NEED_TSIG_SIGNED(&adata->param->tsig_ctx, 0);
/* This was the last packet, finalize zone and publish it. */
int fret = axfr_answer_finalize(adata);
if (fret != KNOT_EOK) {
ret = NS_PROC_FAIL;
ret = KNOT_NS_PROC_FAIL;
}
}
......
......@@ -54,14 +54,14 @@ int xfr_process_list(knot_pkt_t *pkt, xfr_put_cb put, struct query_data *qdata);
/*!
* \brief Process an AXFR query message.
*
* \return NS_PROC_* processing states
* \return KNOT_NS_PROC_* processing states
*/
int axfr_query_process(knot_pkt_t *pkt, struct query_data *qdata);
/*!
* \brief Processes an AXFR response message.
*
* \return NS_PROC_* processing states
* \return KNOT_NS_PROC_* processing states
*/
int axfr_answer_process(knot_pkt_t *pkt, struct answer_data *adata);
......
......@@ -19,8 +19,8 @@
#include "knot/server/udp-handler.h"
/* State-less packet capture, only incoming data is accepted. */
static int reset(knot_layer_t *ctx) { return NS_PROC_FULL; }
static int finish(knot_layer_t *ctx) { return NS_PROC_NOOP; }
static int reset(knot_layer_t *ctx) { return KNOT_NS_PROC_FULL; }
static int finish(knot_layer_t *ctx) { return KNOT_NS_PROC_NOOP; }
/* Set capture parameters (sink). */
static int begin(knot_layer_t *ctx, void *module_param)
......@@ -32,7 +32,7 @@ static int begin(knot_layer_t *ctx, void *module_param)
static int prepare_query(knot_layer_t *ctx, knot_pkt_t *pkt)
{
/* \note Don't touch the query, expect answer. */
return NS_PROC_MORE;
return KNOT_NS_PROC_MORE;
}
/* Forward packet. */
......@@ -44,7 +44,7 @@ static int capture(knot_layer_t *ctx, knot_pkt_t *pkt)
/* Copy packet contents and free. */
knot_pkt_copy(param->sink, pkt);
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
}
/*! \brief Module implementation. */
......
......@@ -752,9 +752,9 @@ int ns_put_rr(knot_pkt_t *pkt, const knot_rrset_t *rr,
#define SOLVE_STEP(solver, state, context) \
state = (solver)(state, response, qdata, context); \
if (state == TRUNC) { \
return NS_PROC_DONE; \
return KNOT_NS_PROC_DONE; \
} else if (state == ERROR) { \
return NS_PROC_FAIL; \
return KNOT_NS_PROC_FAIL; \
}
static int default_answer(knot_pkt_t *response, struct query_data *qdata)
......@@ -782,7 +782,7 @@ static int default_answer(knot_pkt_t *response, struct query_data *qdata)
/* Write resulting RCODE. */
knot_wire_set_rcode(response->wire, qdata->rcode);
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
}
static int planned_answer(struct query_plan *plan, knot_pkt_t *response, struct query_data *qdata)
......@@ -811,7 +811,7 @@ static int planned_answer(struct query_plan *plan, knot_pkt_t *response, struct
/* Write resulting RCODE. */
knot_wire_set_rcode(response->wire, qdata->rcode);
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
}
#undef SOLVE_STEP
......@@ -820,7 +820,7 @@ int internet_query(knot_pkt_t *response, struct query_data *qdata)
{
dbg_ns("%s(%p, %p)\n", __func__, response, qdata);
if (response == NULL || qdata == NULL) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
/* Check valid zone, transaction security (optional) and contents. */
......@@ -869,13 +869,13 @@ static int process_soa_answer(knot_pkt_t *pkt, struct answer_data *data)
/* Expect SOA in answer section. */
const knot_pktsection_t *answer = knot_pkt_section(pkt, KNOT_ANSWER);
if (answer->count < 1 || answer->rr[0].type != KNOT_RRTYPE_SOA) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
/* Our zone is expired, schedule transfer. */
if (zone_contents_is_empty(zone->contents)) {
zone_events_schedule(zone, ZONE_EVENT_XFER, ZONE_EVENT_NOW);
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
}
/* Check if master has newer zone and schedule transfer. */
......@@ -884,20 +884,20 @@ static int process_soa_answer(knot_pkt_t *pkt, struct answer_data *data)
uint32_t their_serial = knot_soa_serial(&answer->rr[0].rrs);
if (knot_serial_compare(our_serial, their_serial) >= 0) {
ANSWER_LOG(LOG_INFO, data, "refresh, outgoing", "zone is up-to-date");
return NS_PROC_DONE; /* Our zone is up to date. */
return KNOT_NS_PROC_DONE; /* Our zone is up to date. */
}
/* Our zone is outdated, schedule zone transfer. */
ANSWER_LOG(LOG_INFO, data, "refresh, outgoing", "master has newer serial %u -> %u",
our_serial, their_serial);
zone_events_schedule(zone, ZONE_EVENT_XFER, ZONE_EVENT_NOW);
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
}
int internet_process_answer(knot_pkt_t *pkt, struct answer_data *data)
{
if (pkt == NULL || data == NULL) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
NS_NEED_TSIG_SIGNED(&data->param->tsig_ctx, 0);
......@@ -907,6 +907,6 @@ int internet_process_answer(knot_pkt_t *pkt, struct answer_data *data)
case KNOT_RRTYPE_SOA:
return process_soa_answer(pkt, data);
default:
return NS_PROC_NOOP;
return KNOT_NS_PROC_NOOP;
}
}
......@@ -27,6 +27,7 @@
#pragma once
#include "libknot/packet/pkt.h"
#include "libknot/processing/layer.h"
#include "knot/zone/contents.h"
/* Query data (from query processing). */
......@@ -92,43 +93,43 @@ int ns_put_rr(knot_pkt_t *pkt, const knot_rrset_t *rr,
#define NS_NEED_QTYPE(qdata, qtype_want, error_rcode) \
if (knot_pkt_qtype((qdata)->query) != (qtype_want)) { \
qdata->rcode = (error_rcode); \
return NS_PROC_FAIL; \
return KNOT_NS_PROC_FAIL; \
}
/*! \brief Require given QUERY NAME or return error code. */
#define NS_NEED_QNAME(qdata, qname_want, error_rcode) \
if (!knot_dname_is_equal(knot_pkt_qname((qdata)->query), (qname_want))) { \
qdata->rcode = (error_rcode); \
return NS_PROC_FAIL; \
return KNOT_NS_PROC_FAIL; \
}
/*! \brief Require existing zone or return failure. */
#define NS_NEED_ZONE(qdata, error_rcode) \
if ((qdata)->zone == NULL) { \
qdata->rcode = (error_rcode); \
return NS_PROC_FAIL; \
return KNOT_NS_PROC_FAIL; \
}
/*! \brief Require existing zone contents or return failure. */
#define NS_NEED_ZONE_CONTENTS(qdata, error_rcode) \
if ((qdata)->zone->contents == NULL) { \
qdata->rcode = (error_rcode); \
return NS_PROC_FAIL; \
return KNOT_NS_PROC_FAIL; \
}
/*! \brief Require authentication. */
#define NS_NEED_AUTH(acl, qdata) \
if (!process_query_acl_check((acl), (qdata))) { \
return NS_PROC_FAIL; \
return KNOT_NS_PROC_FAIL; \
} else { \
if (process_query_verify(qdata) != KNOT_EOK) { \
return NS_PROC_FAIL; \
return KNOT_NS_PROC_FAIL; \
} \
}
#define NS_NEED_TSIG_SIGNED(tsig_ctx, max_unsigned) \
if (tsig_unsigned_count(tsig_ctx) > max_unsigned) { \
return NS_PROC_FAIL; \
return KNOT_NS_PROC_FAIL; \
}
/*! @} */
......@@ -197,7 +197,7 @@ static int ixfr_query_check(struct query_data *qdata)
const knot_rrset_t *their_soa = &authority->rr[0];
if (authority->count < 1 || their_soa->type != KNOT_RRTYPE_SOA) {
qdata->rcode = KNOT_RCODE_FORMERR;
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
/* SOA needs to match QNAME. */
NS_NEED_QNAME(qdata, their_soa->owner, KNOT_RCODE_FORMERR);
......@@ -206,7 +206,7 @@ static int ixfr_query_check(struct query_data *qdata)
NS_NEED_AUTH(&qdata->zone->conf->acl.xfr_out, qdata);
NS_NEED_ZONE_CONTENTS(qdata, KNOT_RCODE_SERVFAIL); /* Check expiration. */
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
}
/*! \brief Cleans up ixfr processing context. */
......@@ -229,7 +229,7 @@ static int ixfr_answer_init(struct query_data *qdata)
{
/* Check IXFR query validity. */
int state = ixfr_query_check(qdata);
if (state == NS_PROC_FAIL) {
if (state == KNOT_NS_PROC_FAIL) {
if (qdata->rcode == KNOT_RCODE_FORMERR) {
return KNOT_EMALF;
} else {
......@@ -291,12 +291,12 @@ static int ixfr_answer_soa(knot_pkt_t *pkt, struct query_data *qdata)
{
dbg_ns("%s: answering IXFR/SOA\n", __func__);
if (pkt == NULL || qdata == NULL) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
/* Check query. */
int state = ixfr_query_check(qdata);
if (state == NS_PROC_FAIL) {
if (state == KNOT_NS_PROC_FAIL) {
return state; /* Malformed query. */
}
......@@ -307,15 +307,15 @@ static int ixfr_answer_soa(knot_pkt_t *pkt, struct query_data *qdata)
const zone_node_t *apex = qdata->zone->contents->apex;
knot_rrset_t soa_rr = node_rrset(apex, KNOT_RRTYPE_SOA);
if (knot_rrset_empty(&soa_rr)) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
int ret = knot_pkt_put(pkt, 0, &soa_rr, 0);
if (ret != KNOT_EOK) {
qdata->rcode = KNOT_RCODE_SERVFAIL;
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
}
/* ------------------------- IXFR-in processing ----------------------------- */
......@@ -569,7 +569,7 @@ static bool out_of_zone(const knot_rrset_t *rr, struct ixfr_proc *proc)
* \param pkt Packet containing the IXFR reply in wire format.
* \param adata Answer data, including processing context.
*
* \return NS_PROC_MORE, NS_PROC_DONE, NS_PROC_FAIL
* \return KNOT_NS_PROC_MORE, KNOT_NS_PROC_DONE, KNOT_NS_PROC_FAIL
*/
static int process_ixfrin_packet(knot_pkt_t *pkt, struct answer_data *adata)
{
......@@ -584,7 +584,7 @@ static int process_ixfrin_packet(knot_pkt_t *pkt, struct answer_data *adata)
for (uint16_t i = 0; i < answer->count; ++i) {
if (journal_limit_exceeded(ixfr)) {
IXFRIN_LOG(LOG_WARNING, "journal is full");
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
const knot_rrset_t *rr = &answer->rr[i];
......@@ -595,16 +595,16 @@ static int process_ixfrin_packet(knot_pkt_t *pkt, struct answer_data *adata)
int ret = ixfrin_step(rr, ixfr);
if (ret != KNOT_EOK) {
IXFRIN_LOG(LOG_WARNING, "failed (%s)", knot_strerror(ret));
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
if (ixfr->state == IXFR_DONE) {
// Transfer done, do not consume more RRs.
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
}
}
return NS_PROC_MORE;
return KNOT_NS_PROC_MORE;
}
/* --------------------------------- API ------------------------------------ */
......@@ -612,7 +612,7 @@ static int process_ixfrin_packet(knot_pkt_t *pkt, struct answer_data *adata)
int ixfr_query(knot_pkt_t *pkt, struct query_data *qdata)
{
if (pkt == NULL || qdata == NULL) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
int ret = KNOT_EOK;
......@@ -644,7 +644,7 @@ int ixfr_query(knot_pkt_t *pkt, struct query_data *qdata)
return axfr_query_process(pkt, qdata);
default: /* Server errors. */
IXFROUT_LOG(LOG_ERR, "failed to start (%s)", knot_strerror(ret));
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
}
......@@ -655,18 +655,18 @@ int ixfr_query(knot_pkt_t *pkt, struct query_data *qdata)
ret = xfr_process_list(pkt, &ixfr_process_changeset, qdata);
switch(ret) {
case KNOT_ESPACE: /* Couldn't write more, send packet and continue. */
return NS_PROC_FULL; /* Check for more. */
return KNOT_NS_PROC_FULL; /* Check for more. */
case KNOT_EOK: /* Last response. */
gettimeofday(&now, NULL);
IXFROUT_LOG(LOG_INFO,
"finished, %.02f seconds, %u messages, %u bytes",
time_diff(&ixfr->proc.tstamp, &now) / 1000.0,
ixfr->proc.npkts, ixfr->proc.nbytes);
ret = NS_PROC_DONE;
ret = KNOT_NS_PROC_DONE;
break;
default: /* Generic error. */
IXFROUT_LOG(LOG_ERR, "failed (%s)", knot_strerror(ret));
ret = NS_PROC_FAIL;
ret = KNOT_NS_PROC_FAIL;
break;
}
......@@ -676,11 +676,11 @@ int ixfr_query(knot_pkt_t *pkt, struct query_data *qdata)
int ixfr_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
{
if (pkt == NULL || adata == NULL) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
if (!ixfr_enough_data(pkt)) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
/* Check for AXFR-style IXFR. */
......@@ -696,7 +696,7 @@ int ixfr_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
if (lut != NULL) {
IXFRIN_LOG(LOG_WARNING, "server responded with %s", lut->name);
}
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
/* Initialize processing with first packet. */
......@@ -704,7 +704,7 @@ int ixfr_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
NS_NEED_TSIG_SIGNED(&adata->param->tsig_ctx, 0);
if (!zone_transfer_needed(adata->param->zone, pkt)) {
IXFRIN_LOG(LOG_INFO, "server has newer zone");
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
}
IXFRIN_LOG(LOG_INFO, "starting");
......@@ -712,18 +712,18 @@ int ixfr_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
int ret = ixfrin_answer_init(adata);
if (ret != KNOT_EOK) {
IXFRIN_LOG(LOG_WARNING, "failed (%s)", knot_strerror(ret));
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
} else {
NS_NEED_TSIG_SIGNED(&adata->param->tsig_ctx, 100);
}
int ret = process_ixfrin_packet(pkt, adata);
if (ret == NS_PROC_DONE) {
if (ret == KNOT_NS_PROC_DONE) {
NS_NEED_TSIG_SIGNED(&adata->param->tsig_ctx, 0);
int fret = ixfrin_finalize(adata);
if (fret != KNOT_EOK) {
ret = NS_PROC_FAIL;
ret = KNOT_NS_PROC_FAIL;
}
}
......
......@@ -56,18 +56,18 @@ static int notify_check_query(struct query_data *qdata)
NS_NEED_ZONE(qdata, KNOT_RCODE_NOTAUTH);
NS_NEED_AUTH(&zone->conf->acl.notify_in, qdata);
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
}
int notify_process_query(knot_pkt_t *pkt, struct query_data *qdata)
{
if (pkt == NULL || qdata == NULL) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
/* Validate notification query. */
int state = notify_check_query(qdata);
if (state == NS_PROC_FAIL) {
if (state == KNOT_NS_PROC_FAIL) {
switch (qdata->rcode) {
case KNOT_RCODE_NOTAUTH: /* Not authoritative or ACL check failed. */
NOTIFY_QLOG(LOG_NOTICE, "unauthorized request");
......@@ -100,7 +100,7 @@ int notify_process_query(knot_pkt_t *pkt, struct query_data *qdata)
zone_t *zone = (zone_t *)qdata->zone;
zone_events_schedule(zone, ZONE_EVENT_REFRESH, ZONE_EVENT_NOW);
return NS_PROC_DONE;
return KNOT_NS_PROC_DONE;
}
#undef NOTIFY_QLOG
......@@ -112,7 +112,7 @@ int notify_process_query(knot_pkt_t *pkt, struct query_data *qdata)
int notify_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
{
if (pkt == NULL || adata == NULL) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
/* Check RCODE. */
......@@ -122,12 +122,12 @@ int notify_process_answer(knot_pkt_t *pkt, struct answer_data *adata)
if (lut != NULL) {
NOTIFY_RLOG(LOG_WARNING, "server responded with %s", lut->name);
}
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
NS_NEED_TSIG_SIGNED(&adata->param->tsig_ctx, 0);
return NS_PROC_DONE; /* No processing. */
return KNOT_NS_PROC_DONE; /* No processing. */
}
#undef NOTIFY_RLOG
......@@ -46,14 +46,14 @@ static int process_answer_begin(knot_layer_t *ctx, void *module_param)
{
/* Initialize context. */
assert(ctx);
ctx->type = NS_PROC_ANSWER_ID;
ctx->type = KNOT_NS_PROC_ANSWER_ID;
ctx->data = knot_mm_alloc(ctx->mm, sizeof(struct answer_data));
/* Initialize persistent data. */
answer_data_init(ctx, module_param);
/* Issue the query. */
return NS_PROC_FULL;
return KNOT_NS_PROC_FULL;
}
static int process_answer_reset(knot_layer_t *ctx)
......@@ -73,7 +73,7 @@ static int process_answer_reset(knot_layer_t *ctx)
answer_data_init(ctx, module_param);
/* Issue the query. */
return NS_PROC_FULL;
return KNOT_NS_PROC_FULL;
}
static int process_answer_finish(knot_layer_t *ctx)
......@@ -82,7 +82,7 @@ static int process_answer_finish(knot_layer_t *ctx)
knot_mm_free(ctx->mm, ctx->data);
ctx->data = NULL;
return NS_PROC_NOOP;
return KNOT_NS_PROC_NOOP;
}
/* \note Private helper for process_answer repetitive checks. */
......@@ -98,27 +98,27 @@ static int process_answer(knot_layer_t *ctx, knot_pkt_t *pkt)
struct answer_data *data = ANSWER_DATA(ctx);
/* Check parse state. */
ANSWER_REQUIRES(pkt->parsed >= KNOT_WIRE_HEADER_SIZE, NS_PROC_FAIL);
ANSWER_REQUIRES(pkt->parsed == pkt->size, NS_PROC_FAIL);
ANSWER_REQUIRES(pkt->parsed >= KNOT_WIRE_HEADER_SIZE, KNOT_NS_PROC_FAIL);
ANSWER_REQUIRES(pkt->parsed == pkt->size, KNOT_NS_PROC_FAIL);
/* Accept only responses. */
ANSWER_REQUIRES(knot_wire_get_qr(pkt->wire), NS_PROC_NOOP);
ANSWER_REQUIRES(knot_wire_get_qr(pkt->wire), KNOT_NS_PROC_NOOP);
/* Check if we want answer paired to query. */
const knot_pkt_t *query = data->param->query;
if (!query) {
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
ANSWER_REQUIRES(is_answer_to_query(query, pkt), NS_PROC_NOOP);
ANSWER_REQUIRES(is_answer_to_query(query, pkt), KNOT_NS_PROC_NOOP);
/* Verify incoming packet. */
int ret = tsig_verify_packet(&data->param->tsig_ctx, pkt);
if (ret != KNOT_EOK) {
ANSWER_LOG(LOG_WARNING, data, "response", "denied (%s)",
knot_strerror(ret));
return NS_PROC_FAIL;
return KNOT_NS_PROC_FAIL;
}
/* Call appropriate processing handler. */
int next_state = NS_PROC_NOOP;
int next_state = KNOT_NS_PROC_NOOP;
int response_type = knot_pkt_type(query) | KNOT_RESPONSE;
/* @note We can't derive type from response, as it may not contain QUESTION at all. */
switch(response_type) {
......@@ -135,7 +135,7 @@ static int process_answer(knot_layer_t *ctx, knot_pkt_t *pkt)
next_state = notify_process_answer(pkt, data);
break;
default:
next_state = NS_PROC_NOOP;
next_state = KNOT_NS_PROC_NOOP;
break;
}
......@@ -146,7 +146,7 @@ static int process_answer(knot_layer_t *ctx, knot_pkt_t *pkt)
static int prepare_query(knot_layer_t *ctx, knot_pkt_t *pkt)
{
/* \note Don't touch the query, expect answer. */
return NS_PROC_MORE;
return KNOT_NS_PROC_MORE;
}
/*! \brief Module implementation. */
......
......@@ -31,8 +31,8 @@
/* Answer processing module implementation. */
const knot_layer_api_t *process_answer_get_module(void);
#define NS_PROC_ANSWER process_answer_get_module()
#define NS_PROC_ANSWER_ID 2
#define KNOT_NS_PROC_ANSWER process_answer_get_module()
#define KNOT_NS_PROC_ANSWER_ID 2
/*! \brief Answer processing logging base. */
#define ANSWER_LOG(severity, data, operation, msg...) \
......
......@@ -45,7 +45,7 @@ static int process_query_begin(knot_layer_t *ctx, void *module_param)
query_data_init(ctx, module_param);
/* Await packet. */
return NS_PROC_MORE;
return KNOT_NS_PROC_MORE;
}
static int process_query_reset(knot_layer_t *ctx)
......@@ -68,7 +68,7 @@ static int process_query_reset(knot_layer_t *ctx)
query_data_init(ctx, module_param);
/* Await packet. */
return NS_PROC_MORE;
return KNOT_NS_PROC_MORE;
}
static int process_query_finish(knot_layer_t *ctx)
......@@ -77,7 +77,7 @@ static int process_query_finish(knot_layer_t *ctx)
knot_mm_free(ctx->mm, ctx->data);
ctx->data = NULL;
return NS_PROC_NOOP;
return KNOT_NS_PROC_NOOP;
}
static int process_query_in(knot_layer_t *ctx, knot_pkt_t *pkt)
......@@ -87,12 +87,12 @@ static int process_query_in(knot_layer_t *ctx, knot_pkt_t *pkt)
/* Check if at least header is parsed. */
if (pkt->parsed < KNOT_WIRE_HEADER_SIZE) {
return NS_PROC_NOOP; /* Ignore. */
return KNOT_NS_PROC_NOOP; /* Ignore. */