Commit d8e2ed5a authored by Jan Včelák's avatar Jan Včelák 🚀

semantic checks: migrate to new logging API

parent 961d5cb4
......@@ -219,8 +219,8 @@ static int apply_remove(zone_contents_t *contents, changeset_t *chset)
}
/*! \brief Adds a single RR into zone contents. */
static int add_rr(zone_node_t *node, const knot_rrset_t *rr,
changeset_t *chset, bool master)
static int add_rr(const zone_contents_t *zone, zone_node_t *node,
const knot_rrset_t *rr, changeset_t *chset, bool master)
{
knot_rrset_t changed_rrset = node_rrset(node, rr->type);
if (!knot_rrset_empty(&changed_rrset)) {
......@@ -252,7 +252,7 @@ static int add_rr(zone_node_t *node, const knot_rrset_t *rr,
if (ret == KNOT_ETTL) {
// Handle possible TTL errors.
log_ttl_error(node, rr);
log_ttl_error(zone, node, rr);
if (!master) {
// TTL errors fatal only for master.
return KNOT_EOK;
......@@ -277,7 +277,7 @@ static int apply_add(zone_contents_t *contents, changeset_t *chset,
return KNOT_ENOMEM;
}
int ret = add_rr(node, rr, chset, master);
int ret = add_rr(contents, node, rr, chset, master);
if (ret != KNOT_EOK) {
return ret;
}
......@@ -297,7 +297,7 @@ static int apply_replace_soa(zone_contents_t *contents, changeset_t *chset)
assert(!node_rrtype_exists(contents->apex, KNOT_RRTYPE_SOA));
return add_rr(contents->apex, chset->soa_to, chset, false);
return add_rr(contents, contents->apex, chset->soa_to, chset, false);
}
/*! \brief Apply single change to zone contents structure. */
......
This diff is collapsed.
......@@ -151,13 +151,14 @@ void err_handler_init(err_handler_t *err_handler);
*
* \return err_handler_t * Created error handler.
*/
err_handler_t *err_handler_new();
err_handler_t *err_handler_new(void);
/*!
* \brief Called when error has been encountered in node. Will either log error
* or print it, depending on handler's options.
*
* \param handler Error handler.
* \param zone Zone content which is being checked.
* \param node Node with semantic error in it.
* \param error Type of error.
* \param data Additional info in string.
......@@ -167,6 +168,7 @@ err_handler_t *err_handler_new();
* \retval ZC_ERR_ALLOC if memory error.
*/
int err_handler_handle_error(err_handler_t *handler,
const zone_contents_t *zone,
const zone_node_t *node,
int error, const char *data);
......@@ -186,13 +188,6 @@ void log_cyclic_errors_in_zone(err_handler_t *handler,
const zone_node_t *last_nsec3_node,
char do_checks);
/*!
* \brief This function prints all errors that occured in zone.
*
* \param handler Error handler containing found errors.
*/
void err_handler_log_all(err_handler_t *handler);
/*!
* \brief Helper function - wraps its arguments into arg_t structure and
* calls function that does the actual work.
......
......@@ -41,13 +41,16 @@
void process_error(zs_scanner_t *s)
{
zcreator_t *zc = s->data;
const knot_dname_t *zname = zc->z->apex->owner;
if (s->stop == true) {
log_zone_error("Fatal error in zone file %s:%"PRIu64": %s "
log_zone_error(zname, "Fatal error in zone file %s:%"PRIu64": %s "
"Stopping zone loading.\n",
s->file_name, s->line_counter,
zs_strerror(s->error_code));
} else {
log_zone_error("Error in zone file %s:%"PRIu64": %s\n",
log_zone_error(zname,"Error in zone file %s:%"PRIu64": %s\n",
s->file_name, s->line_counter,
zs_strerror(s->error_code));
}
......@@ -62,31 +65,29 @@ static int add_rdata_to_rr(knot_rrset_t *rrset, const zs_scanner_t *scanner)
static bool handle_err(zcreator_t *zc, const zone_node_t *node,
const knot_rrset_t *rr, int ret, bool master)
{
char *zname = zc->z ? knot_dname_to_str(zc->z->apex->owner) : NULL;
const knot_dname_t *zname = zc->z->apex->owner;
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",
zname ? zname : "unknown", rrname ? rrname : "unknown");
free(zname);
log_zone_warning(zname, "Ignoring out-of-zone data for %s\n",
rrname ? rrname : "unknown");
free(rrname);
return true;
} else if (ret == KNOT_ETTL) {
free(zname);
free(rrname);
assert(node);
log_ttl_error(node, rr);
log_ttl_error(zc->z, node, rr);
// Fail if we're the master for this zone.
return !master;
} else {
log_zone_error("Zone %s: Cannot process record %s, stopping.\n",
zname ? zname : "unknown", rrname ? rrname : "unknown");
free(zname);
log_zone_error(zname, "Cannot process record %s, stopping\n",
rrname ? rrname : "unknown");
free(rrname);
return false;
}
}
void log_ttl_error(const zone_node_t *node, const knot_rrset_t *rr)
void log_ttl_error(const zone_contents_t *zone, const zone_node_t *node,
const knot_rrset_t *rr)
{
err_handler_t err_handler;
err_handler_init(&err_handler);
......@@ -101,7 +102,7 @@ void log_ttl_error(const zone_node_t *node, const knot_rrset_t *rr)
}
/*!< \todo REPLACE WITH FATAL ERROR for master. */
err_handler_handle_error(&err_handler, node,
err_handler_handle_error(&err_handler, zone, node,
ZC_ERR_TTL_MISMATCH, info_str);
}
......@@ -166,8 +167,9 @@ static void loader_process(zs_scanner_t *scanner)
int ret = add_rdata_to_rr(&rr, scanner);
if (ret != KNOT_EOK) {
char *rr_name = knot_dname_to_str(rr.owner);
log_zone_error("%s:%"PRIu64": Can't add RDATA for '%s'.\n",
scanner->file_name, scanner->line_counter, rr_name);
log_zone_error(zc->z->apex->owner, "File %s:%"PRIu64": "
"Can't add RDATA for '%s'.\n", scanner->file_name,
scanner->line_counter, rr_name);
free(rr_name);
knot_dname_free(&owner, NULL);
zc->ret = ret;
......@@ -252,30 +254,32 @@ zone_contents_t *zonefile_load(zloader_t *loader)
}
zcreator_t *zc = loader->creator;
const knot_dname_t *zname = zc->z->apex->owner;
assert(zc);
int ret = zs_loader_process(loader->file_loader);
if (ret != ZS_OK) {
log_zone_error("%s: zone file could not be loaded (%s).\n",
log_zone_error(zname, "Zone file '%s' could not be loaded: %s\n",
loader->source, zs_strerror(ret));
goto fail;
}
if (zc->ret != KNOT_EOK) {
log_zone_error("%s: zone file could not be loaded (%s).\n",
log_zone_error(zname, "Zone file '%s' could not be loaded: %s\n",
loader->source, knot_strerror(zc->ret));
goto fail;
}
if (loader->file_loader->scanner->error_counter > 0) {
log_zone_error("%s: zone file could not be loaded due to "
"%"PRIu64" errors encountered.\n",
log_zone_error(zname, "Zone file '%s' could not be loaded due "
"to %"PRIu64" errors encountered.\n",
loader->source,
loader->file_loader->scanner->error_counter);
goto fail;
}
if (!node_rrtype_exists(loader->creator->z->apex, KNOT_RRTYPE_SOA)) {
log_zone_error("%s: no SOA record in the zone file.\n",
log_zone_error(zname, "No SOA record in the zone file '%s'\n",
loader->source);
goto fail;
}
......@@ -286,8 +290,8 @@ zone_contents_t *zonefile_load(zloader_t *loader)
int kret = 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",
loader->source, knot_strerror(kret));
log_zone_error(zname, "Failed to finalize zone contents: %s\n",
knot_strerror(kret));
goto fail;
}
......@@ -309,9 +313,7 @@ zone_contents_t *zonefile_load(zloader_t *loader)
zone_do_sem_checks(zc->z, check_level,
&err_handler, first_nsec3_node,
last_nsec3_node);
char *zname = knot_dname_to_str(soa_rr.owner);
log_zone_info("Semantic checks completed for zone=%s\n", zname);
free(zname);
log_zone_info(zname, "Semantic checks completed\n");
}
return zc->z;
......@@ -369,16 +371,18 @@ int zonefile_write(const char *path, zone_contents_t *zone,
return KNOT_EWRITABLE;
}
const knot_dname_t *zname = zone->apex->owner;
FILE *f = fdopen(fd, "w");
if (f == NULL) {
log_zone_warning("Failed to open file descriptor for text zone.\n");
log_zone_warning(zname, "Failed to open zone master file.\n");
unlink(new_fname);
free(new_fname);
return KNOT_ERROR;
}
if (zone_dump_text(zone, from, f) != KNOT_EOK) {
log_zone_warning("Failed to save the transferred zone to '%s'.\n",
log_zone_warning(zname, "Failed to save the transferred zone to '%s'.\n",
new_fname);
fclose(f);
unlink(new_fname);
......@@ -394,8 +398,8 @@ int zonefile_write(const char *path, zone_contents_t *zone,
int ret = rename(new_fname, path);
if (ret < 0 && ret != EEXIST) {
log_zone_warning("Failed to replace old zone file '%s'' with a "
"new zone file '%s'.\n", path, new_fname);
log_zone_warning(zname, "Failed to replace old zone file '%s' "
"with a new zone file '%s'.\n", path, new_fname);
unlink(new_fname);
free(new_fname);
return KNOT_ERROR;
......
......@@ -113,9 +113,11 @@ void process_error(zs_scanner_t *scanner);
/*!
* \brief Logs TTL mismatch error.
*
* \param zone Related zone.
* \param node Node with TTL mismatch.
* \param rr RR that caused the mismatch.
*/
void log_ttl_error(const zone_node_t *node, const knot_rrset_t *rr);
void log_ttl_error(const zone_contents_t *zone, const zone_node_t *node,
const knot_rrset_t *rr);
/*! @} */
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