Merge "Use netd socketDestroy for VPN in T-" am: d8b852fc06
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Connectivity/+/2614310 Change-Id: I3896472d57dfa12a0b5554af6aa85b4699761134 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
fb2ec37ecd
2 changed files with 32 additions and 11 deletions
|
|
@ -8620,10 +8620,18 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maybeCloseSockets(NetworkAgentInfo nai, Set<UidRange> ranges,
|
private void maybeCloseSockets(NetworkAgentInfo nai, Set<UidRange> ranges,
|
||||||
Set<Integer> exemptUids) {
|
UidRangeParcel[] uidRangeParcels, int[] exemptUids) {
|
||||||
if (nai.isVPN() && !nai.networkAgentConfig.allowBypass) {
|
if (nai.isVPN() && !nai.networkAgentConfig.allowBypass) {
|
||||||
try {
|
try {
|
||||||
mDeps.destroyLiveTcpSockets(UidRange.toIntRanges(ranges), exemptUids);
|
if (mDeps.isAtLeastU()) {
|
||||||
|
final Set<Integer> exemptUidSet = new ArraySet<>();
|
||||||
|
for (final int uid: exemptUids) {
|
||||||
|
exemptUidSet.add(uid);
|
||||||
|
}
|
||||||
|
mDeps.destroyLiveTcpSockets(UidRange.toIntRanges(ranges), exemptUidSet);
|
||||||
|
} else {
|
||||||
|
mNetd.socketDestroy(uidRangeParcels, exemptUids);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
loge("Exception in socket destroy: ", e);
|
loge("Exception in socket destroy: ", e);
|
||||||
}
|
}
|
||||||
|
|
@ -8631,16 +8639,16 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateVpnUidRanges(boolean add, NetworkAgentInfo nai, Set<UidRange> uidRanges) {
|
private void updateVpnUidRanges(boolean add, NetworkAgentInfo nai, Set<UidRange> uidRanges) {
|
||||||
final Set<Integer> exemptUids = new ArraySet<>();
|
int[] exemptUids = new int[2];
|
||||||
// TODO: Excluding VPN_UID is necessary in order to not to kill the TCP connection used
|
// TODO: Excluding VPN_UID is necessary in order to not to kill the TCP connection used
|
||||||
// by PPTP. Fix this by making Vpn set the owner UID to VPN_UID instead of system when
|
// by PPTP. Fix this by making Vpn set the owner UID to VPN_UID instead of system when
|
||||||
// starting a legacy VPN, and remove VPN_UID here. (b/176542831)
|
// starting a legacy VPN, and remove VPN_UID here. (b/176542831)
|
||||||
exemptUids.add(VPN_UID);
|
exemptUids[0] = VPN_UID;
|
||||||
exemptUids.add(nai.networkCapabilities.getOwnerUid());
|
exemptUids[1] = nai.networkCapabilities.getOwnerUid();
|
||||||
UidRangeParcel[] ranges = toUidRangeStableParcels(uidRanges);
|
UidRangeParcel[] ranges = toUidRangeStableParcels(uidRanges);
|
||||||
|
|
||||||
// Close sockets before modifying uid ranges so that RST packets can reach to the server.
|
// Close sockets before modifying uid ranges so that RST packets can reach to the server.
|
||||||
maybeCloseSockets(nai, uidRanges, exemptUids);
|
maybeCloseSockets(nai, uidRanges, ranges, exemptUids);
|
||||||
try {
|
try {
|
||||||
if (add) {
|
if (add) {
|
||||||
mNetd.networkAddUidRangesParcel(new NativeUidRangeConfig(
|
mNetd.networkAddUidRangesParcel(new NativeUidRangeConfig(
|
||||||
|
|
@ -8654,7 +8662,7 @@ public class ConnectivityService extends IConnectivityManager.Stub
|
||||||
" on netId " + nai.network.netId + ". " + e);
|
" on netId " + nai.network.netId + ". " + e);
|
||||||
}
|
}
|
||||||
// Close sockets that established connection while requesting netd.
|
// Close sockets that established connection while requesting netd.
|
||||||
maybeCloseSockets(nai, uidRanges, exemptUids);
|
maybeCloseSockets(nai, uidRanges, ranges, exemptUids);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isProxySetOnAnyDefaultNetwork() {
|
private boolean isProxySetOnAnyDefaultNetwork() {
|
||||||
|
|
|
||||||
|
|
@ -12931,9 +12931,16 @@ public class ConnectivityServiceTest {
|
||||||
throws Exception {
|
throws Exception {
|
||||||
InOrder inOrder = inOrder(mMockNetd, mDestroySocketsWrapper);
|
InOrder inOrder = inOrder(mMockNetd, mDestroySocketsWrapper);
|
||||||
final Set<Integer> exemptUidSet = new ArraySet<>(List.of(exemptUid, Process.VPN_UID));
|
final Set<Integer> exemptUidSet = new ArraySet<>(List.of(exemptUid, Process.VPN_UID));
|
||||||
|
ArgumentCaptor<int[]> exemptUidCaptor = ArgumentCaptor.forClass(int[].class);
|
||||||
|
|
||||||
inOrder.verify(mDestroySocketsWrapper).destroyLiveTcpSockets(
|
if (mDeps.isAtLeastU()) {
|
||||||
UidRange.toIntRanges(vpnRanges), exemptUidSet);
|
inOrder.verify(mDestroySocketsWrapper).destroyLiveTcpSockets(
|
||||||
|
UidRange.toIntRanges(vpnRanges), exemptUidSet);
|
||||||
|
} else {
|
||||||
|
inOrder.verify(mMockNetd).socketDestroy(eq(toUidRangeStableParcels(vpnRanges)),
|
||||||
|
exemptUidCaptor.capture());
|
||||||
|
assertContainsExactly(exemptUidCaptor.getValue(), Process.VPN_UID, exemptUid);
|
||||||
|
}
|
||||||
|
|
||||||
if (add) {
|
if (add) {
|
||||||
inOrder.verify(mMockNetd, times(1)).networkAddUidRangesParcel(
|
inOrder.verify(mMockNetd, times(1)).networkAddUidRangesParcel(
|
||||||
|
|
@ -12945,8 +12952,14 @@ public class ConnectivityServiceTest {
|
||||||
toUidRangeStableParcels(vpnRanges), PREFERENCE_ORDER_VPN));
|
toUidRangeStableParcels(vpnRanges), PREFERENCE_ORDER_VPN));
|
||||||
}
|
}
|
||||||
|
|
||||||
inOrder.verify(mDestroySocketsWrapper).destroyLiveTcpSockets(
|
if (mDeps.isAtLeastU()) {
|
||||||
UidRange.toIntRanges(vpnRanges), exemptUidSet);
|
inOrder.verify(mDestroySocketsWrapper).destroyLiveTcpSockets(
|
||||||
|
UidRange.toIntRanges(vpnRanges), exemptUidSet);
|
||||||
|
} else {
|
||||||
|
inOrder.verify(mMockNetd).socketDestroy(eq(toUidRangeStableParcels(vpnRanges)),
|
||||||
|
exemptUidCaptor.capture());
|
||||||
|
assertContainsExactly(exemptUidCaptor.getValue(), Process.VPN_UID, exemptUid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue