Commit 7a9c6ba1 authored by Lubos Slovak's avatar Lubos Slovak

Domain name case hack.

- Converting domain names to lowercase when saving to zone.
  (This will probably remain in the final version too.)
- Temporary converting domain name to lowercase in
  zone_contents_find_dname_hash().

TODO: This should be resolved more systematically. One possible
      solution: save the QNAME converted to lowercase to the packet
      structure and use it for all lookups.

fixes #1164
parent 06d1d54f
......@@ -627,6 +627,35 @@ char *knot_dname_to_str(const knot_dname_t *dname)
/*----------------------------------------------------------------------------*/
int knot_dname_to_lower(knot_dname_t *dname)
{
if (dname == NULL) {
return KNOT_EBADARG;
}
for (int i = 0; i < dname->size; ++i) {
dname->name[i] = knot_tolower(dname->name[i]);
}
return KNOT_EOK;
}
/*----------------------------------------------------------------------------*/
int knot_dname_to_lower_copy(const knot_dname_t *dname, char *name,
size_t size)
{
if (dname == NULL || name == NULL || size < dname->size) {
return KNOT_EBADARG;
}
for (int i = 0; i < dname->size; ++i) {
name[i] = knot_tolower(dname->name[i]);
}
return KNOT_EOK;
}
/*----------------------------------------------------------------------------*/
const uint8_t *knot_dname_name(const knot_dname_t *dname)
{
return dname->name;
......
......@@ -172,6 +172,11 @@ knot_dname_t *knot_dname_deep_copy(const knot_dname_t *dname);
*/
char *knot_dname_to_str(const knot_dname_t *dname);
int knot_dname_to_lower(knot_dname_t *dname);
int knot_dname_to_lower_copy(const knot_dname_t *dname, char *name,
size_t size);
/*!
* \brief Returns the domain name in wire format.
*
......
......@@ -171,6 +171,9 @@ int knot_dname_table_add_dname(knot_dname_table_t *table,
struct dname_table_node *node =
malloc(sizeof(struct dname_table_node));
CHECK_ALLOC_LOG(node, KNOT_ENOMEM);
// convert the dname to lowercase
knot_dname_to_lower(dname);
node->dname = dname;
node->avl.avl_height = 0;
......
......@@ -20,6 +20,7 @@
#include "util/error.h"
#include "util/debug.h"
#include "common/base32hex.h"
#include "consts.h"
/*----------------------------------------------------------------------------*/
/* Non-API functions */
......@@ -1684,6 +1685,18 @@ const knot_node_t *knot_zone_contents_find_previous_nsec3(
return knot_zone_contents_get_previous(zone, name);
}
/*----------------------------------------------------------------------------*/
static void knot_zone_contents_left_chop(char *name, size_t *size)
{
int i = 0;
while (name[i] != '.') {
++i;
}
memcpy(name, name + i + 1, *size - i - 1);
*size = *size - i - 1;
}
/*----------------------------------------------------------------------------*/
#ifdef USE_HASH_TABLE
int knot_zone_contents_find_dname_hash(const knot_zone_contents_t *zone,
......@@ -1716,10 +1729,17 @@ DEBUG_KNOT_ZONE(
*closest_encloser = NULL;
return KNOT_EBADZONE;
}
// temporary name used for hashing
char name_tmp[KNOT_MAX_DNAME_LENGTH];
size_t name_size = name->size;
if (knot_dname_to_lower_copy(name, name_tmp, KNOT_MAX_DNAME_LENGTH)
!= KNOT_EOK) {
return KNOT_ERROR;
}
const ck_hash_table_item_t *item = ck_find_item(zone->table,
(const char *)name->name,
name->size);
name_tmp, name_size);
if (item != NULL) {
*node = (const knot_node_t *)item->value;
......@@ -1738,32 +1758,32 @@ DEBUG_KNOT_ZONE(
// chop leftmost labels until some node is found
// copy the name for chopping
/* Local allocation, will be discarded. */
knot_dname_t *name_copy = knot_dname_deep_copy(name);
//knot_dname_t *name_copy = knot_dname_deep_copy(name);
DEBUG_KNOT_ZONE(
char *n = knot_dname_to_str(name_copy);
debug_knot_zone("Finding closest encloser..\nStarting with: %s\n", n);
free(n);
//char *n = knot_dname_to_str(name_copy);
debug_knot_zone("Finding closest encloser..\nStarting with: %.*s\n",
name_size, name_tmp);
//free(n);
);
while (item == NULL) {
knot_dname_left_chop_no_copy(name_copy);
//knot_dname_left_chop_no_copy(name_copy);
knot_zone_contents_left_chop(name_tmp, &name_size);
DEBUG_KNOT_ZONE(
char *n = knot_dname_to_str(name_copy);
debug_knot_zone("Chopped leftmost label: %s (%.*s, size %u)"
"\n", n, name_copy->size, name_copy->name,
name_copy->size);
free(n);
//char *n = knot_dname_to_str(name_copy);
debug_knot_zone("Chopped leftmost label: %.*s\n",
name_size, name_tmp);
//free(n);
);
// not satisfied in root zone!!
assert(name_copy->label_count > 0);
//assert(name_copy->label_count > 0);
assert(name_size > 0);
item = ck_find_item(zone->table,
(const char *)name_copy->name,
name_copy->size);
item = ck_find_item(zone->table, name_tmp, name_size);
}
/* Directly discard. */
knot_dname_free(&name_copy);
//knot_dname_free(&name_copy);
assert(item != NULL);
*closest_encloser = (const knot_node_t *)item->value;
......
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