Load BPF programs from system and mainline folder am: 4b8e982fae am: ea0fe1584f am: 5cc8270e23 am: 20cc4c86ed

Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/1424248

Change-Id: I15af9e61dfd098fbac449b2c758559065f7805a1
This commit is contained in:
Hungming Chen 2020-09-18 06:12:51 +00:00 committed by Automerger Merge Worker
commit 916a1a7dbc

View file

@ -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,15 +85,17 @@ 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 ===");
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("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) {
ALOGE("Failed to set bpf.progs_loaded property");