From: Vítězslav Kříž Date: Mon, 19 Jun 2017 11:17:57 +0000 (+0200) Subject: dns64-cname: correct order of CNAME and AAAA in answer X-Git-Tag: v1.3.2~12^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3be76db7610;p=thirdparty%2Fknot-resolver.git dns64-cname: correct order of CNAME and AAAA in answer If CNAME chain occurs CNAME is placed before AAAA. --- diff --git a/daemon/lua/kres-gen.lua b/daemon/lua/kres-gen.lua index c0dc75e8a..513240019 100644 --- a/daemon/lua/kres-gen.lua +++ b/daemon/lua/kres-gen.lua @@ -124,6 +124,7 @@ struct kr_request { int has_tls; knot_mm_t pool; }; +enum kr_rank {KR_RANK_INITIAL, KR_RANK_OMIT, KR_RANK_INDET, KR_RANK_BOGUS, KR_RANK_MISMATCH, KR_RANK_MISSING, KR_RANK_INSECURE = 8, KR_RANK_AUTH = 16, KR_RANK_SECURE = 32}; struct knot_rrset { knot_dname_t *_owner; uint16_t type; @@ -151,6 +152,8 @@ struct kr_query { struct timeval timestamp; struct kr_zonecut zone_cut; struct kr_nsrep ns; + struct kr_layer_pickle *deferred; + uint32_t uid; /* ^hidden stub^ */ char _stub[]; }; @@ -199,7 +202,7 @@ int kr_straddr_subnet(void *, const char *); int kr_bitcmp(const char *, const char *, int); int kr_family_len(int); struct sockaddr *kr_straddr_socket(const char *, int); -int kr_rrarray_add(rr_array_t *, const knot_rrset_t *, knot_mm_t *); +int kr_ranked_rrarray_add(ranked_rr_array_t *, const knot_rrset_t *, uint8_t, _Bool, uint32_t, knot_mm_t *); knot_rrset_t *kr_ta_get(map_t *, const knot_dname_t *); int kr_ta_add(map_t *, const knot_dname_t *, uint16_t, uint32_t, const uint8_t *, uint16_t); int kr_ta_del(map_t *, const knot_dname_t *); diff --git a/daemon/lua/kres-gen.sh b/daemon/lua/kres-gen.sh index 40d501470..46b7c119f 100755 --- a/daemon/lua/kres-gen.sh +++ b/daemon/lua/kres-gen.sh @@ -55,6 +55,7 @@ typedef void (*map_free_f)(void *baton, void *ptr); kr_qarray_t struct kr_rplan struct kr_request + enum kr_rank EOF genResType() { @@ -69,7 +70,7 @@ genResType "struct knot_rrset" | sed 's/\/_owner/' genResType "struct kr_nsrep" | sed '/union/,$ d' printf "\t/* beware: hidden stub */\n};\n" -genResType "struct kr_query" | sed '/struct kr_layer_pickle/,$ d' +genResType "struct kr_query" | sed '/uint32_t forward_flags/,$ d' printf "\t/* ^hidden stub^ */\n\tchar _stub[];\n};\n" genResType "struct kr_context" | sed '/struct kr_cache/,$ d' @@ -130,7 +131,7 @@ EOF kr_bitcmp kr_family_len kr_straddr_socket - kr_rrarray_add + kr_ranked_rrarray_add # Trust anchors kr_ta_get kr_ta_add diff --git a/lib/utils.h b/lib/utils.h index 25ab00e27..90412fce3 100644 --- a/lib/utils.h +++ b/lib/utils.h @@ -242,6 +242,7 @@ int kr_rrmap_add(map_t *stash, const knot_rrset_t *rr, uint8_t rank, knot_mm_t * int kr_rrarray_add(rr_array_t *array, const knot_rrset_t *rr, knot_mm_t *pool); /** @internal Add RRSet copy to ranked RR array. */ +KR_EXPORT int kr_ranked_rrarray_add(ranked_rr_array_t *array, const knot_rrset_t *rr, uint8_t rank, bool to_wire, uint32_t qry_uid, knot_mm_t *pool); diff --git a/modules/dns64/dns64.lua b/modules/dns64/dns64.lua index d0295c082..206daa053 100644 --- a/modules/dns64/dns64.lua +++ b/modules/dns64/dns64.lua @@ -24,13 +24,28 @@ mod.layer = { -- Synthetic AAAA from marked A responses local answer = pkt:section(kres.section.ANSWER) if bit.band(qry.flags, MARK_DNS64) ~= 0 then -- Marked request - for i = 1, #answer do - local rr = answer[i] - -- Synthesise AAAA from A - if rr.type == kres.type.A then - ffi.copy(addr_buf, mod.proxy, 16) - ffi.copy(addr_buf + 12, rr.rdata, 4) - req.answer:put(rr.owner, rr.ttl, rr.class, kres.type.AAAA, ffi.string(addr_buf, 16)) + local section = ffi.C.knot_pkt_section(pkt, kres.section.ANSWER) + for i = 1, section.count do + local orig = ffi.C.knot_pkt_rr(section, i - 1) + if orig.type == kres.type.A then + local rrs = ffi.typeof('knot_rrset_t')() + ffi.C.knot_rrset_init_empty(rrs) + rrs._owner = ffi.cast('char *', orig:owner()) -- explicit cast needed here + rrs.type = kres.type.AAAA + rrs.rclass = orig.rclass + for k = 1, orig.rrs.rr_count do + local rdata = orig:rdata( k - 1 ) + ffi.copy(addr_buf, mod.proxy, 16) + ffi.copy(addr_buf + 12, rdata, 4) + ffi.C.knot_rrset_add_rdata(rrs, ffi.string(addr_buf, 16), 16, orig:ttl(), req.pool) + end + ffi.C.kr_ranked_rrarray_add( + req.answ_selected, + rrs, + ffi.C.KR_RANK_OMIT, + true, + qry.uid, + req.pool) end end else -- Observe AAAA NODATA responses