}
/** Module implementation. */
-const knot_layer_api_t *iterate_layer(void)
+const knot_layer_api_t *iterate_layer(struct kr_module *module)
{
static const knot_layer_api_t _layer = {
.begin = &begin,
#include "lib/layer.h"
#include "lib/rplan.h"
-/* Processing module implementation. */
-extern const knot_layer_api_t *iterate_layer(void);
-
/* Packet classification. */
enum {
PKT_NOERROR = 1 << 0, /* Positive response */
int kr_response_classify(knot_pkt_t *pkt);
/* Processing module implementation. */
-const knot_layer_api_t *iterate_layer(void);
\ No newline at end of file
+const knot_layer_api_t *iterate_layer(struct kr_module *module);
\ No newline at end of file
}
/** Module implementation. */
-const knot_layer_api_t *pktcache_layer(void)
+const knot_layer_api_t *pktcache_layer(struct kr_module *module)
{
static const knot_layer_api_t _layer = {
.begin = &begin,
}
/** Module implementation. */
-const knot_layer_api_t *rrcache_layer(void)
+const knot_layer_api_t *rrcache_layer(struct kr_module *module)
{
static const knot_layer_api_t _layer = {
.begin = &begin,
#include "lib/layer.h"
/* Processing module implementation. */
-extern const knot_layer_api_t *rrcache_layer(void);
+const knot_layer_api_t *rrcache_layer(struct kr_module *module);
typedef int (module_init_cb)(struct kr_module *);
typedef int (module_deinit_cb)(struct kr_module *);
typedef int (module_config_cb)(struct kr_module *, const char *);
-typedef const knot_layer_api_t* (module_layer_cb)(void);
+typedef const knot_layer_api_t* (module_layer_cb)(struct kr_module *);
typedef struct kr_prop *(module_prop_cb)(void);
typedef char *(kr_prop_cb)(void *, struct kr_module *, const char *);
-#define KR_MODULE_API ((uint32_t) 0x20150401)
+#define KR_MODULE_API ((uint32_t) 0x20150402)
/* @endcond */
/**
for (size_t i = 0; i < ctx->modules->len; ++i) {
struct kr_module *mod = &ctx->modules->at[i];
if (mod->layer) {
- knot_overlay_add(¶m->overlay, mod->layer(), param);
+ knot_overlay_add(¶m->overlay, mod->layer(mod), param);
}
}
}
.. csv-table::
:header: "C", "Go", "Params", "Comment"
- "``X_api()`` [#]_", "``Api()``", "", "Implemented API (``uint32_t``)"
+ "``X_api()`` [#]_", "``Api()``", "", "Implemented API (``uint32_t``)"
"``X_init()``", "``Init()``", "``module``", "Constructor"
"``X_deinit()``", "``Deinit()``", "``module, key``", "Destructor"
"``X_config()``", "``Config()``", "``module``", "Configuration"
- "``X_layer()``", "``Layer()``", "", ":ref:`Module layer <lib-layers>`"
+ "``X_layer()``", "``Layer()``", "``module``", ":ref:`Module layer <lib-layers>`"
"``X_props()``", "``Props()``", "", "NULL-terminated list of properties"
.. [#] Mandatory symbol.
return 0
}
- func Layer() *C.knot_layer_api_t {
+ func Layer(module *C.struct_kr_module) *C.knot_layer_api_t {
// Wrapping the inline trampoline function
return C._layer()
}
return 0
}
-func Layer() *C.knot_layer_api_t {
+func Layer(module *C.struct_kr_module) *C.knot_layer_api_t {
return C._layer()
}
#define DEFAULT_FILE "/etc/hosts"
#define DEBUG_MSG(qry, fmt...) QRDEBUG(qry, "hint", fmt)
-/** @todo Hack until layers can store userdata. */
-static struct kr_zonecut *g_map = NULL;
-
static int begin(knot_layer_t *ctx, void *module_param)
{
ctx->data = module_param;
static int query(knot_layer_t *ctx, knot_pkt_t *pkt)
{
- assert(pkt && ctx);
struct kr_request *param = ctx->data;
struct kr_query *qry = kr_rplan_current(¶m->rplan);
if (!qry || ctx->state & (KNOT_STATE_DONE|KNOT_STATE_FAIL)) {
}
/* Find a matching name */
- pack_t *pack = kr_zonecut_find(g_map, qry->sname);
+ struct kr_module *module = ctx->api->data;
+ struct kr_zonecut *hint_map = module->data;
+ pack_t *pack = kr_zonecut_find(hint_map, qry->sname);
if (!pack || pack->len == 0) {
return ctx->state;
}
struct kr_zonecut *hints = mm_alloc(pool, sizeof(*hints));
kr_zonecut_init(hints, (const uint8_t *)(""), pool);
module->data = hints;
- g_map = hints;
return load_map(hints, fp);
}
* Module implementation.
*/
-const knot_layer_api_t *hints_layer(void)
+const knot_layer_api_t *hints_layer(struct kr_module *module)
{
- static const knot_layer_api_t _layer = {
+ static knot_layer_api_t _layer = {
.begin = &begin,
- .produce = &query
+ .produce = &query,
};
+ /* Store module reference */
+ _layer.data = module;
return &_layer;
}