Implementation of control flags in asynchronous DNS query API
Flags definitions are in multinetwork.h
Test: built, flashed, booted
system/netd/tests/runtests.sh passes
Change-Id: Iab1983b783d1470bc1cf23489abbef7a2d88e860
diff --git a/resolv/res_cache.cpp b/resolv/res_cache.cpp
index 60a60df..e7a3b9b 100644
--- a/resolv/res_cache.cpp
+++ b/resolv/res_cache.cpp
@@ -49,7 +49,6 @@
#include <android-base/logging.h>
-#include "netd_resolv/resolv.h"
#include "res_state_ext.h"
#include "resolv_cache.h"
#include "resolv_private.h"
@@ -1248,7 +1247,11 @@
}
/* notify the cache that the query failed */
-void _resolv_cache_query_failed(unsigned netid, const void* query, int querylen) {
+void _resolv_cache_query_failed(unsigned netid, const void* query, int querylen, uint32_t flags) {
+ // We should not notify with these flags.
+ if (flags & (ANDROID_RESOLV_NO_CACHE_STORE | ANDROID_RESOLV_NO_CACHE_LOOKUP)) {
+ return;
+ }
Entry key[1];
Cache* cache;
@@ -1463,7 +1466,11 @@
}
ResolvCacheStatus _resolv_cache_lookup(unsigned netid, const void* query, int querylen,
- void* answer, int answersize, int* answerlen) {
+ void* answer, int answersize, int* answerlen,
+ uint32_t flags) {
+ if (flags & ANDROID_RESOLV_NO_CACHE_LOOKUP) {
+ return RESOLV_CACHE_SKIP;
+ }
Entry key[1];
Entry** lookup;
Entry* e;
@@ -1498,6 +1505,11 @@
if (e == NULL) {
VLOG << "NOT IN CACHE";
+ // If it is no-cache-store mode, we won't wait for possible query.
+ if (flags & ANDROID_RESOLV_NO_CACHE_STORE) {
+ result = RESOLV_CACHE_SKIP;
+ goto Exit;
+ }
// calling thread will wait if an outstanding request is found
// that matching this query
if (!_cache_check_pending_request_locked(&cache, key, netid) || cache == NULL) {