Commit 4761990e authored by Jan Kadlec's avatar Jan Kadlec

Merge remote-tracking branch 'origin/master' into zone-events-queue

Conflicts:
	src/knot/server/zones.c
	src/knot/server/zones.h
	src/knot/updates/xfr-in.c
	src/knot/zone/contents.c
	src/knot/zone/contents.h
	src/knot/zone/zone-dump.c
	src/knot/zone/zone-dump.h
	src/knot/zone/zonefile.c
	tests/process_query.c
parents 8e40bff3 ed980cf4
......@@ -2,7 +2,6 @@ ACLOCAL_AMFLAGS = -I m4
SUBDIRS = libtap src tests samples doc man patches
AM_DISTCHECK_CONFIGURE_FLAGS = \
--without-ragel \
--disable-code-coverage
code_coverage_quiet = --quiet
......
......@@ -64,36 +64,11 @@ AS_IF([test "x$YACC_BISON" != "xbison"],
[AC_MSG_ERROR([GNU bison needed for reentrant parsers, set the \$YACC variable before running configure])])
AC_PROG_INSTALL
# Check for Ragel
AC_ARG_WITH([ragel],
AC_HELP_STRING([--with-ragel=path], [Path to Ragel binary. [default=auto]]),
[with_ragel=$withval],
[with_ragel=auto])
AS_CASE([$with_ragel],
[yes|auto], [AC_PATH_PROG([RAGEL], [ragel], [false])],
[no], [RAGEL=false],
[*], [RAGEL=$with_ragel],
)
AM_CONDITIONAL([HAVE_RAGEL], test "$RAGEL" != "false")
# Set FSM type for Ragel
# Set zone parser type
AC_ARG_ENABLE([fastparser],
AS_HELP_STRING([--disable-fastparser], [Don't use faster zone parser]),
[],
[enable_fastparser=yes])
AS_CASE([$enable_fastparser],
[no], [AC_SUBST([FSM_TYPE], [-T0])],
[yes], [AC_SUBST([FSM_TYPE], [-G2])],
[*], [
AS_IF([test "$RAGEL" = "false"],
[AC_MSG_ERROR([Ragel is needed to generate different parsers])])
AC_SUBST([FSM_TYPE], [$enable_fastparser])
])
AM_CONDITIONAL([G2_PARSER], test "$enable_fastparser" = "yes")
AM_CONDITIONAL([T0_PARSER], test "$enable_fastparser" = "no")
AS_HELP_STRING([--disable-fastparser], [Use slower zone parser]),
[], [enable_fastparser=yes])
AM_CONDITIONAL([FAST_PARSER], [test "$enable_fastparser" = yes])
# Systemd integration
AC_ARG_ENABLE([systemd],
......@@ -398,9 +373,9 @@ echo "
CFlags: ${CFLAGS} ${CPPFLAGS}
LDFlags: ${LDFLAGS}
Libs: ${LIBS}
Ragel: ${RAGEL} ${FSM_TYPE}
Fast zone parser: ${enable_fastparser}
Utils with IDN: ${libidn}
Use systemd notifications: ${enable_systemd}
Systemd notifications: ${enable_systemd}
Code coverage: ${enable_code_coverage}
Continue with 'make' command"
......@@ -138,6 +138,9 @@ Show authority section.
.BR + [ no ] additional
Show additional section.
.TP
.BR + [ no ] tsig
Show TSIG pseudosection.
.TP
.BR + [ no ] stats
Show trailing packet statistics.
.TP
......
#!/bin/bash
IN="./scanner.rl"
OUT="./scanner.c"
pushd ../src/zscanner/
ragel -T0 -s -o ./scanner.c ./scanner.rl
sed '/#line/d' ./scanner.c > ./scanner.c.t0
ragel -T0 -s -o $OUT $IN
sed '/#line/d' $OUT > $OUT.t0
rm $OUT
ragel -G2 -s -o ./scanner.c ./scanner.rl
sed '/#line/d' ./scanner.c > ./scanner.c.g2
ragel -G2 -s -o $OUT $IN
sed '/#line/d' $OUT > $OUT.g2
rm $OUT
popd
......@@ -319,15 +319,15 @@ int knot_rrtype_is_metatype(const uint16_t type)
int knot_rrtype_is_ddns_forbidden(const uint16_t type)
{
return type == KNOT_RRTYPE_RRSIG ||
type == KNOT_RRTYPE_NSEC ||
return type == KNOT_RRTYPE_RRSIG ||
type == KNOT_RRTYPE_NSEC ||
type == KNOT_RRTYPE_NSEC3;
}
int knot_rrtype_additional_needed(const uint16_t rrtype)
int knot_rrtype_additional_needed(const uint16_t type)
{
return (rrtype == KNOT_RRTYPE_NS ||
rrtype == KNOT_RRTYPE_MX ||
rrtype == KNOT_RRTYPE_SRV);
return type == KNOT_RRTYPE_NS ||
type == KNOT_RRTYPE_MX ||
type == KNOT_RRTYPE_SRV;
}
......@@ -292,12 +292,12 @@ int knot_rrtype_is_ddns_forbidden(const uint16_t type);
*
* Only MX, NS and SRV types require additional processing.
*
* \param rrtype Type to check.
* \param type Type to check.
*
* \retval <> 0 if additional processing is needed for \a qtype.
* \retval 0 otherwise.
*/
int knot_rrtype_additional_needed(const uint16_t rrtype);
int knot_rrtype_additional_needed(const uint16_t type);
#endif // _KNOT_DESCRIPTOR_H_
......
......@@ -967,8 +967,9 @@ int remote_print_txt(const knot_rrset_t *rr, uint16_t i)
/* Packet parser should have already checked the packet validity. */
char buf[256];
uint16_t parsed = 0;
uint16_t rlen = knot_rrset_rr_size(rr, i);
uint8_t *p = knot_rrset_rr_rdata(rr, i);
const knot_rdata_t *rdata = knot_rdataset_at(&rr->rrs, i);
uint8_t *p = knot_rdata_data(rdata);
uint16_t rlen = knot_rdata_rdlen(rdata);
while (parsed < rlen) {
memcpy(buf, (const char*)(p+1), *p);
buf[*p] = '\0';
......
......@@ -121,7 +121,7 @@ static int shallow_copy_signature(const zone_node_t *from, zone_node_t *to)
if (knot_rrset_empty(&from_sig)) {
return KNOT_EOK;
}
return node_add_rrset(to, &from_sig, NULL);
return node_add_rrset(to, &from_sig);
}
/*!
......@@ -298,7 +298,7 @@ static zone_node_t *create_nsec3_node(knot_dname_t *owner,
return NULL;
}
ret = node_add_rrset(new_node, &nsec3_rrset, NULL);
ret = node_add_rrset(new_node, &nsec3_rrset);
knot_rrset_clear(&nsec3_rrset, NULL);
if (ret != KNOT_EOK) {
node_free(&new_node);
......
......@@ -698,8 +698,9 @@ static bool dnskey_exists_in_zone(const knot_rrset_t *dnskeys,
uint16_t dnskeys_rdata_count = dnskeys->rrs.rr_count;
for (uint16_t i = 0; i < dnskeys_rdata_count; i++) {
uint8_t *rdata = knot_rrset_rr_rdata(dnskeys, i);
uint16_t rdata_size = knot_rrset_rr_size(dnskeys, i);
const knot_rdata_t *rr_data = knot_rdataset_at(&dnskeys->rrs, i);
uint8_t *rdata = knot_rdata_data(rr_data);
uint16_t rdata_size = knot_rdata_rdlen(rr_data);
if (dnskey_rdata_match(key, rdata, rdata_size)) {
return true;
}
......@@ -750,7 +751,9 @@ static int remove_invalid_dnskeys(const knot_rrset_t *soa,
knot_rrset_t *to_remove = NULL;
int result = KNOT_EOK;
if (knot_rrset_rr_ttl(dnskeys, 0) != knot_rrset_rr_ttl(soa, 0)) {
const knot_rdata_t *dnskeys_data = knot_rdataset_at(&dnskeys->rrs, 0);
const knot_rdata_t *soa_data = knot_rdataset_at(&soa->rrs, 0);
if (knot_rdata_ttl(dnskeys_data) != knot_rdata_ttl(soa_data)) {
dbg_dnssec_detail("removing DNSKEYs (SOA TTL differs)\n");
to_remove = knot_rrset_copy(dnskeys, NULL);
result = to_remove ? KNOT_EOK : KNOT_ENOMEM;
......@@ -759,8 +762,9 @@ static int remove_invalid_dnskeys(const knot_rrset_t *soa,
uint16_t dnskeys_rdata_count = dnskeys->rrs.rr_count;
for (uint16_t i = 0; i < dnskeys_rdata_count; i++) {
uint8_t *rdata = knot_rrset_rr_rdata(dnskeys, i);
uint16_t rdata_size = knot_rrset_rr_size(dnskeys, i);
dnskeys_data = knot_rdataset_at(&dnskeys->rrs, i);
uint8_t *rdata = knot_rdata_data(dnskeys_data);
uint16_t rdata_size = knot_rdata_rdlen(dnskeys_data);
uint16_t keytag = knot_keytag(rdata, rdata_size);
const knot_zone_key_t *key = knot_get_zone_key(zone_keys, keytag);
if (key == NULL) {
......@@ -846,8 +850,10 @@ static int add_missing_dnskeys(const knot_rrset_t *soa,
knot_rrset_t *to_add = NULL;
int result = KNOT_EOK;
const knot_rdata_t *dnskeys_data = knot_rdataset_at(&dnskeys->rrs, 0);
const knot_rdata_t *soa_data = knot_rdataset_at(&soa->rrs, 0);
bool add_all = (knot_rrset_empty(dnskeys) ||
knot_rrset_rr_ttl(dnskeys, 0) != knot_rrset_rr_ttl(soa, 0));
knot_rdata_ttl(dnskeys_data) != knot_rdata_ttl(soa_data));
for (int i = 0; i < zone_keys->count; i++) {
const knot_zone_key_t *key = &zone_keys->keys[i];
......@@ -870,8 +876,7 @@ static int add_missing_dnskeys(const knot_rrset_t *soa,
}
}
result = rrset_add_zone_key(to_add, key,
knot_rrset_rr_ttl(soa, 0));
result = rrset_add_zone_key(to_add, key, knot_rdata_ttl(soa_data));
if (result != KNOT_EOK) {
break;
}
......@@ -923,8 +928,9 @@ static int update_dnskeys_rrsigs(const knot_rrset_t *dnskeys,
// add unknown keys from zone
uint16_t dnskeys_rdata_count = dnskeys->rrs.rr_count;
for (uint16_t i = 0; i < dnskeys_rdata_count; i++) {
uint8_t *rdata = knot_rrset_rr_rdata(dnskeys, i);
uint16_t rdata_size = knot_rrset_rr_size(dnskeys, i);
const knot_rdata_t *rr_data = knot_rdataset_at(&dnskeys->rrs, i);
uint8_t *rdata = knot_rdata_data(rr_data);
uint16_t rdata_size = knot_rdata_rdlen(rr_data);
uint16_t keytag = knot_keytag(rdata, rdata_size);
if (knot_get_zone_key(zone_keys, keytag) != NULL) {
continue;
......@@ -944,8 +950,9 @@ static int update_dnskeys_rrsigs(const knot_rrset_t *dnskeys,
continue;
}
const knot_rdata_t *soa_data = knot_rdataset_at(&soa->rrs, 0);
result = rrset_add_zone_key(new_dnskeys, key,
knot_rrset_rr_ttl(soa, 0));
knot_rdata_ttl(soa_data));
if (result != KNOT_EOK) {
goto fail;
}
......
......@@ -90,8 +90,9 @@ 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_rrset_rr_ttl(dname_rr, 0), mm);
knot_rdata_ttl(dname_data), mm);
if (ret != KNOT_EOK) {
knot_dname_free(&owner_copy, mm);
return ret;
......@@ -255,7 +256,8 @@ static int put_authority_soa(knot_pkt_t *pkt, struct query_data *qdata,
int ret = KNOT_EOK;
uint32_t flags = KNOT_PF_NOTRUNC;
uint32_t min = knot_soa_minimum(&soa_rrset.rrs);
if (min < knot_rrset_rr_ttl(&soa_rrset, 0)) {
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) {
......@@ -267,7 +269,8 @@ static int put_authority_soa(knot_pkt_t *pkt, struct query_data *qdata,
knot_dname_free(&dname_cpy, &pkt->mm);
return ret;
}
knot_rrset_rr_set_ttl(&copy, 0, min);
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;
......
......@@ -308,7 +308,11 @@ static int zones_process_update_auth(struct query_data *qdata)
ret = xfrin_apply_changesets(zone, chgsets, &new_contents);
if (ret != KNOT_EOK) {
log_zone_notice("%s: Failed to process: %s.\n", msg, knot_strerror(ret));
qdata->rcode = KNOT_RCODE_SERVFAIL;
if (ret == KNOT_ETTL) {
qdata->rcode = KNOT_RCODE_REFUSED;
} else {
qdata->rcode = KNOT_RCODE_SERVFAIL;
}
knot_changesets_free(&chgsets);
free(msg);
return ret;
......@@ -326,6 +330,7 @@ static int zones_process_update_auth(struct query_data *qdata)
if (sec_chs == NULL) {
xfrin_rollback_update(chgsets, &new_contents);
knot_changesets_free(&chgsets);
knot_changesets_free(&sec_chs);
free(msg);
return KNOT_ENOMEM;
}
......
......@@ -203,7 +203,8 @@ static bool rrset_empty(const knot_rrset_t *rrset)
return true;
}
if (rr_count == 1) {
return knot_rrset_rr_size(rrset, 0) == 0;
const knot_rdata_t *rr = knot_rdataset_at(&rrset->rrs, 0);
return knot_rdata_rdlen(rr) == 0;
}
return false;
}
......@@ -213,7 +214,7 @@ static int process_prereq(const knot_rrset_t *rrset, uint16_t qclass,
const zone_contents_t *zone, uint16_t *rcode,
list_t *rrset_list)
{
if (knot_rrset_rr_ttl(rrset, 0) != 0) {
if (knot_rdata_ttl(knot_rdataset_at(&rrset->rrs, 0)) != 0) {
return KNOT_EMALF;
}
......@@ -252,7 +253,7 @@ static int process_prereq(const knot_rrset_t *rrset, uint16_t qclass,
/* ----------------------- changeset lists helpers -------------------------- */
#warning TODO: Store changesets as a lookup structure
/*! \todo Store changesets as a lookup structure. */
/*!< \brief Returns true if \a cmp code returns true for one RR in list. */
#define LIST_MATCH(l, cmp) \
......@@ -670,15 +671,6 @@ static int process_add_normal(const zone_node_t *node,
return KNOT_EOK;
}
/* First check if the TTL of the new RR is equal to that of the first
* RR in the node's RRSet. If not, refuse the UPDATE.
*/
knot_rrset_t rr_in_zone = node_rrset(node, rr->type);
if (node_rrtype_exists(node, rr->type) &&
knot_rrset_rr_ttl(rr, 0) != knot_rrset_rr_ttl(&rr_in_zone, 0)) {
return KNOT_ETTL;
}
const bool apex_ns = node_rrtype_exists(node, KNOT_RRTYPE_SOA) &&
rr->type == KNOT_RRTYPE_NS;
return add_rr_to_chgset(rr, changeset, apex_ns ? apex_ns_rem : NULL);
......@@ -894,7 +886,7 @@ static int check_update(const knot_rrset_t *rrset, const knot_pkt_t *query,
return KNOT_EMALF;
}
} else if (rrset->rclass == KNOT_CLASS_NONE) {
if (knot_rrset_rr_ttl(rrset, 0) != 0
if (knot_rdata_ttl(knot_rdataset_at(&rrset->rrs, 0)) != 0
|| knot_rrtype_is_metatype(rrset->type)) {
*rcode = KNOT_RCODE_FORMERR;
return KNOT_EMALF;
......
......@@ -678,9 +678,7 @@ static bool can_remove(const zone_node_t *node, const knot_rrset_t *rr)
// Node does not exist, cannot remove anything.
return false;
}
const knot_rdataset_t *node_rrs = node_rdataset(node, rr->type);
if (node_rrs == NULL) {
// Node does not have this type at all.
return false;
......@@ -781,7 +779,7 @@ static int xfrin_apply_remove(zone_contents_t *contents, knot_changeset_t *chset
}
static int add_rr(zone_node_t *node, const knot_rrset_t *rr,
knot_changeset_t *chset)
knot_changeset_t *chset, bool master)
{
knot_rrset_t changed_rrset = node_rrset(node, rr->type);
if (!knot_rrset_empty(&changed_rrset)) {
......@@ -798,47 +796,34 @@ static int add_rr(zone_node_t *node, const knot_rrset_t *rr,
clear_new_rrs(node, rr->type);
return ret;
}
}
// Extract copy, merge into it
knot_rdataset_t *changed_rrs = node_rdataset(node, rr->type);
ret = knot_rdataset_merge(changed_rrs, &rr->rrs, NULL);
if (ret != KNOT_EOK) {
clear_new_rrs(node, rr->type);
return ret;
}
} else {
// Inserting new RRSet, data will be copied.
bool ttl_err = false;
int ret = node_add_rrset(node, rr, &ttl_err);
if (ret != KNOT_EOK) {
return ret;
// Insert new RR to RRSet, data will be copied.
int ret = node_add_rrset(node, rr);
if (ret == KNOT_EOK || ret == KNOT_ETTL) {
// RR added, store for possible rollback.
knot_rdataset_t *rrs = node_rdataset(node, rr->type);
int data_ret = add_new_data(chset, rrs->data);
if (data_ret != KNOT_EOK) {
knot_rdataset_clear(rrs, NULL);
return data_ret;
}
if (ttl_err) {
char type_str[16] = { '\0' };
knot_rrtype_to_string(rr->type, type_str, sizeof(type_str));
char *name = knot_dname_to_str(rr->owner);
char *zname = knot_dname_to_str(chset->soa_from->owner);
log_zone_warning("Changes application to zone %s: TTL mismatch"
" in %s, type %s\n", zname, name, type_str);
free(name);
free(zname);
if (ret == KNOT_ETTL) {
// Handle possible TTL errors.
log_ttl_error(node, rr);
if (!master) {
// TTL errors fatal only for master.
return KNOT_EOK;
}
}
}
// Get changed RRS and store for possible rollback.
knot_rdataset_t *rrs = node_rdataset(node, rr->type);
int ret = add_new_data(chset, rrs->data);
if (ret != KNOT_EOK) {
knot_rdataset_clear(rrs, NULL);
return ret;
}
return KNOT_EOK;
return ret;
}
static int xfrin_apply_add(zone_contents_t *contents,
knot_changeset_t *chset)
knot_changeset_t *chset, bool master)
{
knot_rr_ln_t *rr_node = NULL;
WALK_LIST(rr_node, chset->add) {
......@@ -850,7 +835,7 @@ static int xfrin_apply_add(zone_contents_t *contents,
return KNOT_ENOMEM;
}
int ret = add_rr(node, rr, chset);
int ret = add_rr(node, rr, chset, master);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -872,14 +857,13 @@ static int xfrin_apply_replace_soa(zone_contents_t *contents,
assert(!node_rrtype_exists(contents->apex, KNOT_RRTYPE_SOA));
return add_rr(contents->apex, chset->soa_to, chset);
return add_rr(contents->apex, chset->soa_to, chset, false);
}
/*----------------------------------------------------------------------------*/
static int xfrin_apply_changeset(list_t *old_rrs, list_t *new_rrs,
zone_contents_t *contents,
knot_changeset_t *chset)
static int xfrin_apply_changeset(zone_contents_t *contents,
knot_changeset_t *chset, bool master)
{
/*
* Applies one changeset to the zone. Checks if the changeset may be
......@@ -902,7 +886,7 @@ static int xfrin_apply_changeset(list_t *old_rrs, list_t *new_rrs,
return ret;
}
ret = xfrin_apply_add(contents, chset);
ret = xfrin_apply_add(contents, chset, master);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -1112,25 +1096,26 @@ int xfrin_apply_changesets_directly(zone_contents_t *contents,
knot_changeset_t *set = NULL;
WALK_LIST(set, chsets->sets) {
int ret = xfrin_apply_changeset(&set->old_data,
&set->new_data,
contents, set);
const bool master = true; // Only DNSSEC changesets are applied directly.
int ret = xfrin_apply_changeset(contents, set, master);
if (ret != KNOT_EOK) {
return ret;
}
}
return KNOT_EOK;
return xfrin_finalize_updated_zone(contents, true);
}
/*----------------------------------------------------------------------------*/
/* Post-DDNS application, no need to shallow copy. */
int xfrin_apply_changesets_dnssec_ddns(zone_contents_t *z_new,
int xfrin_apply_changesets_dnssec_ddns(zone_t *zone,
zone_contents_t *z_new,
knot_changesets_t *sec_chsets,
knot_changesets_t *chsets)
{
if (z_new == NULL || sec_chsets == NULL || chsets == NULL) {
if (zone == NULL || z_new == NULL ||
sec_chsets == NULL || chsets == NULL) {
return KNOT_EINVAL;
}
......@@ -1146,15 +1131,6 @@ int xfrin_apply_changesets_dnssec_ddns(zone_contents_t *z_new,
return ret;
}
const bool handle_nsec3 = true;
ret = xfrin_finalize_updated_zone(z_new, handle_nsec3);
if (ret != KNOT_EOK) {
dbg_xfrin("Failed to finalize updated zone: %s\n",
knot_strerror(ret));
xfrin_rollback_update(sec_chsets, &z_new);
return ret;
}
return ret;
}
......@@ -1193,10 +1169,9 @@ int xfrin_apply_changesets(zone_t *zone,
dbg_xfrin_verb("Old contents apex: %p, new apex: %p\n",
old_contents->apex, contents_copy->apex);
knot_changeset_t *set = NULL;
const bool master = (zone_master(zone) == NULL);
WALK_LIST(set, chsets->sets) {
ret = xfrin_apply_changeset(&set->old_data,
&set->new_data,
contents_copy, set);
ret = xfrin_apply_changeset(contents_copy, set, master);
if (ret != KNOT_EOK) {
xfrin_rollback_update(chsets, &contents_copy);
dbg_xfrin("Failed to apply changesets to zone: "
......
......@@ -636,8 +636,9 @@ static zone_node_t *zone_contents_get_nsec3_node(const zone_contents_t *zone,
return n;
}
static int insert_rr(zone_contents_t *z, const knot_rrset_t *rr, zone_node_t **n,
bool nsec3, bool *ttl_err)
static int insert_rr(knot_zone_contents_t *z,
const knot_rrset_t *rr, zone_node_t **n,
bool nsec3)
{
if (z == NULL || knot_rrset_empty(rr) || n == NULL) {
return KNOT_EINVAL;
......@@ -667,7 +668,7 @@ static int insert_rr(zone_contents_t *z, const knot_rrset_t *rr, zone_node_t **n
}
}
return node_add_rrset(*n, rr, ttl_err);
return node_add_rrset(*n, rr);
}
static int recreate_normal_tree(const zone_contents_t *z, zone_contents_t *out)
......@@ -770,10 +771,10 @@ static bool rrset_is_nsec3rel(const knot_rrset_t *rr)
== KNOT_RRTYPE_NSEC3));
}
int zone_contents_add_rr(zone_contents_t *z, const knot_rrset_t *rr,
zone_node_t **n, bool *ttl_err)
int knot_zone_contents_add_rr(knot_zone_contents_t *z,
const knot_rrset_t *rr, zone_node_t **n)
{
return insert_rr(z, rr, n, rrset_is_nsec3rel(rr), ttl_err);
return insert_rr(z, rr, n, rrset_is_nsec3rel(rr));
}
/*----------------------------------------------------------------------------*/
......
......@@ -91,8 +91,8 @@ int zone_contents_gen_is_new(const zone_contents_t *contents);
void zone_contents_set_gen_old(zone_contents_t *contents);
void zone_contents_set_gen_new(zone_contents_t *contents);
int zone_contents_add_rr(zone_contents_t *z, const knot_rrset_t *rr,
zone_node_t **n, bool *ttl_err);
int knot_zone_contents_add_rr(knot_zone_contents_t *z,
const knot_rrset_t *rr, zone_node_t **n);
int zone_contents_remove_node(zone_contents_t *contents, const knot_dname_t *owner);
......
......@@ -165,7 +165,7 @@ size_t estimator_trie_htable_memsize(hattrie_t *table)
return size;
}
void estimator_rrset_memsize_wrap(const zs_scanner_t *scanner)
void estimator_rrset_memsize_wrap(zs_scanner_t *scanner)
{
rrset_memsize(scanner->data, scanner);
}
......
......@@ -75,7 +75,7 @@ size_t estimator_trie_htable_memsize(hattrie_t *table);
*
* \param scanner Scanner context.
*/
void estimator_rrset_memsize_wrap(const zs_scanner_t *scanner);
void estimator_rrset_memsize_wrap(zs_scanner_t *scanner);
/*!
* \brief Cleanup function for use with hattrie.
......
......@@ -70,11 +70,11 @@ static int add_rrset_no_merge(zone_node_t *node, const knot_rrset_t *rrset)
/*! \brief Checks if the added RR has the same TTL as the first RR in the node. */
static bool ttl_error(struct rr_data *node_data, const knot_rrset_t *rrset)
{
if (rrset->type == KNOT_RRTYPE_RRSIG) {
if (rrset->type == KNOT_RRTYPE_RRSIG || node_data->rrs.rr_count == 0) {
return false;
}
const uint32_t inserted_ttl = knot_rrset_rr_ttl(rrset, 0);
const uint32_t inserted_ttl = knot_rdata_ttl(knot_rdataset_at(&rrset->rrs, 0));
// Get first RR from node.
const knot_rdata_t *node_rdata = knot_rdataset_at(&node_data->rrs, 0);
const uint32_t node_ttl = knot_rdata_ttl(node_rdata);
......@@ -164,7 +164,7 @@ zone_node_t *node_shallow_copy(const zone_node_t *src)
return dst;
}
int node_add_rrset(zone_node_t *node, const knot_rrset_t *rrset, bool *ttl_err)
int node_add_rrset(zone_node_t *node, const knot_rrset_t *rrset)
{
if (node == NULL || rrset == NULL) {
return KNOT_EINVAL;
......@@ -173,13 +173,14 @@ int node_add_rrset(zone_node_t *node, const knot_rrset_t *rrset, bool *ttl_err)
for (uint16_t i = 0; i < node->rrset_count; ++i) {
if (node->rrs[i].type == rrset->type) {
struct rr_data *node_data = &node->rrs[i];
if (ttl_err) {
// Do TTL check.
*ttl_err = ttl_error(node_data, rrset);
const bool ttl_err = ttl_error(node_data, rrset);
int ret = knot_rdataset_merge(&node_data->rrs,
&rrset->rrs, NULL);
if (ret != KNOT_EOK) {
return ret;
} else {
return ttl_err ? KNOT_ETTL : KNOT_EOK;
}
return knot_rdataset_merge(&node_data->rrs,
&rrset->rrs, NULL);
}
}
......
......@@ -126,12 +126,10 @@ zone_node_t *node_shallow_copy(const zone_node_t *src);
*
* \param node Node to add the RRSet to.
* \param rrset RRSet to add.
* \param ttl_err Set to true if TTL error occured when inserting. New zone API
* will obsolete this parameter.
*
* \return KNOT_E*
*/
int node_add_rrset(zone_node_t *node, const knot_rrset_t *rrset, bool *ttl_err);
int node_add_rrset(zone_node_t *node, const knot_rrset_t *rrset);
/*!
* \brief Removes data for given RR type from node.
......
......@@ -264,9 +264,8 @@ static int check_dnskey_rdata(const knot_rrset_t *rrset, size_t rdata_pos)
/* check that Zone key bit it set - position 7 in net order */
const uint16_t mask = 1 << 8; //0b0000000100000000;
uint16_t flags =
knot_wire_read_u16(knot_rrset_rr_rdata(rrset, rdata_pos));
const knot_rdata_t *rr_data = knot_rdataset_at(&rrset->rrs, rdata_pos);
uint16_t flags = knot_wire_read_u16(knot_rdata_data(rr_data));
if (flags & mask) {
return KNOT_EOK;
} else {
......@@ -334,7 +333,7 @@ static int check_rrsig_rdata(err_handler_t *handler,
uint16_t rr_count = rrset->rrs.rr_count;
for (uint16_t i = 0; i < rr_count; ++i) {
if (original_ttl != knot_rrset_rr_ttl(rrset, i)) {
if (original_ttl != knot_rdata_ttl(knot_rdataset_at(&rrset->rrs, i))) {
err_handler_handle_error(handler, node,
ZC_ERR_RRSIG_RDATA_TTL,
info_str);
......@@ -382,9 +381,9 @@ static int check_rrsig_rdata(err_handler_t *handler,
}
/* Calculate keytag. */
const knot_rdata_t *rr_data = knot_rdataset_at(&dnskey_rrset->rrs, i);
uint16_t dnskey_key_tag =
knot_keytag(knot_rrset_rr_rdata(dnskey_rrset, i),
knot_rrset_rr_size(dnskey_rrset, i));
knot_keytag(knot_rdata_data(rr_data), knot_rdata_rdlen(rr_data));
if (key_tag_rrsig != dnskey_key_tag) {
continue;
}
......@@ -462,7 +461,7 @@ static int check_rrsig_in_rrset(err_handler_t *handler,
}
const knot_rdata_t *sig_rr = knot_rdataset_at(&rrsigs, 0);
if (knot_rrset_rr_ttl(rrset, 0) != knot_rdata_ttl(sig_rr)) {
if (knot_rdata_ttl(knot_rdataset_at(&rrset->rrs, 0)) != knot_rdata_ttl(sig_rr)) {
err_handler_handle_error(handler, node,
ZC_ERR_RRSIG_TTL,
info_str);
......
......@@ -138,10 +138,14 @@ int knot_zone_tree_get_less_or_equal(knot_zone_tree_t *tree,
value_t *fval = NULL;
int ret = hattrie_find_leq(tree, (char*)lf+1, *lf, &fval);
if (fval) *found = (zone_node_t *)(*fval);
if (fval) {
*found = (zone_node_t *)(*fval);
}
int exact_match = 0;