From bb4fd0b4442301a7c64b52a1241a9d0cd4a75d0b Mon Sep 17 00:00:00 2001 From: Robert Greenwalt Date: Fri, 9 Dec 2011 15:36:50 -0800 Subject: [PATCH] Use the carrier-given dns addrs for tethering. This fixes a complaint from carriers (that we used 8.8.8.8), but also fixes the case where there is only room for one live radio connection: the secondary connection (tethering) doesn't have a default route to prevent on-device traffic from slipping out on the tethering connection, but tethered dns is proxied through dnsmasq, so it is appearing as on-device traffic and is unroutable. By switching to the carrier-indicated dns servers we can use the host-routes already set for those and kill two bugs with one fix. bug:5525764 bug:3045311 Change-Id: Ib1ccea81e0c0ed2d1462dc9721c2647124a790da --- .../server/connectivity/Tethering.java | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/services/java/com/android/server/connectivity/Tethering.java b/services/java/com/android/server/connectivity/Tethering.java index b1551a6554f33..bc8ce7ddf6519 100644 --- a/services/java/com/android/server/connectivity/Tethering.java +++ b/services/java/com/android/server/connectivity/Tethering.java @@ -118,7 +118,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub { "192.168.48.2", "192.168.48.254", }; - private String[] mDnsServers; + private String[] mDefaultDnsServers; private static final String DNS_DEFAULT_SERVER1 = "8.8.8.8"; private static final String DNS_DEFAULT_SERVER2 = "8.8.4.4"; @@ -171,9 +171,9 @@ public class Tethering extends INetworkManagementEventObserver.Stub { updateConfiguration(); // TODO - remove and rely on real notifications of the current iface - mDnsServers = new String[2]; - mDnsServers[0] = DNS_DEFAULT_SERVER1; - mDnsServers[1] = DNS_DEFAULT_SERVER2; + mDefaultDnsServers = new String[2]; + mDefaultDnsServers[0] = DNS_DEFAULT_SERVER1; + mDefaultDnsServers[1] = DNS_DEFAULT_SERVER2; } void updateConfiguration() { @@ -1244,7 +1244,7 @@ public class Tethering extends INetworkManagementEventObserver.Stub { } } try { - mNMService.setDnsForwarders(mDnsServers); + mNMService.setDnsForwarders(mDefaultDnsServers); } catch (Exception e) { transitionTo(mSetDnsForwardersErrorState); return false; @@ -1320,7 +1320,19 @@ public class Tethering extends INetworkManagementEventObserver.Stub { try { linkProperties = mConnService.getLinkProperties(upType); } catch (RemoteException e) { } - if (linkProperties != null) iface = linkProperties.getInterfaceName(); + if (linkProperties != null) { + iface = linkProperties.getInterfaceName(); + String[] dnsServers = mDefaultDnsServers; + Collection dnses = linkProperties.getDnses(); + if (dnses != null) { + dnsServers = NetworkUtils.makeStrings(dnses); + } + try { + mNMService.setDnsForwarders(dnsServers); + } catch (Exception e) { + transitionTo(mSetDnsForwardersErrorState); + } + } } notifyTetheredOfNewUpstreamIface(iface); }