summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-01-04 08:43:03 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2023-01-04 08:43:03 +0000
commit9095fd2e894d5caf3b25bad15875cdc69e76eef8 (patch)
tree7fa3ef08ee52e7a994fbd78ce51c30b6291bf152
parent6db48e52d0645575032d2fce2fcd8b0498df39a4 (diff)
parentac107a2ef74cb969603d8bb5224bb344f0e12973 (diff)
downloadnetd-android13-mainline-tethering-release.tar.gz
Snap for 9453251 from ac107a2ef74cb969603d8bb5224bb344f0e12973 to mainline-tethering-releaseaml_tet_331910040aml_tet_331820050aml_tet_331711040android13-mainline-tethering-release
Change-Id: Ifa44f31720082f34c6dc9ce9b00b5622fef8a7bd
-rw-r--r--server/Android.bp3
-rw-r--r--server/BandwidthController.cpp1
-rw-r--r--server/FirewallController.cpp1
-rw-r--r--server/FirewallController.h1
-rw-r--r--server/InterfaceControllerTest.cpp5
-rw-r--r--server/IptablesBaseTest.h4
-rw-r--r--server/IptablesRestoreControllerTest.cpp4
-rw-r--r--server/MDnsSdListener.cpp1
-rw-r--r--server/NFLogListenerTest.cpp3
-rw-r--r--server/NetworkController.cpp1
-rw-r--r--server/SockDiagTest.cpp3
-rw-r--r--server/TcUtils.h5
-rw-r--r--server/TetherController.h1
-rw-r--r--server/XfrmControllerTest.cpp3
-rw-r--r--tests/Android.bp2
-rw-r--r--tests/benchmarks/bpf_benchmark.cpp2
-rw-r--r--tests/binder_test.cpp7
-rw-r--r--tests/bpf_base_test.cpp129
-rw-r--r--tests/sock_diag_test.cpp3
19 files changed, 22 insertions, 157 deletions
diff --git a/server/Android.bp b/server/Android.bp
index 06ea0bab..f9ac8902 100644
--- a/server/Android.bp
+++ b/server/Android.bp
@@ -45,7 +45,6 @@ cc_library_static {
"system/netd/include",
"system/netd/server/binder",
],
- header_libs: ["bpf_headers"],
srcs: [
"BandwidthController.cpp",
"Controllers.cpp",
@@ -100,7 +99,6 @@ cc_binary {
required: [
"bpfloader",
],
- header_libs: ["bpf_headers"],
shared_libs: [
"android.system.net.netd@1.0",
"android.system.net.netd@1.1",
@@ -204,7 +202,6 @@ cc_test {
"system/netd/server/binder",
"system/netd/tests",
],
- header_libs: ["bpf_headers"],
tidy_timeout_srcs: [
"BandwidthControllerTest.cpp",
"InterfaceControllerTest.cpp",
diff --git a/server/BandwidthController.cpp b/server/BandwidthController.cpp
index 8dba75a5..438dbb8d 100644
--- a/server/BandwidthController.cpp
+++ b/server/BandwidthController.cpp
@@ -56,7 +56,6 @@
#include "Fwmark.h"
#include "NetdConstants.h"
#include "android/net/INetd.h"
-#include "bpf/BpfUtils.h"
/* Alphabetical */
#define ALERT_IPT_TEMPLATE "%s %s -m quota2 ! --quota %" PRId64" --name %s\n"
diff --git a/server/FirewallController.cpp b/server/FirewallController.cpp
index b3c6b025..47975dd3 100644
--- a/server/FirewallController.cpp
+++ b/server/FirewallController.cpp
@@ -34,7 +34,6 @@
#include "Controllers.h"
#include "FirewallController.h"
#include "NetdConstants.h"
-#include "bpf/BpfUtils.h"
using android::base::Join;
using android::base::StringAppendF;
diff --git a/server/FirewallController.h b/server/FirewallController.h
index 6d6f48fa..227ceeb9 100644
--- a/server/FirewallController.h
+++ b/server/FirewallController.h
@@ -24,7 +24,6 @@
#include <vector>
#include "NetdConstants.h"
-#include "bpf/BpfUtils.h"
namespace android {
namespace net {
diff --git a/server/InterfaceControllerTest.cpp b/server/InterfaceControllerTest.cpp
index 006018d7..8075431f 100644
--- a/server/InterfaceControllerTest.cpp
+++ b/server/InterfaceControllerTest.cpp
@@ -22,6 +22,7 @@
#include <gtest/gtest.h>
#include <netdutils/MockSyscalls.h>
+#include <netdutils/NetNativeTestBase.h>
#include <netdutils/Utils.h>
#include "InterfaceController.h"
@@ -66,7 +67,7 @@ class MockProperties {
} // namespace
-class StablePrivacyTest : public testing::Test {
+class StablePrivacyTest : public NetNativeTestBase {
protected:
void expectOpenFile(const std::string& path, const Fd fd, int err) {
if (err == 0) {
@@ -179,7 +180,7 @@ TEST_F(StablePrivacyTest, ExistingPropertyWriteFail) {
EXPECT_NE(ok, enableStablePrivacyAddresses(kTestIface));
}
-class GetIfaceListTest : public testing::Test {};
+class GetIfaceListTest : public NetNativeTestBase {};
TEST_F(GetIfaceListTest, IfaceNames) {
StatusOr<std::vector<std::string>> ifaceNames = getIfaceNames();
diff --git a/server/IptablesBaseTest.h b/server/IptablesBaseTest.h
index abe3f84a..bfcc71a1 100644
--- a/server/IptablesBaseTest.h
+++ b/server/IptablesBaseTest.h
@@ -18,9 +18,11 @@
#include <deque>
+#include <netdutils/NetNativeTestBase.h>
+
#include "NetdConstants.h"
-class IptablesBaseTest : public ::testing::Test {
+class IptablesBaseTest : public NetNativeTestBase {
public:
IptablesBaseTest();
diff --git a/server/IptablesRestoreControllerTest.cpp b/server/IptablesRestoreControllerTest.cpp
index a05c76d1..1999fbf9 100644
--- a/server/IptablesRestoreControllerTest.cpp
+++ b/server/IptablesRestoreControllerTest.cpp
@@ -32,10 +32,10 @@
#include <android-base/strings.h>
#include <log/log.h>
#include <netdutils/MockSyscalls.h>
+#include <netdutils/NetNativeTestBase.h>
#include <netdutils/Stopwatch.h>
#include "NetdConstants.h"
-#include "bpf/BpfUtils.h"
#define XT_LOCK_NAME "/system/etc/xtables.lock"
#define XT_LOCK_ATTEMPTS 10
@@ -55,7 +55,7 @@ using android::netdutils::Stopwatch;
using testing::Return;
using testing::StrictMock;
-class IptablesRestoreControllerTest : public ::testing::Test {
+class IptablesRestoreControllerTest : public NetNativeTestBase {
public:
IptablesRestoreController con;
int mDefaultMaxRetries = con.MAX_RETRIES;
diff --git a/server/MDnsSdListener.cpp b/server/MDnsSdListener.cpp
index 1d1ea40a..0a4cd61a 100644
--- a/server/MDnsSdListener.cpp
+++ b/server/MDnsSdListener.cpp
@@ -21,6 +21,7 @@
#include <errno.h>
#include <inttypes.h>
#include <linux/if.h>
+#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <pthread.h>
diff --git a/server/NFLogListenerTest.cpp b/server/NFLogListenerTest.cpp
index 88ab2c61..878c9884 100644
--- a/server/NFLogListenerTest.cpp
+++ b/server/NFLogListenerTest.cpp
@@ -25,6 +25,7 @@
#include <linux/netfilter/nfnetlink_log.h>
#include <netdutils/MockSyscalls.h>
+#include <netdutils/NetNativeTestBase.h>
#include "NFLogListener.h"
using ::testing::_;
@@ -58,7 +59,7 @@ class MockNetlinkListener : public NetlinkListenerInterface {
MOCK_METHOD1(registerSkErrorHandler, void(const SkErrorHandler& handler));
};
-class NFLogListenerTest : public testing::Test {
+class NFLogListenerTest : public NetNativeTestBase {
protected:
NFLogListenerTest() {
EXPECT_CALL(*mNLListener, subscribe(kNFLogPacketMsgType, _))
diff --git a/server/NetworkController.cpp b/server/NetworkController.cpp
index f1441397..ee85910e 100644
--- a/server/NetworkController.cpp
+++ b/server/NetworkController.cpp
@@ -30,6 +30,7 @@
#include <android-base/strings.h>
#include <cutils/misc.h> // FIRST_APPLICATION_UID
#include <netd_resolv/resolv.h>
+#include <net/if.h>
#include "log/log.h"
#include "Controllers.h"
diff --git a/server/SockDiagTest.cpp b/server/SockDiagTest.cpp
index 49601aa4..864d08d5 100644
--- a/server/SockDiagTest.cpp
+++ b/server/SockDiagTest.cpp
@@ -24,6 +24,7 @@
#include <linux/inet_diag.h>
#include <gtest/gtest.h>
+#include <netdutils/NetNativeTestBase.h>
#include "Fwmark.h"
#include "NetdConstants.h"
@@ -33,7 +34,7 @@
namespace android {
namespace net {
-class SockDiagTest : public ::testing::Test {
+class SockDiagTest : public NetNativeTestBase {
protected:
static bool isLoopbackSocket(const inet_diag_msg *msg) {
return SockDiag::isLoopbackSocket(msg);
diff --git a/server/TcUtils.h b/server/TcUtils.h
index 4b1b2b9f..9b157191 100644
--- a/server/TcUtils.h
+++ b/server/TcUtils.h
@@ -16,17 +16,12 @@
#pragma once
-#include <android-base/result.h>
#include <errno.h>
#include <linux/if_ether.h>
#include <linux/if_link.h>
#include <linux/rtnetlink.h>
#include <tcutils/tcutils.h>
-#include <string>
-
-#include "bpf/BpfUtils.h"
-
namespace android {
namespace net {
diff --git a/server/TetherController.h b/server/TetherController.h
index d2195f23..4aa2a2d6 100644
--- a/server/TetherController.h
+++ b/server/TetherController.h
@@ -27,7 +27,6 @@
#include "NetdConstants.h"
#include "android-base/result.h"
-#include "bpf/BpfMap.h"
#include "android/net/TetherOffloadRuleParcel.h"
diff --git a/server/XfrmControllerTest.cpp b/server/XfrmControllerTest.cpp
index e7f5cfc0..f1c38073 100644
--- a/server/XfrmControllerTest.cpp
+++ b/server/XfrmControllerTest.cpp
@@ -41,6 +41,7 @@
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
#include <gtest/gtest.h>
+#include <netdutils/NetNativeTestBase.h>
#include "Fwmark.h"
#include "NetdConstants.h"
@@ -127,7 +128,7 @@ void expectAddressEquals(int family, const std::string& expected, const xfrm_add
EXPECT_EQ(expected, actualStr);
}
-class XfrmControllerTest : public ::testing::Test {
+class XfrmControllerTest : public NetNativeTestBase {
public:
testing::StrictMock<netdutils::ScopedMockSyscalls> mockSyscalls;
};
diff --git a/tests/Android.bp b/tests/Android.bp
index ff918cc1..ea3b2c5b 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -84,13 +84,11 @@ cc_test {
srcs: [
":netd_integration_test_shared",
"binder_test.cpp",
- "bpf_base_test.cpp",
"kernel_test.cpp",
"netd_client_test.cpp",
"netd_test.cpp",
],
include_dirs: ["system/netd/server"],
- header_libs: ["bpf_connectivity_headers"],
shared_libs: [
"libbase",
"libbinder",
diff --git a/tests/benchmarks/bpf_benchmark.cpp b/tests/benchmarks/bpf_benchmark.cpp
index bf4bd541..4614142f 100644
--- a/tests/benchmarks/bpf_benchmark.cpp
+++ b/tests/benchmarks/bpf_benchmark.cpp
@@ -18,8 +18,8 @@
#include <android-base/stringprintf.h>
#include <benchmark/benchmark.h>
+#define BPF_MAP_MAKE_VISIBLE_FOR_TESTING
#include "bpf/BpfMap.h"
-#include "bpf/BpfUtils.h"
constexpr uint32_t TEST_MAP_SIZE = 10000;
diff --git a/tests/binder_test.cpp b/tests/binder_test.cpp
index bc1e7393..5204576d 100644
--- a/tests/binder_test.cpp
+++ b/tests/binder_test.cpp
@@ -52,12 +52,11 @@
#include <android-base/strings.h>
#include <android/multinetwork.h>
#include <binder/IPCThreadState.h>
-#include <bpf/BpfMap.h>
-#include <bpf/BpfUtils.h>
#include <com/android/internal/net/BnOemNetdUnsolicitedEventListener.h>
#include <com/android/internal/net/IOemNetd.h>
#include <cutils/multiuser.h>
#include <gtest/gtest.h>
+#include <netdutils/NetNativeTestBase.h>
#include <netutils/ifc.h>
#include <utils/Errors.h>
#include "Fwmark.h"
@@ -175,7 +174,7 @@ static const in6_addr V6_ADDR = {
{// 2001:db8:cafe::8888
.u6_addr8 = {0x20, 0x01, 0x0d, 0xb8, 0xca, 0xfe, 0, 0, 0, 0, 0, 0, 0, 0, 0x88, 0x88}}};
-class NetdBinderTest : public ::testing::Test {
+class NetdBinderTest : public NetNativeTestBase {
public:
NetdBinderTest() {
sp<IServiceManager> sm = android::defaultServiceManager();
@@ -4792,7 +4791,7 @@ TEST_F(PerAppNetworkPermissionsTest, PermissionOnlyAffectsUid) {
}
}
-class MDnsBinderTest : public ::testing::Test {
+class MDnsBinderTest : public NetNativeTestBase {
public:
MDnsBinderTest() {
sp<IServiceManager> sm = android::defaultServiceManager();
diff --git a/tests/bpf_base_test.cpp b/tests/bpf_base_test.cpp
deleted file mode 100644
index e402e08e..00000000
--- a/tests/bpf_base_test.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string>
-
-#include <fcntl.h>
-#include <inttypes.h>
-#include <limits.h>
-#include <linux/inet_diag.h>
-#include <linux/sock_diag.h>
-#include <net/if.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include <gtest/gtest.h>
-
-#include <cutils/qtaguid.h>
-#include <processgroup/processgroup.h>
-
-#include <android-base/stringprintf.h>
-#include <android-base/strings.h>
-
-#include "bpf/BpfMap.h"
-#include "bpf/BpfUtils.h"
-#include "bpf_shared.h"
-
-using android::base::Result;
-
-namespace android {
-namespace bpf {
-
-// Use the upper limit of uid to avoid conflict with real app uids. We can't use UID_MAX because
-// it's -1, which is INVALID_UID.
-constexpr uid_t TEST_UID = UID_MAX - 1;
-constexpr uint32_t TEST_TAG = 42;
-
-class BpfBasicTest : public testing::Test {
- protected:
- BpfBasicTest() {}
-};
-
-TEST_F(BpfBasicTest, TestCgroupMounted) {
- std::string cg2_path;
- ASSERT_EQ(true, CgroupGetControllerPath(CGROUPV2_CONTROLLER_NAME, &cg2_path));
- ASSERT_EQ(0, access(cg2_path.c_str(), R_OK));
- ASSERT_EQ(0, access((cg2_path + "/cgroup.controllers").c_str(), R_OK));
-}
-
-TEST_F(BpfBasicTest, TestTrafficControllerSetUp) {
- ASSERT_EQ(0, access(BPF_EGRESS_PROG_PATH, R_OK));
- ASSERT_EQ(0, access(BPF_INGRESS_PROG_PATH, R_OK));
- ASSERT_EQ(0, access(XT_BPF_INGRESS_PROG_PATH, R_OK));
- ASSERT_EQ(0, access(XT_BPF_EGRESS_PROG_PATH, R_OK));
- ASSERT_EQ(0, access(COOKIE_TAG_MAP_PATH, R_OK));
- ASSERT_EQ(0, access(UID_COUNTERSET_MAP_PATH, R_OK));
- ASSERT_EQ(0, access(STATS_MAP_A_PATH, R_OK));
- ASSERT_EQ(0, access(STATS_MAP_B_PATH, R_OK));
- ASSERT_EQ(0, access(IFACE_INDEX_NAME_MAP_PATH, R_OK));
- ASSERT_EQ(0, access(IFACE_STATS_MAP_PATH, R_OK));
- ASSERT_EQ(0, access(CONFIGURATION_MAP_PATH, R_OK));
- ASSERT_EQ(0, access(UID_OWNER_MAP_PATH, R_OK));
-}
-
-TEST_F(BpfBasicTest, TestSocketFilterSetUp) {
- SKIP_IF_EXTENDED_BPF_NOT_SUPPORTED;
-
- ASSERT_EQ(0, access(CGROUP_SOCKET_PROG_PATH, R_OK));
- ASSERT_EQ(0, access(UID_PERMISSION_MAP_PATH, R_OK));
-}
-
-TEST_F(BpfBasicTest, TestTagSocket) {
- BpfMap<uint64_t, UidTagValue> cookieTagMap(COOKIE_TAG_MAP_PATH);
- ASSERT_LE(0, cookieTagMap.getMap());
- int sock = socket(AF_INET6, SOCK_STREAM | SOCK_CLOEXEC, 0);
- ASSERT_LE(0, sock);
- uint64_t cookie = getSocketCookie(sock);
- ASSERT_NE(NONEXISTENT_COOKIE, cookie);
- ASSERT_EQ(0, qtaguid_tagSocket(sock, TEST_TAG, TEST_UID));
- Result<UidTagValue> tagResult = cookieTagMap.readValue(cookie);
- ASSERT_RESULT_OK(tagResult);
- ASSERT_EQ(TEST_UID, tagResult.value().uid);
- ASSERT_EQ(TEST_TAG, tagResult.value().tag);
- ASSERT_EQ(0, qtaguid_untagSocket(sock));
- tagResult = cookieTagMap.readValue(cookie);
- ASSERT_FALSE(tagResult.ok());
- ASSERT_EQ(ENOENT, tagResult.error().code());
-}
-
-TEST_F(BpfBasicTest, TestCloseSocketWithoutUntag) {
- BpfMap<uint64_t, UidTagValue> cookieTagMap(COOKIE_TAG_MAP_PATH);
- ASSERT_LE(0, cookieTagMap.getMap());
- int sock = socket(AF_INET6, SOCK_STREAM | SOCK_CLOEXEC, 0);
- ASSERT_LE(0, sock);
- uint64_t cookie = getSocketCookie(sock);
- ASSERT_NE(NONEXISTENT_COOKIE, cookie);
- ASSERT_EQ(0, qtaguid_tagSocket(sock, TEST_TAG, TEST_UID));
- Result<UidTagValue> tagResult = cookieTagMap.readValue(cookie);
- ASSERT_RESULT_OK(tagResult);
- ASSERT_EQ(TEST_UID, tagResult.value().uid);
- ASSERT_EQ(TEST_TAG, tagResult.value().tag);
- ASSERT_EQ(0, close(sock));
- // Check map periodically until sk destroy handler have done its job.
- for (int i = 0; i < 10; i++) {
- usleep(5000); // 5ms
- tagResult = cookieTagMap.readValue(cookie);
- if (!tagResult.ok()) {
- ASSERT_EQ(ENOENT, tagResult.error().code());
- return;
- }
- }
- FAIL() << "socket tag still exist after 50ms";
-}
-
-}
-}
diff --git a/tests/sock_diag_test.cpp b/tests/sock_diag_test.cpp
index 8ee99083..5d142dc4 100644
--- a/tests/sock_diag_test.cpp
+++ b/tests/sock_diag_test.cpp
@@ -21,6 +21,7 @@
#include <linux/inet_diag.h>
#include <gtest/gtest.h>
+#include <netdutils/NetNativeTestBase.h>
#include "NetdConstants.h"
#include "SockDiag.h"
@@ -29,7 +30,7 @@
#define NUM_SOCKETS 500
-class SockDiagTest : public ::testing::Test {
+class SockDiagTest : public NetNativeTestBase {
};
uint16_t bindAndListen(int s) {