Commit graph android_system_bpf/libbpf_android/include
Message SHA1
libbpf_android: remove libnetdutils dep
Remove libnetdutils dependency because bpf is being used for things other
than networking these days, and we don't want to make libnetdutils
vendor-available in the future. libbase provides an alternative type now.

Bug: 140330870
Test: atest libbpf_android_test netd_integration_test netd_unit_test
    libnetdbpf_test bpf_module_test
Change-Id: I72ae8cd7f58a49bfc7dcb914a332a4c4bad5dea5

Steven Moreland   commited 2020-01-21 10:47:33 -08:00
e7cd2a72d0
BpfUtils - pass file descriptors as 'const unique_fd&'s not raw ints.
Test: builds, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Idde6d9c81ac9ba02aa5a42f9ca9ec72ef7cd5cad

Maciej Żenczykowski   commited 2020-01-18 19:39:39 -08:00
289742f537
BpfMap/Utils - fix const-ness of key & value
When accessing maps keys are always const/read-only.
Similarly for the value when it is being stored in the map.

This eliminates four const_casts.

Test: build, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Icc57b46a8e9e81b5b06264260bfbf34a4ba9105d

Maciej Żenczykowski   commited 2020-01-18 19:32:09 -08:00
79365da151
BpfUtils - move trivial functions from .cpp to static inline's in .h
Test: builds, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I49d1ac6e196c5b1afbe460a7247d2ad38f571958

Maciej Żenczykowski   commited 2020-01-17 09:07:15 +00:00
b479fd6a9f
Merge "libbpf_android/BpfUtils - remove unused bpfProgLoad"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2020-01-14 23:44:11 +00:00
cd6f89bbb6
libbpf_android/BpfUtils - remove unused bpfProgLoad
(due to switch to bpfloader from loading via netd)

Test: build, atest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic95cdfde26b8e7b905551a7fd2b465e0cf99bbce

Maciej Żenczykowski   authored and   Steven Moreland   commited 2020-01-14 09:10:32 -08:00
c66f5c6bc1
Merge "remove network specific struct definitions from BpfUtils.h"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2020-01-14 09:03:11 +00:00
d5f6cf505b
libbpf_android: waitForProgsLoaded
Creating a function for this rather than having people copy/paste a loop
there.

It's very intentional that there is no timeout here. If bpfloader is
down, there is a serious problem, and we shouldn't let code move forward
in a state where it may not have been tested.

Bug: 140330870
Test: boot & use bpf/netd
Change-Id: I358d1fcf77ad5406e294dd57307bc411e2c8ad6a

Steven Moreland   commited 2020-01-10 15:37:53 -08:00
4891e61341
remove network specific struct definitions from BpfUtils.h
This is part of 3 commits in 3 diff git repos, the main one is:
  https://android-review.googlesource.com/c/platform/system/netd/+/1200479
  "share eBPF struct definitions between ebpf and C++ netd"

The struct definitions are being moved to system/netd in:
  libnetdbpf/include/netdbpf/bpf_shared.h

(they also become typedefs and more consistent naming is used)

Test: builds
Bug: 146787904
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0200bce35f910414b96d802cd316717b4307b950

Maciej Żenczykowski   commited 2020-01-06 23:28:06 +00:00
841dd444dd
remove spurious equals comparators
These are unused by virtue of the code continuing to build.

C++20 has https://en.cppreference.com/w/cpp/language/default_comparisons
but still requires explicit declaration of them with '=default' annotation.

Test: builds
Bug: 146787904
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I751ad5592acc1ed4cf763d1ca82c301f2e233e56

Maciej Żenczykowski   commited 2020-01-06 13:57:05 +00:00
be15fa1edd
bpfloader - remove dead code
Test: builds, atest
Bug: 146787904
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iea667cf4adaccdfd8fbffae8960cbe243ae77d70

Maciej Żenczykowski   commited 2019-12-30 04:12:36 -08:00
480c70ac14
fix broken double close in BpfMapTest.cpp
Bug: 139175951
Bug: 139205160
Test: atest libbpf_android_test
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I911ce9276e5f8b2278e459b5b11be8e7ccb3632f

Maciej Żenczykowski   commited 2019-08-10 01:25:17 +00:00
e6cbd40468
remove BPF_CONTINUE and BPF_DELETED constants
These are apparently not used anywhere, and this can be trivially
confirmed via code search.

Test: builds
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I738c83c1b00bf9a7d7344a4b31bf80581788ec10

Maciej Żenczykowski   commited 2019-05-01 14:49:19 -07:00
546d8da936
Clean up the legacy loader
delete the loader code that is no longer used by any bpf programs.

Bug: 130206035
Test: build all the bpf related target.
Change-Id: I3ea4e40cb986b380f3b79a7685c3c09633e4d199

Chenbo Feng   commited 2019-04-19 19:51:30 +00:00
097205c8e1
Add helper function to set rlimit for tests
Add a helper function to set sufficient MEMLOCK rlimit
for bpf related unit tests.

Bug: 119279144
Bug: 129246448
Test: libbpf_android_test
Change-Id: I5390f4d3b21436abff69a661d1c6e6a6749542ed

Chenbo Feng   authored and   Maciej Żenczykowski   commited 2019-04-10 05:54:00 +00:00
0a1a9a11d9
BpfMap.getOrCreate(size, path, type) -> BpfMap.init(path)
We don't have the appropriate selinux privs to create the maps anyway.

Test: builds (when combined with system/netd change)
      'git grep getOrCreate' in system/{bpf,netd} comes up empty
      atest netd_unit_test netd_integration_test libbpf_android_test
Bug: 65674744
Bug: 129654883
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Idffbce5b28b723943c6495cfafdecddc7a0f4e67

Maciej Żenczykowski   commited 2019-04-01 16:54:08 -07:00
52108bf52c
BpfMap - remove mPinnedPath, getPinnedPath, pinToPath
Test: builds, git grep 'mPinnedPath|getPinnedPath|pinToPath' comes up empty
      atest netd_unit_test netd_integration_test libbpf_android_test
Bug: 65674744
Bug: 129654883
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iad84ce7c74bef77e63cf63563d67b7501dd0165b

Maciej Żenczykowski   commited 2019-04-01 16:54:08 -07:00
04d88b7576
Add detailed kernel version when checking bpf support
For devices with 4.14 kernel shipping with bpf feature, they support more
functionality compared to 4.9 kernels. So when checking if the device
supports a given bpf feature, return a bpf level dependent on the detailed
kernel version instead of a simple boolean. This information would be
useful when we support new features such as map_in_map and cgroup socket
filters.

Bug: 111441138
Test: libnetdbpf_test, netd_integration_test
Change-Id: Ib51a56a35643ad76b58987ba1938c69905d28141

Chenbo Feng   commited 2019-02-14 13:39:05 -08:00
79b7e61d49
Remove hardcoded cgroup v2 path
Replace hardcoded cgroup v2 root path with new libprocessgroup API calls.

Bug: 111307099
Test: builds, boots

Change-Id: Ic9c47b52702767f9934f65d04bb91ab303b1d06e
Merged-In: Ic9c47b52702767f9934f65d04bb91ab303b1d06e
Signed-off-by: Suren Baghdasaryan <surenb@google.com>

Suren Baghdasaryan   commited 2019-02-02 16:58:40 +00:00
9217ccba51
Do not take cumulative network stats anymore
Use two maps to record the details of network stats and swap and clean
up after system server pulls the stats. The kernel program checks the
bpf map currently enabled before updating the stats and updates on the
corresponding map. Remove the TAG_STATS_MAP since we don't need to worry
about uid stats overflow problem. All the stats can be stored in the
same map until system server scrapes the stats and clean it up.

Bug: 79171384
Test: dumpsys netd trafficcontroller
      CtsUsageStatsTestCases

Change-Id: Ic79e382f51bf21eee78c4cac5a8a97edaf3654cd

Chenbo Feng   commited 2019-01-22 18:40:10 -08:00
9cd8f14ed0
New bpfloader netd kernel program
Change the netd bpf program to the new format. Adding map definition and
necessary helper functions to the kernel program code. Move the netd bpf
programs out of bpfloader to a new directory.

Test: dumpsys netd trafficcontroller
Bug: 112334572
Change-Id: I9287285d188e966193532b1522b5d3e67e32e930

Chenbo Feng   authored and   Joel Fernandes   commited 2019-01-07 20:17:42 -05:00
c1dd7648b1
Initial checkin for relocatable ELF loader and link with bcc
* Wrote a relocatable ELF loader from scratch. The loader library loads
all objects in /system/etc/bpf/, parses and fixes up eBPF instructions
based on relocation information, creates maps and programs and pins
them. A single API call without arguments is made which results in this
operation. The API has all the information it needs from the filesystem
and the ELF objects, so there is no configuration stored in the code
calling the loader API essentially making it zero conf. Initially this
will be used by time_in_state statistics collection using tracepoints.
In the future, netd's eBPF C code should be rewritten to use this
infrastructure and the old ELF loader can be gotten rid off. This is the
first step.

* Link libbpf with libbpf_android which will come from the external/ bcc
project. This will be used for tracepoint and perf eBPF support. In the
future it can be used for other things as kernel eBPF support advances.

This patch will be merged only after bcc is cloned into external/ to
prevent build breakage.

Bug: 112334572
Change-Id: Ic0fd9504e18031132d40bb627c5e44058d59c9f8
Signed-off-by: Joel Fernandes <joelaf@google.com>

Joel Fernandes   commited 2018-12-17 22:27:56 +00:00
d76a2004a6
Code style clean up
Apply the git clang format on the bpf project to make sure the existing
code compliance with the standard.

Test: project compiles and bpfMapTest pass.
Bug: 112334572
Change-Id: I4774aa2a197be2c671f6fb307c1fc9b71edfeeec

Chenbo Feng   commited 2018-11-28 11:31:36 -08:00
1f20ad3d78
Rename libbpf to libbpf_android
Rename the bpf support library in android to libbpf_android to make
it compatible with external bcc project. Fix the Android.bp file to
prevent build break.

Bug: 112334572
Test: No build breakage.
Change-Id: I24ae8aaf8ca8afdded5e46d21f0deec68d6030da

Chenbo Feng   commited 2018-11-08 11:32:31 -08:00
79a4da2d1e