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()