put tethering bpf maps & programs in /sys/fs/bpf/tethering/...
This makes it harder for system and mainline bpf programs to
conflict with each other, thus enabling easier mainline module
updates.
Test: builds and boots, atest, TreeHugger
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic1b69bb1ddc4a10bd4861dadbd6b97e2520c532d
diff --git a/libbpf_android/Loader.cpp b/libbpf_android/Loader.cpp
index e61f460..05a5067 100644
--- a/libbpf_android/Loader.cpp
+++ b/libbpf_android/Loader.cpp
@@ -403,7 +403,8 @@
return getSymName(elfFile, symtab[index].st_name, name);
}
-static int createMaps(const char* elfPath, ifstream& elfFile, vector<unique_fd>& mapFds) {
+static int createMaps(const char* elfPath, ifstream& elfFile, vector<unique_fd>& mapFds,
+ const char* prefix) {
int ret;
vector<char> mdData;
vector<struct bpf_map_def> md;
@@ -421,11 +422,11 @@
for (int i = 0; i < (int)mapNames.size(); i++) {
unique_fd fd;
- // Format of pin location is /sys/fs/bpf/map_<filename>_<mapname>
+ // Format of pin location is /sys/fs/bpf/<prefix>map_<filename>_<mapname>
string mapPinLoc;
bool reuse = false;
- mapPinLoc = string(BPF_FS_PATH) + "map_" + fname + "_" + string(mapNames[i]);
+ mapPinLoc = string(BPF_FS_PATH) + prefix + "map_" + fname + "_" + string(mapNames[i]);
if (access(mapPinLoc.c_str(), F_OK) == 0) {
fd.reset(bpf_obj_get(mapPinLoc.c_str()));
ALOGD("bpf_create_map reusing map %s, ret: %d\n", mapNames[i].c_str(), fd.get());
@@ -527,7 +528,8 @@
}
}
-static int loadCodeSections(const char* elfPath, vector<codeSection>& cs, const string& license) {
+static int loadCodeSections(const char* elfPath, vector<codeSection>& cs, const string& license,
+ const char* prefix) {
unsigned kvers = kernelVersion();
int ret, fd;
@@ -554,8 +556,10 @@
bool reuse = false;
// Format of pin location is
- // /sys/fs/bpf/prog_<filename>_<mapname>
- string progPinLoc = BPF_FS_PATH "prog_";
+ // /sys/fs/bpf/<prefix>prog_<filename>_<mapname>
+ string progPinLoc = BPF_FS_PATH;
+ progPinLoc += prefix;
+ progPinLoc += "prog_";
progPinLoc += fname;
progPinLoc += '_';
progPinLoc += name;
@@ -609,7 +613,7 @@
return 0;
}
-int loadProg(const char* elfPath, bool* isCritical) {
+int loadProg(const char* elfPath, bool* isCritical, const char* prefix) {
vector<char> license;
vector<char> critical;
vector<codeSection> cs;
@@ -644,7 +648,7 @@
/* Just for future debugging */
if (0) dumpAllCs(cs);
- ret = createMaps(elfPath, elfFile, mapFds);
+ ret = createMaps(elfPath, elfFile, mapFds, prefix);
if (ret) {
ALOGE("Failed to create maps: (ret=%d) in %s\n", ret, elfPath);
return ret;
@@ -655,7 +659,7 @@
applyMapRelo(elfFile, mapFds, cs);
- ret = loadCodeSections(elfPath, cs, string(license.data()));
+ ret = loadCodeSections(elfPath, cs, string(license.data()), prefix);
if (ret) ALOGE("Failed to load programs, loadCodeSections ret=%d\n", ret);
return ret;