Move CookieTag map dump to BpfNetMaps
Also removes dump tests in TrafficController Bug: 217624062 Test: atest BpfNetMaps TagSocketTest Change-Id: I92adad60c55443435d7c7a0bfc84b38162fd51b0
This commit is contained in:
@@ -595,7 +595,7 @@ void dumpBpfMap(const std::string& mapName, DumpWriter& dw, const std::string& h
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrafficController::dump(int fd, bool verbose) {
|
void TrafficController::dump(int fd, bool verbose __unused) {
|
||||||
std::lock_guard guard(mMutex);
|
std::lock_guard guard(mMutex);
|
||||||
DumpWriter dw(fd);
|
DumpWriter dw(fd);
|
||||||
|
|
||||||
@@ -623,31 +623,6 @@ void TrafficController::dump(int fd, bool verbose) {
|
|||||||
getMapStatus(mConfigurationMap.getMap(), CONFIGURATION_MAP_PATH).c_str());
|
getMapStatus(mConfigurationMap.getMap(), CONFIGURATION_MAP_PATH).c_str());
|
||||||
dw.println("mUidOwnerMap status: %s",
|
dw.println("mUidOwnerMap status: %s",
|
||||||
getMapStatus(mUidOwnerMap.getMap(), UID_OWNER_MAP_PATH).c_str());
|
getMapStatus(mUidOwnerMap.getMap(), UID_OWNER_MAP_PATH).c_str());
|
||||||
|
|
||||||
if (!verbose) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
dw.blankline();
|
|
||||||
dw.println("BPF map content:");
|
|
||||||
|
|
||||||
ScopedIndent indentForMapContent(dw);
|
|
||||||
|
|
||||||
// Print CookieTagMap content.
|
|
||||||
// TagSocketTest in CTS was using the output of mCookieTagMap dump.
|
|
||||||
// So, mCookieTagMap dump can not be removed until the previous CTS support period is over.
|
|
||||||
dumpBpfMap("mCookieTagMap", dw, "");
|
|
||||||
const auto printCookieTagInfo = [&dw](const uint64_t& key, const UidTagValue& value,
|
|
||||||
const BpfMap<uint64_t, UidTagValue>&) {
|
|
||||||
dw.println("cookie=%" PRIu64 " tag=0x%x uid=%u", key, value.tag, value.uid);
|
|
||||||
return base::Result<void>();
|
|
||||||
};
|
|
||||||
base::Result<void> res = mCookieTagMap.iterateWithValue(printCookieTagInfo);
|
|
||||||
if (!res.ok()) {
|
|
||||||
dw.println("mCookieTagMap print end with error: %s", res.error().message().c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
dw.blankline();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace net
|
} // namespace net
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ constexpr uid_t TEST_UID2 = 54321;
|
|||||||
constexpr uid_t TEST_UID3 = 98765;
|
constexpr uid_t TEST_UID3 = 98765;
|
||||||
constexpr uint32_t TEST_TAG = 42;
|
constexpr uint32_t TEST_TAG = 42;
|
||||||
constexpr uint32_t TEST_COUNTERSET = 1;
|
constexpr uint32_t TEST_COUNTERSET = 1;
|
||||||
constexpr int TEST_COOKIE = 1;
|
|
||||||
constexpr int TEST_IFINDEX = 999;
|
constexpr int TEST_IFINDEX = 999;
|
||||||
constexpr int RXPACKETS = 1;
|
constexpr int RXPACKETS = 1;
|
||||||
constexpr int RXBYTES = 100;
|
constexpr int RXBYTES = 100;
|
||||||
@@ -769,46 +768,6 @@ TEST_F(TrafficControllerTest, TestGrantDuplicatePermissionSlientlyFail) {
|
|||||||
expectPrivilegedUserSetEmpty();
|
expectPrivilegedUserSetEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(TrafficControllerTest, TestDumpsys) {
|
|
||||||
StatsKey tagStatsMapKey;
|
|
||||||
populateFakeStats(TEST_COOKIE, TEST_UID, TEST_TAG, &tagStatsMapKey);
|
|
||||||
populateFakeCounterSet(TEST_UID3, TEST_COUNTERSET);
|
|
||||||
|
|
||||||
// Expect: (part of this depends on hard-code values in populateFakeStats())
|
|
||||||
//
|
|
||||||
// mCookieTagMap:
|
|
||||||
// cookie=1 tag=0x2a uid=10086
|
|
||||||
//
|
|
||||||
// mUidCounterSetMap:
|
|
||||||
// 98765 1
|
|
||||||
//
|
|
||||||
// mAppUidStatsMap::
|
|
||||||
// uid rxBytes rxPackets txBytes txPackets
|
|
||||||
// 10086 100 1 0 0
|
|
||||||
//
|
|
||||||
// mStatsMapA:
|
|
||||||
// ifaceIndex ifaceName tag_hex uid_int cnt_set rxBytes rxPackets txBytes txPackets
|
|
||||||
// 999 test0 0x2a 10086 1 100 1 0 0
|
|
||||||
std::vector<std::string> expectedLines = {
|
|
||||||
"mCookieTagMap:",
|
|
||||||
fmt::format("cookie={} tag={:#x} uid={}", TEST_COOKIE, TEST_TAG, TEST_UID)};
|
|
||||||
|
|
||||||
EXPECT_TRUE(expectDumpsysContains(expectedLines));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(TrafficControllerTest, dumpsysInvalidMaps) {
|
|
||||||
makeTrafficControllerMapsInvalid();
|
|
||||||
|
|
||||||
const std::string kErrIterate = "print end with error: Get firstKey map -1 failed: "
|
|
||||||
"Bad file descriptor";
|
|
||||||
const std::string kErrReadRulesConfig = "read ownerMatch configure failed with error: "
|
|
||||||
"Read value of map -1 failed: Bad file descriptor";
|
|
||||||
|
|
||||||
std::vector<std::string> expectedLines = {
|
|
||||||
fmt::format("mCookieTagMap {}", kErrIterate)};
|
|
||||||
EXPECT_TRUE(expectDumpsysContains(expectedLines));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(TrafficControllerTest, getFirewallType) {
|
TEST_F(TrafficControllerTest, getFirewallType) {
|
||||||
static const struct TestConfig {
|
static const struct TestConfig {
|
||||||
ChildChain childChain;
|
ChildChain childChain;
|
||||||
|
|||||||
@@ -1023,10 +1023,22 @@ public class BpfNetMaps {
|
|||||||
mDeps.nativeDump(fd, verbose);
|
mDeps.nativeDump(fd, verbose);
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
|
pw.println();
|
||||||
|
pw.println("BPF map content:");
|
||||||
|
pw.increaseIndent();
|
||||||
|
|
||||||
dumpOwnerMatchConfig(pw);
|
dumpOwnerMatchConfig(pw);
|
||||||
dumpCurrentStatsMapConfig(pw);
|
dumpCurrentStatsMapConfig(pw);
|
||||||
pw.println();
|
pw.println();
|
||||||
|
|
||||||
|
// TODO: Remove CookieTagMap content dump
|
||||||
|
// NetworkStatsService also dumps CookieTagMap and NetworkStatsService is a right place
|
||||||
|
// to dump CookieTagMap. But the TagSocketTest in CTS depends on this dump so the tests
|
||||||
|
// need to be updated before remove the dump from BpfNetMaps.
|
||||||
|
BpfDump.dumpMap(sCookieTagMap, pw, "sCookieTagMap",
|
||||||
|
(key, value) -> "cookie=" + key.socketCookie
|
||||||
|
+ " tag=0x" + Long.toHexString(value.tag)
|
||||||
|
+ " uid=" + value.uid);
|
||||||
BpfDump.dumpMap(sUidOwnerMap, pw, "sUidOwnerMap",
|
BpfDump.dumpMap(sUidOwnerMap, pw, "sUidOwnerMap",
|
||||||
(uid, match) -> {
|
(uid, match) -> {
|
||||||
if ((match.rule & IIF_MATCH) != 0) {
|
if ((match.rule & IIF_MATCH) != 0) {
|
||||||
@@ -1038,6 +1050,7 @@ public class BpfNetMaps {
|
|||||||
});
|
});
|
||||||
BpfDump.dumpMap(sUidPermissionMap, pw, "sUidPermissionMap",
|
BpfDump.dumpMap(sUidPermissionMap, pw, "sUidPermissionMap",
|
||||||
(uid, permission) -> uid.val + " " + permissionToString(permission.val));
|
(uid, permission) -> uid.val + " " + permissionToString(permission.val));
|
||||||
|
pw.decreaseIndent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1070,4 +1070,11 @@ public final class BpfNetMapsTest {
|
|||||||
doTestDumpOwnerMatchConfig(DOZABLE_MATCH | invalid_match,
|
doTestDumpOwnerMatchConfig(DOZABLE_MATCH | invalid_match,
|
||||||
"DOZABLE_MATCH UNKNOWN_MATCH(" + invalid_match + ")");
|
"DOZABLE_MATCH UNKNOWN_MATCH(" + invalid_match + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@IgnoreUpTo(Build.VERSION_CODES.S_V2)
|
||||||
|
public void testDumpCookieTagMap() throws Exception {
|
||||||
|
mCookieTagMap.updateEntry(new CookieTagMapKey(123), new CookieTagMapValue(456, 0x789));
|
||||||
|
assertDumpContains(getDump(), "cookie=123 tag=0x789 uid=456");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user