Query libnetd_client for the appropriate netId for host resolution.
If libnetd_client can't be found, operate as before and use the default netId
potentially overriden by a more specific netId passed in to
android_get*fornet().
Change-Id: I42ef3293172651870fb46d2de22464c4f03e8e0b
diff --git a/libc/bionic/NetdClient.cpp b/libc/bionic/NetdClient.cpp
index 72d90b7..23f7c43 100644
--- a/libc/bionic/NetdClient.cpp
+++ b/libc/bionic/NetdClient.cpp
@@ -43,6 +43,8 @@
netdClientInitFunction(netdClientHandle, "netdClientInitAccept", &__netdClientDispatch.accept);
netdClientInitFunction(netdClientHandle, "netdClientInitConnect",
&__netdClientDispatch.connect);
+ netdClientInitFunction(netdClientHandle, "netdClientInitNetIdForResolv",
+ &__netdClientDispatch.netIdForResolv);
}
static pthread_once_t netdClientInitOnce = PTHREAD_ONCE_INIT;
diff --git a/libc/bionic/NetdClientDispatch.cpp b/libc/bionic/NetdClientDispatch.cpp
index adfe16d..62130a1 100644
--- a/libc/bionic/NetdClientDispatch.cpp
+++ b/libc/bionic/NetdClientDispatch.cpp
@@ -25,7 +25,12 @@
extern "C" __socketcall int __accept(int, sockaddr*, socklen_t*);
extern "C" __socketcall int __connect(int, const sockaddr*, socklen_t);
+static unsigned fallBackNetIdForResolv(unsigned netId) {
+ return netId;
+}
+
NetdClientDispatch __netdClientDispatch __attribute__((aligned(32))) = {
__accept,
__connect,
+ fallBackNetIdForResolv,
};
diff --git a/libc/dns/gethnamaddr.c b/libc/dns/gethnamaddr.c
index 4da99b2..41a876a 100644
--- a/libc/dns/gethnamaddr.c
+++ b/libc/dns/gethnamaddr.c
@@ -60,6 +60,7 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
+#include "NetdClient.h"
#include "resolv_netid.h"
#include "resolv_private.h"
#include "resolv_cache.h"
@@ -760,6 +761,8 @@
proxy = android_open_proxy();
if (proxy == NULL) goto exit;
+ netid = __netdClientDispatch.netIdForResolv(netid);
+
/* This is writing to system/netd/DnsProxyListener.cpp and changes
* here need to be matched there */
if (fprintf(proxy, "gethostbyname %u %s %d",
@@ -796,6 +799,8 @@
const char * addrStr = inet_ntop(af, addr, buf, sizeof(buf));
if (addrStr == NULL) goto exit;
+ netid = __netdClientDispatch.netIdForResolv(netid);
+
if (fprintf(proxy, "gethostbyaddr %s %d %d %u",
addrStr, len, af, netid) < 0) {
goto exit;
diff --git a/libc/dns/net/getaddrinfo.c b/libc/dns/net/getaddrinfo.c
index 4c120d9..bdf3ba7 100644
--- a/libc/dns/net/getaddrinfo.c
+++ b/libc/dns/net/getaddrinfo.c
@@ -92,6 +92,7 @@
#include <ctype.h>
#include <errno.h>
#include <netdb.h>
+#include "NetdClient.h"
#include "resolv_cache.h"
#include "resolv_netid.h"
#include "resolv_private.h"
@@ -449,6 +450,8 @@
return EAI_NODATA;
}
+ netid = __netdClientDispatch.netIdForResolv(netid);
+
// Send the request.
proxy = fdopen(sock, "r+");
if (fprintf(proxy, "getaddrinfo %s %s %d %d %d %d %u",
diff --git a/libc/private/NetdClient.h b/libc/private/NetdClient.h
index b2ce7a6..664c54f 100644
--- a/libc/private/NetdClient.h
+++ b/libc/private/NetdClient.h
@@ -17,13 +17,19 @@
#ifndef PRIVATE_NETD_CLIENT_H
#define PRIVATE_NETD_CLIENT_H
+#include <sys/cdefs.h>
#include <sys/socket.h>
+__BEGIN_DECLS
+
struct NetdClientDispatch {
- int (*accept)(int, sockaddr*, socklen_t*);
- int (*connect)(int, const sockaddr*, socklen_t);
+ int (*accept)(int, struct sockaddr*, socklen_t*);
+ int (*connect)(int, const struct sockaddr*, socklen_t);
+ unsigned (*netIdForResolv)(unsigned);
};
-extern NetdClientDispatch __netdClientDispatch;
+extern struct NetdClientDispatch __netdClientDispatch;
+
+__END_DECLS
#endif // PRIVATE_NETD_CLIENT_H