summaryrefslogtreecommitdiff
path: root/usr.sbin/nsd/dname.c
diff options
context:
space:
mode:
authorJakob Schlyter <jakob@cvs.openbsd.org>2012-01-29 11:23:25 +0000
committerJakob Schlyter <jakob@cvs.openbsd.org>2012-01-29 11:23:25 +0000
commite8f30084e102fc5635509a2663287b4757b37897 (patch)
treeb6283ce8425160b7c8248d10b981024be658cbe5 /usr.sbin/nsd/dname.c
parent7bd5b59779f6535dbae898365778c8a035dadc16 (diff)
resolve conflicts
Diffstat (limited to 'usr.sbin/nsd/dname.c')
-rw-r--r--usr.sbin/nsd/dname.c83
1 files changed, 80 insertions, 3 deletions
diff --git a/usr.sbin/nsd/dname.c b/usr.sbin/nsd/dname.c
index cc3c6a2a89c..03d3c624cfd 100644
--- a/usr.sbin/nsd/dname.c
+++ b/usr.sbin/nsd/dname.c
@@ -17,11 +17,19 @@
#include <limits.h>
#include <stdio.h>
#include <string.h>
+#include <errno.h>
#include "dns.h"
#include "dname.h"
#include "query.h"
+/**
+ * The maximum number of labels is the maximum domain name, less 1 for
+ * the root (len == 0) label, divided by two (minimum non-root label of
+ * one character + length byte), then add back in one for the root label.
+ */
+#define MAXLABELS (((MAXDOMAINLEN - 1) / 2) + 1)
+
const dname_type *
dname_make(region_type *region, const uint8_t *name, int normalize)
{
@@ -301,8 +309,10 @@ dname_is_subdomain(const dname_type *left, const dname_type *right)
int
-dname_compare(const dname_type *left, const dname_type *right)
+dname_compare(const void *vleft, const void *vright)
{
+ const dname_type* left = (const dname_type*) vleft;
+ const dname_type* right = (const dname_type*) vright;
int result;
uint8_t label_count;
uint8_t i;
@@ -382,16 +392,27 @@ const char *
dname_to_string(const dname_type *dname, const dname_type *origin)
{
static char buf[MAXDOMAINLEN * 5];
+ return dname_to_string_r(dname, origin, buf);
+}
+
+const char *
+dname_to_string_r(const dname_type *dname, const dname_type *origin,
+ char* buf)
+{
size_t i;
- size_t labels_to_convert = dname->label_count - 1;
+ size_t labels_to_convert = 0;
int absolute = 1;
char *dst;
const uint8_t *src;
-
+ if (!dname) {
+ *buf = '\0';
+ return buf;
+ }
if (dname->label_count == 1) {
strlcpy(buf, ".", sizeof(buf));
return buf;
}
+ labels_to_convert = dname->label_count - 1;
if (origin && dname_is_subdomain(dname, origin)) {
int common_labels = dname_label_match_count(dname, origin);
@@ -495,3 +516,59 @@ dname_replace(region_type* region,
return res;
}
+#ifndef FULL_PREHASH
+/**
+ * Make wildcard synthesis.
+ *
+ */
+int
+dname_make_wildcard(struct region *region,
+ struct dname const *dname,
+ struct dname const **wildcard)
+{
+ uint8_t name_size;
+ uint8_t label_count;
+ uint8_t *names;
+ uint8_t *labels;
+ struct dname *new_dname;
+ unsigned int i;
+ /*
+ * Checks:
+ * dname label_count + 1 < MAXLABELS
+ * dname size + 2 < MAXDOMAINLEN
+ */
+ if (dname->label_count > (MAXLABELS - 1)) {
+ return EINVAL;
+ }
+ if (dname->name_size > (MAXDOMAINLEN - 2)) {
+ return EINVAL;
+ }
+
+ label_count = dname->label_count + 1;
+ name_size = dname->name_size + 2;
+ new_dname = (struct dname *) region_alloc(region,
+ sizeof(dname_type) +
+ (label_count * sizeof(uint8_t)) +
+ (name_size * sizeof(uint8_t)));
+ if (new_dname == NULL) {
+ return ENOMEM;
+ }
+ new_dname->label_count = label_count;
+ new_dname->name_size = name_size;
+ labels = (uint8_t *) dname_label_offsets(new_dname);
+ memcpy(labels, dname_label_offsets(dname),
+ dname->label_count * sizeof(uint8_t));
+ for (i = 0; i < dname->label_count; i++) {
+ labels[i] += 2;
+ }
+ labels[i] = 0;
+
+ names = (uint8_t *) dname_name(new_dname);
+ *names++ = '\001';
+ *names++ = '*';
+ memcpy(names, dname_name(dname),
+ dname->name_size * sizeof(uint8_t));
+ *wildcard = new_dname;
+ return 0;
+}
+#endif \ No newline at end of file