Commit graph android_packages_modules_Co.../staticlibs/native
Message SHA1
NetBpfLoad: enable mainline on T+
Note:
   2 == BPFLOADER_S_VERSION
  19 == BPFLOADER_T_VERSION
  25 == BPFLOADER_OBJ_AT_VER_VERSION
  33 == BPFLOADER_IGNORED_ON_VERSION
  37 == BPFLOADER_U_VERSION [*]
  41 == BPFLOADER_V_VERSION [**]
and currently we have:
  42 == BPFLOADER_MAINLINE_VERSION
  43 == BPFLOADER_MAINLINE_T_VERSION
  44 == BPFLOADER_MAINLINE_U_VERSION
  45 == BPFLOADER_MAINLINE_V_VERSION

[*] udc-dev/udc-release are actually 38, as 37 was some earlier
    udc beta2 (2.1 ifirc), and beta3+ switched to 38

[**] 24Q{1,2}-release (ie. U QPR2+) are technically actually 41,
     but their platform bpfloader no longer even looks in /apex/com.android.tethering/etc/bpf/...
     so it doesn't really matter (although 24Q1's platform
     netbpfload still does, however that is obsoleted by
     this change)

Thus we need to (as minimum for NetBpfLoad):
  BPFLOADER_T_VERSION -> BPFLOADER_MAINLINE_T_VERSION
  BPFLOADER_IGNORED_ON_VERSION -> BPFLOADER_MAINLINE_U_VERSION
to cause these to load appropriately from mainline.

One would perhaps also expect (as minimum for NetBpfLoad):
  BPFLOADER_OBJ_AT_VERSION -> BPFLOADER_MAINLINE_U_VERSION
but (as maximum for platform bpfloader):
  BPFLOADER_OBJ_AT_VERSION -> BPFLOADER_MAINLINE_U_VERSION

However, since the goal is actually for those to load via mainline on T+,
(with the 'old' version of the .o's loading on S via platform bpfloader)
thus one actually needs (as minimum for NetBpfLoad):
  BPFLOADER_OBJ_AT_VERSION -> BPFLOADER_MAINLINE_T_VERSION
and (as maximum for platform bpfloader):
  BPFLOADER_OBJ_AT_VERSION -> BPFLOADER_T_VERSION

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

Maciej Żenczykowski   commited 2024-03-19 21:33:55 +00:00
11141da623
NetBpfLoad: chose bpfloader version at runtime based on Android OS
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iee55d9c6f828f05d4096dff2e874abc6c41eadeb

Maciej Żenczykowski   commited 2024-03-18 15:02:53 -07:00
65f7022461
Eliminate spurious COMPILE_FOR_BPFLOADER_VERSION macro
and make platform bpf.o's target V's platform bpfloader.

Note that all mainline shipped bpf.o's already manually
specify BPFLOADER_MIN_VER.

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

Maciej Żenczykowski   commited 2024-03-15 18:14:16 +00:00
0de80f1a9f
add #define BPFLOADER_MAINLINE_VERSION 42u
See: //packages/modules/Connectivity/netbpfload/loader.cpp
  // This is Network BpfLoader v0.42
  #define BPFLOADER_VERSION_MAJOR 0u
  #define BPFLOADER_VERSION_MINOR 42u

Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ieeed6d402de06d3f01e151c2c9ee44270c53323c

Maciej Żenczykowski   commited 2024-03-12 06:31:36 +00:00
84aa9ea83a
bpf_helpers: add #defines for next 2 LTS KVERs
Test: N/A
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iac303578071ff5dd3848f63c7497180d7694874b

Maciej Żenczykowski   commited 2024-03-10 22:11:54 +00:00
978b3f2d9b
[DON'T BLOCK] Test ownership migration rules
This CL is created as a best effort to migrate test targets
to the new android ownership model. If you find incorrect or unnecessary
attribution in this CL, please create a separate CL to fix that.

For more details please refer to the link below,
<add g3 doc link>

Bug: 304529413
Test: N/A
Change-Id: I243f17b3f0ad7af9ffa15ca242456e36688733f5
Merged-In: I243f17b3f0ad7af9ffa15ca242456e36688733f5

Aditya Choudhary   commited 2024-01-31 12:34:50 +00:00
01b5ede2b2
Add missing libc++ includes
Bug: 175635923
Test: m MODULES-IN-packages-modules-Connectivity
Change-Id: I94dafe991ccd73450671ea68eaf65b787dc1d0fa

Tomasz Wasilczyk   commited 2024-01-09 11:01:22 -08:00
661ec166c7
BpfRingBuf.h - implement wait()
Test: TreeHugger, atest BpfRingbufTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2696077caf4de27dd64e4af1c45a13844ed186c9

Maciej Żenczykowski   commited 2023-11-11 00:59:42 +00:00
ddb0ab8c61
Merge "BpfRingBuf.h - implement isEmpty()" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-11-09 23:20:01 +00:00
ca6cf094b9
BpfRingBuf.h - implement isEmpty()
Test: TreeHugger, atest BpfRingbufTest
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I23020869ab665c029c3219b1b39c3749be6e6992

Maciej Żenczykowski   commited 2023-11-09 19:13:40 +00:00
0b99c961bb
switch SynchronizeKernelRCU back to jni - but from BpfMap
we can't use java for this, because pre-U-QPR2 does not include:
  https://android-review.googlesource.com/c/platform/system/sepolicy/+/2821590
  system_server dontaudit key_socket getopt

so we'll spew lots of:
  11-08 07:52:43.776 1469 1469 I auditd : type=1400 audit(0.0:4): avc: denied { getopt } for comm="system_server" scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=key_socket permissive=0
  11-08 07:52:44.360 1469 1469 I auditd : type=1400 audit(0.0:5): avc: denied { getopt } for comm="NetworkStats" scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=key_socket permissive=0
  11-08 07:52:44.508 1469 1469 I auditd : type=1400 audit(0.0:7): avc: denied { getopt } for comm="android.bg" scontext=u:r:system_server:s0 tcontext=u:r:system_server:s0 tclass=key_socket permissive=0
and the like.

This is due to Java's Os.close() in:
  libcore/luni/src/main/java/libcore/io/BlockGuardOs.java;l=100
calling:
  if (fd.isSocket$()) if (isLingerSocket(fd)) ...

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

Maciej Żenczykowski   commited 2023-11-09 11:08:58 +00:00
c350db788a
BpfMap.h - simplify error returns
Returning the number of the file descriptor isn't actually useful since
it doesn't really tell you anything once the program has terminated.
(most logs we look at are long after the fact)

However, it does involve a fair bit of string processing to generate
the errors.  This is particularly an issue for things we constantly
call and sometimes expect to fail.  For example it is normal for
getNextKey() to fail with ENOENT at the end of iteration...

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

Maciej Żenczykowski   commited 2023-11-08 18:36:42 -08:00
0ad252e03c
remove dead portions of BpfUtils.java
(mostly to improve code coverage)

We can always revert if it ever turns out this is useful,
but I'd prefer for cgroup attach to be a once-at-boot
thing and handled either from bpfloader or the netd updatable
which are both directly C++ code.

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

Maciej Żenczykowski   commited 2023-10-25 17:40:35 +00:00
de9d367ab2
type safety for kernel version
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If05c0c5383dceeb65964143f5574d2ee1a484907

Maciej Żenczykowski   commited 2023-10-06 15:54:38 -07:00
3a64568abb
type safety for bool ignore_on_{eng,user,userdebug}
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ia85e16d1a7f8d1b21e4ce4c306db6bbea06138e0

Maciej Żenczykowski   commited 2023-10-06 14:57:12 -07:00
6dec6e9374
type safety for bool optional
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6f10395ca6f1c73f3513031f561fdf1b1dedf451

Maciej Żenczykowski   commited 2023-10-06 14:48:43 -07:00
f2466ef4bb
type safety for bool shared
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4883eab734f47522fec718f0709475f7e6dd0a53

Maciej Żenczykowski   commited 2023-10-06 14:46:11 -07:00
a262bd3d1e
move PRIVATE/SHARED/MANDATORY/OPTIONAL/{LOAD,IGNORE}_ON_* into core headers
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7053ab46e73b763f64f36baf5e7ab64b62421045

Maciej Żenczykowski   commited 2023-10-06 14:25:41 -07:00
10da6d4e61
BpfClassic.h - add missing commas
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ife32fa36808de13c5f37ace497395dcc381ca336

Maciej Żenczykowski   commited 2023-10-06 13:50:13 -07:00
1e32277fff
more classic bpf macros
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5c7fd55301cd5aa44502f8481923c86bc49ea914

Maciej Żenczykowski   commited 2023-10-04 22:41:21 +00:00
d5bf2061f3
TcUtils jni: jobject clazz -> jclass clazz
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0a06d2627ef06fe4606b3d1a6525af767d218945

Maciej Żenczykowski   commited 2023-10-04 19:15:53 +00:00
f24beefe55
BpfUtils jni: jobject clazz -> jclass clazz
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I3fd51ad129873782b74c7c47b50e16f1f1f0fa6e

Maciej Żenczykowski   commited 2023-10-04 19:15:44 +00:00
b0f8d31e7d
bpf jni: add native_getProgramIdFromCgroup
Test: TreeHugger
Bug: 292156770
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ib7b194b9cbf6519f9fbcfd1fcefcbe5d825f5c3a

Maciej Żenczykowski   commited 2023-10-04 19:14:43 +00:00
85ac050b35
BpfSyscallWrappers: add queryProgram()
Test: TreeHugger
Bug: 292156770
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0f77220a6c4b13efb5630d7a5ade1db39c59901e

Maciej Żenczykowski   commited 2023-10-04 19:12:25 +00:00
340e2ff355
BpfClassic.h - more helpers
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie0eb8895c2d887b71ba886735ad106c1118ebeac

Maciej Żenczykowski   commited 2023-10-02 20:03:41 +00:00
73df7414f1
rename BPF2_REJECT_IF_ANY_BITS_SET -> BPF2_REJECT_IF_ANY_MASKED_BITS_SET
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I54a189f0f7b73917aa3fd049fe2eca387aaca250

Maciej Żenczykowski   authored and   Patrick Rohr   commited 2023-10-02 16:09:05 +00:00
b900201ffe
reverse BpfMap & BpfMapRO inheritence to make sense
Bug: 235590615
Bug: 235907076
Bug: 286003437
Test: TreeHugger, m droid gpuservice_unittest libtimeinstate_test bpf_benchmark bpf_module_test libbpf_load_test && mma
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I020a898fe8b257040a100f146654d4a04b19f843

Maciej Żenczykowski   commited 2023-09-29 00:44:33 +00:00
7e2f53e762
use different log.h header file
Test: TreeHugger
Bug: 299653233
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I1e5c7bfc86d2ad61c0bad3b5ef2add94b4ce1481

Maciej Żenczykowski   commited 2023-09-21 22:11:43 +00:00
601d9f8b65
bump min_sdk_version from 29 (Q) to 30 (R)
Mainline no longer supports Q.
These files were recently moved into p/m/C as part of a refactor.

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

Maciej Żenczykowski   commited 2023-09-19 23:22:58 +00:00
127a1441c3
Merge remote-tracking branch 'remotes/aosp/tmp_libs_net_move' into libs_net_move_merge
frameworks/libs/net/common ->
packages/modules/Connectivity/staticlibs

frameworks/libs/net/client-libs ->
packages/modules/Connectivity/staticlbs/client-libs

Test: TH
Bug: 296014682
Change-Id: I5dc78f0c4653e20312ab3d488b1e69262dbb9840

Motomu Utsumi   commited 2023-09-11 11:53:46 +09:00
c480039309
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

Maciej Żenczykowski   commited 2023-09-06 23:51:37 +00:00
325f675273
Merge "BpfMap.h - hide getMap()" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-08-22 00:32:09 +00:00
1ef814da95
BpfMap.h - hide getMap()
This leaks (what should be) an internal only fd.

There's still multiple uses of getMap() left in:
  common/native/bpf_headers/BpfMapTest.cpp

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

Maciej Żenczykowski   commited 2023-08-21 19:53:04 +00:00
12c0ea929c
Merge "BpfMap.h - add 3 using statements" into main
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-08-21 17:20:17 +00:00
ef136ebfa1
BpfMap.h - add 3 using statements
in particular base::Result is needlessly verbose

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

Maciej Żenczykowski   commited 2023-08-20 23:33:46 +00:00
eb1eb69f86
BpfMap - slightly simplify isEmpty()
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I9b93224ec2d4ff717d5e39c3ad50e63ac73f5f7c

Maciej Żenczykowski   commited 2023-08-20 12:03:26 +00:00
910cf4da9b
BpfClassic - add three more macros
Example use case:
  BPF_LOAD_SKB_PROTOCOL,
  BPF2_ACCEPT_IF_EQUAL(ETH_P_ARP),
  BPF2_REJECT_IF_NOT_EQUAL(ETH_P_IP),
  BPF_LOAD_IPV4_BE16(frag_off),
  BPF2_REJECT_IF_ANY_BITS_SET(IP_MF | IP_OFFMASK),
  BPF_ACCEPT,
which is a sample program which accepts ARP plus non-fragmented IPv4.

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

Maciej Żenczykowski   commited 2023-07-22 14:32:47 +00:00
2cd8b69005
Merge "Add a dumpService variant that uses libbinder_ndk."
Lorenzo Colitti   authored and   Gerrit Code Review   commited 2023-06-23 03:54:37 +00:00
4bf0632086
Add a dumpService variant that uses libbinder_ndk.
The one in this file requires libbinder and cannot be used when
libbinder is not present (e.g., when compiling against the NDK).
This allows users of this code not to link against libbinder, and
have the resulting binary not depend on it:

$ m CtsNativeNetPlatformTestCases netd_integration_test
$ objdump -p out/target/product/vsoc_x86_64/testcases/netd_integration_test/x86_64/netd_integration_test64 | grep NEEDED | grep libbinder
  NEEDED               libbinder.so
  NEEDED               libbinder_ndk.so
$ objdump -p out/target/product/vsoc_x86_64/testcases/CtsNativeNetPlatformTestCases/x86_64/CtsNativeNetPlatformTestCases64 | grep NEEDED | grep libbinder
  NEEDED               libbinder_ndk.so
$

Bug: 268440865
Test: see other CL in topic
Merged-In: Icf982675aad4777677a36e357035809fb251d6e9
Change-Id: Icf982675aad4777677a36e357035809fb251d6e9

Lorenzo Colitti   commited 2023-06-22 19:14:10 +09:00
49e4a98f78
enforce bpf ring buffer size is a power of two
While at it enforce a min/max of 4 kiB and 256 MiB.

A bpf ringbuffer must be an integer multiple of page size
(which is at least 4kiB), so 4kB is forced.

256 MiB upper limit is probably higher than it should be,
but it's really only here to avoid the u32/s32 conversion
mess that happens for 2+ GiB.

Test: TreeHugger
Bug: 279819914
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2216d2273b0956a86c4222dd6ecf7293e0bafd41

Maciej Żenczykowski   commited 2023-06-17 11:26:21 +00:00
f1416b5494
Merge "add macro to disable BTF on user builds"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-06-16 02:37:14 +00:00
1e1d7106bc
add createOuterMap()
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Icf49cc98daa339b0320b5c18cd055b8a53dcba6c

Maciej Żenczykowski   commited 2023-06-14 09:14:19 +00:00
c6e4122db8
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

Maciej Żenczykowski   commited 2023-06-14 09:13:09 +00:00
008f51e585
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

Maciej Żenczykowski   commited 2023-06-14 02:15:07 +00:00
be02054c79
add macro to disable BTF on user builds
Bug: 286369326
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I6a705ae99a12fb8464730dab1119f4ce2ef3f974

Maciej Żenczykowski   commited 2023-06-09 06:06:36 +00:00
8837bf21a5
force map key/value sizes < 1024/65536 bytes to match BpfMap.java
Test: TreeHugger
Bug: 286154283
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I31fb48aa032e22a83e3e9f0ac8d7f2b3253e995e

Maciej Żenczykowski   commited 2023-06-07 06:59:40 +00:00
5bec8b44a9
KernelUtils.h - better static assert messages for impossible conditions
per Lorenzo's request during cherrypick to udc-dev on
https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/libs/net/+/23391171

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

Maciej Żenczykowski   commited 2023-05-25 12:30:52 +00:00
2129040ae4
KernelUtils.h: explicitly do not support x32
x86 has 2 obvious ABIs:
32-bit registers/pointers/system calls (i386/i486/i586/i686)
64-bit registers/pointers/system calls (amd64 / x86_64)

but there also exists a third:
the memory optimizing hybrid 'x32' which uses 64-bit registers,
with 32-bit pointers, and 64-bit system calls (with minor tweaks).

(there is also technically an aarch64/arm64-ilp32 ABI mirroring x32)

Note: It would probably be trivial to add support if we wanted to.

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

Maciej Żenczykowski   commited 2023-05-21 02:33:55 +00:00
4782ab1b9e
Merge "bpfloader: ignore_on_(arch) support"
Maciej Żenczykowski   authored and   Gerrit Code Review   commited 2023-05-20 01:04:21 +00:00
1c4ba307f4
KernelUtils.h - add describeArch()
Test: TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0ae4b5fd8cf9baf04b738743d9e52f94a35aaf21

Maciej Żenczykowski   commited 2023-05-20 00:45:27 +00:00
2998627ddd