Commit 8b3fe591 authored by Jan Včelák's avatar Jan Včelák 🚀

move capture layer to query module

parent 44bebf36
......@@ -315,8 +315,6 @@ libknotd_la_SOURCES = \
knot/modules/synth_record.h \
knot/nameserver/axfr.c \
knot/nameserver/axfr.h \
knot/nameserver/capture.c \
knot/nameserver/capture.h \
knot/nameserver/chaos.c \
knot/nameserver/chaos.h \
knot/nameserver/internet.c \
......@@ -336,6 +334,8 @@ libknotd_la_SOURCES = \
knot/nameserver/tsig_ctx.h \
knot/nameserver/update.c \
knot/nameserver/update.h \
knot/query/capture.c \
knot/query/capture.h \
knot/query/query.c \
knot/query/query.h \
knot/common/evsched.c \
......
......@@ -17,7 +17,7 @@
#include "libknot/processing/requestor.h"
#include "knot/common/log.h"
#include "knot/modules/dnsproxy.h"
#include "knot/nameserver/capture.h"
#include "knot/query/capture.h"
#include "knot/nameserver/process_query.h"
#include "contrib/mempattern.h"
#include "contrib/net.h"
......@@ -75,7 +75,7 @@ static int dnsproxy_fwd(int state, knot_pkt_t *pkt, struct query_data *qdata, vo
.sink = pkt
};
ret = knot_requestor_overlay(&re, LAYER_CAPTURE, &param);
ret = knot_requestor_overlay(&re, query_capture_api(), &param);
if (ret != KNOT_EOK) {
knot_requestor_clear(&re);
return state; /* Ignore, not enough memory. */
......
......@@ -18,8 +18,8 @@
#include "dnssec/random.h"
#include "knot/common/log.h"
#include "knot/query/capture.h"
#include "knot/nameserver/update.h"
#include "knot/nameserver/capture.h"
#include "knot/nameserver/internet.h"
#include "knot/nameserver/process_query.h"
#include "knot/nameserver/log.h"
......@@ -230,7 +230,7 @@ static int remote_forward(conf_t *conf, struct knot_request *request, conf_remot
.sink = request->resp
};
ret = knot_requestor_overlay(&re, LAYER_CAPTURE, &param);
ret = knot_requestor_overlay(&re, query_capture_api(), &param);
if (ret != KNOT_EOK) {
knot_requestor_clear(&re);
knot_pkt_free(&query);
......
/* 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
......@@ -16,48 +16,48 @@
#include <assert.h>
#include "knot/nameserver/capture.h"
#include "knot/query/capture.h"
/* State-less packet capture, only incoming data is accepted. */
static int reset(knot_layer_t *ctx) { return KNOT_STATE_PRODUCE; }
static int finish(knot_layer_t *ctx) { return KNOT_STATE_NOOP; }
static int reset(knot_layer_t *ctx)
{
return KNOT_STATE_PRODUCE;
}
static int finish(knot_layer_t *ctx)
{
return KNOT_STATE_NOOP;
}
/* Set capture parameters (sink). */
static int begin(knot_layer_t *ctx, void *module_param)
{
ctx->data = module_param;
ctx->data = module_param; /* struct capture_param */
return reset(ctx);
}
static int prepare_query(knot_layer_t *ctx, knot_pkt_t *pkt)
{
/* \note Don't touch the query, expect answer. */
return KNOT_STATE_CONSUME;
}
/* Forward packet. */
static int capture(knot_layer_t *ctx, knot_pkt_t *pkt)
{
assert(pkt && ctx);
assert(pkt && ctx && ctx->data);
struct capture_param *param = ctx->data;
/* Copy packet contents and free. */
knot_pkt_copy(param->sink, pkt);
return KNOT_STATE_DONE;
}
/*! \brief Module implementation. */
static const knot_layer_api_t CAPTURE_LAYER = {
&begin,
&reset,
&finish,
&capture,
&prepare_query,
NULL
};
const knot_layer_api_t *capture_get_module(void)
const knot_layer_api_t *query_capture_api(void)
{
return &CAPTURE_LAYER;
static const knot_layer_api_t API = {
.begin = begin,
.reset = reset,
.finish = finish,
.consume = capture,
.produce = prepare_query,
};
return &API;
}
/* 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
......@@ -13,24 +13,16 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file
*
* \brief Simple packet capture processor.
*
* \addtogroup answer_processing
* @{
*/
#pragma once
#include "libknot/processing/layer.h"
#include "libknot/packet/pkt.h"
/* Processing module implementation. */
const knot_layer_api_t *capture_get_module(void);
#define LAYER_CAPTURE capture_get_module()
#define LAYER_CAPTURE_ID 3
/*!
* \brief Processing module for packet capture.
*/
const knot_layer_api_t *query_capture_api(void);
/*!
* \brief Processing module parameters.
......@@ -38,5 +30,3 @@ const knot_layer_api_t *capture_get_module(void);
struct capture_param {
knot_pkt_t *sink; /*!< Container for captured response. */
};
/*! @} */
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