summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-07-20 02:02:45 +0200
committerSven Eden <yamakuzure@gmx.net>2017-03-14 10:07:02 +0100
commit9fc688865394518a68539070e10d8c9eb1f0dd6e (patch)
tree110e217212c04a52570a443b6a6228f6ea8d95b0 /src/shared
parentf08ce65bef386c42d6a1c0171dac612512772c70 (diff)
shared: dns-name - add dns_name_between()
Given three DNS names this function indicates if the second argument lies strictly between the first and the third according to the canonical DNS name order. Note that the order is circular, so the last name is considered to be before the first.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/dns-domain.c22
-rw-r--r--src/shared/dns-domain.h1
2 files changed, 23 insertions, 0 deletions
diff --git a/src/shared/dns-domain.c b/src/shared/dns-domain.c
index 20a44ce4e..e716d333e 100644
--- a/src/shared/dns-domain.c
+++ b/src/shared/dns-domain.c
@@ -464,6 +464,28 @@ int dns_name_endswith(const char *name, const char *suffix) {
}
}
+int dns_name_between(const char *a, const char *b, const char *c) {
+ int n;
+
+ /* Determine if b is strictly greater than a and strictly smaller than c.
+ We consider the order of names to be circular, so that if a is
+ strictly greater than c, we consider b to be between them if it is
+ either greater than a or smaller than c. This is how the canonical
+ DNS name order used in NSEC records work. */
+
+ n = dns_name_compare_func(a, c);
+ if (n == 0)
+ return -EINVAL;
+ else if (n < 0)
+ /* a<---b--->c */
+ return dns_name_compare_func(a, b) < 0 &&
+ dns_name_compare_func(b, c) < 0;
+ else
+ /* <--b--c a--b--> */
+ return dns_name_compare_func(b, c) < 0 ||
+ dns_name_compare_func(a, b) < 0;
+}
+
int dns_name_reverse(int family, const union in_addr_union *a, char **ret) {
const uint8_t *p;
int r;
diff --git a/src/shared/dns-domain.h b/src/shared/dns-domain.h
index 516d244f7..4d9a54e59 100644
--- a/src/shared/dns-domain.h
+++ b/src/shared/dns-domain.h
@@ -40,6 +40,7 @@ unsigned long dns_name_hash_func(const void *s, const uint8_t hash_key[HASH_KEY_
int dns_name_compare_func(const void *a, const void *b);
extern const struct hash_ops dns_name_hash_ops;
+int dns_name_between(const char *a, const char *b, const char *c);
int dns_name_equal(const char *x, const char *y);
int dns_name_endswith(const char *name, const char *suffix);