size_t rdata_len_sum = 0;
for (int i = 0; i < rds->rr_count; ++i) {
if (d + 2 > data_bound) {
+ VERBOSE_MSG(NULL, "materialize: EILSEQ!\n");
return kr_error(EILSEQ);
}
uint16_t len;
//d_out = kr_rdataset_next(d_out);
d_out += 4 + 2 + len; /* TTL + rdlen + rdata */
}
+ VERBOSE_MSG(NULL, "materialized from %d B\n", (int)(d - data));
return d - data;
}
int kr_cache_materialize(knot_rdataset_t *dst, const struct kr_cache_p *ref,
uint32_t new_ttl, knot_mm_t *pool)
{
- return rdataset_materialize(dst, ref->data, ref->data_bound, new_ttl, pool);
+ struct entry_h *eh = ref->raw_data;
+ return rdataset_materialize(dst, eh->data, ref->raw_bound, new_ttl, pool);
}
/** Compute size of dematerialized rdataset. NULL is accepted as empty set. */
return kr_ok();
}
-/** Append an RRset into the current section (*shallow* copy), with given rank. */
+/** Append an RRset into the current section (*shallow* copy), with given rank.
+ * \note it works with empty set as well (skipped). */
int pkt_append(knot_pkt_t *pkt, const knot_rrset_t *rrset, uint8_t rank)
{
+ if (!rrset->rrs.rr_count) {
+ return kr_ok();
+ }
/* allocate space, to be sure */
int ret = pkt_alloc_space(pkt, 1);
if (ret) return kr_error(ret);
/* We may have obtained the record *after* the request started. */
diff = 0;
}
- return entry->ttl - diff;
+ int32_t res = entry->ttl - diff;
+ VERBOSE_MSG(NULL, "TTL remains: %d\n", (int)res);
+ return res;
}
int32_t kr_cache_ttl(const struct kr_cache_p *peek, uint32_t current_time)
{
- const struct entry_h e = { .time = peek->time, .ttl = peek->ttl };
- return get_new_ttl(&e, current_time);
+ const struct entry_h *eh = peek->raw_data;
+ return get_new_ttl(eh, current_time);
}
/** Record is expiring if it has less than 1% TTL (or less than 5s) */
return ctx->state;
}
- /* FIXME FIXME FIXME: (mandatory) glue isn't stashed.
- * => no valid NS left for DNSKEY on TLDs
- * Perhaps let iterator pick it to auth_selected, for simplicity.
- */
-
const uint32_t min_ttl = MAX(DEFAULT_MINTTL, req->ctx->cache.ttl_min);
ranked_rr_array_t *selected[] = kr_request_selected(req);
- for (int psec = KNOT_ANSWER; psec <= KNOT_AUTHORITY; ++psec) {
+ for (int psec = KNOT_ANSWER; psec <= KNOT_ADDITIONAL; ++psec) {
const ranked_rr_array_t *arr = selected[psec];
/* uncached entries are located at the end */
for (ssize_t i = arr->len - 1; i >= 0; --i) {
ret = rdataset_materialize(&rrset.rrs, eh->data,
eh_data_bound, new_ttl, &pkt->mm);
CHECK_RET(ret);
- VERBOSE_MSG(qry, "materialized from %d B\n", ret);
size_t data_off = ret;
/* Materialize the RRSIG RRset for the answer in (pseudo-)packet. */
bool want_rrsigs = kr_rank_test(eh->rank, KR_RANK_SECURE);
eh_data_bound, new_ttl, &pkt->mm);
/* sanity check: we consumed exactly all data */
CHECK_RET(ret);
- VERBOSE_MSG(qry, "materialized from %d B\n", ret);
int unused_bytes = eh_data_bound - (void *)eh->data - data_off - ret;
if (ktype != KNOT_RRTYPE_NS && unused_bytes) {
/* ^^ it doesn't have to hold in multi-RRset entries; LATER: more checks? */
.time = eh->time,
.ttl = eh->ttl,
.rank = eh->rank,
- .data = val.data,
- .data_bound = val.data + val.len,
+ .raw_data = val.data,
+ .raw_bound = val.data + val.len,
};
kr_log_verbose("hit\n");
return kr_ok();
knot_rrset_t cached_rr;
knot_rrset_init(&cached_rr, /*const-cast*/(knot_dname_t *)ns, rrtype, KNOT_CLASS_IN);
- kr_cache_materialize(&cached_rr.rrs, &peek, new_ttl, cut->pool);
+ if (kr_cache_materialize(&cached_rr.rrs, &peek, new_ttl, cut->pool) < 0) {
+ return;
+ }
knot_rdata_t *rd = cached_rr.rrs.data;
for (uint16_t i = 0; i < cached_rr.rrs.rr_count; ++i) {
(void) kr_zonecut_add(cut, ns, rd);
/* Materialize the rdataset temporarily, for simplicity. */
knot_rdataset_t ns_rds = {};
ret = kr_cache_materialize(&ns_rds, &peek, new_ttl, cut->pool);
- if (ret != 0) {
+ if (ret < 0) {
return ret;
}
}
knot_rrset_init(*rr, /*const-cast*/(knot_dname_t *)owner, type, KNOT_CLASS_IN);
ret = kr_cache_materialize(&(*rr)->rrs, &peek, new_ttl, pool);
- if (ret != 0) {
+ if (ret < 0) {
knot_rrset_free(rr, pool);
return ret;
}
int kr_zonecut_find_cached(struct kr_context *ctx, struct kr_zonecut *cut, const knot_dname_t *name,
uint32_t timestamp, bool * restrict secured)
{
+ kr_log_verbose("[ ][ *c ] kr_zonecut_find_cached\n");
if (!ctx || !cut || !name) {
return kr_error(EINVAL);
}
update_cut_name(cut, label);
mm_free(cut->pool, qname);
kr_cache_sync(&ctx->cache);
+ WITH_VERBOSE {
+ kr_dname_print(label, "[ ][ *c ] and found cut: ", "\n");
+ }
return kr_ok();
}
/* Subtract label from QNAME. */