Commit 9aa158ac authored by Jan Kadlec's avatar Jan Kadlec

Simplified zone loading.

- Structures need to be renamed a bit, missing doxygen
- Optimization pending, but that's okay, since future zone API should take care of those
parent 339f7131
......@@ -343,17 +343,7 @@ static int follow_cname(knot_pkt_t *pkt, uint16_t rrtype, struct query_data *qda
return ERROR;
}
cname_rr = dname_cname_synth(cname_rr, qdata->name, &pkt->mm);
if (cname_rr) {
assert(0);
/* TODO need rrsigs? */
const knot_node_t *synth_node =
knot_zone_contents_find_node(qdata->zone->contents,
cname_rr->owner);
rrsigs = knot_node_rrset(synth_node, KNOT_RRTYPE_RRSIG);
} else {
rrsigs = NULL;
}
ret = put_rr(pkt, cname_rr, rrsigs, 0, KNOT_PF_FREE, qdata);
ret = put_rr(pkt, cname_rr, NULL, 0, KNOT_PF_FREE, qdata);
switch (ret) {
case KNOT_EOK: break;
case KNOT_ESPACE: return TRUNC;
......
......@@ -691,6 +691,54 @@ int knot_zone_contents_create_node(knot_zone_contents_t *contents,
/*----------------------------------------------------------------------------*/
static int insert_rr(knot_zone_contents_t *z, knot_rrset_t *rr, knot_node_t **n,
bool nsec3)
{
if (z == NULL || rr == NULL || n == NULL) {
return KNOT_EINVAL;
}
// check if the RRSet belongs to the zone
if (!knot_dname_is_equal(rr->owner, z->apex->owner)
&& !knot_dname_is_sub(rr->owner, z->apex->owner)) {
return KNOT_EOUTOFZONE;
}
int ret = KNOT_EOK;
if (*n == NULL) {
*n = nsec3 ? knot_zone_contents_get_nsec3_node(z, rr->owner) :
knot_zone_contents_get_node(z, rr->owner);
if (*n == NULL) {
// Create new, insert
*n = knot_node_new(rr->owner, NULL, 0);
if (*n == NULL) {
return KNOT_ENOMEM;
}
ret = nsec3 ? knot_zone_contents_add_nsec3_node(z, *n, true, 0) :
knot_zone_contents_add_node(z, *n, true, 0);
if (ret != KNOT_EOK) {
knot_node_free(n);
}
}
}
return knot_node_add_rrset(*n, rr);
}
int knot_zone_contents_add_nsec3_rr(knot_zone_contents_t *z,
knot_rrset_t *rr, knot_node_t **n)
{
const bool nsec3 = true;
return insert_rr(z, rr, n, nsec3);
}
int knot_zone_contents_add_rr(knot_zone_contents_t *z,
knot_rrset_t *rr, knot_node_t **n)
{
const bool nsec3 = false;
return insert_rr(z, rr, n, nsec3);
}
int knot_zone_contents_add_rrset(knot_zone_contents_t *zone,
knot_rrset_t *rrset, knot_node_t **node,
knot_rrset_dupl_handling_t dupl)
......
......@@ -28,7 +28,6 @@
#define _KNOT_ZONE_CONTENTS_H_
#include "knot/zone/node.h"
#include "libknot/dname.h"
#include "libknot/dnssec/nsec3.h"
#include "knot/zone/zone-tree.h"
......@@ -134,6 +133,11 @@ int knot_zone_contents_create_node(knot_zone_contents_t *contents,
const knot_rrset_t *rr,
knot_node_t **node);
int knot_zone_contents_add_nsec3_rr(knot_zone_contents_t *z,
knot_rrset_t *rr, knot_node_t **n);
int knot_zone_contents_add_rr(knot_zone_contents_t *z,
knot_rrset_t *rr, knot_node_t **n);
/*!
* \brief Adds a RRSet to the given zone.
*
......
This diff is collapsed.
......@@ -45,6 +45,13 @@ struct parser_context {
typedef struct parser_context parser_context_t;
typedef struct zone_loader {
knot_zone_contents_t *z;
err_handler_t *err_handler;
hattrie_t *lookup_tree;
int ret;
} zone_loader_t;
/*!
* \brief Zone loader structure.
*/
......@@ -55,7 +62,7 @@ typedef struct zloader_t
int semantic_checks; /*!< Wanted level of semantic checks. */
err_handler_t *err_handler; /*!< Semantic checks error handler. */
file_loader_t *file_loader; /*!< Scanner's file loader. */
parser_context_t *context; /*!< Loader context. */
zone_loader_t *context; /*!< Loader context. */
} zloader_t;
......
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