@@ -1974,7 +1974,8 @@ private void reassessPidDns(int myPid, boolean doBump)
19741974 Integer pid = (Integer )pids .get (j );
19751975 if (pid .intValue () == myPid ) {
19761976 Collection <InetAddress > dnses = p .getDnses ();
1977- writePidDns (dnses , myPid );
1977+ String proto = determineProto (p );
1978+ writePidDns (dnses , myPid , proto );
19781979 if (doBump ) {
19791980 bumpDns ();
19801981 }
@@ -1984,6 +1985,9 @@ private void reassessPidDns(int myPid, boolean doBump)
19841985 }
19851986 }
19861987 // nothing found - delete
1988+ if (SystemProperties .get ("net.dnsproto." + myPid ).length () != 0 ) {
1989+ SystemProperties .set ("net.dnsproto." + myPid , "" );
1990+ }
19871991 for (int i = 1 ; ; i ++) {
19881992 String prop = "net.dns" + i + "." + myPid ;
19891993 if (SystemProperties .get (prop ).length () == 0 ) {
@@ -1997,7 +2001,7 @@ private void reassessPidDns(int myPid, boolean doBump)
19972001 }
19982002
19992003 // return true if results in a change
2000- private boolean writePidDns (Collection <InetAddress > dnses , int pid ) {
2004+ private boolean writePidDns (Collection <InetAddress > dnses , int pid , String proto ) {
20012005 int j = 1 ;
20022006 boolean changed = false ;
20032007 for (InetAddress dns : dnses ) {
@@ -2007,6 +2011,11 @@ private boolean writePidDns(Collection <InetAddress> dnses, int pid) {
20072011 SystemProperties .set ("net.dns" + j ++ + "." + pid , dns .getHostAddress ());
20082012 }
20092013 }
2014+ if (dnses .size () > 0 && (changed || !proto .equals (SystemProperties .get ("net.dnsproto." +
2015+ pid )))) {
2016+ changed = true ;
2017+ SystemProperties .set ("net.dnsproto." + pid , proto );
2018+ }
20102019 return changed ;
20112020 }
20122021
@@ -2037,7 +2046,7 @@ private void bumpDns() {
20372046
20382047 // Caller must grab mDnsLock.
20392048 private boolean updateDns (String network , String iface ,
2040- Collection <InetAddress > dnses , String domains ) {
2049+ Collection <InetAddress > dnses , String domains , String proto ) {
20412050 boolean changed = false ;
20422051 int last = 0 ;
20432052 if (dnses .size () == 0 && mDefaultDns != null ) {
@@ -2073,6 +2082,11 @@ private boolean updateDns(String network, String iface,
20732082 }
20742083 mNumDnsEntries = last ;
20752084
2085+ if (changed || !proto .equals (SystemProperties .get ("net.dnsproto" ))) {
2086+ changed = true ;
2087+ SystemProperties .set ("net.dnsproto" , proto );
2088+ }
2089+
20762090 if (changed ) {
20772091 try {
20782092 mNetd .setDnsServersForInterface (iface , NetworkUtils .makeStrings (dnses ));
@@ -2096,11 +2110,14 @@ private void handleDnsConfigurationChange(int netType) {
20962110 if (p == null ) return ;
20972111 Collection <InetAddress > dnses = p .getDnses ();
20982112 boolean changed = false ;
2113+ String proto = determineProto (p );
2114+
20992115 if (mNetConfigs [netType ].isDefault ()) {
21002116 String network = nt .getNetworkInfo ().getTypeName ();
21012117 synchronized (mDnsLock ) {
21022118 if (!mDnsOverridden ) {
2103- changed = updateDns (network , p .getInterfaceName (), dnses , "" );
2119+ changed = updateDns (network , p .getInterfaceName (), dnses , "" ,
2120+ proto );
21042121 }
21052122 }
21062123 } else {
@@ -2114,13 +2131,35 @@ private void handleDnsConfigurationChange(int netType) {
21142131 List pids = mNetRequestersPids [netType ];
21152132 for (int y =0 ; y < pids .size (); y ++) {
21162133 Integer pid = (Integer )pids .get (y );
2117- changed = writePidDns (dnses , pid .intValue ());
2134+ changed = writePidDns (dnses , pid .intValue (), proto );
21182135 }
21192136 }
21202137 if (changed ) bumpDns ();
21212138 }
21222139 }
21232140
2141+ private String determineProto (LinkProperties p ) {
2142+ boolean v4 = false ;
2143+ boolean v6 = false ;
2144+ for (RouteInfo r : p .getRoutes ()) {
2145+ if (r .getDestination ().getAddress () instanceof Inet6Address ) {
2146+ v6 = true ;
2147+ } else {
2148+ v4 = true ;
2149+ }
2150+ }
2151+ // secondary connections often don't have routes and we infer routes
2152+ // to the dns servers. Look at the dns addrs too
2153+ for (InetAddress i : p .getDnses ()) {
2154+ if (i instanceof Inet6Address ) {
2155+ v6 = true ;
2156+ } else {
2157+ v4 = true ;
2158+ }
2159+ }
2160+ return (v4 ? "v4" : "" ) + (v6 ? "v6" : "" );
2161+ }
2162+
21242163 private int getRestoreDefaultNetworkDelay (int networkType ) {
21252164 String restoreDefaultNetworkDelayStr = SystemProperties .get (
21262165 NETWORK_RESTORE_DELAY_PROP_NAME );
@@ -2842,7 +2881,7 @@ public void override(List<String> dnsServers, List<String> searchDomains) {
28422881 // Apply DNS changes.
28432882 boolean changed = false ;
28442883 synchronized (mDnsLock ) {
2845- changed = updateDns ("VPN" , "VPN" , addresses , domains );
2884+ changed = updateDns ("VPN" , "VPN" , addresses , domains , "v4" );
28462885 mDnsOverridden = true ;
28472886 }
28482887 if (changed ) {
0 commit comments