see kernel's
samples/bpf/bpf_helpers.h
or
tools/testing/selftests/bpf/bpf_legacy.h
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id331fb9abcd87df8bf87c5a86749acf0144ffbde
This is basically a no-op, but will make future compatibility checks easier.
The programs/maps already won't load on a bpfloader outside of
this range, as the entire .o will be skipped.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0669c7ff9e04e24a8da68aa821c9ad705a8f5a93
(this should avoid kernel reading/writing from out of bounds)
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I71fe71eee4e4e6a917477eef5fd2266439e803f3
This feature allows skipping a program or map based on the type of the
build. This allows things like userdebug-only programs.
Bug: 246985031
Test: added test program and watched it skipped on userdebug
Change-Id: I5cd9725ad8f133c98c86e6ba620a266313055157
There is only user left, let us simply move the macro
definition into the resolv_integration_test.cpp file.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6eb66abaa7f6392ab43300e5087e4277491e44c9
This adds a BPF program with a ring buffer and an associated test that
ensures the program and ring buffer can be loaded by the bpf loader. In
the following changes, this foundation will be used to test the user
space ring buffer wrapper class.
Unlike BpfMap, userspace can't (easily) write to the ring buffer so the
most accurate way to test a userspace ring buffer implementation is to
write to it from a BPF program.
Note: the BPF program in this change is never actually attached to a
cgroup, it is only loaded. The program will be executed manually using
BPF_PROG_RUN which is "side-effect free" (it can have side effects on
BPF maps, but not on Kernel state, e.g. dropping packets).
Bug: 246985031
Test: atest libbpf_android_test
Change-Id: Ib9c591218188f5f358a755c8854bc6f87d26af12
_EXT suffix is used for the all-args versions of these, such as the one
here.
Bug: 246985031
Test: build and flash on 4.19 and 5.10
Change-Id: Ibd76cbdc38f4d1f9df4f440147e5f18d9a2ea026
BPF ring buffers are defined like maps, but cannot specify a key or
value size (attempting to do so is a verifier error). This change also
adds the type-safe methods for interacting with the map (output, reserve
and submit).
Bug: 246985031
Test: local run of Network Tracing w/ ring buffers
Change-Id: Ie8a47d987be6cb219fe7d73f2c61a56e3a3ab21a
as this does not appear to be used anywhere anymore
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6905c6fdb4daf48df07e758481368d441637ad13
as this does not appear to be used anywhere anymore
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I95939b0b6c66f41f776ca31ea7178bb30241b81f
See 5.12+ kernel's include/uapi/linux/bpf.h
(note that since bpf is 64-bit, int and long are the same thing)
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib340a619645ad5ab8e41ff76cb7b51671f496bc5
Non platform ones (ie. shipped via mainline) already have
the value manually specified.
The goal here is to be able to do some bpf.o validity checking
in the bpfloader based on the bpfloader_min_ver.
Such validity checking really only makes sense for mainline
shipped bpf.o's which might need to load on older bpfloaders.
Hence we no longer want platform bpf.o's to have minver == 0.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9e2f670c48e30818689a42bc515eb49e86f3cbea
Sometimes you just want to change the setting for all maps and/or
programs in a specific .c file...
Bug: 190523685
Bug: 236925089
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I3ba6b3a8dadf18c1436b21feb1ee03db446e6aba
BpfLoader v0.25+ support loading obj@ver.o files
as if they were obj.o. This allows different
versions of the .o per bpfloader version.
This is useful because BTF enabled bpf.o files
are incompatible with BpfLoader < 0.10.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2067b1c54c36842c0baa779f37a904b75b9dfb6d
Per request on:
https://googleplex-android-review.googlesource.com/c/platform/frameworks/libs/net/+/18992756
While we're at it let's temporarily remove the check in .reset(fd)
if (bpfGetFdMapFlags(mMapFd) != 0) abort(); // TODO: fix for BpfMapRO
We'll add it back when the code is in better shape,
and read-only vs read-write state of the map is something
we actually *know*.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id8d65bdc529872685b42656e638f22048fafb7f6
(split in two to facilitate manual testing)
Bug: 218408035
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ifc00ed168231615819b88b232155e1fe6f9a8c71
Tested by making the map struct conditional on #define V18,
and only #defining that in the top line of netd.c,
this results in:
$ objdump -s -j size_of_bpf_map_def out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/net_shared/clatd.o
out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/net_shared/clatd.o: file format elf64-little
Contents of section size_of_bpf_map_def:
0000 30000000 00000000 0.......
$ objdump -s -j size_of_bpf_prog_def out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/net_shared/clatd.o
out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/net_shared/clatd.o: file format elf64-little
Contents of section size_of_bpf_prog_def:
0000 1c000000 00000000 ........
$ objdump -s -j size_of_bpf_map_def out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/netd_shared/netd.o
out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/netd_shared/netd.o: file format elf64-little
Contents of section size_of_bpf_map_def:
0000 74000000 00000000 t.......
$ objdump -s -j size_of_bpf_prog_def out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/netd_shared/netd.o
out/target/product/vsoc_x86_64/apex/com.android.tethering/etc/bpf/netd_shared/netd.o: file format elf64-little
Contents of section size_of_bpf_prog_def:
0000 5c000000 00000000 \.......
$ echo $[0x00000030] $[0x00000074]
48 116
$ echo $[0x0000001c] $[0x0000005c]
28 92
and it still successfully boots.
So the struct extension infrastructure works as desired.
Bug: 218408035
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8b55769e69dbf9580e844f2a50d48651fd9a0cff
while we're at it:
- replace 'unique_fd != -1' with unique_fd.ok() which is
a test for fd.get() >= 0 and is thus effectively equivalent
- make use of the fact that unique_fd.reset()
takes care to save errno.
(see impl. in //system/libbase/include/android-base/unique_fd.h )
Bug: 236285127
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6fb7bf28a2265ad84baa3c552b39c620cb3875fe
Really we need to fix the inheritance to make
BpfMapRO the parent class of BpfMap:
but that's a far more difficult thing to do,
so in the short term we punt like this.
This makes BpfMapRO a little bit more usable,
and allows a slow transition across the codebase...
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1c5112db70e9e523c113cba536fbe19422b4d3f3
this way is more obviously not calling dup_with_cloexec
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4e1ce3b0a42ccea638332ae451e291e025d57895
to replace less safe uses of BpfMap.reset(create(type, keysize, valuesize, entries, flags))
Meant to be used in tests only.
Bug:
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I869f1f935bcf5d00702c42bc46d6094ea552addc
not perfect due to this being in a header file, so multiple copies
potentially exist, but it's really simple, and works nearly as well.
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id90c6933d57bc12f4dd640c8918fd0885c7474cf