Update underlying network of IpSecTunnelInterface

Bug: 169855650
Test: atest IpSecManagerTunnelTest
Change-Id: I6d1b8d0e49f89c67ddc2caf4ba63fb0b1eb062c0
This commit is contained in:
Yan Yan
2020-09-29 23:38:00 -07:00
parent 5e1ec81e2f
commit a2f3b49f10
3 changed files with 90 additions and 4 deletions

View File

@@ -58,6 +58,9 @@ interface IIpSecService
in LinkAddress localAddr,
in String callingPackage);
void setNetworkForTunnelInterface(
int tunnelResourceId, in Network underlyingNetwork, in String callingPackage);
void deleteTunnelInterface(int resourceId, in String callingPackage);
IpSecTransformResponse createTransform(

View File

@@ -782,6 +782,43 @@ public final class IpSecManager {
}
}
/**
* Update the underlying network for this IpSecTunnelInterface.
*
* <p>This new underlying network will be used for all transforms applied AFTER this call is
* complete. Before new {@link IpSecTransform}(s) with matching addresses are applied to
* this tunnel interface, traffic will still use the old SA, and be routed on the old
* underlying network.
*
* <p>To migrate IPsec tunnel mode traffic, a caller should:
*
* <ol>
* <li>Update the IpSecTunnelInterfaces underlying network.
* <li>Apply {@link IpSecTransform}(s) with matching addresses to this
* IpSecTunnelInterface.
* </ol>
*
* @param underlyingNetwork the new {@link Network} that will carry traffic for this tunnel.
* This network MUST never be the network exposing this IpSecTunnelInterface, otherwise
* this method will throw an {@link IllegalArgumentException}.
* @hide
*/
// TODO: b/169171001 Update the documentation when transform migration is supported.
// The purpose of making updating network and applying transforms separate is to leave open
// the possibility to support lossless migration procedures. To do that, Android platform
// will need to support multiple inbound tunnel mode transforms, just like it can support
// multiple transport mode transforms.
@RequiresFeature(PackageManager.FEATURE_IPSEC_TUNNELS)
@RequiresPermission(android.Manifest.permission.MANAGE_IPSEC_TUNNELS)
public void setUnderlyingNetwork(@NonNull Network underlyingNetwork) throws IOException {
try {
mService.setNetworkForTunnelInterface(
mResourceId, underlyingNetwork, mOpPackageName);
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
private IpSecTunnelInterface(@NonNull Context ctx, @NonNull IIpSecService service,
@NonNull InetAddress localAddress, @NonNull InetAddress remoteAddress,
@NonNull Network underlyingNetwork)