Commit 273d5a0f authored by Jan Kadlec's avatar Jan Kadlec

new_node: Implicit dname copy in knot_rrset_new()

parent 5f31a299
......@@ -41,14 +41,9 @@ static knot_rrset_t *create_nsec_rrset(const knot_node_t *from,
{
assert(from);
assert(to);
// Create new RRSet
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);
knot_rrset_t *rrset = knot_rrset_new(from->owner, KNOT_RRTYPE_NSEC,
KNOT_CLASS_IN, NULL);
if (!rrset) {
knot_dname_free(&owner_cpy, NULL);
return NULL;
}
......@@ -235,17 +230,11 @@ int knot_nsec_changeset_remove(const knot_node_t *n,
knot_rrset_t rrsigs = knot_node_rrset(n, KNOT_RRTYPE_RRSIG);
if (!knot_rrset_empty(&rrsigs)) {
// Sythesize RRSets' RRSIG
knot_dname_t *dname_cpy = knot_dname_copy(n->owner, NULL);
if (dname_cpy == NULL) {
return KNOT_ENOMEM;
}
knot_rrset_t *synth_rrsigs = knot_rrset_new(dname_cpy,
KNOT_RRTYPE_RRSIG,
KNOT_CLASS_IN,
NULL);
knot_rrset_t *synth_rrsigs = knot_rrset_new(n->owner,
KNOT_RRTYPE_RRSIG,
KNOT_CLASS_IN,
NULL);
if (synth_rrsigs == NULL) {
knot_dname_free(&dname_cpy, NULL);
return KNOT_ENOMEM;
}
result = knot_synth_rrsig(KNOT_RRTYPE_NSEC, &rrsigs.rrs,
......
......@@ -46,10 +46,8 @@ static knot_rrset_t *create_empty_rrsigs_for(const knot_rrset_t *covered)
{
assert(!knot_rrset_empty(covered));
knot_dname_t *owner_copy = knot_dname_copy(covered->owner, NULL);
return knot_rrset_new(owner_copy, KNOT_RRTYPE_RRSIG, covered->rclass,
NULL);
return knot_rrset_new(covered->owner, KNOT_RRTYPE_RRSIG,
covered->rclass, NULL);
}
/*!
......@@ -61,12 +59,7 @@ static knot_rrset_t *new_rrset_from(const knot_rrset_t *tpl)
return NULL;
}
knot_dname_t *owner = knot_dname_copy(tpl->owner, NULL);
if (!owner) {
return NULL;
}
return knot_rrset_new(owner, tpl->type, tpl->rclass, NULL);
return knot_rrset_new(tpl->owner, tpl->type, tpl->rclass, NULL);
}
/*- private API - signing of in-zone nodes -----------------------------------*/
......@@ -379,15 +372,9 @@ static int remove_rrset_rrsigs(const knot_dname_t *owner, uint16_t type,
{
assert(owner);
assert(changeset);
knot_dname_t *dname_cpy = knot_dname_copy(owner, NULL);
if (dname_cpy == NULL) {
return KNOT_ENOMEM;
}
knot_rrset_t *synth_rrsig = knot_rrset_new(dname_cpy, KNOT_RRTYPE_RRSIG,
KNOT_CLASS_IN, NULL);
knot_rrset_t *synth_rrsig =
knot_rrset_new(owner, KNOT_RRTYPE_RRSIG, KNOT_CLASS_IN, NULL);
if (synth_rrsig == NULL) {
knot_dname_free(&dname_cpy, NULL);
return KNOT_ENOMEM;
}
......@@ -838,13 +825,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, NULL);
if (!owner) {
return NULL;
}
return knot_rrset_new(owner, KNOT_RRTYPE_DNSKEY, soa->rclass,
NULL);
return knot_rrset_new(soa->owner, KNOT_RRTYPE_DNSKEY, soa->rclass, NULL);
}
/*!
......@@ -1031,15 +1012,11 @@ static int update_dnskeys(const knot_zone_contents_t *zone,
if (result != KNOT_EOK) {
return result;
}
knot_dname_t *dname_cpy = knot_dname_copy(apex->owner, NULL);
if (dname_cpy == NULL) {
return KNOT_ENOMEM;
}
knot_rrset_t *dnskey_rrsig = knot_rrset_new(dname_cpy, KNOT_RRTYPE_RRSIG,
KNOT_CLASS_IN, NULL);
knot_rrset_t *dnskey_rrsig = knot_rrset_new(apex->owner,
KNOT_RRTYPE_RRSIG,
KNOT_CLASS_IN,
NULL);
if (dnskey_rrsig == NULL) {
knot_dname_free(&dname_cpy, NULL);
return KNOT_ENOMEM;
}
result = knot_synth_rrsig(KNOT_RRTYPE_DNSKEY, &rrsigs.rrs,
......
......@@ -227,11 +227,9 @@ static int forward_rr(char *addr_str, synth_template_t *tpl, knot_pkt_t *pkt, kn
static knot_rrset_t *synth_rr(char *addr_str, synth_template_t *tpl, knot_pkt_t *pkt, struct query_data *qdata)
{
/* Synthetize empty RR. */
knot_dname_t* qname = knot_dname_copy(qdata->name, &pkt->mm);
knot_rrset_t *rr = knot_rrset_new(qname, 0, KNOT_CLASS_IN, &pkt->mm);
knot_rrset_t *rr = knot_rrset_new(qdata->name, 0, KNOT_CLASS_IN,
&pkt->mm);
if (rr == NULL) {
knot_dname_free(&qname, &pkt->mm);
return NULL;
}
......
......@@ -167,8 +167,8 @@ int rrset_deserialize(const uint8_t *stream, size_t *stream_size,
/* Create new RRSet. */
*rrset = knot_rrset_new(owner, type, rclass, NULL);
knot_dname_free(&owner, NULL);
if (*rrset == NULL) {
knot_dname_free(&owner, NULL);
return KNOT_ENOMEM;
}
......
......@@ -227,14 +227,10 @@ 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(rrset1->owner,
NULL);
*changes = knot_rrset_new(owner_copy,
rrset1->type,
rrset1->rclass,
NULL);
*changes = knot_rrset_new(rrset1->owner, rrset1->type,
rrset1->rclass, NULL);
if (*changes == NULL) {
knot_dname_free(&owner_copy, NULL);
dbg_zonediff("zone_diff: diff_rdata: "
"Could not create RRSet with changes.\n");
return KNOT_ENOMEM;
......
......@@ -41,7 +41,7 @@ static knot_rrset_t *sig0_create_rrset(void)
knot_dname_t *root = knot_dname_from_str(".");
knot_rrset_t *sig_record = knot_rrset_new(root, KNOT_RRTYPE_SIG,
KNOT_CLASS_ANY, NULL);
knot_dname_free(&root, NULL);
return sig_record;
}
......
......@@ -341,16 +341,22 @@ static int binary_store(uint8_t *rdata, size_t *offset, size_t packet_offset,
return KNOT_EOK;
}
knot_rrset_t *knot_rrset_new(knot_dname_t *owner, uint16_t type,
knot_rrset_t *knot_rrset_new(const knot_dname_t *owner, uint16_t type,
uint16_t rclass, mm_ctx_t *mm)
{
knot_dname_t *owner_cpy = knot_dname_copy(owner, mm);
if (owner_cpy == NULL) {
return NULL;
}
knot_rrset_t *ret = mm_alloc(mm, sizeof(knot_rrset_t));
if (ret == NULL) {
ERR_ALLOC_FAILED;
knot_dname_free(&owner_cpy, mm);
return NULL;
}
knot_rrset_init(ret, owner, type, rclass);
knot_rrset_init(ret, owner_cpy, type, rclass);
return ret;
}
......@@ -376,14 +382,9 @@ knot_rrset_t *knot_rrset_copy(const knot_rrset_t *src, mm_ctx_t *mm)
return NULL;
}
knot_dname_t *owner_cpy = knot_dname_copy(src->owner, mm);
if (owner_cpy == NULL) {
return NULL;
}
knot_rrset_t *rrset = knot_rrset_new(owner_cpy, src->type, src->rclass, mm);
knot_rrset_t *rrset = knot_rrset_new(src->owner, src->type,
src->rclass, mm);
if (rrset == NULL) {
knot_dname_free(&owner_cpy, NULL);
return NULL;
}
......@@ -393,7 +394,6 @@ knot_rrset_t *knot_rrset_copy(const knot_rrset_t *src, mm_ctx_t *mm)
return NULL;
}
rrset->additional = NULL;
return rrset;
}
......
......@@ -73,9 +73,8 @@ typedef enum {
*
* \return New RRSet structure or NULL if an error occured.
*/
knot_rrset_t *knot_rrset_new(knot_dname_t *owner, uint16_t type,
uint16_t rclass,
mm_ctx_t *mm);
knot_rrset_t *knot_rrset_new(const knot_dname_t *owner, uint16_t type,
uint16_t rclass, mm_ctx_t *mm);
/*!
* \brief Initializes RRSet structure with given data.
......
......@@ -449,18 +449,11 @@ int knot_tsig_sign(uint8_t *msg, size_t *msg_len,
return KNOT_EINVAL;
}
knot_dname_t *key_name_copy = knot_dname_copy(key->name, NULL);
if (!key_name_copy) {
dbg_tsig("TSIG: key_name_copy = NULL\n");
return KNOT_ENOMEM;
}
knot_rrset_t *tmp_tsig =
knot_rrset_new(key_name_copy,
KNOT_RRTYPE_TSIG, KNOT_CLASS_ANY, NULL);
knot_rrset_new(key->name, KNOT_RRTYPE_TSIG, KNOT_CLASS_ANY,
NULL);
if (!tmp_tsig) {
dbg_tsig("TSIG: tmp_tsig = NULL\n");
knot_dname_free(&key_name_copy, NULL);
return KNOT_ENOMEM;
}
......@@ -556,15 +549,9 @@ int knot_tsig_sign_next(uint8_t *msg, size_t *msg_len, size_t msg_max_len,
uint8_t digest_tmp[KNOT_TSIG_MAX_DIGEST_SIZE];
size_t digest_tmp_len = 0;
/* Create tmp TSIG. */
knot_dname_t *owner_copy = knot_dname_copy(key->name, NULL);
knot_rrset_t *tmp_tsig = knot_rrset_new(owner_copy,
KNOT_RRTYPE_TSIG,
KNOT_CLASS_ANY,
NULL);
knot_rrset_t *tmp_tsig = knot_rrset_new(key->name, KNOT_RRTYPE_TSIG,
KNOT_CLASS_ANY, NULL);
if (!tmp_tsig) {
knot_dname_free(&owner_copy, NULL);
return KNOT_ENOMEM;
}
......@@ -813,19 +800,11 @@ int knot_tsig_add(uint8_t *msg, size_t *msg_len, size_t msg_max_len,
}
/*! \todo What key to use, when we do not sign? Does this even work? */
knot_dname_t *key_name =
knot_dname_copy(tsig_rr->owner, NULL);
if (key_name == NULL) {
dbg_tsig("TSIG: failed to copy owner\n");
return KNOT_ERROR;
}
knot_rrset_t *tmp_tsig =
knot_rrset_new(key_name, KNOT_RRTYPE_TSIG, KNOT_CLASS_ANY,
NULL);
knot_rrset_new(tsig_rr->owner, KNOT_RRTYPE_TSIG,
KNOT_CLASS_ANY, NULL);
if (!tmp_tsig) {
dbg_tsig("TSIG: tmp_tsig = NULL\n");
knot_dname_free(&key_name, NULL);
return KNOT_ENOMEM;
}
......
......@@ -199,10 +199,7 @@ static void print_section_question(const knot_dname_t *owner,
{
size_t buflen = 8192;
char *buf = calloc(buflen, 1);
knot_dname_t *owner_copy = knot_dname_copy(owner, NULL);
knot_rrset_t *question = knot_rrset_new(owner_copy, qtype,
qclass, NULL);
knot_rrset_t *question = knot_rrset_new(owner, qtype, qclass, NULL);
if (knot_rrset_txt_dump_header(question, 0, buf, buflen,
&(style->style)) < 0) {
......
......@@ -107,8 +107,8 @@ static knot_pkt_t* create_query_packet(const query_t *query)
KNOT_RRTYPE_SOA,
query->class_num,
&packet->mm);
knot_dname_free(&qname, NULL);
if (soa == NULL) {
knot_dname_free(&qname, NULL);
knot_pkt_free(&packet);
return NULL;
}
......
......@@ -290,16 +290,10 @@ static srv_info_t *parse_host(const char *lp, const char* default_port)
/* Append parsed RRSet to list. */
static int rr_list_append(zs_scanner_t *s, list_t *target_list, mm_ctx_t *mm)
{
/* Form a rrset. */
knot_dname_t *owner = knot_dname_copy(s->r_owner, NULL);
if (!owner) {
DBG("%s: failed to create dname\n", __func__);
return KNOT_ENOMEM;
}
knot_rrset_t *rr = knot_rrset_new(owner, s->r_type, s->r_class, NULL);
knot_rrset_t *rr = knot_rrset_new(s->r_owner, s->r_type, s->r_class,
NULL);
if (!rr) {
DBG("%s: failed to create rrset\n", __func__);
knot_dname_free(&owner, NULL);
return KNOT_ENOMEM;
}
......
......@@ -55,7 +55,9 @@ int main(int argc, char *argv[])
'a', 'b', 'c', 'd' // salt
};
rrset = knot_rrset_new(NULL, KNOT_RRTYPE_NSEC3PARAM, KNOT_CLASS_IN, NULL);
knot_dname_t *owner = knot_dname_from_str("test.");
rrset = knot_rrset_new(owner, KNOT_RRTYPE_NSEC3PARAM, KNOT_CLASS_IN, NULL);
knot_dname_free(&owner, NULL);
result = knot_rrset_add_rr(rrset, rdata, sizeof(rdata), 0, NULL);
if (result == KNOT_EOK) {
......
......@@ -103,6 +103,7 @@ int main(int argc, char *argv[])
/* Write ANSWER section. */
rrsets[0] = knot_rrset_new(dnames[0], KNOT_RRTYPE_A, KNOT_CLASS_IN, NULL);
knot_dname_free(&dnames[0], NULL);
knot_rrset_add_rr(rrsets[0], RDVAL(0), RDLEN(0), TTL, NULL);
ret = knot_pkt_put(out, COMPR_HINT_QNAME, rrsets[0], 0);
ok(ret == KNOT_EOK, "pkt: write ANSWER");
......@@ -115,6 +116,7 @@ int main(int argc, char *argv[])
ret = KNOT_EOK;
for (unsigned i = 1; i < NAMECOUNT; ++i) {
rrsets[i] = knot_rrset_new(dnames[i], KNOT_RRTYPE_NS, KNOT_CLASS_IN, NULL);
knot_dname_free(&dnames[i], NULL);
knot_rrset_add_rr(rrsets[i], RDVAL(i), RDLEN(i), TTL, NULL);
ret |= knot_pkt_put(out, COMPR_HINT_NONE, rrsets[i], 0);
}
......
......@@ -48,8 +48,7 @@ void create_root_zone(server_t *server, mm_ctx_t *mm)
zone_t *root = zone_new(conf);
root->contents = knot_zone_contents_new(root->name);
knot_dname_t *root_name = knot_dname_copy(root->name, NULL);
knot_rrset_t *soa_rrset = knot_rrset_new(root_name,
knot_rrset_t *soa_rrset = knot_rrset_new(root->name,
KNOT_RRTYPE_SOA, KNOT_CLASS_IN,
NULL);
knot_rrset_add_rr(soa_rrset, SOA_RDATA, SOA_RDLEN, 7200, NULL);
......
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