]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
kr_rank: use functions to manipulate the non-flag part
authorVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 5 Apr 2017 09:05:12 +0000 (11:05 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Wed, 5 Apr 2017 09:06:19 +0000 (11:06 +0200)
Also fix a related bug in pktcache.

lib/layer/pktcache.c
lib/layer/validate.c
lib/resolve.h

index 39f4405045c88b5e93ca150883f54d2dd8b555d2..b617e3ad30e4cb5a9a525a61f1507ad7ce4e5076 100644 (file)
@@ -70,8 +70,8 @@ static int loot_pktcache(struct kr_cache *cache, knot_pkt_t *pkt,
                return ret;
        }
 
-       if (!knot_wire_get_cd(req->answer->wire)
-           && (entry->rank & KR_RANK_BAD) && !(entry->rank & KR_RANK_OMIT)) {
+       const uint8_t rank_val = rank_get_value(entry->rank);
+       if (!knot_wire_get_cd(req->answer->wire) && rank_val && rank_val != KR_RANK_OMIT) {
                return kr_error(ENOENT); /* it would fail anyway */
        }
 
@@ -234,10 +234,10 @@ static int pktcache_stash(kr_layer_t *ctx, knot_pkt_t *pkt)
 
        /* If cd bit is set, make rank bad, otherwise it depends on flags. */
        if (knot_wire_get_cd(req->answer->wire)) {
-               header.rank |= KR_RANK_OMIT;
+               rank_set_value(&header.rank, KR_RANK_OMIT);
        } else {
                if (qry->flags & QUERY_DNSSEC_BOGUS) {
-                       header.rank |= KR_RANK_BOGUS;
+                       rank_set_value(&header.rank, KR_RANK_BOGUS);
                } else if (qry->flags & QUERY_DNSSEC_INSECURE) {
                        header.rank |= KR_RANK_INSECURE;
                } else if (qry->flags & QUERY_DNSSEC_WANT) {
index e2b7c36473112a15aadc2eafaad7358b4d1c1f3b..49993228c5a8287a5322550c0ae9e8b7b41d6af4 100644 (file)
@@ -76,22 +76,11 @@ static bool pkt_has_type(const knot_pkt_t *pkt, uint16_t type)
        return section_has_type(knot_pkt_section(pkt, KNOT_ADDITIONAL), type);
 }
 
-static inline uint8_t rank_get_value(uint8_t rank)
-{
-       return rank & 0x07;
-}
-
 static inline uint8_t rank_get_flags(uint8_t rank)
 {
        return rank & ~0x07;
 }
 
-static inline void rank_set_value(uint8_t *rank, uint8_t value)
-{
-       assert(rank);
-       *rank = rank_get_flags(*rank) | rank_get_value(value);
-}
-
 static inline void rank_set_flag(uint8_t *rank, uint8_t flag)
 {
        assert(rank);
index e10ab2424b514170384ec422f4b1060c11a78eee..442275801a575297f06d868c26d0943420e1e41c 100644 (file)
@@ -76,6 +76,9 @@
 /**
  * RRset rank - for cache and ranked_rr_*.
  *
+ * The rank has three one-bit flags and additionally several values.
+ * The values are best manipulated via rank_*_value functions.
+ *
  * @note Be careful about chosen cache rank nominal values.
  * - AUTH must be > than !AUTH
  * - AUTH INSECURE must be > than AUTH (because it attempted validation)
@@ -88,7 +91,7 @@
 enum kr_rank {
        KR_RANK_INITIAL = 0,
 
-       KR_RANK_BAD = 7,  /**< For simple manipulation with the four below. */
+       KR_RANK_BAD = 7,  /**< For simpler manipulation with the four values below. */
        KR_RANK_OMIT = 1, /**< Do not validate. */
        KR_RANK_INDET,    /**< Unable to determine whether it should be secure. */
        KR_RANK_BOGUS,    /**< Ought to be secure but isn't. */
@@ -105,6 +108,16 @@ enum kr_rank {
        /* @note Rank must not exceed 6 bits */
 };
 
+static inline uint8_t rank_get_value(uint8_t rank)
+{
+       return rank & KR_RANK_BAD;
+}
+static inline void rank_set_value(uint8_t *rank, uint8_t val)
+{
+       assert(rank && (val & KR_RANK_BAD) == val);
+       *rank = (*rank & ~KR_RANK_BAD) | val;
+}
+
 /** @cond internal Array of modules. */
 typedef array_t(struct kr_module *) module_array_t;
 /* @endcond */