Fix using EDNS0 when no private DNS validated
Do not add NET_CONTEXT_FLAG_USE_EDNS to android_net_context flag
if there is no private DNS server validated.
A server not supporting EDNS might respond with FORMERR or ignore
the request. In former case, we will remove OPT RR and retry again.
In later case, we will not retry, so the DNS query might timeout.
Also fix the bug which dns_responder responds to the query even
though it's been set unresponsive.
Bug: 120257033
Test: system/netd/tests/runtests.sh passed
Checked packets not containging OPT RR when using cleartext DNS
Change-Id: I8250a800ddade0ff810445bc912ea5799b99ec8c
diff --git a/resolv/res_send.cpp b/resolv/res_send.cpp
index 5d165f2..e3e62e9 100644
--- a/resolv/res_send.cpp
+++ b/resolv/res_send.cpp
@@ -1251,6 +1251,15 @@
// Sleep and iterate some small number of times checking for the
// arrival of resolved and validated server IP addresses, instead
// of returning an immediate error.
+ // This is needed because as soon as a network becomes the default network, apps will
+ // send DNS queries on that network. If no servers have yet validated, and we do not
+ // block those queries, they would immediately fail, causing application-visible errors.
+ // Note that this can happen even before the network validates, since an unvalidated
+ // network can become the default network if no validated networks are available.
+ //
+ // TODO: see if there is a better way to address this problem, such as buffering the
+ // queries in a queue or only blocking queries for the first few seconds after a default
+ // network change.
for (int i = 0; i < 42; i++) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (!gPrivateDnsConfiguration.getStatus(netId).validatedServers.empty()) {