summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej Żenczykowski <maze@google.com>2022-05-31 03:30:38 -0700
committerMaciej Żenczykowski <maze@google.com>2022-06-08 01:24:51 +0000
commit7f63f0ff8055f0ec0cbd949fa1f2c40537b9b1e3 (patch)
tree3a51a3e916b289ae5f3190376846d1689209db99
parent3aea21bcd8f66de4189053024e190a3096acdf3e (diff)
downloadnet-7f63f0ff8055f0ec0cbd949fa1f2c40537b9b1e3.tar.gz
BpfMap: introduce resetMap(type, entries, flags)
to replace less safe uses of BpfMap.reset(create(type, keysize, valuesize, entries, flags)) Meant to be used in tests only. Bug: 235286176 Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I869f1f935bcf5d00702c42bc46d6094ea552addc (cherry picked from commit d2dec08c73b2bc1dd2a3969ccb504a59e9cb223f) Merged-In: I869f1f935bcf5d00702c42bc46d6094ea552addc
-rw-r--r--common/native/bpf_headers/include/bpf/BpfMap.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/common/native/bpf_headers/include/bpf/BpfMap.h b/common/native/bpf_headers/include/bpf/BpfMap.h
index bdffc0f0..d07d6104 100644
--- a/common/native/bpf_headers/include/bpf/BpfMap.h
+++ b/common/native/bpf_headers/include/bpf/BpfMap.h
@@ -102,6 +102,23 @@ class BpfMap {
// Function that tries to get map from a pinned path.
base::Result<void> init(const char* path);
+#ifdef TEST_BPF_MAP
+ // due to Android SELinux limitations which prevent map creation by anyone besides the bpfloader
+ // this should only ever be used by test code, it is equivalent to:
+ // .reset(createMap(type, keysize, valuesize, max_entries, map_flags)
+ // TODO: derive map_flags from BpfMap vs BpfMapRO
+ base::Result<void> resetMap(bpf_map_type map_type, uint32_t max_entries, uint32_t map_flags = 0) {
+ int map_fd = createMap(map_type, sizeof(Key), sizeof(Value), max_entries, map_flags);
+ if (map_fd < 0) {
+ auto err = ErrnoErrorf("Unable to create map.");
+ mMapFd.reset();
+ return err;
+ };
+ mMapFd.reset(map_fd);
+ return {};
+ }
+#endif
+
// Iterate through the map and handle each key retrieved based on the filter
// without modification of map content.
base::Result<void> iterate(