]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolve: Refactor mDNS transaction max attempts
authorVishal Chillara Srinivas <vishal.chillarasrinivas@philips.com>
Mon, 7 Apr 2025 09:23:57 +0000 (14:53 +0530)
committerVishal Chillara Srinivas <vishal.chillarasrinivas@philips.com>
Mon, 14 Jul 2025 09:20:03 +0000 (14:50 +0530)
Prepare for upcoming mDNS browse services.

Prevent continuous queries from being attempted thrice.

Co-authored-by: Vishwanath Chandapur <vishwanath.chandapur@philips.com>
src/resolve/resolved-def.h
src/resolve/resolved-dns-transaction.c
src/resolve/resolved-timeouts.h

index de06c8ad28e0b51ae16ae62ca2617f164b1a5be8..d2e3d0fea60559d1ae8e0419260f45d1deb3a74c 100644 (file)
 #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)
index d6dbba546c637fbb9f0245ebf2af7540e8285009..2e183d15fe6d33ccf6aaed37569612df1bca7648 100644 (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)
index 717bccca4a29037295118b857c0bbd40f850812d..4028cf291917347d1c53a875f3e61494ad1a836f 100644 (file)
 /* 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)