]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
cache: more checks, comment cleanup
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 15 Jun 2018 15:31:41 +0000 (17:31 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 15 Jun 2018 15:31:41 +0000 (17:31 +0200)
lib/cache/entry_list.c
lib/cache/entry_rr.c
lib/cache/impl.h
lib/cache/nsec3.c
lib/cache/peek.c

index e8d63d5a33eaa6d94585ffb74b9d7340edeb7109..e6e1a227909e69d74628914ceb949948a70c914c 100644 (file)
@@ -239,6 +239,7 @@ int entry_h_splice(
                        eh_orig = entry_h_consistent(val, type);
                }
        } else {
+               /* We want to fully overwrite the entry, so don't even read it. */
                memset(el, 0, sizeof(el));
        }
 
index 729cb593474a4ec26df7844e4e7493843379acac..5cfe747e4ebda171249b05f127ee3c32810c95fb 100644 (file)
@@ -109,9 +109,9 @@ int entry2answer(struct answer *ans, int id,
 {
        /* We assume it's zeroed.  Do basic sanity check. */
        if (ans->rrsets[id].set.rr || ans->rrsets[id].sig_rds.data
-         /*  || (type == KNOT_RRTYPE_NSEC && ans->nsec_v != 1)
-           || (type == KNOT_RRTYPE_NSEC3 && ans->nsec_v != 3)
-          */ )
+           || (type == KNOT_RRTYPE_NSEC  &&  ans->nsec_p.raw)
+           || (type == KNOT_RRTYPE_NSEC3 && !ans->nsec_p.raw)
+          )
        {
                assert(false);
                return kr_error(EINVAL);
@@ -129,21 +129,20 @@ int entry2answer(struct answer *ans, int id,
        ans->rrsets[id].set.rank = eh->rank;
        ans->rrsets[id].set.expiring = is_expiring(eh->ttl, new_ttl);
        /* Materialize the RRSIG RRset for the answer in (pseudo-)packet. */
-       bool want_rrsigs = true; // TODO
+       bool want_rrsigs = true; /* LATER(optim.): might be omitted in some cases. */
        if (want_rrsigs) {
                ret = rdataset_materialize(&ans->rrsets[id].sig_rds, eh->data + data_off,
                                           eh_bound, new_ttl, ans->mm);
                if (ret < 0) goto fail;
-
-               // TODO
-               #if 0
-               /* sanity check: we consumed exactly all data */
-               int unused_bytes = eh_bound - (void *)eh->data - data_off - ret;
-               if (ktype != KNOT_RRTYPE_NS && unused_bytes) {
-                       /* ^^ it doesn't have to hold in multi-RRset entries; LATER: more checks? */
-                       VERBOSE_MSG(qry, "BAD?  Unused bytes: %d\n", unused_bytes);
+               /* Sanity check: we consumed exactly all data. */
+               int unused_bytes = eh_bound - (uint8_t *)eh->data - data_off - ret;
+               if (unused_bytes) {
+                       kr_log_error("[cach] entry2answer ERROR: unused bytes: %d\n",
+                                       unused_bytes);
+                       assert(!EILSEQ);
+                       ret = kr_error(EILSEQ);
+                       goto fail; /* to be on the safe side */
                }
-               #endif
        }
        return kr_ok();
 fail:
index 2360c9750c7f62078f42980bb5b896dd1ff850dd..3ef8e4c6fc6306322c1d81f6a579828d715dfbb6 100644 (file)
@@ -157,7 +157,12 @@ static inline knot_db_val_t key_exact_type(struct key *k, uint16_t type)
 
 enum { ENTRY_APEX_NSECS_CNT = 2 };
 
-/** Header of 'E' entry with ktype == NS.  Inside is private to ./entry_list.c */
+/** Header of 'E' entry with ktype == NS.  Inside is private to ./entry_list.c
+ *
+ * We store xNAME at NS type to lower the number of searches in closest_NS().
+ * CNAME is only considered for equal name, of course.
+ * We also store NSEC* parameters at NS type.
+ */
 struct entry_apex {
        /* ENTRY_H_FLAGS */
        bool has_ns : 1;
index 2c1ca9b4adae2917acf8f4f71c30fcac39cc006b..076cfb03bd1c899e770b8d837e1d704360b29982 100644 (file)
@@ -274,7 +274,6 @@ static void nsec3_hash2text(const knot_dname_t *owner, char *text)
 int nsec3_encloser(struct key *k, struct answer *ans,
                   const int sname_labels, int *clencl_labels,
                   const struct kr_query *qry, struct kr_cache *cache)
-       /* TODO: cleanup params */
 {
        static const int ESKIP = ABS(ENOENT);
        /* Basic sanity check. */
@@ -431,7 +430,6 @@ int nsec3_encloser(struct key *k, struct answer *ans,
 
 int nsec3_src_synth(struct key *k, struct answer *ans, const knot_dname_t *clencl_name,
                    const struct kr_query *qry, struct kr_cache *cache)
-       /* TODO: cleanup params */
 {
        /* Find a previous-or-equal NSEC3 in cache covering or matching
         * the source of synthesis, checking TTL etc. */
index 15f757ec8a425062b2adf3f1ab9e3fed55629271..c16e75e902a9520741909c49b642853b56a8a506 100644 (file)
@@ -524,12 +524,9 @@ static int try_wild(struct key *k, struct answer *ans, const knot_dname_t *clenc
 }
 
 /** Find the longest prefix zone/xNAME (with OK time+rank), starting at k->*.
- * We store xNAME at NS type to lower the number of searches.
- * CNAME is only considered for equal name, of course.
- * We also store NSEC* parameters at NS type; probably the latest two will be kept.
- * Found type is returned via k->type.
  *
- * \return raw entry from cache (for NS) or rewound entry (xNAME) FIXME
+ * Found type is returned via k->type; the values are returned in el.
+ * \return error code
  */
 static int closest_NS(kr_layer_t *ctx, struct key *k, entry_list_t el)
 {