Make DNS cache lifecycle management explicit
1. Add binder call to support creating cache by netid.
2. revise call flow in res_cache.cpp, not create cache in
resolv_set_nameservers_for_net().
3. revise Log method in ResolverController.cpp
Bug: 129453995
Test: built, flashed, booted
system/netd/tests/runtests.sh pass
Change-Id: I31ab521027a08bce3c721b2a36418faca85853c7
diff --git a/DnsResolverService.cpp b/DnsResolverService.cpp
index db7d23b..949e67a 100644
--- a/DnsResolverService.cpp
+++ b/DnsResolverService.cpp
@@ -278,15 +278,27 @@
return ::ndk::ScopedAStatus(AStatus_newOk());
}
-::ndk::ScopedAStatus DnsResolverService::clearResolverConfiguration(int netId) {
+::ndk::ScopedAStatus DnsResolverService::destroyNetworkCache(int netId) {
+ // Locking happens in res_cache.cpp functions.
ENFORCE_NETWORK_STACK_PERMISSIONS();
auto entry = gDnsResolverLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(netId);
- gDnsResolv->resolverCtrl.clearDnsServers(netId);
+ gDnsResolv->resolverCtrl.destroyNetworkCache(netId);
gResNetdCallbacks.log(entry.withAutomaticDuration().toString().c_str());
return ::ndk::ScopedAStatus(AStatus_newOk());
}
+::ndk::ScopedAStatus DnsResolverService::createNetworkCache(int netId) {
+ // Locking happens in res_cache.cpp functions.
+ ENFORCE_NETWORK_STACK_PERMISSIONS();
+ auto entry = gDnsResolverLog.newEntry().prettyFunction(__PRETTY_FUNCTION__).arg(netId);
+
+ int res = gDnsResolv->resolverCtrl.createNetworkCache(netId);
+
+ gResNetdCallbacks.log(entry.returns(res).withAutomaticDuration().toString().c_str());
+ return statusFromErrcode(res);
+}
+
} // namespace net
} // namespace android