From: Vladimír Čunát Date: Wed, 31 Oct 2018 13:59:20 +0000 (+0100) Subject: various nitpicks around the parent commit X-Git-Tag: v3.1.0~1^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a334c444120362264c8e3c9a805a0d02f786c014;p=thirdparty%2Fknot-resolver.git various nitpicks around the parent commit --- diff --git a/daemon/bindings.c b/daemon/bindings.c index f7b2e7ea4..6b4948e8b 100644 --- a/daemon/bindings.c +++ b/daemon/bindings.c @@ -1222,7 +1222,7 @@ static int cache_get(lua_State *L) } /** Set time interval for cleaning rtt cache. - * Servers with score >= KR_NS_TIMEOUTED will be cleaned after + * Servers with score >= KR_NS_TIMEOUT will be cleaned after * this interval ended up, so that they will be able to participate * in NS elections again. */ static int cache_ns_tout(lua_State *L) diff --git a/lib/nsrep.c b/lib/nsrep.c index 3a9462bf4..bccce77e5 100644 --- a/lib/nsrep.c +++ b/lib/nsrep.c @@ -82,6 +82,8 @@ static void update_nsrep_set(struct kr_nsrep *ns, const knot_dname_t *name, uint #undef ADDR_SET +/** + * \param addr_set pack with one IP address per element */ static unsigned eval_addr_set(const pack_t *addr_set, struct kr_context *ctx, struct kr_qflags opts, unsigned score, uint8_t *addr[]) { @@ -165,7 +167,7 @@ static unsigned eval_addr_set(const pack_t *addr_set, struct kr_context *ctx, break; } } -get_next_iterator : + get_next_iterator: it = pack_obj_next(it); } @@ -326,6 +328,7 @@ int kr_nsrep_set(struct kr_query *qry, size_t index, const struct sockaddr *sock int kr_nsrep_elect(struct kr_query *qry, struct kr_context *ctx) { if (!qry || !ctx) { + //assert(!EINVAL); return kr_error(EINVAL); } @@ -354,6 +357,7 @@ int kr_nsrep_elect(struct kr_query *qry, struct kr_context *ctx) int kr_nsrep_elect_addr(struct kr_query *qry, struct kr_context *ctx) { if (!qry || !ctx) { + //assert(!EINVAL); return kr_error(EINVAL); } diff --git a/lib/nsrep.h b/lib/nsrep.h index 6ea9f167e..3c45c25ec 100644 --- a/lib/nsrep.h +++ b/lib/nsrep.h @@ -36,7 +36,7 @@ enum kr_ns_score { KR_NS_LONG = (3 * KR_NS_TIMEOUT) / 4, KR_NS_UNKNOWN = KR_NS_TIMEOUT / 2, KR_NS_PENALTY = 100, - KR_NS_GLUED = 10 + KR_NS_GLUED = 10, }; /** @@ -145,7 +145,7 @@ int kr_nsrep_elect_addr(struct kr_query *qry, struct kr_context *ctx); * @param addr chosen address (NULL for first) * @param score new score (i.e. RTT), see enum kr_ns_score * after two calls with score = KR_NS_DEAD and umode = KR_NS_UPDATE - * server will be guaranteed to have KR_NS_TIMEOUTED score + * server will be guaranteed to have score >= KR_NS_TIMEOUT * @param cache RTT LRU cache * @param umode update mode (KR_NS_UPDATE or KR_NS_RESET or KR_NS_ADD) * @return 0 on success, error code on failure diff --git a/lib/zonecut.c b/lib/zonecut.c index ac3b23ccd..774c58dd7 100644 --- a/lib/zonecut.c +++ b/lib/zonecut.c @@ -14,18 +14,18 @@ along with this program. If not, see . */ -#include -#include -#include -#include - #include "lib/zonecut.h" -#include "lib/rplan.h" + #include "contrib/cleanup.h" #include "lib/defines.h" +#include "lib/generic/pack.h" #include "lib/layer.h" #include "lib/resolve.h" -#include "lib/generic/pack.h" +#include "lib/rplan.h" + +#include +#include +#include #define VERBOSE_MSG(qry, fmt...) QRVERBOSE(qry, "zcut", fmt) @@ -42,14 +42,6 @@ typedef enum { * LATER: we might be interested whether it's only glue. */ } addrset_info_t; -/* Root hint descriptor. */ -struct hint_info { - const knot_dname_t *name; - size_t len; - const uint8_t *addr; -}; - -#define U8(x) (const uint8_t *)(x) static void update_cut_name(struct kr_zonecut *cut, const knot_dname_t *name) { @@ -67,11 +59,9 @@ int kr_zonecut_init(struct kr_zonecut *cut, const knot_dname_t *name, knot_mm_t return kr_error(EINVAL); } + memset(cut, 0, sizeof(*cut)); cut->name = knot_dname_copy(name, pool); cut->pool = pool; - cut->key = NULL; - cut->trust_anchor = NULL; - cut->parent = NULL; cut->nsset = trie_create(pool); return cut->name && cut->nsset ? kr_ok() : kr_error(ENOMEM); } @@ -294,7 +284,8 @@ int kr_zonecut_set_sbelt(struct kr_context *ctx, struct kr_zonecut *cut) trie_apply(cut->nsset, free_addr_set_cb, cut->pool); trie_clear(cut->nsset); - update_cut_name(cut, U8("")); + const uint8_t *const dname_root = (const uint8_t *)/*sign-cast*/(""); + update_cut_name(cut, dname_root); /* Copy root hints from resolution context. */ return kr_zonecut_copy(cut, &ctx->root_hints); } @@ -525,22 +516,28 @@ int kr_zonecut_find_cached(struct kr_context *ctx, struct kr_zonecut *cut, const knot_dname_t *name, const struct kr_query *qry, bool * restrict secured) { - //VERBOSE_MSG(qry, "_find_cached\n"); if (!ctx || !cut || !name) { + //assert(false); return kr_error(EINVAL); } + /* I'm not sure whether the caller always passes a clean state; + * mixing doesn't seem to make sense in any case, so let's clear it. + * We don't bother freeing the packs, as they're on mempool. */ + trie_clear(cut->nsset); /* Copy name as it may overlap with cut name that is to be replaced. */ knot_dname_t *qname = knot_dname_copy(name, cut->pool); if (!qname) { return kr_error(ENOMEM); } - /* Start at QNAME parent. */ + /* Start at QNAME. */ + int ret; const knot_dname_t *label = qname; while (true) { /* Fetch NS first and see if it's insecure. */ uint8_t rank = 0; const bool is_root = (label[0] == '\0'); - if (fetch_ns(ctx, cut, label, qry, &rank) == 0) { + ret = fetch_ns(ctx, cut, label, qry, &rank); + if (ret == 0) { /* Flag as insecure if cached as this */ if (kr_rank_test(rank, KR_RANK_INSECURE)) { *secured = false; @@ -554,24 +551,27 @@ int kr_zonecut_find_cached(struct kr_context *ctx, struct kr_zonecut *cut, label, KNOT_RRTYPE_DNSKEY, cut->pool, qry); } update_cut_name(cut, label); - mm_free(cut->pool, qname); - kr_cache_sync(&ctx->cache); WITH_VERBOSE(qry) { auto_free char *label_str = kr_dname_text(label); VERBOSE_MSG(qry, "found cut: %s (rank 0%.2o return codes: DS %d, DNSKEY %d)\n", label_str, rank, ret_ds, ret_dnskey); } - return kr_ok(); - } + ret = kr_ok(); + break; + } /* else */ + + trie_clear(cut->nsset); /* Subtract label from QNAME. */ if (!is_root) { label = knot_wire_next_label(label, NULL); } else { + ret = kr_error(ENOENT); break; } } + kr_cache_sync(&ctx->cache); mm_free(cut->pool, qname); - return kr_error(ENOENT); + return ret; }