Merge "Use AI_ADDRCONFIG for most DNS requests"
This commit is contained in:
@@ -795,8 +795,9 @@ public class NetworkMonitor extends StateMachine {
|
|||||||
private void resolveStrictModeHostname() {
|
private void resolveStrictModeHostname() {
|
||||||
try {
|
try {
|
||||||
// Do a blocking DNS resolution using the network-assigned nameservers.
|
// Do a blocking DNS resolution using the network-assigned nameservers.
|
||||||
|
// Do not set AI_ADDRCONFIG in ai_flags so we get all address families in advance.
|
||||||
final InetAddress[] ips = ResolvUtil.blockingResolveAllLocally(
|
final InetAddress[] ips = ResolvUtil.blockingResolveAllLocally(
|
||||||
mNetwork, mPrivateDnsProviderHostname);
|
mNetwork, mPrivateDnsProviderHostname, 0 /* aiFlags */);
|
||||||
mPrivateDnsConfig = new PrivateDnsConfig(mPrivateDnsProviderHostname, ips);
|
mPrivateDnsConfig = new PrivateDnsConfig(mPrivateDnsProviderHostname, ips);
|
||||||
} catch (UnknownHostException uhe) {
|
} catch (UnknownHostException uhe) {
|
||||||
mPrivateDnsConfig = null;
|
mPrivateDnsConfig = null;
|
||||||
|
|||||||
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package android.net.dns;
|
package android.net.dns;
|
||||||
|
|
||||||
|
import static android.system.OsConstants.AI_ADDRCONFIG;
|
||||||
|
|
||||||
import android.net.Network;
|
import android.net.Network;
|
||||||
import android.net.NetworkUtils;
|
import android.net.NetworkUtils;
|
||||||
import android.system.GaiException;
|
import android.system.GaiException;
|
||||||
@@ -41,12 +43,17 @@ public class ResolvUtil {
|
|||||||
|
|
||||||
public static InetAddress[] blockingResolveAllLocally(Network network, String name)
|
public static InetAddress[] blockingResolveAllLocally(Network network, String name)
|
||||||
throws UnknownHostException {
|
throws UnknownHostException {
|
||||||
|
// Use AI_ADDRCONFIG by default
|
||||||
|
return blockingResolveAllLocally(network, name, AI_ADDRCONFIG);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InetAddress[] blockingResolveAllLocally(
|
||||||
|
Network network, String name, int aiFlags) throws UnknownHostException {
|
||||||
final StructAddrinfo hints = new StructAddrinfo();
|
final StructAddrinfo hints = new StructAddrinfo();
|
||||||
// Unnecessary, but expressly no AI_ADDRCONFIG.
|
hints.ai_flags = aiFlags;
|
||||||
hints.ai_flags = 0;
|
// Other hints identical to the default Inet6AddressImpl implementation
|
||||||
// Fetch all IP addresses at once to minimize re-resolution.
|
|
||||||
hints.ai_family = OsConstants.AF_UNSPEC;
|
hints.ai_family = OsConstants.AF_UNSPEC;
|
||||||
hints.ai_socktype = OsConstants.SOCK_DGRAM;
|
hints.ai_socktype = OsConstants.SOCK_STREAM;
|
||||||
|
|
||||||
final Network networkForResolv = getNetworkWithUseLocalNameserversFlag(network);
|
final Network networkForResolv = getNetworkWithUseLocalNameserversFlag(network);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user