share eBPF struct definitions between ebpf and C++ netd
This is the main commit in a set of 3 commits across 3 diff git repos.
The other two are:
https://android-review.googlesource.com/c/platform/system/bpf/+/1199649
"remove network specific struct definitions from BpfUtils.h"
and
https://android-review.googlesource.com/c/platform/frameworks/base/+/1200738
"minor change to keep it building"
We move the struct definitions to bpf_shared.h so they can be
shared between C++ netd and C ebpf code.
They also become typedefs and are renamed for more consistent naming.
(there's some weird issue with ebpf compiler on some devices with
non-typedef'ed structs)
Test: builds, atest
Bug: 146787904
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I324c0ab9db0186dcea0ec9ee33140909be285bc4
diff --git a/tests/bpf_base_test.cpp b/tests/bpf_base_test.cpp
index 46e4306..fa0a589 100644
--- a/tests/bpf_base_test.cpp
+++ b/tests/bpf_base_test.cpp
@@ -100,14 +100,14 @@
TEST_F(BpfBasicTest, TestTagSocket) {
SKIP_IF_BPF_NOT_SUPPORTED;
- BpfMap<uint64_t, UidTag> cookieTagMap(mapRetrieve(COOKIE_TAG_MAP_PATH, 0));
+ BpfMap<uint64_t, UidTagValue> cookieTagMap(mapRetrieve(COOKIE_TAG_MAP_PATH, 0));
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));
- StatusOr<UidTag> tagResult = cookieTagMap.readValue(cookie);
+ StatusOr<UidTagValue> tagResult = cookieTagMap.readValue(cookie);
ASSERT_TRUE(isOk(tagResult));
ASSERT_EQ(TEST_UID, tagResult.value().uid);
ASSERT_EQ(TEST_TAG, tagResult.value().tag);
@@ -120,14 +120,14 @@
TEST_F(BpfBasicTest, TestCloseSocketWithoutUntag) {
SKIP_IF_BPF_NOT_SUPPORTED;
- BpfMap<uint64_t, UidTag> cookieTagMap(mapRetrieve(COOKIE_TAG_MAP_PATH, 0));
+ BpfMap<uint64_t, UidTagValue> cookieTagMap(mapRetrieve(COOKIE_TAG_MAP_PATH, 0));
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));
- StatusOr<UidTag> tagResult = cookieTagMap.readValue(cookie);
+ StatusOr<UidTagValue> tagResult = cookieTagMap.readValue(cookie);
ASSERT_TRUE(isOk(tagResult));
ASSERT_EQ(TEST_UID, tagResult.value().uid);
ASSERT_EQ(TEST_TAG, tagResult.value().tag);