summaryrefslogtreecommitdiff
path: root/src/zcompile
diff options
context:
space:
mode:
Diffstat (limited to 'src/zcompile')
-rw-r--r--src/zcompile/parser-descriptor.c7
-rw-r--r--src/zcompile/parser-util.c143
-rw-r--r--src/zcompile/zcompile.c173
-rw-r--r--src/zcompile/zcompile_main.c17
-rw-r--r--src/zcompile/zparser.y75
5 files changed, 266 insertions, 149 deletions
diff --git a/src/zcompile/parser-descriptor.c b/src/zcompile/parser-descriptor.c
index 41e7f2d..152781c 100644
--- a/src/zcompile/parser-descriptor.c
+++ b/src/zcompile/parser-descriptor.c
@@ -61,7 +61,7 @@
/* FIXME: Generate .y and .l to zoneparser/ */
#include "zparser.h"
-enum desclen { PARSER_RRTYPE_DESCRIPTORS_LENGTH = 32770 }; // used to be 101
+enum desclen { PARSER_RRTYPE_DESCRIPTORS_LENGTH = 65536 }; // used to be 101
/* Taken from RFC 1035, section 3.2.4. */
static knot_lookup_table_t dns_rrclasses[] = {
@@ -364,12 +364,13 @@ static parser_rrtype_descriptor_t
/* 32769 */
[32769] = { PARSER_RRTYPE_DLV, T_DLV, "DLV", 4,
{ PARSER_RDATA_WF_SHORT, PARSER_RDATA_WF_BYTE,
- PARSER_RDATA_WF_BYTE, PARSER_RDATA_WF_BINARY } },
+ PARSER_RDATA_WF_BYTE, PARSER_RDATA_WF_BINARY }},
+ [32770 ... 65535] = { PARSER_RRTYPE_TYPEXXX, T_UTYPE, NULL, 1, { PARSER_RDATA_WF_BINARY }}
};
parser_rrtype_descriptor_t *parser_rrtype_descriptor_by_type(uint16_t type)
{
- if (type <= PARSER_RRTYPE_DLV) {
+ if (type <= 65535) {
return &knot_rrtype_descriptors[type];
}
return &knot_rrtype_descriptors[0];
diff --git a/src/zcompile/parser-util.c b/src/zcompile/parser-util.c
index dde5411..c225872 100644
--- a/src/zcompile/parser-util.c
+++ b/src/zcompile/parser-util.c
@@ -62,7 +62,7 @@
#include "common/base32hex.h"
#include "zcompile/parser-util.h"
#include "zcompile/zcompile.h"
-#include "libknot/util/descriptor.h"
+#include "parser-descriptor.h"
#include "libknot/util/utils.h"
#include "zcompile/zcompile-error.h"
@@ -812,6 +812,7 @@ uint32_t strtoserial(const char *nptr, const char **endptr)
inline void write_uint32(void *dst, uint32_t data)
{
+/*!< \todo Check what this means and delete if obsolete. */
#ifdef ALLOW_UNALIGNED_ACCESSES
*(uint32_t *) dst = htonl(data);
#else
@@ -925,7 +926,6 @@ time_t mktime_from_utc(const struct tm *tm)
}
/*!< Following functions are conversions from text to wire. */
-
//#define DEBUG_UNKNOWN_RDATA
#ifdef DEBUG_UNKNOWN_RDATA
@@ -994,6 +994,8 @@ static inline int rdata_atom_is_domain(uint16_t type, size_t index)
&& (descriptor->wireformat[index] ==
KNOT_RDATA_WF_COMPRESSED_DNAME ||
descriptor->wireformat[index] ==
+ KNOT_RDATA_WF_LITERAL_DNAME ||
+ descriptor->wireformat[index] ==
KNOT_RDATA_WF_UNCOMPRESSED_DNAME));
}
@@ -1013,6 +1015,8 @@ static inline uint8_t rdata_atom_wireformat_type(uint16_t type, size_t index)
return descriptor->wireformat[index];
}
+typedef int (*printf_t)(const char *fmt, ...);
+
/*!
* \brief Converts rdata wireformat to rdata items.
*
@@ -1028,10 +1032,12 @@ static ssize_t rdata_wireformat_to_rdata_atoms(const uint16_t *wireformat,
const uint16_t data_size,
knot_rdata_item_t **items)
{
- dbg_rdata("read length: %d\n", data_size);
- uint16_t const *end = (uint16_t *)((uint8_t *)wireformat + (data_size));
+ /*!< \todo This is so ugly, it makes me wanna puke. */
+ uint16_t const *end =
+ (uint16_t *)((uint8_t *)wireformat + (data_size));
dbg_rdata("set end pointer: %p which means length: %d\n", end,
(uint8_t *)end - (uint8_t *)wireformat);
+ dbg_rdata("Parsing following wf: ");
size_t i;
knot_rdata_item_t *temp_rdatas =
malloc(sizeof(*temp_rdatas) * MAXRDATALEN);
@@ -1050,69 +1056,78 @@ static ssize_t rdata_wireformat_to_rdata_atoms(const uint16_t *wireformat,
descriptor->length, data_size);
for (i = 0; i < descriptor->length; ++i) {
+ dbg_rdata("this particular item is type %d.\n",
+ rdata_atom_wireformat_type(rrtype, i));
int is_domain = 0;
int is_wirestore = 0;
size_t length = 0;
length = 0;
- int required = descriptor->length;
+ bool required = descriptor->fixed_items;
switch (rdata_atom_wireformat_type(rrtype, i)) {
case KNOT_RDATA_WF_COMPRESSED_DNAME:
case KNOT_RDATA_WF_UNCOMPRESSED_DNAME:
+ dbg_rdata("Parsed item is a dname.\n");
is_domain = 1;
break;
case KNOT_RDATA_WF_LITERAL_DNAME:
+ dbg_rdata("Parsed item is a literal dname.\n");
is_domain = 1;
is_wirestore = 1;
break;
case KNOT_RDATA_WF_BYTE:
+ dbg_rdata("Parsed item is a byte.\n");
length = sizeof(uint8_t);
break;
case KNOT_RDATA_WF_SHORT:
+ dbg_rdata("Parsed item is a short.\n");
length = sizeof(uint16_t);
break;
case KNOT_RDATA_WF_LONG:
+ dbg_rdata("Parsed item is a long.\n");
length = sizeof(uint32_t);
break;
+ case KNOT_RDATA_WF_APL:
+ dbg_rdata("APL data.\n");
+ case KNOT_RDATA_WF_TEXT_SINGLE:
case KNOT_RDATA_WF_TEXT:
+ dbg_rdata("TEXT rdata.\n");
case KNOT_RDATA_WF_BINARYWITHLENGTH:
+ dbg_rdata("BINARYWITHLENGTH rdata.\n");
/* Length is stored in the first byte. */
- length = 1;
- if ((uint8_t *)wireformat + length <= (uint8_t *)end) {
- // length += wireformat[length - 1];
- length += *((uint8_t *)wireformat);
- dbg_rdata("%d: set new length: %d\n", i,
- length);
- }
- /*if (buffer_position(packet) + length <= end) {
- length += buffer_current(packet)[length - 1];
- }*/
+ length = data_size;
break;
case KNOT_RDATA_WF_A:
+ dbg_rdata("Parsed item is an IPv4 address.\n");
length = sizeof(in_addr_t);
break;
case KNOT_RDATA_WF_AAAA:
+ dbg_rdata("Parsed item is an IPv6 address.\n");
length = IP6ADDRLEN;
break;
case KNOT_RDATA_WF_BINARY:
/* Remaining RDATA is binary. */
- dbg_rdata("%d: guessing length from pointers: %p %p\n",
+ dbg_rdata("BINARY: item %d: guessing length from pointers: %p %p. ",
i,
wireformat, end);
length = (uint8_t *)end - (uint8_t *)wireformat;
-// length = end - buffer_position(packet);
- break;
- case KNOT_RDATA_WF_APL:
- length = (sizeof(uint16_t) /* address family */
- + sizeof(uint8_t) /* prefix */
- + sizeof(uint8_t)); /* length */
- if ((uint8_t *)wireformat + length <= (uint8_t *)end) {
- /* Mask out negation bit. */
- length += (wireformat[length - 1]
- & APL_LENGTH_MASK);
- }
+ dbg_rdata("Result: %d.\n",
+ length);
break;
+// case KNOT_RDATA_WF_APL:
+// length = (sizeof(uint16_t) /* address family */
+// + sizeof(uint8_t) /* prefix */
+// + sizeof(uint8_t)); /* length */
+// if ((uint8_t *)wireformat + length <= (uint8_t *)end) {
+// /* Mask out negation bit. */
+// dbg_rdata("APL: length was %d. ", length);
+// length += (wireformat[data_size - 1]
+// & APL_LENGTH_MASK);
+// dbg_rdata("APL: after masking: %d.\n", length);
+// }
+// break;
case KNOT_RDATA_WF_IPSECGATEWAY:
+ dbg_rdata("Parsed item is an IPSECGATEWAY address.\n");
switch (rdata_atom_data(temp_rdatas[1])[0]) {
/* gateway type */
default:
@@ -1130,19 +1145,34 @@ static ssize_t rdata_wireformat_to_rdata_atoms(const uint16_t *wireformat,
is_wirestore = 1;
break;
}
+
break;
}
if (is_domain) {
- knot_dname_t *dname;
+ knot_dname_t *dname = NULL;
+ /*
+ * Since we don't know how many dnames there are
+ * in the whole wireformat we have to search for next
+ * '\0'.
+ */
+ for (length = 0;
+ (length < ((uint8_t *)end - (uint8_t *)wireformat))
+ && (((uint8_t *)wireformat)[length] != '\0');
+ length++) {
+ ;
+ }
+ length++;
+ dbg_rdata("item %d: length derived from position of "
+ "0: %d\n", i, length);
if (!required && (wireformat == end)) {
break;
}
- dname = knot_dname_new_from_str((char *)wireformat,
- length,
- NULL);
+ dname = knot_dname_new_from_wire((uint8_t *)wireformat,
+ length,
+ NULL);
if (dname == NULL) {
dbg_rdata("malformed dname!\n");
@@ -1150,8 +1180,9 @@ static ssize_t rdata_wireformat_to_rdata_atoms(const uint16_t *wireformat,
free(temp_rdatas);
return KNOTDZCOMPILE_EBRDATA;
}
- dbg_rdata("%d: created dname: %s\n", i,
- knot_dname_to_str(dname));
+
+ dbg_rdata("item %d: created dname: %s, length: %d\n", i,
+ knot_dname_to_str(dname), length);
if (is_wirestore) {
/*temp_rdatas[i].raw_data =
@@ -1180,7 +1211,8 @@ static ssize_t rdata_wireformat_to_rdata_atoms(const uint16_t *wireformat,
}
} else {
- dbg_rdata("%d :length: %d %d %p %p\n", i, length,
+ /*!< \todo This calculated length makes no sense! */
+ dbg_rdata("item %d :length: %d calculated: %d (%p %p)\n", i, length,
end - wireformat,
wireformat, end);
if ((uint8_t *)wireformat + length > (uint8_t *)end) {
@@ -1188,7 +1220,8 @@ static ssize_t rdata_wireformat_to_rdata_atoms(const uint16_t *wireformat,
/* Truncated RDATA. */
/*! \todo rdata purge */
free(temp_rdatas);
- dbg_rdata("truncated rdata\n");
+ dbg_rdata("truncated rdata, end pointer is exceeded by %d octets.\n",
+ (wireformat + length) - end);
return KNOTDZCOMPILE_EBRDATA;
} else {
break;
@@ -1224,15 +1257,13 @@ static ssize_t rdata_wireformat_to_rdata_atoms(const uint16_t *wireformat,
dbg_rdata("wire: %p\n", wireformat);
dbg_rdata("remaining now: %d\n",
end - wireformat);
-
}
dbg_rdata("%p %p\n", wireformat, (uint8_t *)wireformat);
if (wireformat < end) {
/* Trailing garbage. */
- dbg_rdata("w: %p e: %p %d\n", wireformat, end, end - wireformat);
-// region_destroy(temp_region);
+ dbg_rdata("Garbage: w: %p e: %p %d\n", wireformat, end, end - wireformat);
free(temp_rdatas);
return KNOTDZCOMPILE_EBRDATA;
}
@@ -1240,6 +1271,8 @@ static ssize_t rdata_wireformat_to_rdata_atoms(const uint16_t *wireformat,
*items = temp_rdatas;
/* *rdatas = (rdata_atom_type *) region_alloc_init(
region, temp_rdatas, i * sizeof(rdata_atom_type)); */
+ dbg_rdata("wf_to_rdata_atoms: Succesfully converted %d items.\n",
+ i);
return (ssize_t)i;
}
@@ -2062,8 +2095,9 @@ uint16_t * zparser_conv_loc(char *str)
zc_error_prev_line("space expected after seconds");
return NULL;
}
-
- if (sscanf(start, "%16lf", &d) != 1) {
+
+ d = strtod(start, &start);
+ if (errno != 0) {
zc_error_prev_line("error parsing seconds");
}
@@ -2160,9 +2194,10 @@ uint16_t * zparser_conv_loc(char *str)
if (!isspace((int)*str) && *str != '\0') {
++str;
}
-
- if (sscanf(start, "%16lf", &d) != 1) {
- zc_error_prev_line("error parsing altitude");
+
+ d = strtod(start, &start);
+ if (errno != 0) {
+ zc_error_prev_line("error parsing altitued");
}
alt = (uint32_t)(10000000.0 + d * 100 + 0.5);
@@ -2342,18 +2377,12 @@ void zadd_rdata_txt_wireformat(uint16_t *data, int first)
return;
}
dbg_zp("Adding text!\n");
-// hex_print(data + 1, data[0]);
knot_rdata_item_t *rd;
/* First STR in str_seq, allocate 65K in first unused rdata
* else find last used rdata */
if (first) {
rd = &parser->temporary_items[parser->rdata_count];
-// if ((rd->data = (uint8_t *) region_alloc(parser->rr_region,
-// sizeof(uint8_t) + 65535 * sizeof(uint8_t))) == NULL) {
-// zc_error_prev_line("Could not allocate memory for TXT RR");
-// return;
-// }
rd->raw_data = alloc_rdata(65535 * sizeof(uint8_t));
if (rd->raw_data == NULL) {
parser->error_occurred = KNOTDZCOMPILE_ENOMEM;
@@ -2361,7 +2390,6 @@ void zadd_rdata_txt_wireformat(uint16_t *data, int first)
parser->rdata_count++;
rd->raw_data[0] = 0;
} else {
-// assert(0);
rd = &parser->temporary_items[parser->rdata_count-1];
}
@@ -2392,8 +2420,8 @@ void zadd_rdata_domain(knot_dname_t *dname)
void parse_unknown_rdata(uint16_t type, uint16_t *wireformat)
{
- dbg_rdata("parsing unknown rdata for type: %d\n", type);
-// buffer_type packet;
+ dbg_rdata("parsing unknown rdata for type: %s (%d)\n",
+ knot_rrtype_to_string(type), type);
uint16_t size;
ssize_t rdata_count;
ssize_t i;
@@ -2405,14 +2433,13 @@ void parse_unknown_rdata(uint16_t type, uint16_t *wireformat)
return;
}
-// buffer_create_from(&packet, wireformat + 1, *wireformat);
rdata_count = rdata_wireformat_to_rdata_atoms(wireformat + 1, type,
size, &items);
-// dbg_rdata("got %d items\n", rdata_count);
- dbg_rdata("wf to items returned error: %s (%d)\n",
- error_to_str(knot_zcompile_error_msgs, rdata_count),
- rdata_count);
+ dbg_rdata("got %d items\n", rdata_count);
if (rdata_count < 0) {
+ dbg_rdata("wf to items returned error: %s (%d)\n",
+ error_to_str(knot_zcompile_error_msgs, rdata_count),
+ rdata_count);
zc_error_prev_line("bad unknown RDATA\n");
/*!< \todo leaks */
return;
@@ -2429,6 +2456,8 @@ void parse_unknown_rdata(uint16_t type, uint16_t *wireformat)
free(items);
/* Free wireformat */
free(wireformat);
+
+ dbg_rdata("parse_unknown_rdata: Successfuly parsed unknown rdata.\n");
}
void set_bitnsec(uint8_t bits[NSEC_WINDOW_COUNT][NSEC_WINDOW_BITS_SIZE],
diff --git a/src/zcompile/zcompile.c b/src/zcompile/zcompile.c
index d84feb7..263d0d7 100644
--- a/src/zcompile/zcompile.c
+++ b/src/zcompile/zcompile.c
@@ -36,6 +36,8 @@
#include <sys/stat.h>
#include "common/base32hex.h"
+#include "common/log.h"
+#include "knot/other/debug.h"
#include "zcompile/zcompile.h"
#include "zcompile/parser-util.h"
#include "zcompile/zcompile-error.h"
@@ -54,12 +56,6 @@ static long int totalrrs = 0;
extern FILE *zp_get_in(void *scanner);
-#ifdef KNOT_COMPILER_DEBUG
-#define dbg_zp(msg...) fprintf(stderr, msg)
-#else
-#define dbg_zp(msg...)
-#endif
-
/*!
* \brief Adds RRSet to list.
*
@@ -86,6 +82,8 @@ static int rrset_list_add(rrset_list_t **head, knot_rrset_t *rrsig)
tmp->data = rrsig;
*head = tmp;
}
+
+ dbg_zp_verb("zp: rrset_add: Added RRSIG %p to list.\n", rrsig);
return KNOTDZCOMPILE_EOK;
}
@@ -109,6 +107,8 @@ static void rrset_list_delete(rrset_list_t **head)
}
*head = NULL;
+
+ dbg_zp("zp: list_delete: List deleleted.\n");
}
static int find_rrset_for_rrsig_in_zone(knot_zone_contents_t *zone,
@@ -127,10 +127,11 @@ static int find_rrset_for_rrsig_in_zone(knot_zone_contents_t *zone,
rrsig->owner);
}
- dbg_zp("Found this node for RRSIG: %p\n",
- tmp_node);
+ dbg_zp_verb("zp: find_rr_for_sig: Found this node for RRSIG: %p.\n",
+ tmp_node);
if (tmp_node == NULL) {
+ dbg_zp("zp: find_rr_for_sig: There is no node for this RR.\n");
return KNOTDZCOMPILE_EINVAL;
}
@@ -139,23 +140,37 @@ static int find_rrset_for_rrsig_in_zone(knot_zone_contents_t *zone,
knot_rdata_rrsig_type_covered(
rrsig->rdata));
- dbg_zp("Found this rrset for RRSIG: %p\n",
- tmp_rrset);
+ dbg_zp_verb("zp: find_rr_for_sig: Found this RRSet for RRSIG: %p.\n",
+ tmp_rrset);
if (tmp_rrset == NULL) {
+ dbg_zp("zp: find_rr_for_sig: There is no RRSet "
+ "for this RRSIG.\n");
return KNOTDZCOMPILE_EINVAL;
}
if (tmp_rrset->rrsigs != NULL) {
- knot_zone_contents_add_rrsigs(zone, rrsig, &tmp_rrset, &tmp_node,
+ int ret = knot_zone_contents_add_rrsigs(zone, rrsig,
+ &tmp_rrset, &tmp_node,
KNOT_RRSET_DUPL_MERGE, 1);
+ if (ret != KNOT_EOK) {
+ dbg_zp("zp: find_rr_for_sig: Cannot add RRSIG.\n");
+ return ret;
+ }
knot_rrset_free(&rrsig);
} else {
- knot_zone_contents_add_rrsigs(zone, rrsig, &tmp_rrset, &tmp_node,
+ int ret = knot_zone_contents_add_rrsigs(zone, rrsig,
+ &tmp_rrset, &tmp_node,
KNOT_RRSET_DUPL_SKIP, 1);
+ if (ret != KNOT_EOK) {
+ dbg_zp("zp: find_rr_for_sig: Cannot add RRSIG.\n");
+ return ret;
+ }
}
-
+
+ dbg_zp("zp: find_rr_for_sig: Found node: %p found rrset: %p.\n",
+ tmo_node, tmp_rrset);
return KNOTDZCOMPILE_EOK;
}
@@ -173,18 +188,25 @@ static int find_rrset_for_rrsig_in_node(knot_zone_contents_t *zone,
knot_node_get_rrset(node, rrsig_type_covered(rrsig));
if (tmp_rrset == NULL) {
+ dbg_zp("zp: find_rr_for_sig_in_node: Node does not contain "
+ "RRSet of type %s.\n",
+ knot_rrtype_to_string(rrsig_type_covered(rrsig)));
return KNOTDZCOMPILE_EINVAL;
}
if (tmp_rrset->rrsigs != NULL) {
- if (knot_zone_contents_add_rrsigs(zone, rrsig, &tmp_rrset, &node,
+ if (knot_zone_contents_add_rrsigs(zone, rrsig,
+ &tmp_rrset, &node,
KNOT_RRSET_DUPL_MERGE, 1) < 0) {
+ dbg_zp("zp: find_rr_for_sig: Cannot add RRSIG.\n");
return KNOTDZCOMPILE_EINVAL;
}
knot_rrset_free(&rrsig);
} else {
- if (knot_zone_contents_add_rrsigs(zone, rrsig, &tmp_rrset, &node,
+ if (knot_zone_contents_add_rrsigs(zone, rrsig,
+ &tmp_rrset, &node,
KNOT_RRSET_DUPL_SKIP, 1) < 0) {
+ dbg_zp("zp: find_rr_for_sig: Cannot add RRSIG.\n");
return KNOTDZCOMPILE_EINVAL;
}
}
@@ -201,6 +223,8 @@ static knot_node_t *create_node(knot_zone_contents_t *zone,
knot_node_t *(*node_get_func)(const knot_zone_contents_t *zone,
const knot_dname_t *owner))
{
+ dbg_zp_verb("zp: create_node: Creating node using RRSet: %p.\n",
+ current_rrset);
knot_node_t *node =
knot_node_new(current_rrset->owner, NULL, 0);
if (node_add_func(zone, node, 1, 0, 1) != 0) {
@@ -215,6 +239,8 @@ static knot_node_t *create_node(knot_zone_contents_t *zone,
static void process_rrsigs_in_node(knot_zone_contents_t *zone,
knot_node_t *node)
{
+ dbg_zp_verb("zp: process_rrsigs: Processing RRSIGS in node: %p.\n",
+ node);
rrset_list_t *tmp = parser->node_rrsigs;
while (tmp != NULL) {
if (find_rrset_for_rrsig_in_node(zone, node,
@@ -238,18 +264,22 @@ int process_rr(void)
knot_rrtype_descriptor_t *descriptor =
knot_rrtype_descriptor_by_type(current_rrset->type);
- dbg_zp("%s\n", knot_dname_to_str(parser->current_rrset->owner));
- dbg_zp("type: %s\n", knot_rrtype_to_string(parser->current_rrset->type));
- dbg_zp("rdata count: %d\n", parser->current_rrset->rdata->count);
-// hex_print(parser->current_rrset->rdata->items[0].raw_data,
-// parser->current_rrset->rdata->items[0].raw_data[0]);
+dbg_zp_exec_detail(
+ char *name = knot_dname_to_str(parser->current_rrset->owner);
+ dbg_zp_detail("zp: process_rr: Processing RR owned by: %s .\n",
+ name);
+ free(name);
+);
+ dbg_zp_verb("zp: process_rr: Processing type: %s.\n",
+ knot_rrtype_to_string(parser->current_rrset->type));
+ dbg_zp_verb("zp: process_rr: RDATA count: %d.\n",\
+ parser->current_rrset->rdata->count);
if (descriptor->fixed_items) {
assert(current_rrset->rdata->count == descriptor->length);
}
assert(current_rrset->rdata->count > 0);
-
assert(knot_dname_is_fqdn(current_rrset->owner));
int (*node_add_func)(knot_zone_contents_t *, knot_node_t *, int,
@@ -312,12 +342,15 @@ int process_rr(void)
current_rrset->rclass,
current_rrset->ttl);
if (tmp_rrsig == NULL) {
+ dbg_zp("zp: process_rr: Cannot create tmp RRSIG.\n");
return KNOTDZCOMPILE_ENOMEM;
}
if (knot_rrset_add_rdata(tmp_rrsig,
current_rrset->rdata) != KNOT_EOK) {
knot_rrset_free(&tmp_rrsig);
+ dbg_zp("zp: process_rr: Cannot add data to tmp"
+ " RRSIG.\n");
return KNOTDZCOMPILE_EBRDATA;
}
@@ -353,18 +386,24 @@ int process_rr(void)
current_rrset, node_add_func,
node_get_func)) == NULL) {
knot_rrset_free(&tmp_rrsig);
+ dbg_zp("zp: process_rr: Cannot "
+ "create new node.\n");
return KNOTDZCOMPILE_EBADNODE;
}
}
}
if (rrset_list_add(&parser->node_rrsigs, tmp_rrsig) != 0) {
+ dbg_zp("zp: process_rr: Cannot "
+ "create new node.\n");
return KNOTDZCOMPILE_ENOMEM;
}
-
+
+ dbg_zp_verb("zp: process_rr: RRSIG proccesed successfully.\n");
return KNOTDZCOMPILE_EOK;
}
-
+
+ /*! \todo Move RRSIG and RRSet handling to funtions. */
assert(current_rrset->type != KNOT_RRTYPE_RRSIG);
knot_node_t *node = NULL;
@@ -395,6 +434,8 @@ int process_rr(void)
if ((node = create_node(contents, current_rrset,
node_add_func,
node_get_func)) == NULL) {
+ dbg_zp("zp: process_rr: Cannot "
+ "create new node.\n");
return KNOTDZCOMPILE_EBADNODE;
}
}
@@ -406,11 +447,15 @@ int process_rr(void)
current_rrset->rclass,
current_rrset->ttl);
if (rrset == NULL) {
+ dbg_zp("zp: process_rr: Cannot "
+ "create new RRSet.\n");
return KNOTDZCOMPILE_ENOMEM;
}
if (knot_rrset_add_rdata(rrset, current_rrset->rdata) != 0) {
- free(rrset);
+ knot_rrset_free(&rrset);
+ dbg_zp("zp: process_rr: Cannot "
+ "add RDATA to RRSet.\n");
return KNOTDZCOMPILE_EBRDATA;
}
@@ -418,7 +463,9 @@ int process_rr(void)
* any rrset to skip */
if (knot_zone_contents_add_rrset(contents, rrset, &node,
KNOT_RRSET_DUPL_SKIP, 1) < 0) {
- free(rrset);
+ knot_rrset_free(&rrset);
+ dbg_zp("zp: process_rr: Cannot "
+ "add RDATA to RRSet.\n");
return KNOTDZCOMPILE_EBRDATA;
}
} else {
@@ -426,12 +473,14 @@ int process_rr(void)
KNOT_RRTYPE_RRSIG && rrset->ttl !=
current_rrset->ttl) {
zc_error_prev_line(
- "TTL does not match the TTL of the RRset");
+ "TTL does not match the TTL of the RRSet");
}
if (knot_zone_contents_add_rrset(contents, current_rrset,
&node,
KNOT_RRSET_DUPL_MERGE, 1) < 0) {
+ dbg_zp("zp: process_rr: Cannot "
+ "merge RRSets.\n");
return KNOTDZCOMPILE_EBRDATA;
}
}
@@ -441,9 +490,10 @@ int process_rr(void)
}
parser->last_node = node;
-
++totalrrs;
-
+
+ dbg_zp_verb("zp: process_rr: RRSet %p processed successfully.\n",
+ parser->current_rrset);
return KNOTDZCOMPILE_EOK;
}
@@ -454,12 +504,14 @@ static uint find_rrsets_orphans(knot_zone_contents_t *zone, rrset_list_t
while (head != NULL) {
if (find_rrset_for_rrsig_in_zone(zone, head->data) == 0) {
found_rrsets += 1;
- dbg_zp("RRSET succesfully found: owner %s type %s\n",
+ dbg_zp("zp: find_orphans: "
+ "RRSet succesfully found: owner %s type %s\n",
knot_dname_to_str(head->data->owner),
knot_rrtype_to_string(head->data->type));
}
else { /* we can throw it away now */
- dbg_zp("RRSet not found for RRSIG: %s (%s)\n",
+ dbg_zp("zp: find_orphans: "
+ "RRSet not found for RRSIG: %s (%s)\n",
knot_dname_to_str(head->data->owner),
knot_rrtype_to_string(
knot_rdata_rrsig_type_covered(head->data->rdata)));
@@ -473,6 +525,10 @@ static uint find_rrsets_orphans(knot_zone_contents_t *zone, rrset_list_t
static int zone_open(const char *filename, uint32_t ttl, uint16_t rclass,
knot_node_t *origin, void *scanner, knot_dname_t *origin_from_config)
{
+ /*!< \todo #1676 Implement proper locking. */
+ zparser_init(filename, ttl, rclass, origin, origin_from_config);
+
+
/* Open the zone file... */
if (strcmp(filename, "-") == 0) {
zp_set_in(stdin, scanner);
@@ -487,11 +543,7 @@ static int zone_open(const char *filename, uint32_t ttl, uint16_t rclass,
return 0;
}
}
-
- /*!< \todo #1676 Implement proper locking. */
-
- zparser_init(filename, ttl, rclass, origin, origin_from_config);
-
+
return 1;
}
@@ -503,6 +555,8 @@ int zone_read(const char *name, const char *zonefile, const char *outfile,
zonefile);
return KNOTDZCOMPILE_EINVAL;
}
+
+ dbg_zp("zp: zone_read: Reading zone: %s.\n", zonefile);
/* Check that we can write to outfile. */
FILE *f = fopen(outfile, "wb");
@@ -526,9 +580,8 @@ int zone_read(const char *name, const char *zonefile, const char *outfile,
}
knot_node_t *origin_node = knot_node_new(dname, NULL, 0);
-
+ knot_dname_release(dname); /* Stored in node or should be freed. */
if (origin_node == NULL) {
- knot_dname_release(dname);
return KNOTDZCOMPILE_ENOMEM;
}
@@ -554,10 +607,9 @@ int zone_read(const char *name, const char *zonefile, const char *outfile,
origin_from_config)) {
zc_error_prev_line("Cannot open '%s' (%s).",
zonefile, strerror(errno));
- zparser_free();
zp_lex_destroy(scanner);
knot_dname_release(origin_from_config);
- knot_node_free(&origin_node, 0);
+// knot_node_free(&origin_node, 0);
return KNOTDZCOMPILE_EZONEINVAL;
}
@@ -566,7 +618,8 @@ int zone_read(const char *name, const char *zonefile, const char *outfile,
FILE *in_file = (FILE *)zp_get_in(scanner);
fclose(in_file);
zp_lex_destroy(scanner);
- knot_node_free(&origin_node, 0);
+ knot_dname_release(origin_from_config);
+// knot_node_free(&origin_node, 0);
return KNOTDZCOMPILE_ESYNT;
}
@@ -579,7 +632,8 @@ int zone_read(const char *name, const char *zonefile, const char *outfile,
/*!< \todo #1676 Implement proper locking. */
- dbg_zp("zp complete %p\n", parser->current_zone);
+ dbg_zp("zp: zone_read: Parse complete for %s.\n",
+ zonefile);
if (parser->last_node && parser->node_rrsigs != NULL) {
/* assign rrsigs to last node in the zone*/
@@ -588,15 +642,15 @@ int zone_read(const char *name, const char *zonefile, const char *outfile,
rrset_list_delete(&parser->node_rrsigs);
}
- dbg_zp("zone parsed\n");
+ dbg_zp("zp: zone_read: RRSIGs processed.\n");
if (!(parser->current_zone &&
knot_node_rrset(parser->current_zone->contents->apex,
KNOT_RRTYPE_SOA))) {
zc_error_prev_line("Zone file does not contain SOA record!\n");
- knot_zone_deep_free(&parser->current_zone, 1);
- zparser_free();
- knot_node_free(&origin_node, 0);
+// knot_zone_deep_free(&parser->current_zone, 1);
+ knot_dname_release(origin_from_config);
+// knot_node_free(&origin_node, 0);
return KNOTDZCOMPILE_EZONEINVAL;
}
@@ -604,7 +658,7 @@ int zone_read(const char *name, const char *zonefile, const char *outfile,
found_orphans = find_rrsets_orphans(contents,
parser->rrsig_orphans);
- dbg_zp("%u orphans found\n", found_orphans);
+ dbg_zp("zp: zone_read: %u RRSIG orphans found.\n", found_orphans);
rrset_list_delete(&parser->rrsig_orphans);
@@ -618,17 +672,17 @@ int zone_read(const char *name, const char *zonefile, const char *outfile,
/*! \todo Check return value. */
knot_zone_contents_adjust(contents);
- dbg_zp("rdata adjusted\n");
+ dbg_zp("zp: zone_read: Zone adjusted.\n");
if (parser->errors != 0) {
- fprintf(stderr,
- "Parser finished with error, not dumping the zone!\n");
+ log_zone_error("Parser finished with %d error(s), "
+ "not dumping the zone!\n",
+ parser->errors);
} else {
int fd = open(outfile, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG);
if (fd < 0) {
- fprintf(stderr,
- "Could not open destination file for db: %s.\n",
- outfile);
+ log_zone_error("Could not open destination file for db: %s.\n",
+ outfile);
totalerrors++;
} else {
crc_t crc;
@@ -636,22 +690,22 @@ int zone_read(const char *name, const char *zonefile, const char *outfile,
semantic_checks,
zonefile, &crc);
if (ret != KNOT_EOK) {
- fprintf(stderr, "Could not dump zone, reason: "
- "%s.\n", knot_strerror(ret));
+ log_zone_error("Could not dump zone, reason: "
+ "%s.\n", knot_strerror(ret));
remove(outfile);
totalerrors++;
} else {
/* Write CRC file. */
char *crc_path = knot_zdump_crc_file(outfile);
if (crc_path == NULL) {
- fprintf(stderr,
- "Could not get crc file path.\n");
+ log_zone_error(
+ "Could not get crc file path.\n");
remove(outfile);
totalerrors++;
} else {
FILE *f_crc = fopen(crc_path, "w");
if (f_crc == NULL) {
- fprintf(stderr,
+ log_zone_error(
"Could not open crc file \n");
remove(outfile);
totalerrors++;
@@ -667,12 +721,13 @@ int zone_read(const char *name, const char *zonefile, const char *outfile,
}
- dbg_zp("zone dumped.\n");
+ dbg_zp("zp: zone_read: Zone %s dumped successfully.\n",
+ zonefile);
}
fflush(stdout);
totalerrors += parser->errors;
- zparser_free();
+ knot_dname_release(origin_from_config);
return totalerrors;
}
diff --git a/src/zcompile/zcompile_main.c b/src/zcompile/zcompile_main.c
index c873af6..4b631ce 100644
--- a/src/zcompile/zcompile_main.c
+++ b/src/zcompile/zcompile_main.c
@@ -19,6 +19,7 @@
#include <stdlib.h>
#include "zcompile/zcompile.h"
+#include "common/log.h"
#include <config.h>
static void help(int argc, char **argv)
@@ -81,21 +82,21 @@ int main(int argc, char **argv)
origin = argv[optind];
zonefile = argv[optind + 1];
- // Initialize log (no output)
- //log_init(0);
- //log_levels_set(LOGT_STDOUT, LOG_ANY, LOG_MASK(LOG_DEBUG));
-
- printf("Parsing file '%s', origin '%s' ...\n",
- zonefile, origin);
+ // Initialize log (no syslog)
+ log_init();
+ log_levels_set(LOGT_SYSLOG, LOG_ANY, 0);
+ log_zone_info("Parsing file '%s', origin '%s' ...\n",
+ zonefile, origin);
parser = zparser_create();
if (!parser) {
- fprintf(stderr, "Failed to create parser.\n");
+ log_server_error("Failed to create parser.\n");
//log_close();
return 1;
}
int error = zone_read(origin, zonefile, outfile, semantic_checks);
+ zparser_free();
if (error != 0) {
/* FIXME! */
@@ -107,7 +108,7 @@ int main(int argc, char **argv)
// }
return 1;
} else {
- printf("Compilation successful.\n");
+ log_zone_info("Compilation of '%s' successful.\n", origin);
}
//log_close();
diff --git a/src/zcompile/zparser.y b/src/zcompile/zparser.y
index 59f037d..b353fbe 100644
--- a/src/zcompile/zparser.y
+++ b/src/zcompile/zparser.y
@@ -54,6 +54,7 @@
#include <assert.h>
#include "zcompile/parser-util.h"
+#include "common/log.h"
#include "libknot/libknot.h"
#include "zcompile/zcompile.h"
@@ -198,7 +199,7 @@ line: NL
assert(parser->current_rrset->rdata == NULL);
if (knot_rrset_add_rdata(parser->current_rrset, tmp_rdata)
!= 0) {
- fprintf(stderr, "Could not add rdata!\n");
+ log_zone_error("Could not add rdata!\n");
}
// tmp_rdata->next = tmp_rdata;
// parser->current_rrset->rdata = tmp_rdata;
@@ -223,7 +224,7 @@ line: NL
if ((ret = process_rr()) != 0) {
char *name =
knot_dname_to_str(parser->current_rrset->owner);
- fprintf(stderr, "Error: could not process RRSet\n"
+ log_zone_error("Error: could not process RRSet\n"
"owner: %s reason: %s\n",
name,
error_to_str(knot_zcompile_error_msgs, ret));
@@ -258,7 +259,7 @@ line: NL
* of the converting function was not able to convert. */
if (parser->error_occurred == KNOTDZCOMPILE_ENOMEM) {
/* Ran out of memory in converting functions. */
- fprintf(stderr, "Parser ran out "
+ log_zone_error("Parser ran out "
"of memory, aborting!\n");
knot_rrset_deep_free(&(parser->current_rrset),
0, 0, 0);
@@ -691,7 +692,7 @@ str_sp_seq: STR
char *result = malloc($1.len + $3.len + 1);
if (result == NULL) {
ERR_ALLOC_FAILED;
- fprintf(stderr, "Parser ran out of memory, aborting!\n");
+ log_zone_error("Parser ran out of memory, aborting!\n");
knot_rrset_deep_free(&(parser->current_rrset),
0, 0, 0);
knot_zone_deep_free(&(parser->current_zone),
@@ -719,7 +720,7 @@ str_dot_seq: STR
char *result = malloc($1.len + $3.len + 1);
if (result == NULL) {
ERR_ALLOC_FAILED;
- fprintf(stderr, "Parser ran out of memory, aborting!\n");
+ log_zone_error("Parser ran out of memory, aborting!\n");
knot_rrset_deep_free(&(parser->current_rrset),
0, 0, 0);
knot_zone_deep_free(&(parser->current_zone),
@@ -751,7 +752,7 @@ dotted_str: STR
char *result = malloc($1.len + 2);
if (result == NULL) {
ERR_ALLOC_FAILED;
- fprintf(stderr, "Parser ran out of memory, aborting!\n");
+ log_zone_error("Parser ran out of memory, aborting!\n");
knot_rrset_deep_free(&(parser->current_rrset),
0, 0, 0);
knot_zone_deep_free(&(parser->current_zone),
@@ -771,7 +772,7 @@ dotted_str: STR
char *result = malloc($1.len + $3.len + 2);
if (result == NULL) {
ERR_ALLOC_FAILED;
- fprintf(stderr, "Parser ran out of memory, aborting!\n");
+ log_zone_error("Parser ran out of memory, aborting!\n");
knot_rrset_deep_free(&(parser->current_rrset),
0, 0, 0);
knot_zone_deep_free(&(parser->current_zone),
@@ -1563,23 +1564,19 @@ zparser_type *zparser_create()
result->current_rrset = knot_rrset_new(NULL, 0, 0, 0);
if (result->current_rrset == NULL) {
- ERR_ALLOC_FAILED;
free(result->temporary_items);
free(result);
return NULL;
}
result->root_domain = knot_dname_new_from_str(".", 1, NULL);
-// printf("THE NEW ROOT: %p\n", result->root_domain);
if (result->root_domain == NULL) {
- ERR_ALLOC_FAILED;
free(result->temporary_items);
free(result->current_rrset);
free(result);
return NULL;
}
- knot_dname_retain(result->root_domain);
return result;
}
@@ -1610,6 +1607,7 @@ zparser_init(const char *filename, uint32_t ttl, uint16_t rclass,
parser->filename = filename;
parser->rdata_count = 0;
parser->origin_from_config = origin_from_config;
+ knot_dname_retain(origin_from_config);
parser->last_node = origin;
// parser->root_domain = NULL;
@@ -1630,9 +1628,10 @@ zparser_init(const char *filename, uint32_t ttl, uint16_t rclass,
void zparser_free()
{
-// knot_dname_release(parser->root_domain);
+ knot_dname_release(parser->root_domain);
// knot_dname_release(parser->prev_dname);
- knot_dname_free(&parser->origin_from_config);
+ knot_zone_deep_free(&parser->current_zone, 1);
+ knot_dname_release(parser->origin_from_config);
free(parser->temporary_items);
if (parser->current_rrset != NULL) {
free(parser->current_rrset);
@@ -1649,13 +1648,29 @@ yyerror(void *scanner, const char *message)
static void
error_va_list(unsigned line, const char *fmt, va_list args)
{
+ char sbuf[4096] = {0};
+ size_t buflen = sizeof(sbuf) - 1;
+ char *buf = sbuf;
+ int wb = 0;
if (parser->filename) {
- fprintf(stderr, "%s:%u: ", parser->filename, line);
+ wb = snprintf(buf, buflen, "%s:%u: ",
+ parser->filename, line);
+ if (wb > 0) {
+ buf += wb;
+ buflen -= wb;
+ }
}
- fprintf(stderr, "error: ");
- vfprintf(stderr, fmt, args);
- fprintf(stderr, "\n");
-
+
+ wb = vsnprintf(buf, buflen, fmt, args);
+ if (wb > 0) {
+ buf += wb;
+ buflen -= wb;
+ *buf = '\n';
+ *(buf + 1) = '\0';
+ }
+
+ log_zone_error("%s", sbuf);
+
++parser->errors;
parser->error_occurred = 1;
}
@@ -1685,12 +1700,28 @@ zc_error(const char *fmt, ...)
static void
warning_va_list(unsigned line, const char *fmt, va_list args)
{
+ char sbuf[4096] = {0};
+ size_t buflen = sizeof(sbuf) - 1;
+ char *buf = sbuf;
+ int wb = 0;
if (parser->filename) {
- fprintf(stderr, "%s:%u: ", parser->filename, line);
+ wb = snprintf(buf, buflen, "%s:%u: ",
+ parser->filename, line);
+ if (wb > 0) {
+ buf += wb;
+ buflen -= wb;
+ }
}
- fprintf(stderr, "warning: ");
- vfprintf(stderr, fmt, args);
- fprintf(stderr, "\n");
+
+ wb = vsnprintf(buf, buflen, fmt, args);
+ if (wb > 0) {
+ buf += wb;
+ buflen -= wb;
+ *buf = '\n';
+ *(buf + 1) = '\0';
+ }
+
+ log_zone_warning("%s", sbuf);
}
void