*
* It may return NULL, in which case it marks ->state with _FAIL and no answer will be sent.
* Only use this when it's guaranteed that there will be no delay before sending it.
- * You don't need to call this in places where "resolver knows" that there will be no delay.
+ * You don't need to call this in places where "resolver knows" that there will be no delay,
+ * but even there you need to check if the ->answer is NULL (unless you check for _FAIL anyway).
*/
KR_EXPORT
knot_pkt_t * kr_request_ensure_answer(struct kr_request *request);
if (dnstap_dt->log_resp_pkt) {
const knot_pkt_t *rpkt = req->answer;
- m.response_message.len = rpkt->size;
- m.response_message.data = (uint8_t *)rpkt->wire;
- m.has_response_message = true;
+ m.has_response_message = rpkt != NULL;
+ if (rpkt != NULL) {
+ m.response_message.len = rpkt->size;
+ m.response_message.data = (uint8_t *)rpkt->wire;
+ }
}
/* set query time to the timestamp of the first kr_query
ffi.C.kr_log_req(req, 0, 0, 'dbg',
'following rrsets were marked as interesting:\n' ..
req:selected_tostring())
- ffi.C.kr_log_req(req, 0, 0, 'dbg',
- 'answer packet:\n' ..
- tostring(req.answer))
+ if req.answer ~= nil then
+ ffi.C.kr_log_req(req, 0, 0, 'dbg',
+ 'answer packet:\n' ..
+ tostring(req.answer))
+ else
+ ffi.C.kr_log_req(req, 0, 0, 'dbg',
+ 'answer packet DROPPED\n')
+ end
end)
ffi.gc(debug_logfinish_cb, free_cb)
return key_len + sizeof(type);
}
-static void collect_sample(struct stat_data *data, struct kr_rplan *rplan, knot_pkt_t *pkt)
+static void collect_sample(struct stat_data *data, struct kr_rplan *rplan)
{
/* Sample key = {[2] type, [1-255] owner} */
char key[sizeof(uint16_t) + KNOT_DNAME_MAXLEN];
struct kr_rplan *rplan = ¶m->rplan;
struct stat_data *data = module->data;
+ collect_sample(data, rplan);
+ if (!param->answer) {
+ /* The answer is being dropped. TODO: perhaps add some stat for this? */
+ return ctx->state;
+ }
+
/* Collect data on final answer */
collect_answer(data, param->answer);
- collect_sample(data, rplan, param->answer);
/* Count cached and unresolved */
if (rplan->resolved.len > 0) {
/* Histogram of answer latency. */
local ffi = require('ffi')
function M.layer.finish(state, req, pkt)
+ if pkt == nil then return end
-- fast filter by the length of the first QNAME label
if pkt.wire[5] == 0 then return state end -- QDCOUNT % 256 == 0, in case we produced that
local label_len = pkt.wire[12]