]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
lib/cache: make entry_h_consistent() generic
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 14 Jun 2019 12:48:21 +0000 (14:48 +0200)
committerPetr Špaček <petr.spacek@nic.cz>
Wed, 3 Jul 2019 13:30:22 +0000 (15:30 +0200)
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.

lib/cache/api.c
lib/cache/entry_list.c
lib/cache/impl.h
lib/cache/peek.c

index c851e7fb5a294945fdc32b2f05c252f9fbac0dcd..795755f628d055e9c9d8c8780467cb3f307a3b54 100644 (file)
@@ -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);
index 6a5001c1b7010bb68746f8af971371108bd81abf..3d0d8165d45c6850c0f0f83e5b9a9652e00b5508 100644 (file)
@@ -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. */
index 4d36b921b41419dbccfd8fd69de30ddf3dfe7d94..80478d466d14413d32b50898caeff717664b998d 100644 (file)
@@ -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 */
 
index a84daffd71da91a4046d1cd8ab360b3aa044675b..558a594abcf13770a34313fcbd1e482a1b07cdb0 100644 (file)
@@ -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);