}
bool ok = true;
- ok = ok && (!kr_rank_test_noassert(eh->rank, KR_RANK_BOGUS)
+ ok = ok && kr_rank_check(eh->rank);
+ ok = ok && (!kr_rank_test(eh->rank, KR_RANK_BOGUS)
|| eh->is_packet);
ok = ok && (eh->is_packet || !eh->has_optout);
- /* doesn't hold, because of temporary NSEC3 packet caching
- if (eh->is_packet)
- ok = ok && !kr_rank_test(eh->rank, KR_RANK_SECURE);
- */
-
- //LATER: rank sanity
return ok ? /*const-cast*/(struct entry_h *)eh : NULL;
}
const bool is_negative = kr_response_classify(pkt)
& (PKT_NODATA|PKT_NXDOMAIN);
const struct kr_qflags * const qf = &qry->flags;
- const bool want_pkt = qf->DNSSEC_BOGUS
- || (is_negative && (qf->DNSSEC_INSECURE || !qf->DNSSEC_WANT));
+ const bool want_negative = qf->DNSSEC_INSECURE || !qf->DNSSEC_WANT || has_optout;
+ const bool want_pkt = qf->DNSSEC_BOGUS /*< useful for +cd answers */
+ || (is_negative && want_negative);
- if (!(want_pkt || has_optout) || !knot_wire_get_aa(pkt->wire)
- || pkt->parsed != pkt->size /* malformed packet; still can't detect KNOT_EFEWDATA */
+ if (!want_pkt || !knot_wire_get_aa(pkt->wire)
+ || pkt->parsed != pkt->size /*< malformed packet; still can't detect KNOT_EFEWDATA */
) {
return;
}
} else if (!qf->DNSSEC_WANT) {
/* no TAs at all, leave _RANK_AUTH */
} else if (has_optout) {
- /* FIXME XXX review OPTOUT in this function again! */
/* All bad cases should be filtered above,
* at least the same way as pktcache in kresd 1.5.x. */
kr_rank_set(&rank, KR_RANK_SECURE);
uint32_t ttl; /**< TTL at inception moment. Assuming it fits into int32_t ATM. */
uint8_t rank : 6; /**< See enum kr_rank */
bool is_packet : 1; /**< Negative-answer packet for insecure/bogus name. */
- bool has_optout : 1; /**< Only for packets with NSEC3. */
+ bool has_optout : 1; /**< Only for packets; persisted DNSSEC_OPTOUT. */
uint8_t data[];
};
struct entry_apex;
/* Packet caching; implementation in ./entry_pkt.c */
-/** Stash the packet into cache (if suitable, etc.) */
+/** Stash the packet into cache (if suitable, etc.)
+ * \param has_optout whether the packet contains an opt-out NSEC3 */
void stash_pkt(const knot_pkt_t *pkt, const struct kr_query *qry,
const struct kr_request *req, bool has_optout);
* have it reconstructed at this point. */
int32_t new_ttl_ = get_new_ttl(eh, qry, k->zname, KNOT_RRTYPE_NSEC,
qry->timestamp.tv_sec);
- if (new_ttl_ < 0 || !kr_rank_test_noassert(eh->rank, KR_RANK_SECURE)) {
+ if (new_ttl_ < 0 || !kr_rank_test(eh->rank, KR_RANK_SECURE)) {
return "range search found stale or insecure entry";
/* TODO: remove the stale record *and* retry,
* in case we haven't run off. Perhaps start by in_zone check. */
/* Passing just zone name instead of owner. */
int32_t new_ttl_ = get_new_ttl(eh, qry, k->zname, KNOT_RRTYPE_NSEC3,
qry->timestamp.tv_sec);
- if (new_ttl_ < 0 || !kr_rank_test_noassert(eh->rank, KR_RANK_SECURE)) {
+ if (new_ttl_ < 0 || !kr_rank_test(eh->rank, KR_RANK_SECURE)) {
return "range search found stale or insecure entry";
/* TODO: remove the stale record *and* retry,
* in case we haven't run off. Perhaps start by in_zone check. */
/** Check that a rank value is valid. Meant for assertions. */
bool kr_rank_check(uint8_t rank) KR_PURE;
-/** kr_rank_test() except that `rank` may be rubbish (don't assert that). */
-static inline bool kr_rank_test_noassert(uint8_t rank, uint8_t kr_flag)
+/** Test the presence of any flag/state in a rank, i.e. including KR_RANK_AUTH. */
+static inline bool kr_rank_test(uint8_t rank, uint8_t kr_flag)
{
- assert(kr_rank_check(kr_flag));
+ assert(kr_rank_check(rank) && kr_rank_check(kr_flag));
if (kr_flag == KR_RANK_AUTH) {
return rank & KR_RANK_AUTH;
}
/* The rest are exclusive values - exactly one has to be set. */
return (rank & ~KR_RANK_AUTH) == kr_flag;
}
-/** Test the presence of any flag/state in a rank, i.e. including KR_RANK_AUTH. */
-static inline bool kr_rank_test(uint8_t rank, uint8_t kr_flag)
-{
- assert(kr_rank_check(rank));
- return kr_rank_test_noassert(rank, kr_flag);
-}
/** Set the rank state. The _AUTH flag is kept as it was. */
static inline void kr_rank_set(uint8_t *rank, uint8_t kr_flag)