]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolve: mDNS transaction max attempts fix
authorVishal Chillara Srinivas <vishal.chillarasrinivas@philips.com>
Fri, 17 Jun 2022 06:37:19 +0000 (12:07 +0530)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 22 Jun 2022 07:04:55 +0000 (16:04 +0900)
Maximum attempts to send mDNS requests is one except for probe requests, which should be attempted thrice.
Implemented fix to account for the difference between regular queries and probe requests, and prevent
even regular queries from being attempted thrice.
See RFC 6762 Section 8.1

src/resolve/resolved-dns-transaction.c
src/resolve/resolved-dns-transaction.h

index ba76725655bad9af1ab791d45d344930a46bb574..9368f970fc7ef2fb5eb3cb64352c6c86b7e31b66 100644 (file)
@@ -1621,7 +1621,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->probing)) {
                 DnsTransactionState result;
 
                 if (t->scope->protocol == DNS_PROTOCOL_LLMNR)
index 498cabb7e501b56e4b09bb0281e52c1e9374c860..f4cb5d3d8dfc0b07b52106fe0cda9221baf05559 100644 (file)
@@ -214,11 +214,31 @@ DnsTransactionSource dns_transaction_source_from_string(const char *s) _pure_;
 /* Maximum attempts to send LLMNR requests, see RFC 4795 Section 2.7 */
 #define LLMNR_TRANSACTION_ATTEMPTS_MAX 3
 
-/* 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 MDNS requests is one except for probe requests, see RFC 6762 Section 8.1
+ * RFC 6762 differentiates between normal (single-shot/continuous) and probe requests.
+ * It therefore makes sense to attempt each normal query only once with no retries.
+ * Otherwise we'd be sending out three attempts for even a normal query. */
+#define MDNS_TRANSACTION_ATTEMPTS_MAX 1
+
+#define MDNS_PROBE_TRANSACTION_ATTEMPTS_MAX 3
+
+static inline unsigned dns_transaction_attempts_max(DnsProtocol p, bool probing) {
+
+        switch (p) {
+
+        case DNS_PROTOCOL_LLMNR:
+                return LLMNR_TRANSACTION_ATTEMPTS_MAX;
+
+        case DNS_PROTOCOL_MDNS:
+                if (probing)
+                        return MDNS_PROBE_TRANSACTION_ATTEMPTS_MAX;
+                else
+                        return MDNS_TRANSACTION_ATTEMPTS_MAX;
+
+        case DNS_PROTOCOL_DNS:
+                return DNS_TRANSACTION_ATTEMPTS_MAX;
+
+        default:
+                return 0;
+        }
+}