Commit 9fdf5dc9 authored by Daniel Salzman's avatar Daniel Salzman

libknot: move TTL from rdata to rrset

parent 13c101e1
......@@ -490,6 +490,7 @@ static send_ctx_t *create_send_ctx(const knot_dname_t *zone_name, ctl_args_t *ar
// Set the dump style.
ctx->style.show_ttl = true;
ctx->style.original_ttl = true;
ctx->style.human_tmstamp = true;
// Set the output data buffers.
......@@ -522,7 +523,7 @@ static send_ctx_t *create_send_ctx(const knot_dname_t *zone_name, ctl_args_t *ar
static int send_rrset(knot_rrset_t *rrset, send_ctx_t *ctx)
{
int ret = snprintf(ctx->ttl, sizeof(ctx->ttl), "%u", knot_rrset_ttl(rrset));
int ret = snprintf(ctx->ttl, sizeof(ctx->ttl), "%u", rrset->ttl);
if (ret <= 0 || ret >= sizeof(ctx->ttl)) {
return KNOT_ESPACE;
}
......@@ -823,12 +824,7 @@ static int get_ttl(zone_t *zone, ctl_args_t *args, uint32_t *ttl)
return KNOT_EINVAL;
}
knot_rdataset_t *rdataset = node_rdataset(node, type);
if (rdataset == NULL) {
return KNOT_ETTL;
}
*ttl = knot_rdataset_ttl(rdataset);
*ttl = node_rrset(node, type).ttl;
return KNOT_EOK;
}
......@@ -896,14 +892,14 @@ static int create_rrset(knot_rrset_t **rrset, zone_t *zone, ctl_args_t *args,
// Create output rrset.
*rrset = knot_rrset_new(scanner->r_owner, scanner->r_type,
scanner->r_class, NULL);
scanner->r_class, scanner->r_ttl, NULL);
if (*rrset == NULL) {
ret = KNOT_ENOMEM;
goto parser_failed;
}
ret = knot_rrset_add_rdata(*rrset, scanner->r_data, scanner->r_data_length,
scanner->r_ttl, NULL);
NULL);
parser_failed:
zs_deinit(scanner);
mm_free(&args->mm, scanner);
......
......@@ -38,7 +38,7 @@ static int create_nsec_rrset(knot_rrset_t *rrset, const zone_node_t *from,
{
assert(from);
assert(to);
knot_rrset_init(rrset, from->owner, KNOT_RRTYPE_NSEC, KNOT_CLASS_IN);
knot_rrset_init(rrset, from->owner, KNOT_RRTYPE_NSEC, KNOT_CLASS_IN, ttl);
// Create bitmap
dnssec_nsec_bitmap_t *rr_types = dnssec_nsec_bitmap_new();
......@@ -61,7 +61,7 @@ static int create_nsec_rrset(knot_rrset_t *rrset, const zone_node_t *from,
dnssec_nsec_bitmap_write(rr_types, rdata + next_owner_size);
dnssec_nsec_bitmap_free(rr_types);
return knot_rrset_add_rdata(rrset, rdata, rdata_size, ttl, NULL);
return knot_rrset_add_rdata(rrset, rdata, rdata_size, NULL);
}
/*!
......@@ -344,8 +344,7 @@ cleanup:
/*!
* \brief Add entry for removed NSEC to the changeset.
*/
int knot_nsec_changeset_remove(const zone_node_t *n,
changeset_t *changeset)
int knot_nsec_changeset_remove(const zone_node_t *n, changeset_t *changeset)
{
if (changeset == NULL) {
return KNOT_EINVAL;
......@@ -369,7 +368,7 @@ int knot_nsec_changeset_remove(const zone_node_t *n,
if (!knot_rrset_empty(&rrsigs)) {
knot_rrset_t synth_rrsigs;
knot_rrset_init(&synth_rrsigs, n->owner, KNOT_RRTYPE_RRSIG,
KNOT_CLASS_IN);
KNOT_CLASS_IN, rrsigs.ttl);
result = knot_synth_rrsig(KNOT_RRTYPE_NSEC, &rrsigs.rrs,
&synth_rrsigs.rrs, NULL);
if (result == KNOT_ENOENT) {
......
......@@ -111,8 +111,7 @@ int knot_nsec_chain_iterate_fix(zone_tree_t *old_nodes, zone_tree_t *new_nodes,
*
* \return Error code, KNOT_EOK if successful.
*/
int knot_nsec_changeset_remove(const zone_node_t *n,
changeset_t *changeset);
int knot_nsec_changeset_remove(const zone_node_t *n, changeset_t *changeset);
/*!
* \brief Checks whether the node is empty or eventually contains only NSEC and
......
......@@ -256,7 +256,7 @@ static int create_nsec3_rrset(knot_rrset_t *rrset,
if (owner_copy == NULL) {
return KNOT_ENOMEM;
}
knot_rrset_init(rrset, owner_copy, KNOT_RRTYPE_NSEC3, KNOT_CLASS_IN);
knot_rrset_init(rrset, owner_copy, KNOT_RRTYPE_NSEC3, KNOT_CLASS_IN, ttl);
size_t rdata_size = nsec3_rdata_size(params, rr_types);
uint8_t rdata[rdata_size];
......@@ -268,7 +268,7 @@ static int create_nsec3_rrset(knot_rrset_t *rrset,
return ret;
}
ret = knot_rrset_add_rdata(rrset, rdata, rdata_size, ttl, NULL);
ret = knot_rrset_add_rdata(rrset, rdata, rdata_size, NULL);
if (ret != KNOT_EOK) {
knot_dname_free(&owner_copy, NULL);
return ret;
......
......@@ -28,7 +28,7 @@ static uint32_t zone_soa_min_ttl(const zone_contents_t *zone)
static uint32_t zone_soa_ttl(const zone_contents_t *zone)
{
knot_rrset_t soa = node_rrset(zone->apex, KNOT_RRTYPE_SOA);
return knot_rrset_ttl(&soa);
return soa.ttl;
}
void update_policy_from_zone(knot_kasp_policy_t *policy,
......
......@@ -226,11 +226,9 @@ static int rrsigs_create_rdata(knot_rrset_t *rrsigs, dnssec_sign_ctx_t *ctx,
}
uint8_t header[header_size];
const knot_rdata_t *covered_data = knot_rdataset_at(&covered->rrs, 0);
int res = rrsig_write_rdata(header, header_size,
key, covered->type, owner_labels,
knot_rdata_ttl(covered_data),
sig_incepted, sig_expires);
covered->ttl, sig_incepted, sig_expires);
assert(res == KNOT_EOK);
res = dnssec_sign_init(ctx);
......@@ -257,8 +255,7 @@ static int rrsigs_create_rdata(knot_rrset_t *rrsigs, dnssec_sign_ctx_t *ctx,
dnssec_binary_free(&signature);
return knot_rrset_add_rdata(rrsigs, rrsig, rrsig_size,
knot_rdata_ttl(covered_data), mm);
return knot_rrset_add_rdata(rrsigs, rrsig, rrsig_size, mm);
}
int knot_sign_rrset(knot_rrset_t *rrsigs, const knot_rrset_t *covered,
......@@ -280,7 +277,7 @@ int knot_sign_rrset(knot_rrset_t *rrsigs, const knot_rrset_t *covered,
}
int knot_synth_rrsig(uint16_t type, const knot_rdataset_t *rrsig_rrs,
knot_rdataset_t *out_sig, knot_mm_t *mm)
knot_rdataset_t *out_sig, knot_mm_t *mm)
{
if (rrsig_rrs == NULL) {
return KNOT_ENOENT;
......
......@@ -228,7 +228,8 @@ static int remove_nsec3param(const zone_contents_t *zone, changeset_t *changeset
rrset = node_rrset(zone->apex, KNOT_RRTYPE_RRSIG);
if (!knot_rrset_empty(&rrset)) {
knot_rrset_t rrsig;
knot_rrset_init(&rrsig, zone->apex->owner, KNOT_RRTYPE_RRSIG, KNOT_CLASS_IN);
knot_rrset_init(&rrsig, zone->apex->owner, KNOT_RRTYPE_RRSIG,
KNOT_CLASS_IN, 0);
ret = knot_synth_rrsig(KNOT_RRTYPE_NSEC3PARAM, &rrset.rrs, &rrsig.rrs, NULL);
if (ret != KNOT_EOK) {
return ret;
......@@ -266,7 +267,7 @@ static int set_nsec3param(knot_rrset_t *rrset, const dnssec_nsec3_params_t *para
assert(wire_ctx_available(&wire) == 0);
return knot_rrset_add_rdata(rrset, rdata, rdata_len, 0, NULL);
return knot_rrset_add_rdata(rrset, rdata, rdata_len, NULL);
}
static int add_nsec3param(const zone_contents_t *zone, changeset_t *changeset,
......@@ -277,7 +278,8 @@ static int add_nsec3param(const zone_contents_t *zone, changeset_t *changeset,
assert(params);
knot_rrset_t *rrset = NULL;
rrset = knot_rrset_new(zone->apex->owner, KNOT_RRTYPE_NSEC3PARAM, KNOT_CLASS_IN, NULL);
rrset = knot_rrset_new(zone->apex->owner, KNOT_RRTYPE_NSEC3PARAM,
KNOT_CLASS_IN, 0, NULL);
if (!rrset) {
return KNOT_ENOMEM;
}
......
......@@ -49,7 +49,7 @@ static knot_rrset_t rrset_init_from(const knot_rrset_t *src, uint16_t type)
{
assert(src);
knot_rrset_t rrset;
knot_rrset_init(&rrset, src->owner, type, src->rclass);
knot_rrset_init(&rrset, src->owner, type, src->rclass, src->ttl);
return rrset;
}
......@@ -385,7 +385,7 @@ static int remove_rrset_rrsigs(const knot_dname_t *owner, uint16_t type,
assert(changeset);
knot_rrset_t synth_rrsig;
knot_rrset_init(&synth_rrsig, (knot_dname_t *)owner,
KNOT_RRTYPE_RRSIG, rrsigs->rclass);
KNOT_RRTYPE_RRSIG, rrsigs->rclass, rrsigs->ttl);
int ret = knot_synth_rrsig(type, &rrsigs->rrs, &synth_rrsig.rrs, NULL);
if (ret != KNOT_EOK) {
if (ret != KNOT_ENOENT) {
......@@ -474,7 +474,7 @@ static int remove_standalone_rrsigs(const zone_node_t *node,
if (!node_rrtype_exists(node, type_covered)) {
knot_rrset_t to_remove;
knot_rrset_init(&to_remove, rrsigs->owner, rrsigs->type,
rrsigs->rclass);
rrsigs->rclass, rrsigs->ttl);
knot_rdata_t *rr_rem = knot_rdataset_at(&rrsigs->rrs, i);
int ret = knot_rdataset_add(&to_remove.rrs, rr_rem, NULL);
if (ret != KNOT_EOK) {
......@@ -627,9 +627,7 @@ typedef struct {
/*- private API - DNSKEY handling --------------------------------------------*/
static int rrset_add_zone_key(knot_rrset_t *rrset,
zone_key_t *zone_key,
uint32_t ttl)
static int rrset_add_zone_key(knot_rrset_t *rrset, zone_key_t *zone_key)
{
assert(rrset);
assert(zone_key);
......@@ -637,13 +635,10 @@ static int rrset_add_zone_key(knot_rrset_t *rrset,
dnssec_binary_t dnskey_rdata = { 0 };
dnssec_key_get_rdata(zone_key->key, &dnskey_rdata);
return knot_rrset_add_rdata(rrset, dnskey_rdata.data,
dnskey_rdata.size, ttl, NULL);
return knot_rrset_add_rdata(rrset, dnskey_rdata.data, dnskey_rdata.size, NULL);
}
static int rrset_add_zone_ds(knot_rrset_t *rrset,
zone_key_t *zone_key,
uint32_t ttl)
static int rrset_add_zone_ds(knot_rrset_t *rrset, zone_key_t *zone_key)
{
assert(rrset);
assert(zone_key);
......@@ -651,8 +646,7 @@ static int rrset_add_zone_ds(knot_rrset_t *rrset,
dnssec_binary_t cds_rdata = { 0 };
zone_key_calculate_ds(zone_key, &cds_rdata);
return knot_rrset_add_rdata(rrset, cds_rdata.data,
cds_rdata.size, ttl, NULL);
return knot_rrset_add_rdata(rrset, cds_rdata.data, cds_rdata.size, NULL);
}
/*!
......@@ -939,9 +933,12 @@ int knot_zone_sign_update_dnskeys(zone_update_t *update,
CHECK_RET;
// add DNSKEYs, CDNSKEYs and CDSs
add_dnskeys = knot_rrset_new(apex->owner, KNOT_RRTYPE_DNSKEY, soa.rclass, NULL);
add_cdnskeys = knot_rrset_new(apex->owner, KNOT_RRTYPE_CDNSKEY, soa.rclass, NULL);
add_cdss = knot_rrset_new(apex->owner, KNOT_RRTYPE_CDS, soa.rclass, NULL);
add_dnskeys = knot_rrset_new(apex->owner, KNOT_RRTYPE_DNSKEY, soa.rclass,
dnskey_ttl, NULL);
add_cdnskeys = knot_rrset_new(apex->owner, KNOT_RRTYPE_CDNSKEY, soa.rclass,
0, NULL);
add_cdss = knot_rrset_new(apex->owner, KNOT_RRTYPE_CDS, soa.rclass,
0, NULL);
if (add_dnskeys == NULL || add_cdnskeys == NULL || add_cdss == NULL) {
ret = KNOT_ENOMEM;
CHECK_RET;
......@@ -952,7 +949,7 @@ int knot_zone_sign_update_dnskeys(zone_update_t *update,
for (int i = 0; i < zone_keys->count; i++) {
zone_key_t *key = &zone_keys->keys[i];
if (key->is_public) {
ret = rrset_add_zone_key(add_dnskeys, key, dnskey_ttl);
ret = rrset_add_zone_key(add_dnskeys, key);
CHECK_RET;
}
......@@ -964,9 +961,9 @@ int knot_zone_sign_update_dnskeys(zone_update_t *update,
}
if (ksk_for_cds != NULL) {
ret = rrset_add_zone_key(add_cdnskeys, ksk_for_cds, 0);
ret = rrset_add_zone_key(add_cdnskeys, ksk_for_cds);
CHECK_RET;
ret = rrset_add_zone_ds(add_cdss, ksk_for_cds, 0);
ret = rrset_add_zone_ds(add_cdss, ksk_for_cds);
CHECK_RET;
}
......@@ -974,10 +971,10 @@ int knot_zone_sign_update_dnskeys(zone_update_t *update,
const uint8_t cdnskey_empty[5] = { 0, 0, 3, 0, 0 };
const uint8_t cds_empty[5] = { 0, 0, 0, 0, 0 };
ret = knot_rrset_add_rdata(add_cdnskeys, cdnskey_empty,
sizeof(cdnskey_empty), 0, NULL);
sizeof(cdnskey_empty), NULL);
CHECK_RET;
ret = knot_rrset_add_rdata(add_cdss, cds_empty,
sizeof(cds_empty), 0, NULL);
sizeof(cds_empty), NULL);
CHECK_RET;
}
......
......@@ -68,10 +68,10 @@ int event_load(conf_t *conf, zone_t *zone)
if (ret != KNOT_EOK) {
zf_conts = NULL;
if (dontcare_load_error(conf, zone)) {
log_zone_info(zone->name, "failed to parse zonefile (%s)",
log_zone_info(zone->name, "failed to parse zone file (%s)",
knot_strerror(ret));
} else {
log_zone_error(zone->name, "failed to parse zonefile (%s)",
log_zone_error(zone->name, "failed to parse zone file (%s)",
knot_strerror(ret));
}
goto cleanup;
......@@ -126,8 +126,8 @@ int event_load(conf_t *conf, zone_t *zone)
} else {
ret = zone_update_from_differences(&up, zone, journal_conts, zf_conts, UPDATE_INCREMENTAL);
if (ret == KNOT_ESEMCHECK || ret == KNOT_ERANGE) {
log_zone_warning(zone->name, "zonefile changed with SOA serial %s, "
"ignoring zonefile and loading from journal",
log_zone_warning(zone->name, "zone file changed with SOA serial %s, "
"ignoring zone file and loading from journal",
(ret == KNOT_ESEMCHECK ? "unupdated" : "decreased"));
zone_contents_deep_free(&zf_conts);
ret = zone_update_from_contents(&up, zone, journal_conts, UPDATE_INCREMENTAL);
......
......@@ -49,7 +49,8 @@ static int serialize_rrset(wire_ctx_t *wire, const knot_rrset_t *rrset, long *ph
if (wire_ctx_available(wire) < sizeof(uint32_t) + sizeof(uint16_t) + rdlen) {
return KNOT_EOK;
}
wire_ctx_write_u32(wire, knot_rdata_ttl(rr));
// Compatibility, but one TTL per rrset would be enough.
wire_ctx_write_u32(wire, rrset->ttl);
wire_ctx_write_u16(wire, rdlen);
wire_ctx_write(wire, knot_rdata_data(rr), rdlen);
}
......@@ -81,16 +82,21 @@ static int deserialize_rrset(wire_ctx_t *wire, knot_rrset_t *rrset, long *phase)
if (wire->error != KNOT_EOK) {
return wire->error;
}
knot_rrset_init(rrset, owner, type, rclass);
knot_rrset_init(rrset, owner, type, rclass, 0);
}
bool first = true;
for ( ; *phase > 0 && wire_ctx_available(wire) > 0; (*phase)--) {
uint32_t ttl = wire_ctx_read_u32(wire);
if (first) {
rrset->ttl = ttl;
first = false;
}
uint32_t rdata_size = wire_ctx_read_u16(wire);
if (wire->error != KNOT_EOK ||
wire_ctx_available(wire) < rdata_size ||
knot_rrset_add_rdata(rrset, wire->position, rdata_size,
ttl, NULL) != KNOT_EOK) {
NULL) != KNOT_EOK) {
knot_rrset_clear(rrset, NULL);
return KNOT_EMALF;
}
......
......@@ -97,7 +97,7 @@ static bool want_dnssec(knotd_qdata_t *qdata)
static uint32_t dnskey_ttl(knotd_qdata_t *qdata)
{
knot_rrset_t soa = knotd_qdata_zone_apex_rrset(qdata, KNOT_RRTYPE_SOA);
return knot_rrset_ttl(&soa);
return soa.ttl;
}
static uint32_t nsec_ttl(knotd_qdata_t *qdata)
......@@ -196,7 +196,7 @@ static dnssec_nsec_bitmap_t *synth_bitmap(knot_pkt_t *pkt, const knotd_qdata_t *
static knot_rrset_t *synth_nsec(knot_pkt_t *pkt, knotd_qdata_t *qdata, knot_mm_t *mm)
{
knot_rrset_t *nsec = knot_rrset_new(qdata->name, KNOT_RRTYPE_NSEC,
KNOT_CLASS_IN, mm);
KNOT_CLASS_IN, nsec_ttl(qdata), mm);
if (!nsec) {
return NULL;
}
......@@ -223,9 +223,7 @@ static knot_rrset_t *synth_nsec(knot_pkt_t *pkt, knotd_qdata_t *qdata, knot_mm_t
knot_dname_free(&next, NULL);
dnssec_nsec_bitmap_free(bitmap);
uint32_t ttl = nsec_ttl(qdata);
if (knot_rrset_add_rdata(nsec, rdata, size, ttl, mm) != KNOT_EOK) {
if (knot_rrset_add_rdata(nsec, rdata, size, mm) != KNOT_EOK) {
knot_rrset_free(&nsec, mm);
return NULL;
}
......@@ -241,7 +239,8 @@ static knot_rrset_t *sign_rrset(const knot_dname_t *owner,
{
// copy of RR set with replaced owner name
knot_rrset_t *copy = knot_rrset_new(owner, cover->type, cover->rclass, NULL);
knot_rrset_t *copy = knot_rrset_new(owner, cover->type, cover->rclass,
cover->ttl, NULL);
if (!copy) {
return NULL;
}
......@@ -253,7 +252,8 @@ static knot_rrset_t *sign_rrset(const knot_dname_t *owner,
// resulting RRSIG
knot_rrset_t *rrsig = knot_rrset_new(owner, KNOT_RRTYPE_RRSIG, copy->rclass, mm);
knot_rrset_t *rrsig = knot_rrset_new(owner, KNOT_RRTYPE_RRSIG, copy->rclass,
copy->ttl, mm);
if (!rrsig) {
knot_rrset_free(&copy, NULL);
return NULL;
......@@ -361,7 +361,8 @@ static knot_rrset_t *synth_dnskey(knotd_qdata_t *qdata, const dnssec_key_t *key,
knot_mm_t *mm)
{
knot_rrset_t *dnskey = knot_rrset_new(knotd_qdata_zone_name(qdata),
KNOT_RRTYPE_DNSKEY, KNOT_CLASS_IN, mm);
KNOT_RRTYPE_DNSKEY, KNOT_CLASS_IN,
dnskey_ttl(qdata), mm);
if (!dnskey) {
return 0;
}
......@@ -370,9 +371,7 @@ static knot_rrset_t *synth_dnskey(knotd_qdata_t *qdata, const dnssec_key_t *key,
dnssec_key_get_rdata(key, &rdata);
assert(rdata.size > 0 && rdata.data);
uint32_t ttl = dnskey_ttl(qdata);
int r = knot_rrset_add_rdata(dnskey, rdata.data, rdata.size, ttl, mm);
int r = knot_rrset_add_rdata(dnskey, rdata.data, rdata.size, mm);
if (r != KNOT_EOK) {
knot_rrset_free(&dnskey, mm);
return NULL;
......
......@@ -255,7 +255,7 @@ static int reverse_rr(char *addr_str, synth_template_t *tpl, knot_pkt_t *pkt, kn
}
rr->type = KNOT_RRTYPE_PTR;
knot_rrset_add_rdata(rr, ptrname, knot_dname_size(ptrname), tpl->ttl, &pkt->mm);
knot_rrset_add_rdata(rr, ptrname, knot_dname_size(ptrname), &pkt->mm);
knot_dname_free(&ptrname, NULL);
return KNOT_EOK;
......@@ -271,12 +271,12 @@ static int forward_rr(char *addr_str, synth_template_t *tpl, knot_pkt_t *pkt, kn
rr->type = KNOT_RRTYPE_AAAA;
const struct sockaddr_in6* ip = (const struct sockaddr_in6*)&query_addr;
knot_rrset_add_rdata(rr, (const uint8_t *)&ip->sin6_addr,
sizeof(struct in6_addr), tpl->ttl, &pkt->mm);
sizeof(struct in6_addr), &pkt->mm);
} else if (tpl->addr.ss_family == AF_INET) {
rr->type = KNOT_RRTYPE_A;
const struct sockaddr_in* ip = (const struct sockaddr_in*)&query_addr;
knot_rrset_add_rdata(rr, (const uint8_t *)&ip->sin_addr,
sizeof(struct in_addr), tpl->ttl, &pkt->mm);
sizeof(struct in_addr), &pkt->mm);
} else {
return KNOT_EINVAL;
}
......@@ -287,7 +287,8 @@ 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,
knotd_qdata_t *qdata)
{
knot_rrset_t *rr = knot_rrset_new(qdata->name, 0, KNOT_CLASS_IN, &pkt->mm);
knot_rrset_t *rr = knot_rrset_new(qdata->name, 0, KNOT_CLASS_IN, tpl->ttl,
&pkt->mm);
if (rr == NULL) {
return NULL;
}
......
......@@ -80,18 +80,17 @@ static knotd_in_state_t whoami_query(knotd_in_state_t state, knot_pkt_t *pkt,
/* Synthesize the response RRset. */
/* TTL is taken from the TTL of the SOA record. */
knot_rrset_t soa = knotd_qdata_zone_apex_rrset(qdata, KNOT_RRTYPE_SOA);
/* Owner name, type, and class are taken from the question. */
knot_rrset_t *rrset = knot_rrset_new(qname, qtype, qclass, &pkt->mm);
knot_rrset_t *rrset = knot_rrset_new(qname, qtype, qclass, soa.ttl, &pkt->mm);
if (rrset == NULL) {
return KNOTD_IN_STATE_ERROR;
}
/* TTL is taken from the TTL of the SOA record. */
knot_rrset_t soa = knotd_qdata_zone_apex_rrset(qdata, KNOT_RRTYPE_SOA);
uint32_t ttl = knot_rrset_ttl(&soa);
/* Record data is the query source address. */
int ret = knot_rrset_add_rdata(rrset, rdata, len_rdata, ttl, &pkt->mm);
int ret = knot_rrset_add_rdata(rrset, rdata, len_rdata, &pkt->mm);
if (ret != KNOT_EOK) {
knot_rrset_free(&rrset, &pkt->mm);
return KNOTD_IN_STATE_ERROR;
......
......@@ -97,13 +97,13 @@ static int create_txt_rrset(knot_rrset_t *rrset, const knot_dname_t *owner,
return KNOT_ENOMEM;
}
knot_rrset_init(rrset, rowner, KNOT_RRTYPE_TXT, KNOT_CLASS_CH);
knot_rrset_init(rrset, rowner, KNOT_RRTYPE_TXT, KNOT_CLASS_CH, 0);
uint8_t rdata[response_len + 1];
rdata[0] = response_len;
memcpy(&rdata[1], response_str, response_len);
int ret = knot_rrset_add_rdata(rrset, rdata, response_len + 1, 0, mm);
int ret = knot_rrset_add_rdata(rrset, rdata, response_len + 1, mm);
if (ret != KNOT_EOK) {
knot_dname_free(&rrset->owner, mm);
return ret;
......
......@@ -67,7 +67,8 @@ static int dname_cname_synth(const knot_rrset_t *dname_rr,
if (owner_copy == NULL) {
return KNOT_ENOMEM;
}
knot_rrset_init(cname_rrset, owner_copy, KNOT_RRTYPE_CNAME, dname_rr->rclass);
knot_rrset_init(cname_rrset, owner_copy, KNOT_RRTYPE_CNAME, dname_rr->rclass,
dname_rr->ttl);
/* Replace last labels of qname with DNAME. */
const knot_dname_t *dname_wire = dname_rr->owner;
......@@ -85,9 +86,7 @@ static int dname_cname_synth(const knot_rrset_t *dname_rr,
memcpy(cname_rdata, cname, cname_size);
knot_dname_free(&cname, NULL);
const knot_rdata_t *dname_data = knot_rdataset_at(&dname_rr->rrs, 0);
int ret = knot_rrset_add_rdata(cname_rrset, cname_rdata, cname_size,
knot_rdata_ttl(dname_data), mm);
int ret = knot_rrset_add_rdata(cname_rrset, cname_rdata, cname_size, mm);
if (ret != KNOT_EOK) {
knot_dname_free(&owner_copy, mm);
return ret;
......@@ -179,41 +178,10 @@ static int put_answer(knot_pkt_t *pkt, uint16_t type, knotd_qdata_t *qdata)
static int put_authority_soa(knot_pkt_t *pkt, knotd_qdata_t *qdata,
const zone_contents_t *zone)
{
knot_rrset_t soa_rrset = node_rrset(zone->apex, KNOT_RRTYPE_SOA);
knot_rrset_t soa = node_rrset(zone->apex, KNOT_RRTYPE_SOA);
knot_rrset_t rrsigs = node_rrset(zone->apex, KNOT_RRTYPE_RRSIG);
// if SOA's TTL is larger than MINIMUM, copy the RRSet and set
// MINIMUM as TTL
int ret = KNOT_EOK;
uint32_t flags = KNOT_PF_NOTRUNC;
uint32_t min = knot_soa_minimum(&soa_rrset.rrs);
const knot_rdata_t *soa_data = knot_rdataset_at(&soa_rrset.rrs, 0);
if (min < knot_rdata_ttl(soa_data)) {
knot_rrset_t copy;
knot_dname_t *dname_cpy = knot_dname_copy(soa_rrset.owner, &pkt->mm);
if (dname_cpy == NULL) {
return KNOT_ENOMEM;
}
knot_rrset_init(&copy, dname_cpy, soa_rrset.type, soa_rrset.rclass);
int ret = knot_rdataset_copy(&copy.rrs, &soa_rrset.rrs, &pkt->mm);
if (ret != KNOT_EOK) {
knot_dname_free(&dname_cpy, &pkt->mm);
return ret;
}
knot_rdata_t *copy_data = knot_rdataset_at(&copy.rrs, 0);
knot_rdata_set_ttl(copy_data, min);
flags |= KNOT_PF_FREE;
soa_rrset = copy;
}
ret = process_query_put_rr(pkt, qdata, &soa_rrset, &rrsigs,
KNOT_COMPR_HINT_NONE, flags);
if (ret != KNOT_EOK && (flags & KNOT_PF_FREE)) {
knot_rrset_clear(&soa_rrset, &pkt->mm);
}
return ret;
return process_query_put_rr(pkt, qdata, &soa, &rrsigs,
KNOT_COMPR_HINT_NONE, KNOT_PF_NOTRUNC);
}
/*! \brief Put the delegation NS RRSet to the Authority section. */
......
......@@ -781,7 +781,8 @@ static int put_rrsig(const knot_dname_t *sig_owner, uint16_t type,
knot_rdataset_clear(&synth_rrs, qdata->mm);
return KNOT_ENOMEM;
}
knot_rrset_init(&info->synth_rrsig, owner_copy, rrsigs->type, rrsigs->rclass);
knot_rrset_init(&info->synth_rrsig, owner_copy, rrsigs->type,
rrsigs->rclass, rrsigs->ttl);
/* Store filtered signature. */
info->synth_rrsig.rrs = synth_rrs;
......@@ -817,7 +818,7 @@ int process_query_put_rr(knot_pkt_t *pkt, knotd_qdata_t *qdata,
if (qname_cpy == NULL) {
return KNOT_ENOMEM;
}
knot_rrset_init(&to_add, qname_cpy, rr->type, rr->rclass);
knot_rrset_init(&to_add, qname_cpy, rr->type, rr->rclass, rr->ttl);
ret = knot_rdataset_copy(&to_add.rrs, &rr->rrs, &pkt->mm);
if (ret != KNOT_EOK) {
knot_dname_free(&qname_cpy, &pkt->mm);
......
......@@ -126,10 +126,9 @@ static bool can_remove(const zone_node_t *node, const knot_rrset_t *rr)
return false;
}
const bool compare_ttls = false;
for (uint16_t i = 0; i < rr->rrs.rr_count; ++i) {
knot_rdata_t *rr_cmp = knot_rdataset_at(&rr->rrs, i);
if (knot_rdataset_member(node_rrs, rr_cmp, compare_ttls)) {
if (knot_rdataset_member(node_rrs, rr_cmp)) {
// At least one RR matches.
return true;
}
......@@ -291,9 +290,16 @@ int apply_add_rr(apply_ctx_t *ctx, const knot_rrset_t *rr)
}
if (ret == KNOT_ETTL) {
char buff[KNOT_DNAME_TXT_MAXLEN + 1];
char *owner = knot_dname_to_str(buff, rr->owner, sizeof(buff));
if (owner == NULL) {
owner = "";
}
char type[16] = { '\0' };
knot_rrtype_to_string(rr->type, type, sizeof(type));
log_zone_notice(contents->apex->owner,
"rrset (type %u) TTL mismatch, updated to %u",
rr->type, knot_rrset_ttl(rr));
"TTL mismatch, owner %s, type %s, "
"TTL updated to %u", owner, type, rr->ttl);
return KNOT_EOK;
}
}
......@@ -335,7 +341,7 @@ int apply_remove_rr(apply_ctx_t *ctx, const knot_rrset_t *rr)
knot_rdataset_t *changed_rrs = node_rdataset(node, rr->type);
// Subtract changeset RRS from node RRS.
ret = knot_rdataset_subtract(changed_rrs, &rr->rrs, false, NULL);
ret = knot_rdataset_subtract(changed_rrs, &rr->rrs, NULL);
if (ret != KNOT_EOK) {
clear_new_rrs(node, rr->type);
return ret;
......
......@@ -162,17 +162,20 @@ static void check_redundancy(zone_contents_t *counterpart, const knot_rrset_t *r
// Subtract the data from node's RRSet.
knot_rdataset_t *rrs = node_rdataset(node, rr->type);
uint32_t rrs_ttl = node_rrset(node, rr->type).ttl;
if (fixed_rr != NULL && *fixed_rr != NULL) {
int ret = knot_rdataset_subtract(&(*fixed_rr)->rrs, rrs, true, NULL);
if (fixed_rr != NULL && *fixed_rr != NULL && (*fixed_rr)->ttl == rrs_ttl) {
int ret = knot_rdataset_subtract(&(*fixed_rr)->rrs, rrs, NULL);
if (ret != KNOT_EOK) {
return;
}
}
int ret = knot_rdataset_subtract(rrs, &rr->rrs, true, NULL);
if (ret != KNOT_EOK) {
return;
if (rr->ttl == rrs_ttl) {
int ret = knot_rdataset_subtract(rrs, &rr->rrs, NULL);
if (ret != KNOT_EOK) {
return;
}
}
if (knot_rdataset_size(rrs) == 0) {
......@@ -435,21 +438,25 @@ static int preapply_fix_rrset(const knot_rrset_t *apply, bool adding, void *data
if (adding && zrdataset == NULL) {
return KNOT_EOK;
}
knot_rrset_t *fixrrset;
int ret = KNOT_EOK;
if (adding) {
fixrrset = knot_rrset_new(apply->owner, apply->type, apply->rclass, ctx->mm);
fixrrset = knot_rrset_new(apply->owner, apply->type, apply->rclass,
apply->ttl, ctx->mm);
} else {
fixrrset = knot_rrset_copy(apply, ctx->mm);
}
if (fixrrset == NULL) {
return KNOT_ENOMEM;
}
int ret = KNOT_EOK;
if (adding) {
ret = knot_rdataset_intersect(zrdataset, &apply->rrs, &fixrrset->rrs, ctx->mm);
} else {
if (zrdataset != NULL) {
ret = knot_rdataset_subtract(&fixrrset->rrs, zrdataset, true, ctx->mm);
uint32_t zrrset_ttl = node_rrset(znode, apply->type).ttl;
if (zrdataset != NULL && fixrrset->ttl == zrrset_ttl) {
ret = knot_rdataset_subtract(&fixrrset->rrs, zrdataset, ctx->mm);
}
}
if (ret == KNOT_EOK && !knot_rrset_empty(fixrrset)) {
......@@ -459,6 +466,7 @@ static int preapply_fix_rrset(const knot_rrset_t *apply, bool adding, void *data
ret = changeset_add_addition(ctx->fixing, fixrrset, 0);
}
}
knot_rrset_free(&fixrrset, ctx->mm);
return ret;
}
......
/* Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -197,7 +197,7 @@ static int process_prereq(const knot_rrset_t *rrset, uint16_t qclass,
zone_update_t *update, uint16_t *rcode,
list_t *rrset_list)
{
if (knot_rdata_ttl(knot_rdataset_at(&rrset->rrs, 0)) != 0) {
if (rrset->ttl != 0) {
*rcode = KNOT_RCODE_FORMERR;
return KNOT_EMALF;
}
......@@ -283,10 +283,7 @@ static bool node_contains_rr(const zone_node_t *node,
const knot_rdataset_t *zone_rrs = node_rdataset(node, rr->type);
if (zone_rrs) {
assert(rr->rrs.rr_count == 1);