From a3ecd745945a56fda272324ae73624a2205f41c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Wed, 16 Jul 2025 08:55:30 -0700 Subject: [PATCH] vendorBpfLoader: trivialize getSectionType() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit since we only support skfilter/ we can simplify this (support for any future other vendor types should be added to the rust loader) Test: TreeHugger Flag: EXEMPT cleanup Signed-off-by: Maciej Żenczykowski Change-Id: I72ad38c056728ef768ee70bc38471c3e9d368f60 --- loader/Loader.cpp | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/loader/Loader.cpp b/loader/Loader.cpp index 268ec52..7d8a999 100644 --- a/loader/Loader.cpp +++ b/loader/Loader.cpp @@ -79,30 +79,6 @@ static string pathToObjName(const string& path) { return name.substr(0, name.find_last_of('@')); } -typedef struct { - const char* name; - enum bpf_prog_type type; -} sectionType; - -/* - * Map section name prefixes to program types, the section name will be: - * SECTION(/) - * For example: - * SECTION("tracepoint/sched_switch_func") where sched_switch_funcs - * is the name of the program, and tracepoint is the type. - * - * However, be aware that you should not be directly using the SECTION() macro. - * Instead use the DEFINE_(BPF|XDP)_(PROG|MAP)... & LICENSE/CRITICAL macros. - * - * see b/162057235. For arbitrary program types, the concern is that due to the lack of - * SELinux access controls over BPF program attachpoints, we have no way to control the - * attachment of programs to shared resources (or to detect when a shared resource - * has one BPF program replace another that is attached there) - */ -sectionType sectionNameTypes[] = { - {"skfilter/", BPF_PROG_TYPE_SOCKET_FILTER}, -}; - typedef struct { enum bpf_prog_type type; string name; @@ -258,13 +234,6 @@ static int readSymTab(ifstream& elfFile, int sort, vector& data) { return 0; } -static enum bpf_prog_type getSectionType(string& name) { - for (auto& snt : sectionNameTypes) - if (StartsWith(name, snt.name)) return snt.type; - - return BPF_PROG_TYPE_UNSPEC; -} - static int readProgDefs(ifstream& elfFile, vector& pd) { vector pdData; int ret = readSectionByName("progs", elfFile, pdData); @@ -350,16 +319,14 @@ static int readCodeSections(ifstream& elfFile, vector& cs) { ret = getSymName(elfFile, shTable[i].sh_name, name); if (ret) return ret; - enum bpf_prog_type ptype = getSectionType(name); - - if (ptype == BPF_PROG_TYPE_UNSPEC) continue; + if (!StartsWith(name, "skfilter/")) continue; string oldName = name; // convert all slashes to underscores std::replace(name.begin(), name.end(), '/', '_'); - cs_temp.type = ptype; + cs_temp.type = BPF_PROG_TYPE_SOCKET_FILTER; cs_temp.name = name; ret = readSectionByIdx(elfFile, i, cs_temp.data);