(they're only of historical interest at this point)
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0e52efda62626091c3023c5fd3622ffcdcd00ee1
Since it just came up again, and I just verified this still works
Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I292c94cf9af63488ed30a6ac367ac83c8912e97e
(and a few minor cleanups while at it)
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I657c3314fb0ad2519dc4d1b0743e1be6a81a887a
This implements the bare minimum to read from BPF ring buffers in
userspace. The implementation uses two shared memory regions with
atomic-like access. Currently, the class only guarantees that the
element type has the same size (later can add btf support).
The alternative would be to use libbpf or bcc, but since this is a small
header-only library that seemed like it could end up being more
difficulty than it was worth.
Bug: 246985031
Test: atest libbpf_android_test
Change-Id: I7f08e76db9cb9672ef66c629bccb3db63d3c2229
This is similar to https://r.android.com/2374598 for maps.
Bug: 246985031
Test: build connectivity module
Change-Id: Id4c9f93b69e808d461b4554bf3fa591828635dd1
This updates the ringbuffer and program helpers to allow specifying
which platform builds they are ignored on. In order to use this, you
must specify a min loader version >= 0.32, so the helpers also add
options for setting this at the program/ringbuf level.
Bug: 246985031
Test: tethering build & install, full platform build & install
Change-Id: I6bf9f7945c3fbac8fd4e02b5805016ac275b7884
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
_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