From 559d61b38e5dc036584261be5a8007a79ddeb120 Mon Sep 17 00:00:00 2001 From: Tomas Krizek Date: Wed, 10 Feb 2021 16:01:17 +0100 Subject: [PATCH] bump required Knot DNS version to 2.9 --- daemon/lua/kres-gen.lua | 9 +++++++ daemon/lua/kres-gen.sh | 4 +-- daemon/lua/kres.lua | 35 +------------------------ distro/deb/control | 2 +- distro/rpm/knot-resolver.spec | 6 ++--- doc/build.rst | 2 +- doc/upgrading.rst | 4 +++ lib/cache/entry_rr.c | 18 +++++-------- lib/cache/impl.h | 2 +- lib/utils.c | 17 +++++------- lib/zonecut.c | 2 +- lib/zonecut.h | 10 +------ meson.build | 2 +- modules/edns_keepalive/edns_keepalive.c | 6 +---- modules/nsid/nsid.c | 6 +---- 15 files changed, 41 insertions(+), 84 deletions(-) diff --git a/daemon/lua/kres-gen.lua b/daemon/lua/kres-gen.lua index c4288530a..6ae0557b3 100644 --- a/daemon/lua/kres-gen.lua +++ b/daemon/lua/kres-gen.lua @@ -14,6 +14,15 @@ typedef struct { uint16_t compress_ptr[16]; } knot_rrinfo_t; typedef unsigned char knot_dname_t; +typedef struct { + uint16_t len; + uint8_t data[]; +} knot_rdata_t; +typedef struct { + uint16_t count; + uint32_t size; + knot_rdata_t *rdata; +} knot_rdataset_t; typedef struct knot_mm { void *ctx, *alloc, *free; diff --git a/daemon/lua/kres-gen.sh b/daemon/lua/kres-gen.sh index 4b25f714d..e4745a8a5 100755 --- a/daemon/lua/kres-gen.sh +++ b/daemon/lua/kres-gen.sh @@ -64,8 +64,8 @@ ${CDEFS} ${LIBKRES} types <<-EOF knot_section_t knot_rrinfo_t knot_dname_t - #knot_rdata_t - #knot_rdataset_t + knot_rdata_t + knot_rdataset_t EOF # The generator doesn't work well with typedefs of functions. diff --git a/daemon/lua/kres.lua b/daemon/lua/kres.lua index 3bc2dbf7f..640d8427d 100644 --- a/daemon/lua/kres.lua +++ b/daemon/lua/kres.lua @@ -46,6 +46,7 @@ struct sockaddr { uint16_t sa_family; uint8_t _stub[]; /* Do not touch */ }; + struct knot_error { int code; }; @@ -59,40 +60,6 @@ int inet_pton(int af, const char *src, void *dst); int gettimeofday(struct timeval *tv, struct timezone *tz); ]] - --- TMP: compatibility with both libknot 2.8 and 2.9 -local knot_rdataset_t_cdef -local sover_pos = string.find(libknot_SONAME, '%d') -if not sover_pos then - error('unexpected libknot soname: ' .. libknot_SONAME) -end -local sover = string.sub(libknot_SONAME, sover_pos , sover_pos) -if sover == '9' then - knot_rdataset_t_cdef = [[ - typedef struct { - uint16_t count; - knot_rdata_t *rdata; - } knot_rdataset_t; - ]] -elseif sover == '1' then -- it's 10 really, but this is simpler - knot_rdataset_t_cdef = [[ - typedef struct { - uint16_t count; - uint32_t size; - knot_rdata_t *rdata; - } knot_rdataset_t; - ]] -else - error('unexpected libknot version: ' .. sover) -end -ffi.cdef([[ - typedef struct { - uint16_t len; - uint8_t data[]; - } knot_rdata_t; - ]] .. knot_rdataset_t_cdef) - - require('kres-gen') -- Error code representation diff --git a/distro/deb/control b/distro/deb/control index ac9f5b9fa..8c4432305 100644 --- a/distro/deb/control +++ b/distro/deb/control @@ -10,7 +10,7 @@ Build-Depends: libedit-dev, libfstrm-dev, libgnutls28-dev, - libknot-dev (>= 2.8), + libknot-dev (>= 2.9), liblmdb-dev, libluajit-5.1-dev, libnghttp2-dev, diff --git a/distro/rpm/knot-resolver.spec b/distro/rpm/knot-resolver.spec index 7d43bbc03..ef4c8677c 100644 --- a/distro/rpm/knot-resolver.spec +++ b/distro/rpm/knot-resolver.spec @@ -42,9 +42,9 @@ BuildRequires: meson BuildRequires: pkgconfig(cmocka) BuildRequires: pkgconfig(gnutls) BuildRequires: pkgconfig(libedit) -BuildRequires: pkgconfig(libknot) >= 2.8 -BuildRequires: pkgconfig(libzscanner) >= 2.8 -BuildRequires: pkgconfig(libdnssec) >= 2.8 +BuildRequires: pkgconfig(libknot) >= 2.9 +BuildRequires: pkgconfig(libzscanner) >= 2.9 +BuildRequires: pkgconfig(libdnssec) >= 2.9 BuildRequires: pkgconfig(libnghttp2) BuildRequires: pkgconfig(libsystemd) BuildRequires: pkgconfig(libcap-ng) diff --git a/doc/build.rst b/doc/build.rst index 095568f73..9e854505d 100644 --- a/doc/build.rst +++ b/doc/build.rst @@ -33,7 +33,7 @@ The following dependencies are needed to build and run Knot Resolver: "meson >= 0.46", "*build only* [#]_" "C and C++ compiler", "*build only* [#]_" "`pkg-config`_", "*build only* [#]_" - "libknot_ 2.8+", "Knot DNS libraries" + "libknot_ 2.9+", "Knot DNS libraries" "LuaJIT_ 2.0+", "Embedded scripting language" "libuv_ 1.7+", "Multiplatform I/O and services" "lmdb", "Memory-mapped database for cache" diff --git a/doc/upgrading.rst b/doc/upgrading.rst index 054f27196..ff739f7a1 100644 --- a/doc/upgrading.rst +++ b/doc/upgrading.rst @@ -38,6 +38,10 @@ Configuration file * Module ``dnstap``: option ``log_responses`` has been moved inside a new ``client`` section. Refer to the configuration example in :ref:`mod-dnstap`. +Packagers & Developers +---------------------- + +* Knot DNS >= 2.9 is required. 5.1 to 5.2 ========== diff --git a/lib/cache/entry_rr.c b/lib/cache/entry_rr.c index 37359629f..5e7d26f2e 100644 --- a/lib/cache/entry_rr.c +++ b/lib/cache/entry_rr.c @@ -24,9 +24,8 @@ int rdataset_dematerialize(const knot_rdataset_t *rds, uint8_t * restrict data) memcpy(data, &rr_count, sizeof(rr_count)); data += sizeof(rr_count); if (rr_count) { - size_t size = knot_rdataset_size(rds); - memcpy(data, rds->rdata, size); - data += size; + memcpy(data, rds->rdata, rds->size); + data += rds->size; } //VERBOSE_MSG(NULL, "dematerialized to %d B\n", (int)(data - data0)); (void)data; @@ -45,12 +44,9 @@ static int rdataset_materialize(knot_rdataset_t * restrict rds, const uint8_t * const uint8_t *d = data; /* iterates over the cache data */ /* First sum up the sizes for wire format length. */ /* TODO: we might overrun here already, but we need to trust cache anyway...*/ - const uint32_t rds_size = rdataset_dematerialized_size(d, &rds->count); + rds->size = rdataset_dematerialized_size(d, &rds->count); d += KR_CACHE_RR_COUNT_SIZE; - #if KNOT_VERSION_HEX >= 0x020900 - rds->size = rds_size; - #endif - if (d + rds_size > data_bound) { + if (d + rds->size > data_bound) { VERBOSE_MSG(NULL, "materialize: EILSEQ!\n"); return kr_error(EILSEQ); } @@ -58,12 +54,12 @@ static int rdataset_materialize(knot_rdataset_t * restrict rds, const uint8_t * rds->rdata = NULL; return d - data; } - rds->rdata = mm_alloc(pool, rds_size); + rds->rdata = mm_alloc(pool, rds->size); if (!rds->rdata) { return kr_error(ENOMEM); } - memcpy(rds->rdata, d, rds_size); - d += rds_size; + memcpy(rds->rdata, d, rds->size); + d += rds->size; //VERBOSE_MSG(NULL, "materialized from %d B\n", (int)(d - data)); return d - data; } diff --git a/lib/cache/impl.h b/lib/cache/impl.h index 6751cf1a1..b884c361a 100644 --- a/lib/cache/impl.h +++ b/lib/cache/impl.h @@ -292,7 +292,7 @@ int32_t get_new_ttl(const struct entry_h *entry, const struct kr_query *qry, /** Compute size of serialized rdataset. NULL is accepted as empty set. */ static inline int rdataset_dematerialize_size(const knot_rdataset_t *rds) { - return KR_CACHE_RR_COUNT_SIZE + (rds == NULL ? 0 : knot_rdataset_size(rds)); + return KR_CACHE_RR_COUNT_SIZE + (rds == NULL ? 0 : rds->size); } /** Analyze the length of a dematerialized rdataset. diff --git a/lib/utils.c b/lib/utils.c index a13a615e2..4aad30514 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -824,19 +824,16 @@ int kr_ranked_rrarray_finalize(ranked_rr_array_t *array, uint32_t qry_uid, knot_ } } /* Prepare rdataset, except rdata contents. */ - int size_sum = 0; + knot_rdataset_t *rds = &stashed->rr->rrs; + rds->size = 0; for (int i = 0; i < ra->len; ++i) { if (ra->at[i]) { - size_sum += knot_rdata_size(ra->at[i]->len); + rds->size += knot_rdata_size(ra->at[i]->len); } } - knot_rdataset_t *rds = &stashed->rr->rrs; rds->count = ra->len - dup_count; - #if KNOT_VERSION_HEX >= 0x020900 - rds->size = size_sum; - #endif - if (size_sum) { - rds->rdata = mm_alloc(pool, size_sum); + if (rds->size) { + rds->rdata = mm_alloc(pool, rds->size); if (!rds->rdata) { return kr_error(ENOMEM); } @@ -846,13 +843,13 @@ int kr_ranked_rrarray_finalize(ranked_rr_array_t *array, uint32_t qry_uid, knot_ /* Everything is ready; now just copy all the rdata. */ uint8_t *raw_it = (uint8_t *)rds->rdata; for (int i = 0; i < ra->len; ++i) { - if (ra->at[i] && size_sum/*linters*/) { + if (ra->at[i] && rds->size/*linters*/) { const int size = knot_rdata_size(ra->at[i]->len); memcpy(raw_it, ra->at[i], size); raw_it += size; } } - assert(raw_it == (uint8_t *)rds->rdata + size_sum); + assert(raw_it == (uint8_t *)rds->rdata + rds->size); } stashed->in_progress = false; } diff --git a/lib/zonecut.c b/lib/zonecut.c index 7227bf9c0..cf7bfea46 100644 --- a/lib/zonecut.c +++ b/lib/zonecut.c @@ -322,7 +322,7 @@ static addrset_info_t fetch_addr(pack_t *addrs, const knot_dname_t *ns, uint16_t /* Reserve memory in *addrs. Implementation detail: * pack_t cares for lengths, so we don't store those in the data. */ - const size_t pack_extra_size = knot_rdataset_size(&cached_rr.rrs) + const size_t pack_extra_size = cached_rr.rrs.size - cached_rr.rrs.count * offsetof(knot_rdata_t, len); int ret = pack_reserve_mm(*addrs, cached_rr.rrs.count, pack_extra_size, kr_memreserve, mm_pool); diff --git a/lib/zonecut.h b/lib/zonecut.h index 8800e6703..56ca834d4 100644 --- a/lib/zonecut.h +++ b/lib/zonecut.h @@ -10,14 +10,6 @@ #include "lib/generic/trie.h" -/* TMP: compatibility for using libknot 2.8 API with 2.9. */ -#if KNOT_VERSION_HEX >= 0x020900 -static inline size_t knot_rdataset_size(const knot_rdataset_t *rrs) -{ - return rrs->size; -} -#endif - struct kr_rplan; struct kr_context; @@ -127,7 +119,7 @@ int kr_zonecut_del_all(struct kr_zonecut *cut, const knot_dname_t *ns); * * @note This can be used for membership test, a non-null pack is returned * if the nameserver name exists. - * + * * @param cut * @param ns name server name * @return pack of addresses or NULL diff --git a/meson.build b/meson.build index 9c026302c..2f6509a2e 100644 --- a/meson.build +++ b/meson.build @@ -18,7 +18,7 @@ endif message('--- required dependencies ---') -knot_version = '>=2.8' +knot_version = '>=2.9' libknot = dependency('libknot', version: knot_version) libdnssec = dependency('libdnssec', version: knot_version) libzscanner = dependency('libzscanner', version: knot_version) diff --git a/modules/edns_keepalive/edns_keepalive.c b/modules/edns_keepalive/edns_keepalive.c index ebf26aab7..3d379f510 100644 --- a/modules/edns_keepalive/edns_keepalive.c +++ b/modules/edns_keepalive/edns_keepalive.c @@ -24,11 +24,7 @@ static int edns_keepalive_finalize(kr_layer_t *ctx) const bool ka_want = req->qsource.flags.tcp && src_opt != NULL && - knot_edns_get_option(src_opt, KNOT_EDNS_OPTION_TCP_KEEPALIVE - #if KNOT_VERSION_HEX >= 0x020900 - , NULL - #endif - ) && + knot_edns_get_option(src_opt, KNOT_EDNS_OPTION_TCP_KEEPALIVE, NULL) && answ_opt != NULL; if (!ka_want) { return ctx->state; diff --git a/modules/nsid/nsid.c b/modules/nsid/nsid.c index fa7a4947a..c0eabfdc4 100644 --- a/modules/nsid/nsid.c +++ b/modules/nsid/nsid.c @@ -30,11 +30,7 @@ static int nsid_finalize(kr_layer_t *ctx) { if (src_opt == NULL) return ctx->state; - const uint8_t *req_nsid = knot_edns_get_option(src_opt, KNOT_EDNS_OPTION_NSID - #if KNOT_VERSION_HEX >= 0x020900 - , NULL - #endif - ); + const uint8_t *req_nsid = knot_edns_get_option(src_opt, KNOT_EDNS_OPTION_NSID, NULL); /* NSID option must be explicitly requested */ if (req_nsid == NULL) return ctx->state; -- 2.47.2