Commit a5c81d2b authored by Marek Vavrusa's avatar Marek Vavrusa

Removed label stack and label count.

All the functions using them we're remade using the new wire based
API. Not safe for non-linear names though.
parent 81bc4bc2
This diff is collapsed.
......@@ -43,15 +43,15 @@ struct knot_node;
*/
struct knot_dname {
uint8_t *name; /*!< Wire format of the domain name. */
uint8_t *labels; /*!< Array of labels positions in name. */
struct knot_node *node; /*!< Zone node the domain name belongs to. */
uint32_t count; /*!< Reference counter. */
uint8_t size; /*!< Length of the domain name. */
uint8_t label_count; /*!< Number of labels. */
};
typedef struct knot_dname knot_dname_t;
#define DNAME_LFT_MAXLEN 255 /* maximum lookup format length */
/*----------------------------------------------------------------------------*/
/*!
......@@ -75,20 +75,6 @@ typedef struct knot_dname knot_dname_t;
knot_dname_t *knot_dname_new_from_str(const char *name, unsigned int size,
struct knot_node *node);
/*!
* \brief Creates a dname structure from domain name possibly given in
* non-presentation format.
*
* Works the same as knot_dname_new_from_str but makes sure, that the name
* is terminated with a dot.
*
* \see knot_dname_new_from_str
*
*/
knot_dname_t *knot_dname_new_from_nonfqdn_str(const char *name,
unsigned int size,
struct knot_node *node);
/*!
* \brief Creates a dname structure from domain name given in wire format.
*
......@@ -218,13 +204,6 @@ int knot_dname_is_fqdn(const knot_dname_t *dname);
*/
knot_dname_t *knot_dname_left_chop(const knot_dname_t *dname);
/*!
* \brief Removes leftmost label from \a dname.
*
* \param dname Domain name to remove the first label from.
*/
void knot_dname_left_chop_no_copy(knot_dname_t *dname);
/*!
* \brief Checks if one domain name is a subdomain of other.
*
......@@ -257,18 +236,7 @@ int knot_dname_is_wildcard(const knot_dname_t *dname);
* \return Number of labels common for the two domain names.
*/
int knot_dname_matched_labels(const knot_dname_t *dname1,
const knot_dname_t *dname2);
/*!
* \brief Returns the number of labels in the domain name.
*
* \param dname Domain name to get the label count of.
*
* \return Number of labels in \a dname.
*
* \todo Find out if this counts the root label also.
*/
int knot_dname_label_count(const knot_dname_t *dname);
const knot_dname_t *dname2);
/*!
* \brief Replaces the suffix of given size in one domain name with other domain
......@@ -381,6 +349,49 @@ int knot_dname_wire_size(const uint8_t *name, const uint8_t *pkt);
*/
int knot_dname_wire_labels(const uint8_t *name, const uint8_t *pkt);
/*!
* \brief Align name and reference to a common number of suffix labels.
*/
int knot_dname_align(const uint8_t **d1, uint8_t d1_labels,
const uint8_t **d2, uint8_t d2_labels,
uint8_t *wire);
/*!
* \brief Compare domain name by labels.
*
* \todo No case insensitivity, flags...
*
* \param d1 Domain name.
* \param d2 Domain name.
* \param pkt Packet wire related to names (or NULL).
* \return
*/
int knot_dname_wire_cmp(const knot_dname_t *d1, const knot_dname_t *d2,
const uint8_t *pkt);
/*!
* \brief Convert domain name from wire to lookup format.
*
* Formats names from rightmost label to the leftmost, separated by the lowest
* possible character (\x00). Sorting such formatted names also gives
* correct canonical order (for NSEC/NSEC3).
*
* Example:
* Name: lake.example.com. Wire: \x04lake\x07example\x03com\x00
* Lookup format com\x00example\x00lake\x00
*
* Maximum length of such a domain name is DNAME_LFT_MAXLEN characters.
*
* \param dst Memory to store converted name into.
* \param maxlen Maximum memory length.
* \param src Source domain name.
*
* \retval KNOT_EOK if successful
* \retval KNOT_ESPACE when not enough memory.
* \retval KNOT_EINVAL on invalid parameters
*/
int dname_lf(uint8_t *dst, const knot_dname_t *src, size_t maxlen);
#endif /* _KNOT_DNAME_H_ */
/*! @} */
......@@ -20,18 +20,8 @@
/* Test dname_parse_from_wire */
static int test_fw(size_t l, const char *w) {
size_t p = 0;
knot_dname_t *d = NULL;
d = knot_dname_parse_from_wire((const uint8_t*)w, &p, l, NULL, NULL);
int ret = (d != NULL);
// d = knot_dname_new_from_wire((const uint8_t*)w, l, 0);
// if (d) {
// for(unsigned i = 0; i < d->label_count; ++i) {
// diag("%d", knot_dname_label_size(d, i));
// }
// }
knot_dname_free(&d);
return ret;
const uint8_t *np = (const uint8_t *)w + l;
return knot_dname_wire_check((const uint8_t *)w, np, NULL) > 0;
}
static int dname_tests_count(int argc, char *argv[]);
......@@ -45,12 +35,14 @@ unit_api dname_tests_api = {
static int dname_tests_count(int argc, char *argv[])
{
return 8;
return 11;
}
static int dname_tests_run(int argc, char *argv[])
{
const char *w = NULL;
knot_dname_t *d = NULL;
const char *w = NULL, *t = NULL;
unsigned len = 0;
/* 1. NULL wire */
ok(!test_fw(0, NULL), "parsing NULL dname");
......@@ -80,5 +72,26 @@ static int dname_tests_run(int argc, char *argv[])
w = "\x20\x68\x6d\x6e\x63\x62\x67\x61\x61\x61\x61\x65\x72\x6b\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x61\x61\x61\x62\x65\x6a\x61\x6d\x20\x67\x6e\x69\x64\x68\x62\x61\x61\x61\x61\x65\x6c\x64\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x61\x61\x61\x62\x65\x6a\x61\x6d\x20\x61\x63\x6f\x63\x64\x62\x61\x61\x61\x61\x65\x6b\x72\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x61\x61\x61\x62\x65\x6a\x61\x6d\x20\x69\x62\x63\x6d\x6a\x6f\x61\x61\x61\x61\x65\x72\x6a\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x61\x61\x61\x62\x65\x6a\x61\x6d\x20\x6f\x6c\x6e\x6c\x67\x68\x61\x61\x61\x61\x65\x73\x72\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x61\x61\x61\x62\x65\x6a\x61\x6d\x20\x6a\x6b\x64\x66\x66\x67\x61\x61\x61\x61\x65\x6c\x68\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x61\x61\x61\x62\x65\x6a\x61\x6d\x20\x67\x67\x6c\x70\x70\x61\x61\x61\x61\x61\x65\x73\x72\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x61\x61\x61\x62\x65\x6a\x61\x6d\x20\x65\x6b\x6c\x67\x70\x66\x61\x61\x61\x61\x65\x6c\x68\x30\x30\x30\x30\x64\x6c\x61\x61\x61\x61\x61\x0\x21\x42\x63\x84\xa5\xc6\xe7\x8\xa\xd\x11\x73\x3\x6e\x69\x63\x2\x43\x5a";
ok(!test_fw(277, w), "parsing invalid label (spec. case 1)");
/* 9. parse from string (correct) .*/
len = 10;
w = "\x04""abcd""\x03""efg";
t = "abcd.efg";
d = knot_dname_new_from_str(t, strlen(t), NULL);
ok(d && d->size == len && memcmp(d->name, w, len) == 0,
"dname_fromstr: parsed correct non-FQDN name");
knot_dname_free(&d);
/* 10. parse FQDN from string (correct) .*/
t = "abcd.efg.";
d = knot_dname_new_from_str(t, strlen(t), NULL);
ok(d && d->size == len && memcmp(d->name, w, len) == 0,
"dname_fromstr: parsed correct FQDN name");
knot_dname_free(&d);
/* 11. parse name from string (incorrect) .*/
t = "..";
d = knot_dname_new_from_str(t, strlen(t), NULL);
ok(d == NULL, "dname_fromstr: parsed incorrect name");
return 0;
}
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