]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolved: cache - don't flush the cache of mDNS records unneccesarily
authorTom Gundersen <teg@jklm.no>
Thu, 10 Dec 2015 18:57:41 +0000 (19:57 +0100)
committerTom Gundersen <teg@jklm.no>
Thu, 10 Dec 2015 19:15:58 +0000 (20:15 +0100)
When the DNS_RESOURCE_KEY_CACHE_FLUSH flag is not set for an mDNS packet, we should not flush
the cache for RRs with matching keys. However, we were unconditionally flushing the cache
also for these packets.

Now mark all packets as cache_flush by default, except for these mDNS packets, and respect
that flag in the cache handling.

This fixes 90325e8c2e559a21ef0bc2f26b844c140faf8020.

src/resolve/resolved-dns-cache.c
src/resolve/resolved-dns-packet.c

index 794d587d4d50f72eed2200f5a4598517dd286bcd..25243cb479b674e68c0844bb1376b97c1b0406c0 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "alloc-util.h"
 #include "dns-domain.h"
+#include "resolved-dns-answer.h"
 #include "resolved-dns-cache.h"
 #include "resolved-dns-packet.h"
 #include "string-util.h"
@@ -431,7 +432,7 @@ int dns_cache_put(
                 int owner_family,
                 const union in_addr_union *owner_address) {
 
-        DnsResourceRecord *soa = NULL;
+        DnsResourceRecord *soa = NULL, *rr;
         unsigned cache_keys, i;
         int r;
 
@@ -455,8 +456,9 @@ int dns_cache_put(
                 return 0;
         }
 
-        for (i = 0; i < answer->n_rrs; i++)
-                dns_cache_remove(c, answer->items[i].rr->key);
+        DNS_ANSWER_FOREACH(rr, answer)
+                if (rr->key->cache_flush)
+                        dns_cache_remove(c, rr->key);
 
         /* We only care for positive replies and NXDOMAINs, on all
          * other replies we will simply flush the respective entries,
@@ -478,10 +480,7 @@ int dns_cache_put(
 
         /* Second, add in positive entries for all contained RRs */
         for (i = 0; i < MIN(max_rrs, answer->n_rrs); i++) {
-                DnsResourceRecord *rr = answer->items[i].rr;
-
-                if (rr->key->cache_flush)
-                        dns_cache_remove(c, rr->key);
+                rr = answer->items[i].rr;
 
                 r = dns_cache_put_positive(c, rr, authenticated, timestamp, owner_family, owner_address);
                 if (r < 0)
index 399ba59749d7cb611742c52b18c25bd85d2c7513..e90500ce70f05b97b3da19969669fe153a63d1b8 100644 (file)
@@ -1451,7 +1451,7 @@ fail:
 
 int dns_packet_read_key(DnsPacket *p, DnsResourceKey **ret, size_t *start) {
         _cleanup_free_ char *name = NULL;
-        bool cache_flush = false;
+        bool cache_flush = true;
         uint16_t class, type;
         DnsResourceKey *key;
         size_t saved_rindex;
@@ -1477,10 +1477,10 @@ int dns_packet_read_key(DnsPacket *p, DnsResourceKey **ret, size_t *start) {
         if (p->protocol == DNS_PROTOCOL_MDNS) {
                 /* See RFC6762, Section 10.2 */
 
-                if (class & MDNS_RR_CACHE_FLUSH) {
+                if (class & MDNS_RR_CACHE_FLUSH)
                         class &= ~MDNS_RR_CACHE_FLUSH;
-                        cache_flush = true;
-                }
+                else
+                        cache_flush = false;
         }
 
         key = dns_resource_key_new_consume(class, type, name);