From 246238fe243baaffae3739c4772dfc7fe68573f3 Mon Sep 17 00:00:00 2001 From: Grigorii Demidov <grigorii.demidov@nic.cz> Date: Fri, 8 Jul 2016 13:38:31 +0200 Subject: [PATCH] lib/layer: avoiding usage of libknot's layer.h --- lib/layer.h | 39 +++++++++++++++++++++++++++++++++++++-- lib/layer/pktcache.c | 1 + lib/layer/rrcache.c | 1 + lib/module.h | 1 - lib/resolve.h | 2 +- lib/rplan.c | 1 - lib/zonecut.c | 1 + modules/stats/stats.c | 1 + 8 files changed, 42 insertions(+), 5 deletions(-) diff --git a/lib/layer.h b/lib/layer.h index 3d1d536a3..85f95100c 100644 --- a/lib/layer.h +++ b/lib/layer.h @@ -18,7 +18,6 @@ #include "lib/defines.h" #include "lib/utils.h" -#include "lib/resolve.h" #ifndef NDEBUG /** @internal Print a debug message related to resolution. */ @@ -31,6 +30,42 @@ #define QRDEBUG(query, cls, fmt, ...) #endif +/*! Layer processing states. + * Each state represents the state machine transition, + * and determines readiness for the next action. + */ +enum knot_layer_state { + KNOT_STATE_NOOP = 0, /*!< N/A */ + KNOT_STATE_CONSUME = 1 << 0, /*!< Consume data. */ + KNOT_STATE_PRODUCE = 1 << 1, /*!< Produce data. */ + KNOT_STATE_DONE = 1 << 2, /*!< Finished. */ + KNOT_STATE_FAIL = 1 << 3 /*!< Error. */ +}; + +/* Forward declarations. */ +struct knot_layer_api; + +/*! \brief Packet processing context. */ +typedef struct knot_layer { + knot_mm_t *mm; /* Processing memory context. */ + uint16_t state; /* Bitmap of enum knot_layer_state. */ + void *data; /* Module specific. */ + const struct knot_layer_api *api; +} knot_layer_t; + +/*! \brief Packet processing module API. */ +struct knot_layer_api { + int (*begin)(knot_layer_t *ctx, void *module_param); + int (*reset)(knot_layer_t *ctx); + int (*finish)(knot_layer_t *ctx); + int (*consume)(knot_layer_t *ctx, knot_pkt_t *pkt); + int (*produce)(knot_layer_t *ctx, knot_pkt_t *pkt); + int (*fail)(knot_layer_t *ctx, knot_pkt_t *pkt); + void *data; +}; + +typedef struct knot_layer_api knot_layer_api_t; + /** Pickled layer state (api, input, state). */ struct kr_layer_pickle { struct kr_layer_pickle *next; @@ -40,4 +75,4 @@ struct kr_layer_pickle { }; /* Repurpose layer states. */ -#define KNOT_STATE_YIELD KNOT_STATE_NOOP \ No newline at end of file +#define KNOT_STATE_YIELD KNOT_STATE_NOOP diff --git a/lib/layer/pktcache.c b/lib/layer/pktcache.c index 95fcff6c7..2eb8e652f 100644 --- a/lib/layer/pktcache.c +++ b/lib/layer/pktcache.c @@ -22,6 +22,7 @@ #include "lib/layer/iterate.h" #include "lib/cache.h" #include "lib/module.h" +#include "lib/resolve.h" #define DEBUG_MSG(qry, fmt...) QRDEBUG((qry), " pc ", fmt) #define DEFAULT_MAXTTL (15 * 60) diff --git a/lib/layer/rrcache.c b/lib/layer/rrcache.c index 946e70468..358adf380 100644 --- a/lib/layer/rrcache.c +++ b/lib/layer/rrcache.c @@ -28,6 +28,7 @@ #include "lib/cache.h" #include "lib/module.h" #include "lib/utils.h" +#include "lib/resolve.h" #define DEBUG_MSG(qry, fmt...) QRDEBUG((qry), " rc ", fmt) #define DEFAULT_MINTTL (5) /* Short-time "no data" retention to avoid bursts */ diff --git a/lib/module.h b/lib/module.h index 027201849..0da311a9d 100644 --- a/lib/module.h +++ b/lib/module.h @@ -16,7 +16,6 @@ #pragma once -#include <libknot/processing/layer.h> #include "lib/defines.h" #include "lib/utils.h" #include "lib/layer.h" diff --git a/lib/resolve.h b/lib/resolve.h index 563d85219..b1660a28c 100644 --- a/lib/resolve.h +++ b/lib/resolve.h @@ -17,9 +17,9 @@ #pragma once #include <netinet/in.h> -#include <libknot/processing/layer.h> #include <libknot/packet/pkt.h> +#include "lib/layer.h" #include "lib/generic/map.h" #include "lib/generic/array.h" #include "lib/nsrep.h" diff --git a/lib/rplan.c b/lib/rplan.c index 6eb52a0dc..4c8ca86b8 100644 --- a/lib/rplan.c +++ b/lib/rplan.c @@ -15,7 +15,6 @@ */ #include <libknot/descriptor.h> -#include <libknot/processing/layer.h> #include <libknot/errcode.h> #include "lib/rplan.h" diff --git a/lib/zonecut.c b/lib/zonecut.c index 2aec10366..ce11877a8 100644 --- a/lib/zonecut.c +++ b/lib/zonecut.c @@ -24,6 +24,7 @@ #include "lib/rplan.h" #include "lib/defines.h" #include "lib/layer.h" +#include "lib/resolve.h" #include "lib/generic/pack.h" /* Root hint descriptor. */ diff --git a/modules/stats/stats.c b/modules/stats/stats.c index 7cd8b84a5..777633f78 100644 --- a/modules/stats/stats.c +++ b/modules/stats/stats.c @@ -32,6 +32,7 @@ #include "lib/rplan.h" #include "lib/module.h" #include "lib/layer.h" +#include "lib/resolve.h" /** @internal Compatibility wrapper for Lua < 5.2 */ #if LUA_VERSION_NUM < 502 -- GitLab