Commit Graph

31 Commits

Author SHA1 Message Date
Maciej Żenczykowski
340e2ff355 BpfSyscallWrappers: add queryProgram()
Test: TreeHugger
Bug: 292156770
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0f77220a6c4b13efb5630d7a5ade1db39c59901e
2023-10-04 19:12:25 +00:00
Maciej Żenczykowski
325f675273 fix a compile warning about out of order field init
http://cs/h/prodkernel/kernel/upstream/torvalds/linux-2.6/+/master:tools/include/uapi/linux/bpf.h?l=1486

struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
		__u32		prog_fd;
		__u32		retval;
		__u32		data_size_in;
		__u32		data_size_out;
		__aligned_u64	data_in;
		__aligned_u64	data_out;
...

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2c08b65bdcdbd7fb9872b6d4cbbf542fe28ef916
2023-09-06 23:51:37 +00:00
Maciej Żenczykowski
c6e4122db8 add createOuterMap()
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Icf49cc98daa339b0320b5c18cd055b8a53dcba6c
2023-06-14 09:14:19 +00:00
Maciej Żenczykowski
008f51e585 implement 'int bpfGetFdProgId(const BPF_FD_TYPE prog_fd)'
which fetches the internal kernel identifier of an ebpf program

side note: Linux in include/uapi/linux/bpf.h declares:
  4.14: struct bpf_map_info
  4.14: struct bpf_prog_info
  4.19: struct bpf_btf_info
  5.4: struct bpf_func_info
  5.4: struct bpf_line_info
  5.10: struct bpf_link_info
  5.10: struct bpf_pidns_info

Test: TreeHugger
Bug: 286369326
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8b2fe1a67bdefff521e41b3ff4ef37d29fc90fae
2023-06-14 09:13:09 +00:00
Maciej Żenczykowski
be02054c79 convert ptr_to_u64() macro to an inline function
This allows it to be used from outside this header file,
and provides slightly more type safety.

Test: TreeHugger
Bug: 286369326
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I98e5e37a002188813b602e51fd4fcbb9ca4466cc
2023-06-14 02:15:07 +00:00
Patrick Rohr
93312c998e bpf_headers: Make bpf_headers available to libsysutils
So KernelUtils.h can be used in NetlinkEvent.cpp.

Test: builds
Change-Id: If7a6a28e735ee19dc6b7a72330a97a8a01bcecd5
2023-05-18 14:39:14 -07:00
Ryan Zuklie
2669e24058 Add BpfRingbuf class to wrap ringbuf access
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
2023-01-23 08:28:50 -08:00
Maciej Żenczykowski
d8c03fec3a BpfSyscallWrapper - use 'enum bpf_cmd' instead of int for bpf() arg
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I73d8d33e1677088fbbed02c554c88269912d2f76
2022-12-16 20:59:31 +00:00
Maciej Żenczykowski
0ce7758487 add more comments about bpfGetFd... and kernel version compatibility
Per request on:
  https://googleplex-android-review.googlesource.com/c/platform/frameworks/libs/net/+/18992756

Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I853d177623dc64fdac70ddefde3e0cc65d6b2c9a
2022-06-23 13:20:39 +00:00
Maciej Żenczykowski
5c5fae7a8b BpfMap key/value access size verification
(beginning there of)

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie7cf8cd51b4e272fc76a281df6231ed27955ed3f
2022-06-03 21:23:39 +00:00
Stephane Lee
4806feb3a5 Allow use of shared bpf headers by recovery
This will allow healthd to filter uevent packets, if needed

Bug: 203462310
Test: Ensure that healthd can build if it uses bpf filters
Change-Id: I97bfe9509a6934444f656508176495bba38381be
2022-03-09 14:16:41 -08:00
Maciej Żenczykowski
62b3d9fbb2 Merge "expose bpf_syscall_wrappers to art apex" 2022-02-10 23:26:49 +00:00
Maciej Żenczykowski
2645d2374b Merge "bpf_headers/bpf_syscall_wrappers - remove visibility restrictions" 2022-02-10 19:03:15 +00:00
Maciej Żenczykowski
a11e698749 expose bpf_syscall_wrappers to art apex
The art apex already has access to bpf_headers which includes bpf_syscall_wrappers,
but this extra line is needed to switch it away from needlessly linking libbpf_android.

Since these are header files only, this annotation is kind of pointless,
but it does turn out to be needed...

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9e4d3373cea488080304e31ed7c8708aec988933
2022-02-09 22:23:01 -08:00
Maciej Żenczykowski
6b1d684059 bpf_headers/bpf_syscall_wrappers - remove visibility restrictions
this doesn't appear to make sense now that it's available to vendors

Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If2d24fa8eccfb5c12832fb191a8560b024751db7
2022-02-09 19:33:20 -08:00
Maciej Żenczykowski
b751aee9ab Merge "Add attach bpf with flags and detach single bpf" 2022-02-10 02:26:56 +00:00
KaiWen Zheng
cfe2f2a1c9 Add attach bpf with flags and detach single bpf
Attach bpf program to cgroup with flags, support 'BPF_F_ALLOW_OVERRIDE'
and 'BPF_F_ALLOW_MULTI'; corresponding to detach a single bpf program in
a cgroup.

Test: m
Signed-off-by: KaiWen Zheng <zhengkaiwen5@xiaomi.corp-partner.google.com>
Change-Id: I9a4d2dcb249c6c628e3f1287d7d5d1879b722bd6
2022-02-09 19:27:58 +08:00
Steven Moreland
b0df1895d5 bpf_headers for vendor.
For waitForProgsLoaded.

Bug: 162057235
Test: build, load bpf program from vendor
Change-Id: Ib670aada0a98249fed21beb72879326286b2f4c2
2022-02-08 22:30:07 +00:00
Hungming Chen
51fecf19e2 libclat: Use space indentation instead of tab
Correct the indentation style of libclat in the follows
bpf_headers/Android.bp
bpf_syscall_wrappers/Android.bp

Test: build
Change-Id: I7cdd354141124fa8f7b4a864ddd937bef4676302
2022-01-25 20:09:09 +08:00
Hungming Chen
37b2575137 make bpf_syscall_wrappers visible to libclat
Needed because ClatdController and clatd binary are moved
into apex. libclat is used for accessing BPF map.

Bug: 212345928
Test: manual test
    1. Connect to ipv6-only wifi.
    2. Try IPv4 traffic.
       $ ping 8.8.8.8
Change-Id: I95a1c21927ba95f6094152e1013761d79c73e981
2022-01-16 13:50:34 +08:00
Wayne Ma
321a9f0719 Merge "[NETD-TC#12] Fix dependency on libtraffic_controller" 2022-01-14 10:44:52 +00:00
Wayne Ma
67a69e7396 [NETD-TC#12] Fix dependency on libtraffic_controller
1. Add visibility for libtraffic_control
2. Add com.android.tethering into apex_available statement

Bug: 202086915
Test: m; flash; boot
Change-Id: I817e22c24dd205f09ef62a2a7ff85b2a970f6d3a
2022-01-14 12:24:13 +08:00
Patrick Rohr
a408d3cc06 Move BpfUtils -- make BpfSyscallWrappers visible to libtcutils
Bug: 202086915
Bug: 157552970
Test: atest TetheringTests
Change-Id: I698f492e30e4108037d1b72c5bebc7d6ab85e410
2022-01-12 21:34:48 +01:00
Maciej Żenczykowski
15d8ebee41 bpf_connectivity_headers -> bpf_headers -> bpf_syscall_wrappers
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Idf158fa33670522b43e34c67a77087648b8b97a4
2021-12-28 17:56:27 -08:00
Ken Chen
4bce28bc2a [NETD-BPF#25] Add bpf_syscall_wrappers visibility for libnetd_mainline
retrieveProgram() in bpf_syscall_wrappers is used by libnetd_mainline.

Bug: 202086915
Test: m; flash; boot
Change-Id: I69573a6925fd9f5fcd65935d681e7a340ee73f17
2021-12-07 02:42:32 +00:00
Alessio Balsini
9efcabc929 Allow MediaProvider to use BPF utilities
The FUSE daemon in MediaProvider needs to access the file descriptor of
its pinned BPF program.
The BPF syscall wrappers are handy and would avoid code duplication,
thus extend this project visibility to MediaProvider.

Bug: 202785178
Test: adb logcat FuseDaemon:V \*:S (in git_master)
Signed-off-by: Alessio Balsini <balsini@google.com>
Change-Id: I406c760bb96d74597ca7d8f701cd12c3bd318f68
2021-12-03 01:54:31 +00:00
Tyler Wear
aafd9c18fb bpfmap: Move to Common Util Location
Multiple packages need access to bpf maps. Moving to common
location to allow access from all necessary packages.

Test: atest BpfMapTest
Bug: 179733303

Change-Id: Idae7b620c15c781b2e7980c3a3157f396cfaf66e
2021-10-29 12:38:05 -07:00
Tyler Wear
ae05481b9a export bpf headers to Connectivity Service
Export BPF headers to connectivity service for use with
VendorConnectivityService aidl.

Bug: 179733303
Change-Id: Ibc098facde54aeb621e53b73ac59eb6416ba9ebb
2021-10-20 01:02:31 +00:00
Suren Baghdasaryan
1bd069f24d Allow lmkd to use bpf_syscall_wrappers
LMKD needs access to map_gpu_mem_gpu_mem_total_map
BPF map to record the total size of GPU allocations
at the time of a kill. Change bpf_syscall_wrappers
visibility to allow lmkd to use bpf_syscall_wrappers
library.

Bug: 189366037
Test: lmkd_unit_test
Signed-off-by: Suren Baghdasaryan <surenb@google.com>
Change-Id: Ia1f75852a853f62b504351271119714f3fd95232
2021-06-11 21:00:06 +00:00
Bob Badour
1b8c744bcd [LSC] Add LOCAL_LICENSE_KINDS to frameworks/libs/net
Added SPDX-license-identifier-Apache-2.0 to:
  client-libs/Android.bp
  client-libs/tests/unit/Android.bp
  common/Android.bp
  common/native/bpf_syscall_wrappers/Android.bp
  common/native/netjniutils/Android.bp
  common/tests/unit/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all

Exempt-From-Owner-Approval: janitorial work

Change-Id: I2d4abaee12c1f20c39a7e2c9e02e2fccb96fa3ee
Merged-in: I6942c6844c89048f785f2b6eaa4bb33a24fa6f93
2021-02-17 17:22:02 -08:00
Maciej Żenczykowski
a728a70497 Wrap BPF system calls into a versioned module
This isn't new code, this is basically copied verbatim from
  //system/bpf/libbpf_android/include/bpf/BpfUtils.h

Test: atest BpfMapTest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I80523c9ee0c1e4431f3192eb409ad68c737390a6
2021-01-13 18:29:56 -08:00