From: Yu Watanabe Date: Thu, 29 Sep 2022 07:50:27 +0000 (+0900) Subject: resolve: do not cache mDNS goodbye packet X-Git-Tag: v252-rc1~59 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a78049fc0e6a75446cb782b548ae9db8edf7a107;p=thirdparty%2Fsystemd.git resolve: do not cache mDNS goodbye packet Fixes #24842. --- diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c index 4c004c4a48c..2f97cf7730d 100644 --- a/src/resolve/resolved-dns-cache.c +++ b/src/resolve/resolved-dns-cache.c @@ -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, diff --git a/src/resolve/resolved-dns-cache.h b/src/resolve/resolved-dns-cache.h index fb2e61a65bc..42e744a9108 100644 --- a/src/resolve/resolved-dns-cache.h +++ b/src/resolve/resolved-dns-cache.h @@ -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, diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index 0ef0782bbbf..4066991ecc8 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -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, diff --git a/src/resolve/resolved-mdns.c b/src/resolve/resolved-mdns.c index e1965c3833d..8d51017b5d5 100644 --- a/src/resolve/resolved-mdns.c +++ b/src/resolve/resolved-mdns.c @@ -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));