From: Vishal Chillara Srinivas Date: Mon, 7 Apr 2025 09:23:57 +0000 (+0530) Subject: resolve: Refactor mDNS transaction max attempts X-Git-Tag: v258-rc1~33^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6ccc2b24f5f813d40da380d0e61a078b5db22f5d;p=thirdparty%2Fsystemd.git resolve: Refactor mDNS transaction max attempts Prepare for upcoming mDNS browse services. Prevent continuous queries from being attempted thrice. Co-authored-by: Vishwanath Chandapur --- diff --git a/src/resolve/resolved-def.h b/src/resolve/resolved-def.h index de06c8ad28e..d2e3d0fea60 100644 --- a/src/resolve/resolved-def.h +++ b/src/resolve/resolved-def.h @@ -76,6 +76,10 @@ #define SD_RESOLVED_RELAX_SINGLE_LABEL \ (UINT64_C(1) << 25) +/* Input: To differentiate between a probe and a continuous query. */ +#define SD_RESOLVED_QUERY_CONTINUOUS \ + (UINT64_C(1) << 26) + #define SD_RESOLVED_LLMNR (SD_RESOLVED_LLMNR_IPV4|SD_RESOLVED_LLMNR_IPV6) #define SD_RESOLVED_MDNS (SD_RESOLVED_MDNS_IPV4|SD_RESOLVED_MDNS_IPV6) #define SD_RESOLVED_PROTOCOLS_ALL (SD_RESOLVED_MDNS|SD_RESOLVED_LLMNR|SD_RESOLVED_DNS) diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index d6dbba546c6..2e183d15fe6 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -1708,7 +1708,7 @@ static int dns_transaction_prepare(DnsTransaction *t, usec_t ts) { return 0; } - if (t->n_attempts >= TRANSACTION_ATTEMPTS_MAX(t->scope->protocol)) { + if (t->n_attempts >= dns_transaction_attempts_max(t->scope->protocol, t->query_flags)) { DnsTransactionState result; if (t->scope->protocol == DNS_PROTOCOL_LLMNR) diff --git a/src/resolve/resolved-timeouts.h b/src/resolve/resolved-timeouts.h index 717bccca4a2..4028cf29191 100644 --- a/src/resolve/resolved-timeouts.h +++ b/src/resolve/resolved-timeouts.h @@ -19,12 +19,35 @@ /* Maximum attempts to send MDNS requests, see RFC 6762 Section 8.1 */ #define MDNS_TRANSACTION_ATTEMPTS_MAX 3 -#define TRANSACTION_ATTEMPTS_MAX(p) (\ - (p) == DNS_PROTOCOL_LLMNR ? \ - LLMNR_TRANSACTION_ATTEMPTS_MAX : \ - (p) == DNS_PROTOCOL_MDNS ? \ - MDNS_TRANSACTION_ATTEMPTS_MAX : \ - DNS_TRANSACTION_ATTEMPTS_MAX) +/* Maximum attempts to send an mDNS continuous query. + * + * RFC 6762 Section 5.2 does not specify a maximum number of attempts directly. + * However, it outlines two important guidelines: + * + * 1. The interval between the first two queries MUST be at least one second. + * 2. The intervals between successive queries MUST increase by at least a factor of two. + * + * To adhere to these timing requirements for continuous queries, + * the maximum number of attempts should be set to 1. + */ +#define MDNS_TRANSACTION_CONTINUOUS_QUERY_MAX 1U + +static inline unsigned dns_transaction_attempts_max(DnsProtocol p, uint64_t query_flags) { + switch (p) { + + case DNS_PROTOCOL_LLMNR: + return LLMNR_TRANSACTION_ATTEMPTS_MAX; + + case DNS_PROTOCOL_MDNS: + if (FLAGS_SET(query_flags, SD_RESOLVED_QUERY_CONTINUOUS)) + return MDNS_TRANSACTION_CONTINUOUS_QUERY_MAX; + else + return MDNS_TRANSACTION_ATTEMPTS_MAX; + + default: + return DNS_TRANSACTION_ATTEMPTS_MAX; + } +} /* After how much time to repeat classic DNS requests */ #define TRANSACTION_UDP_TIMEOUT_USEC (SD_RESOLVED_QUERY_TIMEOUT_USEC / DNS_TRANSACTION_ATTEMPTS_MAX)