summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorLorenzo Colitti <lorenzo@google.com>2014-05-14 12:45:38 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2014-05-14 12:45:39 +0000
commit4a0e0173f4b718d63a729028fe75a98f3b0eeb77 (patch)
tree7badbe48fb664359bad02b8e6b8696bb2677860e /services
parentaf46637e4044630be6255a5f80c96d63f32a4b79 (diff)
parentb2829fa165124264c7ec06a6e23b08a1d97b99e5 (diff)
downloadframeworks_base-4a0e0173f4b718d63a729028fe75a98f3b0eeb77.zip
frameworks_base-4a0e0173f4b718d63a729028fe75a98f3b0eeb77.tar.gz
frameworks_base-4a0e0173f4b718d63a729028fe75a98f3b0eeb77.tar.bz2
Merge "Specify netId when adding/removing routes."
Diffstat (limited to 'services')
-rw-r--r--services/core/java/com/android/server/ConnectivityService.java53
-rw-r--r--services/core/java/com/android/server/NetworkManagementService.java59
2 files changed, 37 insertions, 75 deletions
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 1826478..1cb873e 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -1691,7 +1691,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
final long token = Binder.clearCallingIdentity();
try {
LinkProperties lp = tracker.getLinkProperties();
- boolean ok = addRouteToAddress(lp, addr, exempt);
+ boolean ok = addRouteToAddress(lp, addr, exempt, tracker.getNetwork().netId);
if (DBG) log("requestRouteToHostAddress ok=" + ok);
return ok;
} finally {
@@ -1700,24 +1700,25 @@ public class ConnectivityService extends IConnectivityManager.Stub {
}
private boolean addRoute(LinkProperties p, RouteInfo r, boolean toDefaultTable,
- boolean exempt) {
- return modifyRoute(p, r, 0, ADD, toDefaultTable, exempt);
+ boolean exempt, int netId) {
+ return modifyRoute(p, r, 0, ADD, toDefaultTable, exempt, netId);
}
- private boolean removeRoute(LinkProperties p, RouteInfo r, boolean toDefaultTable) {
- return modifyRoute(p, r, 0, REMOVE, toDefaultTable, UNEXEMPT);
+ private boolean removeRoute(LinkProperties p, RouteInfo r, boolean toDefaultTable, int netId) {
+ return modifyRoute(p, r, 0, REMOVE, toDefaultTable, UNEXEMPT, netId);
}
- private boolean addRouteToAddress(LinkProperties lp, InetAddress addr, boolean exempt) {
- return modifyRouteToAddress(lp, addr, ADD, TO_DEFAULT_TABLE, exempt);
+ private boolean addRouteToAddress(LinkProperties lp, InetAddress addr, boolean exempt,
+ int netId) {
+ return modifyRouteToAddress(lp, addr, ADD, TO_DEFAULT_TABLE, exempt, netId);
}
- private boolean removeRouteToAddress(LinkProperties lp, InetAddress addr) {
- return modifyRouteToAddress(lp, addr, REMOVE, TO_DEFAULT_TABLE, UNEXEMPT);
+ private boolean removeRouteToAddress(LinkProperties lp, InetAddress addr, int netId) {
+ return modifyRouteToAddress(lp, addr, REMOVE, TO_DEFAULT_TABLE, UNEXEMPT, netId);
}
private boolean modifyRouteToAddress(LinkProperties lp, InetAddress addr, boolean doAdd,
- boolean toDefaultTable, boolean exempt) {
+ boolean toDefaultTable, boolean exempt, int netId) {
RouteInfo bestRoute = RouteInfo.selectBestRoute(lp.getAllRoutes(), addr);
if (bestRoute == null) {
bestRoute = RouteInfo.makeHostRoute(addr, lp.getInterfaceName());
@@ -1732,11 +1733,11 @@ public class ConnectivityService extends IConnectivityManager.Stub {
bestRoute = RouteInfo.makeHostRoute(addr, bestRoute.getGateway(), iface);
}
}
- return modifyRoute(lp, bestRoute, 0, doAdd, toDefaultTable, exempt);
+ return modifyRoute(lp, bestRoute, 0, doAdd, toDefaultTable, exempt, netId);
}
private boolean modifyRoute(LinkProperties lp, RouteInfo r, int cycleCount, boolean doAdd,
- boolean toDefaultTable, boolean exempt) {
+ boolean toDefaultTable, boolean exempt, int netId) {
if ((lp == null) || (r == null)) {
if (DBG) log("modifyRoute got unexpected null: " + lp + ", " + r);
return false;
@@ -1765,7 +1766,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
bestRoute.getGateway(),
ifaceName);
}
- modifyRoute(lp, bestRoute, cycleCount+1, doAdd, toDefaultTable, exempt);
+ modifyRoute(lp, bestRoute, cycleCount+1, doAdd, toDefaultTable, exempt, netId);
}
}
if (doAdd) {
@@ -1775,7 +1776,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
synchronized (mRoutesLock) {
// only track default table - only one apps can effect
mAddedRoutes.add(r);
- mNetd.addRoute(ifaceName, r);
+ mNetd.addRoute(netId, r);
if (exempt) {
LinkAddress dest = r.getDestination();
if (!mExemptAddresses.contains(dest)) {
@@ -1785,7 +1786,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
}
}
} else {
- mNetd.addSecondaryRoute(ifaceName, r);
+ mNetd.addRoute(netId, r);
}
} catch (Exception e) {
// never crash - catch them all
@@ -1801,7 +1802,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
if (mAddedRoutes.contains(r) == false) {
if (VDBG) log("Removing " + r + " for interface " + ifaceName);
try {
- mNetd.removeRoute(ifaceName, r);
+ mNetd.removeRoute(netId, r);
LinkAddress dest = r.getDestination();
if (mExemptAddresses.contains(dest)) {
mNetd.clearHostExemption(dest);
@@ -1819,7 +1820,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
} else {
if (VDBG) log("Removing " + r + " for interface " + ifaceName);
try {
- mNetd.removeSecondaryRoute(ifaceName, r);
+ mNetd.removeRoute(netId, r);
} catch (Exception e) {
// never crash - catch them all
if (VDBG) loge("Exception trying to remove a route: " + e);
@@ -2608,7 +2609,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
}
}
mCurrentLinkProperties[netType] = newLp;
- boolean resetDns = updateRoutes(newLp, curLp, mNetConfigs[netType].isDefault(), exempt);
+ boolean resetDns = updateRoutes(newLp, curLp, mNetConfigs[netType].isDefault(), exempt,
+ mNetTrackers[netType].getNetwork().netId);
if (resetMask != 0 || resetDns) {
if (VDBG) log("handleConnectivityChange: resetting");
@@ -2687,7 +2689,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
* returns a boolean indicating the routes changed
*/
private boolean updateRoutes(LinkProperties newLp, LinkProperties curLp,
- boolean isLinkDefault, boolean exempt) {
+ boolean isLinkDefault, boolean exempt, int netId) {
Collection<RouteInfo> routesToAdd = null;
CompareResult<InetAddress> dnsDiff = new CompareResult<InetAddress>();
CompareResult<RouteInfo> routeDiff = new CompareResult<RouteInfo>();
@@ -2705,20 +2707,20 @@ public class ConnectivityService extends IConnectivityManager.Stub {
for (RouteInfo r : routeDiff.removed) {
if (isLinkDefault || ! r.isDefaultRoute()) {
if (VDBG) log("updateRoutes: default remove route r=" + r);
- removeRoute(curLp, r, TO_DEFAULT_TABLE);
+ removeRoute(curLp, r, TO_DEFAULT_TABLE, netId);
}
if (isLinkDefault == false) {
// remove from a secondary route table
- removeRoute(curLp, r, TO_SECONDARY_TABLE);
+ removeRoute(curLp, r, TO_SECONDARY_TABLE, netId);
}
}
for (RouteInfo r : routeDiff.added) {
if (isLinkDefault || ! r.isDefaultRoute()) {
- addRoute(newLp, r, TO_DEFAULT_TABLE, exempt);
+ addRoute(newLp, r, TO_DEFAULT_TABLE, exempt, netId);
} else {
// add to a secondary route table
- addRoute(newLp, r, TO_SECONDARY_TABLE, UNEXEMPT);
+ addRoute(newLp, r, TO_SECONDARY_TABLE, UNEXEMPT, netId);
// many radios add a default route even when we don't want one.
// remove the default route unless somebody else has asked for it
@@ -2727,7 +2729,7 @@ public class ConnectivityService extends IConnectivityManager.Stub {
if (!TextUtils.isEmpty(ifaceName) && !mAddedRoutes.contains(r)) {
if (VDBG) log("Removing " + r + " for interface " + ifaceName);
try {
- mNetd.removeRoute(ifaceName, r);
+ mNetd.removeRoute(netId, r);
} catch (Exception e) {
// never crash - catch them all
if (DBG) loge("Exception trying to remove a route: " + e);
@@ -3122,7 +3124,8 @@ public class ConnectivityService extends IConnectivityManager.Stub {
// connection will fail until the provisioning network
// is enabled.
for (RouteInfo r : lp.getRoutes()) {
- removeRoute(lp, r, TO_DEFAULT_TABLE);
+ removeRoute(lp, r, TO_DEFAULT_TABLE,
+ mNetTrackers[info.getType()].getNetwork().netId);
}
} else if (state == NetworkInfo.State.DISCONNECTED) {
handleDisconnect(info);
diff --git a/services/core/java/com/android/server/NetworkManagementService.java b/services/core/java/com/android/server/NetworkManagementService.java
index 24af6b6..a0da2c0 100644
--- a/services/core/java/com/android/server/NetworkManagementService.java
+++ b/services/core/java/com/android/server/NetworkManagementService.java
@@ -868,36 +868,24 @@ public class NetworkManagementService extends INetworkManagementService.Stub
}
@Override
- public void addRoute(String interfaceName, RouteInfo route) {
- mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
- modifyRoute(interfaceName, ADD, route, DEFAULT);
+ public void addRoute(int netId, RouteInfo route) {
+ modifyRoute(netId, ADD, route);
}
@Override
- public void removeRoute(String interfaceName, RouteInfo route) {
- mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
- modifyRoute(interfaceName, REMOVE, route, DEFAULT);
+ public void removeRoute(int netId, RouteInfo route) {
+ modifyRoute(netId, REMOVE, route);
}
- @Override
- public void addSecondaryRoute(String interfaceName, RouteInfo route) {
+ private void modifyRoute(int netId, String action, RouteInfo route) {
mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
- modifyRoute(interfaceName, ADD, route, SECONDARY);
- }
- @Override
- public void removeSecondaryRoute(String interfaceName, RouteInfo route) {
- mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
- modifyRoute(interfaceName, REMOVE, route, SECONDARY);
- }
-
- private void modifyRoute(String interfaceName, String action, RouteInfo route, String type) {
- final Command cmd = new Command("interface", "route", action, interfaceName, type);
+ final Command cmd = new Command("network", "route", action, netId);
- // create triplet: dest-ip-addr prefixlength gateway-ip-addr
+ // create triplet: interface dest-ip-addr/prefixlength gateway-ip-addr
final LinkAddress la = route.getDestination();
- cmd.appendArg(la.getAddress().getHostAddress());
- cmd.appendArg(la.getNetworkPrefixLength());
+ cmd.appendArg(route.getInterface());
+ cmd.appendArg(la.getAddress().getHostAddress() + "/" + la.getNetworkPrefixLength());
cmd.appendArg(route.getGateway().getHostAddress());
try {
@@ -1972,35 +1960,6 @@ public class NetworkManagementService extends INetworkManagementService.Stub
}
@Override
- public void addRouteForNetId(int netId, RouteInfo routeInfo) {
- modifyRouteForNetId(netId, routeInfo, ADD);
- }
-
- @Override
- public void removeRouteForNetId(int netId, RouteInfo routeInfo) {
- modifyRouteForNetId(netId, routeInfo, REMOVE);
- }
-
- private void modifyRouteForNetId(int netId, RouteInfo routeInfo, String action) {
- mContext.enforceCallingOrSelfPermission(CONNECTIVITY_INTERNAL, TAG);
-
- final Command cmd = new Command("network", "route", action, netId);
-
- // create quadlet: dest-ip-addr prefixlength gateway-ip-addr iface
- final LinkAddress la = routeInfo.getDestination();
- cmd.appendArg(la.getAddress().getHostAddress());
- cmd.appendArg(la.getNetworkPrefixLength());
- cmd.appendArg(routeInfo.getGateway().getHostAddress());
- cmd.appendArg(routeInfo.getInterface());
-
- try {
- mConnector.execute(cmd);
- } catch (NativeDaemonConnectorException e) {
- throw e.rethrowAsParcelableException();
- }
- }
-
- @Override
public void addLegacyRouteForNetId(int netId, RouteInfo routeInfo, int uid) {
modifyLegacyRouteForNetId(netId, routeInfo, uid, ADD);
}