]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
modules/dns64: fix incorrect packet writes for cached packets
authorOto Šťáva <oto.stava@nic.cz>
Fri, 18 Mar 2022 14:22:08 +0000 (15:22 +0100)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 21 Mar 2022 09:56:13 +0000 (10:56 +0100)
Also change the return type of kr_pkt_has_dnssec() and lua's :dobit()

NEWS
daemon/lua/kres-gen-30.lua
daemon/lua/kres-gen-31.lua
daemon/lua/kres-gen.sh
daemon/lua/kres.lua
lib/cache/api.h
lib/cache/knot_pkt.c
lib/utils.c
lib/utils.h
modules/dns64/dns64.lua

diff --git a/NEWS b/NEWS
index bd3bc0b8bcdf6d43aa1aaefe418d5eee347ad5fd..3957e9191d4b75e6065a15f809ad02b791794e06 100644 (file)
--- 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)
 ================================
 
index ca701affd66c6b04fccc955271a35b0816b74a25..b2164652f1f3cd8425e752c066797b5e8e5aae09 100644 (file)
@@ -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 *);
index 0e4fb9a396423c3cbae09883c835022e3e19331a..bcbd4a99c600b281c901720f7da64cfbc98e8abc 100644 (file)
@@ -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 *);
index c8e1ce80e6cbdbf1009635fa6ceb32ae18205014..0e660dcd6fcc72344d36979a2501a1788089a7af 100755 (executable)
@@ -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
index 7a00d232d3ef19c5caac22e8f7eaa9811baf3f8a..84198be4191c0cf37db030e0266c9413ee7dd159 100644 (file)
@@ -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)
index 56ae837dc84bf3448fcb6c9fc0f67344e3264443..76cbebc1b9a5f87f2b0ba35424325e13567b6026 100644 (file)
 #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);
index f0723c229db6c0391162463674be75070f54aa12..4c3fc595386ccb46e0e154afe7d585f7320fb913 100644 (file)
@@ -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();
index 57b9512f1ad1a4adab4d4acfaf9d849d92da6652..29d0ce4e6519dab4bd4eb7326d8115215b5f6ce9 100644 (file)
@@ -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);
 }
index 47e13807cee3cfdd5676e8eb7719b8b375ea7edb..cdcda131a51ecdb84eac016ac91473d0bfca3031 100644 (file)
 #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);
index 0f81ed2141ae640d1df5a454688206eaf8f3761a..b4fb1ecb7d1d78f6fbd40a9f19bac4e4b3f552b9 100644 (file)
@@ -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