From 95c80c80cf7f26712e74cbeaadf33fa843cf920d Mon Sep 17 00:00:00 2001 From: luwenpeng Date: Sun, 23 Apr 2023 17:41:57 +0800 Subject: [PATCH] =?UTF-8?q?BPF=E9=80=82=E9=85=8D=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E7=9A=84=E7=BC=96=E8=AF=91=E7=8E=AF=E5=A2=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CMakeLists.txt | 4 +--- bpf/CMakeLists.txt | 8 +++++++- bpf/{bpf_obj.c => bpf_obj.cpp} | 28 ++++++++++++++++++++++++++++ common/CMakeLists.txt | 4 ---- 4 files changed, 36 insertions(+), 8 deletions(-) rename bpf/{bpf_obj.c => bpf_obj.cpp} (79%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b352675..b467b2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,6 +92,4 @@ add_subdirectory(plugin) add_subdirectory(platform) add_subdirectory(cache) add_subdirectory(script) -if (SUPPORT_BPF) - add_subdirectory(bpf) -endif() \ No newline at end of file +add_subdirectory(bpf) \ No newline at end of file diff --git a/bpf/CMakeLists.txt b/bpf/CMakeLists.txt index edaf3a1..095e301 100644 --- a/bpf/CMakeLists.txt +++ b/bpf/CMakeLists.txt @@ -1 +1,7 @@ -execute_process(COMMAND make WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/bpf/) \ No newline at end of file +add_library(bpf_obj bpf_obj.cpp) +target_include_directories(bpf_obj PUBLIC ${CMAKE_CURRENT_LIST_DIR}) +if (SUPPORT_BPF) + target_link_libraries(bpf_obj PUBLIC bpf) + execute_process(COMMAND make WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/bpf/) + install(FILES ./bpf_tun_rss_steering.o DESTINATION ${CMAKE_INSTALL_PREFIX}/resource/bpf/ COMPONENT PROFILE) +endif() \ No newline at end of file diff --git a/bpf/bpf_obj.c b/bpf/bpf_obj.cpp similarity index 79% rename from bpf/bpf_obj.c rename to bpf/bpf_obj.cpp index 86ce8b2..dde48cd 100644 --- a/bpf/bpf_obj.c +++ b/bpf/bpf_obj.cpp @@ -1,9 +1,12 @@ #include +#include +#include #include #include #include #include +#ifdef SUPPORT_BPF #include "bpf_config_user.h" #define MIN(a, b) ((a) > (b) ? (b) : (a)) @@ -95,3 +98,28 @@ int bpf_obj_attach(struct bpf_obj_ctx *ctx, int fd) return -1; } } +#else + +struct bpf_obj_ctx +{ +}; + +#include + +void bpf_obj_unload(struct bpf_obj_ctx *ctx) +{ + printf("ERROR: BPF feature not support on current system\n"); +} + +struct bpf_obj_ctx *bpf_obj_load(const char *obj_file, uint32_t queue_num, uint32_t hash_mode, uint32_t debug_log) +{ + printf("ERROR: BPF feature not support on current system\n"); + return NULL; +} + +int bpf_obj_attach(struct bpf_obj_ctx *ctx, int fd) +{ + printf("ERROR: BPF feature not support on current system\n"); + return -1; +} +#endif \ No newline at end of file diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index c513953..0b3d516 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -7,10 +7,6 @@ target_include_directories(common PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include) target_link_libraries(common PUBLIC libevent-static libevent-static-openssl libevent-static-pthreads rdkafka) target_link_libraries(common PUBLIC MESA_handle_logger cjson) -if (SUPPORT_BPF) - target_link_libraries(common PUBLIC bpf) -endif() - if (SUPPORT_LIBURING) target_link_libraries(common PUBLIC uring) endif()