Also fix a related bug in pktcache.
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 */
}
/* 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) {
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);
/**
* 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)
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. */
/* @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 */