diff options
author | Hungming Chen <nuccachen@google.com> | 2020-09-10 15:51:59 +0800 |
---|---|---|
committer | Hungming Chen <nuccachen@google.com> | 2020-09-17 11:38:53 +0800 |
commit | 4b8e982fae7a6dfcace68755dc3b87f727320098 (patch) | |
tree | 619afba90e4dcdb820b96a8284387359eb5793f4 /bpfloader | |
parent | 0afd92cb3ab3f45eadd16d1fbfaec66595a31af4 (diff) | |
download | bpf-4b8e982fae7a6dfcace68755dc3b87f727320098.tar.gz |
Load BPF programs from system and mainline folder
Test: flash and boot successfully
Change-Id: Ia1a713024686c36e34f7cf525a284abc00fe56e2
Diffstat (limited to 'bpfloader')
-rw-r--r-- | bpfloader/BpfLoader.cpp | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/bpfloader/BpfLoader.cpp b/bpfloader/BpfLoader.cpp index 5aacf6c..33208d1 100644 --- a/bpfloader/BpfLoader.cpp +++ b/bpfloader/BpfLoader.cpp @@ -51,19 +51,21 @@ using android::base::EndsWith; using std::string; -#define BPF_PROG_PATH "/system/etc/bpf/" +#define BPF_PROG_PATH_MAINLINE_TETHERING "/apex/com.android.tethering/etc/bpf/" +#define BPF_PROG_PATH_SYSTEM "/system/etc/bpf/" -int loadAllElfObjects(void) { +int loadAllElfObjects(const char* progDir) { int retVal = 0; DIR* dir; struct dirent* ent; - if ((dir = opendir(BPF_PROG_PATH)) != NULL) { + if ((dir = opendir(progDir)) != NULL) { while ((ent = readdir(dir)) != NULL) { string s = ent->d_name; if (!EndsWith(s, ".o")) continue; - string progPath = BPF_PROG_PATH + s; + string progPath(progDir); + progPath += s; bool critical; int ret = android::bpf::loadProg(progPath.c_str(), &critical); @@ -83,14 +85,16 @@ int main() { if (!android::bpf::isBpfSupported()) return 0; // Load all ELF objects, create programs and maps, and pin them - if (loadAllElfObjects() != 0) { - ALOGE("=== CRITICAL FAILURE LOADING BPF PROGRAMS ==="); - ALOGE("If this triggers reliably, you're probably missing kernel options or patches."); - ALOGE("If this triggers randomly, you might be hitting some memory allocation problems or " - "startup script race."); - ALOGE("--- DO NOT EXPECT SYSTEM TO BOOT SUCCESSFULLY ---"); - sleep(20); - return 2; + for (const auto dir : {BPF_PROG_PATH_MAINLINE_TETHERING, BPF_PROG_PATH_SYSTEM}) { + if (loadAllElfObjects(dir) != 0) { + ALOGE("=== CRITICAL FAILURE LOADING BPF PROGRAMS FROM %s ===", dir); + ALOGE("If this triggers reliably, you're probably missing kernel options or patches."); + ALOGE("If this triggers randomly, you might be hitting some memory allocation " + "problems or startup script race."); + ALOGE("--- DO NOT EXPECT SYSTEM TO BOOT SUCCESSFULLY ---"); + sleep(20); + return 2; + } } if (android::base::SetProperty("bpf.progs_loaded", "1") == false) { |