Commit c3c931a9 authored by Marek Vavruša's avatar Marek Vavruša

nameserver: answer processing stub

parent 97b8287d
......@@ -119,6 +119,8 @@ src/knot/nameserver/notify.c
src/knot/nameserver/notify.h
src/knot/nameserver/nsec_proofs.c
src/knot/nameserver/nsec_proofs.h
src/knot/nameserver/process_answer.c
src/knot/nameserver/process_answer.h
src/knot/nameserver/process_query.c
src/knot/nameserver/process_query.h
src/knot/nameserver/query_module.c
......
......@@ -236,6 +236,8 @@ libknotd_la_SOURCES = \
knot/nameserver/nsec_proofs.h \
knot/nameserver/process_query.c \
knot/nameserver/process_query.h \
knot/nameserver/process_answer.c \
knot/nameserver/process_answer.h \
knot/nameserver/query_module.c \
knot/nameserver/query_module.h \
knot/nameserver/update.c \
......
/* Copyright (C) 2014 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "knot/nameserver/process_answer.h"
static int noop(knot_pkt_t *pkt, knot_process_t *ctx)
{
return NS_PROC_NOOP;
}
/*! \brief Module implementation. */
const knot_process_module_t _process_answer = {
&process_answer_begin,
&process_answer_reset,
&process_answer_finish,
&process_answer,
&noop,
&process_answer_cleanup
};
/*! \brief Accessor to query-specific data. */
#define ANSWER_DATA(ctx) ((struct answer_data *)(ctx)->data)
static void answer_data_init(knot_process_t *ctx, void *module_param)
{
/* Initialize persistent data. */
struct answer_data *data = ANSWER_DATA(ctx);
memset(data, 0, sizeof(struct answer_data));
data->mm = &ctx->mm;
data->param = module_param;
}
int process_answer_begin(knot_process_t *ctx, void *module_param)
{
/* Initialize context. */
assert(ctx);
ctx->type = NS_PROC_ANSWER_ID;
ctx->data = mm_alloc(&ctx->mm, sizeof(struct answer_data));
/* Initialize persistent data. */
answer_data_init(ctx, module_param);
/* Await packet. */
return NS_PROC_MORE;
}
int process_answer_reset(knot_process_t *ctx)
{
assert(ctx);
/* Initialize persistent data. */
answer_data_init(ctx, ANSWER_DATA(ctx)->param);
/* Await packet. */
return NS_PROC_MORE;
}
int process_answer_finish(knot_process_t *ctx)
{
#warning TODO: finalize multi-packet
process_answer_reset(ctx);
mm_free(&ctx->mm, ctx->data);
ctx->data = NULL;
return NS_PROC_NOOP;
}
int process_answer(knot_pkt_t *pkt, knot_process_t *ctx)
{
assert(pkt && ctx);
struct answer_data *data = ANSWER_DATA(ctx);
/* Check if at least header is parsed. */
if (pkt->parsed < KNOT_WIRE_HEADER_SIZE || !knot_wire_get_qr(pkt->wire)) {
knot_pkt_free(&pkt);
return NS_PROC_NOOP; /* Ignore. */
}
/* Check parse state. */
int next_state = NS_PROC_DONE;
if (pkt->parsed < pkt->size) {
knot_pkt_clear(pkt);
next_state = NS_PROC_FAIL;
goto finish;
}
#warning TODO: process the actual packet
finish:
return next_state;
}
int process_answer_cleanup(knot_pkt_t *pkt, knot_process_t *ctx)
{
#warning TODO: cleanup multi-packet
return NS_PROC_DONE;
}
\ No newline at end of file
/* Copyright (C) 2014 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
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "knot/nameserver/process_query.h"
/* Query processing module implementation. */
extern const knot_process_module_t _process_answer;
#define NS_PROC_ANSWER (&_process_answer)
#define NS_PROC_ANSWER_ID 2
/* Module load parameters. */
struct process_answer_param {
zone_t *zone;
int socket;
const knot_pkt_t *query;
struct sockaddr_storage *remote;
};
struct answer_data
{
/* Extensions. */
void *ext;
void (*ext_cleanup)(struct answer_data*); /*!< Extensions cleanup callback. */
knot_sign_context_t sign; /*!< Signing context. */
/* Everything below should be kept on reset. */
struct process_answer_param *param; /*!< Module parameters. */
mm_ctx_t *mm; /*!< Memory context. */
};
/*!
* \brief Initialize answer processing context.
*
* \param ctx
* \param module_param
* \return MORE (awaits answer)
*/
int process_answer_begin(knot_process_t *ctx, void *module_param);
/*!
* \brief Reset answer processing context.
*
* \param ctx
* \return MORE (awaits next answer)
*/
int process_answer_reset(knot_process_t *ctx);
/*!
* \brief Finish and close current answer processing.
*
* \param ctx
* \return NOOP (context will be inoperable further on)
*/
int process_answer_finish(knot_process_t *ctx);
/*!
* \brief Process single answer packet.
*
* \param pkt
* \param ctx
* \retval NOOP (unsupported answer)
* \return MORE (awaits next answer)
* \retval DONE (processing finished)
* \retval FAIL (processing failed)
*/
int process_answer(knot_pkt_t *pkt, knot_process_t *ctx);
/*!
* \brief Cleanup after failed answer processing.
*
* \param pkt
* \param ctx
* \retval DONE (finished)
*/
int process_answer_cleanup(knot_pkt_t *pkt, knot_process_t *ctx);
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