Commit 4ad98bff authored by Vladimír Čunát's avatar Vladimír Čunát

layer: rename knot_ identifiers that are private now

It causes lots of line changes, but it would be confusing to keep the
current state over long term.
parent e22643c2
......@@ -107,7 +107,7 @@ static int l_ffi_init(struct kr_module *module)
/** @internal Unregister layer callback reference from registry. */
#define LAYER_UNREGISTER(L, api, name) do { \
int *cb_slot = (int *)((char *)api + sizeof(knot_layer_api_t)); \
int *cb_slot = (int *)((char *)api + sizeof(kr_layer_api_t)); \
if (cb_slot[SLOT_ ## name] > 0) \
luaL_unref(L, LUA_REGISTRYINDEX, cb_slot[SLOT_ ## name]); \
} while(0)
......@@ -121,7 +121,7 @@ static int l_ffi_deinit(struct kr_module *module)
ret = l_ffi_call(L, 1);
}
/* Free the layer API wrapper (unconst it) */
knot_layer_api_t* api = module->data;
kr_layer_api_t* api = module->data;
if (api) {
LAYER_UNREGISTER(L, api, begin);
LAYER_UNREGISTER(L, api, finish);
......@@ -137,7 +137,7 @@ static int l_ffi_deinit(struct kr_module *module)
/** @internal Helper for retrieving layer Lua function by name. */
#define LAYER_FFI_CALL(ctx, slot) \
int *cb_slot = (int *)((char *)(ctx)->api + sizeof(knot_layer_api_t)); \
int *cb_slot = (int *)((char *)(ctx)->api + sizeof(kr_layer_api_t)); \
if (cb_slot[SLOT_ ## slot] <= 0) { \
return ctx->state; \
} \
......@@ -146,21 +146,21 @@ static int l_ffi_deinit(struct kr_module *module)
lua_rawgeti(L, LUA_REGISTRYINDEX, cb_slot[SLOT_ ## slot]); \
lua_pushnumber(L, ctx->state)
static int l_ffi_layer_begin(knot_layer_t *ctx, void *module_param)
static int l_ffi_layer_begin(kr_layer_t *ctx, void *module_param)
{
LAYER_FFI_CALL(ctx, begin);
lua_pushlightuserdata(L, ctx->data);
return l_ffi_call(L, 2);
}
static int l_ffi_layer_reset(knot_layer_t *ctx)
static int l_ffi_layer_reset(kr_layer_t *ctx)
{
LAYER_FFI_CALL(ctx, reset);
lua_pushlightuserdata(L, ctx->data);
return l_ffi_call(L, 2);
}
static int l_ffi_layer_finish(knot_layer_t *ctx)
static int l_ffi_layer_finish(kr_layer_t *ctx)
{
struct kr_request *req = ctx->data;
LAYER_FFI_CALL(ctx, finish);
......@@ -169,9 +169,9 @@ static int l_ffi_layer_finish(knot_layer_t *ctx)
return l_ffi_call(L, 3);
}
static int l_ffi_layer_consume(knot_layer_t *ctx, knot_pkt_t *pkt)
static int l_ffi_layer_consume(kr_layer_t *ctx, knot_pkt_t *pkt)
{
if (ctx->state & KNOT_STATE_FAIL) {
if (ctx->state & KR_STATE_FAIL) {
return ctx->state; /* Already failed, skip */
}
LAYER_FFI_CALL(ctx, consume);
......@@ -180,9 +180,9 @@ static int l_ffi_layer_consume(knot_layer_t *ctx, knot_pkt_t *pkt)
return l_ffi_call(L, 3);
}
static int l_ffi_layer_produce(knot_layer_t *ctx, knot_pkt_t *pkt)
static int l_ffi_layer_produce(kr_layer_t *ctx, knot_pkt_t *pkt)
{
if (ctx->state & (KNOT_STATE_FAIL)) {
if (ctx->state & (KR_STATE_FAIL)) {
return ctx->state; /* Already failed or done, skip */
}
LAYER_FFI_CALL(ctx, produce);
......@@ -195,7 +195,7 @@ static int l_ffi_layer_produce(knot_layer_t *ctx, knot_pkt_t *pkt)
/** @internal Conditionally register layer trampoline
* @warning Expects 'module.layer' to be on top of Lua stack. */
#define LAYER_REGISTER(L, api, name) do { \
int *cb_slot = (int *)((char *)api + sizeof(knot_layer_api_t)); \
int *cb_slot = (int *)((char *)api + sizeof(kr_layer_api_t)); \
lua_getfield((L), -1, #name); \
if (!lua_isnil((L), -1)) { \
(api)->name = l_ffi_layer_ ## name; \
......@@ -206,12 +206,12 @@ static int l_ffi_layer_produce(knot_layer_t *ctx, knot_pkt_t *pkt)
} while(0)
/** @internal Create C layer api wrapper. */
static knot_layer_api_t *l_ffi_layer_create(lua_State *L, struct kr_module *module)
static kr_layer_api_t *l_ffi_layer_create(lua_State *L, struct kr_module *module)
{
/* Fabricate layer API wrapping the Lua functions
* reserve slots after it for references to Lua callbacks. */
const size_t api_length = sizeof(knot_layer_api_t) + (SLOT_count * SLOT_size);
knot_layer_api_t *api = malloc(api_length);
const size_t api_length = sizeof(kr_layer_api_t) + (SLOT_count * SLOT_size);
kr_layer_api_t *api = malloc(api_length);
if (api) {
memset(api, 0, api_length);
LAYER_REGISTER(L, api, begin);
......@@ -227,10 +227,10 @@ static knot_layer_api_t *l_ffi_layer_create(lua_State *L, struct kr_module *modu
}
/** @internal Retrieve C layer api wrapper. */
static const knot_layer_api_t *l_ffi_layer(struct kr_module *module)
static const kr_layer_api_t *l_ffi_layer(struct kr_module *module)
{
if (module) {
return (const knot_layer_api_t *)module->data;
return (const kr_layer_api_t *)module->data;
}
return NULL;
}
......
......@@ -705,7 +705,7 @@ static int qr_task_finalize(struct qr_task *task, int state)
task->finished = true;
/* Send back answer */
(void) qr_task_send(task, task->source.handle, (struct sockaddr *)&task->source.addr, task->req.answer);
return state == KNOT_STATE_DONE ? 0 : kr_error(EIO);
return state == KR_STATE_DONE ? 0 : kr_error(EIO);
}
static int qr_task_step(struct qr_task *task, const struct sockaddr *packet_source, knot_pkt_t *packet)
......@@ -722,15 +722,15 @@ static int qr_task_step(struct qr_task *task, const struct sockaddr *packet_sour
task->addrlist_count = 0;
task->addrlist_turn = 0;
int state = kr_resolve_consume(&task->req, packet_source, packet);
while (state == KNOT_STATE_PRODUCE) {
while (state == KR_STATE_PRODUCE) {
state = kr_resolve_produce(&task->req, &task->addrlist, &sock_type, task->pktbuf);
if (unlikely(++task->iter_count > KR_ITER_LIMIT || task->timeouts >= KR_TIMEOUT_LIMIT)) {
return qr_task_finalize(task, KNOT_STATE_FAIL);
return qr_task_finalize(task, KR_STATE_FAIL);
}
}
/* We're done, no more iterations needed */
if (state & (KNOT_STATE_DONE|KNOT_STATE_FAIL)) {
if (state & (KR_STATE_DONE|KR_STATE_FAIL)) {
return qr_task_finalize(task, state);
} else if (!task->addrlist || sock_type < 0) {
return qr_task_step(task, NULL, NULL);
......@@ -794,7 +794,7 @@ static int qr_task_step(struct qr_task *task, const struct sockaddr *packet_sour
/* Start next step with timeout, fatal if can't start a timer. */
if (ret != 0) {
subreq_finalize(task, packet_source, packet);
return qr_task_finalize(task, KNOT_STATE_FAIL);
return qr_task_finalize(task, KR_STATE_FAIL);
}
return 0;
}
......
......@@ -92,7 +92,7 @@ This structure contains pointers to resolution context, resolution plan and also
.. code-block:: c
int consume(knot_layer_t *ctx, knot_pkt_t *pkt)
int consume(kr_layer_t *ctx, knot_pkt_t *pkt)
{
struct kr_request *request = ctx->data;
struct kr_query *query = request->current_query;
......@@ -102,7 +102,7 @@ This is only passive processing of the incoming answer. If you want to change th
.. code-block:: c
int produce(knot_layer_t *ctx, knot_pkt_t *pkt)
int produce(kr_layer_t *ctx, knot_pkt_t *pkt)
{
struct kr_request *request = ctx->data;
struct kr_query *cur = request->current_query;
......@@ -112,7 +112,7 @@ This is only passive processing of the incoming answer. If you want to change th
/* This flag makes the resolver move the query
* to the "resolved" list. */
cur->flags |= QUERY_RESOLVED;
return KNOT_STATE_DONE;
return KR_STATE_DONE;
}
/* Pass-through. */
......@@ -123,7 +123,7 @@ It is possible to not only act during the query resolution, but also to view the
.. code-block:: c
int finish(knot_layer_t *ctx)
int finish(kr_layer_t *ctx)
{
struct kr_request *request = ctx->data;
struct kr_rplan *rplan = request->rplan;
......
......@@ -34,45 +34,45 @@
* 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. */
enum kr_layer_state {
KR_STATE_NOOP = 0, /*!< N/A */
KR_STATE_CONSUME = 1 << 0, /*!< Consume data. */
KR_STATE_PRODUCE = 1 << 1, /*!< Produce data. */
KR_STATE_DONE = 1 << 2, /*!< Finished. */
KR_STATE_FAIL = 1 << 3 /*!< Error. */
};
/* Forward declarations. */
struct knot_layer_api;
struct kr_layer_api;
/*! \brief Packet processing context. */
typedef struct knot_layer {
typedef struct kr_layer {
knot_mm_t *mm; /* Processing memory context. */
uint16_t state; /* Bitmap of enum knot_layer_state. */
uint16_t state; /* Bitmap of enum kr_layer_state. */
void *data; /* Module specific. */
const struct knot_layer_api *api;
} knot_layer_t;
const struct kr_layer_api *api;
} kr_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);
struct kr_layer_api {
int (*begin)(kr_layer_t *ctx, void *module_param);
int (*reset)(kr_layer_t *ctx);
int (*finish)(kr_layer_t *ctx);
int (*consume)(kr_layer_t *ctx, knot_pkt_t *pkt);
int (*produce)(kr_layer_t *ctx, knot_pkt_t *pkt);
int (*fail)(kr_layer_t *ctx, knot_pkt_t *pkt);
void *data;
};
typedef struct knot_layer_api knot_layer_api_t;
typedef struct kr_layer_api kr_layer_api_t;
/** Pickled layer state (api, input, state). */
struct kr_layer_pickle {
struct kr_layer_pickle *next;
const struct knot_layer_api *api;
const struct kr_layer_api *api;
knot_pkt_t *pkt;
unsigned state;
};
/* Repurpose layer states. */
#define KNOT_STATE_YIELD KNOT_STATE_NOOP
#define KR_STATE_YIELD KR_STATE_NOOP
This diff is collapsed.
......@@ -100,11 +100,11 @@ static int loot_pktcache(struct kr_cache *cache, knot_pkt_t *pkt, struct kr_quer
return loot_cache_pkt(cache, pkt, qname, rrtype, want_secure, timestamp, flags);
}
static int pktcache_peek(knot_layer_t *ctx, knot_pkt_t *pkt)
static int pktcache_peek(kr_layer_t *ctx, knot_pkt_t *pkt)
{
struct kr_request *req = ctx->data;
struct kr_query *qry = req->current_query;
if (ctx->state & (KNOT_STATE_FAIL|KNOT_STATE_DONE) || (qry->flags & QUERY_NO_CACHE)) {
if (ctx->state & (KR_STATE_FAIL|KR_STATE_DONE) || (qry->flags & QUERY_NO_CACHE)) {
return ctx->state; /* Already resolved/failed */
}
if (qry->ns.addr[0].ip.sa_family != AF_UNSPEC) {
......@@ -127,7 +127,7 @@ static int pktcache_peek(knot_layer_t *ctx, knot_pkt_t *pkt)
pkt->parsed = pkt->size;
knot_wire_set_qr(pkt->wire);
knot_wire_set_aa(pkt->wire);
return KNOT_STATE_DONE;
return KR_STATE_DONE;
}
return ctx->state;
}
......@@ -170,13 +170,13 @@ static uint32_t packet_ttl(knot_pkt_t *pkt, bool is_negative)
return limit_ttl(ttl);
}
static int pktcache_stash(knot_layer_t *ctx, knot_pkt_t *pkt)
static int pktcache_stash(kr_layer_t *ctx, knot_pkt_t *pkt)
{
struct kr_request *req = ctx->data;
struct kr_query *qry = req->current_query;
/* Cache only answers that make query resolved (i.e. authoritative)
* that didn't fail during processing and are negative. */
if (qry->flags & QUERY_CACHED || ctx->state & KNOT_STATE_FAIL) {
if (qry->flags & QUERY_CACHED || ctx->state & KR_STATE_FAIL) {
return ctx->state; /* Don't cache anything if failed. */
}
/* Cache only authoritative answers from IN class. */
......@@ -238,9 +238,9 @@ static int pktcache_stash(knot_layer_t *ctx, knot_pkt_t *pkt)
}
/** Module implementation. */
const knot_layer_api_t *pktcache_layer(struct kr_module *module)
const kr_layer_api_t *pktcache_layer(struct kr_module *module)
{
static const knot_layer_api_t _layer = {
static const kr_layer_api_t _layer = {
.produce = &pktcache_peek,
.consume = &pktcache_stash
};
......
......@@ -110,11 +110,11 @@ static int loot_rrcache(struct kr_cache *cache, knot_pkt_t *pkt, struct kr_query
return ret;
}
static int rrcache_peek(knot_layer_t *ctx, knot_pkt_t *pkt)
static int rrcache_peek(kr_layer_t *ctx, knot_pkt_t *pkt)
{
struct kr_request *req = ctx->data;
struct kr_query *qry = req->current_query;
if (ctx->state & (KNOT_STATE_FAIL|KNOT_STATE_DONE) || (qry->flags & QUERY_NO_CACHE)) {
if (ctx->state & (KR_STATE_FAIL|KR_STATE_DONE) || (qry->flags & QUERY_NO_CACHE)) {
return ctx->state; /* Already resolved/failed */
}
if (qry->ns.addr[0].ip.sa_family != AF_UNSPEC) {
......@@ -145,7 +145,7 @@ static int rrcache_peek(knot_layer_t *ctx, knot_pkt_t *pkt)
pkt->parsed = pkt->size;
knot_wire_set_qr(pkt->wire);
knot_wire_set_aa(pkt->wire);
return KNOT_STATE_DONE;
return KR_STATE_DONE;
}
return ctx->state;
}
......@@ -320,11 +320,11 @@ static int stash_answer(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, kno
return kr_ok();
}
static int rrcache_stash(knot_layer_t *ctx, knot_pkt_t *pkt)
static int rrcache_stash(kr_layer_t *ctx, knot_pkt_t *pkt)
{
struct kr_request *req = ctx->data;
struct kr_query *qry = req->current_query;
if (!qry || ctx->state & KNOT_STATE_FAIL) {
if (!qry || ctx->state & KR_STATE_FAIL) {
return ctx->state;
}
/* Do not cache truncated answers. */
......@@ -377,9 +377,9 @@ static int rrcache_stash(knot_layer_t *ctx, knot_pkt_t *pkt)
}
/** Module implementation. */
const knot_layer_api_t *rrcache_layer(struct kr_module *module)
const kr_layer_api_t *rrcache_layer(struct kr_module *module)
{
static const knot_layer_api_t _layer = {
static const kr_layer_api_t _layer = {
.produce = &rrcache_peek,
.consume = &rrcache_stash
};
......
......@@ -274,7 +274,7 @@ static int update_parent_keys(struct kr_query *qry, uint16_t answer_type)
DEBUG_MSG(qry, "<= parent: updating DNSKEY\n");
parent->zone_cut.key = knot_rrset_copy(qry->zone_cut.key, parent->zone_cut.pool);
if (!parent->zone_cut.key) {
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
break;
case KNOT_RRTYPE_DS:
......@@ -285,7 +285,7 @@ static int update_parent_keys(struct kr_query *qry, uint16_t answer_type)
} else { /* DS existence proven. */
parent->zone_cut.trust_anchor = knot_rrset_copy(qry->zone_cut.trust_anchor, parent->zone_cut.pool);
if (!parent->zone_cut.trust_anchor) {
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
}
break;
......@@ -369,13 +369,13 @@ static const knot_dname_t *signature_authority(knot_pkt_t *pkt)
return NULL;
}
static int validate(knot_layer_t *ctx, knot_pkt_t *pkt)
static int validate(kr_layer_t *ctx, knot_pkt_t *pkt)
{
int ret = 0;
struct kr_request *req = ctx->data;
struct kr_query *qry = req->current_query;
/* Ignore faulty or unprocessed responses. */
if (ctx->state & (KNOT_STATE_FAIL|KNOT_STATE_CONSUME)) {
if (ctx->state & (KR_STATE_FAIL|KR_STATE_CONSUME)) {
return ctx->state;
}
......@@ -389,7 +389,7 @@ static int validate(knot_layer_t *ctx, knot_pkt_t *pkt)
if (!(qry->flags & QUERY_CACHED) && !knot_pkt_has_dnssec(pkt) && !use_signatures) {
DEBUG_MSG(qry, "<= got insecure response\n");
qry->flags |= QUERY_DNSSEC_BOGUS;
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
/* Track difference between current TA and signer name.
......@@ -399,8 +399,8 @@ static int validate(knot_layer_t *ctx, knot_pkt_t *pkt)
const knot_dname_t *ta_name = qry->zone_cut.trust_anchor ? qry->zone_cut.trust_anchor->owner : NULL;
const knot_dname_t *signer = signature_authority(pkt);
if (track_pc_change && ta_name && (!signer || !knot_dname_is_equal(ta_name, signer))) {
if (ctx->state == KNOT_STATE_YIELD) { /* Already yielded for revalidation. */
return KNOT_STATE_FAIL;
if (ctx->state == KR_STATE_YIELD) { /* Already yielded for revalidation. */
return KR_STATE_FAIL;
}
DEBUG_MSG(qry, ">< cut changed, needs revalidation\n");
if (!signer) {
......@@ -419,7 +419,7 @@ static int validate(knot_layer_t *ctx, knot_pkt_t *pkt)
}
qry->zone_cut.name = knot_dname_copy(signer, &req->pool);
} /* else zone cut matches, but DS/DNSKEY doesn't => refetch. */
return KNOT_STATE_YIELD;
return KR_STATE_YIELD;
}
/* Check if this is a DNSKEY answer, check trust chain and store. */
......@@ -431,7 +431,7 @@ static int validate(knot_layer_t *ctx, knot_pkt_t *pkt)
if (ret != 0) {
DEBUG_MSG(qry, "<= bad keys, broken trust chain\n");
qry->flags |= QUERY_DNSSEC_BOGUS;
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
}
......@@ -446,7 +446,7 @@ static int validate(knot_layer_t *ctx, knot_pkt_t *pkt)
if (ret != 0) {
DEBUG_MSG(qry, "<= bad NXDOMAIN proof\n");
qry->flags |= QUERY_DNSSEC_BOGUS;
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
}
......@@ -473,7 +473,7 @@ static int validate(knot_layer_t *ctx, knot_pkt_t *pkt)
} else {
DEBUG_MSG(qry, "<= bad NODATA proof\n");
qry->flags |= QUERY_DNSSEC_BOGUS;
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
}
}
......@@ -486,7 +486,7 @@ static int validate(knot_layer_t *ctx, knot_pkt_t *pkt)
if (ret != 0) {
DEBUG_MSG(qry, "<= couldn't validate RRSIGs\n");
qry->flags |= QUERY_DNSSEC_BOGUS;
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
}
......@@ -503,21 +503,21 @@ static int validate(knot_layer_t *ctx, knot_pkt_t *pkt)
/* Check and update current delegation point security status. */
ret = update_delegation(req, qry, pkt, has_nsec3);
if (ret != 0) {
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
/* Update parent query zone cut */
if (qry->parent) {
if (update_parent_keys(qry, qtype) != 0) {
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
}
DEBUG_MSG(qry, "<= answer valid, OK\n");
return KNOT_STATE_DONE;
return KR_STATE_DONE;
}
/** Module implementation. */
const knot_layer_api_t *validate_layer(struct kr_module *module)
const kr_layer_api_t *validate_layer(struct kr_module *module)
{
static const knot_layer_api_t _layer = {
static const kr_layer_api_t _layer = {
.consume = &validate,
};
/* Store module reference */
......
......@@ -24,10 +24,10 @@
#include "lib/module.h"
/* List of embedded modules */
const knot_layer_api_t *iterate_layer(struct kr_module *module);
const knot_layer_api_t *validate_layer(struct kr_module *module);
const knot_layer_api_t *rrcache_layer(struct kr_module *module);
const knot_layer_api_t *pktcache_layer(struct kr_module *module);
const kr_layer_api_t *iterate_layer(struct kr_module *module);
const kr_layer_api_t *validate_layer(struct kr_module *module);
const kr_layer_api_t *rrcache_layer(struct kr_module *module);
const kr_layer_api_t *pktcache_layer(struct kr_module *module);
static const struct kr_module embedded_modules[] = {
{ "iterate", NULL, NULL, NULL, iterate_layer, NULL, NULL, NULL },
{ "validate", NULL, NULL, NULL, validate_layer, NULL, NULL, NULL },
......
......@@ -34,7 +34,7 @@ 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)(struct kr_module *);
typedef const kr_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) 0x20150402)
......
This diff is collapsed.
......@@ -52,11 +52,11 @@
* state = kr_resolve_consume(&req, query);
*
* // Generate answer
* while (state == KNOT_STATE_PRODUCE) {
* while (state == KR_STATE_PRODUCE) {
*
* // Additional query generate, do the I/O and pass back answer
* state = kr_resolve_produce(&req, &addr, &type, query);
* while (state == KNOT_STATE_CONSUME) {
* while (state == KR_STATE_CONSUME) {
* int ret = sendrecv(addr, proto, query, resp);
*
* // If I/O fails, make "resp" empty
......
......@@ -210,11 +210,11 @@ to avoid multiple declarations. Here's how the preface looks like:
#include "lib/layer.h"
#include "lib/module.h"
// Need a forward declaration of the function signature
int finish(knot_layer_t *);
int finish(kr_layer_t *);
// Workaround for layers composition
static inline const knot_layer_api_t *_layer(void)
static inline const kr_layer_api_t *_layer(void)
{
static const knot_layer_api_t api = {
static const kr_layer_api_t api = {
.finish = &finish
};
return &api;
......@@ -228,7 +228,7 @@ Now we can add the implementations for the ``finish`` layer and finalize the mod
.. code-block:: go
//export finish
func finish(ctx *C.knot_layer_t) C.int {
func finish(ctx *C.kr_layer_t) C.int {
// Since the context is unsafe.Pointer, we need to cast it
var param *C.struct_kr_request = (*C.struct_kr_request)(ctx.data)
// Now we can use the C API as well
......@@ -237,7 +237,7 @@ Now we can add the implementations for the ``finish`` layer and finalize the mod
}
//export mymodule_layer
func mymodule_layer(module *C.struct_kr_module) *C.knot_layer_api_t {
func mymodule_layer(module *C.struct_kr_module) *C.kr_layer_api_t {
// Wrapping the inline trampoline function
return C._layer()
}
......
......@@ -216,13 +216,13 @@ static bool check_cookie_content_and_cache(const struct kr_cookie_settings *clnt
}
/** Process incoming response. */
int check_response(knot_layer_t *ctx, knot_pkt_t *pkt)
int check_response(kr_layer_t *ctx, knot_pkt_t *pkt)
{
struct kr_request *req = ctx->data;
struct kr_query *qry = req->current_query;
struct kr_cookie_ctx *cookie_ctx = &req->ctx->cookie_ctx;
if (ctx->state & (KNOT_STATE_DONE | KNOT_STATE_FAIL)) {
if (ctx->state & (KR_STATE_DONE | KR_STATE_FAIL)) {
return ctx->state;
}
......@@ -246,7 +246,7 @@ int check_response(knot_layer_t *ctx, knot_pkt_t *pkt)
/* We haven't received any cookies although we should. */
DEBUG_MSG(NULL, "%s\n",
"expected to receive a cookie but none received");
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
if (!pkt_cookie_opt) {
......@@ -256,7 +256,7 @@ int check_response(knot_layer_t *ctx, knot_pkt_t *pkt)
if (!check_cookie_content_and_cache(&cookie_ctx->clnt, req,
pkt_cookie_opt, cookie_cache)) {
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
uint16_t rcode = knot_pkt_get_ext_rcode(pkt);
......@@ -281,10 +281,10 @@ int check_response(knot_layer_t *ctx, knot_pkt_t *pkt)
* we always expect that the server doesn't support TCP.
*/
qry->flags &= ~QUERY_BADCOOKIE_AGAIN;
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
return KNOT_STATE_CONSUME;
return KR_STATE_CONSUME;
}
return ctx->state;
......@@ -303,7 +303,7 @@ static inline uint8_t *req_cookie_option(struct kr_request *req)
* @brief Returns resolver state and sets answer RCODE on missing or invalid
* server cookie.
*
* @note Caller should exit when only KNOT_STATE_FAIL is returned.
* @note Caller should exit when only KR_STATE_FAIL is returned.
*
* @param state original resolver state
* @param sc_present true if server cookie is present
......@@ -319,15 +319,15 @@ static int invalid_sc_status(int state, bool sc_present, bool ignore_badcookie,
const knot_pkt_t *pkt = req->qsource.packet;
if (!pkt) {
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
if (knot_wire_get_qdcount(pkt->wire) == 0) {
/* RFC7873 5.4 */
state = KNOT_STATE_DONE;
state = KR_STATE_DONE;
if (sc_present) {
kr_pkt_set_ext_rcode(answer, KNOT_RCODE_BADCOOKIE);
state |= KNOT_STATE_FAIL;
state |= KR_STATE_FAIL;
}
} else if (!ignore_badcookie) {
/* Generate BADCOOKIE response. */
......@@ -338,23 +338,23 @@ static int invalid_sc_status(int state, bool sc_present, bool ignore_badcookie,
DEBUG_MSG(NULL, "%s\n",
"missing EDNS section in prepared answer");
/* Caller should exit on this (and only this) state. */
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
kr_pkt_set_ext_rcode(answer, KNOT_RCODE_BADCOOKIE);
state = KNOT_STATE_FAIL | KNOT_STATE_DONE;
state = KR_STATE_FAIL | KR_STATE_DONE;
}
return state;
}
int check_request(knot_layer_t *ctx, void *module_param)
int check_request(kr_layer_t *ctx, void *module_param)
{
struct kr_request *req = ctx->data;
struct kr_cookie_settings *srvr_sett = &req->ctx->cookie_ctx.srvr;
knot_pkt_t *answer = req->answer;
if (ctx->state & (KNOT_STATE_DONE | KNOT_STATE_FAIL)) {
if (ctx->state & (KR_STATE_DONE | KR_STATE_FAIL)) {
return ctx->state;
}
......@@ -378,7 +378,7 @@ int check_request(knot_layer_t *ctx, void *module_param)
/* FORMERR -- malformed cookies. */
DEBUG_MSG(NULL, "%s\n", "request with malformed cookie");
knot_wire_set_rcode(answer->wire, KNOT_RCODE_FORMERR);
return KNOT_STATE_FAIL | KNOT_STATE_DONE;
return KR_STATE_FAIL | KR_STATE_DONE;
}
/*
......@@ -392,7 +392,7 @@ int check_request(knot_layer_t *ctx, void *module_param)
if (!req->qsource.addr || !srvr_sett->current.secr || !current_sc_alg) {
DEBUG_MSG(NULL, "%s\n", "missing valid server cookie context");
return KNOT_STATE_FAIL;
return KR_STATE_FAIL;
}
int return_state = ctx->state;
......@@ -419,7 +419,7 @@ int check_request(knot_layer_t *ctx, void *module_param)
/* Request has no server cookie. */
return_state = invalid_sc_status(return_state, false,
ignore_badcookie, req, answer);
if (return_state == KNOT_STATE_FAIL) {
if (return_state == KR_STATE_FAIL) {
return return_state;
}
goto answer_add_cookies;
......@@ -445,7 +445,7 @@ int check_request(knot_layer_t *ctx, void *module_param)
/* Invalid server cookie. */
return_state = invalid_sc_status(return_state, true,
ignore_badcookie, req, answer);
if (return_state == KNOT_STATE_FAIL) {
if (return_state == KR_STATE_FAIL) {
return return_state;
}
goto answer_add_cookies;
......@@ -457,7 +457,7 @@ int check_request(knot_layer_t *ctx, void *module_param)
/* Add server cookie into response. */
ret = kr_answer_write_cookie(&sc_input, &nonce, current_sc_alg, answer);
if (ret != kr_ok()) {
return_state = KNOT_STATE_FAIL;
return_state = KR_STATE_FAIL;
}
return return_state;
}
......@@ -26,7 +26,7 @@
* @param module_param module parameters
* @return layer state
*/
int check_request(knot_layer_t *ctx, void *module_param);
int check_request(kr_layer_t *ctx, void *module_param);
/**
* @brief Checks cookies of received responses.
......@@ -34,4 +34,4 @@ int check_request(knot_layer_t *ctx, void *module_param);
* @param pkt response packet
* @return layer state
*/
int check_response(knot_layer_t *ctx, knot_pkt_t *pkt);
int check_response(kr_layer_t *ctx, knot_pkt_t *pkt);
......@@ -73,12 +73,12 @@ int cookies_deinit(struct kr_module *module)
}
KR_EXPORT
const knot_layer_api_t *cookies_layer(struct kr_module *module)
const kr_layer_api_t *cookies_layer(struct kr_module *module)
{
/* The function answer_finalize() in resolver is called before any
* .finish callback. Therefore this layer does not use it. */
static knot_layer_api_t _layer = {
static kr_layer_api_t _layer = {
.begin = &check_request,
.consume = &check_response
};
......
......@@ -48,7 +48,7 @@ struct rev_search_baton {
size_t addr_len;
};
static int begin(knot_layer_t *ctx, void *module_param)
static int begin(kr_layer_t *ctx, void *module_param)
{
ctx->data = module_param;
return ctx->state;
......@@ -179,11 +179,11 @@ static int satisfy_forward(struct kr_zonecut *hints, knot_pkt_t *pkt, struct kr_
return put_answer(pkt, &rr);
}
static int query(knot_layer_t *ctx, knot_pkt_t *pkt)
static int query(kr_layer_t *ctx, knot_pkt_t *pkt)
{
struct kr_request *req = ctx->data;
struct kr_query *qry =