Merge "libbpf_load_test: fix map location"
diff --git a/OWNERS b/OWNERS
index 9d84f37..094de96 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,5 +1,5 @@
-fengc@google.com
-joelaf@google.com
+connoro@google.com
 lorenzo@google.com
 maze@google.com
+smoreland@google.com
 sspatil@google.com
diff --git a/libbpf_android/Android.bp b/libbpf_android/Android.bp
index 0892fad..7f8bd38 100644
--- a/libbpf_android/Android.bp
+++ b/libbpf_android/Android.bp
@@ -54,6 +54,7 @@
         "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/BpfUtils.cpp b/libbpf_android/BpfUtils.cpp
index df8c901..32b4120 100644
--- a/libbpf_android/BpfUtils.cpp
+++ b/libbpf_android/BpfUtils.cpp
@@ -125,30 +125,6 @@
     return bpf(BPF_MAP_GET_NEXT_KEY, Slice(&attr, sizeof(attr)));
 }
 
-int bpfProgLoad(bpf_prog_type prog_type, Slice bpf_insns, const char* license,
-                uint32_t kern_version, Slice bpf_log) {
-    bpf_attr attr;
-    memset(&attr, 0, sizeof(attr));
-    attr.prog_type = prog_type;
-    attr.insns = ptr_to_u64(bpf_insns.base());
-    attr.insn_cnt = bpf_insns.size() / sizeof(struct bpf_insn);
-    attr.license = ptr_to_u64((void*)license);
-    attr.log_buf = ptr_to_u64(bpf_log.base());
-    attr.log_size = bpf_log.size();
-    attr.log_level = DEFAULT_LOG_LEVEL;
-    attr.kern_version = kern_version;
-    int ret = bpf(BPF_PROG_LOAD, Slice(&attr, sizeof(attr)));
-
-    if (ret < 0) {
-        std::string prog_log = netdutils::toString(bpf_log);
-        std::istringstream iss(prog_log);
-        for (std::string line; std::getline(iss, line);) {
-            ALOGE("%s", line.c_str());
-        }
-    }
-    return ret;
-}
-
 int bpfFdPin(const base::unique_fd& map_fd, const char* pathname) {
     bpf_attr attr;
     memset(&attr, 0, sizeof(attr));
diff --git a/libbpf_android/Loader.cpp b/libbpf_android/Loader.cpp
index fb4e36c..f4533cb 100644
--- a/libbpf_android/Loader.cpp
+++ b/libbpf_android/Loader.cpp
@@ -36,6 +36,7 @@
 #include <string>
 #include <vector>
 
+#include <android-base/properties.h>
 #include <android-base/strings.h>
 #include <android-base/unique_fd.h>
 
@@ -390,6 +391,7 @@
     string fname = pathToFilename(string(elfPath), true);
 
     ret = readSectionByName("maps", elfFile, mdData);
+    if (ret == -2) return 0;  // no maps to read
     if (ret) return ret;
     md.resize(mdData.size() / sizeof(struct bpf_map_def));
     memcpy(md.data(), mdData.data(), mdData.size());
@@ -589,5 +591,11 @@
     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/bpf/BpfUtils.h b/libbpf_android/include/bpf/BpfUtils.h
index 7afdb5b..e94f9e1 100644
--- a/libbpf_android/include/bpf/BpfUtils.h
+++ b/libbpf_android/include/bpf/BpfUtils.h
@@ -43,38 +43,6 @@
 namespace android {
 namespace bpf {
 
-struct UidTag {
-    uint32_t uid;
-    uint32_t tag;
-};
-
-struct StatsKey {
-    uint32_t uid;
-    uint32_t tag;
-    uint32_t counterSet;
-    uint32_t ifaceIndex;
-};
-
-struct StatsValue {
-    uint64_t rxPackets;
-    uint64_t rxBytes;
-    uint64_t txPackets;
-    uint64_t txBytes;
-};
-
-struct Stats {
-    uint64_t rxBytes;
-    uint64_t rxPackets;
-    uint64_t txBytes;
-    uint64_t txPackets;
-    uint64_t tcpRxPackets;
-    uint64_t tcpTxPackets;
-};
-
-struct IfaceValue {
-    char name[IFNAMSIZ];
-};
-
 int mapRetrieve(const char* pathname, uint32_t flags);
 
 enum class BpfLevel {
@@ -106,8 +74,6 @@
 int deleteMapEntry(const base::unique_fd& map_fd, void* key);
 int getNextMapKey(const base::unique_fd& map_fd, void* key, void* next_key);
 int getFirstMapKey(const base::unique_fd& map_fd, void* firstKey);
-int bpfProgLoad(bpf_prog_type prog_type, netdutils::Slice bpf_insns, const char* license,
-                uint32_t kern_version, netdutils::Slice bpf_log);
 int bpfFdPin(const base::unique_fd& map_fd, const char* pathname);
 int bpfFdGet(const char* pathname, uint32_t flags);
 int attachProgram(bpf_attach_type type, uint32_t prog_fd, uint32_t cg_fd);
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