Make use of the DNS query hook in the netcontext
This will allow netd to run queries over TLS:
https://android-review.googlesource.com/#/c/391513/
https://android-review.googlesource.com/#/c/380593/
Bug: 34953048
Test: Device tests pass. No issues during manual testing.
Change-Id: I8d613322307fc40cdba59b82599eda753697278f
diff --git a/libc/dns/include/resolv_private.h b/libc/dns/include/resolv_private.h
index 284270c..77b03bf 100644
--- a/libc/dns/include/resolv_private.h
+++ b/libc/dns/include/resolv_private.h
@@ -504,8 +504,8 @@
__LIBC_HIDDEN__ int res_getservers(res_state,
union res_sockaddr_union *, int);
-__LIBC_HIDDEN__ void res_setnetid(res_state, unsigned);
-__LIBC_HIDDEN__ void res_setmark(res_state, unsigned);
+struct android_net_context; /* forward */
+__LIBC_HIDDEN__ void res_setnetcontext(res_state, const struct android_net_context *);
// We use the OpenBSD __res_randomid...
u_int __res_randomid(void);
diff --git a/libc/dns/net/getaddrinfo.c b/libc/dns/net/getaddrinfo.c
index 4215963..418bf6d 100644
--- a/libc/dns/net/getaddrinfo.c
+++ b/libc/dns/net/getaddrinfo.c
@@ -1981,8 +1981,7 @@
* fully populate the thread private data here, but if we get down there
* and have a cache hit that would be wasted, so we do the rest there on miss
*/
- res_setnetid(res, netcontext->dns_netid);
- res_setmark(res, netcontext->dns_mark);
+ res_setnetcontext(res, netcontext);
if (res_searchN(name, &q, res) < 0) {
__res_put_state(res);
free(buf);
diff --git a/libc/dns/net/gethnamaddr.c b/libc/dns/net/gethnamaddr.c
index a22d718..4e416fd 100644
--- a/libc/dns/net/gethnamaddr.c
+++ b/libc/dns/net/gethnamaddr.c
@@ -827,8 +827,7 @@
FILE* proxy = android_open_proxy();
if (proxy == NULL) {
// Either we're not supposed to be using the proxy or the proxy is unavailable.
- res_setnetid(res, netcontext->dns_netid);
- res_setmark(res, netcontext->dns_mark);
+ res_setnetcontext(res, netcontext);
return gethostbyname_internal_real(name, af, res, hp, hbuf, hbuflen, errorp);
}
@@ -1296,8 +1295,7 @@
free(buf);
return NS_NOTFOUND;
}
- res_setnetid(res, netcontext->dns_netid);
- res_setmark(res, netcontext->dns_mark);
+ res_setnetcontext(res, netcontext);
n = res_nquery(res, qbuf, C_IN, T_PTR, buf->buf, (int)sizeof(buf->buf));
if (n < 0) {
free(buf);
diff --git a/libc/dns/resolv/res_init.c b/libc/dns/resolv/res_init.c
index b9fc131..302a62b 100644
--- a/libc/dns/resolv/res_init.c
+++ b/libc/dns/resolv/res_init.c
@@ -768,17 +768,12 @@
}
#ifdef ANDROID_CHANGES
-void res_setnetid(res_state statp, unsigned netid)
+void res_setnetcontext(res_state statp, const struct android_net_context *netcontext)
{
if (statp != NULL) {
- statp->netid = netid;
- }
-}
-
-void res_setmark(res_state statp, unsigned mark)
-{
- if (statp != NULL) {
- statp->_mark = mark;
+ statp->netid = netcontext->dns_netid;
+ statp->_mark = netcontext->dns_mark;
+ statp->qhook = netcontext->qhook;
}
}