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

nameserver: packet capture processor

parent 2c24a122
......@@ -335,3 +335,5 @@ tests/worker_queue.c
tests/zone_events.c
tests/zonedb.c
tests/ztree.c
src/knot/nameserver/capture.c
src/knot/nameserver/capture.h
......@@ -231,6 +231,8 @@ libknotd_la_SOURCES = \
knot/nameserver/axfr.h \
knot/nameserver/chaos.c \
knot/nameserver/chaos.h \
knot/nameserver/capture.c \
knot/nameserver/capture.h \
knot/nameserver/internet.c \
knot/nameserver/internet.h \
knot/nameserver/ixfr.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/capture.h"
#include "knot/server/tcp-handler.h"
#include "knot/server/udp-handler.h"
/* State-less packet capture, only incoming data is accepted. */
static int noop(knot_pkt_t *pkt, knot_process_t *ctx) { return NS_PROC_NOOP; }
static int reset(knot_process_t *ctx) { return NS_PROC_MORE; }
static int finish(knot_process_t *ctx) { return NS_PROC_NOOP; }
/* Set capture parameters (sink). */
static int begin(knot_process_t *ctx, void *module_param)
{
ctx->data = module_param;
return NS_PROC_MORE;
}
/* Forward packet. */
static int capture(knot_pkt_t *pkt, knot_process_t *ctx)
{
assert(pkt && ctx);
struct process_capture_param *param = ctx->data;
/* Copy packet contents and free. */
knot_pkt_copy(param->sink, pkt);
knot_pkt_free(&pkt);
return NS_PROC_DONE;
}
/*! \brief Module implementation. */
static const knot_process_module_t PROCESS_CAPTURE_MODULE = {
&begin,
&reset,
&finish,
&capture,
&noop, /* No output. */
&noop /* No error processing. */
};
const knot_process_module_t *proc_capture_get_module(void)
{
return &PROCESS_CAPTURE_MODULE;
}
/*!
* \file capture.h
*
* \author Marek Vavrusa <marek.vavrusa@nic.cz>
*
* \brief Simple packet capture processor.
*
* \addtogroup answer_processing
* @{
*/
/* 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 "libknot/processing/process.h"
#include "libknot/packet/pkt.h"
/* Processing module implementation. */
const knot_process_module_t *proc_capture_get_module(void);
#define NS_PROC_CAPTURE proc_capture_get_module()
#define NS_PROC_CAPTURE_ID 3
/*!
* \brief Processing module parameters.
*/
struct process_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