From 564b852d4200ac970e1cddd542af93a609e04ed5 Mon Sep 17 00:00:00 2001 From: Jan Kadlec <jan.kadlec@nic.cz> Date: Thu, 29 Nov 2012 20:24:03 +0100 Subject: [PATCH] Basic zones working with new parser. - Needs a lot of ironing out - Data from parser are wrong with DNSKEY and NSEC3 RRs --- src/Makefile.am | 2 - src/common/descriptor_new.c | 1 - src/libknot/rrset.c | 181 ++++++++++++++++++++++--------- src/libknot/rrset.h | 4 +- src/libknot/util/debug.c | 62 +++++------ src/libknot/util/descriptor.h | 121 +++++++++++---------- src/libknot/zone/zone-contents.c | 28 ++--- src/zcompile/zcompile.c | 109 ++++++++++--------- 8 files changed, 296 insertions(+), 212 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index f7a2bdf9f..347635bcf 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,9 +18,7 @@ knot_zcompile_SOURCES = \ libknot/rrset.h \ zcompile/zcompile_main.c \ zcompile/zcompile-error.c \ - zcompile/parser-descriptor.h \ zcompile/zcompile.c \ - zcompile/parser-descriptor.c \ zscanner/test/processing.h \ zscanner/test/processing.c \ libknot/util/utils.c \ diff --git a/src/common/descriptor_new.c b/src/common/descriptor_new.c index 542c5fb29..57c2b72d1 100644 --- a/src/common/descriptor_new.c +++ b/src/common/descriptor_new.c @@ -131,4 +131,3 @@ int descriptor_item_is_remainder(int item) } } - diff --git a/src/libknot/rrset.c b/src/libknot/rrset.c index 62ae1d311..cf766ae1f 100644 --- a/src/libknot/rrset.c +++ b/src/libknot/rrset.c @@ -59,7 +59,7 @@ static uint8_t *rrset_rdata_pointer(const knot_rrset_t *rrset, size_t pos) { if (rrset == NULL || rrset->rdata == NULL - || rrset->rdata_count >= pos) { + || pos >= rrset->rdata_count) { return NULL; } @@ -95,12 +95,13 @@ size_t rrset_rdata_naptr_bin_chunk_size(const knot_rrset_t *rrset, static uint32_t rrset_rdata_size_total(const knot_rrset_t *rrset) { - if (rrset == NULL || rrset->rdata_indices || rrset->rdata_count == 0) { + if (rrset == NULL || rrset->rdata_indices == NULL || + rrset->rdata_count == 0) { return 0; } /* Last index denotes end of all RRs. */ - return (rrset->rdata_indices[rrset->rdata_count]); + return (rrset->rdata_indices[rrset->rdata_count - 1]); } @@ -118,6 +119,8 @@ knot_rrset_t *knot_rrset_new(knot_dname_t *owner, uint16_t type, } ret->rdata = NULL; + ret->rdata_count = 0; + ret->rdata_indices = NULL; /* Retain reference to owner. */ knot_dname_retain(owner); @@ -133,6 +136,17 @@ knot_rrset_t *knot_rrset_new(knot_dname_t *owner, uint16_t type, /*----------------------------------------------------------------------------*/ +int knot_rrset_add_rdata_single(knot_rrset_t *rrset, uint8_t *rdata, + uint32_t size) +{ + rrset->rdata_indices = malloc(sizeof(uint32_t)); + assert(rrset->rdata_indices); + rrset->rdata_indices[0] = size; + rrset->rdata = rdata; + rrset->rdata_count = 1; + return KNOT_EOK; +} + int knot_rrset_add_rdata(knot_rrset_t *rrset, uint8_t *rdata, uint32_t size) { @@ -141,12 +155,20 @@ int knot_rrset_add_rdata(knot_rrset_t *rrset, } /* Realloc indices. We will allocate exact size to save space. */ - void *tmp = realloc(rrset->rdata_indices, rrset->rdata_count + 1); + /* TODO this sucks big time - allocation of length 1. */ + /* But another variable holding allocated count is not a question. What now?*/ + void *tmp = realloc(rrset->rdata_indices, (rrset->rdata_count + 1) * 100); if (tmp == NULL) { ERR_ALLOC_FAILED; return KNOT_ENOMEM; } else { +// printf("Adding actual data. Type %d size %d\n", +// rrset->type, size); + hex_print(rdata, size); rrset->rdata_indices = tmp; + // TODO has to be better, realloc and all + rrset->rdata = malloc(size); + memcpy(rrset->rdata, rdata, size); } if (rrset->rdata_count == 0) { @@ -157,6 +179,10 @@ int knot_rrset_add_rdata(knot_rrset_t *rrset, } rrset->rdata_count++; + +// printf("RDATA position %d is %d\n", +// rrset->rdata_count, +// rrset_rdata_offset(rrset, rrset->rdata_count - 1)); return KNOT_EOK; } @@ -902,34 +928,34 @@ int knot_rrset_deep_copy(const knot_rrset_t *from, knot_rrset_t **to, rrset_rdata_size_total(from) + 1); /* Here comes the hard part. */ - if (copy_rdata_dnames) { - knot_dname_t *dname_from = NULL; - knot_dname_t **dname_to = NULL; - knot_dname_t *dname_copy = NULL; - while ((dname_from = - knot_rrset_get_next_dname(from, dname_from)) != NULL) { - dname_to = - knot_rrset_get_next_dname_pointer(*to, - dname_to); - /* These pointers have to be the same. */ - assert(dname_from == *dname_to); - dname_copy = knot_dname_deep_copy(dname_from); - if (dname_copy == NULL) { - dbg_rrset("rrset: deep_copy: Cannot copy RDATA" - " dname.\n"); - /*! \todo This will leak. Is it worth fixing? */ - knot_rrset_deep_free(&(*to)->rrsigs, 1, - copy_rdata_dnames); - free((*to)->rdata); - free((*to)->rdata_indices); - free(*to); - return KNOT_ENOMEM; - } +// if (copy_rdata_dnames) { +// knot_dname_t *dname_from = NULL; +// knot_dname_t **dname_to = NULL; +// knot_dname_t *dname_copy = NULL; +// while ((dname_from = +// knot_rrset_get_next_dname(from, dname_from)) != NULL) { +// dname_to = +// knot_rrset_get_next_dname_pointer(*to, +// dname_to); +// /* These pointers have to be the same. */ +// assert(dname_from == *dname_to); +// dname_copy = knot_dname_deep_copy(dname_from); +// if (dname_copy == NULL) { +// dbg_rrset("rrset: deep_copy: Cannot copy RDATA" +// " dname.\n"); +// /*! \todo This will leak. Is it worth fixing? */ +// knot_rrset_deep_free(&(*to)->rrsigs, 1, +// copy_rdata_dnames); +// free((*to)->rdata); +// free((*to)->rdata_indices); +// free(*to); +// return KNOT_ENOMEM; +// } - /* This cannot work, test. TODO */ - *dname_to = dname_copy; - } - } +// /* This cannot work, test. TODO */ +// *dname_to = dname_copy; +// } +// } return KNOT_EOK; } @@ -1097,7 +1123,14 @@ int knot_rrset_merge(void **r1, void **r2) void *tmp = realloc(rrset1->rdata, rrset_rdata_size_total(rrset1) + rrset_rdata_size_total(rrset2)); if (tmp == NULL) { + printf("%d %d\n", knot_rrset_rdata_rr_count(rrset1), + knot_rrset_rdata_rr_count(rrset2)); + printf("%d %d\n", rrset_rdata_size_total(rrset1), + rrset_rdata_size_total(rrset2)); + printf("%d %p %p\n", rrset1->type, rrset1->rdata, rrset2->rdata); ERR_ALLOC_FAILED; + knot_rrset_dump(rrset1); + knot_rrset_dump(rrset2); return KNOT_ENOMEM; } else { rrset1->rdata = tmp; @@ -1109,15 +1142,17 @@ int knot_rrset_merge(void **r1, void **r2) /* Indices have to be readjusted. But space has to be made first. */ tmp = realloc(rrset1->rdata_indices, - rrset1->rdata_count + rrset2->rdata_count + 1); + (rrset1->rdata_count + rrset2->rdata_count) * + sizeof(uint32_t)); if (tmp == NULL) { ERR_ALLOC_FAILED; return KNOT_ENOMEM; } else { - rrset1->rdata = tmp; + rrset1->rdata_indices = tmp; } uint32_t rrset1_total_size = rrset_rdata_size_total(rrset1); + uint32_t rrset2_total_size = rrset_rdata_size_total(rrset2); /* * Move the indices. Discard the last item in the first array, as it @@ -1127,13 +1162,18 @@ int knot_rrset_merge(void **r1, void **r2) rrset2->rdata_indices, rrset2->rdata_count); /* Go through the second part of index array and adjust offsets. */ - for (uint16_t i = 0; i < rrset2->rdata_count; i++) { + for (uint16_t i = 0; i < rrset2->rdata_count - 1; i++) { rrset1->rdata_indices[rrset1->rdata_count + i] += rrset1_total_size; } + rrset1->rdata_indices[rrset1->rdata_count + rrset2->rdata_count - 1] = + rrset1_total_size + rrset2_total_size; + rrset1->rdata_count += rrset2->rdata_count; +// knot_rrset_dump(rrset1); + return KNOT_EOK; } @@ -1288,16 +1328,6 @@ int knot_rrset_merge_no_dupl(void **r1, void **r2) // return KNOT_EOK; //} -uint32_t knot_rrset_rdata_length(const knot_rrset_t *rrset, size_t rdata_pos) -{ - return 0; -} - -uint32_t knot_rrset_rdata_length_total(const knot_rrset_t *rrset) -{ - return 0; -} - /*----------------------------------------------------------------------------*/ const knot_dname_t *knot_rrset_rdata_cname_name(const knot_rrset_t *rrset) @@ -1577,39 +1607,88 @@ uint8_t *knot_rrset_rdata_prealloc(const knot_rrset_t *rrset) return ret; } + +void knot_rrset_dump(const knot_rrset_t *rrset) +{ + if (rrset == NULL) { + return; + } + + fprintf(stderr, " ------- RRSET -------\n"); + + char *name = knot_dname_to_str(rrset->owner); + fprintf(stderr, " owner: %s\n", name); + free(name); + fprintf(stderr, " type: %u\n", rrset->type); + fprintf(stderr, " class: %d\n", rrset->rclass); + fprintf(stderr, " ttl: %d\n", rrset->ttl); + fprintf(stderr, " RDATA count: %d\n", rrset->rdata_count); + + fprintf(stderr, " RRSIGs:\n"); + if (rrset->rrsigs != NULL) { + knot_rrset_dump(rrset->rrsigs); + } else { + fprintf(stderr, " none\n"); + } + + fprintf(stderr, "RDATA indices (total=%d):\n", + rrset_rdata_size_total(rrset)); + for (uint16_t i = 0; i < rrset->rdata_count; i++) { + fprintf(stderr, "%d=%d ", i, rrset_rdata_offset(rrset, i)); + } + fprintf(stderr, "\n"); + + if (knot_rrset_rdata_rr_count(rrset) == 0) { + fprintf(stderr, "NO RDATA\n"); + } + + for (uint16_t i = 0; i < knot_rrset_rdata_rr_count(rrset);i ++) { + knot_rrset_rdata_dump(rrset, i); + } +} + void knot_rrset_rdata_dump(const knot_rrset_t *rrset, size_t rdata_pos) { - fprintf(stderr, " ------- RDATA -------\n"); + fprintf(stderr, " ------- RDATA pos=%d -------\n", rdata_pos); if (rrset->rdata_count == 0) { fprintf(stderr, " There are no rdata in this RRset!\n"); fprintf(stderr, " ------- RDATA -------\n"); return; } - rdata_descriptor_t *desc = get_rdata_descriptor(knot_rrset_type(rrset)); assert(desc != NULL); + +// fprintf(stderr, "Packed form (%p size=%d):\n", rrset->rdata, +// knot_rrset_rdata_length_total(rrset)); +// hex_print(rrset->rdata, knot_rrset_rdata_length(rrset, rdata_pos)); size_t offset = 0; for (int i = 0; desc->block_types[i] != KNOT_RDATA_WF_END; i++) { int item = desc->block_types[i]; - uint8_t *rdata = rrset_rdata_offset(rrset, rdata_pos); + uint8_t *rdata = rrset_rdata_pointer(rrset, rdata_pos); if (descriptor_item_is_dname(item)) { - knot_dname_t *dname = - (knot_dname_t *)(rdata + offset); + knot_dname_t *dname; + memcpy(&dname, rdata + offset, sizeof(knot_dname_t *)); char *name = knot_dname_to_str(dname); if (dname == NULL) { fprintf(stderr, "DNAME error.\n"); return; } - fprintf(stderr, "block=%d DNAME=%s.\n", + fprintf(stderr, "block=%d: DNAME=%s.\n", i, name); free(name); + offset += sizeof(knot_dname_t *); } else if (descriptor_item_is_fixed(item)) { - ; + fprintf(stderr, "block=%d Raw data:\n", + i); + hex_print(rdata + offset, item); + offset += item; } else if (descriptor_item_is_remainder(item)) { + printf("remainder TODO\n"); ; } else { assert(rrset->type == KNOT_RRTYPE_NAPTR); + assert(0); } } } diff --git a/src/libknot/rrset.h b/src/libknot/rrset.h index 0fa0aeb8a..c87fe55e9 100644 --- a/src/libknot/rrset.h +++ b/src/libknot/rrset.h @@ -351,9 +351,6 @@ int knot_rrset_merge_no_dupl(void **r1, void **r2); const knot_dname_t *knot_rrset_rdata_cname_name(const knot_rrset_t *rrset); const knot_dname_t *knot_rrset_rdata_dname_target(const knot_rrset_t *rrset); -uint32_t knot_rrset_rdata_length(const knot_rrset_t *rrset, size_t rdata_pos); -uint32_t knot_rrset_rdata_length_total(const knot_rrset_t *rrset); - const knot_dname_t *knot_rrset_rdata_cname_name(const knot_rrset_t *rrset); const knot_dname_t *knot_rrset_rdata_dname_target(const knot_rrset_t *rrset); int64_t knot_rrset_rdata_soa_serial(const knot_rrset_t *rrset); @@ -392,6 +389,7 @@ knot_dname_t **knot_rrset_get_next_dname_pointer(const knot_rrset_t *rrset, uint8_t *knot_rrset_rdata_prealloc(const knot_rrset_t *rrset); +void knot_rrset_dump(const knot_rrset_t *rrset); void knot_rrset_rdata_dump(const knot_rrset_t *rrset, size_t rdata_pos); #endif /* _KNOT_RRSET_H_ */ diff --git a/src/libknot/util/debug.c b/src/libknot/util/debug.c index c50b26eae..165339cc8 100644 --- a/src/libknot/util/debug.c +++ b/src/libknot/util/debug.c @@ -32,39 +32,39 @@ void knot_rdata_dump(const knot_rrset_t *rrset, size_t rdata_pos) #endif } -void knot_rrset_dump(const knot_rrset_t *rrset) -{ -#if defined(KNOT_ZONE_DEBUG) || defined(KNOT_RRSET_DEBUG) - fprintf(stderr, " ------- RRSET -------\n"); - fprintf(stderr, " %p\n", rrset); - if (!rrset) { - return; - } - char *name = knot_dname_to_str(rrset->owner); - fprintf(stderr, " owner: %s\n", name); - free(name); - fprintf(stderr, " type: %u\n", rrset->type); - fprintf(stderr, " class: %d\n", rrset->rclass); - fprintf(stderr, " ttl: %d\n", rrset->ttl); - - fprintf(stderr, " RRSIGs:\n"); - if (rrset->rrsigs != NULL) { - knot_rrset_dump(rrset->rrsigs); - } else { - fprintf(stderr, " none\n"); - } - - if (rrset->rdata == NULL) { - fprintf(stderr, " NO RDATA!\n"); - fprintf(stderr, " ------- RRSET -------\n"); - return; - } +//void knot_rrset_dump(const knot_rrset_t *rrset) +//{ +//#if defined(KNOT_ZONE_DEBUG) || defined(KNOT_RRSET_DEBUG) +// fprintf(stderr, " ------- RRSET -------\n"); +// fprintf(stderr, " %p\n", rrset); +// if (!rrset) { +// return; +// } +// char *name = knot_dname_to_str(rrset->owner); +// fprintf(stderr, " owner: %s\n", name); +// free(name); +// fprintf(stderr, " type: %u\n", rrset->type); +// fprintf(stderr, " class: %d\n", rrset->rclass); +// fprintf(stderr, " ttl: %d\n", rrset->ttl); + +// fprintf(stderr, " RRSIGs:\n"); +// if (rrset->rrsigs != NULL) { +// knot_rrset_dump(rrset->rrsigs); +// } else { +// fprintf(stderr, " none\n"); +// } + +// if (rrset->rdata == NULL) { +// fprintf(stderr, " NO RDATA!\n"); +// fprintf(stderr, " ------- RRSET -------\n"); +// return; +// } - // TODO dump rdata +// // TODO dump rdata - fprintf(stderr, " ------- RRSET -------\n"); -#endif -} +// fprintf(stderr, " ------- RRSET -------\n"); +//#endif +//} void knot_node_dump(knot_node_t *node) { diff --git a/src/libknot/util/descriptor.h b/src/libknot/util/descriptor.h index 108217bdb..cacfa284d 100644 --- a/src/libknot/util/descriptor.h +++ b/src/libknot/util/descriptor.h @@ -44,12 +44,13 @@ * POSSIBILITY OF SUCH DAMAGE. */ -//#ifndef _KNOT_DESCRIPTOR_H_ -//#define _KNOT_DESCRIPTOR_H_ +#ifndef _KNOT_DESCRIPTOR_H_ +#define _KNOT_DESCRIPTOR_H_ -//#include <stdint.h> -//#include <stdbool.h> -//#include <string.h> +#include <stdint.h> +#include <stdbool.h> +#include <string.h> +#include <common/descriptor_new.h> //enum knot_mxrdtln { // /*! \brief Maximum items in RDATA wireformat. */ @@ -314,67 +315,67 @@ // */ //knot_rrtype_descriptor_t *knot_rrtype_descriptor_by_name(const char *name); -///*! -// * \brief Converts numeric type representation to mnemonic string. -// * -// * \param rrtype Type RR type code to be converted. -// * \param out Output buffer. -// * \param out_len Length of the output buffer. -// * -// * \return Length of output string. -// * \return -1 if error. -// */ -//int32_t knot_rrtype_to_string(const uint16_t rrtype, -// char *out, -// const uint32_t out_len); +/*! + * \brief Converts numeric type representation to mnemonic string. + * + * \param rrtype Type RR type code to be converted. + * \param out Output buffer. + * \param out_len Length of the output buffer. + * + * \return Length of output string. + * \return -1 if error. + */ +int32_t knot_rrtype_to_string(const uint16_t rrtype, + char *out, + const uint32_t out_len); -///*! -// * \brief Converts mnemonic string representation of a type to numeric one. -// * -// * \param name Mnemonic string to be converted. -// * -// * \return Correct code if found, 0 otherwise. -// */ -//uint16_t knot_rrtype_from_string(const char *name); +/*! + * \brief Converts mnemonic string representation of a type to numeric one. + * + * \param name Mnemonic string to be converted. + * + * \return Correct code if found, 0 otherwise. + */ +uint16_t knot_rrtype_from_string(const char *name); -///*! -// * \brief Converts numeric class representation to the string one. -// * -// * \param rrclass Class code to be converted. -// * \param out Output buffer. -// * \param out_len Length of the output buffer. -// * -// * \return Length of output string. -// * \return -1 if error. -// */ -//int32_t knot_rrclass_to_string(const uint16_t rrclass, -// char *out, -// const uint32_t out_len); +/*! + * \brief Converts numeric class representation to the string one. + * + * \param rrclass Class code to be converted. + * \param out Output buffer. + * \param out_len Length of the output buffer. + * + * \return Length of output string. + * \return -1 if error. + */ +int32_t knot_rrclass_to_string(const uint16_t rrclass, + char *out, + const uint32_t out_len); -///*! -// * \brief Converts string representation of a class to numeric one. -// * -// * \param name Class string to be converted. -// * -// * \return Correct code if found, 0 otherwise. -// */ -//uint16_t knot_rrclass_from_string(const char *name); +/*! + * \brief Converts string representation of a class to numeric one. + * + * \param name Class string to be converted. + * + * \return Correct code if found, 0 otherwise. + */ +uint16_t knot_rrclass_from_string(const char *name); -///*! -// * \brief Returns size of wireformat type in bytes. -// * -// * \param wire_type Wireformat type. -// * -// * \retval Size of given type on success. -// * \retval 0 on unknown type or type that has no length. -// */ -//size_t knot_wireformat_size(unsigned int wire_type); +/*! + * \brief Returns size of wireformat type in bytes. + * + * \param wire_type Wireformat type. + * + * \retval Size of given type on success. + * \retval 0 on unknown type or type that has no length. + */ +size_t knot_wireformat_size(unsigned int wire_type); -//int knot_rrtype_is_metatype(uint16_t type); +int knot_rrtype_is_metatype(uint16_t type); -//size_t knot_ds_digest_length(uint8_t algorithm); +size_t knot_ds_digest_length(uint8_t algorithm); -//#endif /* _KNOT_DESCRIPTOR_H_ */ +#endif /* _KNOT_DESCRIPTOR_H_ */ -///*! @} */ +/*! @} */ diff --git a/src/libknot/zone/zone-contents.c b/src/libknot/zone/zone-contents.c index f5c13abcd..52e907f0d 100644 --- a/src/libknot/zone/zone-contents.c +++ b/src/libknot/zone/zone-contents.c @@ -951,11 +951,11 @@ static int knot_zc_nsec3_parameters_match(const knot_rrset_t *rrset, dbg_zone_detail("RDATA algo: %u, iterations: %u, salt length: %u, salt:" " %.*s\n", - knot_rdata_nsec3_algorithm(rdata), - knot_rdata_nsec3_iterations(rdata), - knot_rdata_nsec3_salt_length(rdata), - knot_rdata_nsec3_salt_length(rdata), - knot_rdata_nsec3_salt(rdata)); + knot_rrset_rdata_nsec3_algorithm(rrset, rdata_pos), + knot_rrset_rdata_nsec3_iterations(rrset, rdata_pos), + knot_rrset_rdata_nsec3_salt_length(rrset, rdata_pos), + knot_rrset_rdata_nsec3_salt_length(rrset, rdata_pos), + knot_rrset_rdata_nsec3_salt(rrset, rdata_pos)); dbg_zone_detail("NSEC3PARAM algo: %u, iterations: %u, salt length: %u, " "salt: %.*s\n", params->algorithm, params->iterations, params->salt_length, params->salt_length, params->salt); @@ -1374,10 +1374,11 @@ int knot_zone_contents_add_rrset(knot_zone_contents_t *zone, } dbg_zone_exec_detail( - char *name = knot_dname_to_str(knot_rrset_owner(rrset)); - dbg_zone_detail("Adding RRSet to zone contents: %s, type %s\n", - name, knot_rrtype_to_string(knot_rrset_type(rrset))); - free(name); +// char *name = knot_dname_to_str(knot_rrset_owner(rrset)); + //TODO debug +// dbg_zone_detail("Adding RRSet to zone contents: %s, type %s\n", +// name, knot_rrtype_to_string(knot_rrset_type(rrset))); +// free(name); ); // check if the RRSet belongs to the zone @@ -1505,10 +1506,11 @@ dbg_zone_exec( // find the RRSet in the node // take only the first RDATA from the RRSIGs - dbg_zone_detail("Finding RRSet for type %s\n", - knot_rrtype_to_string( - knot_rdata_rrsig_type_covered( - knot_rrset_rdata(rrsigs)))); + //TODO debug +// dbg_zone_detail("Finding RRSet for type %s\n", +// knot_rrtype_to_string( +// knot_rdata_rrsig_type_covered( +// knot_rrset_rdata(rrsigs)))); *rrset = knot_node_get_rrset( *node, knot_rrset_rdata_rrsig_type_covered(rrsigs)); if (*rrset == NULL) { diff --git a/src/zcompile/zcompile.c b/src/zcompile/zcompile.c index 553d24be9..8828ee7ee 100644 --- a/src/zcompile/zcompile.c +++ b/src/zcompile/zcompile.c @@ -47,6 +47,11 @@ #include "libknot/util/utils.h" #include "zscanner/file_loader.h" +#define dbg_zp_detail printf +#define dbg_zp printf + +#define dbg_zp_exec_detail(cmds) do { cmds } while (0) + struct parser { rrset_list_t *node_rrsigs; @@ -129,8 +134,8 @@ static int find_rrset_for_rrsig_in_node(knot_zone_contents_t *zone, 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))); + "RRSet of type %d.\n", + knot_rrset_rdata_rrsig_type_covered(rrsig)); tmp_rrset = knot_rrset_new(rrsig->owner, knot_rrset_rdata_rrsig_type_covered(rrsig), rrsig->rclass, @@ -245,23 +250,28 @@ int add_rdata_to_rr(knot_rrset_t *rrset, const scanner_t *scanner) scanner->r_data_blocks[i + 1] - scanner->r_data_blocks[i], NULL); if (dname == NULL) { - printf("Dname failed\n."); //TODO handle return KNOT_ERROR; } - +dbg_zp_exec_detail( + char *name = knot_dname_to_str(dname); + dbg_zp_detail("zp: arr_rdata_to_rr: " + "Offset=%d:Adding dname=%s (%p)\n", + offset, name, dname); + free(name); +); memcpy(rdata + offset, &dname, sizeof(knot_dname_t *)); offset += sizeof(knot_dname_t *); //parse dname from binary } else if (descriptor_item_is_fixed(item)) { //copy the whole thing // TODO check the size + assert(item == scanner->r_data_blocks[i + 1] - + scanner->r_data_blocks[i]); memcpy(rdata + offset, scanner->r_data + scanner->r_data_blocks[i], - scanner->r_data_blocks[i + 1] - - scanner->r_data_blocks[i]); - offset += scanner->r_data_blocks[i + 1] - - scanner->r_data_blocks[i]; + item); + offset += item; } else if (descriptor_item_is_remainder(item)) { //copy the rest memcpy(rdata + offset, @@ -277,15 +287,13 @@ int add_rdata_to_rr(knot_rrset_t *rrset, const scanner_t *scanner) } } - int ret = knot_rrset_add_rdata(rrset, rdata, offset); + int ret = knot_rrset_add_rdata_single(rrset, rdata, offset); if (ret != KNOT_EOK) { dbg_zp("zp: add_rdat_to_rr: Could not add RR. Reason: %s.\n", knot_strerror(ret)); return ret; } - printf("Data ok\n"); - return KNOT_EOK; } @@ -310,12 +318,7 @@ void process_rr(const scanner_t *scanner) int ret = add_rdata_to_rr(current_rrset, scanner); assert(ret == 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",\ @@ -385,12 +388,12 @@ dbg_zp_exec_detail( if (current_rrset->type == KNOT_RRTYPE_RRSIG) { /*!< \todo Use deep copy function here! */ - knot_rrset_t *tmp_rrsig = NULL; - int ret = knot_rrset_deep_copy(current_rrset, &tmp_rrsig, 1); - if (ret != KNOT_EOK) { - dbg_zp("zp: Cannot copy RRSet.\n"); - return ret; - } + knot_rrset_t *tmp_rrsig = current_rrset; +// int ret = knot_rrset_deep_copy(current_rrset, &tmp_rrsig, 1); +// if (ret != KNOT_EOK) { +// dbg_zp("zp: Cannot copy RRSet.\n"); +// return ret; +// } // knot_rrset_t *tmp_rrsig = // knot_rrset_new(current_rrset->owner, // KNOT_RRTYPE_RRSIG, @@ -501,11 +504,14 @@ dbg_zp_exec_detail( rrset = knot_node_get_rrset(node, current_rrset->type); if (!rrset) { - int ret = knot_rrset_deep_copy(current_rrset, &rrset, 1); - if (ret != KNOT_EOK) { - dbg_zp("zp: Cannot copy RRSet.\n"); - return ret; - } + rrset = current_rrset; + } +/// if (!rrset) { +// int ret = knot_rrset_deep_copy(current_rrset, &rrset, 1); +// if (ret != KNOT_EOK) { +// dbg_zp("zp: Cannot copy RRSet.\n"); +// return ret; +// } // rrset = knot_rrset_new(current_rrset->owner, // current_rrset->type, // current_rrset->rclass, @@ -524,30 +530,30 @@ dbg_zp_exec_detail( // } /* Selected merge option does not really matter here. */ - if (knot_zone_contents_add_rrset(contents, rrset, &node, - KNOT_RRSET_DUPL_MERGE, 1) < 0) { - knot_rrset_free(&rrset); - dbg_zp("zp: process_rr: Cannot " - "add RDATA to RRSet.\n"); - return KNOTDZCOMPILE_EBRDATA; - } - } else { - if (current_rrset->type != - KNOT_RRTYPE_RRSIG && rrset->ttl != - current_rrset->ttl) { - fprintf(stderr, - "TTL does not match the TTL of the RRSet. " - "Changing to %d.\n", rrset->ttl); - } +// if (knot_zone_contents_add_rrset(contents, current_rrset, &node, +// KNOT_RRSET_DUPL_MERGE, 1) < 0) { +// knot_rrset_free(&rrset); +// dbg_zp("zp: process_rr: Cannot " +// "add RDATA to RRSet.\n"); +// return KNOTDZCOMPILE_EBRDATA; +// } +// } else { + if (current_rrset->type != + KNOT_RRTYPE_RRSIG && rrset->ttl != + current_rrset->ttl) { + fprintf(stderr, + "TTL does not match the TTL of the RRSet. " + "Changing to %d.\n", rrset->ttl); + } - 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; - } + if (knot_zone_contents_add_rrset(contents, current_rrset, + &node, + KNOT_RRSET_DUPL_MERGE, 1) < 0) { + dbg_zp("zp: process_rr: Cannot " + "add RRSets.\n"); + return KNOTDZCOMPILE_EBRDATA; } +// } parser->last_node = node; @@ -569,12 +575,13 @@ int zone_read(const char *name, const char *zonefile, const char *outfile, NULL, 0); my_parser.current_zone = knot_zone_contents_new(my_parser.last_node, 0, 0, zone); + my_parser.node_rrsigs = NULL; file_loader_t *loader = file_loader_create(zonefile, name, KNOT_CLASS_IN, 3600, process_rr, process_error, &my_parser); file_loader_process(loader); - printf("Done?\n"); + file_loader_free(loader); } /*! @} */ -- GitLab