From: Oto Šťáva Date: Fri, 18 Mar 2022 14:22:08 +0000 (+0100) Subject: modules/dns64: fix incorrect packet writes for cached packets X-Git-Tag: v5.5.1~25^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00be81d248de0eb78dfb4019cf2b78e887ae900e;p=thirdparty%2Fknot-resolver.git modules/dns64: fix incorrect packet writes for cached packets Also change the return type of kr_pkt_has_dnssec() and lua's :dobit() --- diff --git a/NEWS b/NEWS index bd3bc0b8b..3957e9191 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,11 @@ +Knot Resolver 5.5.1 (2022-mm-dd) +================================ + +Bugfixes +-------- +- modules/dns64: fix incorrect packet writes for cached packets (#727, !1275) + + Knot Resolver 5.5.0 (2022-03-15) ================================ diff --git a/daemon/lua/kres-gen-30.lua b/daemon/lua/kres-gen-30.lua index ca701affd..b2164652f 100644 --- a/daemon/lua/kres-gen-30.lua +++ b/daemon/lua/kres-gen-30.lua @@ -407,7 +407,8 @@ void kr_pkt_make_auth_header(knot_pkt_t *); int kr_pkt_put(knot_pkt_t *, const knot_dname_t *, uint32_t, uint16_t, uint16_t, const uint8_t *, uint16_t); int kr_pkt_recycle(knot_pkt_t *); int kr_pkt_clear_payload(knot_pkt_t *); -uint16_t kr_pkt_has_dnssec(const knot_pkt_t *); +_Bool kr_pkt_has_wire(const knot_pkt_t *); +_Bool kr_pkt_has_dnssec(const knot_pkt_t *); uint16_t kr_pkt_qclass(const knot_pkt_t *); uint16_t kr_pkt_qtype(const knot_pkt_t *); char *kr_pkt_text(const knot_pkt_t *); diff --git a/daemon/lua/kres-gen-31.lua b/daemon/lua/kres-gen-31.lua index 0e4fb9a39..bcbd4a99c 100644 --- a/daemon/lua/kres-gen-31.lua +++ b/daemon/lua/kres-gen-31.lua @@ -407,7 +407,8 @@ void kr_pkt_make_auth_header(knot_pkt_t *); int kr_pkt_put(knot_pkt_t *, const knot_dname_t *, uint32_t, uint16_t, uint16_t, const uint8_t *, uint16_t); int kr_pkt_recycle(knot_pkt_t *); int kr_pkt_clear_payload(knot_pkt_t *); -uint16_t kr_pkt_has_dnssec(const knot_pkt_t *); +_Bool kr_pkt_has_wire(const knot_pkt_t *); +_Bool kr_pkt_has_dnssec(const knot_pkt_t *); uint16_t kr_pkt_qclass(const knot_pkt_t *); uint16_t kr_pkt_qtype(const knot_pkt_t *); char *kr_pkt_text(const knot_pkt_t *); diff --git a/daemon/lua/kres-gen.sh b/daemon/lua/kres-gen.sh index c8e1ce80e..0e660dcd6 100755 --- a/daemon/lua/kres-gen.sh +++ b/daemon/lua/kres-gen.sh @@ -226,6 +226,7 @@ ${CDEFS} ${LIBKRES} functions <<-EOF kr_pkt_put kr_pkt_recycle kr_pkt_clear_payload + kr_pkt_has_wire kr_pkt_has_dnssec kr_pkt_qclass kr_pkt_qtype diff --git a/daemon/lua/kres.lua b/daemon/lua/kres.lua index 7a00d232d..84198be41 100644 --- a/daemon/lua/kres.lua +++ b/daemon/lua/kres.lua @@ -688,6 +688,12 @@ ffi.metatype( knot_pkt_t, { if ret ~= 0 then return nil, knot_error_t(ret) end return true end, + -- Checks whether the packet has a wire, i.e. the .size is not + -- equal to KR_PKT_SIZE_NOWIRE + has_wire = function (pkt) + assert(ffi.istype(knot_pkt_t, pkt)) + return C.kr_pkt_has_wire(pkt) + end, recycle = function (pkt) assert(ffi.istype(knot_pkt_t, pkt)) local ret = C.kr_pkt_recycle(pkt) diff --git a/lib/cache/api.h b/lib/cache/api.h index 56ae837dc..76cbebc1b 100644 --- a/lib/cache/api.h +++ b/lib/cache/api.h @@ -11,10 +11,6 @@ #include "lib/defines.h" #include "contrib/ucw/config.h" /*uint*/ -/** When knot_pkt is passed from cache without ->wire, this is the ->size. */ -static const size_t PKT_SIZE_NOWIRE = -1; - - #include "lib/module.h" /* Prototypes for the 'cache' module implementation. */ int cache_peek(kr_layer_t *ctx, knot_pkt_t *pkt); diff --git a/lib/cache/knot_pkt.c b/lib/cache/knot_pkt.c index f0723c229..4c3fc5953 100644 --- a/lib/cache/knot_pkt.c +++ b/lib/cache/knot_pkt.c @@ -20,7 +20,7 @@ int pkt_renew(knot_pkt_t *pkt, const knot_dname_t *name, uint16_t type) if (ret) return kr_error(ret); } - pkt->parsed = pkt->size = PKT_SIZE_NOWIRE; + pkt->parsed = pkt->size = KR_PKT_SIZE_NOWIRE; knot_wire_set_qr(pkt->wire); knot_wire_set_aa(pkt->wire); return kr_ok(); diff --git a/lib/utils.c b/lib/utils.c index 57b9512f1..29d0ce4e6 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -1174,7 +1174,11 @@ void kr_rrset_init(knot_rrset_t *rrset, knot_dname_t *owner, if (kr_fails_assert(rrset)) return; knot_rrset_init(rrset, owner, type, rclass, ttl); } -uint16_t kr_pkt_has_dnssec(const knot_pkt_t *pkt) +bool kr_pkt_has_wire(const knot_pkt_t *pkt) +{ + return pkt->size != KR_PKT_SIZE_NOWIRE; +} +bool kr_pkt_has_dnssec(const knot_pkt_t *pkt) { return knot_pkt_has_dnssec(pkt); } diff --git a/lib/utils.h b/lib/utils.h index 47e13807c..cdcda131a 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -29,6 +29,10 @@ #include "lib/log.h" +/** When knot_pkt is passed from cache without ->wire, this is the ->size. */ +static const size_t KR_PKT_SIZE_NOWIRE = -1; + + /* * Logging and debugging. */ @@ -543,7 +547,8 @@ const char *kr_strptime_diff(const char *format, const char *time1_str, /* Trivial non-inline wrappers, to be used in lua. */ KR_EXPORT void kr_rrset_init(knot_rrset_t *rrset, knot_dname_t *owner, uint16_t type, uint16_t rclass, uint32_t ttl); -KR_EXPORT uint16_t kr_pkt_has_dnssec(const knot_pkt_t *pkt); +KR_EXPORT bool kr_pkt_has_wire(const knot_pkt_t *pkt); +KR_EXPORT bool kr_pkt_has_dnssec(const knot_pkt_t *pkt); KR_EXPORT uint16_t kr_pkt_qclass(const knot_pkt_t *pkt); KR_EXPORT uint16_t kr_pkt_qtype(const knot_pkt_t *pkt); KR_EXPORT uint32_t kr_rrsig_sig_inception(const knot_rdata_t *rdata); diff --git a/modules/dns64/dns64.lua b/modules/dns64/dns64.lua index 0f81ed214..b4fb1ecb7 100644 --- a/modules/dns64/dns64.lua +++ b/modules/dns64/dns64.lua @@ -177,7 +177,7 @@ function M.layer.produce(_, req, pkt) then return end -- Update packet question if it was minimized. qry.flags.NO_MINIMIZE = true - if not ffi.C.knot_dname_is_equal(pkt.wire + 12, sname) then + if not ffi.C.knot_dname_is_equal(pkt.wire + 12, sname) or not pkt:has_wire() then if not pkt:recycle() or not pkt:question(sname, qry.sclass, qry.stype) then return end end