Commit 3be76db7 authored by Vitezslav Kriz's avatar Vitezslav Kriz Committed by Vitezslav Kriz

dns64-cname: correct order of CNAME and AAAA in answer

If CNAME chain occurs CNAME is placed before AAAA.
parent 2f2b78c9
Pipeline #7864 canceled with stages
in 76 minutes and 8 seconds
......@@ -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 *);
......
......@@ -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\>/_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
......
......@@ -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);
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment