Use framework hints to determine dns query type.

Instead of checking for IPv4 or IPv6 connectivity, try using pid-specific
hints the framework has left for us.

bug:5284168
Change-Id: Id64d48db3900865a7d58ada8309870c63d6eab12
This commit is contained in:
Robert Greenwalt 2011-09-13 17:33:52 -07:00
parent 3884bfe966
commit 8af58f0fd4

View File

@ -377,9 +377,20 @@ _test_connect(int pf, struct sockaddr *addr, size_t addrlen) {
* available, but whether addresses of the specified family are "configured
* on the local system". However, bionic doesn't currently support getifaddrs,
* so checking for connectivity is the next best thing.
*
* Note that simply checking connectivity is going to do the wrong thing on
* multihomed devices. Now we pass in a hint from the framework about what
* to use for this request ("v4", "v4v6", or "v6").
*/
static int
_have_ipv6() {
_have_ipv6(const char *propvalue) {
if (*propvalue != 0) {
if ((strcmp(propvalue, "v4v6") == 0) || (strcmp(propvalue, "v6") == 0)) {
return 1;
} else {
return 0;
}
} else {
static const struct sockaddr_in6 sin6_test = {
.sin6_family = AF_INET6,
.sin6_addr.s6_addr = { // 2000::
@ -387,16 +398,21 @@ _have_ipv6() {
};
sockaddr_union addr = { .in6 = sin6_test };
return _test_connect(PF_INET6, &addr.generic, sizeof(addr.in6));
}
}
static int
_have_ipv4() {
_have_ipv4(const char *propvalue) {
if (*propvalue != 0) {
return (strncmp(propvalue, "v4", 2) == 0);
} else {
static const struct sockaddr_in sin_test = {
.sin_family = AF_INET,
.sin_addr.s_addr = __constant_htonl(0x08080808L) // 8.8.8.8
};
sockaddr_union addr = { .in = sin_test };
return _test_connect(PF_INET, &addr.generic, sizeof(addr.in));
}
}
// Returns 0 on success, else returns non-zero on error (in which case
@ -1909,8 +1925,16 @@ _dns_getaddrinfo(void *rv, void *cb_data, va_list ap)
q.anslen = sizeof(buf->buf);
int query_ipv6 = 1, query_ipv4 = 1;
if (pai->ai_flags & AI_ADDRCONFIG) {
query_ipv6 = _have_ipv6();
query_ipv4 = _have_ipv4();
/* check if the fwk gave us a hint */
char propname[PROP_NAME_MAX];
char propvalue[PROP_VALUE_MAX];
propvalue[0] = 0;
snprintf(propname, sizeof(propname), "net.dnsproto.%d", getpid());
if (__system_property_get(propname, propvalue) <= 0) {
__system_property_get("net.dnsproto", propvalue);
}
query_ipv6 = _have_ipv6(propvalue);
query_ipv4 = _have_ipv4(propvalue);
}
if (query_ipv6) {
q.qtype = T_AAAA;