Specify netId when adding/removing routes.
Change-Id: I07fd950aee726e9721153f75c3e4c10d8e19d8e9
This commit is contained in:
committed by
Lorenzo Colitti
parent
79a1058480
commit
b2829fa165
@@ -99,24 +99,12 @@ interface INetworkManagementService
|
||||
/**
|
||||
* Add the specified route to the interface.
|
||||
*/
|
||||
void addRoute(String iface, in RouteInfo route);
|
||||
void addRoute(int netId, in RouteInfo route);
|
||||
|
||||
/**
|
||||
* Remove the specified route from the interface.
|
||||
*/
|
||||
void removeRoute(String iface, in RouteInfo route);
|
||||
|
||||
/**
|
||||
* Add the specified route to a secondary interface
|
||||
* This will go into a special route table to be accessed
|
||||
* via ip rules
|
||||
*/
|
||||
void addSecondaryRoute(String iface, in RouteInfo route);
|
||||
|
||||
/**
|
||||
* Remove the specified secondary route.
|
||||
*/
|
||||
void removeSecondaryRoute(String iface, in RouteInfo route);
|
||||
void removeRoute(int netId, in RouteInfo route);
|
||||
|
||||
/**
|
||||
* Set the specified MTU size
|
||||
@@ -431,9 +419,6 @@ interface INetworkManagementService
|
||||
*/
|
||||
void removeNetwork(int netId);
|
||||
|
||||
void addRouteForNetId(int netId, in RouteInfo routeInfo);
|
||||
void removeRouteForNetId(int netId, in RouteInfo routeInfo);
|
||||
|
||||
void addLegacyRouteForNetId(int netId, in RouteInfo routeInfo, int uid);
|
||||
void removeLegacyRouteForNetId(int netId, in RouteInfo routeInfo, int uid);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
final Command cmd = new Command("network", "route", action, netId);
|
||||
|
||||
private void modifyRoute(String interfaceName, String action, RouteInfo route, String type) {
|
||||
final Command cmd = new Command("interface", "route", action, interfaceName, type);
|
||||
|
||||
// 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 {
|
||||
@@ -1971,35 +1959,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);
|
||||
|
||||
Reference in New Issue
Block a user