(regression since 4.1.0 release, in less common cases)
- prefill module: allow a different module-loading style (#506)
+Improvements
+------------
+- add compatibility with (future) libknot 2.9
+
Knot Resolver 4.2.0 (2019-08-05)
================================
if (!eh->is_packet) { /* Positive RRset + its RRsig set (may be empty). */
int sets = 2;
while (sets-- > 0) {
- d += rdataset_dematerialized_size(d);
+ d += KR_CACHE_RR_COUNT_SIZE + rdataset_dematerialized_size(d, NULL);
if (d > data_bound) {
assert(!EILSEQ);
return kr_error(EILSEQ);
/*&& !((size_t)data & 1)*/);
assert(pool); /* not required, but that's our current usage; guard leaks */
const uint8_t *d = data; /* iterates over the cache data */
- {
- uint16_t rr_count;
- memcpy(&rr_count, d, sizeof(rr_count));
- d += sizeof(rr_count);
- rds->count = rr_count;
- if (!rr_count) { /* avoid mm_alloc(pool, 0); etc. */
- return d - data;
- }
- }
/* First sum up the sizes for wire format length. */
- const knot_rdataset_t rds_tmp = {
- .count = rds->count,
- .rdata = (knot_rdata_t *)d,
- };
- size_t rds_size = knot_rdataset_size(&rds_tmp); /* TODO: we might overrun here already,
- but we need to trust cache anyway...*/
+ /* TODO: we might overrun here already, but we need to trust cache anyway...*/
+ const uint32_t rds_size = rdataset_dematerialized_size(d, &rds->count);
+ d += KR_CACHE_RR_COUNT_SIZE;
+ #if KNOT_VERSION_MINOR >= 9
+ rds->size = rds_size;
+ #endif
if (d + rds_size > data_bound) {
VERBOSE_MSG(NULL, "materialize: EILSEQ!\n");
return kr_error(EILSEQ);
}
+ if (!rds->count) { /* avoid mm_alloc(pool, 0); etc. */
+ rds->rdata = NULL;
+ return d - data;
+ }
rds->rdata = mm_alloc(pool, rds_size);
if (!rds->rdata) {
return kr_error(ENOMEM);
return KR_CACHE_RR_COUNT_SIZE + (rds == NULL ? 0 : knot_rdataset_size(rds));
}
-static inline int rdataset_dematerialized_size(const uint8_t *data)
+/** Analyze the length of a dematerialized rdataset.
+ * Note that in the data it's KR_CACHE_RR_COUNT_SIZE and then this returned size. */
+static inline int rdataset_dematerialized_size(const uint8_t *data, uint16_t *rdataset_count)
{
- knot_rdataset_t rds;
- memcpy(&rds.count, data, sizeof(rds.count));
- rds.rdata = (knot_rdata_t *)(data + sizeof(rds.count));
- return sizeof(rds.count) + knot_rdataset_size(&rds);
+ uint16_t count;
+ assert(sizeof(count) == KR_CACHE_RR_COUNT_SIZE);
+ memcpy(&count, data, sizeof(count));
+ const uint8_t *rdata = data + sizeof(count);
+ if (rdataset_count)
+ *rdataset_count = count;
+ for (int i = 0; i < count; ++i)
+ rdata += knot_rdata_size(((knot_rdata_t *)rdata)->len);
+ return rdata - (data + sizeof(count));
}
/** Serialize an rdataset. */
return kr_error(ESTALE);
}
/* Materialize the rdataset temporarily, for simplicity. */
- knot_rdataset_t ns_rds = { 0, NULL };
+ knot_rdataset_t ns_rds = { 0 };
ret = kr_cache_materialize(&ns_rds, &peek, cut->pool);
if (ret < 0) {
return ret;
#include "lib/generic/pack.h"
#include "lib/generic/trie.h"
+
+/* TMP: compatibility for using libknot 2.8 API with 2.9. */
+#if KNOT_VERSION_MINOR >= 9
+static inline size_t knot_rdataset_size(const knot_rdataset_t *rrs)
+{
+ return rrs->size;
+}
+#endif
+
struct kr_rplan;
struct kr_context;