diff options
| author | Robert Greenwalt <rgreenwalt@google.com> | 2011-05-11 13:07:38 -0700 |
|---|---|---|
| committer | Android Git Automerger <android-git-automerger@android.com> | 2011-05-11 13:07:38 -0700 |
| commit | fc82cb170cfaf419f2a8da3baff8296d3ea4e241 (patch) | |
| tree | 90b0d7a0f7538767e3ee6e798237e1db85cf4cc7 /services/java/com/android/server/ConnectivityService.java | |
| parent | a0f5bb10a5a7b10f376b5001b7cabb6b267d734f (diff) | |
| parent | 441bc9a6f41ca1678a6c965bec7e2f18227ac100 (diff) | |
am 441bc9a6: am e6848fac: Merge "Fix the adding of host routes." into honeycomb-LTE
* commit '441bc9a6f41ca1678a6c965bec7e2f18227ac100':
Fix the adding of host routes.
Diffstat (limited to 'services/java/com/android/server/ConnectivityService.java')
| -rw-r--r-- | services/java/com/android/server/ConnectivityService.java | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java index 7272e769e915..a9a7af459bb7 100644 --- a/services/java/com/android/server/ConnectivityService.java +++ b/services/java/com/android/server/ConnectivityService.java @@ -81,6 +81,10 @@ public class ConnectivityService extends IConnectivityManager.Stub { private static final String NETWORK_RESTORE_DELAY_PROP_NAME = "android.telephony.apn-restore"; + // used in recursive route setting to add gateways for the host for which + // a host route was requested. + private static final int MAX_HOSTROUTE_CYCLE_COUNT = 10; + private Tethering mTethering; private boolean mTetheringConfigValid = false; @@ -911,7 +915,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { } try { InetAddress addr = InetAddress.getByAddress(hostAddress); - return addHostRoute(tracker, addr); + return addHostRoute(tracker, addr, 0); } catch (UnknownHostException e) {} return false; } @@ -924,24 +928,45 @@ public class ConnectivityService extends IConnectivityManager.Stub { * TODO - deprecate * @return {@code true} on success, {@code false} on failure */ - private boolean addHostRoute(NetworkStateTracker nt, InetAddress hostAddress) { + private boolean addHostRoute(NetworkStateTracker nt, InetAddress hostAddress, int cycleCount) { if (nt.getNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI) { return false; } - LinkProperties p = nt.getLinkProperties(); - if (p == null) return false; - String interfaceName = p.getInterfaceName(); + LinkProperties lp = nt.getLinkProperties(); + if ((lp == null) || (hostAddress == null)) return false; + String interfaceName = lp.getInterfaceName(); if (DBG) { - log("Requested host route to " + hostAddress + "(" + interfaceName + ")"); + log("Requested host route to " + hostAddress + "(" + interfaceName + "), cycleCount=" + + cycleCount); } - if (interfaceName != null) { - return NetworkUtils.addHostRoute(interfaceName, hostAddress, null); - } else { + if (interfaceName == null) { if (DBG) loge("addHostRoute failed due to null interface name"); return false; } + + RouteInfo bestRoute = RouteInfo.selectBestRoute(lp.getRoutes(), hostAddress); + InetAddress gateway = null; + if (bestRoute != null) { + gateway = bestRoute.getGateway(); + // if the best route is ourself, don't relf-reference, just add the host route + if (hostAddress.equals(gateway)) gateway = null; + } + if (gateway != null) { + if (cycleCount > MAX_HOSTROUTE_CYCLE_COUNT) { + loge("Error adding hostroute - too much recursion"); + return false; + } + if (!addHostRoute(nt, gateway, cycleCount+1)) return false; + } + return NetworkUtils.addHostRoute(interfaceName, hostAddress, gateway); + } + + // TODO support the removal of single host routes. Keep a ref count of them so we + // aren't over-zealous + private boolean removeHostRoute(NetworkStateTracker nt, InetAddress hostAddress) { + return false; } /** @@ -1393,7 +1418,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { Collection<InetAddress> dnsList = p.getDnses(); for (InetAddress dns : dnsList) { if (DBG) log(" adding " + dns); - NetworkUtils.addHostRoute(interfaceName, dns, null); + addHostRoute(nt, dns, 0); } nt.privateDnsRouteSet(true); } @@ -1427,7 +1452,7 @@ public class ConnectivityService extends IConnectivityManager.Stub { //TODO - handle non-default routes if (route.isDefaultRoute()) { InetAddress gateway = route.getGateway(); - if (NetworkUtils.addHostRoute(interfaceName, gateway, null) && + if (addHostRoute(nt, gateway, 0) && NetworkUtils.addDefaultRoute(interfaceName, gateway)) { if (DBG) { NetworkInfo networkInfo = nt.getNetworkInfo(); |
