resolve: do not cache mDNS goodbye packet

Fixes #24842.
This commit is contained in:
Yu Watanabe 2022-09-29 16:50:27 +09:00
parent 9449268fae
commit a78049fc0e
4 changed files with 22 additions and 1 deletions

View 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,

View 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,

View 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,

View 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));