diff --git a/src/knot/ctl/remote.c b/src/knot/ctl/remote.c index af7bba03e1c7b0e4b19ce53b6d4bdb390ac1e40e..f8aadc8eac775d4b039b17ea89703cde88933f9b 100644 --- a/src/knot/ctl/remote.c +++ b/src/knot/ctl/remote.c @@ -550,7 +550,7 @@ int remote_answer(int fd, server_t *s, knot_packet_t *pkt, uint8_t* rwire, size_ /* Command: * QNAME: leftmost label of QNAME */ - size_t cmd_len = knot_dname_label_size(qname, 0); + size_t cmd_len = *knot_dname_name(qname); char *cmd = strndup((char*)qname->name + 1, cmd_len); /* Data: diff --git a/src/libknot/dname.c b/src/libknot/dname.c index ffbf51b5a4d424503b4bc767d506a721b8fc541e..05de73c924a74a7c7f4f083b4774db13387c02c5 100644 --- a/src/libknot/dname.c +++ b/src/libknot/dname.c @@ -31,81 +31,25 @@ #include "util/utils.h" #include "util/wire.h" -/*! \todo dnames allocated from TLS cache will be discarded after thread - * termination. This shouldn't happpen. - */ -#if 0 -/* - * Memory cache. - */ -#include "common/slab/slab.h" -#include <stdio.h> -#include <pthread.h> - -/*! \brief TLS unique key for each thread cache. */ -static pthread_key_t dname_ckey; -static pthread_once_t dname_once = PTHREAD_ONCE_INIT; - -/*! \brief Destroy thread dname cache (automatically called). */ -static void knot_dname_cache_free(void *ptr) -{ - slab_cache_t* cache = (slab_cache_t*)ptr; - if (cache) { - slab_cache_destroy(cache); - free(cache); - } -} -/*! \brief Cleanup for main() TLS. */ -static void knot_dname_cache_main_free() -{ - knot_dname_cache_free(pthread_getspecific(dname_ckey)); -} +/*----------------------------------------------------------------------------*/ +/* Non-API functions */ +/*----------------------------------------------------------------------------*/ -static void knot_dname_cache_init() +static knot_dname_t *knot_dname_new() { - (void) pthread_key_create(&dname_ckey, knot_dname_cache_free); - atexit(knot_dname_cache_main_free); // Main thread cleanup -} -#endif + knot_dname_t *dname = malloc(sizeof(knot_dname_t)); -/*! - * \brief Allocate item from thread cache. - * \retval Allocated dname instance on success. - * \retval NULL on error. - */ -static knot_dname_t* knot_dname_alloc() -{ - return malloc(sizeof(knot_dname_t)); - - /*! \todo dnames allocated from TLS cache will be discarded after thread - * termination. This shouldn't happpen. - */ -#if 0 - /* Initialize dname cache TLS key. */ - (void)pthread_once(&dname_once, knot_dname_cache_init); - - /* Create cache if not exists. */ - slab_cache_t* cache = pthread_getspecific(dname_ckey); - if (knot_unlikely(!cache)) { - cache = malloc(sizeof(slab_cache_t)); - if (!cache) { - return 0; - } - - /* Initialize cache. */ - slab_cache_init(cache, sizeof(knot_dname_t)); - (void)pthread_setspecific(dname_ckey, cache); - } + dname->name = NULL; + dname->labels = NULL; + dname->node = NULL; + dname->count = 1; + dname->size = 0; + dname->label_count = 0; - return slab_cache_alloc(cache); -#endif + return dname; } -/*----------------------------------------------------------------------------*/ -/* Non-API functions */ -/*----------------------------------------------------------------------------*/ - static int knot_dname_set(knot_dname_t *dname, uint8_t *wire, short wire_size, const uint8_t *labels, short label_count) @@ -369,22 +313,6 @@ dbg_dname_exec_verb( /* API functions */ /*----------------------------------------------------------------------------*/ -knot_dname_t *knot_dname_new() -{ - knot_dname_t *dname = knot_dname_alloc(); - - dname->name = NULL; - dname->labels = NULL; - dname->node = NULL; - dname->count = 1; - dname->size = 0; - dname->label_count = 0; - - return dname; -} - -/*----------------------------------------------------------------------------*/ - knot_dname_t *knot_dname_new_from_str(const char *name, uint size, struct knot_node *node) { @@ -746,24 +674,8 @@ uint knot_dname_size(const knot_dname_t *dname) /*----------------------------------------------------------------------------*/ -uint8_t knot_dname_size_part(const knot_dname_t *dname, int labels) -{ - assert(labels < dname->label_count); - assert(dname->labels != NULL); - return (dname->labels[labels]); -} - -/*----------------------------------------------------------------------------*/ - const struct knot_node *knot_dname_node(const knot_dname_t *dname) -{ - return knot_dname_get_node(dname); -} - -/*----------------------------------------------------------------------------*/ - -struct knot_node *knot_dname_get_node(const knot_dname_t *dname) { if (dname == NULL) { return NULL; @@ -1027,17 +939,6 @@ int knot_dname_label_count(const knot_dname_t *dname) /*----------------------------------------------------------------------------*/ -uint8_t knot_dname_label_size(const knot_dname_t *dname, int i) -{ - assert(i >= 0); - assert(dname->size == 1 || i + 1 == dname->label_count - || dname->labels[i + 1] - dname->labels[i] - 1 - == dname->name[dname->labels[i]]); - return dname->name[dname->labels[i]]; -} - -/*----------------------------------------------------------------------------*/ - knot_dname_t *knot_dname_replace_suffix(const knot_dname_t *dname, int size, const knot_dname_t *suffix) { diff --git a/src/libknot/dname.h b/src/libknot/dname.h index de9a920ca5e0fb5aed5122d339e941fe6ed901c5..7fc081f8b2adae5aa16a17e8725f86d7d5395283 100644 --- a/src/libknot/dname.h +++ b/src/libknot/dname.h @@ -54,18 +54,6 @@ typedef struct knot_dname knot_dname_t; /*----------------------------------------------------------------------------*/ -/*! - * \brief Creates empty dname structure (no name, no owner node). - * - * \note Newly created dname is referenced, caller is responsible for releasing - * it after use. - * - * \return Newly allocated and initialized dname structure. - * - * \todo Possibly useless. - */ -knot_dname_t *knot_dname_new(); - /*! * \brief Creates a dname structure from domain name given in presentation * format. @@ -194,16 +182,6 @@ const uint8_t *knot_dname_name(const knot_dname_t *dname); */ unsigned int knot_dname_size(const knot_dname_t *dname); -/*! - * \brief Returns size of a part of domain name. - * - * \param dname Domain name. - * \param labels Count of labels to get the size of (counted from left). - * - * \return Size of first \a labels labels of \a dname, counted from left. - */ -uint8_t knot_dname_size_part(const knot_dname_t *dname, int labels); - /*! * \brief Returns the zone node the domain name belongs to. * @@ -213,8 +191,6 @@ uint8_t knot_dname_size_part(const knot_dname_t *dname, int labels); */ const struct knot_node *knot_dname_node(const knot_dname_t *dname); -struct knot_node *knot_dname_get_node(const knot_dname_t *dname); - void knot_dname_update_node(knot_dname_t *dname); void knot_dname_set_node(knot_dname_t *dname, struct knot_node *node); @@ -294,16 +270,6 @@ int knot_dname_matched_labels(const knot_dname_t *dname1, */ int knot_dname_label_count(const knot_dname_t *dname); -/*! - * \brief Returns the size of the requested label in the domain name. - * - * \param dname Domain name to get the label size from. - * \param i Index of the label (0 is the leftmost label). - * - * \return Size of \a i-th label in \a dname (counted from left). - */ -uint8_t knot_dname_label_size(const knot_dname_t *dname, int i); - /*! * \brief Replaces the suffix of given size in one domain name with other domain * name.