}
*(p - 1) = '\0';
lua_pushstring(L, buf);
- lua_setfield(L, -2, "mac");
+ lua_setfield(L, -2, "mac");
/* Push table */
lua_setfield(L, -2, iface.name);
register_lib(L, "cache", lib);
return 1;
-}
\ No newline at end of file
+}
/** Print help and available commands. */
static int l_help(lua_State *L)
{
- static const char *help_str =
+ static const char *help_str =
"help()\n show this help\n"
"quit()\n quit\n"
"modules.list()\n list modules\n"
return ret;
}
- return uv_run(uv_default_loop(), UV_RUN_DEFAULT);
+ return uv_run(uv_default_loop(), UV_RUN_DEFAULT);
}
void engine_stop(struct engine *engine)
struct engine *engine_luaget(lua_State *L)
{
- lua_getglobal(L, "__engine");
+ lua_getglobal(L, "__engine");
struct engine *engine = lua_touserdata(L, -1);
lua_pop(engine->L, 1);
return engine;
-}
\ No newline at end of file
+}
int engine_unregister(struct engine *engine, const char *module);
/** Return engine light userdata. */
void engine_lualib(struct engine *engine, const char *name, int (*lib_cb) (struct lua_State *));
-struct engine *engine_luaget(struct lua_State *L);
\ No newline at end of file
+struct engine *engine_luaget(struct lua_State *L);
*port = atoi(p + 1);
*p = '\0';
}
-
+
return addr;
}
return EXIT_FAILURE;
}
printf("[system] rundir '%s'\n", argv[optind]);
- }
+ }
/* Block signals. */
uv_loop_t *loop = uv_default_loop();
break;
}
}
-
+
/* Collapse key if it has no endpoint. */
if (ep_array->len == 0) {
free(ep_array);
/**
* Resolve query.
- *
+ *
* @param worker
* @param answer
* @param query
/**
* Set EDNS DO (DNSSEC OK) bit.
- *
+ *
* @param value EDNS DO bit (0 or 1, default 0).
*/
getdns_return_t getdns_context_set_edns_do_bit(
if (copy.owner == NULL) {
return copy;
}
-
+
for (uint16_t i = 0; i < src->rrs.rr_count; ++i) {
knot_rdata_t *rd = knot_rdataset_at(&src->rrs, i);
if (knot_rdata_ttl(rd) > drift) {
}
}
}
-
+
/* Update TTLs. */
for (uint16_t i = 0; i < copy.rrs.rr_count; ++i) {
knot_rdata_t *rd = knot_rdataset_at(©.rrs, i);
knot_rdata_set_ttl(rd, knot_rdata_ttl(rd) - drift);
}
-
+
return copy;
}
*/
/** \addtogroup cache
- * @{
+ * @{
*/
#pragma once
*/
/** \addtogroup resolution
- * @{
+ * @{
*/
#pragma once
*/
#define KR_DNS_PORT 53
#define KR_EDNS_VERSION 0
-#define KR_EDNS_PAYLOAD 4096
+#define KR_EDNS_PAYLOAD 4096
/** @} */
* \note The C has no generics, so it is implemented mostly using macros.
* Be aware of that, as direct usage of the macros in the evaluating macros
* may lead to different expectations, i.e.
- *
+ *
* MIN(array_push(arr, val))
*
* May evaluate the code twice, leading to unexpected behaviour.
* This is a price to pay for absence of proper generics.
*
* Example usage:
- *
+ *
* array_t(const char*) arr;
* array_init(arr);
- *
+ *
* // Reserve memory in advance
* if (array_reserve(arr, 2) < 0) {
* return ENOMEM;
*
* // Random delete
* array_del(arr, 0);
- *
+ *
* \addtogroup generics
- * @{
+ * @{
*/
#pragma once
x->value = value;
memcpy(x->key, str, len);
}
- return x;
+ return x;
}
/*! Creates a new, empty critbit map */
* Generics - A Crit-bit tree 'map' implementation.
*
* @warning If the user provides a custom allocator, it must return addresses aligned to 2B boundary.
- *
+ *
* Example usage:
- *
+ *
* map_t map = map_make();
*
- * // Custom allocator (optional)
- * map.malloc = &mymalloc;
- * map.baton = &mymalloc_context;
+ * // Custom allocator (optional)
+ * map.malloc = &mymalloc;
+ * map.baton = &mymalloc_context;
*
* // Insert keys
* if (map_set(&map, "princess") != 0 ||
* }
*
* // Prefix search
- * int i = 0;
+ * int i = 0;
* int count(const char *s, void *n) { (*(int *)n)++; return 0; }
* if (map_walk_prefixed(map, "princ", count, &i) == 0) {
* printf("%d matches\n", i);
*
* // Clear the map
* map_clear(&map);
- *
+ *
* \addtogroup generics
- * @{
+ * @{
*/
#pragma once
}
#endif
-/** @} */
\ No newline at end of file
+/** @} */
* Generics - A Crit-bit set implementation.
*
* @note The API is based on @fn map.h, see it for more examples.
- *
+ *
* Example usage:
- *
+ *
* set_t set = set_make();
*
* // Insert keys
* }
*
* // Prefix search
- * int i = 0;
+ * int i = 0;
* int count(const char *s, void *n) { (*(int *)n)++; return 0; }
* if (set_walk_prefixed(set, "princ", count, &i) == 0) {
* printf("%d matches\n", i);
*
* // Clear the set
* set_clear(&set);
- *
+ *
* \addtogroup generics
- * @{
+ * @{
*/
#pragma once
#pragma once
/** \addtogroup rplan
- * @{
+ * @{
*/
#include <libknot/processing/layer.h>
PKT_NOERROR = 1 << 0, /* Positive response */
PKT_NODATA = 1 << 1, /* No data response */
PKT_NXDOMAIN = 1 << 2, /* Negative response */
- PKT_ERROR = 1 << 3 /* Refused or server failure */
+ PKT_ERROR = 1 << 3 /* Refused or server failure */
};
/* Iterator often walks through packet section, this is an abstraction. */
int rr_update_answer(const knot_rrset_t *rr, unsigned hint, struct kr_layer_param *param)
{
knot_pkt_t *answer = param->answer;
-
+
/* Write copied RR to the result packet. */
int ret = knot_pkt_put(answer, KNOT_COMPR_HINT_NONE, rr, hint);
if (ret != KNOT_EOK) {
const knot_rrset_t *rr = knot_pkt_rr(ar, i);
if ((rr->type == KNOT_RRTYPE_A || rr->type == KNOT_RRTYPE_AAAA) &&
(knot_dname_is_equal(ns_name, rr->owner))) {
- return true;
+ return true;
}
}
return false;
query->id = dnssec_random_uint16_t();
knot_wire_set_id(pkt->wire, query->id);
-
+
/* Declare EDNS0 support. */
knot_rrset_t opt_rr;
ret = knot_edns_init(&opt_rr, KR_EDNS_PAYLOAD, 0, KR_EDNS_VERSION, &pkt->mm);
if (rr_copy.rrs.rr_count == 0) {
return KNOT_STATE_FAIL;
}
-
+
return rr_update_answer(&rr_copy, 0, param);
}
/** Check ABI version, return error on mismatch. */
#define ABI_CHECK(m, prefix, symname, required) do { \
if ((m)->lib != RTLD_DEFAULT) { \
- module_api_cb *_api = NULL; \
- *(void **) (&_api) = load_symbol((m)->lib, (prefix), (symname)); \
- if (_api == NULL) { \
- return kr_error(ENOENT); \
- } \
- if (_api() != (required)) { \
- return kr_error(ENOTSUP); \
- } \
- }\
- } while (0)
-
-/** Load ABI by symbol names. */
+ module_api_cb *_api = NULL; \
+ *(void **) (&_api) = load_symbol((m)->lib, (prefix), (symname)); \
+ if (_api == NULL) { \
+ return kr_error(ENOENT); \
+ } \
+ if (_api() != (required)) { \
+ return kr_error(ENOTSUP); \
+ } \
+ }\
+} while (0)
+
+/** Load ABI by symbol names. */
#define ABI_LOAD(m, prefix, s_init, s_deinit, s_config, s_layer, s_prop) do { \
- module_prop_cb *module_prop = NULL; \
+ module_prop_cb *module_prop = NULL; \
*(void **) (&(m)->init) = load_symbol((m)->lib, (prefix), (s_init)); \
*(void **) (&(m)->deinit) = load_symbol((m)->lib, (prefix), (s_deinit)); \
*(void **) (&(m)->config) = load_symbol((m)->lib, (prefix), (s_config)); \
/** Load C module symbols. */
static int load_sym_c(struct kr_module *module, uint32_t api_required)
{
- auto_free char *module_prefix = kr_strcatdup(2, module->name, "_");
- ABI_CHECK(module, module_prefix, "api", api_required);
- ABI_LOAD(module, module_prefix, "init", "deinit", "config", "layer", "props");
+ auto_free char *module_prefix = kr_strcatdup(2, module->name, "_");
+ ABI_CHECK(module, module_prefix, "api", api_required);
+ ABI_LOAD(module, module_prefix, "init", "deinit", "config", "layer", "props");
return kr_ok();
}
return kr_ok();
}
-/** Load Go module symbols. */
+/** Load Go module symbols. */
static int load_ffi_go(struct kr_module *module, uint32_t api_required)
{
/* Bootstrap libgo */
auto_free char *local_path = kr_strcatdup(2, getenv("HOME"), "/.local" MODULEDIR);
if (load_library(module, name, local_path) != 0) {
if (load_library(module, name, PREFIX MODULEDIR) != 0) {
- module->lib = RTLD_DEFAULT;
+ module->lib = RTLD_DEFAULT;
}
}
}
kr_module_unload(module);
}
-
return ret;
}
*/
/** \addtogroup modules
- * @{
+ * @{
*/
#pragma once
/**
* Load module instance into memory.
- *
+ *
* @param module module structure
* @param name module name
* @param path module search path
/**
* Unload module instance.
- *
+ *
* @param module module structure
*/
void kr_module_unload(struct kr_module *module);
/**
* Export module API version (place this at the end of your module).
- *
+ *
* @param module module name (f.e. hints)
*/
#define KR_MODULE_EXPORT(module) \
{
/* TODO: stub, always returns valid */
return KR_NS_VALID;
-}
\ No newline at end of file
+}
*/
/** \addtogroup nameservers
- * @{
+ * @{
*/
#pragma once
if (txn == NULL) {
return KNOT_EOK;
}
-
+
/* Fetch current nameserver cache. */
uint32_t drift = qry->timestamp.tv_sec;
knot_rrset_t cached;
return KNOT_EOK;
}
cached = kr_cache_materialize(&cached, drift, rplan->pool);
-
+
/* Find a matching RD. */
knot_rdataset_t to_remove;
knot_rdataset_init(&to_remove);
}
knot_rdataset_subtract(&cached.rrs, &to_remove, rplan->pool);
knot_rdataset_clear(&to_remove, rplan->pool);
-
+
/* Remove record(s) */
int ret = KNOT_EOK;
if (cached.rrs.rr_count == 0) {
static int ns_resolve_addr(struct kr_query *cur, struct kr_layer_param *param)
{
- if (kr_rplan_satisfies(cur, cur->zone_cut.ns, KNOT_CLASS_IN, KNOT_RRTYPE_A) ||
+ if (kr_rplan_satisfies(cur, cur->zone_cut.ns, KNOT_CLASS_IN, KNOT_RRTYPE_A) ||
kr_rplan_satisfies(cur, cur->zone_cut.ns, KNOT_CLASS_IN, KNOT_RRTYPE_AAAA)) {
DEBUG_MSG("=> dependency loop, bailing out\n");
kr_rplan_pop(param->rplan, cur);
*/
/** \addtogroup resolution
- * @{
+ * @{
*/
#pragma once
*/
/** \addtogroup rplan
- * @{
+ * @{
*/
#pragma once
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
+
#include "lib/defines.h"
#include "lib/utils.h"
*/
void _cleanup_free(char **p)
{
- free(*p);
+ free(*p);
}
void _cleanup_close(int *p)
{
- if (*p > 0) close(*p);
+ if (*p > 0) close(*p);
}
void _cleanup_fclose(FILE **p)
{
- if (*p) fclose(*p);
+ if (*p) fclose(*p);
}
char* kr_strcatdup(unsigned n, ...)
{
- /* Calculate total length */
- size_t total_len = 0;
- va_list vl;
- va_start(vl, n);
- for (unsigned i = 0; i < n; ++i) {
- char *item = va_arg(vl, char *);
- total_len += strlen_safe(item);
- }
- va_end(vl);
-
- /* Allocate result and fill */
- char *result = NULL;
- if (total_len > 0) {
- result = malloc(total_len + 1);
- }
- if (result) {
- char *stream = result;
- va_start(vl, n);
- for (unsigned i = 0; i < n; ++i) {
- char *item = va_arg(vl, char *);
- if (item) {
- size_t len = strlen(item);
- memcpy(stream, item, len + 1);
- stream += len;
- }
- }
- va_end(vl);
- }
-
- return result;
-}
\ No newline at end of file
+ /* Calculate total length */
+ size_t total_len = 0;
+ va_list vl;
+ va_start(vl, n);
+ for (unsigned i = 0; i < n; ++i) {
+ char *item = va_arg(vl, char *);
+ total_len += strlen_safe(item);
+ }
+ va_end(vl);
+
+ /* Allocate result and fill */
+ char *result = NULL;
+ if (total_len > 0) {
+ result = malloc(total_len + 1);
+ }
+ if (result) {
+ char *stream = result;
+ va_start(vl, n);
+ for (unsigned i = 0; i < n; ++i) {
+ char *item = va_arg(vl, char *);
+ if (item) {
+ size_t len = strlen(item);
+ memcpy(stream, item, len + 1);
+ stream += len;
+ }
+ }
+ va_end(vl);
+ }
+
+ return result;
+}
*/
/** \addtogroup utils
- * @{
+ * @{
*/
#pragma once
if (ret != KNOT_EOK) {
return ret;
}
-
+
/* Accept only if has address records cached. */
for (unsigned i = 0; i < cached_rr.rrs.rr_count; ++i) {
kr_set_zone_cut(cut, name, knot_ns_name(&cached_rr.rrs, i));
*/
/** \addtogroup rplan
- * @{
+ * @{
*/
#pragma once
*
* Input: N/A
* Output: { size: int }
- *
+ *
*/
static char* get_size(void *env, struct kr_module *module, const char *args)
{
} else {
asprintf(&result, "{ \"error\": \"%s\" }", knot_strerror(ret));
}
-
+
return result;
}
*
* Input: N/A
* Output: { pruned: int }
- *
+ *
*/
static char* prune(void *env, struct kr_module *module, const char *args)
{
} else {
asprintf(&result, "{ \"pruned\": %d }", pruned);
}
-
+
return result;
}
*
* Input: N/A
* Output: { result: bool }
- *
+ *
*/
static char* clear(void *env, struct kr_module *module, const char *args)
{
struct kr_prop *cachectl_props(void)
{
- static struct kr_prop prop_list[] = {
- { &get_size, "size", "Return number of cached records.", },
- { &prune, "prune", "Prune expired/invalid records.", },
- { &clear, "clear", "Clear all cache records.", },
- { NULL, NULL, NULL }
- };
- return prop_list;
+ static struct kr_prop prop_list[] = {
+ { &get_size, "size", "Return number of cached records.", },
+ { &prune, "prune", "Prune expired/invalid records.", },
+ { &clear, "clear", "Clear all cache records.", },
+ { NULL, NULL, NULL }
+ };
+ return prop_list;
}
KR_MODULE_EXPORT(cachectl);
/* TODO: this is an experimental (slow) proof-of-concept,
* this will be rewritten with namedb API
- */
+ */
typedef int (*rr_callback_t)(const knot_rrset_t *, unsigned, struct kr_layer_param *);
knot_rrset_t rr;
knot_rrset_init(&rr, pair->name, qtype, KNOT_CLASS_IN);
struct sockaddr_storage addr;
- sockaddr_set(&addr, addr_type, pair->addr, 0);
+ sockaddr_set(&addr, addr_type, pair->addr, 0);
size_t addr_len = 0;
uint8_t *raw_addr = sockaddr_raw(&addr, &addr_len);
knot_rrset_add_rdata(&rr, raw_addr, addr_len, 0, ¶m->answer->mm);
if (pair->addr == NULL) {
return kr_error(ENOMEM);
}
-
+
strcpy(pair->addr, tok);
add_tail(&map->list, &pair->n);
name_tok = strtok_r(NULL, " \t\n", &saveptr);
const char *global_env;
#define CACHE_SIZE 10 * 4096
-#define CACHE_TTL 2
+#define CACHE_TTL 2
/* Test invalid parameters. */
static void test_invalid(void **state)
memset(&global_context, 0, sizeof(struct kr_context));
global_context.pool = &global_mm;
global_context.modules = &global_modules;
-
+
global_tmpdir = test_tmpdir_create();
assert(global_tmpdir);
global_context.cache = kr_cache_open(global_tmpdir, &global_mm, 100 * 4096);
/* No configuration parsing support yet. */
if (strstr(config, "query-minimization: on") == NULL) {
- global_context.options |= QUERY_NO_MINIMIZE;
+ global_context.options |= QUERY_NO_MINIMIZE;
}
return Py_BuildValue("");
assert_null(kr_rplan_txn_acquire(NULL, 0));
assert_int_equal(kr_rplan_txn_commit(NULL), KNOT_EINVAL);
kr_rplan_deinit(NULL);
-
+
/* NULL mandatory parameters */
struct kr_rplan rplan;