OSDN Git Service

Add a netcontext variant of gethostbyname
authorBen Schwartz <bemasc@google.com>
Mon, 22 May 2017 14:19:25 +0000 (10:19 -0400)
committerBen Schwartz <bemasc@google.com>
Mon, 22 May 2017 14:19:25 +0000 (10:19 -0400)
Bug: 34953048
Test: Integration tests pass
Change-Id: I670427d67fde09d8e76ea6a920c90a1969230c4f

libc/dns/include/resolv_netid.h
libc/dns/net/gethnamaddr.c
libc/libc.arm.map
libc/libc.arm64.map
libc/libc.map.txt
libc/libc.mips.map
libc/libc.mips64.map
libc/libc.x86.map
libc/libc.x86_64.map

index 711792b..3b2f4da 100644 (file)
@@ -86,6 +86,7 @@ int android_getaddrinfofornet(const char *, const char *, const struct addrinfo
  * explore_fqdn() dispatch table method, with the below function only making DNS calls.
  */
 struct hostent *android_gethostbyaddrfornetcontext(const void *, socklen_t, int, const struct android_net_context *) __used_in_netd;
+struct hostent *android_gethostbynamefornetcontext(const char *, int, const struct android_net_context *) __used_in_netd;
 int android_getaddrinfofornetcontext(const char *, const char *, const struct addrinfo *,
     const struct android_net_context *, struct addrinfo **) __used_in_netd;
 
index 036ad1d..a22d718 100644 (file)
@@ -160,7 +160,7 @@ static int _dns_gethtbyaddr(void *, void *, va_list);
 static int _dns_gethtbyname(void *, void *, va_list);
 
 static struct hostent *gethostbyname_internal(const char *, int, res_state,
-    struct hostent *, char *, size_t, int *, unsigned, unsigned);
+    struct hostent *, char *, size_t, int *, const struct android_net_context *);
 static struct hostent* android_gethostbyaddrfornetcontext_proxy_internal(const void*, socklen_t,
     int, struct hostent *, char *, size_t, int *, const struct android_net_context *);
 
@@ -529,15 +529,15 @@ gethostbyname_r(const char *name, struct hostent *hp, char *buf, size_t buflen,
        _DIAGASSERT(name != NULL);
 
        if (res->options & RES_USE_INET6) {
-               *result = gethostbyname_internal(name, AF_INET6, res, hp, buf, buflen, errorp, NETID_UNSET,
-                                                MARK_UNSET);
+               *result = gethostbyname_internal(name, AF_INET6, res, hp, buf, buflen, errorp,
+                                                &NETCONTEXT_UNSET);
                if (*result) {
                        __res_put_state(res);
                        return 0;
                }
        }
-       *result = gethostbyname_internal(name, AF_INET, res, hp, buf, buflen, errorp, NETID_UNSET,
-                                        MARK_UNSET);
+       *result = gethostbyname_internal(name, AF_INET, res, hp, buf, buflen, errorp,
+                                        &NETCONTEXT_UNSET);
        __res_put_state(res);
        if (!*result && errno == ENOSPC) {
          errno = ERANGE;
@@ -558,8 +558,8 @@ gethostbyname2_r(const char *name, int af, struct hostent *hp, char *buf,
                *errorp = NETDB_INTERNAL;
                return -1;
        }
-       *result = gethostbyname_internal(name, af, res, hp, buf, buflen, errorp, NETID_UNSET,
-                                        MARK_UNSET);
+       *result = gethostbyname_internal(name, af, res, hp, buf, buflen, errorp,
+                                        &NETCONTEXT_UNSET);
        __res_put_state(res);
        if (!*result && errno == ENOSPC) {
                errno = ERANGE;
@@ -822,17 +822,17 @@ fake:
 // 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, unsigned netid, unsigned mark)
+                       size_t hbuflen, int *errorp, const struct android_net_context *netcontext)
 {
        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, netid);
-               res_setmark(res, mark);
+               res_setnetid(res, netcontext->dns_netid);
+               res_setmark(res, netcontext->dns_mark);
                return gethostbyname_internal_real(name, af, res, hp, hbuf, hbuflen, errorp);
        }
 
-       netid = __netdClientDispatch.netIdForResolv(netid);
+       unsigned netid = __netdClientDispatch.netIdForResolv(netcontext->app_netid);
 
        // This is writing to system/netd/server/DnsProxyListener.cpp and changes
        // here need to be matched there.
@@ -1611,13 +1611,21 @@ static struct android_net_context make_context(unsigned netid, unsigned mark) {
 struct hostent *
 android_gethostbynamefornet(const char *name, int af, unsigned netid, unsigned mark)
 {
+       const struct android_net_context netcontext = make_context(netid, mark);
+       return android_gethostbynamefornetcontext(name, af, &netcontext);
+}
+
+struct hostent *
+android_gethostbynamefornetcontext(const char *name, int af,
+       const struct android_net_context *netcontext)
+{
        struct hostent *hp;
        res_state res = __res_get_state();
        if (res == NULL)
                return NULL;
        res_static rs = __res_get_static(); /* Use res_static to provide thread-safety. */
        hp = gethostbyname_internal(name, af, res, &rs->host, rs->hostbuf, sizeof(rs->hostbuf),
-                                   &h_errno, netid, mark);
+                                   &h_errno, netcontext);
        __res_put_state(res);
        return hp;
 }
index a74027a..b32f769 100644 (file)
@@ -1496,6 +1496,7 @@ LIBC_PRIVATE {
     android_gethostbyaddrfornet;
     android_gethostbyaddrfornetcontext;
     android_gethostbynamefornet;
+    android_gethostbynamefornetcontext;
     arc4random_addrandom; # arm x86 mips
     arc4random_stir; # arm x86 mips
     atexit; # arm
index 34d3429..afcf8bb 100644 (file)
@@ -1244,6 +1244,7 @@ LIBC_PRIVATE {
     android_gethostbyaddrfornet;
     android_gethostbyaddrfornetcontext;
     android_gethostbynamefornet;
+    android_gethostbynamefornetcontext;
     free_malloc_leak_info;
     get_malloc_leak_info;
     gMallocLeakZygoteChild;
index 90929f5..f05e7eb 100644 (file)
@@ -1522,6 +1522,7 @@ LIBC_PRIVATE {
     android_gethostbyaddrfornet;
     android_gethostbyaddrfornetcontext;
     android_gethostbynamefornet;
+    android_gethostbynamefornetcontext;
     arc4random_addrandom; # arm x86 mips
     arc4random_stir; # arm x86 mips
     atexit; # arm
index aac876d..a472214 100644 (file)
@@ -1339,6 +1339,7 @@ LIBC_PRIVATE {
     android_gethostbyaddrfornet;
     android_gethostbyaddrfornetcontext;
     android_gethostbynamefornet;
+    android_gethostbynamefornetcontext;
     arc4random_addrandom; # arm x86 mips
     arc4random_stir; # arm x86 mips
     bcopy; # arm x86 mips
index 34d3429..afcf8bb 100644 (file)
@@ -1244,6 +1244,7 @@ LIBC_PRIVATE {
     android_gethostbyaddrfornet;
     android_gethostbyaddrfornetcontext;
     android_gethostbynamefornet;
+    android_gethostbynamefornetcontext;
     free_malloc_leak_info;
     get_malloc_leak_info;
     gMallocLeakZygoteChild;
index 682f2c4..27a597f 100644 (file)
@@ -1338,6 +1338,7 @@ LIBC_PRIVATE {
     android_gethostbyaddrfornet;
     android_gethostbyaddrfornetcontext;
     android_gethostbynamefornet;
+    android_gethostbynamefornetcontext;
     arc4random_addrandom; # arm x86 mips
     arc4random_stir; # arm x86 mips
     bcopy; # arm x86 mips
index 34d3429..afcf8bb 100644 (file)
@@ -1244,6 +1244,7 @@ LIBC_PRIVATE {
     android_gethostbyaddrfornet;
     android_gethostbyaddrfornetcontext;
     android_gethostbynamefornet;
+    android_gethostbynamefornetcontext;
     free_malloc_leak_info;
     get_malloc_leak_info;
     gMallocLeakZygoteChild;