Skip to content
Snippets Groups Projects
Verified Commit 750a6967 authored by Vladimír Čunát's avatar Vladimír Čunát Committed by Tomas Krizek
Browse files

add compatibility with libknot 2.9

It's fairly easy to keep keep compatible with both 2.8 and 2.9,
so I'd go for that for now, as it may be practical.
parent f4bcca85
No related branches found
No related tags found
1 merge request!864add compatibility with libknot 2.9
......@@ -8,6 +8,10 @@ Bugfixes
(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)
================================
......
......@@ -132,7 +132,7 @@ static int entry_h_len(const knot_db_val_t val)
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);
......
......@@ -55,26 +55,21 @@ static int rdataset_materialize(knot_rdataset_t * restrict rds, const uint8_t *
/*&& !((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);
......
......@@ -307,12 +307,19 @@ static inline int rdataset_dematerialize_size(const knot_rdataset_t *rds)
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. */
......
......@@ -400,7 +400,7 @@ static int fetch_ns(struct kr_context *ctx, struct kr_zonecut *cut,
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;
......
......@@ -21,6 +21,15 @@
#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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment