1
0
Fork 0
mirror of https://github.com/pavel-odintsov/fastnetmon synced 2024-06-09 01:06:04 +02:00

Added workaround for https://github.com/libbpf/libbpf/issues/249 to build new libbpf on Ubuntu 20.04 and Debian 10

This commit is contained in:
Pavel Odintsov 2022-11-27 17:48:18 +00:00
parent 8987633ac2
commit 3b91233280
2 changed files with 66 additions and 0 deletions

View File

@ -284,6 +284,43 @@ if (ENABLE_AFPACKET_SUPPORT)
add_library(afpacket_plugin STATIC afpacket_plugin/afpacket_collector.cpp)
endif()
# We need to check that kernel headers actually support it as it's relatively new thing
CHECK_CXX_SOURCE_COMPILES("
#include <linux/bpf.h>
int main() {
bpf_stats_type my_bpf_type;
return 1;
}
" HAVE_BPF_STATS_TYPE)
if (${HAVE_BPF_STATS_TYPE})
message(STATUS "Kernel has enum bpf_stats_type declared")
else()
message(STATUS "Kernel does not have enum bpf_stats_type declared. Try to declare our own to address libbpf issue: https://github.com/libbpf/libbpf/issues/249")
add_definitions(-DDECLARE_FAKE_BPF_STATS)
endif()
# We need to check that kernel headers actually include it
CHECK_CXX_SOURCE_COMPILES("
#include <linux/bpf.h>
int main() {
bpf_link_type my_bpf_type;
return 1;
}
" HAVE_BPF_LINK_TYPE)
if (${HAVE_BPF_LINK_TYPE})
message(STATUS "Kernel has enum bpf_link_type declared")
else()
message(STATUS "Kernel does not have enum bpf_link_type declared. Try to declare our own to address libbpf issue: https://github.com/libbpf/libbpf/issues/249")
add_definitions(-DDECLARE_FAKE_BPF_LINK_TYPE)
endif()
CHECK_CXX_SOURCE_COMPILES("
#include <linux/if_xdp.h>
int main() {

View File

@ -10,6 +10,35 @@
// TODO: add support for multiple interfaces
// Only relatively fresh kernels have this type and we need to declare this type on older kernels to be able to compile libbpf
// On Ubuntu 20.04 and Debian 11
#ifdef DECLARE_FAKE_BPF_STATS
/* type for BPF_ENABLE_STATS */
enum bpf_stats_type {
/* enabled run_time_ns and run_cnt */
BPF_STATS_RUN_TIME = 0,
};
#endif
#ifdef DECLARE_FAKE_BPF_LINK_TYPE
enum bpf_link_type {
BPF_LINK_TYPE_UNSPEC = 0,
BPF_LINK_TYPE_RAW_TRACEPOINT = 1,
BPF_LINK_TYPE_TRACING = 2,
BPF_LINK_TYPE_CGROUP = 3,
BPF_LINK_TYPE_ITER = 4,
BPF_LINK_TYPE_NETNS = 5,
BPF_LINK_TYPE_XDP = 6,
BPF_LINK_TYPE_PERF_EVENT = 7,
MAX_BPF_LINK_TYPE,
};
#endif
extern "C" {
#include <bpf/bpf.h>
#include <bpf/libbpf.h>