summaryrefslogtreecommitdiff
path: root/src/resolve/resolved-dns-cache.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-11-24 00:18:49 +0100
committerLennart Poettering <lennart@poettering.net>2015-11-24 00:20:39 +0100
commit58db254ade4fb2ef77de68f28c4f13814819f6a1 (patch)
tree597cc7eb7ec7822f62b91e25558e3e9d490b655c /src/resolve/resolved-dns-cache.c
parent5ce1946f4def03e0ab7127dd5729949a32e060ac (diff)
resolved: implement client-side DNAME resolution
Most servers apparently always implicitly convert DNAME to CNAME, but some servers don't, hence implement this properly, as this is required by edns0.
Diffstat (limited to 'src/resolve/resolved-dns-cache.c')
-rw-r--r--src/resolve/resolved-dns-cache.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c
index 04f64022e0..d963ce6e00 100644
--- a/src/resolve/resolved-dns-cache.c
+++ b/src/resolve/resolved-dns-cache.c
@@ -20,8 +20,10 @@
***/
#include "alloc-util.h"
+#include "dns-domain.h"
#include "resolved-dns-cache.h"
#include "resolved-dns-packet.h"
+#include "string-util.h"
/* Never cache more than 1K entries */
#define CACHE_MAX 1024
@@ -521,25 +523,53 @@ fail:
static DnsCacheItem *dns_cache_get_by_key_follow_cname(DnsCache *c, DnsResourceKey *k) {
_cleanup_(dns_resource_key_unrefp) DnsResourceKey *cname_key = NULL;
- DnsCacheItem *i, *j;
+ DnsCacheItem *i;
+ const char *n;
+ int r;
assert(c);
assert(k);
+ /* If we hit some OOM error, or suchlike, we don't care too
+ * much, after all this is just a cache */
+
i = hashmap_get(c->by_key, k);
- if (i || k->type == DNS_TYPE_CNAME)
+ if (i || k->type == DNS_TYPE_CNAME || k->type == DNS_TYPE_DNAME)
return i;
- /* check if we have a CNAME record instead */
+ /* Check if we have a CNAME record instead */
cname_key = dns_resource_key_new_cname(k);
if (!cname_key)
return NULL;
- j = hashmap_get(c->by_key, cname_key);
- if (j)
- return j;
+ i = hashmap_get(c->by_key, cname_key);
+ if (i)
+ return i;
+
+ /* OK, let's look for cached DNAME records. */
+ n = DNS_RESOURCE_KEY_NAME(k);
+ for (;;) {
+ _cleanup_(dns_resource_key_unrefp) DnsResourceKey *dname_key = NULL;
+ char label[DNS_LABEL_MAX];
+
+ if (isempty(n))
+ return NULL;
- return i;
+ dname_key = dns_resource_key_new(k->class, DNS_TYPE_DNAME, n);
+ if (!dname_key)
+ return NULL;
+
+ i = hashmap_get(c->by_key, dname_key);
+ if (i)
+ return i;
+
+ /* Jump one label ahead */
+ r = dns_label_unescape(&n, label, sizeof(label));
+ if (r <= 0)
+ return NULL;
+ }
+
+ return NULL;
}
int dns_cache_lookup(DnsCache *c, DnsResourceKey *key, int *rcode, DnsAnswer **ret) {