Disable shared version of libtetheringflags
- since the flags are readonly there is no real content to this,
and it should be statically linked for compile/link time optimization
(which should basically optimize the entire library out)
Use C++ magic to compile time verify the macro and flag are in sync.
The way this works:
constexpr auto useLibBpf = COM_ANDROID_TETHERING_READONLY_FLAGS_USE_LIBBPF;
^ this basically requires the macro to resolve to true/false, so that 'auto' resolves to 'const bool'
static_assert(std::is_same<decltype(useLibBpf), const bool>::value, "useLibBpf must be a boolean.");
^ which we check here
static_assert(useLibBpf == com::android::tethering::readonly:🎏:use_libbpf(), "useLibBpf flag mismatch");
^ and this then requires the macro and flag to be identical *and* compile time known
Test: TreeHugger
Flag: EXEMPT PURE_REFACTOR
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Id5cd8c7d91b424765d6f469806434b3e9587f074
Maciej Żenczykowskicommited 2025-09-12 04:04:39 -07:00
It turns out this doesn't work anyway:
Both our Java and C++ higher level map opening logic on 4.14+
kernels will check key/value sizes match, which will fail due to
the kernel uapi mismatch.
(Note: that the fixup was only ever applied/enabled inside of
the NetBpfLoad process itself, not in any later .so/Java/JNI)
This removes the fixup and simply chooses to not even attempt to
load bpf. This will result in the mainline bpf provided
maps and programs simply not existing. This would/will cause
a failure of 'bpf_existence_test' - but who cares, so long
as things keep on booting.
We need to transition to libbpf, and clearly making this work
isn't worth the considerable effort it would be, since S ebpf
functionality (ie. tethering offload) hasn't worked on the
affected devices in years.
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic93a5a9d5b3ba8078500e20dfdf00ef68256874c
Maciej Żenczykowskicommited 2025-09-11 13:01:01 -07:00
by joining two log lines into one with effectively the same info
(the kernel version is already printed during startup)
Test: TreeHugger
Flag: EXEMPT mainline / logging
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ide066edf2d54ffd6a61fdcb115a249bff80cdff9
Maciej Żenczykowskicommited 2025-09-11 11:34:49 -07:00
libbpf ignores BTF load error but this causes boot failure only when BTF
is required for some reasons (e.g. SK_STORAGE).
This CL makes boot fails regardless of the necessity of BTF on 4.19+
kernel
Test: boot kernel on 4.14, 4.19, 5.10, 6.1
Flag: EXEMPT mainline
Change-Id: I0af1e7eedcbea803c22c064ff157700a01307691
Should fix observed failure on a Xiaomi S device with 4.19 kernel:
I NetBpfLoad: NetBpfLoad v0.42 (/apex/com.android.tethering/bin/netbpfload) api:31/31 kver:413009d (64-on-aarch64) libbpf: v1.4 uid:1000 rc:10
I NetBpfLoad: Tethering APEX version 360911260
E NetBpfLoad: bpfGetNextMapId(final 15) returned 0 errno 2
W NetBpfLoad: Enabling bpfCmdFixupIsNeeded.
...
W NetBpfLoad: libbpf: BTF loading error: -2
E NetBpfLoad: btf__load_into_kernel failed, errno: 2
E NetBpfLoad: Failed to create maps: (ret=-2) in /apex/com.android.tethering/etc/bpf/mainline/offload.o
E NetBpfLoad: Failed to load object: /apex/com.android.tethering/etc/bpf/mainline/offload.o, ret: No such file or directory
E NetBpfLoad: === CRITICAL FAILURE LOADING BPF PROGRAMS ===
(errno 2 is ENOENT)
Bug: 438099891
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I07eea956fe6b862c68d3679dbd9eac81bec05e71
Maciej Żenczykowskicommited 2025-08-18 12:56:44 -07:00
Corrected the comment in Android.bp regarding the target SDK version. In NetBpfLoad.cpp, added specific handling for RiscV builds to account for its undefined minimum API level. Added an error to ensure NetBpfLoad is always compiled within an APEX. Clarified that `minSupportedKernelVer` must be 0 for APEX builds to enable runtime kernel version enforcement.
Bug: 438908493
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie3affbfd702ff1f6d5f2887b6f56ade0ed7fb5dd
Maciej Żenczykowskicommited 2025-08-15 14:58:10 -07:00
We're adding a lot of 'isAtLeastKernelVersion(x,y,z)' checks,
that would ideally compile time optimize out whenever possible.
Note: we should be able to bump the '__ANDROID_API__ == 30' assert
in NetBpfLoad to 31/S any day now, since technically tip-of-tree
only goes into M-2025-11 which requires S. But none of the
prep work for that is ready yet.
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I4d9a7916833f086cd36011e094005999fe770583
Maciej Żenczykowskicommited 2025-08-14 20:10:43 -07:00
(unfortunately need to keep kernelVersion() around for some uses outside of p/m/C)
The goal of this is to make isAtLeastKernelVersion() checks
cheaper. Currently they all have to check that we've already
parsed uname...
We use that all over the place, even at runtime in BpfMap.h.
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iaf53fc1e36eb9f88df20c39643cbd53f420ded4e
Maciej Żenczykowskicommited 2025-08-11 15:12:52 -07:00
automatically fall back for older kernels
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ice377331442f71fa69f086a3be8a8c10cbc6575f
Maciej Żenczykowskicommited 2025-08-07 15:53:42 -07:00
Note: I discovered that C considers:
char s[4] = "abcd";
a valid initialization without a terminating NULL, resulting
in an invalid string.
(Specifically pinned programs had a '\1' as their last char
due to little endian encoding of the next field in the array
of prog def structs)
The simplest workaround appears to be to explicitly add a "\0"
That results in a string/array that ends with 2 NULLs,
and the compiler will at most *strip* the final one.
ie.
char s[4] = "abcd\0";
fails to compile.
Obviously:
char s[100] = "abcd\0";
also does the right thing, since it 0-pads with or without the extra null.
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Iaeb8db2cd4750f8521a971382b9f9f9f216195b2
Maciej Żenczykowskicommited 2025-08-04 18:02:51 -07:00
in favour of just using the info from the prog definition
which was calculated at compilation time.
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I7542726b4c671177b30f79e90361b2dffdb38ac2
Maciej Żenczykowskicommited 2025-08-04 15:09:29 -07:00
(this matches what we did for maps)
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I2d75fb519f00471a6f1e6b0ffded9f327ecae7b4
Maciej Żenczykowskicommited 2025-08-04 15:07:05 -07:00
This is already documented at:
//packages/modules/Connectivity/bpf/progs/include/bpf_helpers.h
which is the more logical location, since we're trying
to merge all the .o's into 1 per kernel version.
Test: TreeHugger
Flag: EXEMPT mainline/noop
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ibda074ccbbf6efdf36dffd481d953ef38b421637
Maciej Żenczykowskicommited 2025-08-04 14:08:46 -07:00
This cannot happen (it's a .c misconfig if it does)
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5d82c7bb8c0214f5ffcc0ce391daddb9fe6a3295
Maciej Żenczykowskicommited 2025-08-04 13:02:06 -07:00
so that elf object related functions are next to each other
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I159e4e7ad96e3764206546f9f8c69ff156bcf790
Maciej Żenczykowskicommited 2025-08-01 14:53:27 -07:00
We go to a lot of trouble to return error codes, but
we never actually care about anything besides pass/fail.
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I8c0552246f1050813cca372a280b2302c701d617
Maciej Żenczykowskicommited 2025-08-01 14:53:18 -07:00
Sometimes *all* we see is the return code of the binary printed
out by init when we terminate with failure. Unique codes will
make debugging easier.
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Icc93813674af2855b2d9f378a1accac48b403aa3
Maciej Żenczykowskicommited 2025-08-01 14:53:06 -07:00
Since these are equivalent, search and replace...
Test: TreeHugger
Flag: EXEMPT mainline/noop
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I358220f5db70fcde671ce2560086fc7a220f49c7
Maciej Żenczykowskicommited 2025-07-31 17:19:10 -07:00
The field is actually just a compile time calculate index into pin_location.
We add a C++ only helper to return the ASCIIZ string at this offset.
Temporary abort() added to show this is equivalent.
Test: TreeHugger
Flag: EXEMPT mainline/noop
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: If57390b99f348ab03b277e8f68e7f38636c751fc
Maciej Żenczykowskicommited 2025-07-31 17:17:41 -07:00
easy to do for maps now, but harder for programs
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I0aedef7a8f28d8cc60ca4912f2666f920b9dbeb5
Maciej Żenczykowskicommited 2025-07-31 12:31:56 -07:00
Basically we can verify and precalculate this at build time.
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ie4e336c6dc82a0e93a3e62c88c313a32cb245861
Maciej Żenczykowskicommited 2025-07-30 15:27:49 -07:00
No longer required now that we have compile time verification.
Test: TreeHugger
Flag: EXEMPT mainline
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: I5b18727e8ebf820a06ba647bb7349ba755d5d798
Maciej Żenczykowskicommited 2025-07-30 15:02:07 -07:00