IN_SET(t->scope->protocol, DNS_PROTOCOL_LLMNR, 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. */
+ /* RFC 4795 Section 2.7 suggests all queries should be delayed by a random time from 0 to
+ * JITTER_INTERVAL. */
t->initial_jitter_scheduled = true;
- random_bytes(&jitter, sizeof(jitter));
-
switch (t->scope->protocol) {
case DNS_PROTOCOL_LLMNR:
- jitter %= LLMNR_JITTER_INTERVAL_USEC;
+ jitter = random_u64_range(LLMNR_JITTER_INTERVAL_USEC);
accuracy = LLMNR_JITTER_INTERVAL_USEC;
break;
case DNS_PROTOCOL_MDNS:
- jitter %= MDNS_JITTER_RANGE_USEC;
- jitter += MDNS_JITTER_MIN_USEC;
+ jitter = usec_add(random_u64_range(MDNS_JITTER_RANGE_USEC), MDNS_JITTER_MIN_USEC);
accuracy = MDNS_JITTER_RANGE_USEC;
break;
default:
assert_not_reached("bad protocol");
}
- r = sd_event_add_time(
+ assert(!t->timeout_event_source);
+
+ r = sd_event_add_time_relative(
t->scope->manager->event,
&t->timeout_event_source,
clock_boottime_or_monotonic(),
- ts + jitter, accuracy,
+ jitter, accuracy,
on_transaction_timeout, t);
if (r < 0)
return r;
t->next_attempt_after = ts;
t->state = DNS_TRANSACTION_PENDING;
- log_debug("Delaying %s transaction for " USEC_FMT "us.", dns_protocol_to_string(t->scope->protocol), jitter);
+ log_debug("Delaying %s transaction %" PRIu16 " for " USEC_FMT "us.",
+ dns_protocol_to_string(t->scope->protocol),
+ t->id,
+ jitter);
return 1;
}
* question. If so, let's see if there are any NSEC/NSEC3 RRs
* included. If not, the answer is unsigned. */
- r = dns_answer_contains_nsec_or_nsec3(t->answer);
- if (r < 0)
- return r;
- if (r > 0)
- return false;
-
- return true;
+ return !dns_answer_contains_nsec_or_nsec3(t->answer);
}
static int dns_transaction_is_primary_response(DnsTransaction *t, DnsResourceRecord *rr) {
}
static const char* const dns_transaction_state_table[_DNS_TRANSACTION_STATE_MAX] = {
- [DNS_TRANSACTION_NULL] = "null",
- [DNS_TRANSACTION_PENDING] = "pending",
- [DNS_TRANSACTION_VALIDATING] = "validating",
- [DNS_TRANSACTION_RCODE_FAILURE] = "rcode-failure",
- [DNS_TRANSACTION_SUCCESS] = "success",
- [DNS_TRANSACTION_NO_SERVERS] = "no-servers",
- [DNS_TRANSACTION_TIMEOUT] = "timeout",
+ [DNS_TRANSACTION_NULL] = "null",
+ [DNS_TRANSACTION_PENDING] = "pending",
+ [DNS_TRANSACTION_VALIDATING] = "validating",
+ [DNS_TRANSACTION_RCODE_FAILURE] = "rcode-failure",
+ [DNS_TRANSACTION_SUCCESS] = "success",
+ [DNS_TRANSACTION_NO_SERVERS] = "no-servers",
+ [DNS_TRANSACTION_TIMEOUT] = "timeout",
[DNS_TRANSACTION_ATTEMPTS_MAX_REACHED] = "attempts-max-reached",
- [DNS_TRANSACTION_INVALID_REPLY] = "invalid-reply",
- [DNS_TRANSACTION_ERRNO] = "errno",
- [DNS_TRANSACTION_ABORTED] = "aborted",
- [DNS_TRANSACTION_DNSSEC_FAILED] = "dnssec-failed",
- [DNS_TRANSACTION_NO_TRUST_ANCHOR] = "no-trust-anchor",
- [DNS_TRANSACTION_RR_TYPE_UNSUPPORTED] = "rr-type-unsupported",
- [DNS_TRANSACTION_NETWORK_DOWN] = "network-down",
- [DNS_TRANSACTION_NOT_FOUND] = "not-found",
- [DNS_TRANSACTION_NO_SOURCE] = "no-source",
- [DNS_TRANSACTION_STUB_LOOP] = "stub-loop",
+ [DNS_TRANSACTION_INVALID_REPLY] = "invalid-reply",
+ [DNS_TRANSACTION_ERRNO] = "errno",
+ [DNS_TRANSACTION_ABORTED] = "aborted",
+ [DNS_TRANSACTION_DNSSEC_FAILED] = "dnssec-failed",
+ [DNS_TRANSACTION_NO_TRUST_ANCHOR] = "no-trust-anchor",
+ [DNS_TRANSACTION_RR_TYPE_UNSUPPORTED] = "rr-type-unsupported",
+ [DNS_TRANSACTION_NETWORK_DOWN] = "network-down",
+ [DNS_TRANSACTION_NOT_FOUND] = "not-found",
+ [DNS_TRANSACTION_NO_SOURCE] = "no-source",
+ [DNS_TRANSACTION_STUB_LOOP] = "stub-loop",
};
DEFINE_STRING_TABLE_LOOKUP(dns_transaction_state, DnsTransactionState);
static const char* const dns_transaction_source_table[_DNS_TRANSACTION_SOURCE_MAX] = {
- [DNS_TRANSACTION_NETWORK] = "network",
- [DNS_TRANSACTION_CACHE] = "cache",
- [DNS_TRANSACTION_ZONE] = "zone",
+ [DNS_TRANSACTION_NETWORK] = "network",
+ [DNS_TRANSACTION_CACHE] = "cache",
+ [DNS_TRANSACTION_ZONE] = "zone",
[DNS_TRANSACTION_TRUST_ANCHOR] = "trust-anchor",
};
DEFINE_STRING_TABLE_LOOKUP(dns_transaction_source, DnsTransactionSource);