diff options
author | Maciej Żenczykowski <maze@google.com> | 2022-12-10 11:06:03 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-12-10 11:06:03 +0000 |
commit | 1432ac4cca7075f39c57e7ebb78398eabdf5ce4c (patch) | |
tree | 678719ba07d2398993e43c6472cf6d184f94073b | |
parent | bba7ee57a819e5b2368cc24a50e96b55adca6da6 (diff) | |
parent | b909fed62affbc89ce5d98065d3144de319c102a (diff) | |
download | bpf-1432ac4cca7075f39c57e7ebb78398eabdf5ce4c.tar.gz |
Merge "bpfloader: pass whole struct Location to loadProg()" am: b909fed62a
Original change: https://android-review.googlesource.com/c/platform/system/bpf/+/2325035
Change-Id: I94d604c44cc2c6315ceebba96c52ff9745281352
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | bpfloader/BpfLoader.cpp | 17 | ||||
-rw-r--r-- | libbpf_android/BpfLoadTest.cpp | 12 | ||||
-rw-r--r-- | libbpf_android/Loader.cpp | 13 | ||||
-rw-r--r-- | libbpf_android/include/libbpf_android.h | 12 |
4 files changed, 28 insertions, 26 deletions
diff --git a/bpfloader/BpfLoader.cpp b/bpfloader/BpfLoader.cpp index ea074fa..313b097 100644 --- a/bpfloader/BpfLoader.cpp +++ b/bpfloader/BpfLoader.cpp @@ -118,15 +118,8 @@ constexpr bpf_prog_type kVendorAllowedProgTypes[] = { BPF_PROG_TYPE_SOCKET_FILTER, }; -struct Location { - const char* const dir; - const char* const prefix; - unsigned long long allowedDomainBitmask; - const bpf_prog_type* allowedProgTypes = nullptr; - size_t allowedProgTypesLength = 0; -}; -const Location locations[] = { +const android::bpf::Location locations[] = { // S+ Tethering mainline module (network_stack): tether offload { .dir = "/apex/com.android.tethering/etc/bpf/", @@ -187,7 +180,7 @@ const Location locations[] = { }, }; -int loadAllElfObjects(const Location& location) { +int loadAllElfObjects(const android::bpf::Location& location) { int retVal = 0; DIR* dir; struct dirent* ent; @@ -201,11 +194,7 @@ int loadAllElfObjects(const Location& location) { progPath += s; bool critical; - int ret = android::bpf::loadProg(progPath.c_str(), &critical, - location.prefix, - location.allowedDomainBitmask, - location.allowedProgTypes, - location.allowedProgTypesLength); + int ret = android::bpf::loadProg(progPath.c_str(), &critical, location); if (ret) { if (critical) retVal = ret; ALOGE("Failed to load object: %s, ret: %s", progPath.c_str(), std::strerror(-ret)); diff --git a/libbpf_android/BpfLoadTest.cpp b/libbpf_android/BpfLoadTest.cpp index 8e853b9..0c4e6ee 100644 --- a/libbpf_android/BpfLoadTest.cpp +++ b/libbpf_android/BpfLoadTest.cpp @@ -53,9 +53,15 @@ class BpfLoadTest : public TestWithParam<std::string> { bpf_prog_type kAllowed[] = { BPF_PROG_TYPE_UNSPEC, }; - EXPECT_EQ(android::bpf::loadProg(progPath.c_str(), &critical, "", 0, kAllowed, - arraysize(kAllowed)), - -1); + + Location loc = { + .dir = "", + .prefix = "", + .allowedDomainBitmask = 0, + .allowedProgTypes = kAllowed, + .allowedProgTypesLength = arraysize(kAllowed), + }; + EXPECT_EQ(android::bpf::loadProg(progPath.c_str(), &critical, loc), -1); EXPECT_EQ(android::bpf::loadProg(progPath.c_str(), &critical), 0); EXPECT_EQ(false, critical); diff --git a/libbpf_android/Loader.cpp b/libbpf_android/Loader.cpp index 5b621ae..f1a0123 100644 --- a/libbpf_android/Loader.cpp +++ b/libbpf_android/Loader.cpp @@ -1139,9 +1139,7 @@ static int loadCodeSections(const char* elfPath, vector<codeSection>& cs, const return 0; } -int loadProg(const char* elfPath, bool* isCritical, const char* prefix, - const unsigned long long allowedDomainBitmask, const bpf_prog_type* allowed, - size_t numAllowed) { +int loadProg(const char* elfPath, bool* isCritical, const Location& location) { vector<char> license; vector<char> critical; vector<codeSection> cs; @@ -1214,7 +1212,8 @@ int loadProg(const char* elfPath, bool* isCritical, const char* prefix, return -1; } - ret = readCodeSections(elfFile, cs, sizeOfBpfProgDef, allowed, numAllowed); + ret = readCodeSections(elfFile, cs, sizeOfBpfProgDef, location.allowedProgTypes, + location.allowedProgTypesLength); if (ret) { ALOGE("Couldn't read all code sections in %s", elfPath); return ret; @@ -1223,7 +1222,8 @@ int loadProg(const char* elfPath, bool* isCritical, const char* prefix, /* Just for future debugging */ if (0) dumpAllCs(cs); - ret = createMaps(elfPath, elfFile, mapFds, prefix, allowedDomainBitmask, sizeOfBpfMapDef); + ret = createMaps(elfPath, elfFile, mapFds, location.prefix, location.allowedDomainBitmask, + sizeOfBpfMapDef); if (ret) { ALOGE("Failed to create maps: (ret=%d) in %s", ret, elfPath); return ret; @@ -1234,7 +1234,8 @@ int loadProg(const char* elfPath, bool* isCritical, const char* prefix, applyMapRelo(elfFile, mapFds, cs); - ret = loadCodeSections(elfPath, cs, string(license.data()), prefix, allowedDomainBitmask); + ret = loadCodeSections(elfPath, cs, string(license.data()), location.prefix, + location.allowedDomainBitmask); if (ret) ALOGE("Failed to load programs, loadCodeSections ret=%d", ret); return ret; diff --git a/libbpf_android/include/libbpf_android.h b/libbpf_android/include/libbpf_android.h index 95e1f19..7811179 100644 --- a/libbpf_android/include/libbpf_android.h +++ b/libbpf_android/include/libbpf_android.h @@ -78,10 +78,16 @@ static constexpr bool inDomainBitmask(domain d, unsigned long long v) { return domainToBitmask(d) & v; } +struct Location { + const char* const dir = ""; + const char* const prefix = ""; + unsigned long long allowedDomainBitmask = 0; + const bpf_prog_type* allowedProgTypes = nullptr; + size_t allowedProgTypesLength = 0; +}; + // BPF loader implementation. Loads an eBPF ELF object -int loadProg(const char* elfPath, bool* isCritical, const char* prefix = "", - const unsigned long long allowedDomainBitmask = 0, - const bpf_prog_type* allowed = nullptr, size_t numAllowed = 0); +int loadProg(const char* elfPath, bool* isCritical, const Location &location = {}); // Exposed for testing unsigned int readSectionUint(const char* name, std::ifstream& elfFile, unsigned int defVal); |