]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
add compatibility with libknot 2.9
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 6 Sep 2019 07:54:32 +0000 (09:54 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Fri, 20 Sep 2019 08:14:00 +0000 (10:14 +0200)
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.

NEWS
lib/cache/entry_list.c
lib/cache/entry_rr.c
lib/cache/impl.h
lib/zonecut.c
lib/zonecut.h

diff --git a/NEWS b/NEWS
index 72b55fd533d4ea9e0786dd8f5a2e85735e9ab380..322f44a4bcef64ff880eb05cf5f8d498b066a143 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -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)
 ================================
index 3d0d8165d45c6850c0f0f83e5b9a9652e00b5508..4969b5df5a72f34b9584c2bb62a2dae40ce4e6a1 100644 (file)
@@ -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);
index 94dd0e83e702c1465f9b8e0f51cc390c09d07ec5..f6d9168ad2b7a6c67255f95420ff396514722770 100644 (file)
@@ -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);
index 6afd389a46ee7baeda517e9b6aee699a5eb55906..f38a93ca35249811494fd032516e4b780c103128 100644 (file)
@@ -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. */
index 248a4c5cea8b312ab6362ef07bb55cb8bd054964..c8497787bb736d53d28b060e33003a74402da2f2 100644 (file)
@@ -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;
index 2808c66d151ca03f85167ef73d8375fda9912069..4de4087c0fc1fe5fa425517798967b8b371557af 100644 (file)
 #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;