From 456e5446ad420ad3773ac735cb8499d3e8aa2058 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Vavrus=CC=8Ca?= Date: Thu, 17 Dec 2015 18:52:57 +0100 Subject: [PATCH] all: ported to upcoming libknot APIs this is not going to be backwards compatible change, but it will be the first tagged libknot release sufficient for resolver --- contrib/base32hex.c | 207 ++++++++++++++++++++++++++ contrib/base32hex.h | 52 +++++++ contrib/contrib.mk | 3 +- contrib/wire.h | 174 ++++++++++++++++++++++ daemon/bindings.c | 5 +- daemon/engine.c | 15 +- daemon/engine.h | 7 +- daemon/lua/kres.lua | 8 - daemon/main.c | 8 +- daemon/network.c | 1 + daemon/worker.c | 19 ++- daemon/worker.h | 4 +- lib/README.rst | 4 - lib/cache.c | 37 +++-- lib/cache.h | 14 +- lib/dnssec.c | 2 +- lib/dnssec.h | 1 - lib/dnssec/nsec.c | 2 +- lib/dnssec/nsec.h | 5 +- lib/dnssec/nsec3.c | 4 +- lib/dnssec/nsec3.h | 2 - lib/dnssec/packet/pkt.c | 56 ------- lib/dnssec/packet/pkt.h | 27 ---- lib/dnssec/rrtype/ds.h | 50 ------- lib/dnssec/signature.c | 4 +- lib/layer/iterate.c | 3 +- lib/layer/pktcache.c | 4 +- lib/layer/rrcache.c | 12 +- lib/layer/validate.c | 47 +++++- lib/lib.mk | 3 - lib/nsrep.c | 1 - lib/resolve.c | 22 +-- lib/resolve.h | 6 +- lib/rplan.c | 67 +++++---- lib/rplan.h | 20 +-- lib/utils.c | 6 +- lib/utils.h | 24 ++- lib/zonecut.c | 4 +- lib/zonecut.h | 4 +- modules/cachectl/cachectl.c | 23 +-- modules/hints/hints.c | 16 +- modules/kmemcached/kmemcached.c | 4 +- modules/kmemcached/namedb_memcached.c | 38 ++--- modules/redis/namedb_redis.c | 38 ++--- modules/redis/redis.c | 4 +- modules/stats/stats.c | 10 +- scripts/bootstrap-depends.sh | 2 +- tests/test.h | 4 +- tests/test_array.c | 2 +- tests/test_cache.c | 46 +++--- tests/test_pack.c | 2 +- tests/test_rplan.c | 2 +- 52 files changed, 742 insertions(+), 383 deletions(-) create mode 100644 contrib/base32hex.c create mode 100644 contrib/base32hex.h create mode 100644 contrib/wire.h delete mode 100644 lib/dnssec/packet/pkt.c delete mode 100644 lib/dnssec/packet/pkt.h delete mode 100644 lib/dnssec/rrtype/ds.h diff --git a/contrib/base32hex.c b/contrib/base32hex.c new file mode 100644 index 000000000..28701e56f --- /dev/null +++ b/contrib/base32hex.c @@ -0,0 +1,207 @@ +/* Copyright (C) 2011 CZ.NIC, z.s.p.o. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +#include "contrib/base32hex.h" + +#include +#include + +/*! \brief Maximal length of binary input to Base32hex encoding. */ +#define MAX_BIN_DATA_LEN ((INT32_MAX / 8) * 5) + +/*! \brief Base32hex padding character. */ +const uint8_t base32hex_pad = '='; +/*! \brief Base32hex alphabet. */ +const uint8_t base32hex_enc[] = "0123456789ABCDEFGHIJKLMNOPQRSTUV"; + +/*! \brief Indicates bad Base32hex character. */ +#define KO 255 +/*! \brief Indicates Base32hex padding character. */ +#define PD 32 + +/*! \brief Transformation and validation table for decoding Base32hex. */ +const uint8_t base32hex_dec[256] = { + [ 0] = KO, [ 43] = KO, ['V'] = 31, [129] = KO, [172] = KO, [215] = KO, + [ 1] = KO, [ 44] = KO, ['W'] = KO, [130] = KO, [173] = KO, [216] = KO, + [ 2] = KO, [ 45] = KO, ['X'] = KO, [131] = KO, [174] = KO, [217] = KO, + [ 3] = KO, [ 46] = KO, ['Y'] = KO, [132] = KO, [175] = KO, [218] = KO, + [ 4] = KO, [ 47] = KO, ['Z'] = KO, [133] = KO, [176] = KO, [219] = KO, + [ 5] = KO, ['0'] = 0, [ 91] = KO, [134] = KO, [177] = KO, [220] = KO, + [ 6] = KO, ['1'] = 1, [ 92] = KO, [135] = KO, [178] = KO, [221] = KO, + [ 7] = KO, ['2'] = 2, [ 93] = KO, [136] = KO, [179] = KO, [222] = KO, + [ 8] = KO, ['3'] = 3, [ 94] = KO, [137] = KO, [180] = KO, [223] = KO, + [ 9] = KO, ['4'] = 4, [ 95] = KO, [138] = KO, [181] = KO, [224] = KO, + [ 10] = KO, ['5'] = 5, [ 96] = KO, [139] = KO, [182] = KO, [225] = KO, + [ 11] = KO, ['6'] = 6, ['a'] = 10, [140] = KO, [183] = KO, [226] = KO, + [ 12] = KO, ['7'] = 7, ['b'] = 11, [141] = KO, [184] = KO, [227] = KO, + [ 13] = KO, ['8'] = 8, ['c'] = 12, [142] = KO, [185] = KO, [228] = KO, + [ 14] = KO, ['9'] = 9, ['d'] = 13, [143] = KO, [186] = KO, [229] = KO, + [ 15] = KO, [ 58] = KO, ['e'] = 14, [144] = KO, [187] = KO, [230] = KO, + [ 16] = KO, [ 59] = KO, ['f'] = 15, [145] = KO, [188] = KO, [231] = KO, + [ 17] = KO, [ 60] = KO, ['g'] = 16, [146] = KO, [189] = KO, [232] = KO, + [ 18] = KO, ['='] = PD, ['h'] = 17, [147] = KO, [190] = KO, [233] = KO, + [ 19] = KO, [ 62] = KO, ['i'] = 18, [148] = KO, [191] = KO, [234] = KO, + [ 20] = KO, [ 63] = KO, ['j'] = 19, [149] = KO, [192] = KO, [235] = KO, + [ 21] = KO, [ 64] = KO, ['k'] = 20, [150] = KO, [193] = KO, [236] = KO, + [ 22] = KO, ['A'] = 10, ['l'] = 21, [151] = KO, [194] = KO, [237] = KO, + [ 23] = KO, ['B'] = 11, ['m'] = 22, [152] = KO, [195] = KO, [238] = KO, + [ 24] = KO, ['C'] = 12, ['n'] = 23, [153] = KO, [196] = KO, [239] = KO, + [ 25] = KO, ['D'] = 13, ['o'] = 24, [154] = KO, [197] = KO, [240] = KO, + [ 26] = KO, ['E'] = 14, ['p'] = 25, [155] = KO, [198] = KO, [241] = KO, + [ 27] = KO, ['F'] = 15, ['q'] = 26, [156] = KO, [199] = KO, [242] = KO, + [ 28] = KO, ['G'] = 16, ['r'] = 27, [157] = KO, [200] = KO, [243] = KO, + [ 29] = KO, ['H'] = 17, ['s'] = 28, [158] = KO, [201] = KO, [244] = KO, + [ 30] = KO, ['I'] = 18, ['t'] = 29, [159] = KO, [202] = KO, [245] = KO, + [ 31] = KO, ['J'] = 19, ['u'] = 30, [160] = KO, [203] = KO, [246] = KO, + [ 32] = KO, ['K'] = 20, ['v'] = 31, [161] = KO, [204] = KO, [247] = KO, + [ 33] = KO, ['L'] = 21, ['w'] = KO, [162] = KO, [205] = KO, [248] = KO, + [ 34] = KO, ['M'] = 22, ['x'] = KO, [163] = KO, [206] = KO, [249] = KO, + [ 35] = KO, ['N'] = 23, ['y'] = KO, [164] = KO, [207] = KO, [250] = KO, + [ 36] = KO, ['O'] = 24, ['z'] = KO, [165] = KO, [208] = KO, [251] = KO, + [ 37] = KO, ['P'] = 25, [123] = KO, [166] = KO, [209] = KO, [252] = KO, + [ 38] = KO, ['Q'] = 26, [124] = KO, [167] = KO, [210] = KO, [253] = KO, + [ 39] = KO, ['R'] = 27, [125] = KO, [168] = KO, [211] = KO, [254] = KO, + [ 40] = KO, ['S'] = 28, [126] = KO, [169] = KO, [212] = KO, [255] = KO, + [ 41] = KO, ['T'] = 29, [127] = KO, [170] = KO, [213] = KO, + [ 42] = KO, ['U'] = 30, [128] = KO, [171] = KO, [214] = KO, +}; + +int32_t base32hex_decode(const uint8_t *in, + const uint32_t in_len, + uint8_t *out, + const uint32_t out_len) +{ + // Checking inputs. + if (in == NULL || out == NULL) { + return -1; + } + if (in_len > INT32_MAX || out_len < ((in_len + 7) / 8) * 5) { + return -1; + } + if ((in_len % 8) != 0) { + return -1; + } + + const uint8_t *stop = in + in_len; + uint8_t *bin = out; + uint8_t pad_len = 0; + uint8_t c1, c2, c3, c4, c5, c6, c7, c8; + + // Decoding loop takes 8 characters and creates 5 bytes. + while (in < stop) { + // Filling and transforming 8 Base32hex chars. + c1 = base32hex_dec[in[0]]; + c2 = base32hex_dec[in[1]]; + c3 = base32hex_dec[in[2]]; + c4 = base32hex_dec[in[3]]; + c5 = base32hex_dec[in[4]]; + c6 = base32hex_dec[in[5]]; + c7 = base32hex_dec[in[6]]; + c8 = base32hex_dec[in[7]]; + + // Check 8. char if is bad or padding. + if (c8 >= PD) { + if (c8 == PD && pad_len == 0) { + pad_len = 1; + } else { + return -1; + } + } + + // Check 7. char if is bad or padding (if so, 6. must be too). + if (c7 >= PD) { + if (c7 == PD && c6 == PD && pad_len == 1) { + pad_len = 3; + } else { + return -1; + } + } + + // Check 6. char if is bad or padding. + if (c6 >= PD) { + if (!(c6 == PD && pad_len == 3)) { + return -1; + } + } + + // Check 5. char if is bad or padding. + if (c5 >= PD) { + if (c5 == PD && pad_len == 3) { + pad_len = 4; + } else { + return -1; + } + } + + // Check 4. char if is bad or padding (if so, 3. must be too). + if (c4 >= PD) { + if (c4 == PD && c3 == PD && pad_len == 4) { + pad_len = 6; + } else { + return -1; + } + } + + // Check 3. char if is bad or padding. + if (c3 >= PD) { + if (!(c3 == PD && pad_len == 6)) { + return -1; + } + } + + // 1. and 2. chars must not be padding. + if (c2 >= PD || c1 >= PD) { + return -1; + } + + // Computing of output data based on padding length. + switch (pad_len) { + case 0: + bin[4] = (c7 << 5) + c8; + case 1: + bin[3] = (c5 << 7) + (c6 << 2) + (c7 >> 3); + case 3: + bin[2] = (c4 << 4) + (c5 >> 1); + case 4: + bin[1] = (c2 << 6) + (c3 << 1) + (c4 >> 4); + case 6: + bin[0] = (c1 << 3) + (c2 >> 2); + } + + // Update output end. + switch (pad_len) { + case 0: + bin += 5; + break; + case 1: + bin += 4; + break; + case 3: + bin += 3; + break; + case 4: + bin += 2; + break; + case 6: + bin += 1; + break; + } + + in += 8; + } + + return (bin - out); +} diff --git a/contrib/base32hex.h b/contrib/base32hex.h new file mode 100644 index 000000000..404b981a8 --- /dev/null +++ b/contrib/base32hex.h @@ -0,0 +1,52 @@ +/* Copyright (C) 2011 CZ.NIC, z.s.p.o. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +/*! + * \file + * + * \brief Base32hex implementation (RFC 4648). + * + * \note Input Base32hex string can contain a-v characters. These characters + * are considered as A-V equivalent. + * + * \addtogroup contrib + * @{ + */ + +#pragma once + +#include + +/*! + * \brief Decodes text data using Base32hex. + * + * \note Input data needn't be terminated with '\0'. + * + * \note Input data must be continuous Base32hex string! + * + * \param in Input text data. + * \param in_len Length of input string. + * \param out Output data buffer. + * \param out_len Size of output buffer. + * + * \retval >=0 length of output data. + * \retval KNOT_E* if error. + */ +int32_t base32hex_decode(const uint8_t *in, + const uint32_t in_len, + uint8_t *out, + const uint32_t out_len); + +/*! @} */ diff --git a/contrib/contrib.mk b/contrib/contrib.mk index 3daf43df5..5d924734a 100644 --- a/contrib/contrib.mk +++ b/contrib/contrib.mk @@ -4,7 +4,8 @@ contrib_SOURCES := \ contrib/ccan/isaac/isaac.c \ contrib/ccan/json/json.c \ contrib/ucw/mempool.c \ - contrib/murmurhash3/murmurhash3.c + contrib/murmurhash3/murmurhash3.c \ + contrib/base32hex.c contrib_CFLAGS := -fPIC contrib_TARGET := $(abspath contrib)/contrib$(AREXT) $(eval $(call make_static,contrib,contrib)) diff --git a/contrib/wire.h b/contrib/wire.h new file mode 100644 index 000000000..7a367cd17 --- /dev/null +++ b/contrib/wire.h @@ -0,0 +1,174 @@ +/* Copyright (C) 2011 CZ.NIC, z.s.p.o. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +/*! + * \file + * + * \brief Wire integer operations. + * + * \addtogroup contrib + * @{ + */ + +#pragma once + +#include +#include + +#if defined(__linux__) +# include +# ifndef be64toh +# include +# include +# if BYTE_ORDER == LITTLE_ENDIAN +# define be16toh(x) ntohs(x) +# define be32toh(x) ntohl(x) +# define be64toh(x) bswap_64 (x) +# define le16toh(x) (x) +# define le32toh(x) (x) +# define le64toh(x) (x) +# else +# define be16toh(x) (x) +# define be32toh(x) (x) +# define be64toh(x) (x) +# define le16toh(x) ntohs(x) +# define le32toh(x) ntohl(x) +# define le64toh(x) bswap_64 (x) +# endif +# endif +#elif defined(__FreeBSD__) || defined(__NetBSD__) +# include +#elif defined(__OpenBSD__) +# include +#elif defined(__APPLE__) +# include +# define be16toh(x) OSSwapBigToHostInt16(x) +# define be32toh(x) OSSwapBigToHostInt32(x) +# define be64toh(x) OSSwapBigToHostInt64(x) +# define htobe16(x) OSSwapHostToBigInt16(x) +# define htobe32(x) OSSwapHostToBigInt32(x) +# define htobe64(x) OSSwapHostToBigInt64(x) +# define le16toh(x) OSSwapLittleToHostInt16(x) +# define le32toh(x) OSSwapLittleToHostInt32(x) +# define le64toh(x) OSSwapLittleToHostInt64(x) +# define htole16(x) OSSwapHostToLittleInt16(x) +# define htole32(x) OSSwapHostToLittleInt32(x) +# define htole64(x) OSSwapHostToLittleInt64(x) +#endif + +/*! + * \brief Reads 2 bytes from the wireformat data. + * + * \param pos Data to read the 2 bytes from. + * + * \return The 2 bytes read, in host byte order. + */ +inline static uint16_t wire_read_u16(const uint8_t *pos) +{ + return be16toh(*(uint16_t *)pos); +} + +/*! + * \brief Reads 4 bytes from the wireformat data. + * + * \param pos Data to read the 4 bytes from. + * + * \return The 4 bytes read, in host byte order. + */ +inline static uint32_t wire_read_u32(const uint8_t *pos) +{ + return be32toh(*(uint32_t *)pos); +} + +/*! + * \brief Reads 6 bytes from the wireformat data. + * + * \param pos Data to read the 6 bytes from. + * + * \return The 6 bytes read, in host byte order. + */ +inline static uint64_t wire_read_u48(const uint8_t *pos) +{ + uint64_t input = 0; + memcpy((uint8_t *)&input + 1, pos, 6); + return be64toh(input) >> 8; +} + +/*! + * \brief Read 8 bytes from the wireformat data. + * + * \param pos Data to read the 8 bytes from. + * + * \return The 8 bytes read, in host byte order. + */ +inline static uint64_t wire_read_u64(const uint8_t *pos) +{ + return be64toh(*(uint64_t *)pos); +} + +/*! + * \brief Writes 2 bytes in wireformat. + * + * The data are stored in network byte order (big endian). + * + * \param pos Position where to put the 2 bytes. + * \param data Data to put. + */ +inline static void wire_write_u16(uint8_t *pos, uint16_t data) +{ + *(uint16_t *)pos = htobe16(data); +} + +/*! + * \brief Writes 4 bytes in wireformat. + * + * The data are stored in network byte order (big endian). + * + * \param pos Position where to put the 4 bytes. + * \param data Data to put. + */ +inline static void wire_write_u32(uint8_t *pos, uint32_t data) +{ + *(uint32_t *)pos = htobe32(data); +} + +/*! + * \brief Writes 6 bytes in wireformat. + * + * The data are stored in network byte order (big endian). + * + * \param pos Position where to put the 4 bytes. + * \param data Data to put. + */ +inline static void wire_write_u48(uint8_t *pos, uint64_t data) +{ + uint64_t swapped = htobe64(data << 8); + memcpy(pos, (uint8_t *)&swapped + 1, 6); +} + +/*! + * \brief Writes 8 bytes in wireformat. + * + * The data are stored in network byte order (big endian). + * + * \param pos Position where to put the 8 bytes. + * \param data Data to put. + */ +inline static void wire_write_u64(uint8_t *pos, uint64_t data) +{ + *(uint64_t *)pos = htobe64(data); +} + +/*! @} */ diff --git a/daemon/bindings.c b/daemon/bindings.c index e97230c91..0c62422c3 100644 --- a/daemon/bindings.c +++ b/daemon/bindings.c @@ -14,6 +14,7 @@ along with this program. If not, see . */ +#include #include #include #include @@ -334,11 +335,11 @@ static int cache_backends(lua_State *L) static int cache_count(lua_State *L) { struct engine *engine = engine_luaget(L); - const namedb_api_t *storage = engine->resolver.cache.api; + const knot_db_api_t *storage = engine->resolver.cache.api; /* Fetch item count */ struct kr_cache_txn txn; - int ret = kr_cache_txn_begin(&engine->resolver.cache, &txn, NAMEDB_RDONLY); + int ret = kr_cache_txn_begin(&engine->resolver.cache, &txn, KNOT_DB_RDONLY); if (ret != 0) { format_error(L, kr_strerror(ret)); lua_error(L); diff --git a/daemon/engine.c b/daemon/engine.c index fcdca1aad..ba996149d 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -21,9 +21,8 @@ #include #include #include -#include -/* #include @todo Not supported (doesn't keep value copy) */ -#include +/* #include @todo Not supported (doesn't keep value copy) */ +#include #include "daemon/engine.h" #include "daemon/bindings.h" @@ -177,7 +176,7 @@ static int l_option(lua_State *L) unsigned opt_code = 0; if (lua_isstring(L, 1)) { const char *opt = lua_tostring(L, 1); - for (const lookup_table_t *it = kr_query_flag_names(); it->name; ++it) { + for (const knot_lookup_t *it = kr_query_flag_names(); it->name; ++it) { if (strcmp(it->name, opt) == 0) { opt_code = it->id; break; @@ -320,9 +319,9 @@ static int l_trampoline(lua_State *L) */ /** @internal Make lmdb options. */ -void *namedb_lmdb_mkopts(const char *conf, size_t maxsize) +void *knot_db_lmdb_mkopts(const char *conf, size_t maxsize) { - struct namedb_lmdb_opts *opts = malloc(sizeof(*opts)); + struct knot_db_lmdb_opts *opts = malloc(sizeof(*opts)); if (opts) { memset(opts, 0, sizeof(*opts)); opts->path = (conf && strlen(conf)) ? conf : "."; @@ -366,7 +365,7 @@ static int init_resolver(struct engine *engine) /* Initialize storage backends */ struct storage_api lmdb = { - "lmdb://", namedb_lmdb_api, namedb_lmdb_mkopts + "lmdb://", knot_db_lmdb_api, knot_db_lmdb_mkopts }; return array_push(engine->storage_registry, lmdb); @@ -406,7 +405,7 @@ static int init_state(struct engine *engine) return kr_ok(); } -int engine_init(struct engine *engine, mm_ctx_t *pool) +int engine_init(struct engine *engine, knot_mm_t *pool) { if (engine == NULL) { return kr_error(EINVAL); diff --git a/daemon/engine.h b/daemon/engine.h index 0b32dfd80..d9755157b 100644 --- a/daemon/engine.h +++ b/daemon/engine.h @@ -35,13 +35,14 @@ */ struct lua_State; +#include "lib/utils.h" #include "lib/resolve.h" #include "daemon/network.h" /** Cache storage backend. */ struct storage_api { const char *prefix; /**< Storage prefix, e.g. 'lmdb://' */ - const namedb_api_t *(*api)(void); /**< Storage API implementation */ + const knot_db_api_t *(*api)(void); /**< Storage API implementation */ void *(*opts_create)(const char *, size_t); /**< Storage options factory */ }; @@ -53,11 +54,11 @@ struct engine { struct network net; module_array_t modules; storage_registry_t storage_registry; - mm_ctx_t *pool; + knot_mm_t *pool; struct lua_State *L; }; -int engine_init(struct engine *engine, mm_ctx_t *pool); +int engine_init(struct engine *engine, knot_mm_t *pool); void engine_deinit(struct engine *engine); /** @warning This function leaves 1 string result on stack. */ int engine_cmd(struct engine *engine, const char *str); diff --git a/daemon/lua/kres.lua b/daemon/lua/kres.lua index 0834b65d7..b73ee2094 100644 --- a/daemon/lua/kres.lua +++ b/daemon/lua/kres.lua @@ -118,9 +118,6 @@ struct sockaddr { /* libknot */ typedef int knot_section_t; /* Do not touch */ typedef void knot_rrinfo_t; /* Do not touch */ -typedef struct node { - struct node *next, *prev; -} node_t; typedef uint8_t knot_dname_t; typedef uint8_t knot_rdata_t; typedef struct knot_rdataset { @@ -174,7 +171,6 @@ typedef struct { size_t cap; } rr_array_t; struct kr_query { - node_t _node; struct kr_query *parent; knot_dname_t *sname; uint16_t type; @@ -353,10 +349,6 @@ local kr_query_t = ffi.typeof('struct kr_query') ffi.metatype( kr_query_t, { __index = { name = function(qry, new_name) return ffi.string(qry.sname, knot.knot_dname_size(qry.sname)) end, - next = function(qry) - assert(qry) - return C.kr_rplan_next(qry) - end, resolved = function(qry) return band(qry.flags, kres.query.RESOLVED) ~= 0 end, diff --git a/daemon/main.c b/daemon/main.c index 62375a40e..4eda21ac8 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -18,9 +18,11 @@ #include #include #include +#include #include #include #include +#include #include "lib/defines.h" #include "lib/resolve.h" @@ -141,7 +143,7 @@ static void help(int argc, char *argv[]) " [rundir] Path to the working directory (default: .)\n"); } -static struct worker_ctx *init_worker(uv_loop_t *loop, struct engine *engine, mm_ctx_t *pool, int worker_id, int worker_count) +static struct worker_ctx *init_worker(uv_loop_t *loop, struct engine *engine, knot_mm_t *pool, int worker_id, int worker_count) { /* Load bindings */ engine_lualib(engine, "modules", lib_modules); @@ -333,9 +335,9 @@ int main(int argc, char **argv) uv_signal_start(&sigint, signal_handler, SIGINT); uv_signal_start(&sigterm, signal_handler, SIGTERM); /* Create a server engine. */ - mm_ctx_t pool = { + knot_mm_t pool = { .ctx = mp_new (4096), - .alloc = (mm_alloc_t) mp_alloc + .alloc = (knot_mm_alloc_t) mp_alloc }; struct engine engine; ret = engine_init(&engine, &pool); diff --git a/daemon/network.c b/daemon/network.c index 103823dc6..ace172595 100644 --- a/daemon/network.c +++ b/daemon/network.c @@ -14,6 +14,7 @@ along with this program. If not, see . */ +#include #include "daemon/network.h" #include "daemon/worker.h" #include "daemon/io.h" diff --git a/daemon/worker.c b/daemon/worker.c index b05643a27..34d1f003c 100644 --- a/daemon/worker.c +++ b/daemon/worker.c @@ -20,10 +20,12 @@ #include #include #include +#include #if defined(__GLIBC__) && defined(_GNU_SOURCE) #include #endif - +#include +#include "lib/utils.h" #include "daemon/worker.h" #include "daemon/engine.h" #include "daemon/io.h" @@ -227,9 +229,9 @@ static struct qr_task *qr_task_create(struct worker_ctx *worker, uv_handle_t *ha } /* Recycle available mempool if possible */ - mm_ctx_t pool = { + knot_mm_t pool = { .ctx = pool_take(worker), - .alloc = (mm_alloc_t) mp_alloc + .alloc = (knot_mm_alloc_t) mp_alloc }; /* Create resolution task */ @@ -265,7 +267,10 @@ static struct qr_task *qr_task_create(struct worker_ctx *worker, uv_handle_t *ha task->on_complete = NULL; /* Remember query source addr */ if (addr) { - memcpy(&task->source.addr, addr, sockaddr_len(addr)); + size_t addr_len = sizeof(struct sockaddr_in); + if (addr->sa_family == AF_INET6) + addr_len = sizeof(struct sockaddr_in6); + memcpy(&task->source.addr, addr, addr_len); task->req.qsource.addr = (const struct sockaddr *)&task->source.addr; } else { task->source.addr.ip4.sin_family = AF_UNSPEC; @@ -505,10 +510,10 @@ static void subreq_finalize(struct qr_task *task, const struct sockaddr *packet_ map_del(&task->worker->outstanding, key); } /* Notify waiting tasks. */ - struct kr_query *leader_qry = TAIL(task->req.rplan.pending); + struct kr_query *leader_qry = array_tail(task->req.rplan.pending); for (size_t i = task->waiting.len; i --> 0;) { struct qr_task *follower = task->waiting.at[i]; - struct kr_query *qry = TAIL(follower->req.rplan.pending); + struct kr_query *qry = array_tail(follower->req.rplan.pending); /* Reuse MSGID and 0x20 secret */ if (qry) { qry->id = leader_qry->id; @@ -773,7 +778,7 @@ int worker_reserve(struct worker_ctx *worker, size_t ring_maxlen) return kr_error(ENOMEM); memset(&worker->pkt_pool, 0, sizeof(worker->pkt_pool)); worker->pkt_pool.ctx = mp_new (4 * sizeof(knot_pkt_t)); - worker->pkt_pool.alloc = (mm_alloc_t) mp_alloc; + worker->pkt_pool.alloc = (knot_mm_alloc_t) mp_alloc; worker->outstanding = map_make(); return kr_ok(); } diff --git a/daemon/worker.h b/daemon/worker.h index 00a67a56b..eed855d82 100644 --- a/daemon/worker.h +++ b/daemon/worker.h @@ -16,8 +16,6 @@ #pragma once -#include - #include "daemon/engine.h" #include "lib/generic/array.h" #include "lib/generic/map.h" @@ -52,7 +50,7 @@ struct worker_ctx { map_t outstanding; mp_freelist_t pools; mp_freelist_t ioreqs; - mm_ctx_t pkt_pool; + knot_mm_t pkt_pool; }; /* Worker callback */ diff --git a/lib/README.rst b/lib/README.rst index 56b94dc27..ac0d5e94a 100644 --- a/lib/README.rst +++ b/lib/README.rst @@ -259,10 +259,6 @@ In layers that either begin or finalize, you can walk the list of resolved queri local last = req:resolved() print(last.type) - last = last:next() - if last ~= nil then - print(last.type) - end As described in the layers, you can not only retrieve information about current query, but also push new ones or pop old ones. diff --git a/lib/cache.c b/lib/cache.c index 50347f722..f9c9b62d3 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -20,8 +20,7 @@ #include #include -#include -#include +#include #include #include #include @@ -48,8 +47,8 @@ static void assert_right_version(struct kr_cache *cache) if (ret != 0) { return; /* N/A, doesn't work. */ } - namedb_val_t key = { KEY_VERSION, 2 }; - namedb_val_t val = { NULL, 0 }; + knot_db_val_t key = { KEY_VERSION, 2 }; + knot_db_val_t val = { NULL, 0 }; ret = txn_api(&txn)->find(&txn.t, &key, &val, 0); if (ret == 0) { /* Version is OK */ kr_cache_txn_abort(&txn); @@ -70,13 +69,13 @@ static void assert_right_version(struct kr_cache *cache) } } -int kr_cache_open(struct kr_cache *cache, const namedb_api_t *api, void *opts, mm_ctx_t *mm) +int kr_cache_open(struct kr_cache *cache, const knot_db_api_t *api, void *opts, knot_mm_t *mm) { if (!cache) { return kr_error(EINVAL); } /* Open cache */ - cache->api = (api == NULL) ? namedb_lmdb_api() : api; + cache->api = (api == NULL) ? knot_db_lmdb_api() : api; int ret = cache->api->init(&cache->db, mm, opts); if (ret != 0) { return ret; @@ -109,7 +108,7 @@ int kr_cache_txn_begin(struct kr_cache *cache, struct kr_cache_txn *txn, unsigne } else { /* Count statistics */ txn->owner = cache; - if (flags & NAMEDB_RDONLY) { + if (flags & KNOT_DB_RDONLY) { cache->stats.txn_read += 1; } else { cache->stats.txn_write += 1; @@ -166,8 +165,8 @@ static struct kr_cache_entry *lookup(struct kr_cache_txn *txn, uint8_t tag, cons } /* Look up and return value */ - namedb_val_t key = { keybuf, key_len }; - namedb_val_t val = { NULL, 0 }; + knot_db_val_t key = { keybuf, key_len }; + knot_db_val_t val = { NULL, 0 }; int ret = txn_api(txn)->find(&txn->t, &key, &val, 0); if (ret != KNOT_EOK) { return NULL; @@ -220,7 +219,7 @@ int kr_cache_peek(struct kr_cache_txn *txn, uint8_t tag, const knot_dname_t *nam return ret; } -static void entry_write(struct kr_cache_entry *dst, struct kr_cache_entry *header, namedb_val_t data) +static void entry_write(struct kr_cache_entry *dst, struct kr_cache_entry *header, knot_db_val_t data) { assert(dst && header); memcpy(dst, header, sizeof(*header)); @@ -229,7 +228,7 @@ static void entry_write(struct kr_cache_entry *dst, struct kr_cache_entry *heade } int kr_cache_insert(struct kr_cache_txn *txn, uint8_t tag, const knot_dname_t *name, uint16_t type, - struct kr_cache_entry *header, namedb_val_t data) + struct kr_cache_entry *header, knot_db_val_t data) { if (!txn_is_valid(txn) || !name || !header) { return kr_error(EINVAL); @@ -241,13 +240,13 @@ int kr_cache_insert(struct kr_cache_txn *txn, uint8_t tag, const knot_dname_t *n if (key_len == 0) { return kr_error(EILSEQ); } - namedb_val_t key = { keybuf, key_len }; - namedb_val_t entry = { NULL, sizeof(*header) + data.len }; - const namedb_api_t *db_api = txn_api(txn); + knot_db_val_t key = { keybuf, key_len }; + knot_db_val_t entry = { NULL, sizeof(*header) + data.len }; + const knot_db_api_t *db_api = txn_api(txn); /* LMDB can do late write and avoid copy */ txn->owner->stats.insert += 1; - if (db_api == namedb_lmdb_api()) { + if (db_api == knot_db_lmdb_api()) { int ret = db_api->insert(&txn->t, &key, &entry, 0); if (ret != 0) { return ret; @@ -281,7 +280,7 @@ int kr_cache_remove(struct kr_cache_txn *txn, uint8_t tag, const knot_dname_t *n if (key_len == 0) { return kr_error(EILSEQ); } - namedb_val_t key = { keybuf, key_len }; + knot_db_val_t key = { keybuf, key_len }; txn->owner->stats.delete += 1; return txn_api(txn)->del(&txn->t, &key); } @@ -331,7 +330,7 @@ int kr_cache_peek_rank(struct kr_cache_txn *txn, uint8_t tag, const knot_dname_t return found->rank; } -int kr_cache_materialize(knot_rrset_t *dst, const knot_rrset_t *src, uint32_t drift, mm_ctx_t *mm) +int kr_cache_materialize(knot_rrset_t *dst, const knot_rrset_t *src, uint32_t drift, knot_mm_t *mm) { if (!dst || !src) { return kr_error(EINVAL); @@ -391,7 +390,7 @@ int kr_cache_insert_rr(struct kr_cache_txn *txn, const knot_rrset_t *rr, uint16_ rd = kr_rdataset_next(rd); } - namedb_val_t data = { rr->rrs.data, knot_rdataset_size(&rr->rrs) }; + knot_db_val_t data = { rr->rrs.data, knot_rdataset_size(&rr->rrs) }; return kr_cache_insert(txn, KR_CACHE_RR, rr->owner, rr->type, &header, data); } @@ -443,6 +442,6 @@ int kr_cache_insert_rrsig(struct kr_cache_txn *txn, const knot_rrset_t *rr, uint } uint16_t covered = knot_rrsig_type_covered(&rr->rrs, 0); - namedb_val_t data = { rr->rrs.data, knot_rdataset_size(&rr->rrs) }; + knot_db_val_t data = { rr->rrs.data, knot_rdataset_size(&rr->rrs) }; return kr_cache_insert(txn, KR_CACHE_SIG, rr->owner, covered, &header, data); } diff --git a/lib/cache.h b/lib/cache.h index 3fabea7ce..89ce695f9 100644 --- a/lib/cache.h +++ b/lib/cache.h @@ -17,7 +17,7 @@ #pragma once #include -#include +#include #include "lib/defines.h" /** Cache entry tag */ @@ -61,8 +61,8 @@ struct kr_cache_entry */ struct kr_cache { - namedb_t *db; /**< Storage instance */ - const namedb_api_t *api; /**< Storage engine */ + knot_db_t *db; /**< Storage instance */ + const knot_db_api_t *api; /**< Storage engine */ struct { uint32_t hit; /**< Number of cache hits */ uint32_t miss; /**< Number of cache misses */ @@ -75,7 +75,7 @@ struct kr_cache /** Cache transaction */ struct kr_cache_txn { - namedb_txn_t t; /**< Storage transaction */ + knot_db_txn_t t; /**< Storage transaction */ struct kr_cache *owner; /**< Transaction owner */ }; @@ -88,7 +88,7 @@ struct kr_cache_txn { * @return 0 or an error code */ KR_EXPORT -int kr_cache_open(struct kr_cache *cache, const namedb_api_t *api, void *opts, mm_ctx_t *mm); +int kr_cache_open(struct kr_cache *cache, const knot_db_api_t *api, void *opts, knot_mm_t *mm); /** * Close persistent cache. @@ -153,7 +153,7 @@ int kr_cache_peek(struct kr_cache_txn *txn, uint8_t tag, const knot_dname_t *nam */ KR_EXPORT int kr_cache_insert(struct kr_cache_txn *txn, uint8_t tag, const knot_dname_t *name, uint16_t type, - struct kr_cache_entry *header, namedb_val_t data); + struct kr_cache_entry *header, knot_db_val_t data); /** * Remove asset from cache. @@ -207,7 +207,7 @@ int kr_cache_peek_rr(struct kr_cache_txn *txn, knot_rrset_t *rr, uint16_t *rank, * @return 0 or an errcode */ KR_EXPORT -int kr_cache_materialize(knot_rrset_t *dst, const knot_rrset_t *src, uint32_t drift, mm_ctx_t *mm); +int kr_cache_materialize(knot_rrset_t *dst, const knot_rrset_t *src, uint32_t drift, knot_mm_t *mm); /** * Insert RRSet into cache, replacing any existing data. diff --git a/lib/dnssec.c b/lib/dnssec.c index 1577aaab2..91680adbf 100644 --- a/lib/dnssec.c +++ b/lib/dnssec.c @@ -27,7 +27,7 @@ #include #include #include - +#include #include "lib/defines.h" #include "lib/dnssec/nsec.h" diff --git a/lib/dnssec.h b/lib/dnssec.h index 82ea7bccf..b6d41df96 100644 --- a/lib/dnssec.h +++ b/lib/dnssec.h @@ -17,7 +17,6 @@ #pragma once #include "lib/defines.h" -#include #include /** diff --git a/lib/dnssec/nsec.c b/lib/dnssec/nsec.c index 7106a968e..a9a053236 100644 --- a/lib/dnssec/nsec.c +++ b/lib/dnssec/nsec.c @@ -138,7 +138,7 @@ static int name_error_response_check_rr(int *flags, const knot_rrset_t *nsec, } int kr_nsec_name_error_response_check(const knot_pkt_t *pkt, knot_section_t section_id, - const knot_dname_t *sname, mm_ctx_t *pool) + const knot_dname_t *sname) { const knot_pktsection_t *sec = knot_pkt_section(pkt, section_id); if (!sec || !sname) { diff --git a/lib/dnssec/nsec.h b/lib/dnssec/nsec.h index 41bdc1a74..21ac6e4d3 100644 --- a/lib/dnssec/nsec.h +++ b/lib/dnssec/nsec.h @@ -16,8 +16,6 @@ #pragma once -#include -#include #include /** @@ -35,11 +33,10 @@ bool kr_nsec_bitmap_contains_type(const uint8_t *bm, uint16_t bm_size, uint16_t * @param pkt Packet structure to be processed. * @param section_id Packet section to be processed. * @param sname Name to be checked. - * @param pool * @return 0 or error code. */ int kr_nsec_name_error_response_check(const knot_pkt_t *pkt, knot_section_t section_id, - const knot_dname_t *sname, mm_ctx_t *pool); + const knot_dname_t *sname); /** * No data response check (RFC4035 3.1.3.1; RFC4035 5.4, bullet 1). diff --git a/lib/dnssec/nsec3.c b/lib/dnssec/nsec3.c index dcfa4053e..a0b22d46d 100644 --- a/lib/dnssec/nsec3.c +++ b/lib/dnssec/nsec3.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include @@ -107,7 +107,7 @@ static int read_owner_hash(dnssec_binary_t *hash, size_t max_hash_size, const kn int32_t ret = base32hex_decode(nsec3->owner + 1, nsec3->owner[0], hash->data, max_hash_size); if (ret < 0) { - return ret; + return kr_error(EILSEQ); } hash->size = ret; diff --git a/lib/dnssec/nsec3.h b/lib/dnssec/nsec3.h index b4a50405c..50e27e431 100644 --- a/lib/dnssec/nsec3.h +++ b/lib/dnssec/nsec3.h @@ -16,8 +16,6 @@ #pragma once -#include -#include #include /** diff --git a/lib/dnssec/packet/pkt.c b/lib/dnssec/packet/pkt.c deleted file mode 100644 index 91088aba1..000000000 --- a/lib/dnssec/packet/pkt.c +++ /dev/null @@ -1,56 +0,0 @@ -/* Copyright (C) 2015 CZ.NIC, z.s.p.o. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ - -#include - -#include "lib/dnssec/packet/pkt.h" - -/** - * Search in section for given type. - * @param sec Packet section. - * @param type Type to search for. - * @return True if found. - */ -static bool section_has_type(const knot_pktsection_t *sec, uint16_t type) -{ - if (!sec) { - return false; - } - - for (unsigned i = 0; i < sec->count; ++i) { - const knot_rrset_t *rr = knot_pkt_rr(sec, i); - if (rr->type == type) { - return true; - } - } - - return false; -} - -bool _knot_pkt_has_type(const knot_pkt_t *pkt, uint16_t type) -{ - if (!pkt) { - return false; - } - - if (section_has_type(knot_pkt_section(pkt, KNOT_ANSWER), type)) { - return true; - } - if (section_has_type(knot_pkt_section(pkt, KNOT_AUTHORITY), type)) { - return true; - } - return section_has_type(knot_pkt_section(pkt, KNOT_ADDITIONAL), type); -} diff --git a/lib/dnssec/packet/pkt.h b/lib/dnssec/packet/pkt.h deleted file mode 100644 index 429ad0fb8..000000000 --- a/lib/dnssec/packet/pkt.h +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright (C) 2015 CZ.NIC, z.s.p.o. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ - -#pragma once - -#include - -/** - * Check whether packet contains given type. - * @param pkt Packet to seek through. - * @param type RR type to search for. - * @return True if found. - */ -bool _knot_pkt_has_type(const knot_pkt_t *pkt, uint16_t type); diff --git a/lib/dnssec/rrtype/ds.h b/lib/dnssec/rrtype/ds.h deleted file mode 100644 index 32e131c31..000000000 --- a/lib/dnssec/rrtype/ds.h +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (C) 2015 CZ.NIC, z.s.p.o. - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ - -#pragma once - -#include - -static inline -uint16_t _knot_ds_ktag(const knot_rdataset_t *rrs, size_t pos) -{ - KNOT_RDATASET_CHECK(rrs, pos, return 0); - return wire_read_u16(knot_rdata_offset(rrs, pos, 0)); -} - -static inline -uint8_t _knot_ds_alg(const knot_rdataset_t *rrs, size_t pos) -{ - KNOT_RDATASET_CHECK(rrs, pos, return 0); - return *knot_rdata_offset(rrs, pos, 2); -} - -static inline -uint8_t _knot_ds_dtype(const knot_rdataset_t *rrs, size_t pos) -{ - KNOT_RDATASET_CHECK(rrs, pos, return 0); - return *knot_rdata_offset(rrs, pos, 3); -} - -static inline -void _knot_ds_digest(const knot_rdataset_t *rrs, size_t pos, - uint8_t **digest, uint16_t *digest_size) -{ - KNOT_RDATASET_CHECK(rrs, pos, return); - *digest = knot_rdata_offset(rrs, pos, 4); - const knot_rdata_t *rr = knot_rdataset_at(rrs, pos); - *digest_size = knot_rdata_rdlen(rr) - 4; -} diff --git a/lib/dnssec/signature.c b/lib/dnssec/signature.c index 1570ab855..27e7eeefb 100644 --- a/lib/dnssec/signature.c +++ b/lib/dnssec/signature.c @@ -26,10 +26,10 @@ #include #include #include +#include #include "lib/defines.h" #include "lib/utils.h" -#include "lib/dnssec/rrtype/ds.h" #include "lib/dnssec/signature.h" static int authenticate_ds(const dnssec_key_t *key, dnssec_binary_t *ds_rdata, uint8_t digest_type) @@ -69,7 +69,7 @@ int kr_authenticate_referral(const knot_rrset_t *ref, const dnssec_key_t *key) .size = knot_rdata_rdlen(rd), .data = knot_rdata_data(rd) }; - ret = authenticate_ds(key, &ds_rdata, _knot_ds_dtype(&ref->rrs, i)); + ret = authenticate_ds(key, &ds_rdata, knot_ds_dtype(&ref->rrs, i)); if (ret == 0) { /* Found a good DS */ break; } diff --git a/lib/layer/iterate.c b/lib/layer/iterate.c index 69ec3714c..32485306f 100644 --- a/lib/layer/iterate.c +++ b/lib/layer/iterate.c @@ -15,6 +15,7 @@ */ #include +#include #include #include @@ -520,7 +521,7 @@ static int resolve(knot_layer_t *ctx, knot_pkt_t *pkt) } #ifndef NDEBUG - lookup_table_t *rcode = lookup_by_id(knot_rcode_names, knot_wire_get_rcode(pkt->wire)); + const knot_lookup_t *rcode = knot_lookup_by_id(knot_rcode_names, knot_wire_get_rcode(pkt->wire)); #endif /* Check response code. */ diff --git a/lib/layer/pktcache.c b/lib/layer/pktcache.c index 3330e20f6..b9b6db957 100644 --- a/lib/layer/pktcache.c +++ b/lib/layer/pktcache.c @@ -110,7 +110,7 @@ static int pktcache_peek(knot_layer_t *ctx, knot_pkt_t *pkt) /* Prepare read transaction */ struct kr_cache_txn txn; struct kr_cache *cache = &req->ctx->cache; - if (kr_cache_txn_begin(cache, &txn, NAMEDB_RDONLY) != 0) { + if (kr_cache_txn_begin(cache, &txn, KNOT_DB_RDONLY) != 0) { return ctx->state; } @@ -191,7 +191,7 @@ static int pktcache_stash(knot_layer_t *ctx, knot_pkt_t *pkt) if (kr_cache_txn_begin(&req->ctx->cache, &txn, 0) != 0) { return ctx->state; /* Couldn't acquire cache, ignore. */ } - namedb_val_t data = { pkt->wire, pkt->size }; + knot_db_val_t data = { pkt->wire, pkt->size }; struct kr_cache_entry header = { .timestamp = qry->timestamp.tv_sec, .ttl = ttl, diff --git a/lib/layer/rrcache.c b/lib/layer/rrcache.c index eff217023..ca5bdedf1 100644 --- a/lib/layer/rrcache.c +++ b/lib/layer/rrcache.c @@ -80,7 +80,7 @@ static int loot_rr(struct kr_cache_txn *txn, knot_pkt_t *pkt, const knot_dname_t static int loot_rrcache(struct kr_cache *cache, knot_pkt_t *pkt, struct kr_query *qry, uint16_t rrtype, bool dobit) { struct kr_cache_txn txn; - int ret = kr_cache_txn_begin(cache, &txn, NAMEDB_RDONLY); + int ret = kr_cache_txn_begin(cache, &txn, KNOT_DB_RDONLY); if (ret != 0) { return ret; } @@ -209,7 +209,7 @@ static int stash_commit(map_t *stash, struct kr_query *qry, struct kr_cache_txn return map_walk(stash, &commit_rr, &baton); } -static void stash_glue(map_t *stash, knot_pkt_t *pkt, const knot_dname_t *ns_name, mm_ctx_t *pool) +static void stash_glue(map_t *stash, knot_pkt_t *pkt, const knot_dname_t *ns_name, knot_mm_t *pool) { const knot_pktsection_t *additional = knot_pkt_section(pkt, KNOT_ADDITIONAL); for (unsigned i = 0; i < additional->count; ++i) { @@ -223,7 +223,7 @@ static void stash_glue(map_t *stash, knot_pkt_t *pkt, const knot_dname_t *ns_nam } /* @internal DS is special and is present only parent-side */ -static void stash_ds(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, mm_ctx_t *pool) +static void stash_ds(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, knot_mm_t *pool) { const knot_pktsection_t *authority = knot_pkt_section(pkt, KNOT_AUTHORITY); for (unsigned i = 0; i < authority->count; ++i) { @@ -234,7 +234,7 @@ static void stash_ds(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, mm_ctx } } -static int stash_authority(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, mm_ctx_t *pool) +static int stash_authority(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, knot_mm_t *pool) { const knot_pktsection_t *authority = knot_pkt_section(pkt, KNOT_AUTHORITY); for (unsigned i = 0; i < authority->count; ++i) { @@ -253,7 +253,7 @@ static int stash_authority(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, return kr_ok(); } -static int stash_answer(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, mm_ctx_t *pool) +static int stash_answer(struct kr_query *qry, knot_pkt_t *pkt, map_t *stash, knot_mm_t *pool) { /* Work with QNAME, as minimised name data is cacheable. */ const knot_dname_t *cname_begin = knot_pkt_qname(pkt); @@ -312,7 +312,7 @@ static int rrcache_stash(knot_layer_t *ctx, knot_pkt_t *pkt) ret = stash_answer(qry, pkt, &stash, &req->pool); } /* Cache authority only if chasing referral/cname chain */ - if (!is_auth || qry != TAIL(req->rplan.pending)) { + if (!is_auth || qry != array_tail(req->rplan.pending)) { ret = stash_authority(qry, pkt, &stash, &req->pool); } /* Cache DS records in referrals */ diff --git a/lib/layer/validate.c b/lib/layer/validate.c index 6f97bb620..88c50e11b 100644 --- a/lib/layer/validate.c +++ b/lib/layer/validate.c @@ -26,7 +26,6 @@ #include "lib/dnssec/nsec.h" #include "lib/dnssec/nsec3.h" -#include "lib/dnssec/packet/pkt.h" #include "lib/dnssec.h" #include "lib/layer.h" #include "lib/resolve.h" @@ -37,6 +36,44 @@ #define DEBUG_MSG(qry, fmt...) QRDEBUG(qry, "vldr", fmt) +/** + * Search in section for given type. + * @param sec Packet section. + * @param type Type to search for. + * @return True if found. + */ +static bool section_has_type(const knot_pktsection_t *sec, uint16_t type) +{ + if (!sec) { + return false; + } + + for (unsigned i = 0; i < sec->count; ++i) { + const knot_rrset_t *rr = knot_pkt_rr(sec, i); + if (rr->type == type) { + return true; + } + } + + return false; +} + +static bool pkt_has_type(const knot_pkt_t *pkt, uint16_t type) +{ + if (!pkt) { + return false; + } + + if (section_has_type(knot_pkt_section(pkt, KNOT_ANSWER), type)) { + return true; + } + if (section_has_type(knot_pkt_section(pkt, KNOT_AUTHORITY), type)) { + return true; + } + return section_has_type(knot_pkt_section(pkt, KNOT_ADDITIONAL), type); +} + + /** @internal Baton for validate_section */ struct validate_baton { const knot_pkt_t *pkt; @@ -63,7 +100,7 @@ static int validate_rrset(const char *key, void *val, void *data) } static int validate_section(struct kr_query *qry, knot_pkt_t *answer, - knot_section_t section_id, mm_ctx_t *pool, + knot_section_t section_id, knot_mm_t *pool, bool has_nsec3) { const knot_pktsection_t *sec = knot_pkt_section(answer, section_id); @@ -120,7 +157,7 @@ fail: return ret; } -static int validate_records(struct kr_query *qry, knot_pkt_t *answer, mm_ctx_t *pool, bool has_nsec3) +static int validate_records(struct kr_query *qry, knot_pkt_t *answer, knot_mm_t *pool, bool has_nsec3) { if (!qry->zone_cut.key) { DEBUG_MSG(qry, "<= no DNSKEY, can't validate\n"); @@ -346,7 +383,7 @@ static int validate(knot_layer_t *ctx, knot_pkt_t *pkt) /* Check if this is a DNSKEY answer, check trust chain and store. */ uint8_t pkt_rcode = knot_wire_get_rcode(pkt->wire); uint16_t qtype = knot_pkt_qtype(pkt); - bool has_nsec3 = _knot_pkt_has_type(pkt, KNOT_RRTYPE_NSEC3); + bool has_nsec3 = pkt_has_type(pkt, KNOT_RRTYPE_NSEC3); if (knot_wire_get_aa(pkt->wire) && qtype == KNOT_RRTYPE_DNSKEY) { ret = validate_keyset(qry, pkt, has_nsec3); if (ret != 0) { @@ -360,7 +397,7 @@ static int validate(knot_layer_t *ctx, knot_pkt_t *pkt) if (!(qry->flags & QUERY_CACHED) && pkt_rcode == KNOT_RCODE_NXDOMAIN) { /* @todo If knot_pkt_qname(pkt) is used instead of qry->sname then the tests crash. */ if (!has_nsec3) { - ret = kr_nsec_name_error_response_check(pkt, KNOT_AUTHORITY, qry->sname, &req->pool); + ret = kr_nsec_name_error_response_check(pkt, KNOT_AUTHORITY, qry->sname); } else { ret = kr_nsec3_name_error_response_check(pkt, KNOT_AUTHORITY, qry->sname); } diff --git a/lib/lib.mk b/lib/lib.mk index 7d89590fb..5ed334511 100644 --- a/lib/lib.mk +++ b/lib/lib.mk @@ -6,7 +6,6 @@ libkres_SOURCES := \ lib/layer/pktcache.c \ lib/dnssec/nsec.c \ lib/dnssec/nsec3.c \ - lib/dnssec/packet/pkt.c \ lib/dnssec/signature.c \ lib/dnssec/ta.c \ lib/dnssec.c \ @@ -25,8 +24,6 @@ libkres_HEADERS := \ lib/layer.h \ lib/dnssec/nsec.h \ lib/dnssec/nsec3.h \ - lib/dnssec/packet/pkt.h \ - lib/dnssec/rrtype/ds.h \ lib/dnssec/signature.h \ lib/dnssec/ta.h \ lib/dnssec.h \ diff --git a/lib/nsrep.c b/lib/nsrep.c index b872c33e8..3fd91d7d0 100644 --- a/lib/nsrep.c +++ b/lib/nsrep.c @@ -18,7 +18,6 @@ #include #include #include -#include #include "lib/nsrep.h" #include "lib/rplan.h" diff --git a/lib/resolve.c b/lib/resolve.c index df7c91ff9..3999a14bf 100644 --- a/lib/resolve.c +++ b/lib/resolve.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include #include #include @@ -161,7 +163,7 @@ static int ns_fetch_cut(struct kr_query *qry, struct kr_request *req, knot_pkt_t /* Find closest zone cut from cache */ struct kr_cache_txn txn; - if (kr_cache_txn_begin(&req->ctx->cache, &txn, NAMEDB_RDONLY) == 0) { + if (kr_cache_txn_begin(&req->ctx->cache, &txn, KNOT_DB_RDONLY) == 0) { /* If at/subdomain of parent zone cut, start from its encloser. * This is for case when we get to a dead end (and need glue from parent), or DS refetch. */ struct kr_query *parent = qry->parent; @@ -313,8 +315,8 @@ static int answer_finalize(struct kr_request *request, int state) } /* Set AD=1 if succeeded and requested secured answer. */ struct kr_rplan *rplan = &request->rplan; - if (state == KNOT_STATE_DONE && !EMPTY_LIST(rplan->resolved)) { - struct kr_query *last = TAIL(rplan->resolved); + if (state == KNOT_STATE_DONE && rplan->resolved.len > 0) { + struct kr_query *last = array_tail(rplan->resolved); /* Do not set AD for RRSIG query, as we can't validate it. */ if ((last->flags & QUERY_DNSSEC_WANT) && knot_pkt_has_dnssec(answer) && knot_pkt_qtype(answer) != KNOT_RRTYPE_RRSIG) { @@ -420,7 +422,7 @@ int kr_resolve_consume(struct kr_request *request, const struct sockaddr *src, k } /* Different processing for network error */ - struct kr_query *qry = TAIL(rplan->pending); + struct kr_query *qry = array_tail(rplan->pending); bool tried_tcp = (qry->flags & QUERY_TCP); if (!packet || packet->size == 0) { if (tried_tcp) @@ -447,7 +449,7 @@ int kr_resolve_consume(struct kr_request *request, const struct sockaddr *src, k gettimeofday(&now, NULL); kr_nsrep_update_rtt(&qry->ns, src, time_diff(&qry->timestamp, &now), ctx->cache_rtt); WITH_DEBUG { - char addr_str[SOCKADDR_STRLEN]; + char addr_str[INET6_ADDRSTRLEN]; inet_ntop(src->sa_family, kr_inaddr(src), addr_str, sizeof(addr_str)); DEBUG_MSG(qry, "<= server: '%s' rtt: %ld ms\n", addr_str, time_diff(&qry->timestamp, &now)); } @@ -457,7 +459,7 @@ int kr_resolve_consume(struct kr_request *request, const struct sockaddr *src, k } else if (!(qry->flags & QUERY_DNSSEC_BOGUS)) { kr_nsrep_update_rtt(&qry->ns, src, KR_NS_TIMEOUT, ctx->cache_rtt); WITH_DEBUG { - char addr_str[SOCKADDR_STRLEN]; + char addr_str[INET6_ADDRSTRLEN]; inet_ntop(src->sa_family, kr_inaddr(src), addr_str, sizeof(addr_str)); DEBUG_MSG(qry, "=> server: '%s' flagged as 'bad'\n", addr_str); } @@ -624,7 +626,7 @@ int kr_resolve_produce(struct kr_request *request, struct sockaddr **dst, int *t return KNOT_STATE_FAIL; } /* If we have deferred answers, resume them. */ - struct kr_query *qry = TAIL(rplan->pending); + struct kr_query *qry = array_tail(rplan->pending); if (qry->deferred != NULL) { /* @todo: Refactoring validator, check trust chain before resuming. */ switch(trust_chain_check(request, qry)) { @@ -718,7 +720,7 @@ ns_election: } WITH_DEBUG { - char qname_str[KNOT_DNAME_MAXLEN], zonecut_str[KNOT_DNAME_MAXLEN], ns_str[SOCKADDR_STRLEN], type_str[16]; + char qname_str[KNOT_DNAME_MAXLEN], zonecut_str[KNOT_DNAME_MAXLEN], ns_str[INET6_ADDRSTRLEN], type_str[16]; knot_dname_to_str(qname_str, knot_pkt_qname(packet), sizeof(qname_str)); knot_dname_to_str(zonecut_str, qry->zone_cut.name, sizeof(zonecut_str)); knot_rrtype_to_string(knot_pkt_qtype(packet), type_str, sizeof(type_str)); @@ -760,7 +762,7 @@ int kr_resolve_finish(struct kr_request *request, int state) request->state = state; ITERATE_LAYERS(request, NULL, finish); DEBUG_MSG(NULL, "finished: %d, queries: %zu, mempool: %zu B\n", - request->state, list_size(&rplan->resolved), (size_t) mp_total_size(request->pool.ctx)); + request->state, rplan->resolved.len, (size_t) mp_total_size(request->pool.ctx)); return KNOT_STATE_DONE; } @@ -772,7 +774,7 @@ struct kr_rplan *kr_resolve_plan(struct kr_request *request) return NULL; } -mm_ctx_t *kr_resolve_pool(struct kr_request *request) +knot_mm_t *kr_resolve_pool(struct kr_request *request) { if (request) { return &request->pool; diff --git a/lib/resolve.h b/lib/resolve.h index 905e134e0..d79b58a6c 100644 --- a/lib/resolve.h +++ b/lib/resolve.h @@ -92,7 +92,7 @@ struct kr_context kr_nsrep_lru_t *cache_rtt; kr_nsrep_lru_t *cache_rep; module_array_t *modules; - mm_ctx_t *pool; + knot_mm_t *pool; }; /** @@ -118,7 +118,7 @@ struct kr_request { rr_array_t authority; rr_array_t additional; struct kr_rplan rplan; - mm_ctx_t pool; + knot_mm_t pool; }; /** @@ -191,5 +191,5 @@ struct kr_rplan *kr_resolve_plan(struct kr_request *request); * @return mempool */ KR_EXPORT KR_PURE -mm_ctx_t *kr_resolve_pool(struct kr_request *request); +knot_mm_t *kr_resolve_pool(struct kr_request *request); diff --git a/lib/rplan.c b/lib/rplan.c index 8bae41cd1..6eb52a0dc 100644 --- a/lib/rplan.c +++ b/lib/rplan.c @@ -29,19 +29,19 @@ ((q)->sclass == (cls) && (q)->stype == type && knot_dname_is_equal((q)->sname, name)) /** @internal LUT of query flag names. */ -const lookup_table_t query_flag_names[] = { +const knot_lookup_t query_flag_names[] = { #define X(flag, _) { QUERY_ ## flag, #flag }, QUERY_FLAGS(X) #undef X { 0, NULL } }; -const lookup_table_t *kr_query_flag_names(void) +const knot_lookup_t *kr_query_flag_names(void) { return query_flag_names; } -static struct kr_query *query_create(mm_ctx_t *pool, const knot_dname_t *name) +static struct kr_query *query_create(knot_mm_t *pool, const knot_dname_t *name) { if (name == NULL) { return NULL; @@ -63,14 +63,14 @@ static struct kr_query *query_create(mm_ctx_t *pool, const knot_dname_t *name) return qry; } -static void query_free(mm_ctx_t *pool, struct kr_query *qry) +static void query_free(knot_mm_t *pool, struct kr_query *qry) { kr_zonecut_deinit(&qry->zone_cut); mm_free(pool, qry->sname); mm_free(pool, qry); } -int kr_rplan_init(struct kr_rplan *rplan, struct kr_request *request, mm_ctx_t *pool) +int kr_rplan_init(struct kr_rplan *rplan, struct kr_request *request, knot_mm_t *pool) { if (rplan == NULL) { return KNOT_EINVAL; @@ -80,8 +80,8 @@ int kr_rplan_init(struct kr_rplan *rplan, struct kr_request *request, mm_ctx_t * rplan->pool = pool; rplan->request = request; - init_list(&rplan->pending); - init_list(&rplan->resolved); + array_init(rplan->pending); + array_init(rplan->resolved); return KNOT_EOK; } @@ -91,13 +91,14 @@ void kr_rplan_deinit(struct kr_rplan *rplan) return; } - struct kr_query *qry = NULL, *next = NULL; - WALK_LIST_DELSAFE(qry, next, rplan->pending) { - query_free(rplan->pool, qry); + for (size_t i = 0; i < rplan->pending.len; ++i) { + query_free(rplan->pool, rplan->pending.at[i]); } - WALK_LIST_DELSAFE(qry, next, rplan->resolved) { - query_free(rplan->pool, qry); + for (size_t i = 0; i < rplan->resolved.len; ++i) { + query_free(rplan->pool, rplan->resolved.at[i]); } + array_clear_mm(rplan->pending, mm_free, rplan->pool); + array_clear_mm(rplan->resolved, mm_free, rplan->pool); } bool kr_rplan_empty(struct kr_rplan *rplan) @@ -106,7 +107,7 @@ bool kr_rplan_empty(struct kr_rplan *rplan) return true; } - return EMPTY_LIST(rplan->pending); + return rplan->pending.len == 0; } struct kr_query *kr_rplan_push(struct kr_rplan *rplan, struct kr_query *parent, @@ -116,6 +117,12 @@ struct kr_query *kr_rplan_push(struct kr_rplan *rplan, struct kr_query *parent, return NULL; } + /* Make sure there's enough space */ + int ret = array_reserve_mm(rplan->pending, rplan->pending.len + 1, kr_memreserve, rplan->pool); + if (ret != 0) { + return NULL; + } + struct kr_query *qry = query_create(rplan->pool, name); if (qry == NULL) { return NULL; @@ -126,8 +133,8 @@ struct kr_query *kr_rplan_push(struct kr_rplan *rplan, struct kr_query *parent, qry->parent = parent; qry->ns.addr[0].ip.sa_family = AF_UNSPEC; gettimeofday(&qry->timestamp, NULL); - add_tail(&rplan->pending, &qry->node); kr_zonecut_init(&qry->zone_cut, (const uint8_t *)"", rplan->pool); + array_push(rplan->pending, qry); WITH_DEBUG { char name_str[KNOT_DNAME_MAXLEN], type_str[16]; @@ -144,16 +151,26 @@ int kr_rplan_pop(struct kr_rplan *rplan, struct kr_query *qry) return KNOT_EINVAL; } - rem_node(&qry->node); - add_tail(&rplan->resolved, &qry->node); + /* Make sure there's enough space */ + int ret = array_reserve_mm(rplan->resolved, rplan->resolved.len + 1, kr_memreserve, rplan->pool); + if (ret != 0) { + return ret; + } + + /* Find the query, it will likely be on top */ + for (size_t i = rplan->pending.len; i --> 0;) { + if (rplan->pending.at[i] == qry) { + array_del(rplan->pending, i); + array_push(rplan->resolved, qry); + break; + } + } return KNOT_EOK; } bool kr_rplan_satisfies(struct kr_query *closure, const knot_dname_t *name, uint16_t cls, uint16_t type) { - if (!name) - return false; - while (closure != NULL) { + while (name && closure) { if (QUERY_PROVIDES(closure, name, cls, type)) { return true; } @@ -164,18 +181,10 @@ bool kr_rplan_satisfies(struct kr_query *closure, const knot_dname_t *name, uint struct kr_query *kr_rplan_resolved(struct kr_rplan *rplan) { - if (EMPTY_LIST(rplan->resolved)) { - return NULL; - } - return TAIL(rplan->resolved); -} - -struct kr_query *kr_rplan_next(struct kr_query *qry) -{ - if (!qry) { + if (rplan->resolved.len == 0) { return NULL; } - return (struct kr_query *)qry->node.prev; /* The lists are used as stack, TOP is the TAIL. */ + return array_tail(rplan->resolved); } #undef DEBUG_MSG diff --git a/lib/rplan.h b/lib/rplan.h index 0d05269c7..f2e2cbaf3 100644 --- a/lib/rplan.h +++ b/lib/rplan.h @@ -18,9 +18,7 @@ #include #include -#include -#include -#include +#include #include "lib/cache.h" #include "lib/zonecut.h" @@ -55,13 +53,12 @@ enum kr_query_flag { /** Query flag names table */ KR_EXPORT KR_CONST -const lookup_table_t *kr_query_flag_names(void); +const knot_lookup_t *kr_query_flag_names(void); /** * Single query representation. */ struct kr_query { - node_t node; struct kr_query *parent; knot_dname_t *sname; uint16_t stype; @@ -75,6 +72,9 @@ struct kr_query { struct kr_layer_pickle *deferred; }; +/** @internal Array of queries. */ +typedef array_t(struct kr_query *) kr_qarray_t; + /** * Query resolution plan structure. * @@ -83,10 +83,10 @@ struct kr_query { * It also keeps a notion of current zone cut. */ struct kr_rplan { - list_t pending; /**< List of pending queries. */ - list_t resolved; /**< List of resolved queries. */ - struct kr_request *request; /**< Parent resolution request. */ - mm_ctx_t *pool; /**< Temporary memory pool. */ + kr_qarray_t pending; /**< List of pending queries. */ + kr_qarray_t resolved; /**< List of resolved queries. */ + struct kr_request *request; /**< Parent resolution request. */ + knot_mm_t *pool; /**< Temporary memory pool. */ }; /** @@ -96,7 +96,7 @@ struct kr_rplan { * @param pool ephemeral memory pool for whole resolution */ KR_EXPORT -int kr_rplan_init(struct kr_rplan *rplan, struct kr_request *request, mm_ctx_t *pool); +int kr_rplan_init(struct kr_rplan *rplan, struct kr_request *request, knot_mm_t *pool); /** * Deinitialize resolution plan, aborting any uncommited transactions. diff --git a/lib/utils.c b/lib/utils.c index 4cad3f4ad..ff824edcf 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -180,7 +180,7 @@ int kr_memreserve(void *baton, char **mem, size_t elm_size, size_t want, size_t if (*have >= want) { return 0; } else { - mm_ctx_t *pool = baton; + knot_mm_t *pool = baton; size_t next_size = array_next_count(want); void *mem_new = mm_alloc(pool, next_size * elm_size); if (mem_new != NULL) { @@ -337,7 +337,7 @@ int kr_rrkey(char *key, const knot_dname_t *owner, uint16_t type, uint8_t rank) return (char *)&key_buf[ret] - key; } -int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, uint8_t rank, mm_ctx_t *pool) +int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, uint8_t rank, knot_mm_t *pool) { if (!stash || !rr) { return kr_error(EINVAL); @@ -372,7 +372,7 @@ int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, uint8_t rank, mm_ctx_t *p return knot_rdataset_merge(&stashed->rrs, &rr->rrs, pool); } -int kr_rrarray_add(rr_array_t *array, const knot_rrset_t *rr, mm_ctx_t *pool) +int kr_rrarray_add(rr_array_t *array, const knot_rrset_t *rr, knot_mm_t *pool) { int ret = array_reserve_mm(*array, array->len + 1, kr_memreserve, pool); if (ret != 0) { diff --git a/lib/utils.h b/lib/utils.h index d47dce3b6..8690beadc 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -17,11 +17,13 @@ #pragma once #include +#include #include #include #include #include "lib/generic/map.h" #include "lib/generic/array.h" +#include "lib/defines.h" /* * Logging and debugging. @@ -42,6 +44,22 @@ KR_EXPORT void kr_log_debug(const char *fmt, ...); #define WITH_DEBUG if(0) #endif +/** @cond Memory alloc routines */ +static inline void *mm_alloc(knot_mm_t *mm, size_t size) +{ + if (mm) return mm->alloc(mm->ctx, size); + else return malloc(size); +} +static inline void mm_free(knot_mm_t *mm, void *what) +{ + if (mm) { + if (mm->free) + mm->free(what); + } + else free(what); +} +/* @endcond */ + /** Return time difference in miliseconds. * @note based on the _BSD_SOURCE timersub() macro */ static inline long time_diff(struct timeval *begin, struct timeval *end) { @@ -77,7 +95,7 @@ int kr_rand_reseed(void); KR_EXPORT unsigned kr_rand_uint(unsigned max); -/** Memory reservation routine for mm_ctx_t */ +/** Memory reservation routine for knot_mm_t */ KR_EXPORT int kr_memreserve(void *baton, char **mem, size_t elm_size, size_t want, size_t *have); @@ -131,10 +149,10 @@ int kr_rrkey(char *key, const knot_dname_t *owner, uint16_t type, uint8_t rank); * @note RRSIG RRSets are merged according the type covered fields. * @return 0 or an error */ -int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, uint8_t rank, mm_ctx_t *pool); +int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, uint8_t rank, knot_mm_t *pool); /** @internal Add RRSet copy to RR array. */ -int kr_rrarray_add(rr_array_t *array, const knot_rrset_t *rr, mm_ctx_t *pool); +int kr_rrarray_add(rr_array_t *array, const knot_rrset_t *rr, knot_mm_t *pool); /** * Call module property. diff --git a/lib/zonecut.c b/lib/zonecut.c index 05e18a9cf..cab154ea3 100644 --- a/lib/zonecut.c +++ b/lib/zonecut.c @@ -78,7 +78,7 @@ static void update_cut_name(struct kr_zonecut *cut, const knot_dname_t *name) cut->name = next_name; } -int kr_zonecut_init(struct kr_zonecut *cut, const knot_dname_t *name, mm_ctx_t *pool) +int kr_zonecut_init(struct kr_zonecut *cut, const knot_dname_t *name, knot_mm_t *pool) { if (!cut || !name) { return kr_error(EINVAL); @@ -349,7 +349,7 @@ static int fetch_ns(struct kr_context *ctx, struct kr_zonecut *cut, const knot_d * Fetch RRSet of given type. */ static int fetch_rrset(knot_rrset_t **rr, const knot_dname_t *owner, uint16_t type, - struct kr_cache_txn *txn, mm_ctx_t *pool, uint32_t timestamp) + struct kr_cache_txn *txn, knot_mm_t *pool, uint32_t timestamp) { if (!rr) { return kr_error(ENOENT); diff --git a/lib/zonecut.h b/lib/zonecut.h index 64ebd7b5b..b87f80cda 100644 --- a/lib/zonecut.h +++ b/lib/zonecut.h @@ -33,7 +33,7 @@ struct kr_zonecut { knot_rrset_t* key; /**< Zone cut DNSKEY. */ knot_rrset_t* trust_anchor; /**< Current trust anchor. */ struct kr_zonecut *parent; /**< Parent zone cut. */ - mm_ctx_t *pool; /**< Memory pool. */ + knot_mm_t *pool; /**< Memory pool. */ }; /** @@ -44,7 +44,7 @@ struct kr_zonecut { * @return 0 or error code */ KR_EXPORT -int kr_zonecut_init(struct kr_zonecut *cut, const knot_dname_t *name, mm_ctx_t *pool); +int kr_zonecut_init(struct kr_zonecut *cut, const knot_dname_t *name, knot_mm_t *pool); /** * Clear the structure and free the address set. diff --git a/modules/cachectl/cachectl.c b/modules/cachectl/cachectl.c index ce7c407d4..f47bc4252 100644 --- a/modules/cachectl/cachectl.c +++ b/modules/cachectl/cachectl.c @@ -27,6 +27,7 @@ #include #include +#include #include #include "daemon/engine.h" @@ -40,7 +41,7 @@ * Properties. */ -typedef int (*cache_cb_t)(struct kr_cache_txn *txn, namedb_iter_t *it, namedb_val_t *key, void *baton); +typedef int (*cache_cb_t)(struct kr_cache_txn *txn, knot_db_iter_t *it, knot_db_val_t *key, void *baton); /** @internal Prefix walk. */ static int cache_prefixed(struct engine *engine, const char *args, unsigned txn_flags, cache_cb_t cb, void *baton) @@ -76,7 +77,7 @@ static int cache_prefixed(struct engine *engine, const char *args, unsigned txn_ /* Start search transaction */ struct kr_cache *cache = &engine->resolver.cache; - const namedb_api_t *api = cache->api; + const knot_db_api_t *api = cache->api; struct kr_cache_txn txn; ret = kr_cache_txn_begin(cache, &txn, txn_flags); if (ret != 0) { @@ -86,10 +87,10 @@ static int cache_prefixed(struct engine *engine, const char *args, unsigned txn_ /* Walk through cache records matching given prefix. * Note that since the backend of the cache is opaque, there's no exactly efficient * way to do prefix search (i.e. Redis uses hashtable but offers SCAN, LMDB can do lexical closest match, ...). */ - namedb_val_t key = { prefix, prefix_len }; - namedb_iter_t *it = api->iter_begin(&txn.t, 0); + knot_db_val_t key = { prefix, prefix_len }; + knot_db_iter_t *it = api->iter_begin(&txn.t, 0); if (it) { /* Seek first key matching the prefix. */ - it = api->iter_seek(it, &key, NAMEDB_GEQ); + it = api->iter_seek(it, &key, KNOT_DB_GEQ); } while (it != NULL) { if (api->iter_key(it, &key) != 0) { @@ -123,7 +124,7 @@ static bool is_expired(struct kr_cache_entry *entry, uint32_t drift) } /** @internal Delete iterated key. */ -static int cache_delete_cb(struct kr_cache_txn *txn, namedb_iter_t *it, namedb_val_t *key, void *baton) +static int cache_delete_cb(struct kr_cache_txn *txn, knot_db_iter_t *it, knot_db_val_t *key, void *baton) { struct kr_cache *cache = txn->owner; return cache->api->del(&txn->t, key); @@ -140,7 +141,7 @@ static char* prune(void *env, struct kr_module *module, const char *args) { struct engine *engine = env; struct kr_cache *cache = &engine->resolver.cache; - const namedb_api_t *storage = cache->api; + const knot_db_api_t *storage = cache->api; struct kr_cache_txn txn; int ret = kr_cache_txn_begin(cache, &txn, 0); @@ -161,10 +162,10 @@ static char* prune(void *env, struct kr_module *module, const char *args) /* Fetch current time and start iterating */ struct timeval now; gettimeofday(&now, NULL); - namedb_iter_t *it = storage->iter_begin(&txn.t, 0); + knot_db_iter_t *it = storage->iter_begin(&txn.t, 0); while (it && pruned < prune_max) { /* Fetch RR from cache */ - namedb_val_t key, val; + knot_db_val_t key, val; if (storage->iter_key(it, &key) != 0 || storage->iter_val(it, &val) != 0) { break; @@ -242,7 +243,7 @@ static char* clear(void *env, struct kr_module *module, const char *args) } /** @internal Serialize cached record name into JSON. */ -static int cache_dump_cb(struct kr_cache_txn *txn, namedb_iter_t *it, namedb_val_t *key, void *baton) +static int cache_dump_cb(struct kr_cache_txn *txn, knot_db_iter_t *it, knot_db_val_t *key, void *baton) { JsonNode* json_records = baton; char buf[KNOT_DNAME_MAXLEN]; @@ -291,7 +292,7 @@ static char* get(void *env, struct kr_module *module, const char *args) char *result = NULL; JsonNode *json_records = json_mkobject(); if (json_records) { - int ret = cache_prefixed(env, args, NAMEDB_RDONLY, &cache_dump_cb, json_records); + int ret = cache_prefixed(env, args, KNOT_DB_RDONLY, &cache_dump_cb, json_records); if (ret == 0) { result = json_encode(json_records); } diff --git a/modules/hints/hints.c b/modules/hints/hints.c index 03c13ce06..ff7eb922a 100644 --- a/modules/hints/hints.c +++ b/modules/hints/hints.c @@ -214,7 +214,13 @@ static int query(knot_layer_t *ctx, knot_pkt_t *pkt) static int parse_addr_str(struct sockaddr_storage *sa, const char *addr) { int family = strchr(addr, ':') ? AF_INET6 : AF_INET; - return sockaddr_set(sa, family, addr, 0); + memset(sa, 0, sizeof(struct sockaddr_storage)); + sa->ss_family = family; + char *addr_bytes = (char *)kr_inaddr((struct sockaddr *)sa); + if (inet_pton(family, addr, addr_bytes) < 1) { + return kr_error(EILSEQ); + } + return 0; } static int add_pair(struct kr_zonecut *hints, const char *name, const char *addr) @@ -276,11 +282,11 @@ static int load(struct kr_module *module, const char *path) } /* Create pool and copy itself */ - mm_ctx_t _pool = { + knot_mm_t _pool = { .ctx = mp_new(4096), - .alloc = (mm_alloc_t) mp_alloc + .alloc = (knot_mm_alloc_t) mp_alloc }; - mm_ctx_t *pool = mm_alloc(&_pool, sizeof(*pool)); + knot_mm_t *pool = mm_alloc(&_pool, sizeof(*pool)); if (!pool) { return kr_error(ENOMEM); } @@ -330,7 +336,7 @@ static char* hint_set(void *env, struct kr_module *module, const char *args) /** @internal Pack address list into JSON array. */ static JsonNode *pack_addrs(pack_t *pack) { - char buf[SOCKADDR_STRLEN]; + char buf[INET6_ADDRSTRLEN]; JsonNode *root = json_mkarray(); uint8_t *addr = pack_head(*pack); while (addr != pack_tail(*pack)) { diff --git a/modules/kmemcached/kmemcached.c b/modules/kmemcached/kmemcached.c index 367c31c85..d1979818a 100644 --- a/modules/kmemcached/kmemcached.c +++ b/modules/kmemcached/kmemcached.c @@ -14,7 +14,7 @@ along with this program. If not, see . */ -#include +#include #include #include "daemon/engine.h" @@ -22,7 +22,7 @@ #include "lib/cache.h" /** @internal Memcached API */ -extern const namedb_api_t *namedb_memcached_api(void); +extern const knot_db_api_t *namedb_memcached_api(void); /** @internal Make memcached options. */ void *namedb_memcached_mkopts(const char *conf, size_t maxsize) diff --git a/modules/kmemcached/namedb_memcached.c b/modules/kmemcached/namedb_memcached.c index 3aefe1b72..5d764565e 100644 --- a/modules/kmemcached/namedb_memcached.c +++ b/modules/kmemcached/namedb_memcached.c @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include #include @@ -37,7 +37,7 @@ /* Oh, the irony... */ typedef array_t(char *) freelist_t; -static int init(namedb_t **db, mm_ctx_t *mm, void *arg) +static int init(knot_db_t **db, knot_mm_t *mm, void *arg) { if (!db || !arg) { return KNOT_EINVAL; @@ -55,12 +55,12 @@ static int init(namedb_t **db, mm_ctx_t *mm, void *arg) return KNOT_EOK; } -static void deinit(namedb_t *db) +static void deinit(knot_db_t *db) { memcached_free((memcached_st *)db); } -static int txn_begin(namedb_t *db, namedb_txn_t *txn, unsigned flags) +static int txn_begin(knot_db_t *db, knot_db_txn_t *txn, unsigned flags) { freelist_t *freelist = malloc(sizeof(*freelist)); if (!freelist) { @@ -72,7 +72,7 @@ static int txn_begin(namedb_t *db, namedb_txn_t *txn, unsigned flags) return KNOT_EOK; } -static int txn_commit(namedb_txn_t *txn) +static int txn_commit(knot_db_txn_t *txn) { freelist_t *freelist = txn->txn; if (freelist) { @@ -86,7 +86,7 @@ static int txn_commit(namedb_txn_t *txn) return KNOT_EOK; } -static void txn_abort(namedb_txn_t *txn) +static void txn_abort(knot_db_txn_t *txn) { /** @warning No real transactions here, * all the reads/writes are done synchronously. @@ -96,7 +96,7 @@ static void txn_abort(namedb_txn_t *txn) txn_commit(txn); } -static int count(namedb_txn_t *txn) +static int count(knot_db_txn_t *txn) { memcached_return_t error = 0; memcached_stat_st *stats = memcached_stat(txn->db, NULL, &error); @@ -108,7 +108,7 @@ static int count(namedb_txn_t *txn) return ret; } -static int clear(namedb_txn_t *txn) +static int clear(knot_db_txn_t *txn) { memcached_return_t ret = memcached_flush(txn->db, 0); if (ret != 0) { @@ -117,7 +117,7 @@ static int clear(namedb_txn_t *txn) return KNOT_EOK; } -static int find(namedb_txn_t *txn, namedb_val_t *key, namedb_val_t *val, unsigned flags) +static int find(knot_db_txn_t *txn, knot_db_val_t *key, knot_db_val_t *val, unsigned flags) { uint32_t mc_flags = 0; memcached_return_t error = 0; @@ -134,7 +134,7 @@ static int find(namedb_txn_t *txn, namedb_val_t *key, namedb_val_t *val, unsigne return KNOT_EOK; } -static int insert(namedb_txn_t *txn, namedb_val_t *key, namedb_val_t *val, unsigned flags) +static int insert(knot_db_txn_t *txn, knot_db_val_t *key, knot_db_val_t *val, unsigned flags) { if (!txn || !key || !val) { return KNOT_EINVAL; @@ -150,7 +150,7 @@ static int insert(namedb_txn_t *txn, namedb_val_t *key, namedb_val_t *val, unsig return KNOT_EOK; } -static int del(namedb_txn_t *txn, namedb_val_t *key) +static int del(knot_db_txn_t *txn, knot_db_val_t *key) { memcached_return_t ret = memcached_delete(txn->db, key->data, key->len, 0); if (ret != 0) { @@ -159,43 +159,43 @@ static int del(namedb_txn_t *txn, namedb_val_t *key) return KNOT_EOK; } -static namedb_iter_t *iter_begin(namedb_txn_t *txn, unsigned flags) +static knot_db_iter_t *iter_begin(knot_db_txn_t *txn, unsigned flags) { /* Iteration is not supported, pruning should be * left on the memcached server */ return NULL; } -static namedb_iter_t *iter_seek(namedb_iter_t *iter, namedb_val_t *key, unsigned flags) +static knot_db_iter_t *iter_seek(knot_db_iter_t *iter, knot_db_val_t *key, unsigned flags) { assert(0); return NULL; /* ENOTSUP */ } -static namedb_iter_t *iter_next(namedb_iter_t *iter) +static knot_db_iter_t *iter_next(knot_db_iter_t *iter) { assert(0); return NULL; } -static int iter_key(namedb_iter_t *iter, namedb_val_t *val) +static int iter_key(knot_db_iter_t *iter, knot_db_val_t *val) { return KNOT_ENOTSUP; } -static int iter_val(namedb_iter_t *iter, namedb_val_t *val) +static int iter_val(knot_db_iter_t *iter, knot_db_val_t *val) { return KNOT_ENOTSUP; } -static void iter_finish(namedb_iter_t *iter) +static void iter_finish(knot_db_iter_t *iter) { assert(0); } -const namedb_api_t *namedb_memcached_api(void) +const knot_db_api_t *namedb_memcached_api(void) { - static const namedb_api_t api = { + static const knot_db_api_t api = { "memcached", init, deinit, txn_begin, txn_commit, txn_abort, diff --git a/modules/redis/namedb_redis.c b/modules/redis/namedb_redis.c index 6f95fdc7e..db10c5d51 100644 --- a/modules/redis/namedb_redis.c +++ b/modules/redis/namedb_redis.c @@ -22,7 +22,7 @@ #include #include -#include +#include #include "modules/redis/redis.h" @@ -79,7 +79,7 @@ static void cli_free(struct redis_cli *cli) free(cli); } -static int init(namedb_t **db, mm_ctx_t *mm, void *arg) +static int init(knot_db_t **db, knot_mm_t *mm, void *arg) { if (!db || !arg) { return kr_error(EINVAL); @@ -99,13 +99,13 @@ static int init(namedb_t **db, mm_ctx_t *mm, void *arg) return ret; } -static void deinit(namedb_t *db) +static void deinit(knot_db_t *db) { struct redis_cli *cli = db; cli_free(cli); } -static int txn_begin(namedb_t *db, namedb_txn_t *txn, unsigned flags) +static int txn_begin(knot_db_t *db, knot_db_txn_t *txn, unsigned flags) { if (!db || !txn) { return kr_error(EINVAL); @@ -114,7 +114,7 @@ static int txn_begin(namedb_t *db, namedb_txn_t *txn, unsigned flags) return kr_ok(); } -static int txn_commit(namedb_txn_t *txn) +static int txn_commit(knot_db_txn_t *txn) { if (!txn || !txn->db) { return kr_error(EINVAL); @@ -124,7 +124,7 @@ static int txn_commit(namedb_txn_t *txn) return kr_ok(); } -static void txn_abort(namedb_txn_t *txn) +static void txn_abort(knot_db_txn_t *txn) { /** @warning No real transactions here. */ txn_commit(txn); @@ -145,7 +145,7 @@ static void txn_abort(namedb_txn_t *txn) } \ } -static int count(namedb_txn_t *txn) +static int count(knot_db_txn_t *txn) { if (!txn || !txn->db) { return kr_error(EINVAL); @@ -165,7 +165,7 @@ static int count(namedb_txn_t *txn) return ret; } -static int clear(namedb_txn_t *txn) +static int clear(knot_db_txn_t *txn) { if (!txn || !txn->db) { return kr_error(EINVAL); @@ -181,7 +181,7 @@ static int clear(namedb_txn_t *txn) return kr_ok(); } -static int find(namedb_txn_t *txn, namedb_val_t *key, namedb_val_t *val, unsigned flags) +static int find(knot_db_txn_t *txn, knot_db_val_t *key, knot_db_val_t *val, unsigned flags) { if (!txn || !key || !val) { return kr_error(EINVAL); @@ -207,7 +207,7 @@ static int find(namedb_txn_t *txn, namedb_val_t *key, namedb_val_t *val, unsigne return kr_ok(); } -static int insert(namedb_txn_t *txn, namedb_val_t *key, namedb_val_t *val, unsigned flags) +static int insert(knot_db_txn_t *txn, knot_db_val_t *key, knot_db_val_t *val, unsigned flags) { if (!txn || !key || !val) { return kr_error(EINVAL); @@ -228,48 +228,48 @@ static int insert(namedb_txn_t *txn, namedb_val_t *key, namedb_val_t *val, unsig return kr_ok(); } -static int del(namedb_txn_t *txn, namedb_val_t *key) +static int del(knot_db_txn_t *txn, knot_db_val_t *key) { return kr_error(ENOSYS); } -static namedb_iter_t *iter_begin(namedb_txn_t *txn, unsigned flags) +static knot_db_iter_t *iter_begin(knot_db_txn_t *txn, unsigned flags) { /* Iteration is not supported, pruning should be * left on the Redis server setting */ return NULL; } -static namedb_iter_t *iter_seek(namedb_iter_t *iter, namedb_val_t *key, unsigned flags) +static knot_db_iter_t *iter_seek(knot_db_iter_t *iter, knot_db_val_t *key, unsigned flags) { assert(0); return NULL; /* ENOSYS */ } -static namedb_iter_t *iter_next(namedb_iter_t *iter) +static knot_db_iter_t *iter_next(knot_db_iter_t *iter) { assert(0); return NULL; } -static int iter_key(namedb_iter_t *iter, namedb_val_t *val) +static int iter_key(knot_db_iter_t *iter, knot_db_val_t *val) { return kr_error(ENOSYS); } -static int iter_val(namedb_iter_t *iter, namedb_val_t *val) +static int iter_val(knot_db_iter_t *iter, knot_db_val_t *val) { return kr_error(ENOSYS); } -static void iter_finish(namedb_iter_t *iter) +static void iter_finish(knot_db_iter_t *iter) { assert(0); } -const namedb_api_t *namedb_redis_api(void) +const knot_db_api_t *namedb_redis_api(void) { - static const namedb_api_t api = { + static const knot_db_api_t api = { "redis", init, deinit, txn_begin, txn_commit, txn_abort, diff --git a/modules/redis/redis.c b/modules/redis/redis.c index c38cbc5cc..79f7c66cb 100644 --- a/modules/redis/redis.c +++ b/modules/redis/redis.c @@ -14,7 +14,7 @@ along with this program. If not, see . */ -#include +#include #include #include @@ -24,7 +24,7 @@ #include "lib/cache.h" /** @internal Redis API */ -extern const namedb_api_t *namedb_redis_api(void); +extern const knot_db_api_t *namedb_redis_api(void); /** @internal Make redis options. */ void *namedb_redis_mkopts(const char *conf_, size_t maxsize) diff --git a/modules/stats/stats.c b/modules/stats/stats.c index 2b3e6219e..884098da2 100644 --- a/modules/stats/stats.c +++ b/modules/stats/stats.c @@ -115,9 +115,9 @@ static void collect_sample(struct stat_data *data, struct kr_rplan *rplan, knot_ { /* Sample key = {[2] type, [1-255] owner} */ char key[sizeof(uint16_t) + KNOT_DNAME_MAXLEN]; - struct kr_query *qry = NULL; - WALK_LIST(qry, rplan->resolved) { + for (size_t i = 0; i < rplan->resolved.len; ++i) { /* Sample queries leading to iteration or expiring */ + struct kr_query *qry = rplan->resolved.at[i]; if ((qry->flags & QUERY_CACHED) && !(qry->flags & QUERY_EXPIRING)) { continue; } @@ -146,10 +146,10 @@ static int collect(knot_layer_t *ctx) collect_answer(data, param->answer); collect_sample(data, rplan, param->answer); /* Count cached and unresolved */ - if (!EMPTY_LIST(rplan->resolved)) { + if (rplan->resolved.len > 0) { /* Histogram of answer latency. */ - struct kr_query *first = HEAD(rplan->resolved); - struct kr_query *last = TAIL(rplan->resolved); + struct kr_query *first = rplan->resolved.at[0]; + struct kr_query *last = array_tail(rplan->resolved); struct timeval now; gettimeofday(&now, NULL); long elapsed = time_diff(&first->timestamp, &now); diff --git a/scripts/bootstrap-depends.sh b/scripts/bootstrap-depends.sh index 3631130a2..3b20d16f4 100755 --- a/scripts/bootstrap-depends.sh +++ b/scripts/bootstrap-depends.sh @@ -5,7 +5,7 @@ CMOCKA_TAG="cmocka-0.4.1" CMOCKA_URL="git://git.cryptomilk.org/projects/cmocka.git" LIBUV_TAG="v1.x" LIBUV_URL="https://github.com/libuv/libuv.git" -KNOT_TAG="c1353efc" +KNOT_TAG="27ccff2" KNOT_URL="https://github.com/CZ-NIC/knot.git" GMP_TAG="6.0.0" GMP_URL="https://gmplib.org/download/gmp/gmp-${GMP_TAG}.tar.xz" diff --git a/tests/test.h b/tests/test.h index ceb43e0f9..b0e9c2ce4 100644 --- a/tests/test.h +++ b/tests/test.h @@ -31,7 +31,7 @@ #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #include "lib/defines.h" -#include +#include "lib/utils.h" #include #include @@ -42,7 +42,7 @@ static inline void mm_test_free(void *p) { if (p) test_free(p); } /** Memory context using CMocka allocator. */ -static inline void test_mm_ctx_init(mm_ctx_t *mm) +static inline void test_mm_ctx_init(knot_mm_t *mm) { mm->alloc = &mm_test_malloc; mm->free = &mm_test_free; diff --git a/tests/test_array.c b/tests/test_array.c index decac5b2c..d8ed5e3fc 100644 --- a/tests/test_array.c +++ b/tests/test_array.c @@ -17,7 +17,7 @@ #include "tests/test.h" #include "lib/generic/array.h" -mm_ctx_t global_mm; +knot_mm_t global_mm; static void test_array(void **state) { diff --git a/tests/test_cache.c b/tests/test_cache.c index 3bf0c41a5..95da6c265 100644 --- a/tests/test_cache.c +++ b/tests/test_cache.c @@ -14,7 +14,7 @@ along with this program. If not, see . */ -#include +#include #include #include "tests/test.h" @@ -24,7 +24,7 @@ #include #include -mm_ctx_t global_mm; +knot_mm_t global_mm; struct kr_cache_txn global_txn; knot_rrset_t global_rr; const char *global_env; @@ -33,7 +33,7 @@ struct kr_cache_entry global_fake_ce; #define NAMEDB_INTS 256 #define NAMEDB_DATA_SIZE (NAMEDB_INTS * sizeof(int)) uint8_t namedb_data[NAMEDB_DATA_SIZE]; -namedb_val_t global_namedb_data = {namedb_data, NAMEDB_DATA_SIZE}; +knot_db_val_t global_namedb_data = {namedb_data, NAMEDB_DATA_SIZE}; bool is_malloc_mocked = false; #define CACHE_SIZE 10 * 4096 @@ -41,7 +41,7 @@ bool is_malloc_mocked = false; #define CACHE_TIME 0 void * (*original_malloc) (size_t __size); -int (*original_knot_rdataset_add)(knot_rdataset_t *rrs, const knot_rdata_t *rr, mm_ctx_t *mm) = NULL; +int (*original_knot_rdataset_add)(knot_rdataset_t *rrs, const knot_rdata_t *rr, knot_mm_t *mm) = NULL; void *malloc(size_t __size) { @@ -58,7 +58,7 @@ void *malloc(size_t __size) return (err_mock != KNOT_EOK) ? NULL : original_malloc (__size); } -int knot_rdataset_add(knot_rdataset_t *rrs, const knot_rdata_t *rr, mm_ctx_t *mm) +int knot_rdataset_add(knot_rdataset_t *rrs, const knot_rdata_t *rr, knot_mm_t *mm) { int err, err_mock; err_mock = (int)mock(); @@ -74,39 +74,39 @@ int knot_rdataset_add(knot_rdataset_t *rrs, const knot_rdata_t *rr, mm_ctx_t *mm } /* Simulate init failure */ -static int fake_test_init(namedb_t **db_ptr, mm_ctx_t *mm, void *arg) +static int fake_test_init(knot_db_t **db_ptr, knot_mm_t *mm, void *arg) { static char db[1024]; *db_ptr = db; return mock(); } -static void fake_test_deinit(namedb_t *db) +static void fake_test_deinit(knot_db_t *db) { return; } /* Simulate commit failure */ -static int fake_test_commit(namedb_txn_t *txn) +static int fake_test_commit(knot_db_txn_t *txn) { return KNOT_ESPACE; } /* Dummy abort */ -static void fake_test_abort(namedb_txn_t *txn) +static void fake_test_abort(knot_db_txn_t *txn) { return; } /* Stub for find */ -static int fake_test_find(namedb_txn_t *txn, namedb_val_t *key, namedb_val_t *val, unsigned flags) +static int fake_test_find(knot_db_txn_t *txn, knot_db_val_t *key, knot_db_val_t *val, unsigned flags) { val->data = &global_fake_ce; return KNOT_EOK; } /* Stub for insert */ -static int fake_test_ins(namedb_txn_t *txn, namedb_val_t *key, namedb_val_t *val, unsigned flags) +static int fake_test_ins(knot_db_txn_t *txn, knot_db_val_t *key, knot_db_val_t *val, unsigned flags) { struct kr_cache_entry *header = val->data; int res_cmp, err = (int)mock(); @@ -125,15 +125,15 @@ static int fake_test_ins(namedb_txn_t *txn, namedb_val_t *key, namedb_val_t *val return err; } -static int fake_test_txn_begin(namedb_t *db, namedb_txn_t *txn, unsigned flags) +static int fake_test_txn_begin(knot_db_t *db, knot_db_txn_t *txn, unsigned flags) { return KNOT_EOK; } /* Fake api */ -static namedb_api_t *fake_namedb_lmdb_api(void) +static knot_db_api_t *fake_knot_db_lmdb_api(void) { - static namedb_api_t fake_api = { + static knot_db_api_t fake_api = { "lmdb_fake_api", fake_test_init, fake_test_deinit, fake_test_txn_begin, fake_test_commit, fake_test_abort, @@ -145,10 +145,10 @@ static namedb_api_t *fake_namedb_lmdb_api(void) } /* Test cache open */ -static int test_open(void **state, namedb_api_t *api) +static int test_open(void **state, knot_db_api_t *api) { static struct kr_cache cache; - struct namedb_lmdb_opts opts; + struct knot_db_lmdb_opts opts; memset(&cache, 0, sizeof(cache)); memset(&opts, 0, sizeof(opts)); opts.path = global_env; @@ -162,10 +162,10 @@ static void test_open_fake_api(void **state) { bool res; will_return(fake_test_init,KNOT_EINVAL); - assert_int_equal(test_open(state, fake_namedb_lmdb_api()),KNOT_EINVAL); + assert_int_equal(test_open(state, fake_knot_db_lmdb_api()),KNOT_EINVAL); will_return(fake_test_init,KNOT_EOK); - assert_int_equal(test_open(state, fake_namedb_lmdb_api()),KNOT_EOK); - res = (((struct kr_cache *)(*state))->api == fake_namedb_lmdb_api()); + assert_int_equal(test_open(state, fake_knot_db_lmdb_api()),KNOT_EOK); + res = (((struct kr_cache *)(*state))->api == fake_knot_db_lmdb_api()); assert_true(res); } @@ -173,7 +173,7 @@ static void test_open_conventional_api(void **state) { bool res; assert_int_equal(test_open(state, NULL),KNOT_EOK); - res = (((struct kr_cache *)(*state))->api == namedb_lmdb_api()); + res = (((struct kr_cache *)(*state))->api == knot_db_lmdb_api()); assert_true(res); } @@ -197,7 +197,7 @@ static struct kr_cache_txn *test_txn_write(void **state) static struct kr_cache_txn *test_txn_rdonly(void **state) { assert_non_null(*state); - assert_int_equal(kr_cache_txn_begin(*state, &global_txn, NAMEDB_RDONLY), 0); + assert_int_equal(kr_cache_txn_begin(*state, &global_txn, KNOT_DB_RDONLY), 0); return &global_txn; } @@ -205,7 +205,7 @@ static struct kr_cache_txn *test_txn_rdonly(void **state) static void test_fake_invalid (void **state) { struct kr_cache_txn *txn = NULL; - const namedb_api_t *api_saved = NULL; + const knot_db_api_t *api_saved = NULL; knot_dname_t dname[] = ""; struct kr_cache_entry *entry = NULL; int ret = 0; @@ -251,7 +251,7 @@ static void test_invalid(void **state) { knot_dname_t dname[] = ""; uint32_t timestamp = CACHE_TIME; - struct namedb_lmdb_opts opts; + struct knot_db_lmdb_opts opts; struct kr_cache_entry *entry = NULL; memset(&opts, 0, sizeof(opts)); diff --git a/tests/test_pack.c b/tests/test_pack.c index c2a470b4a..b55c15cc2 100644 --- a/tests/test_pack.c +++ b/tests/test_pack.c @@ -18,7 +18,7 @@ #include "lib/generic/pack.h" #define U8(x) (const uint8_t *)(x) -mm_ctx_t global_mm; +knot_mm_t global_mm; static void test_pack_std(void **state) { diff --git a/tests/test_rplan.c b/tests/test_rplan.c index 53d22f92b..f05cdde21 100644 --- a/tests/test_rplan.c +++ b/tests/test_rplan.c @@ -40,7 +40,7 @@ static void test_rplan_params(void **state) static void test_rplan_push(void **state) { - mm_ctx_t mm; + knot_mm_t mm; test_mm_ctx_init(&mm); struct kr_request request = { .pool = mm, -- 2.47.2