resolve: Refactor mDNS transaction max attempts

Prepare for upcoming mDNS browse services.

Prevent continuous queries from being attempted thrice.

Co-authored-by: Vishwanath Chandapur <vishwanath.chandapur@philips.com>
This commit is contained in:
Vishal Chillara Srinivas
2025-07-14 14:50:03 +05:30
co-authored by Vishwanath Chandapur
parent f7d5177dd2
commit 6ccc2b24f5
3 changed files with 34 additions and 7 deletions
+4
View File
@@ -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)
+1 -1
View File
@@ -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)
+29 -6
View File
@@ -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)