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);
diff --git a/tests/netlink_listener_test.cpp b/tests/netlink_listener_test.cpp
index 94e9524..269c1bf 100644
--- a/tests/netlink_listener_test.cpp
+++ b/tests/netlink_listener_test.cpp
@@ -64,7 +64,7 @@
class NetlinkListenerTest : public testing::Test {
protected:
NetlinkListenerTest() {}
- BpfMap<uint64_t, UidTag> mCookieTagMap;
+ BpfMap<uint64_t, UidTagValue> mCookieTagMap;
void SetUp() {
SKIP_IF_BPF_NOT_SUPPORTED;
@@ -76,8 +76,8 @@
void TearDown() {
SKIP_IF_BPF_NOT_SUPPORTED;
- const auto deleteTestCookieEntries = [](const uint64_t& key, const UidTag& value,
- BpfMap<uint64_t, UidTag>& map) {
+ const auto deleteTestCookieEntries = [](const uint64_t& key, const UidTagValue& value,
+ BpfMap<uint64_t, UidTagValue>& map) {
if ((value.uid == TEST_UID) && (value.tag == TEST_TAG)) {
Status res = map.deleteValue(key);
if (isOk(res) || (res.code() == ENOENT)) {
@@ -93,8 +93,8 @@
}
Status checkNoGarbageTagsExist() {
- const auto checkGarbageTags = [](const uint64_t&, const UidTag& value,
- const BpfMap<uint64_t, UidTag>&) {
+ const auto checkGarbageTags = [](const uint64_t&, const UidTagValue& value,
+ const BpfMap<uint64_t, UidTagValue>&) {
if ((TEST_UID == value.uid) && (TEST_TAG == value.tag)) {
return statusFromErrno(EUCLEAN, "Closed socket is not untagged");
}