From: Vladimír Čunát Date: Fri, 14 Jun 2019 12:48:21 +0000 (+0200) Subject: lib/cache: make entry_h_consistent() generic X-Git-Tag: v4.1.0~8^2~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab18e20dbab58851b149d10c77a01503dec38e24;p=thirdparty%2Fknot-resolver.git lib/cache: make entry_h_consistent() generic Basically all use cases get renamed to *_E(), except one in utils/kr_cache_gc. It was perhaps confusing that this name only applied to 'E' entries. --- diff --git a/lib/cache/api.c b/lib/cache/api.c index c851e7fb5..795755f62 100644 --- a/lib/cache/api.c +++ b/lib/cache/api.c @@ -201,7 +201,7 @@ int kr_cache_clear(struct kr_cache *cache) } /* When going stricter, BEWARE of breaking entry_h_consistent_NSEC() */ -struct entry_h * entry_h_consistent(knot_db_val_t data, uint16_t type) +struct entry_h * entry_h_consistent_E(knot_db_val_t data, uint16_t type) { (void) type; /* unused, for now */ if (!data.data) return NULL; @@ -599,7 +599,7 @@ static ssize_t stash_rrset(struct kr_cache *cache, const struct kr_query *qry, eh->rank = 0; assert(false); } - assert(entry_h_consistent(val_new_entry, rr->type)); + assert(entry_h_consistent_E(val_new_entry, rr->type)); #if 0 /* Occasionally useful when debugging some kinds of changes. */ { @@ -802,7 +802,7 @@ static int peek_exact_real(struct kr_cache *cache, const knot_dname_t *name, uin if (!ret) ret = entry_h_seek(&val, type); if (ret) return kr_error(ret); - const struct entry_h *eh = entry_h_consistent(val, type); + const struct entry_h *eh = entry_h_consistent_E(val, type); if (!eh || eh->is_packet) { // TODO: no packets, but better get rid of whole kr_cache_peek_exact(). return kr_error(ENOENT); diff --git a/lib/cache/entry_list.c b/lib/cache/entry_list.c index 6a5001c1b..3d0d8165d 100644 --- a/lib/cache/entry_list.c +++ b/lib/cache/entry_list.c @@ -234,7 +234,7 @@ int entry_h_splice( } /* val is on the entry, in either case (or error) */ if (!ret) { - eh_orig = entry_h_consistent(val, type); + eh_orig = entry_h_consistent_E(val, type); } } else { /* We want to fully overwrite the entry, so don't even read it. */ diff --git a/lib/cache/impl.h b/lib/cache/impl.h index 4d36b921b..80478d466 100644 --- a/lib/cache/impl.h +++ b/lib/cache/impl.h @@ -63,8 +63,7 @@ struct entry_apex; /** Check basic consistency of entry_h for 'E' entries, not looking into ->data. * (for is_packet the length of data is checked) */ -KR_EXPORT -struct entry_h * entry_h_consistent(knot_db_val_t data, uint16_t type); +struct entry_h * entry_h_consistent_E(knot_db_val_t data, uint16_t type); struct entry_apex * entry_apex_consistent(knot_db_val_t val); @@ -72,12 +71,22 @@ struct entry_apex * entry_apex_consistent(knot_db_val_t val); static inline struct entry_h * entry_h_consistent_NSEC(knot_db_val_t data) { /* ATM it's enough to just extend the checks for exact entries. */ - const struct entry_h *eh = entry_h_consistent(data, KNOT_RRTYPE_NSEC); + const struct entry_h *eh = entry_h_consistent_E(data, KNOT_RRTYPE_NSEC); bool ok = eh != NULL; ok = ok && !eh->is_packet && !eh->has_optout; return ok ? /*const-cast*/(struct entry_h *)eh : NULL; } +static inline struct entry_h * entry_h_consistent(knot_db_val_t data, uint16_t type) +{ + switch (type) { + case KNOT_RRTYPE_NSEC: + case KNOT_RRTYPE_NSEC3: + return entry_h_consistent_NSEC(data); + default: + return entry_h_consistent_E(data, type); + } +} /* nsec_p* - NSEC* chain parameters */ diff --git a/lib/cache/peek.c b/lib/cache/peek.c index a84daffd7..558a594ab 100644 --- a/lib/cache/peek.c +++ b/lib/cache/peek.c @@ -258,7 +258,7 @@ int peek_nosync(kr_layer_t *ctx, knot_pkt_t *pkt) knot_db_val_t val = { NULL, 0 }; ret = cache_op(cache, read, &key, &val, 1); const struct entry_h *eh; - if (ret || !(eh = entry_h_consistent(val, KNOT_RRTYPE_SOA))) { + if (ret || !(eh = entry_h_consistent_E(val, KNOT_RRTYPE_SOA))) { assert(ret); /* only want to catch `eh` failures */ VERBOSE_MSG(qry, "=> SOA missed\n"); return ctx->state; @@ -472,7 +472,7 @@ static int found_exact_hit(kr_layer_t *ctx, knot_pkt_t *pkt, knot_db_val_t val, int ret = entry_h_seek(&val, qry->stype); if (ret) return ret; - const struct entry_h *eh = entry_h_consistent(val, qry->stype); + const struct entry_h *eh = entry_h_consistent_E(val, qry->stype); if (!eh) { assert(false); return kr_error(ENOENT); @@ -532,7 +532,7 @@ static int try_wild(struct key *k, struct answer *ans, const knot_dname_t *clenc return ret; } /* Check if the record is OK. */ - const struct entry_h *eh = entry_h_consistent(val, type); + const struct entry_h *eh = entry_h_consistent_E(val, type); if (!eh) { assert(false); return kr_error(ret); @@ -697,7 +697,7 @@ static int check_NS_entry(struct key *k, const knot_db_val_t entry, const int i, } else { type = EL2RRTYPE(i); /* Find the entry for the type, check positivity, TTL */ - const struct entry_h *eh = entry_h_consistent(entry, type); + const struct entry_h *eh = entry_h_consistent_E(entry, type); if (!eh) { VERBOSE_MSG(qry, "=> EH not consistent\n"); assert(false);