]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolve: do not cache mDNS goodbye packet
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 29 Sep 2022 07:50:27 +0000 (16:50 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 30 Sep 2022 09:50:56 +0000 (18:50 +0900)
Fixes #24842.

src/resolve/resolved-dns-cache.c
src/resolve/resolved-dns-cache.h
src/resolve/resolved-dns-transaction.c
src/resolve/resolved-mdns.c

index 4c004c4a48c069dd995b900837ff4d0c6b02c8e0..2f97cf7730db71434e945ed05c03d1404aaebaff 100644 (file)
@@ -401,6 +401,7 @@ static void dns_cache_item_update_positive(
 
 static int dns_cache_put_positive(
                 DnsCache *c,
+                DnsProtocol protocol,
                 DnsResourceRecord *rr,
                 DnsAnswer *answer,
                 DnsPacket *full_packet,
@@ -461,6 +462,10 @@ static int dns_cache_put_positive(
                 return 0;
         }
 
+        /* Do not cache mDNS goodbye packet. */
+        if (protocol == DNS_PROTOCOL_MDNS && rr->ttl <= 1)
+                return 0;
+
         /* Otherwise, add the new RR */
         r = dns_cache_init(c);
         if (r < 0)
@@ -665,6 +670,7 @@ static bool rr_eligible(DnsResourceRecord *rr) {
 int dns_cache_put(
                 DnsCache *c,
                 DnsCacheMode cache_mode,
+                DnsProtocol protocol,
                 DnsResourceKey *key,
                 int rcode,
                 DnsAnswer *answer,
@@ -758,6 +764,7 @@ int dns_cache_put(
 
                 r = dns_cache_put_positive(
                                 c,
+                                protocol,
                                 item->rr,
                                 primary ? answer : NULL,
                                 primary ? full_packet : NULL,
index fb2e61a65bcab73140dd6f54d585b3ec20410454..42e744a9108477921698b6ed4c657373f83d0644 100644 (file)
@@ -26,6 +26,7 @@ void dns_cache_prune(DnsCache *c);
 int dns_cache_put(
                 DnsCache *c,
                 DnsCacheMode cache_mode,
+                DnsProtocol protocol,
                 DnsResourceKey *key,
                 int rcode,
                 DnsAnswer *answer,
index 0ef0782bbbf14fe138c0eec391eed5af5f2f19e5..4066991ecc8ccfe6641aa0ff02d8d67114908ad9 100644 (file)
@@ -817,6 +817,7 @@ static void dns_transaction_cache_answer(DnsTransaction *t) {
 
         dns_cache_put(&t->scope->cache,
                       t->scope->manager->enable_cache,
+                      t->scope->protocol,
                       dns_transaction_key(t),
                       t->answer_rcode,
                       t->answer,
index e1965c3833d80828771fa1bdecb85f2747ac0adb..8d51017b5d555012bb56379b8a3e46423c2c0d97 100644 (file)
@@ -433,7 +433,19 @@ static int on_mdns_packet(sd_event_source *s, int fd, uint32_t revents, void *us
                         }
                 }
 
-                dns_cache_put(&scope->cache, scope->manager->enable_cache, NULL, DNS_PACKET_RCODE(p), p->answer, NULL, false, _DNSSEC_RESULT_INVALID, UINT32_MAX, p->family, &p->sender);
+                dns_cache_put(
+                        &scope->cache,
+                        scope->manager->enable_cache,
+                        DNS_PROTOCOL_MDNS,
+                        NULL,
+                        DNS_PACKET_RCODE(p),
+                        p->answer,
+                        NULL,
+                        false,
+                        _DNSSEC_RESULT_INVALID,
+                        UINT32_MAX,
+                        p->family,
+                        &p->sender);
 
         } else if (dns_packet_validate_query(p) > 0)  {
                 log_debug("Got mDNS query packet for id %u", DNS_PACKET_ID(p));