Commit de701dc3 authored by Marek Vavruša's avatar Marek Vavruša

daemon/lua: pkt:clear(), pkt:question()

parent 1abf5c54
......@@ -251,9 +251,12 @@ int kr_nsrep_set(struct kr_query *qry, uint8_t *addr, size_t addr_len);
unsigned kr_rand_uint(unsigned max);
int kr_pkt_put(knot_pkt_t *pkt, const knot_dname_t *name, uint32_t ttl,
uint16_t rclass, uint16_t rtype, const uint8_t *rdata, uint16_t rdlen);
int kr_pkt_recycle(knot_pkt_t *pkt);
const char *kr_inaddr(const struct sockaddr *addr);
int kr_inaddr_len(const struct sockaddr *addr);
int kr_straddr_family(const char *addr);
int kr_straddr_subnet(void *dst, const char *addr);
int kr_bitcmp(const char *a, const char *b, int bits);
int kr_family_len(int family);
int kr_rrarray_add(rr_array_t *array, const knot_rrset_t *rr, void *pool);
/* Trust anchors */
......@@ -331,7 +334,11 @@ ffi.metatype( knot_pkt_t, {
begin = function (pkt, section) return knot.knot_pkt_begin(pkt, section) end,
put = function (pkt, owner, ttl, rclass, rtype, rdata)
return C.kr_pkt_put(pkt, owner, ttl, rclass, rtype, rdata, string.len(rdata))
end
end,
clear = function (pkt) return C.kr_pkt_recycle(pkt) end,
question = function(pkt, qname, qclass, qtype)
return C.knot_pkt_put_question(pkt, qname, qclass, qtype)
end,
},
})
-- Metatype for query
......
......@@ -224,6 +224,10 @@ e.g. you can't write to ANSWER after writing AUTHORITY, it's like stages where y
.. code-block:: lua
pkt:rcode(kres.rcode.NXDOMAIN)
-- Clear answer and write QUESTION
pkt:clear()
pkt:question('\7blocked', kres.class.IN, kres.type.SOA)
-- Start writing data
pkt:begin(kres.section.ANSWER)
-- Nothing in answer
pkt:begin(kres.section.AUTHORITY)
......
......@@ -60,7 +60,7 @@ static int loot_rr(struct kr_cache_txn *txn, knot_pkt_t *pkt, const knot_dname_t
/* Update packet question */
if (!knot_dname_is_equal(knot_pkt_qname(pkt), name)) {
KR_PKT_RECYCLE(pkt);
kr_pkt_recycle(pkt);
knot_pkt_put_question(pkt, qry->sname, qry->sclass, qry->stype);
}
......
......@@ -730,9 +730,10 @@ int kr_resolve_finish(struct kr_request *request, int state)
}
}
request->state = state;
ITERATE_LAYERS(request, NULL, finish);
DEBUG_MSG(NULL, "finished: %d, queries: %zu, mempool: %zu B\n",
state, list_size(&rplan->resolved), (size_t) mp_total_size(request->pool.ctx));
request->state, list_size(&rplan->resolved), (size_t) mp_total_size(request->pool.ctx));
return KNOT_STATE_DONE;
}
......
......@@ -167,6 +167,16 @@ int mm_reserve(void *baton, char **mem, size_t elm_size, size_t want, size_t *ha
return -1;
}
int kr_pkt_recycle(knot_pkt_t *pkt)
{
pkt->rrset_count = 0;
pkt->size = KNOT_WIRE_HEADER_SIZE;
pkt->current = KNOT_ANSWER;
memset(pkt->sections, 0, sizeof(pkt->sections));
knot_pkt_begin(pkt, KNOT_ANSWER);
return knot_pkt_parse_question(pkt);
}
int kr_pkt_put(knot_pkt_t *pkt, const knot_dname_t *name, uint32_t ttl,
uint16_t rclass, uint16_t rtype, const uint8_t *rdata, uint16_t rdlen)
{
......
......@@ -93,14 +93,7 @@ unsigned kr_rand_uint(unsigned max);
int mm_reserve(void *baton, char **mem, size_t elm_size, size_t want, size_t *have);
/** @internal Fast packet reset. */
#define KR_PKT_RECYCLE(pkt) do { \
(pkt)->rrset_count = 0; \
(pkt)->size = KNOT_WIRE_HEADER_SIZE; \
(pkt)->current = KNOT_ANSWER; \
memset((pkt)->sections, 0, sizeof((pkt)->sections)); \
knot_pkt_begin((pkt), KNOT_ANSWER); \
knot_pkt_parse_question((pkt)); \
} while (0)
int kr_pkt_recycle(knot_pkt_t *pkt);
/** Construct and put record to packet. */
int kr_pkt_put(knot_pkt_t *pkt, const knot_dname_t *name, uint32_t ttl,
......
......@@ -59,7 +59,7 @@ static int put_answer(knot_pkt_t *pkt, knot_rrset_t *rr)
if (!knot_rrset_empty(rr)) {
/* Update packet question */
if (!knot_dname_is_equal(knot_pkt_qname(pkt), rr->owner)) {
KR_PKT_RECYCLE(pkt);
kr_pkt_recycle(pkt);
knot_pkt_put_question(pkt, rr->owner, rr->rclass, rr->type);
}
/* Append to packet */
......
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