Commit 633befbb authored by Jan Kadlec's avatar Jan Kadlec

new_node: basic dname functions use mm_ctx_t

- some cleanup and fixes as well, namely simplified RR creation during
  zone load (no malloc)
parent 1e8e389d
......@@ -284,12 +284,12 @@ static int conf_key_exists(void *scanner, char *item)
WALK_LIST (r, new_config->keys) {
if (knot_dname_cmp(r->k.name, sample) == 0) {
cf_error(scanner, "key '%s' is already defined", item);
knot_dname_free(&sample);
knot_dname_free(&sample, NULL);
return 1;
}
}
knot_dname_free(&sample);
knot_dname_free(&sample, NULL);
return 0;
}
......@@ -306,13 +306,13 @@ static int conf_key_add(void *scanner, knot_tsig_key_t **key, char *item)
WALK_LIST (r, new_config->keys) {
if (knot_dname_cmp(r->k.name, sample) == 0) {
*key = &r->k;
knot_dname_free(&sample);
knot_dname_free(&sample, NULL);
return 0;
}
}
cf_error(scanner, "key '%s' is not defined", item);
knot_dname_free(&sample);
knot_dname_free(&sample, NULL);
return 1;
}
......@@ -360,7 +360,7 @@ static void conf_zone_start(void *scanner, char *name) {
knot_dname_size(dn)) != NULL) {
cf_error(scanner, "zone '%s' is already present, refusing to "
"duplicate", this_zone->name);
knot_dname_free(&dn);
knot_dname_free(&dn, NULL);
free(this_zone->name);
this_zone->name = NULL;
/* Must not free, some versions of flex might continue after
......@@ -372,7 +372,7 @@ static void conf_zone_start(void *scanner, char *name) {
*hattrie_get(new_config->zones, (const char *)dn,
knot_dname_size(dn)) = this_zone;
knot_dname_free(&dn);
knot_dname_free(&dn, NULL);
}
}
......@@ -659,7 +659,7 @@ keys:
k->k.algorithm = $3.alg;
if (knot_binary_from_base64($4.t, &(k->k.secret)) != 0) {
cf_error(scanner, "invalid key secret '%s'", $4.t);
knot_dname_free(&dname);
knot_dname_free(&dname, NULL);
free(k);
} else {
add_tail(&new_config->keys, &k->n);
......
......@@ -572,10 +572,10 @@ int remote_answer(int sock, server_t *s, knot_pkt_t *pkt)
knot_dname_t *realm = knot_dname_from_str(KNOT_CTL_REALM);
if (!knot_dname_is_sub(qname, realm) != 0) {
dbg_server("remote: qname != *%s\n", KNOT_CTL_REALM_EXT);
knot_dname_free(&realm);
knot_dname_free(&realm, NULL);
return KNOT_EMALF;
}
knot_dname_free(&realm);
knot_dname_free(&realm, NULL);
/* Command:
* QNAME: leftmost label of QNAME
......@@ -742,11 +742,11 @@ knot_pkt_t* remote_query(const char *query, const knot_tsig_key_t *key)
/* Cannot return != KNOT_EOK, but still. */
if (knot_pkt_put_question(pkt, dname, KNOT_CLASS_CH, KNOT_RRTYPE_ANY) != KNOT_EOK) {
knot_pkt_free(&pkt);
knot_dname_free(&dname);
knot_dname_free(&dname, NULL);
return NULL;
}
knot_dname_free(&dname);
knot_dname_free(&dname, NULL);
return pkt;
}
......@@ -785,7 +785,7 @@ knot_rrset_t* remote_build_rr(const char *k, uint16_t t)
/* Create RRSet. */
knot_rrset_t *rr = knot_rrset_new(key, t, KNOT_CLASS_CH, NULL);
if (rr == NULL)
knot_dname_free(&key);
knot_dname_free(&key, NULL);
return rr;
}
......@@ -834,7 +834,7 @@ int remote_create_ns(knot_rrset_t *rr, const char *d)
/* Build RDATA. */
int dn_size = knot_dname_size(dn);
int result = knot_rrset_add_rr(rr, dn, dn_size, 0, NULL);
knot_dname_free(&dn);
knot_dname_free(&dn, NULL);
return result;
}
......
......@@ -42,11 +42,12 @@ static knot_rrset_t *create_nsec_rrset(const knot_node_t *from,
assert(to);
// Create new RRSet
knot_dname_t *owner_cpy = knot_dname_copy(from->owner);
knot_dname_t *owner_cpy = knot_dname_copy(from->owner, NULL);
knot_rrset_t *rrset = knot_rrset_new(owner_cpy,
KNOT_RRTYPE_NSEC, KNOT_CLASS_IN,
NULL);
if (!rrset) {
knot_dname_free(&owner_cpy, NULL);
return NULL;
}
......
......@@ -46,7 +46,7 @@ static knot_rrset_t *create_empty_rrsigs_for(const knot_rrset_t *covered)
{
assert(covered);
knot_dname_t *owner_copy = knot_dname_copy(covered->owner);
knot_dname_t *owner_copy = knot_dname_copy(covered->owner, NULL);
return knot_rrset_new(owner_copy, KNOT_RRTYPE_RRSIG, covered->rclass,
NULL);
......@@ -803,7 +803,7 @@ static knot_rrset_t *create_dnskey_rrset_from_soa(const knot_rrset_t *soa)
{
assert(soa);
knot_dname_t *owner = knot_dname_copy(soa->owner);
knot_dname_t *owner = knot_dname_copy(soa->owner, NULL);
if (!owner) {
return NULL;
}
......@@ -1103,7 +1103,7 @@ static int rr_already_signed(const knot_rrset_t *rrset, hattrie_t *t,
}
memset(info, 0, sizeof(signed_info_t));
// Store actual dname repr
info->dname = knot_dname_copy(rrset->owner);
info->dname = knot_dname_copy(rrset->owner, NULL);
if (info->dname == NULL) {
free(info);
return KNOT_ENOMEM;
......@@ -1228,8 +1228,8 @@ static int free_helper_trie_node(value_t *val, void *d)
WALK_LIST_FREE(*(info->type_list));
}
free(info->type_list);
knot_dname_free(&info->dname);
knot_dname_free(&info->hashed_dname);
knot_dname_free(&info->dname, NULL);
knot_dname_free(&info->hashed_dname, NULL);
free(info);
return KNOT_EOK;
}
......
......@@ -62,7 +62,7 @@ static knot_rrset_t *create_txt_rrset(const knot_dname_t *owner,
response_len = KNOT_DNAME_MAXLEN;
}
knot_dname_t *rowner = knot_dname_copy(owner);
knot_dname_t *rowner = knot_dname_copy(owner, NULL);
if (!rowner) {
return NULL;
}
......
......@@ -82,11 +82,11 @@ static int dname_cname_synth(const knot_rrset_t *dname_rr,
knot_rrset_rr_ttl(dname_rr, 0),
mm);
if (cname_rdata == NULL) {
knot_dname_free(&cname);
knot_dname_free(&cname, NULL);
return KNOT_ENOMEM;
}
memcpy(cname_rdata, cname, cname_size);
knot_dname_free(&cname);
knot_dname_free(&cname, NULL);
return KNOT_EOK;
}
......@@ -120,7 +120,8 @@ static int put_rrsig(const knot_dname_t *sig_owner, uint16_t type,
knot_rrinfo_t *rrinfo,
struct query_data *qdata)
{
knot_rrset_t synth_sig = *rrsigs;
knot_rrset_t synth_sig;
knot_rrs_init(&synth_sig.rrs);
int ret = knot_rrs_synth_rrsig(type, &rrsigs->rrs,
&synth_sig.rrs, qdata->mm);
if (ret == KNOT_ENOENT) {
......@@ -130,6 +131,10 @@ static int put_rrsig(const knot_dname_t *sig_owner, uint16_t type,
if (ret != KNOT_EOK) {
return ret;
}
synth_sig.owner = (knot_dname_t *)sig_owner;
synth_sig.type = KNOT_RRTYPE_RRSIG;
synth_sig.rclass = KNOT_CLASS_IN;
synth_sig.additional = NULL;
struct rrsig_info *info = mm_alloc(qdata->mm,
sizeof(struct rrsig_info));
if (info == NULL) {
......
......@@ -44,7 +44,7 @@ static knot_dname_t *ns_next_closer(const knot_dname_t *closest_encloser,
name = knot_wire_next_label(name, NULL);
}
return knot_dname_copy(name);
return knot_dname_copy(name, NULL);
}
/*----------------------------------------------------------------------------*/
......@@ -227,7 +227,7 @@ dbg_ns_exec_verb(
);
ret = ns_put_covering_nsec3(zone, new_next_closer, qdata, resp);
knot_dname_free(&new_next_closer);
knot_dname_free(&new_next_closer, NULL);
} else {
ret = ns_put_covering_nsec3(zone, next_closer, qdata, resp);
}
......@@ -343,7 +343,7 @@ static int ns_put_nsec3_no_wildcard_child(const knot_zone_contents_t *zone,
ret = ns_put_covering_nsec3(zone, wildcard, qdata, resp);
/* Directly discard wildcard. */
knot_dname_free(&wildcard);
knot_dname_free(&wildcard, NULL);
}
return ret;
......@@ -400,7 +400,7 @@ dbg_ns_exec_verb(
int ret = ns_put_covering_nsec3(zone, next_closer, qdata, resp);
/* Duplicate from ns_next_close(), safe to discard. */
knot_dname_free(&next_closer);
knot_dname_free(&next_closer, NULL);
return ret;
}
......@@ -548,7 +548,7 @@ dbg_ns_exec_verb(
);
/* Directly discard dname. */
knot_dname_free(&wildcard);
knot_dname_free(&wildcard, NULL);
if (prev_new != previous) {
knot_node_fill_rrset(prev_new, KNOT_RRTYPE_NSEC, &rrset);
......
......@@ -380,7 +380,7 @@ static int zone_loader_thread(dthread_t *thread)
return KNOT_ENOMEM;
}
zone_t *old_zone = knot_zonedb_find(ctx->db_old, apex);
knot_dname_free(&apex);
knot_dname_free(&apex, NULL);
/* Update the zone. */
zone = update_zone(old_zone, zone_config, ctx->server);
......
......@@ -1161,7 +1161,7 @@ int zones_save_zone(const knot_ns_xfr_t *xfr)
const knot_dname_t *new_name = NULL;
new_name = knot_node_owner(knot_zone_contents_apex(new_zone));
int r = knot_dname_cmp(cur_name, new_name);
knot_dname_free(&cur_name);
knot_dname_free(&cur_name, NULL);
if (r != 0) {
rcu_read_unlock();
return KNOT_EINVAL;
......
......@@ -129,7 +129,7 @@ static int knot_ddns_add_prereq_dname(const knot_dname_t *dname,
return ret;
}
knot_dname_t *dname_new = knot_dname_copy(dname);
knot_dname_t *dname_new = knot_dname_copy(dname, NULL);
if (dname_new == NULL) {
return KNOT_ENOMEM;
}
......@@ -556,12 +556,12 @@ void knot_ddns_prereqs_free(knot_ddns_prereq_t **prereq)
free((*prereq)->not_exist);
for (i = 0; i < (*prereq)->in_use_count; ++i) {
knot_dname_free(&(*prereq)->in_use[i]);
knot_dname_free(&(*prereq)->in_use[i], NULL);
}
free((*prereq)->in_use);
for (i = 0; i < (*prereq)->not_in_use_count; ++i) {
knot_dname_free(&(*prereq)->not_in_use[i]);
knot_dname_free(&(*prereq)->not_in_use[i], NULL);
}
free((*prereq)->not_in_use);
......@@ -1414,12 +1414,12 @@ static int knot_ddns_process_rem_rrset(const knot_rrset_t *rrset,
size_t from_chgset_count = 0;
/* 4 a) Remove redundant RRs from the ADD section of the changeset. */
knot_dname_t *owner_copy = knot_dname_copy(rrset->owner);
knot_dname_t *owner_copy = knot_dname_copy(rrset->owner, NULL);
knot_rrset_t *empty_rrset =
knot_rrset_new(owner_copy, type, rrset->rclass, NULL);
if (empty_rrset == NULL) {
free(to_chgset);
knot_dname_free(&owner_copy);
knot_dname_free(&owner_copy, NULL);
return KNOT_ENOMEM;
}
ret = knot_ddns_check_remove_rr(changeset, knot_node_owner(node),
......
......@@ -110,7 +110,7 @@ static int insert_dname_into_table(hattrie_t *table, knot_dname_t *d,
static void rrset_memsize(zone_estim_t *est, const zs_scanner_t *scanner)
{
// Handle RRSet's owner
knot_dname_t *owner = knot_dname_copy(scanner->r_owner);
knot_dname_t *owner = knot_dname_copy(scanner->r_owner, NULL);
if (owner == NULL) {
return;
}
......@@ -123,7 +123,7 @@ static void rrset_memsize(zone_estim_t *est, const zs_scanner_t *scanner)
est->dname_size += dname_memsize(owner);
// Trie's nodes handled at the end of computation
}
knot_dname_free(&owner);
knot_dname_free(&owner, NULL);
assert(n);
// We will always add RDATA
......
......@@ -101,13 +101,13 @@ static knot_rrset_t *rrset_from_rr_data(const knot_node_t *n, size_t pos,
mm_ctx_t *mm)
{
struct rr_data data = n->rrs[pos];
knot_dname_t *dname_copy = knot_dname_copy(n->owner);
knot_dname_t *dname_copy = knot_dname_copy(n->owner, mm);
if (dname_copy == NULL) {
return NULL;
}
knot_rrset_t *rrset = knot_rrset_new(dname_copy, data.type, KNOT_CLASS_IN, mm);
if (rrset == NULL) {
knot_dname_free(&dname_copy);
knot_dname_free(&dname_copy, mm);
return NULL;
}
......@@ -149,7 +149,7 @@ knot_node_t *knot_node_new(const knot_dname_t *owner, knot_node_t *parent,
* do the copying (or not if he decides to do so).
*/
if (owner) {
ret->owner = knot_dname_copy(owner);
ret->owner = knot_dname_copy(owner, NULL);
}
knot_node_set_parent(ret, parent);
......@@ -715,7 +715,7 @@ void knot_node_free(knot_node_t **node)
(*node)->rrset_count = 0;
}
knot_dname_free(&(*node)->owner);
knot_dname_free(&(*node)->owner, NULL);
free(*node);
*node = NULL;
......@@ -740,7 +740,7 @@ int knot_node_shallow_copy(const knot_node_t *from, knot_node_t **to)
// do not use the API function to set parent, so that children count
// is not changed
memcpy(*to, from, sizeof(knot_node_t));
(*to)->owner = knot_dname_copy(from->owner);
(*to)->owner = knot_dname_copy(from->owner, NULL);
// copy RRSets
size_t rrlen = sizeof(struct rr_data) * from->rrset_count;
......
......@@ -443,7 +443,7 @@ static inline struct rr_data *knot_node_rr_data_n(const knot_node_t *node,
}
#define _RRSET_INIT(node, rr_data) \
{.owner = node->owner,\
{.owner = node ? node->owner : NULL,\
.type = rr_data->type,\
.rclass = KNOT_CLASS_IN,\
.rrs = rr_data->rrs,\
......
......@@ -479,7 +479,7 @@ static int check_rrsig_in_rrset(err_handler_t *handler,
if (ret < 0 || ret >= sizeof(info_str)) {
return KNOT_ENOMEM;
}
knot_rrs_t rrsigs;
knot_rrs_t rrsigs = { 0 };
ret = knot_rrs_synth_rrsig(rrset->type,
knot_node_rrs(node, KNOT_RRTYPE_RRSIG),
&rrsigs, NULL);
......@@ -714,7 +714,7 @@ static int check_nsec3_node_in_zone(knot_zone_contents_t *zone,
ZC_ERR_NSEC3_RDATA_CHAIN, NULL);
}
knot_dname_free(&next_dname);
knot_dname_free(&next_dname, NULL);
size_t arr_size;
uint16_t *array = NULL;
......@@ -999,7 +999,7 @@ static int semantic_checks_dnssec(knot_zone_contents_t *zone,
const knot_dname_t *next_domain =
knot_rrs_nsec_next(nsec_rrs);
// Convert name to lowercase for trie lookup
knot_dname_t *lowercase = knot_dname_copy(next_domain);
knot_dname_t *lowercase = knot_dname_copy(next_domain, NULL);
if (lowercase == NULL) {
return KNOT_ENOMEM;
}
......@@ -1015,7 +1015,7 @@ static int semantic_checks_dnssec(knot_zone_contents_t *zone,
/* saving the last node */
*last_node = node;
}
knot_dname_free(&lowercase);
knot_dname_free(&lowercase, NULL);
} else if (nsec3 && (auth || deleg)) { /* nsec3 */
int ret = check_nsec3_node_in_zone(zone, node,
handler);
......@@ -1157,7 +1157,7 @@ void log_cyclic_errors_in_zone(err_handler_t *handler,
}
/* Directly discard. */
knot_dname_free(&next_dname);
knot_dname_free(&next_dname, NULL);
} else if (do_checks == 2 ) {
if (last_node == NULL) {
......
......@@ -251,7 +251,7 @@ static int adjust_nsec3_pointers(knot_node_t **tnode, void *data)
ret = KNOT_EOK;
}
knot_dname_free(&nsec3_name);
knot_dname_free(&nsec3_name, NULL);
return ret;
}
......@@ -1017,7 +1017,7 @@ int knot_zone_contents_find_nsec3_for_name(const knot_zone_contents_t *zone,
// check if the NSEC3 tree is not empty
if (knot_zone_tree_weight(zone->nsec3_nodes) == 0) {
dbg_zone("NSEC3 tree is empty.\n");
knot_dname_free(&nsec3_name);
knot_dname_free(&nsec3_name, NULL);
return KNOT_ENSEC3CHAIN;
}
......@@ -1034,7 +1034,7 @@ dbg_zone_exec_verb(
zone->nsec3_nodes, nsec3_name, &found, &prev);
assert(exact_match >= 0);
knot_dname_free(&nsec3_name);
knot_dname_free(&nsec3_name, NULL);
dbg_zone_exec_detail(
if (found) {
......
......@@ -94,17 +94,11 @@ int zcreator_step(zcreator_t *zc, knot_rrset_t *rr)
if (ret < 0) {
if (!handle_err(zc, rr, ret)) {
// Fatal error
knot_rrset_free(&rr, NULL);
return ret;
}
// Recoverable error, skip record
knot_rrset_free(&rr, NULL);
return KNOT_EOK;
} else if (ret > 0) {
knot_rrset_free(&rr, NULL);
}
// TODO: free everytime for now
knot_rrset_free(&rr, NULL);
assert(node);
// assert(zone_rrset);
......@@ -134,37 +128,33 @@ static void loader_process(const zs_scanner_t *scanner)
return;
}
knot_dname_t *owner = knot_dname_copy(scanner->r_owner);
knot_dname_t *owner = knot_dname_copy(scanner->r_owner, NULL);
if (owner == NULL) {
zc->ret = KNOT_ENOMEM;
return;
}
knot_dname_to_lower(owner);
knot_rrset_t *rr = knot_rrset_new(owner,
scanner->r_type,
scanner->r_class,
NULL);
if (rr == NULL) {
knot_dname_free(&owner);
zc->ret = KNOT_ENOMEM;
return;
}
int ret = add_rdata_to_rr(rr, scanner);
knot_rrset_t rr = {.owner = owner,
.type = scanner->r_type,
.rclass = scanner->r_class,
.additional = NULL};
knot_rrs_init(&rr.rrs);
int ret = add_rdata_to_rr(&rr, scanner);
if (ret != KNOT_EOK) {
char *rr_name = knot_dname_to_str(rr->owner);
char *rr_name = knot_dname_to_str(rr.owner);
log_zone_error("%s:%"PRIu64": Can't add RDATA for '%s'.\n",
scanner->file_name, scanner->line_counter, rr_name);
free(rr_name);
knot_rrset_free(&rr, NULL);
knot_dname_free(&owner, NULL);
zc->ret = ret;
return;
}
ret = zcreator_step(zc, rr);
ret = zcreator_step(zc, &rr);
knot_dname_free(&owner, NULL);
knot_rrs_clear(&rr.rrs, NULL);
if (ret != KNOT_EOK) {
knot_rrset_free(&rr, NULL);
zc->ret = ret;
return;
}
......@@ -181,7 +171,7 @@ static knot_zone_contents_t *create_zone_from_name(const char *origin)
}
knot_dname_to_lower(owner);
knot_zone_contents_t *z = knot_zone_contents_new(owner);
knot_dname_free(&owner);
knot_dname_free(&owner, NULL);
return z;
}
......
......@@ -249,13 +249,13 @@ static int knot_zone_diff_rdata_return_changes(const knot_rrset_t *rrset1,
* changed/removed rdatas. This has awful computation time.
*/
/* Create fake RRSet, it will be easier to handle. */
knot_dname_t *owner_copy = knot_dname_copy(knot_rrset_get_owner(rrset1));
knot_dname_t *owner_copy = knot_dname_copy(knot_rrset_get_owner(rrset1), NULL);
*changes = knot_rrset_new(owner_copy,
knot_rrset_type(rrset1),
knot_rrset_class(rrset1),
NULL);
if (*changes == NULL) {
knot_dname_free(&owner_copy);
knot_dname_free(&owner_copy, NULL);
dbg_zonediff("zone_diff: diff_rdata: "
"Could not create RRSet with changes.\n");
return KNOT_ENOMEM;
......
......@@ -223,7 +223,7 @@ void zone_free(zone_t **zone_ptr)
zone_t *zone = *zone_ptr;
knot_dname_free(&zone->name);
knot_dname_free(&zone->name, NULL);
/* Cancel and free timers. */
zone_timer_free(zone->xfr_in.timer);
......
......@@ -101,7 +101,8 @@ int knot_dname_wire_check(const uint8_t *name, const uint8_t *endp,
/*----------------------------------------------------------------------------*/
knot_dname_t *knot_dname_parse(const uint8_t *pkt, size_t *pos, size_t maxpos)
knot_dname_t *knot_dname_parse(const uint8_t *pkt, size_t *pos, size_t maxpos,
mm_ctx_t *mm)
{
if (pkt == NULL || pos == NULL)
return NULL;
......@@ -120,7 +121,7 @@ knot_dname_t *knot_dname_parse(const uint8_t *pkt, size_t *pos, size_t maxpos)
}
/* Allocate space for the name. */
knot_dname_t *res = malloc(decompressed_len);
knot_dname_t *res = mm_alloc(mm, decompressed_len);
if (res) {
/* Unpack name (expand compression pointers). */
if (knot_dname_unpack(res, name, decompressed_len, pkt) > 0) {
......@@ -136,22 +137,23 @@ knot_dname_t *knot_dname_parse(const uint8_t *pkt, size_t *pos, size_t maxpos)
/*----------------------------------------------------------------------------*/
knot_dname_t *knot_dname_copy(const knot_dname_t *name)
knot_dname_t *knot_dname_copy(const knot_dname_t *name, mm_ctx_t *mm)
{
if (name == NULL)
return NULL;
return knot_dname_copy_part(name, knot_dname_size(name));
return knot_dname_copy_part(name, knot_dname_size(name), mm);
}
/*----------------------------------------------------------------------------*/
knot_dname_t *knot_dname_copy_part(const knot_dname_t *name, unsigned len)
knot_dname_t *knot_dname_copy_part(const knot_dname_t *name, unsigned len,
mm_ctx_t *mm)
{
if (name == NULL || len == 0)
return NULL;
knot_dname_t *dst = malloc(len);
knot_dname_t *dst = mm_alloc(mm, len);
if (knot_dname_to_wire(dst, name, len) < 1) {
free(dst);
return NULL;
......@@ -540,12 +542,12 @@ knot_dname_t *knot_dname_replace_suffix(const knot_dname_t *name, unsigned label
/*----------------------------------------------------------------------------*/
void knot_dname_free(knot_dname_t **name)
void knot_dname_free(knot_dname_t **name, mm_ctx_t *mm)
{
if (name == NULL || *name == NULL)
return;
free(*name);
mm_free(mm, *name);
*name = NULL;
}
......@@ -615,7 +617,7 @@ knot_dname_t *knot_dname_cat(knot_dname_t *d1, const knot_dname_t *d2)
/* Like if we are reallocating d1. */
if (ret != NULL)
knot_dname_free(&d1);
knot_dname_free(&d1, NULL);
return ret;
}
......
......@@ -32,6 +32,7 @@
#include <stdio.h>
#include <stdbool.h>
#include "common/mempattern.h"
#include "libknot/consts.h"
typedef uint8_t knot_dname_t;
......@@ -58,10 +59,12 @@ int knot_dname_wire_check(const uint8_t *name, const uint8_t *endp,
* \param pkt Message in wire format.
* \param pos Position of the domain name on wire.
* \param maxpos Domain name length.
* \param mm Memory context.
*
* \return parsed domain name or NULL.
*/
knot_dname_t *knot_dname_parse(const uint8_t *pkt, size_t *pos, size_t maxpos);
knot_dname_t *knot_dname_parse(const uint8_t *pkt, size_t *pos, size_t maxpos,
mm_ctx_t *mm);
/*!
* \brief Duplicates the given domain name.
......@@ -70,7 +73,7 @@ knot_dname_t *knot_dname_parse(const uint8_t *pkt, size_t *pos, size_t maxpos);
*
* \return New domain name which is an exact copy of \a dname.
*/
knot_dname_t *knot_dname_copy(const knot_dname_t *name);
knot_dname_t *knot_dname_copy(const knot_dname_t *name, mm_ctx_t *mm);
/*!
* \brief Duplicates part of the given domain name.
......@@ -80,7 +83,7 @@ knot_dname_t *knot_dname_copy(const knot_dname_t *name);
*
* \return New domain name which is an partial copy of \a dname.
*/
knot_dname_t *knot_dname_copy_part(const knot_dname_t *name, unsigned len);
knot_dname_t *knot_dname_copy_part(const knot_dname_t *name, unsigned len, mm_ctx_t *mm);
/*!
* \brief Copy name to wire as is, no compression pointer expansion will be done.
......@@ -236,7 +239,7 @@ knot_dname_t *knot_dname_replace_suffix(const knot_dname_t *name,
*
* \param name Domain name to be destroyed.
*/
void knot_dname_free(knot_dname_t **name);
void knot_dname_free(knot_dname_t **name, mm_ctx_t *mm);
/*!
* \brief Compares two domain names (case sensitive).
......
......@@ -155,7 +155,7 @@ static int get_key_info_from_public_key(const char *filename,
return KNOT_KEY_EPUBLIC_KEY_INVALID;
}
knot_dname_t *owner = knot_dname_copy(scanner->r_owner);
knot_dname_t *owner = knot_dname_copy(scanner->r_owner, NULL);
if (!owner) {
zs_scanner_free(scanner);
return KNOT_ENOMEM;
......@@ -167,7 +167,7 @@ static int get_key_info_from_public_key(const char *filename,
&rdata_bin);
if (result != KNOT_EOK) {
zs_scanner_free(scanner);
knot_dname_free(&owner);
knot_dname_free(&owner, NULL);
return result;
}
......@@ -385,7 +385,7 @@ int knot_load_key_params(const char *filename, knot_key_params_t *key_params)
if (!fp) {
free(public_key);
free(private_key);
knot_dname_free(&name);
knot_dname_free(&name, NULL);
return KNOT_KEY_EPRIVATE_KEY_OPEN;
}
......@@ -425,7 +425,7 @@ int knot_copy_key_params(const knot_key_params_t *src, knot_key_params_t *dst)
int ret = 0;
if (src->name != NULL) {
dst->name = knot_dname_copy(src->name);
dst->name = knot_dname_copy(src->name, NULL);
if (dst->name == NULL) {
ret += -1;
}
......@@ -470,7 +470,7 @@ int knot_free_key_params(knot_key_params_t *key_params)
return KNOT_EINVAL;
}
knot_dname_free(&key_params->name);
knot_dname_free(&key_params->name, NULL);
knot_binary_free(&key_params->rdata);
knot_binary_free(&key_params->secret);
......@@ -541,7 +541,7 @@ int knot_tsig_create_key(const char *name, int algorithm,
knot_binary_t secret;
int result = knot_binary_from_base64(b64secret, &secret);
if (result != KNOT_EOK) {
knot_dname_free(&dname);
knot_dname_free(&dname, NULL);
return result;
}
......@@ -567,7 +567,7 @@ int knot_tsig_key_from_params(const knot_key_params_t *params,
return result;
}
key->name = knot_dname_copy(params->name);
key->name = knot_dname_copy(params->name, NULL);
key->algorithm = params->algorithm;
......@@ -583,7 +583,7 @@ int knot_tsig_key_free(knot_tsig_key_t *key)
return KNOT_EINVAL;
}
knot_dname_free(&key->name);
knot_dname_free(&key->name, NULL);
knot_binary_free(&key->secret);
memset(key, '\0', sizeof(knot_tsig_key_t));
......
......@@ -1116,7 +1116,7 @@ int knot_dnssec_key_from_params(const knot_key_params_t *params,
return KNOT_EINVAL;
}
knot_dname_t *name = knot_dname_copy(params->name);
knot_dname_t *name = knot_dname_copy(params->name, NULL);
if (!name) {