summaryrefslogtreecommitdiff
path: root/netd/BpfHandlerTest.cpp
diff options
context:
space:
mode:
authorHungming Chen <nuccachen@google.com>2022-03-07 14:13:49 +0800
committerHungming Chen <nuccachen@google.com>2022-03-07 16:04:32 +0800
commitbcc0f5b14fbcf63c06cce1cd04cfa0e8282d2762 (patch)
tree4725908240474a9ef0033ca0469425be9028df45 /netd/BpfHandlerTest.cpp
parent478c0eb21c1be93e9baa762c1d69f0057a5941fe (diff)
BpfHandler: only allow to tag INET/INET6 socket
This is a follow up commit for the family validation {INET, INET6}. The protocol validation {TCP, UDP} has been added in previous commit. The TrafficController socket destroy listener only monitors on the group {INET_TCP, INET_UDP, INET6_TCP, INET6_UDP}. Tagging listener unsupported socket causes that the tag can't be removed from tag map automatically. Eventually, the tag map run out of space because of dead tag entries. See TrafficController::makeSkDestroyListener in packages/modules/Connectivity/service/native/TrafficController.cpp Also address the comments from previous commit. - Remove the useless else-statment in tagSocket protocol validation. - Make the socket cookie query and test into one line in BpfHandlerTest#TestTagSocketWithUnsupportedProtocol Bug: 223094609 Test: atest BpfHandlerTest Change-Id: I0f571fc00caa01c86399f0dbb593e8a40ad94bbd
Diffstat (limited to 'netd/BpfHandlerTest.cpp')
-rw-r--r--netd/BpfHandlerTest.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/netd/BpfHandlerTest.cpp b/netd/BpfHandlerTest.cpp
index 66a2f803a3..cd6b565653 100644
--- a/netd/BpfHandlerTest.cpp
+++ b/netd/BpfHandlerTest.cpp
@@ -188,11 +188,17 @@ TEST_F(BpfHandlerTest, TestTagInvalidSocket) {
expectMapEmpty(mFakeCookieTagMap);
}
+TEST_F(BpfHandlerTest, TestTagSocketWithUnsupportedFamily) {
+ int packetSocket = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
+ EXPECT_LE(0, packetSocket);
+ EXPECT_NE(NONEXISTENT_COOKIE, getSocketCookie(packetSocket));
+ EXPECT_EQ(-EAFNOSUPPORT, mBh.tagSocket(packetSocket, TEST_TAG, TEST_UID, TEST_UID));
+}
+
TEST_F(BpfHandlerTest, TestTagSocketWithUnsupportedProtocol) {
int rawSocket = socket(AF_INET, SOCK_RAW | SOCK_CLOEXEC, IPPROTO_RAW);
EXPECT_LE(0, rawSocket);
- uint64_t sockCookie = getSocketCookie(rawSocket);
- EXPECT_NE(NONEXISTENT_COOKIE, sockCookie);
+ EXPECT_NE(NONEXISTENT_COOKIE, getSocketCookie(rawSocket));
EXPECT_EQ(-EPROTONOSUPPORT, mBh.tagSocket(rawSocket, TEST_TAG, TEST_UID, TEST_UID));
}