]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/modules: layer() api now accept module name
authorMarek Vavruša <marek.vavrusa@nic.cz>
Wed, 6 May 2015 08:27:47 +0000 (10:27 +0200)
committerMarek Vavruša <marek.vavrusa@nic.cz>
Wed, 6 May 2015 08:27:47 +0000 (10:27 +0200)
module api can now store userdata, e.g. owner

lib/layer/iterate.c
lib/layer/iterate.h
lib/layer/pktcache.c
lib/layer/rrcache.c
lib/layer/rrcache.h
lib/module.h
lib/resolve.c
modules/README.rst
modules/gostats/gostats.go
modules/hints/hints.c

index 9b69beb57f704bab2ced6f00ab20beb10bcacb9e..fbe45bfc32e7e905c07a8b19f62e00cd8e74fe90 100644 (file)
@@ -442,7 +442,7 @@ static int resolve(knot_layer_t *ctx, knot_pkt_t *pkt)
 }
 
 /** 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,
index 4ae49a217c2308b15e097c027e4e019efb29b4f7..dbdcf81c88d56deb5a000a368823e8ff4219d98e 100644 (file)
@@ -19,9 +19,6 @@
 #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 */
@@ -34,4 +31,4 @@ enum {
 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
index 12db00def25f46bc800c6ee3cd885909e0074ac1..383ad4e10d6a8637c8293f0b2f644b13b14e7b91 100644 (file)
@@ -148,7 +148,7 @@ static int stash(knot_layer_t *ctx)
 }
 
 /** 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,
index 94a590deeade30b192177da5da502285194cb826..d5ef9b2f88e05ead29ac8ef57fe4501688327640 100644 (file)
@@ -247,7 +247,7 @@ static int stash(knot_layer_t *ctx, knot_pkt_t *pkt)
 }
 
 /** 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,
index cb5474664c0f5c25fb6217c00bfba4da7b794244..305addaff7a5dc9a27eb55be794d537426f77317 100644 (file)
@@ -19,4 +19,4 @@
 #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);
index 2b8c9c7eff5d97e6f02e20895db4b0a258491fc6..eb5a6ebfe557f145ff398552105e8740cbe5177d 100644 (file)
@@ -34,10 +34,10 @@ typedef uint32_t (module_api_cb)(void);
 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 */
 
 /**
index 1ebf77a8a196a90d911007c87f1923780bf27499..8dbc0c6edf394be1373ef6daab529a7691a3c19c 100644 (file)
@@ -61,7 +61,7 @@ static void prepare_layers(struct kr_request *param)
        for (size_t i = 0; i < ctx->modules->len; ++i) {
                struct kr_module *mod = &ctx->modules->at[i];
                if (mod->layer) {
-                       knot_overlay_add(&param->overlay, mod->layer(), param);
+                       knot_overlay_add(&param->overlay, mod->layer(mod), param);
                }
        }
 }
index 66072265488ea2717d359a4466d8256bdd9fb5a5..a731dc761202c354ac4ba4853337fbcd1aa103c6 100644 (file)
@@ -30,11 +30,11 @@ A module is a shared library defining specific functions, here's an overview of
 .. 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.
@@ -170,7 +170,7 @@ Now we can add the implementations for the ``Begin`` and ``Finish`` functions, a
                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()
        }
index 0c3b4ee61f0c0375889430cd79f7e2c9e87e4a6c..92fd2ebd4a42b402291d9b9e5733218fdef2857d 100644 (file)
@@ -41,6 +41,6 @@ func Finish(ctx *C.knot_layer_t) C.int {
        return 0
 }
 
-func Layer() *C.knot_layer_api_t {
+func Layer(module *C.struct_kr_module) *C.knot_layer_api_t {
        return C._layer()
 }
index 8a0b2a9cf0a2efb6deb74d6de1539bd507d86b2d..36a71aa7ef75efaf80a29636e6e15eb067d33051 100644 (file)
@@ -36,9 +36,6 @@
 #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;
@@ -78,7 +75,6 @@ static int answer_query(knot_pkt_t *pkt, pack_t *addr_set, struct kr_request *pa
 
 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(&param->rplan);
        if (!qry || ctx->state & (KNOT_STATE_DONE|KNOT_STATE_FAIL)) {
@@ -89,7 +85,9 @@ static int query(knot_layer_t *ctx, knot_pkt_t *pkt)
        }
 
        /* 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;
        }
@@ -182,7 +180,6 @@ static int load(struct kr_module *module, const char *path)
        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);
 }
 
@@ -268,12 +265,14 @@ static char* hint_get(void *env, struct kr_module *module, const char *args)
  * 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;
 }