BPF适配不同的编译环境

This commit is contained in:
luwenpeng
2023-04-23 17:41:57 +08:00
parent cbf424884c
commit 95c80c80cf
4 changed files with 36 additions and 8 deletions

View File

@@ -92,6 +92,4 @@ add_subdirectory(plugin)
add_subdirectory(platform)
add_subdirectory(cache)
add_subdirectory(script)
if (SUPPORT_BPF)
add_subdirectory(bpf)
endif()
add_subdirectory(bpf)

View File

@@ -1 +1,7 @@
execute_process(COMMAND make WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/bpf/)
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()

View File

@@ -1,9 +1,12 @@
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/if_tun.h>
#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 <sys/types.h>
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

View File

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