From: Vladimír Čunát Date: Fri, 3 Aug 2018 09:30:22 +0000 (+0200) Subject: reorder_RR(): implement again and better X-Git-Tag: v3.0.0~6^2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1ab5d2010af002c8674adb2a25a92af9054671e8;p=thirdparty%2Fknot-resolver.git reorder_RR(): implement again and better ... thanks to new API in libknot-2.7. Apart from being simpler, it now rotates even uncached answers. --- diff --git a/NEWS b/NEWS index 2bc662684..a3f70493a 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,11 @@ Incompatible changes Note that by default cache is open *after* reading the configuration, and older versions were silently doing nothing. +Improvements +------------ +- reorder_RR() implementation is brought back + + Knot Resolver 2.4.1 (2018-08-02) ================================ diff --git a/daemon/README.rst b/daemon/README.rst index 4c775d68a..6e561aed3 100644 --- a/daemon/README.rst +++ b/daemon/README.rst @@ -271,8 +271,8 @@ Environment :param boolean value: New value for the option *(optional)* :return: The (new) value of the option - If set, resolver will vary the order of resource records within RR-sets - every time when answered from cache. It is disabled by default. + If set, resolver will vary the order of resource records within RR-sets. + It is disabled by default. .. function:: user(name, [group]) diff --git a/daemon/lua/kres.lua b/daemon/lua/kres.lua index b32272fb6..0ee9b5c42 100644 --- a/daemon/lua/kres.lua +++ b/daemon/lua/kres.lua @@ -646,10 +646,10 @@ ffi.metatype( knot_pkt_t, { end, -- Put an RR set in the packet -- Note: the packet doesn't take ownership of the RR set - put_rr = function (pkt, rr) + put_rr = function (pkt, rr, rotate, flags) assert(ffi.istype(knot_pkt_t, pkt)) assert(ffi.istype(knot_rrset_t, rr)) - local ret = C.knot_pkt_put_rotate(pkt, 0, rr, 0, 0) + local ret = C.knot_pkt_put_rotate(pkt, 0, rr, rotate or 0, flags or 0) if ret ~= 0 then return nil, knot_error_t(ret) end return true end, diff --git a/lib/resolve.c b/lib/resolve.c index 64467e955..67d4da337 100644 --- a/lib/resolve.c +++ b/lib/resolve.c @@ -466,10 +466,10 @@ static int answer_prepare(knot_pkt_t *answer, knot_pkt_t *query, struct kr_reque } /** @return error code, ignoring if forced to truncate the packet. */ -static int write_extra_records(const rr_array_t *arr, knot_pkt_t *answer) +static int write_extra_records(const rr_array_t *arr, uint16_t reorder, knot_pkt_t *answer) { for (size_t i = 0; i < arr->len; ++i) { - int err = knot_pkt_put(answer, 0, arr->at[i], 0); + int err = knot_pkt_put_rotate(answer, 0, arr->at[i], reorder, 0); if (err != KNOT_EOK) { return err == KNOT_ESPACE ? kr_ok() : kr_error(err); } @@ -483,8 +483,8 @@ static int write_extra_records(const rr_array_t *arr, knot_pkt_t *answer) * @param all_cname optionally output if all written RRs are CNAMEs and RRSIGs of CNAMEs * @return error code, ignoring if forced to truncate the packet. */ -static int write_extra_ranked_records(const ranked_rr_array_t *arr, knot_pkt_t *answer, - bool *all_secure, bool *all_cname) +static int write_extra_ranked_records(const ranked_rr_array_t *arr, uint16_t reorder, + knot_pkt_t *answer, bool *all_secure, bool *all_cname) { const bool has_dnssec = knot_pkt_has_dnssec(answer); bool all_sec = true; @@ -502,7 +502,7 @@ static int write_extra_ranked_records(const ranked_rr_array_t *arr, knot_pkt_t * continue; } } - err = knot_pkt_put(answer, 0, rr, 0); + err = knot_pkt_put_rotate(answer, 0, rr, reorder, 0); if (err != KNOT_EOK) { if (err == KNOT_ESPACE) { err = kr_ok(); @@ -604,6 +604,7 @@ static int answer_finalize(struct kr_request *request, int state) secure = false; /* the last answer is insecure due to opt-out */ } + const uint16_t reorder = last ? last->reorder : 0; bool answ_all_cnames = false/*arbitrary*/; if (request->answ_selected.len > 0) { assert(answer->current <= KNOT_ANSWER); @@ -611,8 +612,8 @@ static int answer_finalize(struct kr_request *request, int state) if (answer->current < KNOT_ANSWER) { knot_pkt_begin(answer, KNOT_ANSWER); } - if (write_extra_ranked_records(&request->answ_selected, answer, - &secure, &answ_all_cnames)) + if (write_extra_ranked_records(&request->answ_selected, reorder, + answer, &secure, &answ_all_cnames)) { return answer_fail(request); } @@ -622,12 +623,13 @@ static int answer_finalize(struct kr_request *request, int state) if (answer->current < KNOT_AUTHORITY) { knot_pkt_begin(answer, KNOT_AUTHORITY); } - if (write_extra_ranked_records(&request->auth_selected, answer, &secure, NULL)) { + if (write_extra_ranked_records(&request->auth_selected, reorder, + answer, &secure, NULL)) { return answer_fail(request); } /* Write additional records. */ knot_pkt_begin(answer, KNOT_ADDITIONAL); - if (write_extra_records(&request->additional, answer)) { + if (write_extra_records(&request->additional, reorder, answer)) { return answer_fail(request); } /* Write EDNS information */ diff --git a/modules/hints/hints.c b/modules/hints/hints.c index bea5df0d0..2667bee3c 100644 --- a/modules/hints/hints.c +++ b/modules/hints/hints.c @@ -63,7 +63,8 @@ static int put_answer(knot_pkt_t *pkt, struct kr_query *qry, knot_rrset_t *rr, b } if (!knot_rrset_empty(rr)) { /* Append to packet */ - ret = knot_pkt_put(pkt, KNOT_COMPR_HINT_QNAME, rr, KNOT_PF_FREE); + ret = knot_pkt_put_rotate(pkt, KNOT_COMPR_HINT_QNAME, rr, + qry->reorder, KNOT_PF_FREE); } else { /* Return empty answer if name exists, but type doesn't match */ knot_wire_set_aa(pkt->wire);