blob: a2a48b2ab7bbff4ca288dded60547542dc612dd5 [file] [log] [blame]
Mike Yub601ff72018-11-01 20:07:00 +08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ken Chen5471dca2019-04-15 15:25:35 +080017#define LOG_TAG "resolv"
Mike Yub601ff72018-11-01 20:07:00 +080018
Mike Yu303b0df2018-12-24 17:05:02 +080019#include "PrivateDnsConfiguration.h"
20
Mike Yu3d5130d2020-12-21 17:57:18 +080021#include <android-base/format.h>
chenbruceaff85842019-05-31 15:46:42 +080022#include <android-base/logging.h>
Mike Yu04f1d482019-08-08 11:09:32 +080023#include <android-base/stringprintf.h>
Mike Yu04f1d482019-08-08 11:09:32 +080024#include <netdutils/ThreadUtil.h>
Mike Yub601ff72018-11-01 20:07:00 +080025#include <sys/socket.h>
26
Bernie Innocentiec4219b2019-01-30 11:16:36 +090027#include "DnsTlsTransport.h"
Mike Yu303b0df2018-12-24 17:05:02 +080028#include "ResolverEventReporter.h"
Bernie Innocentiec4219b2019-01-30 11:16:36 +090029#include "netd_resolv/resolv.h"
Mike Yub601ff72018-11-01 20:07:00 +080030#include "netdutils/BackoffSequence.h"
Mike Yu9c720102019-11-14 11:34:33 +080031#include "util.h"
Mike Yub601ff72018-11-01 20:07:00 +080032
paulhu0664f692020-12-14 16:48:26 +080033using aidl::android::net::resolv::aidl::IDnsResolverUnsolicitedEventListener;
34using aidl::android::net::resolv::aidl::PrivateDnsValidationEventParcel;
Mike Yucb902c92020-05-20 19:26:56 +080035using android::base::StringPrintf;
36using android::netdutils::setThreadName;
Mike Yua772c202019-09-23 17:47:21 +080037using std::chrono::milliseconds;
38
Mike Yub601ff72018-11-01 20:07:00 +080039namespace android {
Mike Yub601ff72018-11-01 20:07:00 +080040namespace net {
41
Mike Yub601ff72018-11-01 20:07:00 +080042bool parseServer(const char* server, sockaddr_storage* parsed) {
Nick Desaulnierscd6395a2019-10-11 09:15:24 -070043 addrinfo hints = {
44 .ai_flags = AI_NUMERICHOST | AI_NUMERICSERV,
45 .ai_family = AF_UNSPEC,
46 };
Mike Yub601ff72018-11-01 20:07:00 +080047 addrinfo* res;
48
49 int err = getaddrinfo(server, "853", &hints, &res);
50 if (err != 0) {
chenbruceaff85842019-05-31 15:46:42 +080051 LOG(WARNING) << "Failed to parse server address (" << server << "): " << gai_strerror(err);
Mike Yub601ff72018-11-01 20:07:00 +080052 return false;
53 }
54
55 memcpy(parsed, res->ai_addr, res->ai_addrlen);
56 freeaddrinfo(res);
57 return true;
58}
59
Mike Yub601ff72018-11-01 20:07:00 +080060int PrivateDnsConfiguration::set(int32_t netId, uint32_t mark,
61 const std::vector<std::string>& servers, const std::string& name,
Mike Yu40e67072019-10-09 21:14:09 +080062 const std::string& caCert) {
Mike Yu04f1d482019-08-08 11:09:32 +080063 LOG(DEBUG) << "PrivateDnsConfiguration::set(" << netId << ", 0x" << std::hex << mark << std::dec
Mike Yu40e67072019-10-09 21:14:09 +080064 << ", " << servers.size() << ", " << name << ")";
Mike Yub601ff72018-11-01 20:07:00 +080065
66 // Parse the list of servers that has been passed in
Mike Yufa985f72020-11-23 20:24:21 +080067 PrivateDnsTracker tmp;
Mike Yu40e67072019-10-09 21:14:09 +080068 for (const auto& s : servers) {
Mike Yub601ff72018-11-01 20:07:00 +080069 sockaddr_storage parsed;
Mike Yu40e67072019-10-09 21:14:09 +080070 if (!parseServer(s.c_str(), &parsed)) {
Mike Yub601ff72018-11-01 20:07:00 +080071 return -EINVAL;
72 }
73 DnsTlsServer server(parsed);
74 server.name = name;
waynema0e73c2e2019-07-31 15:04:08 +080075 server.certificate = caCert;
Mike Yue60ab412020-12-01 17:56:12 +080076 server.mark = mark;
Mike Yufa985f72020-11-23 20:24:21 +080077 tmp[ServerIdentity(server)] = server;
Mike Yub601ff72018-11-01 20:07:00 +080078 }
79
80 std::lock_guard guard(mPrivateDnsLock);
waynema0e73c2e2019-07-31 15:04:08 +080081 if (!name.empty()) {
Mike Yub601ff72018-11-01 20:07:00 +080082 mPrivateDnsModes[netId] = PrivateDnsMode::STRICT;
Mike Yufa985f72020-11-23 20:24:21 +080083 } else if (!tmp.empty()) {
Mike Yub601ff72018-11-01 20:07:00 +080084 mPrivateDnsModes[netId] = PrivateDnsMode::OPPORTUNISTIC;
85 } else {
86 mPrivateDnsModes[netId] = PrivateDnsMode::OFF;
87 mPrivateDnsTransports.erase(netId);
Mike Yuf7717f52020-11-24 17:31:12 +080088 // TODO: signal validation threads to stop.
Mike Yub601ff72018-11-01 20:07:00 +080089 return 0;
90 }
91
92 // Create the tracker if it was not present
Mike Yuf7717f52020-11-24 17:31:12 +080093 auto& tracker = mPrivateDnsTransports[netId];
Mike Yub601ff72018-11-01 20:07:00 +080094
Mike Yuf7717f52020-11-24 17:31:12 +080095 // Add the servers if not contained in tracker.
Mike Yufa985f72020-11-23 20:24:21 +080096 for (const auto& [identity, server] : tmp) {
Mike Yuf7717f52020-11-24 17:31:12 +080097 if (tracker.find(identity) == tracker.end()) {
98 tracker[identity] = server;
99 }
100 }
Mike Yu3334a5e2020-11-19 13:33:17 +0800101
Mike Yuf7717f52020-11-24 17:31:12 +0800102 for (auto& [identity, server] : tracker) {
103 const bool active = tmp.find(identity) != tmp.end();
104 server.setActive(active);
105
106 // For simplicity, deem the validation result of inactive servers as unreliable.
107 if (!server.active() && server.validationState() == Validation::success) {
108 updateServerState(identity, Validation::success_but_expired, netId);
109 }
110
111 if (needsValidation(server)) {
Mike Yufa985f72020-11-23 20:24:21 +0800112 updateServerState(identity, Validation::in_process, netId);
Mike Yu82ae84b2020-12-02 21:04:40 +0800113 startValidation(server, netId, false);
Mike Yub601ff72018-11-01 20:07:00 +0800114 }
115 }
Mike Yue655b1d2019-08-28 17:49:59 +0800116
Mike Yu8d9da4a2020-11-09 17:09:14 +0800117 return 0;
Mike Yub601ff72018-11-01 20:07:00 +0800118}
119
Mike Yu82ae84b2020-12-02 21:04:40 +0800120PrivateDnsStatus PrivateDnsConfiguration::getStatus(unsigned netId) const {
Mike Yub601ff72018-11-01 20:07:00 +0800121 PrivateDnsStatus status{PrivateDnsMode::OFF, {}};
Mike Yub601ff72018-11-01 20:07:00 +0800122 std::lock_guard guard(mPrivateDnsLock);
123
124 const auto mode = mPrivateDnsModes.find(netId);
125 if (mode == mPrivateDnsModes.end()) return status;
126 status.mode = mode->second;
127
128 const auto netPair = mPrivateDnsTransports.find(netId);
129 if (netPair != mPrivateDnsTransports.end()) {
Mike Yufa985f72020-11-23 20:24:21 +0800130 for (const auto& [_, server] : netPair->second) {
Mike Yuf7717f52020-11-24 17:31:12 +0800131 if (server.active()) {
132 status.serversMap.emplace(server, server.validationState());
133 }
Mike Yub601ff72018-11-01 20:07:00 +0800134 }
135 }
136
137 return status;
138}
139
Mike Yub601ff72018-11-01 20:07:00 +0800140void PrivateDnsConfiguration::clear(unsigned netId) {
chenbruceaff85842019-05-31 15:46:42 +0800141 LOG(DEBUG) << "PrivateDnsConfiguration::clear(" << netId << ")";
Mike Yub601ff72018-11-01 20:07:00 +0800142 std::lock_guard guard(mPrivateDnsLock);
143 mPrivateDnsModes.erase(netId);
144 mPrivateDnsTransports.erase(netId);
145}
146
Mike Yu82ae84b2020-12-02 21:04:40 +0800147base::Result<void> PrivateDnsConfiguration::requestValidation(unsigned netId,
148 const DnsTlsServer& server,
149 uint32_t mark) {
Mike Yue60ab412020-12-01 17:56:12 +0800150 std::lock_guard guard(mPrivateDnsLock);
Mike Yu82ae84b2020-12-02 21:04:40 +0800151
152 // Running revalidation requires to mark the server as in_process, which means the server
153 // won't be used until the validation passes. It's necessary and safe to run revalidation
154 // when in private DNS opportunistic mode, because there's a fallback mechanics even if
155 // all of the private DNS servers are in in_process state.
156 if (auto it = mPrivateDnsModes.find(netId); it == mPrivateDnsModes.end()) {
157 return Errorf("NetId not found in mPrivateDnsModes");
158 } else if (it->second != PrivateDnsMode::OPPORTUNISTIC) {
159 return Errorf("Private DNS setting is not opportunistic mode");
160 }
161
Mike Yue60ab412020-12-01 17:56:12 +0800162 auto netPair = mPrivateDnsTransports.find(netId);
163 if (netPair == mPrivateDnsTransports.end()) {
Mike Yu82ae84b2020-12-02 21:04:40 +0800164 return Errorf("NetId not found in mPrivateDnsTransports");
Mike Yue60ab412020-12-01 17:56:12 +0800165 }
166
167 auto& tracker = netPair->second;
168 const ServerIdentity identity = ServerIdentity(server);
169 auto it = tracker.find(identity);
170 if (it == tracker.end()) {
Mike Yu82ae84b2020-12-02 21:04:40 +0800171 return Errorf("Server was removed");
Mike Yue60ab412020-12-01 17:56:12 +0800172 }
173
174 const DnsTlsServer& target = it->second;
175
Mike Yu82ae84b2020-12-02 21:04:40 +0800176 if (!target.active()) return Errorf("Server is not active");
Mike Yue60ab412020-12-01 17:56:12 +0800177
Mike Yu82ae84b2020-12-02 21:04:40 +0800178 if (target.validationState() != Validation::success) {
179 return Errorf("Server validation state mismatched");
180 }
Mike Yue60ab412020-12-01 17:56:12 +0800181
182 // Don't run the validation if |mark| (from android_net_context.dns_mark) is different.
183 // This is to protect validation from running on unexpected marks.
184 // Validation should be associated with a mark gotten by system permission.
Mike Yu82ae84b2020-12-02 21:04:40 +0800185 if (target.mark != mark) return Errorf("Socket mark mismatched");
Mike Yue60ab412020-12-01 17:56:12 +0800186
187 updateServerState(identity, Validation::in_process, netId);
Mike Yu82ae84b2020-12-02 21:04:40 +0800188 startValidation(target, netId, true);
189 return {};
Mike Yue60ab412020-12-01 17:56:12 +0800190}
191
Mike Yu82ae84b2020-12-02 21:04:40 +0800192void PrivateDnsConfiguration::startValidation(const DnsTlsServer& server, unsigned netId,
193 bool isRevalidation) REQUIRES(mPrivateDnsLock) {
194 // Note that capturing |server|, |netId|, and |isRevalidation| in this lambda create copies.
195 std::thread validate_thread([this, server, netId, isRevalidation] {
Mike Yucb902c92020-05-20 19:26:56 +0800196 setThreadName(StringPrintf("TlsVerify_%u", netId).c_str());
Mike Yu04f1d482019-08-08 11:09:32 +0800197
Mike Yub601ff72018-11-01 20:07:00 +0800198 // cat /proc/sys/net/ipv4/tcp_syn_retries yields "6".
199 //
200 // Start with a 1 minute delay and backoff to once per hour.
201 //
202 // Assumptions:
203 // [1] Each TLS validation is ~10KB of certs+handshake+payload.
204 // [2] Network typically provision clients with <=4 nameservers.
205 // [3] Average month has 30 days.
206 //
207 // Each validation pass in a given hour is ~1.2MB of data. And 24
208 // such validation passes per day is about ~30MB per month, in the
209 // worst case. Otherwise, this will cost ~600 SYNs per month
210 // (6 SYNs per ip, 4 ips per validation pass, 24 passes per day).
Bernie Innocenti23c6e2a2019-05-16 15:18:35 +0900211 auto backoff = netdutils::BackoffSequence<>::Builder()
Mike Yub601ff72018-11-01 20:07:00 +0800212 .withInitialRetransmissionTime(std::chrono::seconds(60))
213 .withMaximumRetransmissionTime(std::chrono::seconds(3600))
214 .build();
215
216 while (true) {
217 // ::validate() is a blocking call that performs network operations.
218 // It can take milliseconds to minutes, up to the SYN retry limit.
Mike Yu74770542020-12-15 14:25:21 +0800219 LOG(WARNING) << "Validating DnsTlsServer " << server.toIpString() << " with mark 0x"
220 << std::hex << server.mark;
221 const bool success = DnsTlsTransport::validate(server, server.mark);
222 LOG(WARNING) << "validateDnsTlsServer returned " << success << " for "
223 << server.toIpString();
Mike Yub601ff72018-11-01 20:07:00 +0800224
Mike Yu82ae84b2020-12-02 21:04:40 +0800225 const bool needs_reeval =
226 this->recordPrivateDnsValidation(server, netId, success, isRevalidation);
227
Mike Yub601ff72018-11-01 20:07:00 +0800228 if (!needs_reeval) {
229 break;
230 }
231
232 if (backoff.hasNextTimeout()) {
Mike Yuf7717f52020-11-24 17:31:12 +0800233 // TODO: make the thread able to receive signals to shutdown early.
Mike Yub601ff72018-11-01 20:07:00 +0800234 std::this_thread::sleep_for(backoff.getNextTimeout());
235 } else {
236 break;
237 }
238 }
239 });
240 validate_thread.detach();
241}
242
paulhu0664f692020-12-14 16:48:26 +0800243void PrivateDnsConfiguration::sendPrivateDnsValidationEvent(const DnsTlsServer& server,
244 unsigned netId, bool success) {
245 LOG(DEBUG) << "Sending validation " << (success ? "success" : "failure") << " event on netId "
246 << netId << " for " << server.toIpString() << " with hostname {" << server.name
247 << "}";
248 // Send a validation event to NetdEventListenerService.
249 const auto& listeners = ResolverEventReporter::getInstance().getListeners();
250 if (listeners.empty()) {
251 LOG(ERROR)
252 << "Validation event not sent since no INetdEventListener receiver is available.";
253 }
254 for (const auto& it : listeners) {
255 it->onPrivateDnsValidationEvent(netId, server.toIpString(), server.name, success);
256 }
257
258 // Send a validation event to unsolicited event listeners.
259 const auto& unsolEventListeners = ResolverEventReporter::getInstance().getUnsolEventListeners();
260 const PrivateDnsValidationEventParcel validationEvent = {
261 .netId = static_cast<int32_t>(netId),
262 .ipAddress = server.toIpString(),
263 .hostname = server.name,
264 .validation = success ? IDnsResolverUnsolicitedEventListener::VALIDATION_RESULT_SUCCESS
265 : IDnsResolverUnsolicitedEventListener::VALIDATION_RESULT_FAILURE,
266 };
267 for (const auto& it : unsolEventListeners) {
268 it->onPrivateDnsValidationEvent(validationEvent);
269 }
270}
271
Mike Yub601ff72018-11-01 20:07:00 +0800272bool PrivateDnsConfiguration::recordPrivateDnsValidation(const DnsTlsServer& server, unsigned netId,
Mike Yu82ae84b2020-12-02 21:04:40 +0800273 bool success, bool isRevalidation) {
Mike Yub601ff72018-11-01 20:07:00 +0800274 constexpr bool NEEDS_REEVALUATION = true;
275 constexpr bool DONT_REEVALUATE = false;
Mike Yufa985f72020-11-23 20:24:21 +0800276 const ServerIdentity identity = ServerIdentity(server);
Mike Yub601ff72018-11-01 20:07:00 +0800277
278 std::lock_guard guard(mPrivateDnsLock);
279
280 auto netPair = mPrivateDnsTransports.find(netId);
281 if (netPair == mPrivateDnsTransports.end()) {
chenbruceaff85842019-05-31 15:46:42 +0800282 LOG(WARNING) << "netId " << netId << " was erased during private DNS validation";
Mike Yu453b5e42021-02-19 20:03:07 +0800283 notifyValidationStateUpdate(identity.sockaddr, Validation::fail, netId);
Mike Yub601ff72018-11-01 20:07:00 +0800284 return DONT_REEVALUATE;
285 }
286
287 const auto mode = mPrivateDnsModes.find(netId);
288 if (mode == mPrivateDnsModes.end()) {
chenbruceaff85842019-05-31 15:46:42 +0800289 LOG(WARNING) << "netId " << netId << " has no private DNS validation mode";
Mike Yu453b5e42021-02-19 20:03:07 +0800290 notifyValidationStateUpdate(identity.sockaddr, Validation::fail, netId);
Mike Yub601ff72018-11-01 20:07:00 +0800291 return DONT_REEVALUATE;
292 }
Mike Yub601ff72018-11-01 20:07:00 +0800293
Mike Yu82ae84b2020-12-02 21:04:40 +0800294 bool reevaluationStatus = NEEDS_REEVALUATION;
295 if (success) {
296 reevaluationStatus = DONT_REEVALUATE;
297 } else if (mode->second == PrivateDnsMode::OFF) {
298 reevaluationStatus = DONT_REEVALUATE;
299 } else if (mode->second == PrivateDnsMode::OPPORTUNISTIC && !isRevalidation) {
300 reevaluationStatus = DONT_REEVALUATE;
301 }
Mike Yub601ff72018-11-01 20:07:00 +0800302
303 auto& tracker = netPair->second;
Mike Yufa985f72020-11-23 20:24:21 +0800304 auto serverPair = tracker.find(identity);
Mike Yub601ff72018-11-01 20:07:00 +0800305 if (serverPair == tracker.end()) {
Mike Yu4499ee32020-11-24 20:05:18 +0800306 LOG(WARNING) << "Server " << server.toIpString()
chenbruceaff85842019-05-31 15:46:42 +0800307 << " was removed during private DNS validation";
Mike Yub601ff72018-11-01 20:07:00 +0800308 success = false;
309 reevaluationStatus = DONT_REEVALUATE;
Mike Yufa985f72020-11-23 20:24:21 +0800310 } else if (!(serverPair->second == server)) {
Mike Yu4499ee32020-11-24 20:05:18 +0800311 LOG(WARNING) << "Server " << server.toIpString()
chenbruceaff85842019-05-31 15:46:42 +0800312 << " was changed during private DNS validation";
Mike Yub601ff72018-11-01 20:07:00 +0800313 success = false;
314 reevaluationStatus = DONT_REEVALUATE;
Mike Yuf7717f52020-11-24 17:31:12 +0800315 } else if (!serverPair->second.active()) {
Mike Yu4499ee32020-11-24 20:05:18 +0800316 LOG(WARNING) << "Server " << server.toIpString() << " was removed from the configuration";
Mike Yuf7717f52020-11-24 17:31:12 +0800317 success = false;
318 reevaluationStatus = DONT_REEVALUATE;
Mike Yub601ff72018-11-01 20:07:00 +0800319 }
320
paulhu0664f692020-12-14 16:48:26 +0800321 // Send private dns validation result to listeners.
322 sendPrivateDnsValidationEvent(server, netId, success);
Mike Yub601ff72018-11-01 20:07:00 +0800323
324 if (success) {
Mike Yufa985f72020-11-23 20:24:21 +0800325 updateServerState(identity, Validation::success, netId);
Mike Yub601ff72018-11-01 20:07:00 +0800326 } else {
327 // Validation failure is expected if a user is on a captive portal.
328 // TODO: Trigger a second validation attempt after captive portal login
329 // succeeds.
Mike Yu3334a5e2020-11-19 13:33:17 +0800330 const auto result = (reevaluationStatus == NEEDS_REEVALUATION) ? Validation::in_process
331 : Validation::fail;
Mike Yufa985f72020-11-23 20:24:21 +0800332 updateServerState(identity, result, netId);
Mike Yub601ff72018-11-01 20:07:00 +0800333 }
Mike Yu04f1d482019-08-08 11:09:32 +0800334 LOG(WARNING) << "Validation " << (success ? "success" : "failed");
Mike Yub601ff72018-11-01 20:07:00 +0800335
336 return reevaluationStatus;
337}
338
Mike Yufa985f72020-11-23 20:24:21 +0800339void PrivateDnsConfiguration::updateServerState(const ServerIdentity& identity, Validation state,
Mike Yu3334a5e2020-11-19 13:33:17 +0800340 uint32_t netId) {
341 auto netPair = mPrivateDnsTransports.find(netId);
Mike Yufa985f72020-11-23 20:24:21 +0800342 if (netPair == mPrivateDnsTransports.end()) {
Mike Yu453b5e42021-02-19 20:03:07 +0800343 notifyValidationStateUpdate(identity.sockaddr, Validation::fail, netId);
Mike Yufa985f72020-11-23 20:24:21 +0800344 return;
Mike Yu3334a5e2020-11-19 13:33:17 +0800345 }
346
Mike Yufa985f72020-11-23 20:24:21 +0800347 auto& tracker = netPair->second;
348 if (tracker.find(identity) == tracker.end()) {
Mike Yu453b5e42021-02-19 20:03:07 +0800349 notifyValidationStateUpdate(identity.sockaddr, Validation::fail, netId);
Mike Yufa985f72020-11-23 20:24:21 +0800350 return;
351 }
352
353 tracker[identity].setValidationState(state);
Mike Yu453b5e42021-02-19 20:03:07 +0800354 notifyValidationStateUpdate(identity.sockaddr, state, netId);
Mike Yu3d5130d2020-12-21 17:57:18 +0800355
356 RecordEntry record(netId, identity, state);
357 mPrivateDnsLog.push(std::move(record));
Mike Yu3334a5e2020-11-19 13:33:17 +0800358}
359
Mike Yuf7717f52020-11-24 17:31:12 +0800360bool PrivateDnsConfiguration::needsValidation(const DnsTlsServer& server) {
361 // The server is not expected to be used on the network.
362 if (!server.active()) return false;
Zhang Wei-e7976c1d68adb2019-08-23 23:13:22 -0500363
Mike Yuf7717f52020-11-24 17:31:12 +0800364 // The server is newly added.
365 if (server.validationState() == Validation::unknown_server) return true;
Zhang Wei-e7976c1d68adb2019-08-23 23:13:22 -0500366
Mike Yuf7717f52020-11-24 17:31:12 +0800367 // The server has failed at least one validation attempt. Give it another try.
368 if (server.validationState() == Validation::fail) return true;
369
370 // The previous validation result might be unreliable.
371 if (server.validationState() == Validation::success_but_expired) return true;
372
373 return false;
Mike Yub601ff72018-11-01 20:07:00 +0800374}
375
Mike Yua6853e82020-12-11 19:47:06 +0800376void PrivateDnsConfiguration::setObserver(PrivateDnsValidationObserver* observer) {
Mike Yu0ee1dc92020-11-09 14:56:54 +0800377 std::lock_guard guard(mPrivateDnsLock);
378 mObserver = observer;
379}
380
Mike Yu453b5e42021-02-19 20:03:07 +0800381void PrivateDnsConfiguration::notifyValidationStateUpdate(const netdutils::IPSockAddr& sockaddr,
Mike Yu74770542020-12-15 14:25:21 +0800382 Validation validation,
383 uint32_t netId) const {
Mike Yu0ee1dc92020-11-09 14:56:54 +0800384 if (mObserver) {
Mike Yu453b5e42021-02-19 20:03:07 +0800385 mObserver->onValidationStateUpdate(sockaddr.ip().toString(), validation, netId);
Mike Yu0ee1dc92020-11-09 14:56:54 +0800386 }
387}
388
Mike Yu3d5130d2020-12-21 17:57:18 +0800389void PrivateDnsConfiguration::dump(netdutils::DumpWriter& dw) const {
390 dw.println("PrivateDnsLog:");
391 netdutils::ScopedIndent indentStats(dw);
392
393 for (const auto& record : mPrivateDnsLog.copy()) {
Mike Yu453b5e42021-02-19 20:03:07 +0800394 dw.println(fmt::format(
395 "{} - netId={} PrivateDns={{{}/{}}} state={}", timestampToString(record.timestamp),
396 record.netId, record.serverIdentity.sockaddr.toString(),
397 record.serverIdentity.provider, validationStatusToString(record.state)));
Mike Yu3d5130d2020-12-21 17:57:18 +0800398 }
399 dw.blankline();
400}
401
Mike Yub601ff72018-11-01 20:07:00 +0800402} // namespace net
403} // namespace android