From: Vladimír Čunát Date: Fri, 15 Jun 2018 15:31:41 +0000 (+0200) Subject: cache: more checks, comment cleanup X-Git-Tag: v2.4.0~19^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5610327119c100e2cab2e78a2fa3d1f8cd9cd4ab;p=thirdparty%2Fknot-resolver.git cache: more checks, comment cleanup --- diff --git a/lib/cache/entry_list.c b/lib/cache/entry_list.c index e8d63d5a3..e6e1a2279 100644 --- a/lib/cache/entry_list.c +++ b/lib/cache/entry_list.c @@ -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)); } diff --git a/lib/cache/entry_rr.c b/lib/cache/entry_rr.c index 729cb5934..5cfe747e4 100644 --- a/lib/cache/entry_rr.c +++ b/lib/cache/entry_rr.c @@ -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: diff --git a/lib/cache/impl.h b/lib/cache/impl.h index 2360c9750..3ef8e4c6f 100644 --- a/lib/cache/impl.h +++ b/lib/cache/impl.h @@ -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; diff --git a/lib/cache/nsec3.c b/lib/cache/nsec3.c index 2c1ca9b4a..076cfb03b 100644 --- a/lib/cache/nsec3.c +++ b/lib/cache/nsec3.c @@ -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. */ diff --git a/lib/cache/peek.c b/lib/cache/peek.c index 15f757ec8..c16e75e90 100644 --- a/lib/cache/peek.c +++ b/lib/cache/peek.c @@ -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) {