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/server/TrafficController.cpp b/server/TrafficController.cpp
index 86f1f53..0de2370 100644
--- a/server/TrafficController.cpp
+++ b/server/TrafficController.cpp
@@ -368,7 +368,7 @@
uint64_t sock_cookie = getSocketCookie(sockFd);
if (sock_cookie == NONEXISTENT_COOKIE) return -errno;
- UidTag newKey = {.uid = (uint32_t)uid, .tag = tag};
+ UidTagValue newKey = {.uid = (uint32_t)uid, .tag = tag};
uint32_t totalEntryCount = 0;
uint32_t perUidEntryCount = 0;
@@ -487,8 +487,9 @@
// First we go through the cookieTagMap to delete the target uid tag combination. Or delete all
// the tags related to the uid if the tag is 0.
- const auto deleteMatchedCookieEntries = [uid, tag](const uint64_t& key, const UidTag& value,
- BpfMap<uint64_t, UidTag>& map) {
+ const auto deleteMatchedCookieEntries = [uid, tag](const uint64_t& key,
+ const UidTagValue& value,
+ BpfMap<uint64_t, UidTagValue>& map) {
if (value.uid == uid && (value.tag == tag || tag == 0)) {
Status res = map.deleteValue(key);
if (isOk(res) || (res.code() == ENOENT)) {
@@ -991,8 +992,8 @@
// Print CookieTagMap content.
dumpBpfMap("mCookieTagMap", dw, "");
- const auto printCookieTagInfo = [&dw](const uint64_t& key, const UidTag& value,
- const BpfMap<uint64_t, UidTag>&) {
+ 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 netdutils::status::ok;
};