Add the DNS query hook to net context
This change
- adds a query hook to android_net_context
- exposes relevant definitions to netd
- corrects a bug in query hooks' interaction with the cache
This change does not introduce any code to read the query hook
from the net context or make use of it.
Bug: 34953048
Test: Netd test suite passes
Change-Id: Ie091980e22ce9da07a3c4d387b371e544379d762
diff --git a/libc/dns/include/resolv_netid.h b/libc/dns/include/resolv_netid.h
index 37c1891..ae94768 100644
--- a/libc/dns/include/resolv_netid.h
+++ b/libc/dns/include/resolv_netid.h
@@ -34,6 +34,7 @@
*/
#include <sys/cdefs.h>
#include <netinet/in.h>
+#include "resolv_params.h"
#include <stdio.h>
/*
@@ -71,6 +72,7 @@
unsigned dns_netid;
unsigned dns_mark;
uid_t uid;
+ res_send_qhook qhook;
};
#define NET_CONTEXT_INVALID_UID ((uid_t)-1)
diff --git a/libc/dns/include/resolv_params.h b/libc/dns/include/resolv_params.h
index 49ae691..1b9d433 100644
--- a/libc/dns/include/resolv_params.h
+++ b/libc/dns/include/resolv_params.h
@@ -43,4 +43,15 @@
uint8_t max_samples; // max # samples taken into account for statistics
};
+typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
+ res_sendhookact;
+
+typedef res_sendhookact (*res_send_qhook)(struct sockaddr * const *,
+ const u_char **, int *,
+ u_char *, int, int *);
+
+typedef res_sendhookact (*res_send_rhook)(const struct sockaddr *,
+ const u_char *, int, u_char *,
+ int, int *);
+
#endif // _RESOLV_PARAMS_H
diff --git a/libc/dns/include/resolv_private.h b/libc/dns/include/resolv_private.h
index 54b9626..284270c 100644
--- a/libc/dns/include/resolv_private.h
+++ b/libc/dns/include/resolv_private.h
@@ -116,17 +116,6 @@
#endif
#endif
-typedef enum { res_goahead, res_nextns, res_modified, res_done, res_error }
- res_sendhookact;
-
-typedef res_sendhookact (*res_send_qhook)(struct sockaddr * const *,
- const u_char **, int *,
- u_char *, int, int *);
-
-typedef res_sendhookact (*res_send_rhook)(const struct sockaddr *,
- const u_char *, int, u_char *,
- int, int *);
-
struct res_sym {
int number; /* Identifying number, like T_MX */
const char * name; /* Its symbolic name, like "MX" */
diff --git a/libc/dns/resolv/res_send.c b/libc/dns/resolv/res_send.c
index f53da5f..71cc852 100644
--- a/libc/dns/resolv/res_send.c
+++ b/libc/dns/resolv/res_send.c
@@ -523,6 +523,10 @@
res_nclose(statp);
goto next_ns;
case res_done:
+ if (cache_status == RESOLV_CACHE_NOTFOUND) {
+ _resolv_cache_add(statp->netid, buf, buflen,
+ ans, resplen);
+ }
return (resplen);
case res_modified:
/* give the hook another try */