commit | b73b5e5183dde337f6a8f0b2939c3e07d7bc9db8 | [log] [tgz] |
---|---|---|
author | Motomu Utsumi <motomuman@google.com> | Wed Mar 29 15:20:56 2023 +0900 |
committer | Cherrypicker Worker <android-build-cherrypicker-worker@google.com> | Fri May 12 10:07:46 2023 +0000 |
tree | 4b72979d4b7b367f4a241132a37a7ed8be85157c | |
parent | c80be403c0b4702670637c4342d6f3bf5d0ebd3c [diff] |
Close sockets from ConnectivityService#setFirewallChainEnabled And replace netd.socketDestroy by Java implementation Bug: 270298713 Test: atest FrameworksNetTests CtsNetTestCases (cherry picked from https://android-review.googlesource.com/q/commit:c279918639e9b46ce1bba420daffda08cfad6bd1) Merged-In: I744b98ac1be04a1aede9d96787305e5a1a9d9ae6 Change-Id: I744b98ac1be04a1aede9d96787305e5a1a9d9ae6
diff --git a/common/device/com/android/net/module/util/netlink/InetDiagMessage.java b/common/device/com/android/net/module/util/netlink/InetDiagMessage.java index d462c53..e69a844 100644 --- a/common/device/com/android/net/module/util/netlink/InetDiagMessage.java +++ b/common/device/com/android/net/module/util/netlink/InetDiagMessage.java
@@ -468,6 +468,23 @@ && !isAdbSocket(diagMsg)); } + /** + * Close tcp sockets that match the following condition + * 1. TCP status is one of TCP_ESTABLISHED, TCP_SYN_SENT, and TCP_SYN_RECV + * 2. Owner uid of socket is in the targetUids + * 3. Socket is not loopback + * 4. Socket is not adb socket + * + * @param ownerUids target uids to close sockets + */ + public static void destroyLiveTcpSocketsByOwnerUids(Set<Integer> ownerUids) + throws SocketException, InterruptedIOException, ErrnoException { + destroySockets(IPPROTO_TCP, TCP_ALIVE_STATE_FILTER, + (diagMsg) -> ownerUids.contains(diagMsg.inetDiagMsg.idiag_uid) + && !isLoopback(diagMsg) + && !isAdbSocket(diagMsg)); + } + @Override public String toString() { return "InetDiagMessage{ "