Commit 3b5b6140 authored by Jan Kadlec's avatar Jan Kadlec

Renamed zone-load.c in zone folder to zone-create, minor cleaunp, doxygen.

- Removed hattrie for duplicated DNAMEs - was not active anyway.
parent 7ba06abb
......@@ -154,8 +154,8 @@ src/knot/zone/zone-diff.c
src/knot/zone/zone-diff.h
src/knot/zone/zone-dump.c
src/knot/zone/zone-dump.h
src/knot/zone/zone-load.c
src/knot/zone/zone-load.h
src/knot/zone/zone-create.c
src/knot/zone/zone-create.h
src/knot/zone/zone-tree.c
src/knot/zone/zone-tree.h
src/knot/zone/zone.c
......
......@@ -264,8 +264,8 @@ libknotd_la_SOURCES = \
knot/zone/zone-diff.h \
knot/zone/zone-dump.c \
knot/zone/zone-dump.h \
knot/zone/zone-load.c \
knot/zone/zone-load.h \
knot/zone/zone-create.c \
knot/zone/zone-create.h \
knot/zone/zone-tree.c \
knot/zone/zone-tree.h \
knot/zone/zone.c \
......
......@@ -31,7 +31,7 @@
#include "knot/ctl/process.h"
#include "knot/ctl/remote.h"
#include "knot/conf/conf.h"
#include "knot/zone/zone-load.h"
#include "knot/zone/zone-create.h"
#include "knot/server/socket.h"
#include "knot/server/tcp-handler.h"
#include "libknot/packet/wire.h"
......
......@@ -23,7 +23,7 @@
#include "knot/other/debug.h"
#include "knot/server/zone-load.h"
#include "knot/server/zones.h"
#include "knot/zone/zone-load.h"
#include "knot/zone/zone-create.h"
#include "libknot/dname.h"
#include "libknot/dnssec/crypto.h"
#include "libknot/dnssec/random.h"
......
......@@ -27,7 +27,7 @@
#include "libknot/packet/pkt.h"
#include "libknot/dname.h"
#include "knot/zone/zone.h"
#include "knot/zone/zone-load.h"
#include "knot/zone/zone-create.h"
#include "knot/dnssec/zone-nsec.h"
#include "knot/dnssec/zone-sign.h"
#include "libknot/dnssec/random.h"
......@@ -311,14 +311,14 @@ int xfrin_process_axfr_packet(knot_ns_xfr_t *xfr, knot_zone_contents_t **zone)
++xfr->packet_nr;
}
// Init zone loader
zone_loader_t zl = {.z = *zone, .lookup_tree = NULL,
.last_node = NULL, .ret = KNOT_EOK };
// Init zone creator
zcreator_t zc = {.z = *zone,
.last_node = NULL, .ret = KNOT_EOK };
while (ret == KNOT_EOK && rr) {
if (rr->type == KNOT_RRTYPE_SOA &&
knot_node_rrset(zl.z->apex, KNOT_RRTYPE_SOA)) {
knot_node_rrset(zc.z->apex, KNOT_RRTYPE_SOA)) {
// Last SOA, last message, check TSIG.
ret = xfrin_check_tsig(packet, xfr, 1);
knot_pkt_free(&packet);
......@@ -328,7 +328,7 @@ int xfrin_process_axfr_packet(knot_ns_xfr_t *xfr, knot_zone_contents_t **zone)
}
return 1; // Signal that transfer finished.
} else {
ret = zone_loader_step(&zl, rr);
ret = zcreator_step(&zc, rr);
if (ret != KNOT_EOK) {
knot_pkt_free(&packet);
knot_rrset_deep_free(&rr, true, NULL);
......
......@@ -33,12 +33,10 @@
#include "knot/zone/zone-contents.h"
#include "knot/dnssec/zone-nsec.h"
#include "knot/other/debug.h"
#include "knot/zone/zone-load.h"
#include "knot/zone/zone-create.h"
#include "zscanner/file_loader.h"
#include "libknot/rdata.h"
/* ZONE LOADING FROM FILE USING RAGEL PARSER */
void process_error(const scanner_t *s)
{
if (s->stop == true) {
......@@ -75,11 +73,11 @@ static int add_rdata_to_rr(knot_rrset_t *rrset, const scanner_t *scanner)
return KNOT_EOK;
}
static bool handle_err(zone_loader_t *zl,
static bool handle_err(zcreator_t *zc,
const knot_rrset_t *rr,
int ret)
{
char *zname = zl->z ? knot_dname_to_str(zl->z->apex->owner) : NULL;
char *zname = zc->z ? knot_dname_to_str(zc->z->apex->owner) : NULL;
char *rrname = rr ? knot_dname_to_str(rr->owner) : NULL;
if (ret == KNOT_EOUTOFZONE) {
log_zone_warning("Zone %s: Ignoring out-of-zone data for %s\n",
......@@ -96,29 +94,29 @@ static bool handle_err(zone_loader_t *zl,
}
}
int zone_loader_step(zone_loader_t *zl, knot_rrset_t *rr)
int zcreator_step(zcreator_t *zc, knot_rrset_t *rr)
{
assert(zl && rr);
assert(zc && rr);
if (rr->type == KNOT_RRTYPE_SOA &&
knot_node_rrset(zl->z->apex, KNOT_RRTYPE_SOA)) {
knot_node_rrset(zc->z->apex, KNOT_RRTYPE_SOA)) {
// Ignore extra SOA
knot_rrset_deep_free(&rr, true, NULL);
return KNOT_EOK;
}
knot_node_t *n;
if (zl->last_node &&
knot_dname_is_equal(zl->last_node->owner, rr->owner)) {
if (zc->last_node &&
knot_dname_is_equal(zc->last_node->owner, rr->owner)) {
// Reuse hint from last addition.
n = zl->last_node;
n = zc->last_node;
} else {
// Search for node or create a new one
n = NULL;
}
int ret = knot_zone_contents_add_rr(zl->z, rr, &n);
int ret = knot_zone_contents_add_rr(zc->z, rr, &n);
if (ret < 0) {
if (!handle_err(zl, rr, ret)) {
if (!handle_err(zc, rr, ret)) {
// Fatal error
return ret;
}
......@@ -129,12 +127,12 @@ int zone_loader_step(zone_loader_t *zl, knot_rrset_t *rr)
knot_rrset_deep_free(&rr, true, NULL);
}
assert(n);
zl->last_node = n;
zc->last_node = n;
bool sem_fatal_error = false;
err_handler_t err_handler;
err_handler_init(&err_handler);
ret = sem_check_node_plain(zl->z, n,
ret = sem_check_node_plain(zc->z, n,
&err_handler, true,
&sem_fatal_error);
if (ret != KNOT_EOK) {
......@@ -147,14 +145,14 @@ int zone_loader_step(zone_loader_t *zl, knot_rrset_t *rr)
/*! \brief Creates RR from parser input, passes it to handling function. */
static void loader_process(const scanner_t *scanner)
{
zone_loader_t *zl = scanner->data;
if (zl->ret != KNOT_EOK) {
zcreator_t *zc = scanner->data;
if (zc->ret != KNOT_EOK) {
return;
}
knot_dname_t *owner = knot_dname_copy(scanner->r_owner);
if (owner == NULL) {
zl->ret = KNOT_ENOMEM;
zc->ret = KNOT_ENOMEM;
return;
}
knot_dname_to_lower(owner);
......@@ -165,7 +163,7 @@ static void loader_process(const scanner_t *scanner)
scanner->r_ttl, NULL);
if (rr == NULL) {
knot_dname_free(&owner);
zl->ret = KNOT_ENOMEM;
zc->ret = KNOT_ENOMEM;
return;
}
......@@ -175,14 +173,14 @@ static void loader_process(const scanner_t *scanner)
log_zone_error("%s:%"PRIu64": Can't add RDATA for '%s'.\n",
scanner->file_name, scanner->line_counter, rr_name);
free(rr_name);
zl->ret = ret;
zc->ret = ret;
return;
}
ret = zone_loader_step(zl, rr);
ret = zcreator_step(zc, rr);
if (ret != KNOT_EOK) {
knot_rrset_deep_free(&rr, 1, NULL);
zl->ret = ret;
zc->ret = ret;
return;
}
}
......@@ -213,18 +211,12 @@ int zonefile_open(zloader_t *loader, const conf_zone_t *conf)
}
/* Create context. */
zone_loader_t *zl = xmalloc(sizeof(zone_loader_t));
memset(zl, 0, sizeof(*zl));
zcreator_t *zc = xmalloc(sizeof(zcreator_t));
memset(zc, 0, sizeof(zcreator_t));
/* Create trie for DNAME duplicits. */
zl->lookup_tree = hattrie_create();
if (zl->lookup_tree == NULL) {
free(zl);
return KNOT_ENOMEM;
}
zl->z = create_zone_from_name(conf->name);
if (zl->z == NULL) {
free(zl);
zc->z = create_zone_from_name(conf->name);
if (zc->z == NULL) {
free(zc);
return KNOT_ENOMEM;
}
......@@ -233,16 +225,15 @@ int zonefile_open(zloader_t *loader, const conf_zone_t *conf)
loader->file_loader = file_loader_create(conf->file, conf->name,
KNOT_CLASS_IN, 3600,
loader_process, process_error,
zl);
zc);
if (loader->file_loader == NULL) {
hattrie_free(zl->lookup_tree);
free(zl);
free(zc);
return KNOT_ERROR;
}
loader->source = strdup(conf->file);
loader->origin = strdup(conf->name);
loader->context = zl;
loader->creator = zc;
loader->semantic_checks = conf->enable_checks;
return KNOT_EOK;
......@@ -256,8 +247,8 @@ knot_zone_contents_t *zonefile_load(zloader_t *loader)
return NULL;
}
zone_loader_t *c = loader->context;
assert(c);
zcreator_t *zc = loader->creator;
assert(zc);
int ret = file_loader_process(loader->file_loader);
if (ret != ZSCANNER_OK) {
log_zone_error("%s: zone file could not be loaded (%s).\n",
......@@ -265,9 +256,9 @@ knot_zone_contents_t *zonefile_load(zloader_t *loader)
goto fail;
}
if (c->ret != KNOT_EOK) {
if (zc->ret != KNOT_EOK) {
log_zone_error("%s: zone file could not be loaded (%s).\n",
loader->source, knot_strerror(c->ret));
loader->source, knot_strerror(zc->ret));
goto fail;
}
......@@ -279,7 +270,7 @@ knot_zone_contents_t *zonefile_load(zloader_t *loader)
goto fail;
}
if (knot_node_rrset(loader->context->z->apex, KNOT_RRTYPE_SOA) == NULL) {
if (knot_node_rrset(loader->creator->z->apex, KNOT_RRTYPE_SOA) == NULL) {
log_zone_error("%s: no SOA record in the zone file.\n",
loader->source);
goto fail;
......@@ -288,7 +279,7 @@ knot_zone_contents_t *zonefile_load(zloader_t *loader)
knot_node_t *first_nsec3_node = NULL;
knot_node_t *last_nsec3_node = NULL;
int kret = knot_zone_contents_adjust_full(c->z,
int kret = knot_zone_contents_adjust_full(zc->z,
&first_nsec3_node, &last_nsec3_node);
if (kret != KNOT_EOK) {
log_zone_error("%s: Failed to finalize zone contents: %s\n",
......@@ -299,21 +290,21 @@ knot_zone_contents_t *zonefile_load(zloader_t *loader)
if (loader->semantic_checks) {
int check_level = 1;
const knot_rrset_t *soa_rr =
knot_node_rrset(knot_zone_contents_apex(c->z),
knot_node_rrset(zc->z->apex,
KNOT_RRTYPE_SOA);
assert(soa_rr); // In this point, SOA has to exist
const knot_rrset_t *nsec3param_rr =
knot_node_rrset(knot_zone_contents_apex(c->z),
knot_node_rrset(zc->z->apex,
KNOT_RRTYPE_NSEC3PARAM);
if (knot_zone_contents_is_signed(c->z) && nsec3param_rr == NULL) {
if (knot_zone_contents_is_signed(zc->z) && nsec3param_rr == NULL) {
/* Set check level to DNSSEC. */
check_level = 2;
} else if (knot_zone_contents_is_signed(c->z) && nsec3param_rr) {
} else if (knot_zone_contents_is_signed(zc->z) && nsec3param_rr) {
check_level = 3;
}
err_handler_t err_handler;
err_handler_init(&err_handler);
zone_do_sem_checks(c->z, check_level,
zone_do_sem_checks(zc->z, check_level,
&err_handler, first_nsec3_node,
last_nsec3_node);
char *zname = knot_dname_to_str(knot_rrset_owner(soa_rr));
......@@ -321,10 +312,10 @@ knot_zone_contents_t *zonefile_load(zloader_t *loader)
free(zname);
}
return c->z;
return zc->z;
fail:
knot_zone_contents_deep_free(&c->z);
knot_zone_contents_deep_free(&zc->z);
return NULL;
}
......@@ -334,11 +325,9 @@ void zonefile_close(zloader_t *loader)
return;
}
hattrie_free(loader->context->lookup_tree);
file_loader_free(loader->file_loader);
free(loader->source);
free(loader->origin);
free(loader->context);
free(loader->creator);
}
......@@ -32,26 +32,25 @@
#include "knot/zone/zone.h"
#include "knot/zone/semantic-check.h"
#include "zscanner/zscanner.h"
typedef struct zone_loader {
knot_zone_contents_t *z;
hattrie_t *lookup_tree;
knot_node_t *last_node;
int ret;
} zone_loader_t;
/*!
* \brief Zone creator structure.
*/
typedef struct zone_creator {
knot_zone_contents_t *z; /*!< Created zone. */
knot_node_t *last_node; /*!< Last used node, use to save zone lookup. */
int ret; /*!< Return value. */
} zcreator_t;
/*!
* \brief Zone loader structure.
*/
typedef struct zloader_t
{
char *source; /*!< Zone source file. */
char *origin; /*!< Zone's origin string. */
bool semantic_checks; /*!< Do semantic checks. */
err_handler_t *err_handler; /*!< Semantic checks error handler. */
file_loader_t *file_loader; /*!< Scanner's file loader. */
zone_loader_t *context; /*!< Loader context. */
typedef struct zloader_t {
char *source; /*!< Zone source file. */
char *origin; /*!< Zone's origin string. */
bool semantic_checks; /*!< Do semantic checks. */
err_handler_t *err_handler; /*!< Semantic checks error handler. */
file_loader_t *file_loader; /*!< Scanner's file loader. */
zcreator_t *creator; /*!< Loader context. */
} zloader_t;
/*!
......@@ -84,7 +83,7 @@ void zonefile_close(zloader_t *loader);
knot_zone_contents_t *create_zone_from_name(const char *origin);
int zone_loader_step(zone_loader_t *zl, knot_rrset_t *rr);
int zcreator_step(zcreator_t *zl, knot_rrset_t *rr);
void process_error(const scanner_t *scanner);
......
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