chiark / gitweb /
resolved: properly process DNAME RRs
[elogind.git] / src / resolve / resolved-dns-cache.c
index 8c859d19b5fed0c23687cb1cf21bc7e616c6bd36..7359dfa271973272637ca15f050b6e2538df090c 100644 (file)
@@ -270,6 +270,11 @@ static int dns_cache_put_positive(DnsCache *c, DnsResourceRecord *rr, usec_t tim
                 return 0;
         }
 
+        if (rr->key->class == DNS_CLASS_ANY)
+                return 0;
+        if (rr->key->type == DNS_TYPE_ANY)
+                return 0;
+
         /* Entry exists already? Update TTL and timestamp */
         existing = dns_cache_get(c, rr);
         if (existing) {
@@ -311,6 +316,11 @@ static int dns_cache_put_negative(DnsCache *c, DnsResourceKey *key, int rcode, u
 
         dns_cache_remove(c, key);
 
+        if (key->class == DNS_CLASS_ANY)
+                return 0;
+        if (key->type == DNS_TYPE_ANY)
+                return 0;
+
         if (!IN_SET(rcode, DNS_RCODE_SUCCESS, DNS_RCODE_NXDOMAIN))
                 return 0;
 
@@ -337,17 +347,21 @@ static int dns_cache_put_negative(DnsCache *c, DnsResourceKey *key, int rcode, u
         return 0;
 }
 
-int dns_cache_put(DnsCache *c, DnsQuestion *q, int rcode, DnsAnswer *answer, usec_t timestamp) {
+int dns_cache_put(DnsCache *c, DnsQuestion *q, int rcode, DnsAnswer *answer, unsigned max_rrs, usec_t timestamp) {
         unsigned i;
         int r;
 
         assert(c);
-        assert(answer);
+        assert(q);
 
         /* First, delete all matching old RRs, so that we only keep
          * complete by_key in place. */
         for (i = 0; i < q->n_keys; i++)
                 dns_cache_remove(c, q->keys[i]);
+
+        if (!answer)
+                return 0;
+
         for (i = 0; i < answer->n_rrs; i++)
                 dns_cache_remove(c, answer->rrs[i]->key);
 
@@ -365,7 +379,7 @@ int dns_cache_put(DnsCache *c, DnsQuestion *q, int rcode, DnsAnswer *answer, use
                 timestamp = now(CLOCK_MONOTONIC);
 
         /* Second, add in positive entries for all contained RRs */
-        for (i = 0; i < answer->n_rrs; i++) {
+        for (i = 0; i < MIN(max_rrs, answer->n_rrs); i++) {
                 r = dns_cache_put_positive(c, answer->rrs[i], timestamp);
                 if (r < 0)
                         goto fail;
@@ -426,6 +440,14 @@ int dns_cache_lookup(DnsCache *c, DnsQuestion *q, int *rcode, DnsAnswer **ret) {
         for (i = 0; i < q->n_keys; i++) {
                 DnsCacheItem *j;
 
+                if (q->keys[i]->type == DNS_TYPE_ANY ||
+                    q->keys[i]->class == DNS_CLASS_ANY) {
+                        /* If we have ANY lookups we simply refresh */
+                        *ret = NULL;
+                        *rcode = 0;
+                        return 0;
+                }
+
                 j = hashmap_get(c->by_key, q->keys[i]);
                 if (!j) {
                         /* If one question cannot be answered we need to refresh */