From 4891e61341488050507f9a3e5c0915ff906a9c13 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Fri, 10 Jan 2020 15:35:52 -0800 Subject: [PATCH] libbpf_android: waitForProgsLoaded Creating a function for this rather than having people copy/paste a loop there. It's very intentional that there is no timeout here. If bpfloader is down, there is a serious problem, and we shouldn't let code move forward in a state where it may not have been tested. Bug: 140330870 Test: boot & use bpf/netd Change-Id: I358d1fcf77ad5406e294dd57307bc411e2c8ad6a --- libbpf_android/Android.bp | 1 + libbpf_android/Loader.cpp | 7 +++++++ libbpf_android/include/libbpf_android.h | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/libbpf_android/Android.bp b/libbpf_android/Android.bp index c369c8c..956fd93 100644 --- a/libbpf_android/Android.bp +++ b/libbpf_android/Android.bp @@ -54,6 +54,7 @@ cc_library { "libbpf_android_headers" ], export_header_lib_headers: ["libbpf_android_headers"], + export_shared_lib_headers: ["libbpf"], local_include_dirs: ["include"], defaults: ["bpf_defaults"], diff --git a/libbpf_android/Loader.cpp b/libbpf_android/Loader.cpp index fb4e36c..021e79f 100644 --- a/libbpf_android/Loader.cpp +++ b/libbpf_android/Loader.cpp @@ -36,6 +36,7 @@ #include #include +#include #include #include @@ -589,5 +590,11 @@ int loadProg(const char* elfPath) { return ret; } +void waitForProgsLoaded() { + while (!android::base::WaitForProperty("bpf.progs_loaded", "1", std::chrono::seconds(5))) { + ALOGW("Waited 5s for bpf.progs_loaded, still waiting..."); + } +} + } // namespace bpf } // namespace android diff --git a/libbpf_android/include/libbpf_android.h b/libbpf_android/include/libbpf_android.h index cea707c..0a01c85 100644 --- a/libbpf_android/include/libbpf_android.h +++ b/libbpf_android/include/libbpf_android.h @@ -23,8 +23,13 @@ namespace android { namespace bpf { + // BPF loader implementation. Loads an eBPF ELF object int loadProg(const char* elfpath); + +// Wait for bpfloader to load BPF programs. +void waitForProgsLoaded(); + } // namespace bpf } // namespace android