Commit 8971ef2c authored by Marek Vavrusa's avatar Marek Vavrusa

Chunky patch to update most of the libknot + knot dname usage.

There are still (marked) several leak points, as the names are not
referenced counted now. But this should be addressed as a part of
node/rrset refactoring efforts.

refs #21
parent 037924e5
......@@ -263,10 +263,10 @@ static void conf_acl_item(void *scanner, char *item)
static int conf_key_exists(void *scanner, char *item)
{
/* Find existing node in keys. */
knot_dname_t *sample = knot_dname_new_from_str(item, strlen(item));
knot_dname_t *sample = knot_dname_from_str(item, strlen(item));
conf_key_t* r = 0;
WALK_LIST (r, new_config->keys) {
if (knot_dname_compare(r->k.name, sample) == 0) {
if (knot_dname_cmp(r->k.name, sample) == 0) {
cf_error(scanner, "key '%s' is already defined", item);
knot_dname_free(&sample);
return 1;
......@@ -283,11 +283,11 @@ static int conf_key_add(void *scanner, knot_tsig_key_t **key, char *item)
*key = 0;
/* Find in keys */
knot_dname_t *sample = knot_dname_new_from_str(item, strlen(item));
knot_dname_t *sample = knot_dname_from_str(item, strlen(item));
conf_key_t* r = 0;
WALK_LIST (r, new_config->keys) {
if (knot_dname_compare(r->k.name, sample) == 0) {
if (knot_dname_cmp(r->k.name, sample) == 0) {
*key = &r->k;
knot_dname_free(&sample);
return 0;
......@@ -338,7 +338,7 @@ static void conf_zone_start(void *scanner, char *name) {
/* Check domain name. */
knot_dname_t *dn = NULL;
if (this_zone->name != NULL) {
dn = knot_dname_new_from_str(this_zone->name, nlen);
dn = knot_dname_from_str(this_zone->name, nlen);
}
if (dn == NULL) {
free(this_zone->name);
......@@ -347,7 +347,7 @@ static void conf_zone_start(void *scanner, char *name) {
cf_error(scanner, "invalid zone origin");
} else {
/* Check for duplicates. */
if (hattrie_tryget(new_config->names, (const char*)dn->name, dn->size) != NULL) {
if (hattrie_tryget(new_config->names, (const char *)dn, knot_dname_size(dn)) != NULL) {
cf_error(scanner, "zone '%s' is already present, refusing to "
"duplicate", this_zone->name);
knot_dname_free(&dn);
......@@ -361,7 +361,7 @@ static void conf_zone_start(void *scanner, char *name) {
/* Directly discard dname, won't be needed. */
add_tail(&new_config->zones, &this_zone->n);
*hattrie_get(new_config->names, (const char*)dn->name, dn->size) = (void *)1;
*hattrie_get(new_config->names, (const char*)dn, knot_dname_size(dn)) = (void *)1;
++new_config->zones_count;
knot_dname_free(&dn);
}
......@@ -604,7 +604,7 @@ keys:
}
if (fqdn != NULL && !conf_key_exists(scanner, fqdn)) {
knot_dname_t *dname = knot_dname_new_from_str(fqdn, fqdnl);
knot_dname_t *dname = knot_dname_from_str(fqdn, fqdnl);
if (!dname) {
cf_error(scanner, "key name '%s' not in valid domain name format",
fqdn);
......
......@@ -525,9 +525,9 @@ int remote_answer(int fd, server_t *s, knot_packet_t *pkt, uint8_t* rwire, size_
return KNOT_EMALF;
}
knot_dname_t *realm = knot_dname_new_from_str(KNOT_CTL_REALM,
knot_dname_t *realm = knot_dname_from_str(KNOT_CTL_REALM,
KNOT_CTL_REALM_LEN);
if (!knot_dname_is_subdomain(qname, realm) != 0) {
if (!knot_dname_is_sub(qname, realm) != 0) {
dbg_server("remote: qname != *%s\n", KNOT_CTL_REALM_EXT);
knot_dname_free(&realm);
return KNOT_EMALF;
......@@ -537,8 +537,8 @@ int remote_answer(int fd, server_t *s, knot_packet_t *pkt, uint8_t* rwire, size_
/* Command:
* QNAME: leftmost label of QNAME
*/
size_t cmd_len = *knot_dname_name(qname);
char *cmd = strndup((char*)qname->name + 1, cmd_len);
size_t cmd_len = *qname;
char *cmd = strndup((char*)qname + 1, cmd_len);
/* Data:
* NS: TSIG
......@@ -691,7 +691,7 @@ knot_packet_t* remote_query(const char *query, const knot_tsig_key_t *key)
/* Question section. */
char *qname = strcdup(query, KNOT_CTL_REALM_EXT);
knot_dname_t *dname = knot_dname_new_from_str(qname, strlen(qname));
knot_dname_t *dname = knot_dname_from_str(qname, strlen(qname));
if (!dname) {
knot_packet_free(&qr);
free(qname);
......@@ -759,14 +759,16 @@ knot_rrset_t* remote_build_rr(const char *k, uint16_t t)
}
/* Assert K is FQDN. */
knot_dname_t *key = knot_dname_new_from_str(k, strlen(k));
if (!key) {
knot_dname_t *key = knot_dname_from_str(k, strlen(k));
if (key == NULL) {
return NULL;
}
/* Create RRSet. */
knot_rrset_t *rr = knot_rrset_new(key, t, KNOT_CLASS_CH, 0);
knot_dname_release(key);
if (rr == NULL)
knot_dname_free(&key);
return rr;
}
......@@ -807,7 +809,7 @@ int remote_create_ns(knot_rrset_t *rr, const char *d)
}
/* Create dname. */
knot_dname_t *dn = knot_dname_new_from_str(d, strlen(d));
knot_dname_t *dn = knot_dname_from_str(d, strlen(d));
if (!dn) {
return KNOT_ERROR;
}
......
......@@ -378,7 +378,7 @@ int main(int argc, char **argv)
log_server_info("Starting integrity check of "
"zone: %s\n", zone);
knot_dname_t *zdn =
knot_dname_new_from_str(zone,
knot_dname_from_str(zone,
strlen(zone),
NULL);
knot_zone_t *z =
......
......@@ -128,14 +128,15 @@ static uint8_t rrl_clsid(rrl_req_t *p)
}
static int rrl_clsname(char *dst, size_t maxlen, uint8_t cls,
rrl_req_t *p, const knot_zone_t *z)
rrl_req_t *req, const knot_zone_t *zone)
{
const knot_dname_t *dn = NULL;
const uint8_t *n = (const uint8_t*)"\x00"; /* Fallback zone (for errors etc.) */
int nb = 1;
if (z) { /* Found associated zone. */
dn = knot_zone_name(z);
}
/* Fallback zone (for errors etc.) */
const knot_dname_t *dn = (const knot_dname_t*)"\x00";
/* Found associated zone. */
if (zone != NULL)
dn = knot_zone_name(zone);
switch (cls) {
case CLS_ERROR: /* Could be a non-existent zone or garbage. */
case CLS_NXDOMAIN: /* Queries to non-existent names in zone. */
......@@ -143,25 +144,14 @@ static int rrl_clsname(char *dst, size_t maxlen, uint8_t cls,
dbg_rrl_verb("%s: using zone/fallback name\n", __func__);
break;
default:
if (p->query) dn = knot_packet_qname(p->query);
/* Use QNAME */
if (req->query)
dn = knot_packet_qname(req->query);
break;
}
if (dn) { /* Check used dname. */
assert(dn); /* Should be always set. */
n = knot_dname_name(dn);
nb = (int)knot_dname_size(dn);
}
/* Write to wire */
if ((size_t)nb > maxlen) return KNOT_ESPACE;
if (memcpy(dst, n, nb) == NULL) {
dbg_rrl("%s: failed to serialize name=%p len=%u\n",
__func__, n, nb);
return KNOT_ERROR;
}
return nb;
return knot_dname_to_wire((uint8_t *)dst, dn, maxlen);
}
static int rrl_classify(char *dst, size_t maxlen, const sockaddr_t *a,
......@@ -191,7 +181,8 @@ static int rrl_classify(char *dst, size_t maxlen, const sockaddr_t *a,
uint16_t *nlen = (uint16_t*)(dst + blklen);
blklen += sizeof(uint16_t);
int len = rrl_clsname(dst + blklen, maxlen - blklen, cls, p, z);
if (len < 0) return len;
if (len < 0)
return len;
*nlen = len;
blklen += len;
......
......@@ -934,7 +934,7 @@ static int xfr_check_tsig(knot_ns_xfr_t *xfr, knot_rcode_t *rcode, char **tag)
/* Evaluate configured key for claimed key name.*/
key = xfr->tsig_key; /* Expects already set key (check_zone) */
xfr->tsig_key = 0;
if (key && kname && knot_dname_compare(key->name, kname) == 0) {
if (key && kname && knot_dname_cmp(key->name, kname) == 0) {
dbg_xfr("xfr: found claimed TSIG key for comparison\n");
} else {
......
......@@ -587,8 +587,8 @@ static int zones_load_zone(knot_zone_t **dst, const char *zone_name,
/* Check if loaded origin matches. */
const knot_dname_t *dname = knot_zone_name(*dst);
knot_dname_t *dname_req = NULL;
dname_req = knot_dname_new_from_str(zone_name, strlen(zone_name));
if (knot_dname_compare(dname, dname_req) != 0) {
dname_req = knot_dname_from_str(zone_name, strlen(zone_name));
if (knot_dname_cmp(dname, dname_req) != 0) {
log_server_error("Origin of the zone db file is "
"different than '%s'\n",
zone_name);
......@@ -1041,7 +1041,7 @@ static int zones_insert_zone(conf_zone_t *z, knot_zone_t **dst,
/* Convert the zone name into a domain name. */
/* Local allocation, will be discarded. */
knot_dname_t *dname = knot_dname_new_from_str(z->name, strlen(z->name));
knot_dname_t *dname = knot_dname_from_str(z->name, strlen(z->name));
if (dname == NULL) {
log_server_error("Error creating domain name from zone"
" name\n");
......@@ -1073,7 +1073,7 @@ static int zones_insert_zone(conf_zone_t *z, knot_zone_t **dst,
dbg_zones_verb("zones: loading stub zone '%s' "
"for bootstrap.\n",
z->name);
knot_dname_t *owner = knot_dname_deep_copy(dname);
knot_dname_t *owner = knot_dname_copy(dname);
zone = knot_zone_new_empty(owner);
if (zone != NULL) {
ret = KNOT_EOK;
......@@ -2644,11 +2644,11 @@ int zones_save_zone(const knot_ns_xfr_t *xfr)
const char *zonefile = zd->conf->file;
/* Check if the new zone apex dname matches zone name. */
knot_dname_t *cur_name = knot_dname_new_from_str(zd->conf->name,
knot_dname_t *cur_name = knot_dname_from_str(zd->conf->name,
strlen(zd->conf->name));
const knot_dname_t *new_name = NULL;
new_name = knot_node_owner(knot_zone_contents_apex(new_zone));
int r = knot_dname_compare(cur_name, new_name);
int r = knot_dname_cmp(cur_name, new_name);
knot_dname_free(&cur_name);
if (r != 0) {
return KNOT_EINVAL;
......@@ -3218,7 +3218,7 @@ int zones_schedule_refresh(knot_zone_t *zone, int64_t time)
zd->xfr_in.timer = evsched_schedule_cb(sch, zones_refresh_ev,
zone, time);
dbg_zones("zone: REFRESH '%s' set to %u\n",
zd->conf->name, time);
zd->conf->name, (unsigned)time);
zd->xfr_in.state = XFR_SCHED;
}
rcu_read_unlock();
......@@ -3288,7 +3288,7 @@ int zones_verify_tsig_query(const knot_packet_t *query,
* 2) Find the particular key used by the TSIG.
* Check not only name, but also the algorithm.
*/
if (key && kname && knot_dname_compare(key->name, kname) == 0
if (key && kname && knot_dname_cmp(key->name, kname) == 0
&& key->algorithm == alg) {
dbg_zones_verb("Found claimed TSIG key for comparison\n");
} else {
......
......@@ -77,29 +77,25 @@ static int dummy_node_add_type(dummy_node_t *n, uint16_t t)
static size_t dname_memsize(const knot_dname_t *d)
{
size_t d_size = d->size;
size_t l_size = d->label_count;
if (d->size < MALLOC_MIN) {
size_t d_size = knot_dname_size(d);
if (d_size < MALLOC_MIN) {
d_size = MALLOC_MIN;
}
if (d->label_count < MALLOC_MIN) {
l_size = MALLOC_MIN;
}
return (sizeof(knot_dname_t) + d_size + l_size)
* DNAME_MULT + DNAME_ADD;
return d_size * DNAME_MULT + DNAME_ADD;
}
// return: 0 - unique, 1 - duplicate
static int insert_dname_into_table(hattrie_t *table, knot_dname_t *d,
dummy_node_t **n)
{
value_t *val = hattrie_tryget(table, (char *)d->name, d->size);
value_t *val = hattrie_tryget(table, (char *)d, knot_dname_size(d));
if (val == NULL) {
// Create new dummy node to use for this dname
*n = xmalloc(sizeof(dummy_node_t));
init_list(&(*n)->node_list);
*hattrie_get(table, (char *)d->name, d->size) = *n;
*hattrie_get(table, (char *)d, knot_dname_size(d)) = *n;
return 0;
} else {
// Return previously found dummy node
......@@ -119,11 +115,8 @@ static size_t rdata_memsize(zone_estim_t *est, const scanner_t *scanner)
if (descriptor_item_is_dname(item)) {
size += sizeof(knot_dname_t *);
knot_dname_t *dname =
knot_dname_new_from_wire(scanner->r_data +
scanner->r_data_blocks[i],
scanner->r_data_blocks[i + 1] -
scanner->r_data_blocks[i],
NULL);
knot_dname_copy(scanner->r_data +
scanner->r_data_blocks[i]);
if (dname == NULL) {
return KNOT_ERROR;
}
......@@ -152,9 +145,7 @@ static size_t rdata_memsize(zone_estim_t *est, const scanner_t *scanner)
static void rrset_memsize(zone_estim_t *est, const scanner_t *scanner)
{
// Handle RRSet's owner
knot_dname_t *owner = knot_dname_new_from_wire(scanner->r_owner,
scanner->r_owner_length,
NULL);
knot_dname_t *owner = knot_dname_copy(scanner->r_owner);
if (owner == NULL) {
return;
}
......
......@@ -308,8 +308,7 @@ static int check_rrsig_rdata(err_handler_t *handler,
/* label number at the 2nd index should be same as owner's */
uint8_t labels_rdata = knot_rrset_rdata_rrsig_labels(rrsig, rr_pos);
int tmp = knot_dname_wire_labels(knot_rrset_owner(rrset)->name, NULL) -
labels_rdata;
int tmp = knot_dname_labels(knot_rrset_owner(rrset), NULL) - labels_rdata;
if (tmp != 0) {
/* if name has wildcard, label must not be included */
......@@ -340,7 +339,7 @@ static int check_rrsig_rdata(err_handler_t *handler,
knot_rrset_rdata_rrsig_signer_name(rrsig, rr_pos);
/* dnskey is in the apex node */
if (knot_dname_compare(signer_name,
if (knot_dname_cmp(signer_name,
knot_rrset_owner(dnskey_rrset)) != 0) {
err_handler_handle_error(handler, node,
ZC_ERR_RRSIG_RDATA_DNSKEY_OWNER,
......@@ -447,7 +446,7 @@ static int check_rrsig_in_rrset(err_handler_t *handler,
/* Different owner, class, ttl */
if (knot_dname_compare(knot_rrset_owner(rrset),
if (knot_dname_cmp(knot_rrset_owner(rrset),
knot_rrset_owner(rrsigs)) != 0) {
err_handler_handle_error(handler, node,
ZC_ERR_RRSIG_OWNER,
......@@ -687,7 +686,7 @@ static int check_nsec3_node_in_zone(knot_zone_contents_t *zone,
/* Local allocation, will be discarded. */
knot_dname_t *next_dname =
knot_dname_new_from_str((char *)next_dname_decoded,
knot_dname_from_str((char *)next_dname_decoded,
real_size);
if (next_dname == NULL) {
free(next_dname_decoded);
......@@ -697,11 +696,10 @@ static int check_nsec3_node_in_zone(knot_zone_contents_t *zone,
free(next_dname_decoded);
knot_dname_to_lower(next_dname);
if (knot_dname_cat(next_dname,
knot_node_owner(knot_zone_contents_apex(zone))) == NULL) {
next_dname = knot_dname_cat(next_dname,
knot_node_owner(knot_zone_contents_apex(zone)));
if (next_dname == NULL) {
log_zone_warning("Could not concatenate dnames!\n");
knot_dname_free(&next_dname);
return KNOT_ERROR;
}
......@@ -882,7 +880,7 @@ static int sem_check_node_optional(knot_zone_contents_t *zone,
/* TODO How about multiple RRs? */
knot_dname_t *ns_dname =
knot_dname_deep_copy(knot_rrset_rdata_ns_name(ns_rrset,
knot_dname_copy(knot_rrset_rdata_ns_name(ns_rrset,
0));
if (ns_dname == NULL) {
return KNOT_ENOMEM;
......@@ -891,28 +889,15 @@ static int sem_check_node_optional(knot_zone_contents_t *zone,
const knot_node_t *glue_node =
knot_zone_contents_find_node(zone, ns_dname);
if (knot_dname_is_subdomain(ns_dname,
if (knot_dname_is_sub(ns_dname,
knot_node_owner(knot_zone_contents_apex(zone)))) {
if (glue_node == NULL) {
/* Try wildcard. */
knot_dname_t *wildcard =
knot_dname_new_from_str("*", 1);
if (wildcard == NULL) {
knot_dname_free(&ns_dname);
return KNOT_ENOMEM;
}
knot_dname_t *old_ns_dname = ns_dname;
ns_dname = knot_dname_left_chop(ns_dname);
knot_dname_free(&old_ns_dname);
if (knot_dname_cat(wildcard,
ns_dname) == NULL) {
knot_dname_free(&ns_dname);
knot_dname_free(&wildcard);
return KNOT_ENOMEM;
}
/* Try wildcard ([1]* + suffix). */
knot_dname_t wildcard[KNOT_DNAME_MAXLEN];
memcpy(wildcard, "\x1""*", 2);
knot_dname_to_wire(wildcard + 2,
knot_wire_next_label(ns_dname, NULL),
sizeof(wildcard));
const knot_node_t *wildcard_node =
knot_zone_contents_find_node(zone,
wildcard);
......@@ -931,7 +916,6 @@ static int sem_check_node_optional(knot_zone_contents_t *zone,
NULL);
}
}
knot_dname_free(&wildcard);
} else {
if ((knot_node_rrset(glue_node,
KNOT_RRTYPE_A) == NULL) &&
......@@ -1103,7 +1087,7 @@ static int semantic_checks_dnssec(knot_zone_contents_t *zone,
ZC_ERR_NSEC_RDATA_CHAIN, NULL);
}
if (knot_dname_compare(next_domain,
if (knot_dname_cmp(next_domain,
knot_node_owner(knot_zone_contents_apex(zone)))
== 0) {
/* saving the last node */
......@@ -1248,7 +1232,7 @@ void log_cyclic_errors_in_zone(err_handler_t *handler,
/* Local allocation, will be discarded. */
knot_dname_t *next_dname =
knot_dname_new_from_str((char *)next_dname_decoded,
knot_dname_from_str((char *)next_dname_decoded,
real_size);
if (next_dname == NULL) {
dbg_semcheck("Could not allocate dname!\n");
......@@ -1258,14 +1242,13 @@ void log_cyclic_errors_in_zone(err_handler_t *handler,
free(next_dname_decoded);
knot_dname_to_lower(next_dname);
next_dname = knot_dname_cat(next_dname,
knot_node_owner(knot_zone_contents_apex(zone)));
if (knot_dname_cat(next_dname,
knot_node_owner(knot_zone_contents_apex(zone))) ==
NULL) {
if (next_dname == NULL) {
dbg_semcheck("Could not concatenate dnames!\n");
err_handler_handle_error(handler, last_nsec3_node,
ZC_ERR_NSEC3_RDATA_CHAIN, NULL);
knot_dname_free(&next_dname);
return;
}
......@@ -1278,8 +1261,7 @@ void log_cyclic_errors_in_zone(err_handler_t *handler,
ZC_ERR_NSEC3_RDATA_CHAIN, NULL);
} else {
/* Compare with the actual first NSEC3 node. */
if (knot_dname_compare_non_canon(first_nsec3_node->owner,
next_dname) != 0) {
if (!knot_dname_is_equal(first_nsec3_node->owner, next_dname)) {
err_handler_handle_error(handler, last_nsec3_node,
ZC_ERR_NSEC3_RDATA_CHAIN, NULL);
}
......@@ -1312,7 +1294,7 @@ void log_cyclic_errors_in_zone(err_handler_t *handler,
knot_node_owner(knot_zone_contents_apex(zone));
assert(apex_dname);
if (knot_dname_compare(next_dname, apex_dname) !=0) {
if (knot_dname_cmp(next_dname, apex_dname) !=0) {
err_handler_handle_error(handler, last_node,
ZC_ERR_NSEC_RDATA_CHAIN_NOT_CYCLIC, NULL);
}
......
......@@ -90,7 +90,7 @@ static int find_rrset_for_rrsig_in_node(knot_zone_contents_t *zone,
{
assert(node);
assert(knot_dname_compare(rrsig->owner, node->owner) == 0);
assert(knot_dname_cmp(rrsig->owner, node->owner) == 0);
knot_rrset_t *tmp_rrset =
knot_node_get_rrset(node,
......@@ -255,9 +255,7 @@ static int add_rdata_to_rr(knot_rrset_t *rrset, const scanner_t *scanner)
int item = desc->block_types[i];
if (descriptor_item_is_dname(item)) {
knot_dname_t *dname =
knot_dname_new_from_wire(scanner->r_data +
scanner->r_data_blocks[i],
scanner->r_data_blocks[i + 1] - scanner->r_data_blocks[i]);
knot_dname_copy(scanner->r_data + scanner->r_data_blocks[i]);
if (dname == NULL) {
return KNOT_ERROR;
}
......@@ -305,39 +303,19 @@ static void process_rr(const scanner_t *scanner)
if (parser->ret != KNOT_EOK) {
return;
}
knot_zone_contents_t *contents = parser->current_zone;
knot_dname_t *current_owner = NULL;
#warning Node/RRSet compression at this level? To avoid duplicate names.
knot_rrset_t *current_rrset = NULL;
if (parser->last_node &&
(scanner->r_owner_length == parser->last_node->owner->size) &&
(strncmp((char *)parser->last_node->owner->name,
(char *)scanner->r_owner, scanner->r_owner_length) == 0)) {
// no need to create new dname;
current_owner = parser->last_node->owner;
knot_dname_retain(current_owner);
} else {
current_owner =
knot_dname_new_from_wire(scanner->r_owner,
scanner->r_owner_length);
if (current_owner == NULL) {
parser->ret = KNOT_ERROR;
return;
}
knot_dname_to_lower(current_owner);
/*!< \todo
* If name is already in the table, we might not need to create
* dname object, just compare wires.
*/
knot_zone_contents_insert_dname_into_table(&current_owner,
parser->lookup_tree);
}
knot_dname_t *current_owner = knot_dname_copy(scanner->r_owner);
knot_dname_to_lower(current_owner);
/*!< \todo Do not create RRSet each time - merging needs to be sorted though. */
current_rrset = knot_rrset_new(current_owner,
scanner->r_type,
scanner->r_class,
scanner->r_ttl);
knot_dname_release(current_owner);
assert(current_owner);
assert(current_rrset);
......@@ -402,7 +380,7 @@ static void process_rr(const scanner_t *scanner)
}
if (current_rrset->type == KNOT_RRTYPE_SOA) {
if (knot_dname_compare(current_rrset->owner,
if (knot_dname_cmp(current_rrset->owner,
parser->origin_from_config) != 0) {
log_zone_error("SOA record has a different "
"owner than the one specified "
......@@ -418,8 +396,7 @@ static void process_rr(const scanner_t *scanner)
knot_rrset_t *tmp_rrsig = current_rrset;
if (parser->last_node &&
knot_dname_compare_non_canon(parser->last_node->owner,
current_rrset->owner) != 0) {
!knot_dname_is_equal(parser->last_node->owner, current_rrset->owner)) {
/* RRSIG is first in the node, so we have to create it
* before we return
*/
......@@ -482,9 +459,7 @@ static void process_rr(const scanner_t *scanner)
knot_node_t *node = NULL;
/* \note this could probably be much simpler */
if (parser->last_node && current_rrset->type != KNOT_RRTYPE_SOA &&
knot_dname_compare_non_canon(parser->last_node->owner,
current_rrset->owner) ==
0) {
knot_dname_is_equal(parser->last_node->owner, current_rrset->owner)) {
node = parser->last_node;
} else {
if (parser->last_node && parser->node_rrsigs) {
......@@ -600,16 +575,11 @@ int knot_zload_open(zloader_t **dst, const char *source, const char *origin,
return KNOT_ENOMEM;
}
context->origin_from_config =
knot_dname_new_from_str(origin, strlen(origin));
/* As it's a first node, no need for compression yet. */
context->origin_from_config = knot_dname_from_str(origin, strlen(origin));
assert(context->origin_from_config);
knot_dname_to_lower(context->origin_from_config);
/* Add first DNAME to lookup tree. */
knot_zone_contents_insert_dname_into_table(&context->origin_from_config,
context->lookup_tree);
context->last_node = knot_node_new(context->origin_from_config,
NULL, 0);
knot_dname_release(context->origin_from_config);
context->last_node = knot_node_new(context->origin_from_config, NULL, 0);
knot_zone_t *zone = knot_zone_new(context->last_node);
context->current_zone = knot_zone_get_contents(zone);
context->node_rrsigs = NULL;
......
......@@ -34,10 +34,8 @@
/*!
* \brief Basic limits for domain names (RFC 1035).
*/
typedef enum {
KNOT_MAX_DNAME_LENGTH = 255, /*!< 1-byte maximum. */
KNOT_MAX_DNAME_LABELS = 127 /*!< 1-char labels. */
} knot_const_t;
#define KNOT_DNAME_MAXLEN 255 /*!< 1-byte maximum. */
#define KNOT_DNAME_MAXLABELS 127 /*!< 1-char labels. */
/*!
* \brief DNS operation codes (OPCODEs).
......
......@@ -60,13 +60,12 @@ static knot_rrset_t *create_txt_rrset(const knot_dname_t *owner,
if (response_len > 255)
response_len = 255;
knot_dname_t *rowner = knot_dname_deep_copy(owner);
knot_dname_t *rowner = knot_dname_copy(owner);
if (!rowner)
return NULL;
knot_rrset_t *rrset;
rrset = knot_rrset_new(rowner, KNOT_RRTYPE_TXT, KNOT_CLASS_CH, 0);
knot_dname_release(rowner);
if (!rrset)
return NULL;
......
......@@ -97,11 +97,8 @@ static const knot_zone_t *ns_get_zone_for_qname(knot_zonedb_t *zdb,
* records are only present in a parent zone.
*/
if (qtype == KNOT_RRTYPE_DS) {
/*! \todo Optimize, do not deep copy dname. */
knot_dname_t *name = knot_dname_left_chop(qname);
zone = knot_zonedb_find_zone_for_name(zdb, name);
/* Directly discard. */
knot_dname_free(&name);
const knot_dname_t *parent = knot_wire_next_label(qname, NULL);
zone = knot_zonedb_find_zone_for_name(zdb, parent);
/* If zone does not exist, search for its parent zone,
this will later result to NODATA answer. */
if (zone == NULL) {
......@@ -137,9 +134,8 @@ static knot_rrset_t *ns_synth_from_wildcard(
return NULL;
}
knot_dname_t *dname_copy = knot_dname_deep_copy(qname);
knot_dname_t *dname_copy = knot_dname_copy(qname);
knot_rrset_set_owner(rrset, dname_copy);
knot_dname_release(dname_copy);
return rrset;
}
......@@ -941,8 +937,8 @@ static int ns_put_authority_soa(const knot_zone_contents_t *zone,
static knot_dname_t *ns_next_closer(const knot_dname_t *closest_encloser,
const knot_dname_t *name)
{
int ce_labels = knot_dname_wire_labels(closest_encloser, NULL);
int qname_labels = knot_dname_wire_labels(name, NULL);
int ce_labels = knot_dname_labels(closest_encloser, NULL);
int qname_labels = knot_dname_labels(name, NULL);
assert(ce_labels < qname_labels);
......@@ -951,18 +947,11 @@ static knot_dname_t *ns_next_closer(const knot_dname_t *closest_encloser,
== ce_labels);
// chop some labels from the qname
knot_dname_t *next_closer = knot_dname_deep_copy(name);
if (next_closer == NULL) {
return NULL;
}
for (int i = 0; i < (qname_labels - ce_labels - 1); ++i) {
knot_dname_t *old_next_closer = next_closer;
next_closer = knot_dname_left_chop(next_closer);
knot_dname_free(&old_next_closer);
name = knot_wire_next_label(name, NULL);
}
return next_closer;
return knot_dname_copy(name);
}
/*----------------------------------------------------------------------------*/
......@@ -1153,7 +1142,7 @@ dbg_ns_exec_verb(
);
ret = ns_put_covering_nsec3(zone, new_next_closer, resp);
knot_dname_release(new_next_closer);
knot_dname_free(&new_next_closer);
} else {
ret = ns_put_covering_nsec3(zone, next_closer, resp);
}
......@@ -1173,16 +1162,14 @@ static knot_dname_t *ns_wildcard_child_name(const knot_dname_t *name)
{
assert(name != NULL);
knot_dname_t *wildcard = knot_dname_new_from_str("*", 1);
knot_dname_t *wildcard = knot_dname_from_str("*", 1);
if (wildcard == NULL) {
return NULL;
}
if (knot_dname_cat(wildcard, name) == NULL) {
/* Directly discard dname. */
knot_dname_free(&wildcard);
wildcard = knot_dname_cat(wildcard, name);
if (wildcard == NULL)
return NULL;
}
dbg_ns_exec_verb(
char *name = knot_dname_to_str(wildcard);
......@@ -1373,7 +1360,7 @@ dbg_ns_exec_verb(
const knot_node_t *prev_new = previous;
while (knot_dname_compare(knot_node_owner(prev_new),
while (knot_dname_cmp(knot_node_owner(prev_new),
wildcard) > 0) {
dbg_ns_exec_verb(
char *name = knot_dname_to_str(knot_node_owner(prev_new));
......@@ -1383,7 +1370,7 @@ dbg_ns_exec_verb(
assert(prev_new != knot_zone_contents_apex(zone));
prev_new = knot_node_previous(prev_new);
}
assert(knot_dname_compare(knot_node_owner(prev_new),
assert(knot_dname_cmp(knot_node_owner(prev_new),
wildcard) < 0);
dbg_ns_exec_verb(
......@@ -1549,7 +1536,7 @@ dbg_ns_exec_verb(