@@ -1955,7 +1955,8 @@ private void reassessPidDns(int myPid, boolean doBump)
19551955 Integer pid = (Integer )pids .get (j );
19561956 if (pid .intValue () == myPid ) {
19571957 Collection <InetAddress > dnses = p .getDnses ();
1958- writePidDns (dnses , myPid );
1958+ String proto = determineProto (p );
1959+ writePidDns (dnses , myPid , proto );
19591960 if (doBump ) {
19601961 bumpDns ();
19611962 }
@@ -1965,6 +1966,9 @@ private void reassessPidDns(int myPid, boolean doBump)
19651966 }
19661967 }
19671968 // nothing found - delete
1969+ if (SystemProperties .get ("net.dnsproto." + myPid ).length () != 0 ) {
1970+ SystemProperties .set ("net.dnsproto." + myPid , "" );
1971+ }
19681972 for (int i = 1 ; ; i ++) {
19691973 String prop = "net.dns" + i + "." + myPid ;
19701974 if (SystemProperties .get (prop ).length () == 0 ) {
@@ -1978,7 +1982,7 @@ private void reassessPidDns(int myPid, boolean doBump)
19781982 }
19791983
19801984 // return true if results in a change
1981- private boolean writePidDns (Collection <InetAddress > dnses , int pid ) {
1985+ private boolean writePidDns (Collection <InetAddress > dnses , int pid , String proto ) {
19821986 int j = 1 ;
19831987 boolean changed = false ;
19841988 for (InetAddress dns : dnses ) {
@@ -1988,6 +1992,11 @@ private boolean writePidDns(Collection <InetAddress> dnses, int pid) {
19881992 SystemProperties .set ("net.dns" + j ++ + "." + pid , dns .getHostAddress ());
19891993 }
19901994 }
1995+ if (dnses .size () > 0 && (changed || !proto .equals (SystemProperties .get ("net.dnsproto." +
1996+ pid )))) {
1997+ changed = true ;
1998+ SystemProperties .set ("net.dnsproto." + pid , proto );
1999+ }
19912000 return changed ;
19922001 }
19932002
@@ -2018,7 +2027,7 @@ private void bumpDns() {
20182027
20192028 // Caller must grab mDnsLock.
20202029 private boolean updateDns (String network , String iface ,
2021- Collection <InetAddress > dnses , String domains ) {
2030+ Collection <InetAddress > dnses , String domains , String proto ) {
20222031 boolean changed = false ;
20232032 int last = 0 ;
20242033 if (dnses .size () == 0 && mDefaultDns != null ) {
@@ -2054,6 +2063,11 @@ private boolean updateDns(String network, String iface,
20542063 }
20552064 mNumDnsEntries = last ;
20562065
2066+ if (changed || !proto .equals (SystemProperties .get ("net.dnsproto" ))) {
2067+ changed = true ;
2068+ SystemProperties .set ("net.dnsproto" , proto );
2069+ }
2070+
20572071 if (changed ) {
20582072 try {
20592073 mNetd .setDnsServersForInterface (iface , NetworkUtils .makeStrings (dnses ));
@@ -2077,11 +2091,14 @@ private void handleDnsConfigurationChange(int netType) {
20772091 if (p == null ) return ;
20782092 Collection <InetAddress > dnses = p .getDnses ();
20792093 boolean changed = false ;
2094+ String proto = determineProto (p );
2095+
20802096 if (mNetConfigs [netType ].isDefault ()) {
20812097 String network = nt .getNetworkInfo ().getTypeName ();
20822098 synchronized (mDnsLock ) {
20832099 if (!mDnsOverridden ) {
2084- changed = updateDns (network , p .getInterfaceName (), dnses , "" );
2100+ changed = updateDns (network , p .getInterfaceName (), dnses , "" ,
2101+ proto );
20852102 }
20862103 }
20872104 } else {
@@ -2095,13 +2112,35 @@ private void handleDnsConfigurationChange(int netType) {
20952112 List pids = mNetRequestersPids [netType ];
20962113 for (int y =0 ; y < pids .size (); y ++) {
20972114 Integer pid = (Integer )pids .get (y );
2098- changed = writePidDns (dnses , pid .intValue ());
2115+ changed = writePidDns (dnses , pid .intValue (), proto );
20992116 }
21002117 }
21012118 if (changed ) bumpDns ();
21022119 }
21032120 }
21042121
2122+ private String determineProto (LinkProperties p ) {
2123+ boolean v4 = false ;
2124+ boolean v6 = false ;
2125+ for (RouteInfo r : p .getRoutes ()) {
2126+ if (r .getDestination ().getAddress () instanceof Inet6Address ) {
2127+ v6 = true ;
2128+ } else {
2129+ v4 = true ;
2130+ }
2131+ }
2132+ // secondary connections often don't have routes and we infer routes
2133+ // to the dns servers. Look at the dns addrs too
2134+ for (InetAddress i : p .getDnses ()) {
2135+ if (i instanceof Inet6Address ) {
2136+ v6 = true ;
2137+ } else {
2138+ v4 = true ;
2139+ }
2140+ }
2141+ return (v4 ? "v4" : "" ) + (v6 ? "v6" : "" );
2142+ }
2143+
21052144 private int getRestoreDefaultNetworkDelay (int networkType ) {
21062145 String restoreDefaultNetworkDelayStr = SystemProperties .get (
21072146 NETWORK_RESTORE_DELAY_PROP_NAME );
@@ -2819,7 +2858,7 @@ public void override(List<String> dnsServers, List<String> searchDomains) {
28192858 // Apply DNS changes.
28202859 boolean changed = false ;
28212860 synchronized (mDnsLock ) {
2822- changed = updateDns ("VPN" , "VPN" , addresses , domains );
2861+ changed = updateDns ("VPN" , "VPN" , addresses , domains , "v4" );
28232862 mDnsOverridden = true ;
28242863 }
28252864 if (changed ) {
0 commit comments