Commit 1ab5d201 authored by Vladimír Čunát's avatar Vladimír Čunát

reorder_RR(): implement again and better

... thanks to new API in libknot-2.7.
Apart from being simpler, it now rotates even uncached answers.
parent 08c0b746
......@@ -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)
================================
......
......@@ -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])
......
......@@ -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,
......
......@@ -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 */
......
......@@ -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);
......
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