From d689e6e01ad9a4b262159058f5eb26a9036098a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Tue, 17 Jun 2025 04:18:01 -0700 Subject: [PATCH] bpfloader: refactor C++ loader to just one function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit no need for the complexity, as it is only for vendor now Test: TreeHugger Signed-off-by: Maciej Żenczykowski Change-Id: Ia807f7ee8aeca25d92e60e46f180ffe536eef87c --- loader/Loader.cpp | 8 +------- loader/bpfloader.rs | 11 ++++------- loader/include/libbpf_android.h | 7 ++----- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/loader/Loader.cpp b/loader/Loader.cpp index 651be69..af684c5 100644 --- a/loader/Loader.cpp +++ b/loader/Loader.cpp @@ -936,23 +936,19 @@ int createSysFsBpfSubDir(const char* const prefix) { // ----- extern C stuff for rust below here ----- -void initLogging() { +void vendorBpfLoader() { // since we only ever get called from mainline NetBpfLoad // (see packages/modules/Connectivity/netbpfload/NetBpfLoad.cpp around line 516) // and there no arguments, so we can just pretend/assume this is the case. const char* argv[] = {"/system/bin/bpfloader", NULL}; android::base::InitLogging(const_cast(argv), &android::base::KernelLogger); -} -void createBpfFsSubDirectories() { for (const auto& location : android::bpf::locations) { if (android::bpf::createSysFsBpfSubDir(location.prefix)) { exit(120); } } -} -void legacyBpfLoader() { // Load all ELF objects, create programs and maps, and pin them for (const auto& location : android::bpf::locations) { if (android::bpf::loadAllElfObjects(location)) { @@ -965,9 +961,7 @@ void legacyBpfLoader() { exit(121); } } -} -void execNetBpfLoadDone() { const char* args[] = {"/apex/com.android.tethering/bin/netbpfload", "done", NULL}; execve(args[0], (char**)args, environ); ALOGE("FATAL: execve(): %d[%s]", errno, strerror(errno)); diff --git a/loader/bpfloader.rs b/loader/bpfloader.rs index b3af300..6c73606 100644 --- a/loader/bpfloader.rs +++ b/loader/bpfloader.rs @@ -640,14 +640,11 @@ fn main() { load_libbpf_progs(); info!("Loading legacy BPF progs"); - // SAFETY: Linking in the existing legacy bpfloader functionality. - // Any of the four following bindgen functions can abort() or exit() - // on failure and execNetBpfLoadDone() execve()'s. + // SAFETY: Linking in the existing legacy vendor bpfloader functionality. + // The following bindgen function can abort() or exit() on failure, + // but will usually execve(). unsafe { - bpf_android_bindgen::initLogging(); - bpf_android_bindgen::createBpfFsSubDirectories(); - bpf_android_bindgen::legacyBpfLoader(); - bpf_android_bindgen::execNetBpfLoadDone(); + bpf_android_bindgen::vendorBpfLoader(); } } diff --git a/loader/include/libbpf_android.h b/loader/include/libbpf_android.h index ae4a36d..9fb30b5 100644 --- a/loader/include/libbpf_android.h +++ b/loader/include/libbpf_android.h @@ -47,11 +47,8 @@ extern "C" { #define __noreturn #endif // __cplusplus -// The C++ portion of the BpfLoader is exposed as 3 functions to be called in order. -void initLogging(); -void createBpfFsSubDirectories(); -void legacyBpfLoader(); -__noreturn void execNetBpfLoadDone(); +// The C++ portion of the BpfLoader is exposed as a terminal function. +__noreturn void vendorBpfLoader(); #ifdef __cplusplus } // extern C