bpfloader: refactor C++ loader to just one function
no need for the complexity, as it is only for vendor now Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: Ia807f7ee8aeca25d92e60e46f180ffe536eef87c
This commit is contained in:
parent
c041c4825b
commit
d689e6e01a
3 changed files with 7 additions and 19 deletions
|
|
@ -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<char**>(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));
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue