netbpfload: prep work to support <U
proc file writes were only moved from .rc into bpfloader binary in U. Test: TreeHugger Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I20eda71d4f4e16130401d1cfff239c7cd8ea9bf6
This commit is contained in:
@@ -38,6 +38,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <android/api-level.h>
|
||||
#include <android-base/logging.h>
|
||||
#include <android-base/macros.h>
|
||||
#include <android-base/properties.h>
|
||||
@@ -172,6 +173,9 @@ int main(int argc, char** argv, char * const envp[]) {
|
||||
(void)argc;
|
||||
android::base::InitLogging(argv, &android::base::KernelLogger);
|
||||
|
||||
const int device_api_level = android_get_device_api_level();
|
||||
const bool isAtLeastU = (device_api_level >= __ANDROID_API_U__);
|
||||
|
||||
if (!android::bpf::isAtLeastKernelVersion(4, 19, 0)) {
|
||||
ALOGE("Android U QPR2 requires kernel 4.19.");
|
||||
return 1;
|
||||
@@ -208,9 +212,11 @@ int main(int argc, char** argv, char * const envp[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Linux 5.16-rc1 changed the default to 2 (disabled but changeable), but we need 0 (enabled)
|
||||
// (this writeFile is known to fail on at least 4.19, but always defaults to 0 on pre-5.13,
|
||||
// on 5.13+ it depends on CONFIG_BPF_UNPRIV_DEFAULT_OFF)
|
||||
if (isAtLeastU) {
|
||||
// Linux 5.16-rc1 changed the default to 2 (disabled but changeable),
|
||||
// but we need 0 (enabled)
|
||||
// (this writeFile is known to fail on at least 4.19, but always defaults to 0 on
|
||||
// pre-5.13, on 5.13+ it depends on CONFIG_BPF_UNPRIV_DEFAULT_OFF)
|
||||
if (writeProcSysFile("/proc/sys/kernel/unprivileged_bpf_disabled", "0\n") &&
|
||||
android::bpf::isAtLeastKernelVersion(5, 13, 0)) return 1;
|
||||
|
||||
@@ -226,6 +232,7 @@ int main(int argc, char** argv, char * const envp[]) {
|
||||
// (Note: this (open) will fail with ENOENT 'No such file or directory' if
|
||||
// kernel does not have CONFIG_HAVE_EBPF_JIT=y)
|
||||
if (writeProcSysFile("/proc/sys/net/core/bpf_jit_kallsyms", "1\n")) return 1;
|
||||
}
|
||||
|
||||
// Create all the pin subdirectories
|
||||
// (this must be done first to allow selinux_context and pin_subdir functionality,
|
||||
|
||||
Reference in New Issue
Block a user