Commit ed83b973 authored by Vladimír Čunát's avatar Vladimír Čunát Committed by Petr Špaček

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.
parent 1b78de8e
......@@ -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;
......@@ -601,7 +601,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. */
{
......@@ -804,7 +804,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);
......
......@@ -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. */
......
......@@ -64,7 +64,7 @@ struct entry_apex;
* (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 +72,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 */
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment