netbpfload: Support <4.14 kernels
Change-Id: I3d6573c102c1d64a64209bf61ecb8ed0c4ecb64c
Signed-off-by: Jis G Jacob <studiokeys@blissroms.org>
diff --git a/netbpfload/NetBpfLoad.cpp b/netbpfload/NetBpfLoad.cpp
index ed5193d..236adde 100644
--- a/netbpfload/NetBpfLoad.cpp
+++ b/netbpfload/NetBpfLoad.cpp
@@ -225,12 +225,14 @@
// kernel does not have CONFIG_BPF_JIT=y)
// BPF_JIT is required by R VINTF (which means 4.14/4.19/5.4 kernels),
// but 4.14/4.19 were released with P & Q, and only 5.4 is new in R+.
- if (writeProcSysFile("/proc/sys/net/core/bpf_jit_enable", "1\n")) return 1;
+ if (writeProcSysFile("/proc/sys/net/core/bpf_jit_enable", "1\n") &&
+ android::bpf::isAtLeastKernelVersion(4, 14, 0)) return 1;
// Enable JIT kallsyms export for privileged users only
// (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;
+ if (writeProcSysFile("/proc/sys/net/core/bpf_jit_kallsyms", "1\n") &&
+ android::bpf::isAtLeastKernelVersion(4, 14, 0)) return 1;
}
// Create all the pin subdirectories
diff --git a/netbpfload/loader.cpp b/netbpfload/loader.cpp
index 7754a3e..af9e9f1 100644
--- a/netbpfload/loader.cpp
+++ b/netbpfload/loader.cpp
@@ -784,7 +784,9 @@
.max_entries = max_entries,
.map_flags = md[i].map_flags,
};
- strlcpy(req.map_name, mapNames[i].c_str(), sizeof(req.map_name));
+ if (isAtLeastKernelVersion(4, 14, 0)) {
+ strlcpy(req.map_name, mapNames[i].c_str(), sizeof(req.map_name));
+ }
fd.reset(bpf(BPF_MAP_CREATE, req));
saved_errno = errno;
ALOGD("bpf_create_map name %s, ret: %d", mapNames[i].c_str(), fd.get());
@@ -1026,7 +1028,9 @@
.log_size = static_cast<__u32>(log_buf.size()),
.expected_attach_type = cs[i].expected_attach_type,
};
- strlcpy(req.prog_name, cs[i].name.c_str(), sizeof(req.prog_name));
+ if (isAtLeastKernelVersion(4, 14, 0)) {
+ strlcpy(req.prog_name, cs[i].name.c_str(), sizeof(req.prog_name));
+ }
fd.reset(bpf(BPF_PROG_LOAD, req));
ALOGD("BPF_PROG_LOAD call for %s (%s) returned fd: %d (%s)", elfPath,