From dcb5228f2c0554cbee98be6477848451eb7fa94e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20=C5=BBenczykowski?= Date: Sun, 17 Jan 2021 03:36:34 -0800 Subject: [PATCH] remove BpfLevel and getBpfSupportLevel in favour of isAtLeastKernelVersion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test: builds, atest, TreeHugger Bug: 167500195 Signed-off-by: Maciej Żenczykowski Change-Id: I50dbed1843a8c2802e1b416281e193ae7d282a99 --- libbpf_android/BpfUtils.cpp | 18 --------------- libbpf_android/include/bpf/BpfUtils.h | 33 ++++++++++++--------------- 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