summaryrefslogtreecommitdiff
path: root/bpf
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2023-04-23 17:41:57 +0800
committerluwenpeng <[email protected]>2023-04-23 19:16:28 +0800
commit95c80c80cf7f26712e74cbeaadf33fa843cf920d (patch)
tree57a9bd70c39e8097bbf9df6e727bebce209b4a95 /bpf
parentcbf424884c0ea184353abb28e1bf8ba86ca19cf5 (diff)
BPF适配不同的编译环境
Diffstat (limited to 'bpf')
-rw-r--r--bpf/CMakeLists.txt8
-rw-r--r--bpf/bpf_obj.cpp (renamed from bpf/bpf_obj.c)28
2 files changed, 35 insertions, 1 deletions
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
index 86ce8b2..dde48cd 100644
--- a/bpf/bpf_obj.c
+++ b/bpf/bpf_obj.cpp
@@ -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 \ No newline at end of file