Skip to content
Snippets Groups Projects
Commit 033e21e6 authored by Marek Vavruša's avatar Marek Vavruša
Browse files

lib/utils: packet recycling (keeps header, doesn’t free memory)

parent 0c60259d
Branches
Tags
No related merge requests found
......@@ -150,14 +150,9 @@ static int pkt_question(lua_State *L)
uint8_t dname[KNOT_DNAME_MAXLEN];
knot_dname_from_str(dname, lua_tostring(L, 2), sizeof(dname));
if (!knot_dname_is_equal(knot_pkt_qname(pkt), dname)) {
uint8_t header[KNOT_WIRE_HEADER_SIZE];
memcpy(header, pkt->wire, sizeof(header));
knot_pkt_clear(pkt);
memcpy(pkt->wire, header, sizeof(header));
size_t max_size = pkt->max_size;
KR_PKT_RECYCLE(pkt);
knot_pkt_put_question(pkt, dname, lua_tointeger(L, 3), lua_tointeger(L, 4));
pkt->parsed = pkt->size;
pkt->max_size = max_size;
}
return 0;
}
......
......@@ -46,10 +46,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)) {
uint8_t header[KNOT_WIRE_HEADER_SIZE];
memcpy(header, pkt->wire, sizeof(header));
knot_pkt_clear(pkt);
memcpy(pkt->wire, header, sizeof(header));
KR_PKT_RECYCLE(pkt);
knot_pkt_put_question(pkt, qry->sname, qry->sclass, qry->stype);
}
......
......@@ -34,6 +34,12 @@ extern void _cleanup_fclose(FILE **p);
* Defines.
*/
/** @internal Fast packet reset. */
#define KR_PKT_RECYCLE(pkt) do { \
(pkt)->parsed = (pkt)->size = KNOT_WIRE_HEADER_SIZE; \
knot_pkt_parse_question((pkt)); \
} while (0)
/** Concatenate N strings. */
char* kr_strcatdup(unsigned n, ...);
......
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