]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
various nitpicks around the parent commit
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 31 Oct 2018 13:59:20 +0000 (14:59 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Fri, 2 Nov 2018 15:21:31 +0000 (16:21 +0100)
daemon/bindings.c
lib/nsrep.c
lib/nsrep.h
lib/zonecut.c

index f7b2e7ea4aabb7aca6055f0a53faa0655b924750..6b4948e8b99f8dfd6cb951b14f11c9f2cc46f2a7 100644 (file)
@@ -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)
index 3a9462bf4776624dec1588bd9ceb1e69d67a36cf..bccce77e5cae8d1612aa9e21350056b99f1f285b 100644 (file)
@@ -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);
        }
 
index 6ea9f167e69ab88b8160971537ddf6acc2ef04f7..3c45c25ec2acae9a209b7a8c7c517da5e2312705 100644 (file)
@@ -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
index ac3b23ccd29fb623a57bee4c133619329abd3dda..774c58dd79389e8b95bc7e825c1203f6a2781407 100644 (file)
     along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-#include <libknot/descriptor.h>
-#include <libknot/rrtype/rdname.h>
-#include <libknot/packet/wire.h>
-#include <libknot/descriptor.h>
-
 #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 <libknot/descriptor.h>
+#include <libknot/packet/wire.h>
+#include <libknot/rrtype/rdname.h>
 
 #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;
 }