]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
reorder_RR(): implement again and better
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 3 Aug 2018 09:30:22 +0000 (11:30 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 14 Aug 2018 08:36:12 +0000 (10:36 +0200)
... thanks to new API in libknot-2.7.
Apart from being simpler, it now rotates even uncached answers.

NEWS
daemon/README.rst
daemon/lua/kres.lua
lib/resolve.c
modules/hints/hints.c

diff --git a/NEWS b/NEWS
index 2bc662684dfe249dc4e06f348e4bfa5806519b86..a3f70493a67e3829bbf3dde767c47d1569ecb6a0 100644 (file)
--- 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)
 ================================
 
index 4c775d68add5f136592cad977293bc68345139c2..6e561aed3f7c309f026772b0f682572858cca4c8 100644 (file)
@@ -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])
 
index b32272fb604fefb37d43ad4d7ff9e3ad265650da..0ee9b5c42687e9518c7170d49c6a780bf529d4ba 100644 (file)
@@ -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,
index 64467e955d3a9b225367f364d033fb18fe23c4e0..67d4da3377bbe7cc53a16f597098e81a5a8dff64 100644 (file)
@@ -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 */
index bea5df0d0a0df44e70ff266bf1bcfeb2da5b2304..2667bee3c5822d948c22e1f19f068e1610d8dd9e 100644 (file)
@@ -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);