summaryrefslogtreecommitdiff
path: root/src/resolve/resolved-dns-transaction.h
diff options
context:
space:
mode:
authorVishal Chillara Srinivas <vishal.chillarasrinivas@philips.com>2022-06-17 12:07:19 +0530
committerYu Watanabe <watanabe.yu+github@gmail.com>2022-06-22 16:04:55 +0900
commit127b26f3d8b589907ed75a34d34ab330995778f9 (patch)
tree58e6f94de63c7af1eb3af8fd87d6c27d2a4bc9ab /src/resolve/resolved-dns-transaction.h
parent919ea64f69f710840c1bc93f0f7cb7c51aae45d0 (diff)
downloadsystemd-127b26f3d8b589907ed75a34d34ab330995778f9.tar.gz
resolve: mDNS transaction max attempts fix
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
Diffstat (limited to 'src/resolve/resolved-dns-transaction.h')
-rw-r--r--src/resolve/resolved-dns-transaction.h36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/resolve/resolved-dns-transaction.h b/src/resolve/resolved-dns-transaction.h
index 498cabb7e5..f4cb5d3d8d 100644
--- a/src/resolve/resolved-dns-transaction.h
+++ b/src/resolve/resolved-dns-transaction.h
@@ -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;
+ }
+}