Commit c9e2ce52 authored by Daniel Salzman's avatar Daniel Salzman

contrib: move libUCW source from internal

parent cdb41dcc
......@@ -31,6 +31,12 @@ libtap/tap/float.h
libtap/tap/macros.h
samples/Makefile.am
src/Makefile.am
src/contrib/ucw/array-sort.h
src/contrib/ucw/binsearch.h
src/contrib/ucw/heap.c
src/contrib/ucw/heap.h
src/contrib/ucw/mempool.c
src/contrib/ucw/mempool.h
src/dnssec/Makefile.am
src/dnssec/contrib/gnutls_error.c
src/dnssec/lib/binary.c
......@@ -335,20 +341,16 @@ src/libknot/dnssec/rrset-sign.c
src/libknot/dnssec/rrset-sign.h
src/libknot/errcode.c
src/libknot/errcode.h
src/libknot/internal/array-sort.h
src/libknot/internal/base32hex.c
src/libknot/internal/base32hex.h
src/libknot/internal/base64.c
src/libknot/internal/base64.h
src/libknot/internal/binsearch.h
src/libknot/internal/consts.h
src/libknot/internal/endian.h
src/libknot/internal/errcode.c
src/libknot/internal/errcode.h
src/libknot/internal/getline.c
src/libknot/internal/getline.h
src/libknot/internal/heap.c
src/libknot/internal/heap.h
src/libknot/internal/hhash.c
src/libknot/internal/hhash.h
src/libknot/internal/lists.c
......@@ -358,8 +360,6 @@ src/libknot/internal/mem.c
src/libknot/internal/mem.h
src/libknot/internal/mempattern.c
src/libknot/internal/mempattern.h
src/libknot/internal/mempool.c
src/libknot/internal/mempool.h
src/libknot/internal/namedb/lmdb.h
src/libknot/internal/namedb/mdb.c
src/libknot/internal/namedb/midl.c
......@@ -412,6 +412,7 @@ src/libknot/rrset.c
src/libknot/rrset.h
src/libknot/rrtype/aaaa.h
src/libknot/rrtype/dnskey.h
src/libknot/rrtype/naptr.c
src/libknot/rrtype/naptr.h
src/libknot/rrtype/nsec.h
src/libknot/rrtype/nsec3.c
......@@ -496,6 +497,7 @@ src/zscanner/tests/tests.h
src/zscanner/tests/zscanner-tool.c
tests-fuzz/Makefile.am
tests-fuzz/packet.c
tests-fuzz/packet_libfuzzer.c
tests-fuzz/wrap/server.c
tests-fuzz/wrap/tcp-handler.c
tests-fuzz/wrap/udp-handler.c
......
libtap
src
src/contrib
src/dnssec/lib
src/dnssec/lib/dnssec
src/dnssec/shared
src/dnssec/utils
src/zscanner
tests
tests-fuzz
\ No newline at end of file
tests-fuzz
tests-fuzz/wrap
......@@ -4,6 +4,7 @@ SUBDIRS = zscanner dnssec dnstap .
lib_LTLIBRARIES = \
libknot.la
noinst_LTLIBRARIES = \
libcontrib.la \
libknot-internal.la \
libknot-yparser.la
......@@ -21,6 +22,13 @@ AM_LDFLAGS = $(CODE_COVERAGE_LDFLAGS)
# Knot DNS Libraries #
######################
libcontrib_ladir = $(includedir)
nobase_libcontrib_la_HEADERS = \
contrib/ucw/array-sort.h \
contrib/ucw/binsearch.h \
contrib/ucw/heap.h \
contrib/ucw/mempool.h
# dynamic: libknot headers
libknot_ladir = $(includedir)
nobase_libknot_la_HEADERS = \
......@@ -59,21 +67,17 @@ nobase_libknot_la_HEADERS = \
libknot_internal_ladir = $(includedir)
nobase_libknot_internal_la_HEADERS = \
libknot/internal/array-sort.h \
libknot/internal/base32hex.h \
libknot/internal/base64.h \
libknot/internal/binsearch.h \
libknot/internal/consts.h \
libknot/internal/endian.h \
libknot/internal/errcode.h \
libknot/internal/getline.h \
libknot/internal/heap.h \
libknot/internal/hhash.h \
libknot/internal/lists.h \
libknot/internal/macros.h \
libknot/internal/mem.h \
libknot/internal/mempattern.h \
libknot/internal/mempool.h \
libknot/internal/namedb/namedb.h \
libknot/internal/namedb/namedb_lmdb.h \
libknot/internal/namedb/namedb_trie.h \
......@@ -96,6 +100,11 @@ nobase_libknot_yparser_la_HEADERS = \
libknot/yparser/yptrafo.h
# dynamic: libknot sources
libcontrib_la_SOURCES = \
contrib/ucw/heap.c \
contrib/ucw/mempool.c \
$(nobase_libcontrib_la_HEADERS)
libknot_la_SOURCES = \
libknot/binary.c \
libknot/consts.c \
......@@ -135,12 +144,10 @@ libknot_internal_la_SOURCES = \
libknot/internal/base64.c \
libknot/internal/errcode.c \
libknot/internal/getline.c \
libknot/internal/heap.c \
libknot/internal/hhash.c \
libknot/internal/lists.c \
libknot/internal/mem.c \
libknot/internal/mempattern.c \
libknot/internal/mempool.c \
libknot/internal/namedb/namedb_lmdb.c \
libknot/internal/namedb/namedb_trie.c \
libknot/internal/net.c \
......@@ -154,13 +161,16 @@ libknot_internal_la_SOURCES = \
libknot/internal/utils.c \
$(nobase_libknot_internal_la_HEADERS)
libcontrib_la_CPPFLAGS = $(AM_CPPFLAGS)
libcontrib_la_CFLAGS = $(AM_CFLAGS)
libknot_internal_la_CPPFLAGS = $(AM_CPPFLAGS) $(lmdb_CFLAGS)
libknot_internal_la_CFLAGS = $(AM_CFLAGS)
libknot_la_CPPFLAGS = $(AM_CPPFLAGS) $(CFLAG_VISIBILITY) $(lmdb_CFLAGS)
libknot_la_CFLAGS = $(AM_CFLAGS)
libknot_la_LDFLAGS = $(AM_LDFLAGS) $(libknot_VERSION_INFO) $(lmdb_LIBS)
libknot_la_LIBADD = dnssec/libdnssec.la libknot-internal.la
libknot_la_LIBADD = dnssec/libdnssec.la libcontrib.la libknot-internal.la
# pkg-config
pkgconfig_DATA = libknot.pc
......@@ -352,7 +362,7 @@ libknotd_la_LIBADD = libknot.la libknot-yparser.la zscanner/libzscanner.la $(lib
knotd_CPPFLAGS = $(AM_CPPFLAGS) $(liburcu_CFLAGS)
knotd_LDADD = libknotd.la $(liburcu_LIBS)
knotc_LDADD = libknotd.la
knot1to2_LDADD = libknot-internal.la
knot1to2_LDADD = libknot-internal.la libcontrib.la
####################################
# Optional Knot DNS Daemon modules #
......@@ -434,7 +444,7 @@ libknotus_la_SOURCES = \
libknotus_la_CPPFLAGS = $(AM_CPPFLAGS) $(libidn_CFLAGS)
libknotus_la_LDFLAGS = $(AM_LDFLAGS) $(libidn_LIBS)
libknotus_la_LIBADD = libknot.la
libknotus_la_LIBADD = libcontrib.la libknot.la
# bin programs
kdig_LDADD = $(libidn_LIBS) libknotus.la
......
......@@ -7,6 +7,10 @@
* of the GNU Lesser General Public License.
*/
#pragma once
#include "libknot/internal/macros.h"
/*
* This is not a normal header file, it's a generator of sorting
* routines. Each time you include it with parameters set in the
......@@ -27,25 +31,19 @@
* ASORT_KEY_TYPE [*] data type of a single array entry key
* ASORT_ELT(i) returns the key of i-th element; if this macro is not
* defined, the function gets a pointer to an array to be sorted
* ASORT_LT(x,y) x < y for ASORT_TYPE (default: "x<y")
* ASORT_LT(x,y) x < y for ASORT_KEY_TYPE (default: "x<y")
* ASORT_SWAP(i,j) swap i-th and j-th element (default: assume _ELT
* is an l-value and swap just the keys)
* ASORT_THRESHOLD threshold for switching between quicksort and insertsort
* ASORT_EXTRA_ARGS extra arguments for the sort function (they are always
* visible in all the macros supplied above), starts with comma
*
* After including this file, a function ASORT_PREFIX(sort)(uns array_size)
* or ASORT_PREFIX(sort)(ASORT_KEY_TYPE *array, uns array_size) [if ASORT_ELT
* After including this file, a function ASORT_PREFIX(sort)(unsigned array_size)
* or ASORT_PREFIX(sort)(ASORT_KEY_TYPE *array, unsigned array_size) [if ASORT_ELT
* is not defined] is declared and all parameter macros are automatically
* undef'd.
*/
#pragma once
#include "libknot/internal/macros.h"
typedef unsigned uns;
#ifndef ASORT_LT
#define ASORT_LT(x,y) ((x) < (y))
#endif
......@@ -75,11 +73,11 @@ typedef unsigned uns;
* sorted. If the macro is provided, this parameter is omitted. In that case,
* you can sort global variables or pass your structure by @ASORT_EXTRA_ARGS.
**/
static void ASORT_PREFIX(sort)(ASORT_ARRAY_ARG uns array_size ASORT_EXTRA_ARGS)
static void ASORT_PREFIX(sort)(ASORT_ARRAY_ARG unsigned array_size ASORT_EXTRA_ARGS)
{
struct stk { int l, r; } stack[8*sizeof(uns)];
struct stk { int l, r; } stack[8*sizeof(unsigned)];
int l, r, left, right, m;
uns sp = 0;
unsigned sp = 0;
ASORT_KEY_TYPE pivot;
if (array_size <= 1)
......
......@@ -21,10 +21,10 @@
* The time complexity is `O(log(N))`.
**/
#define BIN_SEARCH_FIRST_GE_CMP(ary, N, ary_lt_x, x, ...) ({ \
uns l = 0, r = (N); \
unsigned l = 0, r = (N); \
while (l < r) \
{ \
uns m = (l+r)/2; \
unsigned m = (l+r)/2; \
if (ary_lt_x(ary, m, x, __VA_ARGS__)) \
l = m+1; \
else \
......
/*
* Universal Heap Macros
* Binary heap
*
* (c) 2012 Ondrej Filip <feela@network.cz>
*
......@@ -8,7 +8,6 @@
*/
/***
* [[intro]]
* Introduction
* ------------
*
......@@ -31,17 +30,11 @@
* - `heap[i] >= heap[i / 2]` for each `i` in `[2, num]`
*
* The first element `heap[1]` is always lower or equal to all other elements.
*
* [[macros]]
* Macros
* ------
***/
#include "libknot/internal/macros.h"
#include "libknot/internal/heap.h"
#include <string.h>
#include <stdlib.h>
#include "contrib/ucw/heap.h"
static inline void heap_swap(heap_val_t *e1, heap_val_t *e2)
{
......
......@@ -13,17 +13,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*!
* \file heap.h
*
* \author Ondrej Filip <ondrej.filip@nic.cz>
*
* \brief Universal heap support
*
*
* \addtogroup common_lib
* @{
*/
#pragma once
......@@ -36,12 +25,12 @@ struct heap {
heap_val_t *data;
}; /* Array follows */
#define INITIAL_HEAP_SIZE 512 /* initial heap size */
#define HEAP_INCREASE_STEP 2 /* multiplier for each inflation, keep conservative */
#define HEAP_DECREASE_THRESHOLD 2 /* threshold for deflation, keep conservative */
#define HELEMENT(h,num) ((h)->data + (num))
#define HHEAD(h) HELEMENT((h),1)
#define EMPTY_HEAP(h) ((h)->num == 0) /* h->num == 0 */
#define INITIAL_HEAP_SIZE 512 /* initial heap size */
#define HEAP_INCREASE_STEP 2 /* multiplier for each inflation, keep conservative */
#define HEAP_DECREASE_THRESHOLD 2 /* threshold for deflation, keep conservative */
#define HELEMENT(h,num) ((h)->data + (num))
#define HHEAD(h) HELEMENT((h), 1)
#define EMPTY_HEAP(h) ((h)->num == 0) /* h->num == 0 */
int heap_init(struct heap *, int (*cmp)(), int);
void heap_delmin(struct heap *);
......@@ -49,6 +38,3 @@ int heap_insert(struct heap *, void *);
int heap_find(struct heap *, void *);
void heap_delete(struct heap *, int);
void heap_replace(struct heap *h, int pos, void *e);
/*! @} */
......@@ -10,12 +10,12 @@
#undef LOCAL_DEBUG
#include "libknot/internal/mempool.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include "libknot/internal/macros.h"
#include "contrib/ucw/mempool.h"
/** \todo This shouldn't be precalculated, but computed on load. */
#define CPU_PAGE_SIZE 4096
......@@ -24,10 +24,6 @@
#define ALIGN_TO(s, a) (((s)+a-1)&~(a-1))
#define MP_CHUNK_TAIL ALIGN_TO(sizeof(struct mempool_chunk), CPU_STRUCT_ALIGN)
#define MP_SIZE_MAX (~0U - MP_CHUNK_TAIL - CPU_PAGE_SIZE)
#ifndef MAX
#define MAX(a, b) \
({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; })
#endif
#define DBG(s, ...)
/** \note Imported MMAP backend from bigalloc.c */
......
......@@ -31,8 +31,8 @@
#include <stdint.h>
#include <sys/time.h>
#include "libknot/internal/heap.h"
#include "knot/server/dthreads.h"
#include "contrib/ucw/heap.h"
/* Forward decls. */
struct evsched;
......
......@@ -30,7 +30,7 @@
#include "libknot/internal/sockaddr.h"
#include "libknot/yparser/ypformat.h"
#include "libknot/yparser/yptrafo.h"
#include "libknot/internal/mempool.h"
#include "contrib/ucw/mempool.h"
// The active configuration.
conf_t *s_conf;
......
......@@ -38,11 +38,11 @@
#include "knot/common/log.h"
#include "knot/common/time.h"
#include "knot/nameserver/process_query.h"
#include "libknot/internal/mempool.h"
#include "libknot/internal/macros.h"
#include "libknot/internal/net.h"
#include "libknot/internal/sockaddr.h"
#include "libknot/processing/overlay.h"
#include "contrib/ucw/mempool.h"
/*! \brief TCP context data. */
typedef struct tcp_context {
......
......@@ -39,10 +39,10 @@
#include "knot/server/server.h"
#include "libknot/internal/sockaddr.h"
#include "libknot/internal/mempattern.h"
#include "libknot/internal/mempool.h"
#include "libknot/internal/macros.h"
#include "libknot/libknot.h"
#include "libknot/processing/overlay.h"
#include "contrib/ucw/mempool.h"
/* Buffer identifiers. */
enum {
......
......@@ -22,7 +22,7 @@
#include "knot/zone/serial.h"
#include "libknot/internal/lists.h"
#include "libknot/internal/mempool.h"
#include "contrib/ucw/mempool.h"
static int add_to_node(zone_node_t *node, const zone_node_t *add_node,
mm_ctx_t *mm)
......
......@@ -18,10 +18,10 @@
#include "dnssec/random.h"
#include "libknot/libknot.h"
#include "libknot/internal/mempool.h"
#include "libknot/internal/macros.h"
#include "libknot/processing/requestor.h"
#include "libknot/yparser/yptrafo.h"
#include "contrib/ucw/mempool.h"
#include "knot/common/log.h"
#include "knot/common/trim.h"
......
......@@ -27,8 +27,8 @@
#include "libknot/packet/wire.h"
#include "knot/zone/node.h"
#include "libknot/internal/mempattern.h"
#include "libknot/internal/mempool.h"
#include "libknot/internal/macros.h"
#include "contrib/ucw/mempool.h"
/*----------------------------------------------------------------------------*/
/* Non-API functions */
......
......@@ -4,7 +4,6 @@
#include "libknot/internal/macros.h"
#include "libknot/internal/hhash.h"
#include "libknot/internal/binsearch.h"
#include "libknot/internal/trie/murmurhash3.h"
#include "libknot/internal/errcode.h"
......@@ -14,7 +13,8 @@ static int universal_cmp(uint32_t k1, uint32_t k2, hhash_t *tbl);
#define ASORT_KEY_TYPE uint32_t
#define ASORT_LT(x, y) (universal_cmp((x), (y), tbl) < 0)
#define ASORT_EXTRA_ARGS , hhash_t *tbl
#include "libknot/internal/array-sort.h"
#include "contrib/ucw/array-sort.h"
#include "contrib/ucw/binsearch.h"
/* Hopscotch internal defines. */
#define HOP_NEXT(x) __builtin_ctz((x))
......
......@@ -18,7 +18,7 @@
#include "libknot/internal/macros.h"
#include "libknot/internal/mempattern.h"
#include "libknot/internal/mempool.h"
#include "contrib/ucw/mempool.h"
static void mm_nofree(void *p)
{
......
......@@ -25,8 +25,8 @@
#include "utils/common/netio.h"
#include "libknot/libknot.h"
#include "libknot/internal/mempattern.h"
#include "libknot/internal/mempool.h"
#include "libknot/tsig.h"
#include "contrib/ucw/mempool.h"
#define DEFAULT_RETRIES_NSUPDATE 3
#define DEFAULT_TIMEOUT_NSUPDATE 12
......
......@@ -19,8 +19,15 @@
#include <tap/basic.h>
#include "libknot/internal/trie/hat-trie.h"
#include "libknot/internal/macros.h"
#include "libknot/internal/mem.h"
/* UCW array sorting defines. */
#define ASORT_PREFIX(X) str_key_##X
#define ASORT_KEY_TYPE char*
#define ASORT_LT(x, y) (strcmp((x), (y)) < 0)
#include "contrib/ucw/array-sort.h"
/* Constants. */
#define KEY_MAXLEN 64
......@@ -93,12 +100,6 @@ static bool str_key_find_leq(hattrie_t *trie, char **keys, size_t i, size_t size
}
/* UCW array sorting defines. */
#define ASORT_PREFIX(X) str_key_##X
#define ASORT_KEY_TYPE char*
#define ASORT_LT(x, y) (strcmp((x), (y)) < 0)
#include "libknot/internal/array-sort.h"
int main(int argc, char *argv[])
{
plan_lazy();
......
......@@ -20,9 +20,9 @@
#include "libknot/internal/hhash.h"
#include "libknot/internal/mempattern.h"
#include "libknot/internal/mempool.h"
#include "libknot/internal/macros.h"
#include "libknot/libknot.h"
#include "contrib/ucw/mempool.h"
/* Test defines. */
#define ELEM_COUNT 65535
......
......@@ -23,12 +23,18 @@
#include <assert.h>
#include <tap/basic.h>
#include "libknot/internal/mempool.h"
#include "libknot/internal/mem.h"
#include "libknot/internal/namedb/namedb_lmdb.h"
#include "libknot/internal/namedb/namedb_trie.h"
#include "libknot/internal/strlcpy.h"
#include "libknot/libknot.h"
#include "contrib/ucw/mempool.h"
/* UCW array sorting defines. */
#define ASORT_PREFIX(X) str_key_##X
#define ASORT_KEY_TYPE char*
#define ASORT_LT(x, y) (strcmp((x), (y)) < 0)
#include "contrib/ucw/array-sort.h"
/* Constants. */
#define KEY_MAXLEN 64
......@@ -46,12 +52,6 @@ static char *str_key_rand(size_t len, mm_ctx_t *pool)
return s;
}
/* UCW array sorting defines. */
#define ASORT_PREFIX(X) str_key_##X
#define ASORT_KEY_TYPE char*
#define ASORT_LT(x, y) (strcmp((x), (y)) < 0)
#include "libknot/internal/array-sort.h"
static void namedb_test_set(unsigned nkeys, char **keys, void *opts,
const namedb_api_t *api, mm_ctx_t *pool)
{
......
......@@ -18,8 +18,8 @@
#include <string.h>
#include <stdlib.h>
#include "libknot/internal/mempool.h"
#include "libknot/processing/overlay.h"
#include "contrib/ucw/mempool.h"
/* @note Purpose of this test is to verify, that FSM chaining works. */
......
......@@ -17,11 +17,11 @@
#include <tap/basic.h>
#include "libknot/libknot.h"
#include "libknot/internal/mempool.h"
#include "libknot/descriptor.h"
#include "libknot/libknot.h"
#include "libknot/packet/pkt.h"
#include "libknot/rrtype/tsig.h"
#include "contrib/ucw/mempool.h"
#define TTL 7200
#define NAMECOUNT 3
......
......@@ -18,11 +18,11 @@
#include <string.h>
#include <stdlib.h>
#include "libknot/internal/mempool.h"
#include "libknot/descriptor.h"
#include "libknot/packet/wire.h"
#include "knot/nameserver/process_answer.h"
#include "fake_server.h"
#include "contrib/ucw/mempool.h"
/* @note Test helpers. */
#define TEST_RESET() \
......
......@@ -18,11 +18,11 @@
#include <string.h>
#include <stdlib.h>
#include "libknot/internal/mempool.h"
#include "libknot/descriptor.h"
#include "libknot/packet/wire.h"
#include "knot/nameserver/process_query.h"
#include "fake_server.h"
#include "contrib/ucw/mempool.h"
/* Basic response check (4 TAP tests). */
static void answer_sanity_check(const uint8_t *query,
......
......@@ -19,10 +19,10 @@
#include <stdlib.h>
#include "libknot/internal/mempattern.h"
#include "libknot/internal/mempool.h"
#include "libknot/libknot.h"
#include "knot/nameserver/query_module.h"
#include "libknot/packet/pkt.h"
#include "contrib/ucw/mempool.h"
/* Universal processing stage. */
int state_visit(int state, knot_pkt_t *pkt, struct query_data *qdata, void *ctx)
......
......@@ -21,10 +21,10 @@
#include <fcntl.h>
#include "knot/conf/conf.h"
#include "libknot/internal/mempool.h"
#include "libknot/internal/net.h"
#include "libknot/processing/layer.h"
#include "libknot/processing/requestor.h"
#include "contrib/ucw/mempool.h"
/* @note Purpose of this test is not to verify process_answer functionality,
* but simply if the requesting/receiving works, so mirror is okay. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment