Commit 1e68d5aa authored by Lubos Slovak's avatar Lubos Slovak

RDATA lowercase: Dnames to lc when adding to zone.

parent a229fa7f
......@@ -602,6 +602,10 @@ static int insert_rr(zone_contents_t *z,
return KNOT_EINVAL;
}
/* TODO [lowercase]: Here we would need the RR to be in lowercase, at least
* the owner.
*/
// check if the RRSet belongs to the zone
if (!knot_dname_is_sub(rr->owner, z->apex->owner) &&
!knot_dname_is_equal(rr->owner, z->apex->owner)) {
......@@ -729,10 +733,87 @@ static bool rrset_is_nsec3rel(const knot_rrset_t *rr)
== KNOT_RRTYPE_NSEC3));
}
static size_t naptr_header_size(uint8_t *naptr, uint8_t *maxp)
{
/*! \todo Copy-pasted from rrset.c. Unify. */
size_t size = 0;
/* Fixed fields size (order, preference) */
size += 2 * sizeof(uint16_t);
/* Variable fields size (flags, services, regexp) */
for (int i = 0; i < 3; i++) {
uint8_t *len_ptr = naptr + size;
assert(len_ptr < maxp);
size += 1 + *len_ptr;
}
return size;
}
static void convert_to_lowercase(knot_rrset_t *rrset)
{
int ret = knot_dname_to_lower(rrset->owner);
assert(ret == KNOT_EOK);
const rdata_descriptor_t *desc = knot_get_rdata_descriptor(rrset->type);
for (int j = 0; j < rrset->rrs.rr_count; ++j) {
knot_rdata_t *rdata = knot_rdataset_at(&rrset->rrs, j);
uint16_t rdlen = knot_rdata_rdlen(rdata);
uint8_t *pos = knot_rdata_data(rdata);
for (int i = 0; desc->block_types[i] != KNOT_RDATA_WF_END; ++i) {
int type = desc->block_types[i];
switch (type) {
case KNOT_RDATA_WF_COMPRESSIBLE_DNAME:
case KNOT_RDATA_WF_DECOMPRESSIBLE_DNAME:
case KNOT_RDATA_WF_FIXED_DNAME:
ret = knot_dname_to_lower(pos);
assert(ret == KNOT_EOK);
pos += knot_dname_size(pos);
break;
case KNOT_RDATA_WF_NAPTR_HEADER:
pos += naptr_header_size(pos, rdata + rdlen);
break;
case KNOT_RDATA_WF_REMAINDER:
break;
default:
/* Fixed size block */
assert(type > 0);
pos += type;
}
}
}
}
static knot_rrset_t *rrset_to_lowercase(const knot_rrset_t *rrset)
{
knot_rrset_t *rr_l = knot_rrset_copy(rrset, NULL);
if (rr_l != NULL) {
convert_to_lowercase(rr_l);
}
return rr_l;
}
int zone_contents_add_rr(zone_contents_t *z, const knot_rrset_t *rr,
zone_node_t **n)
{
return insert_rr(z, rr, n, rrset_is_nsec3rel(rr));
/* Convert all dnames in RRSet to lowercase. */
knot_rrset_t *rr_lc = rrset_to_lowercase(rr);
int ret;
if (rr_lc != NULL) {
ret = insert_rr(z, rr_lc, n, rrset_is_nsec3rel(rr));
knot_rrset_free(&rr_lc, NULL);
} else {
ret = KNOT_ERROR;
}
return ret;
}
/*----------------------------------------------------------------------------*/
......
......@@ -178,6 +178,7 @@ int node_add_rrset(zone_node_t *node, const knot_rrset_t *rrset, mm_ctx_t *mm)
if (node->rrs[i].type == rrset->type) {
struct rr_data *node_data = &node->rrs[i];
const bool ttl_err = ttl_error(node_data, rrset);
/* TODO[lowercase] should change case. */
int ret = knot_rdataset_merge(&node_data->rrs,
&rrset->rrs, mm);
if (ret != KNOT_EOK) {
......@@ -189,6 +190,7 @@ int node_add_rrset(zone_node_t *node, const knot_rrset_t *rrset, mm_ctx_t *mm)
}
// New RRSet (with one RR)
/* TODO[lowercase] should change case. */
return add_rrset_no_merge(node, rrset, mm);
}
......
......@@ -115,6 +115,10 @@ int zcreator_step(zcreator_t *zc, const knot_rrset_t *rr)
return KNOT_EOK;
}
/* TODO[lowercase]: Convert to lowercase here? AXFR + zone load.
* Below, in zone_contents_add_rr() it would also deal with IXFR.
*/
zone_node_t *node = NULL;
int ret = zone_contents_add_rr(zc->z, rr, &node);
if (ret != KNOT_EOK) {
......@@ -160,6 +164,8 @@ static void scanner_process(zs_scanner_t *scanner)
}
knot_dname_to_lower(owner);
/* TODO[lowercase]: Owner is in lowercase, need the RDATA! */
knot_rrset_t rr;
knot_rrset_init(&rr, owner, scanner->r_type, scanner->r_class);
int ret = add_rdata_to_rr(&rr, 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