Replace android_open_proxy with dns_open_proxy
remove android_open_proxy and use dns_open_proxy instead of it. dns_open_proxy is in libnetd_client and it does the same thing as android_open_proxy except return value. It returns fd directly now. Test: build, dns works fine Change-Id: I984743fb50b23eeb9a7d24e9fc347832acfe2afe
This commit is contained in:
parent
c89a3971e9
commit
e3ed892faa
6 changed files with 11 additions and 36 deletions
|
@ -58,6 +58,8 @@ static void netdClientInitImpl() {
|
|||
netdClientInitFunction(netdClientHandle, "netdClientInitNetIdForResolv",
|
||||
&__netdClientDispatch.netIdForResolv);
|
||||
netdClientInitFunction(netdClientHandle, "netdClientInitSocket", &__netdClientDispatch.socket);
|
||||
netdClientInitFunction(netdClientHandle, "netdClientInitDnsOpenProxy",
|
||||
&__netdClientDispatch.dnsOpenProxy);
|
||||
}
|
||||
|
||||
static pthread_once_t netdClientInitOnce = PTHREAD_ONCE_INIT;
|
||||
|
|
|
@ -30,6 +30,10 @@ static unsigned fallBackNetIdForResolv(unsigned netId) {
|
|||
return netId;
|
||||
}
|
||||
|
||||
static int fallBackDnsOpenProxy() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// This structure is modified only at startup (when libc.so is loaded) and never
|
||||
// afterwards, so it's okay that it's read later at runtime without a lock.
|
||||
__LIBC_HIDDEN__ NetdClientDispatch __netdClientDispatch __attribute__((aligned(32))) = {
|
||||
|
@ -37,4 +41,5 @@ __LIBC_HIDDEN__ NetdClientDispatch __netdClientDispatch __attribute__((aligned(3
|
|||
__connect,
|
||||
__socket,
|
||||
fallBackNetIdForResolv,
|
||||
fallBackDnsOpenProxy,
|
||||
};
|
||||
|
|
|
@ -107,7 +107,6 @@ extern void _resolv_delete_cache_for_net(unsigned netid) __used_in_netd;
|
|||
/* Internal use only. */
|
||||
struct hostent *android_gethostbyaddrfornetcontext_proxy(const void *, socklen_t, int , const struct android_net_context *) __LIBC_HIDDEN__;
|
||||
int android_getnameinfofornet(const struct sockaddr *, socklen_t, char *, size_t, char *, size_t, int, unsigned, unsigned) __LIBC_HIDDEN__;
|
||||
FILE* android_open_proxy(void) __LIBC_HIDDEN__;
|
||||
|
||||
__END_DECLS
|
||||
|
||||
|
|
|
@ -422,11 +422,10 @@ android_getaddrinfo_proxy(
|
|||
return EAI_NODATA;
|
||||
}
|
||||
|
||||
FILE* proxy = android_open_proxy();
|
||||
FILE* proxy = fdopen(__netdClientDispatch.dnsOpenProxy(), "r+");
|
||||
if (proxy == NULL) {
|
||||
return EAI_SYSTEM;
|
||||
}
|
||||
|
||||
netid = __netdClientDispatch.netIdForResolv(netid);
|
||||
|
||||
// Send the request.
|
||||
|
|
|
@ -565,34 +565,6 @@ gethostbyname2_r(const char *name, int af, struct hostent *hp, char *buf,
|
|||
return h_errno_to_result(errorp);
|
||||
}
|
||||
|
||||
__LIBC_HIDDEN__ FILE* android_open_proxy() {
|
||||
const char* cache_mode = getenv("ANDROID_DNS_MODE");
|
||||
bool use_proxy = (cache_mode == NULL || strcmp(cache_mode, "local") != 0);
|
||||
if (!use_proxy) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int s = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
|
||||
if (s == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const int one = 1;
|
||||
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
|
||||
|
||||
struct sockaddr_un proxy_addr;
|
||||
memset(&proxy_addr, 0, sizeof(proxy_addr));
|
||||
proxy_addr.sun_family = AF_UNIX;
|
||||
strlcpy(proxy_addr.sun_path, "/dev/socket/dnsproxyd", sizeof(proxy_addr.sun_path));
|
||||
|
||||
if (TEMP_FAILURE_RETRY(connect(s, (const struct sockaddr*) &proxy_addr, sizeof(proxy_addr))) != 0) {
|
||||
close(s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return fdopen(s, "r+");
|
||||
}
|
||||
|
||||
static struct hostent *
|
||||
android_read_hostent(FILE* proxy, struct hostent* hp, char* hbuf, size_t hbuflen, int *he)
|
||||
{
|
||||
|
@ -816,18 +788,16 @@ fake:
|
|||
return hp;
|
||||
}
|
||||
|
||||
// very similar in proxy-ness to android_getaddrinfo_proxy
|
||||
static struct hostent *
|
||||
gethostbyname_internal(const char *name, int af, res_state res, struct hostent *hp, char *hbuf,
|
||||
size_t hbuflen, int *errorp, const struct android_net_context *netcontext)
|
||||
{
|
||||
FILE* proxy = android_open_proxy();
|
||||
FILE* proxy = fdopen(__netdClientDispatch.dnsOpenProxy(), "r+");
|
||||
if (proxy == NULL) {
|
||||
// Either we're not supposed to be using the proxy or the proxy is unavailable.
|
||||
res_setnetcontext(res, netcontext);
|
||||
return gethostbyname_internal_real(name, af, res, hp, hbuf, hbuflen, errorp);
|
||||
}
|
||||
|
||||
unsigned netid = __netdClientDispatch.netIdForResolv(netcontext->app_netid);
|
||||
|
||||
// This is writing to system/netd/server/DnsProxyListener.cpp and changes
|
||||
|
@ -925,12 +895,11 @@ android_gethostbyaddrfornetcontext_proxy_internal(const void* addr, socklen_t le
|
|||
struct hostent *hp, char *hbuf, size_t hbuflen, int *he,
|
||||
const struct android_net_context *netcontext)
|
||||
{
|
||||
FILE* proxy = android_open_proxy();
|
||||
FILE* proxy = fdopen(__netdClientDispatch.dnsOpenProxy(), "r+");
|
||||
if (proxy == NULL) {
|
||||
// Either we're not supposed to be using the proxy or the proxy is unavailable.
|
||||
return android_gethostbyaddrfornetcontext_real(addr,len, af, hp, hbuf, hbuflen, he, netcontext);
|
||||
}
|
||||
|
||||
char buf[INET6_ADDRSTRLEN]; //big enough for IPv4 and IPv6
|
||||
const char * addrStr = inet_ntop(af, addr, buf, sizeof(buf));
|
||||
if (addrStr == NULL) {
|
||||
|
|
|
@ -27,6 +27,7 @@ struct NetdClientDispatch {
|
|||
int (*connect)(int, const struct sockaddr*, socklen_t);
|
||||
int (*socket)(int, int, int);
|
||||
unsigned (*netIdForResolv)(unsigned);
|
||||
int (*dnsOpenProxy)();
|
||||
};
|
||||
|
||||
extern __LIBC_HIDDEN__ struct NetdClientDispatch __netdClientDispatch;
|
||||
|
|
Loading…
Reference in a new issue