diff --git a/src/knot/zone/zone-load.c b/src/knot/zone/zone-load.c index 579b19ccac85c978209db78191182033e33bb710..d114f2d3b0dea2c0c013dee2b131384ba203edf3 100644 --- a/src/knot/zone/zone-load.c +++ b/src/knot/zone/zone-load.c @@ -231,62 +231,65 @@ static int add_rdata_to_rr(knot_rrset_t *rrset, const scanner_t *scanner) return KNOT_EINVAL; } - parser_context_t *parser = scanner->data; +// parser_context_t *parser = scanner->data; - const rdata_descriptor_t *desc = - get_rdata_descriptor(knot_rrset_type(rrset)); - assert(desc); +// const rdata_descriptor_t *desc = +// get_rdata_descriptor(knot_rrset_type(rrset)); +// assert(desc); dbg_zp_detail("zp: add_rdata_to_rr: Adding type %d, RRSet has %d RRs.\n", rrset->type, rrset->rdata_count); - size_t rdlen = calculate_item_size(rrset, scanner); - size_t offset = 0; - uint8_t *rdata = knot_rrset_create_rdata(rrset, rdlen); +// size_t rdlen = calculate_item_size(rrset, scanner); +// size_t offset = 0; + uint8_t *rdata = knot_rrset_create_rdata(rrset, scanner->r_data_length); if (rdata == NULL) { dbg_zp("zp: create_rdata: Could not create RR.\n"); return KNOT_ENOMEM; } - for (int i = 0; desc->block_types[i] != KNOT_RDATA_WF_END; i++) { - int item = desc->block_types[i]; - if (descriptor_item_is_dname(item)) { - knot_dname_t *dname = - knot_dname_copy(scanner->r_data + scanner->r_data_blocks[i]); - if (dname == NULL) { - return KNOT_ERROR; - } - knot_dname_to_lower(dname); -dbg_zp_exec_detail( - char *name = knot_dname_to_str(dname); - dbg_zp_detail("zp: arr_rdata_to_rr: " - "Offset=%zu:Adding dname=%s (%p)\n", - offset, name, dname); - free(name); -); - /* Handle DNAME duplications. */ - knot_zone_contents_insert_dname_into_table(&dname, - parser->lookup_tree); - memcpy(rdata + offset, &dname, sizeof(knot_dname_t *)); - offset += sizeof(knot_dname_t *); - } 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], - item); - offset += item; - } else { - 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]; - } - } +/* RRSet refactor: All this is useless now, just copy what is parsed. */ +// for (int i = 0; desc->block_types[i] != KNOT_RDATA_WF_END; i++) { +// int item = desc->block_types[i]; +// if (descriptor_item_is_dname(item)) { +// knot_dname_t *dname = +// knot_dname_copy(scanner->r_data + scanner->r_data_blocks[i]); +// if (dname == NULL) { +// return KNOT_ERROR; +// } +// knot_dname_to_lower(dname); +//dbg_zp_exec_detail( +// char *name = knot_dname_to_str(dname); +// dbg_zp_detail("zp: arr_rdata_to_rr: " +// "Offset=%zu:Adding dname=%s (%p)\n", +// offset, name, dname); +// free(name); +//); +// /* Handle DNAME duplications. */ +// knot_zone_contents_insert_dname_into_table(&dname, +// parser->lookup_tree); +// memcpy(rdata + offset, &dname, sizeof(knot_dname_t *)); +// offset += sizeof(knot_dname_t *); +// } 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], +// item); +// offset += item; +// } else { +// 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]; +// } +// } + + memcpy(rdata, scanner->r_data, scanner->r_data_length); return KNOT_EOK; } @@ -325,6 +328,10 @@ static void process_rr(const scanner_t *scanner) return; } + /* [RRSet refactor] Checking RRSet format. */ + printf("Parsed RR: \n"); + knot_rrset_dump(current_rrset); + dbg_zp_verb("zp: process_rr: Processing type: %d.\n", parser->current_rrset->type); diff --git a/src/libknot/rrset.c b/src/libknot/rrset.c index aae7111ef27f61efe8b01cd46f378ac380609ef4..cef40f17c212b99759fab3530d37e5e624c20079 100644 --- a/src/libknot/rrset.c +++ b/src/libknot/rrset.c @@ -121,8 +121,8 @@ dbg_rrset_exec_detail( int item = desc->block_types[i]; const uint8_t *rdata = rrset_rdata_pointer(rrset, rdata_pos); if (descriptor_item_is_dname(item)) { - knot_dname_t *dname; - memcpy(&dname, rdata + offset, sizeof(knot_dname_t *)); + knot_dname_t *dname = rdata + offset; + //memcpy(&dname, rdata + offset, sizeof(knot_dname_t *)); char *name = knot_dname_to_str(dname); if (dname == NULL) { dbg_rrset_detail("DNAME error.\n"); @@ -131,7 +131,7 @@ dbg_rrset_exec_detail( dbg_rrset_detail("block=%d: (%p) DNAME=%s\n", i, dname, name); free(name); - offset += sizeof(knot_dname_t *); + offset += knot_dname_size(dname); } else if (descriptor_item_is_fixed(item)) { dbg_rrset_detail("block=%d Raw data (size=%d):\n", i, item); @@ -185,12 +185,12 @@ static int rrset_rdata_compare_one(const knot_rrset_t *rrset1, for (int i = 0; desc->block_types[i] != KNOT_RDATA_WF_END; i++) { if (descriptor_item_is_dname(desc->block_types[i])) { - knot_dname_t *dname1 = NULL; - memcpy(&dname1, r1 + offset, sizeof(knot_dname_t *)); - knot_dname_t *dname2 = NULL; - memcpy(&dname2, r2 + offset, sizeof(knot_dname_t *)); + knot_dname_t *dname1 = r1 + offset; + //memcpy(&dname1, r1 + offset, sizeof(knot_dname_t *)); + knot_dname_t *dname2 = r2 + offset; + //memcpy(&dname2, r2 + offset, sizeof(knot_dname_t *)); cmp = knot_dname_cmp(dname1, dname2); - offset += sizeof(knot_dname_t *); + offset += knot_dname_size(dname1); } else if (descriptor_item_is_fixed(desc->block_types[i])) { cmp = memcmp(r1 + offset, r2 + offset, desc->block_types[i]); @@ -1461,13 +1461,14 @@ void knot_rrset_deep_free(knot_rrset_t **rrset, int free_owner, } if ((*rrset)->rrsigs != NULL) { - knot_rrset_deep_free(&(*rrset)->rrsigs, free_owner, free_rdata_dnames); + knot_rrset_deep_free(&(*rrset)->rrsigs, free_owner, + free_rdata_dnames); } - if (free_rdata_dnames) { - rrset_dnames_apply(*rrset, rrset_release_dnames_in_rr, - NULL); - } +// if (free_rdata_dnames) { +// rrset_dnames_apply(*rrset, rrset_release_dnames_in_rr, +// NULL); +// } free((*rrset)->rdata); free((*rrset)->rdata_indices); @@ -1487,13 +1488,13 @@ void knot_rrset_deep_free_no_sig(knot_rrset_t **rrset, int free_owner, return; } - if (free_rdata_dnames) { - int ret = rrset_dnames_apply(*rrset, rrset_release_dnames_in_rr, - NULL); - if (ret != KNOT_EOK) { - dbg_rrset("rr: deep_free: Could not free DNAMEs in RDATA.\n"); - } - } +// if (free_rdata_dnames) { +// int ret = rrset_dnames_apply(*rrset, rrset_release_dnames_in_rr, +// NULL); +// if (ret != KNOT_EOK) { +// dbg_rrset("rr: deep_free: Could not free DNAMEs in RDATA.\n"); +// } +// } free((*rrset)->rdata); free((*rrset)->rdata_indices); @@ -1626,8 +1627,8 @@ const knot_dname_t *knot_rrset_rdata_cname_name(const knot_rrset_t *rrset) return NULL; } - knot_dname_t *dname; - memcpy(&dname, rrset->rdata, sizeof(knot_dname_t *)); + const knot_dname_t *dname = rrset->rdata; +// memcpy(&dname, rrset->rdata, sizeof(knot_dname_t *)); return dname; } @@ -1636,8 +1637,8 @@ const knot_dname_t *knot_rrset_rdata_dname_target(const knot_rrset_t *rrset) if (rrset == NULL) { return NULL; } - knot_dname_t *dname; - memcpy(&dname, rrset->rdata, sizeof(knot_dname_t *)); + const knot_dname_t *dname = rrset->rdata; +// memcpy(&dname, rrset->rdata, sizeof(knot_dname_t *)); return dname; } @@ -1646,8 +1647,8 @@ const knot_dname_t *knot_rrset_rdata_soa_primary_ns(const knot_rrset_t *rrset) if (rrset == NULL) { return NULL; } - knot_dname_t *dname; - memcpy(&dname, rrset->rdata, sizeof(knot_dname_t *)); + const knot_dname_t *dname = rrset->rdata; +// memcpy(&dname, rrset->rdata, sizeof(knot_dname_t *)); return dname; } @@ -1656,9 +1657,10 @@ const knot_dname_t *knot_rrset_rdata_soa_mailbox(const knot_rrset_t *rrset) if (rrset == NULL) { return NULL; } - knot_dname_t *dname; - memcpy(&dname, rrset->rdata + sizeof(knot_dname_t *), - sizeof(knot_dname_t *)); + const knot_dname_t *dname = rrset->rdata + + knot_dname_size(rrset->rdata); +// memcpy(&dname, rrset->rdata + sizeof(knot_dname_t *), +// sizeof(knot_dname_t *)); return dname; } @@ -1669,8 +1671,8 @@ const knot_dname_t *knot_rrset_rdata_rp_first_dname(const knot_rrset_t *rrset, return NULL; } - knot_dname_t *dname; - memcpy(&dname, knot_rrset_get_rdata(rrset, pos), sizeof(knot_dname_t *)); + const knot_dname_t *dname = knot_rrset_get_rdata(rrset, pos); +// memcpy(&dname, knot_rrset_get_rdata(rrset, pos), sizeof(knot_dname_t *)); return dname; } @@ -1681,9 +1683,10 @@ const knot_dname_t *knot_rrset_rdata_rp_second_dname(const knot_rrset_t *rrset, return NULL; } - knot_dname_t *dname; - memcpy(&dname, knot_rrset_get_rdata(rrset, pos) + sizeof(knot_dname_t *), - sizeof(knot_dname_t *)); + const knot_dname_t *dname = knot_rrset_get_rdata(rrset, pos) + + knot_dname_size(rrset->rdata); +// memcpy(&dname, knot_rrset_get_rdata(rrset, pos) + sizeof(knot_dname_t *), +// sizeof(knot_dname_t *)); return dname; } @@ -2177,9 +2180,8 @@ dbg_rrset_exec_detail( rrset_rdata_size_total(rrset)); for (uint16_t i = 0; i < rrset->rdata_count; i++) { - dbg_rrset_detail("%d=%d ", i, rrset_rdata_offset(rrset, i)); + dbg_rrset_detail("%d=%d\n", i, rrset_rdata_offset(rrset, i)); } - dbg_rrset_detail("\n"); if (knot_rrset_rdata_rr_count(rrset) == 0) { dbg_rrset_detail("NO RDATA\n"); @@ -2376,9 +2378,9 @@ const knot_dname_t *knot_rrset_rdata_ns_name(const knot_rrset_t *rrset, return NULL; } - const knot_dname_t *dname; - memcpy(&dname, rrset_rdata_pointer(rrset, rdata_pos), - sizeof(knot_dname_t *)); + const knot_dname_t *dname = rrset_rdata_pointer(rrset, rdata_pos); +// memcpy(&dname, rrset_rdata_pointer(rrset, rdata_pos), +// sizeof(knot_dname_t *)); return dname; } @@ -2389,9 +2391,9 @@ const knot_dname_t *knot_rrset_rdata_mx_name(const knot_rrset_t *rrset, return NULL; } - knot_dname_t *dname; - memcpy(&dname, rrset_rdata_pointer(rrset, rdata_pos) + 2, - sizeof(knot_dname_t *)); + const knot_dname_t *dname = rrset_rdata_pointer(rrset, rdata_pos) + 2; +// memcpy(&dname, rrset_rdata_pointer(rrset, rdata_pos) + 2, +// sizeof(knot_dname_t *)); return dname; } @@ -2402,9 +2404,9 @@ const knot_dname_t *knot_rrset_rdata_srv_name(const knot_rrset_t *rrset, return NULL; } - knot_dname_t *dname; - memcpy(&dname, rrset_rdata_pointer(rrset, rdata_pos) + 6, - sizeof(knot_dname_t *)); + const knot_dname_t *dname = rrset_rdata_pointer(rrset, rdata_pos) + 6; +// memcpy(&dname, rrset_rdata_pointer(rrset, rdata_pos) + 6, +// sizeof(knot_dname_t *)); return dname; }