resolved: add mDNS initial jitter

The logic is to kick off mDNS packets in a delayed way is mostly identical
to what LLMNR needs, except that the constants are different.
This commit is contained in:
Daniel Mack 2015-08-25 14:08:29 +02:00
parent b4f1862df2
commit ea12bcc789
2 changed files with 24 additions and 6 deletions

View File

@ -751,8 +751,10 @@ int dns_transaction_go(DnsTransaction *t) {
}
}
if (t->scope->protocol == DNS_PROTOCOL_LLMNR && !t->initial_jitter) {
usec_t jitter;
if (!t->initial_jitter &&
(t->scope->protocol == DNS_PROTOCOL_LLMNR ||
t->scope->protocol == DNS_PROTOCOL_MDNS)) {
usec_t jitter, accuracy;
/* RFC 4795 Section 2.7 suggests all queries should be
* delayed by a random time from 0 to JITTER_INTERVAL. */
@ -760,14 +762,26 @@ int dns_transaction_go(DnsTransaction *t) {
t->initial_jitter = true;
random_bytes(&jitter, sizeof(jitter));
jitter %= LLMNR_JITTER_INTERVAL_USEC;
switch (t->scope->protocol) {
case DNS_PROTOCOL_LLMNR:
jitter %= LLMNR_JITTER_INTERVAL_USEC;
accuracy = LLMNR_JITTER_INTERVAL_USEC;
break;
case DNS_PROTOCOL_MDNS:
jitter %= MDNS_JITTER_RANGE_USEC;
jitter += MDNS_JITTER_MIN_USEC;
accuracy = MDNS_JITTER_RANGE_USEC;
break;
default:
assert_not_reached("bad protocol");
}
r = sd_event_add_time(
t->scope->manager->event,
&t->timeout_event_source,
clock_boottime_or_monotonic(),
ts + jitter,
LLMNR_JITTER_INTERVAL_USEC,
ts + jitter, accuracy,
on_transaction_timeout, t);
if (r < 0)
return r;
@ -775,7 +789,7 @@ int dns_transaction_go(DnsTransaction *t) {
t->n_attempts = 0;
t->state = DNS_TRANSACTION_PENDING;
log_debug("Delaying LLMNR transaction for " USEC_FMT "us.", jitter);
log_debug("Delaying %s transaction for " USEC_FMT "us.", dns_protocol_to_string(t->scope->protocol), jitter);
return 0;
}

View File

@ -119,6 +119,10 @@ DnsTransactionSource dns_transaction_source_from_string(const char *s) _pure_;
/* LLMNR Jitter interval, see RFC 4795 Section 7 */
#define LLMNR_JITTER_INTERVAL_USEC (100 * USEC_PER_MSEC)
/* mDNS Jitter interval, see RFC 6762 Section 5.2 */
#define MDNS_JITTER_MIN_USEC (20 * USEC_PER_MSEC)
#define MDNS_JITTER_RANGE_USEC (100 * USEC_PER_MSEC)
/* Maximum attempts to send DNS requests, across all DNS servers */
#define DNS_TRANSACTION_ATTEMPTS_MAX 16