summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaciej Żenczykowski <maze@google.com>2021-01-17 03:36:34 -0800
committerMaciej Żenczykowski <maze@google.com>2021-01-19 23:48:01 -0800
commitdcb5228f2c0554cbee98be6477848451eb7fa94e (patch)
tree71a26bb3e81931899eb12a0273983ea643a316fb
parentd8a4578f30dd1a355591a7b18d139a9ac0a48f72 (diff)
downloadplatform_system_bpf-dcb5228f2c0554cbee98be6477848451eb7fa94e.tar.gz
platform_system_bpf-dcb5228f2c0554cbee98be6477848451eb7fa94e.tar.bz2
platform_system_bpf-dcb5228f2c0554cbee98be6477848451eb7fa94e.zip
remove BpfLevel and getBpfSupportLevel in favour of isAtLeastKernelVersion
Test: builds, atest, TreeHugger Bug: 167500195 Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I50dbed1843a8c2802e1b416281e193ae7d282a99
-rw-r--r--libbpf_android/BpfUtils.cpp18
-rw-r--r--libbpf_android/include/bpf/BpfUtils.h33
2 files changed, 14 insertions, 37 deletions
diff --git a/libbpf_android/BpfUtils.cpp b/libbpf_android/BpfUtils.cpp
index 5fed9c2..8689192 100644
--- a/libbpf_android/BpfUtils.cpp
+++ b/libbpf_android/BpfUtils.cpp
@@ -94,8 +94,6 @@ int setrlimitForTest() {
return res;
}
-#define KVER(a, b, c) ((a)*65536 + (b)*256 + (c))
-
unsigned kernelVersion() {
struct utsname buf;
int ret = uname(&buf);
@@ -112,21 +110,5 @@ unsigned kernelVersion() {
return KVER(kver_major, kver_minor, kver_sub);
}
-static BpfLevel getUncachedBpfSupportLevel() {
- unsigned kver = kernelVersion();
-
- if (kver >= KVER(5, 4, 0)) return BpfLevel::EXTENDED_5_4;
- if (kver >= KVER(4, 19, 0)) return BpfLevel::EXTENDED_4_19;
- if (kver >= KVER(4, 14, 0)) return BpfLevel::EXTENDED_4_14;
-
- // Basic BPF support is required on all devices.
- return BpfLevel::BASIC_4_9;
-}
-
-BpfLevel getBpfSupportLevel() {
- static BpfLevel cache = getUncachedBpfSupportLevel();
- return cache;
-}
-
} // namespace bpf
} // namespace android
diff --git a/libbpf_android/include/bpf/BpfUtils.h b/libbpf_android/include/bpf/BpfUtils.h
index 0843339..08c1844 100644
--- a/libbpf_android/include/bpf/BpfUtils.h
+++ b/libbpf_android/include/bpf/BpfUtils.h
@@ -30,17 +30,6 @@
namespace android {
namespace bpf {
-enum class BpfLevel {
- // Devices shipped in P with android 4.9 kernel only have the basic eBPF
- // functionalities such as xt_bpf and cgroup skb filter.
- BASIC_4_9,
- // For devices that have 4.14 kernel. It supports advanced features like
- // map_in_map and cgroup socket filter.
- EXTENDED_4_14,
- EXTENDED_4_19,
- EXTENDED_5_4,
-};
-
constexpr const int OVERFLOW_COUNTERSET = 2;
constexpr const uint64_t NONEXISTENT_COOKIE = 0;
@@ -50,20 +39,26 @@ constexpr const int MINIMUM_API_REQUIRED = 28;
uint64_t getSocketCookie(int sockFd);
int synchronizeKernelRCU();
int setrlimitForTest();
+
+#define KVER(a, b, c) ((a)*65536 + (b)*256 + (c))
+
unsigned kernelVersion();
-BpfLevel getBpfSupportLevel();
+
+static inline bool isAtLeastKernelVersion(unsigned major, unsigned minor, unsigned sub) {
+ return kernelVersion() >= KVER(major, minor, sub);
+}
inline bool isBpfSupported() {
return true;
}
-#define SKIP_IF_EXTENDED_BPF_NOT_SUPPORTED \
- do { \
- if (android::bpf::getBpfSupportLevel() < android::bpf::BpfLevel::EXTENDED_4_14) { \
- GTEST_LOG_(INFO) << "This test is skipped since extended bpf feature" \
- << "not supported\n"; \
- return; \
- } \
+#define SKIP_IF_EXTENDED_BPF_NOT_SUPPORTED \
+ do { \
+ if (!android::bpf::isAtLeastKernelVersion(4, 14, 0)) { \
+ GTEST_LOG_(INFO) << "This test is skipped since extended bpf feature" \
+ << "not supported\n"; \
+ return; \
+ } \
} while (0)
} // namespace bpf