From 5ef0990f942176e7c42fda6e89e6cb8a697ad0e5 Mon Sep 17 00:00:00 2001 From: lec-bit Date: Thu, 20 Nov 2025 10:24:30 +0800 Subject: [PATCH 1/2] rm OE_23_03 MARCO and optmize build Signed-off-by: lec-bit --- bpf/include/common.h | 8 +------ bpf/kmesh/ads/include/ctx/sock_ops.h | 11 ---------- build.sh | 7 ++++++ config/kmesh_marcos_def.h | 22 ------------------- hack/gen_bpf_specs.go | 4 +++- hack/utils.sh | 2 +- kernel/ko_src/Makefile | 4 +++- kernel/ko_src/kmesh/defer_connect.c | 22 +------------------ oncn-mda/include/mesh_accelerate.h | 10 ++------- .../new_version_mapspec_loader_enhanced.go | 1 - pkg/controller/controller.go | 7 +++--- 11 files changed, 21 insertions(+), 77 deletions(-) diff --git a/bpf/include/common.h b/bpf/include/common.h index 95249f8b6..b3691ecf9 100644 --- a/bpf/include/common.h +++ b/bpf/include/common.h @@ -113,14 +113,8 @@ static inline bool is_ipv4_mapped_addr(__u32 ip6[4]) (dst)[3] = (src)[3]; \ } while (0) -#if OE_23_03 -#define bpf__strncmp bpf_strncmp -#define GET_SKOPS_REMOTE_PORT(sk_ops) (__u16)((sk_ops)->remote_port) -#else #define GET_SKOPS_REMOTE_PORT(sk_ops) (__u16)((sk_ops)->remote_port >> 16) -#endif - -#define GET_SKOPS_LOCAL_PORT(sk_ops) (__u16)((sk_ops)->local_port) +#define GET_SKOPS_LOCAL_PORT(sk_ops) (__u16)((sk_ops)->local_port) #define MAX_BUF_LEN 100 #define MAX_IP4_LEN 16 diff --git a/bpf/kmesh/ads/include/ctx/sock_ops.h b/bpf/kmesh/ads/include/ctx/sock_ops.h index fe733f909..34a0f1a76 100644 --- a/bpf/kmesh/ads/include/ctx/sock_ops.h +++ b/bpf/kmesh/ads/include/ctx/sock_ops.h @@ -22,16 +22,6 @@ typedef struct bpf_sock_ops ctx_buff_t; name.ipv4 = (ctx)->remote_ip4; \ name.port = (ctx)->remote_port -#if OE_23_03 -#define SET_CTX_ADDRESS(ctx, address) \ - (ctx)->remote_ip4 = (address)->ipv4; \ - (ctx)->remote_port = (address)->port - -#define MARK_REJECTED(ctx) \ - BPF_LOG(DEBUG, KMESH, "mark reject\n"); \ - (ctx)->remote_ip4 = 0; \ - (ctx)->remote_port = 0 -#else #define SET_CTX_ADDRESS(ctx, address) \ (ctx)->replylong[2] = (address)->ipv4; \ (ctx)->replylong[3] = (address)->port @@ -40,6 +30,5 @@ typedef struct bpf_sock_ops ctx_buff_t; BPF_LOG(DEBUG, KMESH, "mark reject\n"); \ (ctx)->replylong[2] = 0; \ (ctx)->replylong[3] = 0 -#endif #endif //__BPF_CTX_SOCK_OPS_H diff --git a/build.sh b/build.sh index 1d40a7b3e..93bfddbdd 100755 --- a/build.sh +++ b/build.sh @@ -48,6 +48,13 @@ if [ -z "$1" -o "$1" == "-b" -o "$1" == "--build" ]; then exit fi +if [ "$1" == "-d" -o "$1" == "--docker" ]; then + prepare + make kmesh-bpf + make all-binary + exit +fi + if [ "$1" == "-i" -o "$1" == "--install" ]; then make install install diff --git a/config/kmesh_marcos_def.h b/config/kmesh_marcos_def.h index 4daf23236..51cd0b274 100644 --- a/config/kmesh_marcos_def.h +++ b/config/kmesh_marcos_def.h @@ -24,28 +24,6 @@ */ #define MDA_GID_UID_FILTER 1 -/* - * openEuler-23.03 is an innovative version of openEuler, in the early time, we - * developed kmesh based on openEuler-23.03, and the implementation of kmesh - * was related to the openEuler-23.03 kernel. Now, the general implementation - * of kmesh differs from the previous openEuler-23.03 version, so we need to - * use this macro to distinguish these differences. - * The main differences between the general implementation of kmesh and the - * openEuler-23.03 version are as follows: - * 1. Use replylong parameter instead of directly modifying the remote IP and Port; - * 2. Use bpf__strncmp instead of bpf_strncmp for string comparison; - * 3. Fix Port shift bug on openEuler-23.03.In the kernel network protocol - * stack, the port is stored in u16, but in the bpf network module, the port - * is stored in u32. Therefore, after the endian conversion, the 16-bit port - * needs to be obtained from the 32-bit data structure. - * You need to find the position of the valid 16 bits. Generally, after the - * port is extended from 16 bits to 32 bits, the port is in the upper 16 - * bits after the endian conversion. Therefore, you need to offset the port - * before using the u16 RX port. In some specific kernels, the port stored - * in sockops is in the lower 16 bits and does not need to be offset. - */ -#define OE_23_03 0 - /* * in kernel 6.x version, add the new iter type ITER_UBUF, and we need add code * for the corresponding scenarios. diff --git a/hack/gen_bpf_specs.go b/hack/gen_bpf_specs.go index ff7a84040..b0af05186 100644 --- a/hack/gen_bpf_specs.go +++ b/hack/gen_bpf_specs.go @@ -167,7 +167,9 @@ func main() { importPath := filepath.ToSlash(filepath.Join(modulePrefix, "bpf", "kmesh", "bpf2go", real)) pi := pkgInfo{Alias: alias, ImportPath: importPath, OutputDir: real, Entries: list} pkgsDefault = append(pkgsDefault, pi) - pkgsEnhanced = append(pkgsEnhanced, pi) + if !strings.HasPrefix(real, "dualengine") { + pkgsEnhanced = append(pkgsEnhanced, pi) + } } } } diff --git a/hack/utils.sh b/hack/utils.sh index 2f7eaad63..1201ede71 100644 --- a/hack/utils.sh +++ b/hack/utils.sh @@ -30,7 +30,7 @@ function get_arch() { function build_kmesh() { local container_id=$1 docker exec $container_id git config --global --add safe.directory /kmesh - docker exec -e VERSION=$VERSION $container_id sh /kmesh/build.sh + docker exec -e VERSION=$VERSION $container_id sh /kmesh/build.sh -d docker exec -e VERSION=$VERSION $container_id sh /kmesh/build.sh -i docker exec $container_id sh -c "$(declare -f copy_to_host); copy_to_host" } diff --git a/kernel/ko_src/Makefile b/kernel/ko_src/Makefile index 580555f43..6281f68e5 100644 --- a/kernel/ko_src/Makefile +++ b/kernel/ko_src/Makefile @@ -2,8 +2,10 @@ CURRENT_PATH := $(shell pwd) DIRS := $(shell find $(CURRENT_PATH) -maxdepth 1 -type d) BASE_DIRS := $(basename $(patsubst $(CURRENT_PATH)/%, %, $(DIRS))) BASE_DIRS := $(filter-out $(CURRENT_PATH), $(BASE_DIRS)) +CONFIG_FILE := ../../config/kmesh_marcos_def.h +ENHANCED_KERNEL := $(shell grep -q "#define ENHANCED_KERNEL 1" $(CONFIG_FILE) && echo yes || echo no) -ifeq ($(ENHANCED_KERNEL), enhanced) +ifeq ($(ENHANCED_KERNEL), yes) all: @for dir in ${BASE_DIRS}; do \ make -C $(CURRENT_PATH)/$$dir; \ diff --git a/kernel/ko_src/kmesh/defer_connect.c b/kernel/ko_src/kmesh/defer_connect.c index 412419b7d..4e1b9bc7c 100644 --- a/kernel/ko_src/kmesh/defer_connect.c +++ b/kernel/ko_src/kmesh/defer_connect.c @@ -79,31 +79,11 @@ static int defer_connect(struct sock *sk, struct msghdr *msg, size_t size) tmpMem.size = kbuf_size; tmpMem.ptr = kbuf; -#if OE_23_03 - tcp_call_bpf_3arg( - sk, - BPF_SOCK_OPS_TCP_DEFER_CONNECT_CB, - ((u64)(&tmpMem) & U32_MAX), - (((u64)(&tmpMem) >> 32) & U32_MAX), - kbuf_size); - daddr = sk->sk_daddr; - dport = sk->sk_dport; - - // daddr == 0 && dport == 0 are special flags meaning the circuit breaker is open - // Should reject connection here - if (daddr == 0 && dport == 0) { - tcp_set_state(sk, TCP_CLOSE); - sk->sk_route_caps = 0; - inet_sk(sk)->inet_dport = 0; - err = -1; - goto out; - } -#else uaddr.sin_family = AF_INET; uaddr.sin_addr.s_addr = daddr; uaddr.sin_port = dport; err = BPF_CGROUP_RUN_PROG_INET4_CONNECT_KMESH(sk, (struct sockaddr *)&uaddr, &tmpMem); -#endif + connect: err = sk->sk_prot->connect(sk, (struct sockaddr *)&uaddr, sizeof(struct sockaddr_in)); if (unlikely(err)) { diff --git a/oncn-mda/include/mesh_accelerate.h b/oncn-mda/include/mesh_accelerate.h index 39aeca01a..2d9710c5f 100644 --- a/oncn-mda/include/mesh_accelerate.h +++ b/oncn-mda/include/mesh_accelerate.h @@ -20,15 +20,9 @@ enum bpf_loglevel { BPF_LOG_DEBUG, }; -#define BPF_LOGLEVEL BPF_LOG_ERROR - -#if OE_23_03 -#define GET_SKOPS_REMOTE_PORT(sk_ops) (__u16)((sk_ops)->remote_port) -#else +#define BPF_LOGLEVEL BPF_LOG_ERROR #define GET_SKOPS_REMOTE_PORT(sk_ops) (__u16)((sk_ops)->remote_port >> 16) -#endif - -#define GET_SKOPS_LOCAL_PORT(sk_ops) (__u16)((sk_ops)->local_port) +#define GET_SKOPS_LOCAL_PORT(sk_ops) (__u16)((sk_ops)->local_port) #ifndef bpf_printk #define bpf_printk(fmt, ...) \ diff --git a/pkg/bpf/restart/new_version_mapspec_loader_enhanced.go b/pkg/bpf/restart/new_version_mapspec_loader_enhanced.go index c0c1a4fd5..32937e07a 100644 --- a/pkg/bpf/restart/new_version_mapspec_loader_enhanced.go +++ b/pkg/bpf/restart/new_version_mapspec_loader_enhanced.go @@ -26,7 +26,6 @@ import ( "github.com/cilium/ebpf" - dualengine "kmesh.net/kmesh/bpf/kmesh/bpf2go/dualengine" general "kmesh.net/kmesh/bpf/kmesh/bpf2go/general" kernelnative_enhanced "kmesh.net/kmesh/bpf/kmesh/bpf2go/kernelnative/enhanced" "kmesh.net/kmesh/daemon/options" diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 17a0d53e8..4eccaf787 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -168,14 +168,13 @@ func (c *Controller) Start(stopCh <-chan struct{}) error { if err := c.client.WorkloadController.Run(ctx, stopCh); err != nil { return fmt.Errorf("failed to start workload controller: %+v", err) } + if err := c.setupDNSProxy(); err != nil { + return fmt.Errorf("failed to start dns proxy: %+v", err) + } } else { c.client.AdsController.StartDnsController(stopCh) } - if err := c.setupDNSProxy(); err != nil { - return fmt.Errorf("failed to start dns proxy: %+v", err) - } - return c.client.Run(stopCh) } From 4d7ddf010ad88dcb43da668ba6dcbe2f2a80d954 Mon Sep 17 00:00:00 2001 From: lec-bit Date: Wed, 26 Nov 2025 11:43:22 +0800 Subject: [PATCH 2/2] opt Signed-off-by: lec-bit --- bpf/include/common.h | 13 ++++++++- bpf/kmesh/ads/cgroup_sock.c | 9 +++--- bpf/kmesh/ads/include/kmesh_common.h | 5 ---- build.sh | 1 + config/kmesh_marcos_def.h | 7 ++++- kernel/ko_src/kmesh/Makefile | 3 +- kernel/ko_src/kmesh/defer_connect.c | 11 +++++-- kmesh_compile_env_pre.sh | 43 +++++++++++++++++++++++++--- kmesh_macros_env.sh | 29 ++----------------- kmesh_macros_env_kernel.sh | 31 +++++++++++--------- 10 files changed, 92 insertions(+), 60 deletions(-) diff --git a/bpf/include/common.h b/bpf/include/common.h index b3691ecf9..ca8cb5f8f 100644 --- a/bpf/include/common.h +++ b/bpf/include/common.h @@ -5,6 +5,7 @@ #define _COMMON_H_ #include "../../config/kmesh_marcos_def.h" +#include #include #include #include @@ -17,7 +18,17 @@ #include "errno.h" #if ENHANCED_KERNEL -#include +#if KERNEL_KFUNC +#include "bpf_kfunc.h" +#else +struct bpf_mem_ptr { + void *ptr; + __u32 size; +}; +#include "bpf_helper_defs_ext.h" +#define bpf_km_setsockopt bpf_setsockopt +#define bpf_km_getsockopt bpf_getsockopt +#endif #endif #define bpf_unused __attribute__((__unused__)) diff --git a/bpf/kmesh/ads/cgroup_sock.c b/bpf/kmesh/ads/cgroup_sock.c index ca125cda8..38ab19479 100644 --- a/bpf/kmesh/ads/cgroup_sock.c +++ b/bpf/kmesh/ads/cgroup_sock.c @@ -14,11 +14,11 @@ #if ENHANCED_KERNEL #include "route_config.h" +static const char kmesh_module_ulp_name[] = KMESH_MODULE_ULP_NAME; #endif #if KMESH_ENABLE_IPV4 #if KMESH_ENABLE_HTTP -static const char kmesh_module_name[] = "kmesh_defer"; static char kmesh_module_name_get[KMESH_MODULE_NAME_LEN] = ""; static inline int sock4_traffic_control(struct bpf_sock_addr *ctx) { @@ -42,9 +42,10 @@ static inline int sock4_traffic_control(struct bpf_sock_addr *ctx) BPF_LOG(DEBUG, KMESH, "bpf find listener addr=[%s:%u]\n", ip2str(&ip, 1), bpf_ntohs(ctx->user_port)); #if ENHANCED_KERNEL - ret = bpf_getsockopt(ctx, IPPROTO_TCP, TCP_ULP, (void *)kmesh_module_name_get, KMESH_MODULE_NAME_LEN); - if (CHECK_MODULE_NAME_NULL(ret) || bpf__strncmp(kmesh_module_name_get, KMESH_MODULE_NAME_LEN, kmesh_module_name)) { - ret = bpf_setsockopt(ctx, IPPROTO_TCP, TCP_ULP, (void *)kmesh_module_name, sizeof(kmesh_module_name)); + ret = bpf_km_getsockopt(ctx, IPPROTO_TCP, TCP_ULP, kmesh_module_ulp_name_get, KMESH_MODULE_NAME_LEN); + if (CHECK_MODULE_NAME_NULL(ret) + || bpf__strncmp(kmesh_module_ulp_name_get, KMESH_MODULE_NAME_LEN, kmesh_module_ulp_name)) { + ret = bpf_km_setsockopt(ctx, IPPROTO_TCP, TCP_ULP, kmesh_module_ulp_name, sizeof(kmesh_module_ulp_name)); if (ret) BPF_LOG(ERR, KMESH, "bpf set sockopt failed! ret %d\n", ret); return 0; diff --git a/bpf/kmesh/ads/include/kmesh_common.h b/bpf/kmesh/ads/include/kmesh_common.h index d59f02d04..2d525f8cc 100644 --- a/bpf/kmesh/ads/include/kmesh_common.h +++ b/bpf/kmesh/ads/include/kmesh_common.h @@ -31,11 +31,6 @@ val; \ }) -struct bpf_mem_ptr { - void *ptr; - __u32 size; -}; - static inline int bpf__strncmp(const char *dst, int n, const char *src) { if (dst == NULL || src == NULL) diff --git a/build.sh b/build.sh index 93bfddbdd..172447bd4 100755 --- a/build.sh +++ b/build.sh @@ -43,6 +43,7 @@ if [ "$1" == "-h" -o "$1" == "--help" ]; then fi if [ -z "$1" -o "$1" == "-b" -o "$1" == "--build" ]; then + bash kmesh_macros_env_kernel.sh prepare make exit diff --git a/config/kmesh_marcos_def.h b/config/kmesh_marcos_def.h index 51cd0b274..085b9d879 100644 --- a/config/kmesh_marcos_def.h +++ b/config/kmesh_marcos_def.h @@ -28,7 +28,7 @@ * in kernel 6.x version, add the new iter type ITER_UBUF, and we need add code * for the corresponding scenarios. */ -#define ITER_TYPE_IS_UBUF 0 +#define KERNEL_VERISON6 1 /* * Kmesh’s Layer 7 acceleration proxy capability relies on kernel enhancements. @@ -46,3 +46,8 @@ * is enabled accordingly. * */ #define LIBBPF_HIGHER_0_6_0_VERSION 0 + +/* + * Determine whether the current kernel version supports the use of kfunc. + */ +#define KERNEL_KFUNC 0 diff --git a/kernel/ko_src/kmesh/Makefile b/kernel/ko_src/kmesh/Makefile index 264a37b80..d25566f56 100644 --- a/kernel/ko_src/kmesh/Makefile +++ b/kernel/ko_src/kmesh/Makefile @@ -13,12 +13,13 @@ kmesh-objs = kmesh_main.o defer_connect.o \ kmesh_parse_http_1_1.o KERNELDIR ?= /lib/modules/$(shell uname -r)/build +VMLINUX_PATH := /sys/kernel/btf/vmlinux PWD := $(shell pwd) ccflags-y += -Wno-discarded-qualifiers all: - $(MAKE) -C $(KERNELDIR) M=$(PWD) + $(MAKE) -C $(KERNELDIR) M=$(PWD) KBUILD_VMLINUX_LIBS=$(VMLINUX_PATH) modules install: install -dp -m 0500 /lib/modules/kmesh diff --git a/kernel/ko_src/kmesh/defer_connect.c b/kernel/ko_src/kmesh/defer_connect.c index 4e1b9bc7c..a9e4b2539 100644 --- a/kernel/ko_src/kmesh/defer_connect.c +++ b/kernel/ko_src/kmesh/defer_connect.c @@ -20,8 +20,9 @@ #include "defer_connect.h" +#define KMESH_MODULE_ULP_NAME "kmesh_defer" + static struct proto *kmesh_defer_proto = NULL; -#define KMESH_DELAY_ERROR -1000 #define BPF_CGROUP_RUN_PROG_INET4_CONNECT_KMESH(sk, uaddr, t_ctx) \ ({ \ @@ -54,13 +55,17 @@ static int defer_connect(struct sock *sk, struct msghdr *msg, size_t size) ubase = iov->iov_base; kbuf_size = iov->iov_len; } else if (iter_is_iovec(&msg->msg_iter)) { - iov = msg->msg_iter.iov; +#if KERNEL_VERISON6 + iov = msg->msg_iter.__iov; ubase = iov->iov_base; kbuf_size = iov->iov_len; -#if ITER_TYPE_IS_UBUF } else if (iter_is_ubuf(&msg->msg_iter)) { ubase = msg->msg_iter.ubuf; kbuf_size = msg->msg_iter.count; +#else + iov = msg->msg_iter.iov; + ubase = iov->iov_base; + kbuf_size = iov->iov_len; #endif } else goto connect; diff --git a/kmesh_compile_env_pre.sh b/kmesh_compile_env_pre.sh index fc28bc96e..518163cc4 100644 --- a/kmesh_compile_env_pre.sh +++ b/kmesh_compile_env_pre.sh @@ -15,7 +15,7 @@ function dependency_pkg_install() { if command -v apt >/dev/null; then echo "Checking for required packages on a Debian-based system..." - packages=(git make clang libbpf-dev llvm linux-tools-generic protobuf-compiler libprotobuf-dev libprotobuf-c-dev protobuf-c-compiler cmake pkg-config gcc-multilib) + packages=(git make clang libbpf-dev llvm linux-tools-generic protobuf-compiler libprotobuf-dev libprotobuf-c-dev protobuf-c-compiler cmake pkg-config gcc-multilib pahole linux-headers) update_needed=false for pkg in "${packages[@]}"; do @@ -47,7 +47,7 @@ function dependency_pkg_install() { echo "Checking for required packages on a Red Hat-based system..." # List of required packages - packages=(git make clang llvm libboundscheck protobuf protobuf-c protobuf-c-devel bpftool libbpf libbpf-devel cmake pkg-config glibc-devel libstdc++-devel) + packages=(git make clang llvm libboundscheck protobuf protobuf-c protobuf-c-devel bpftool libbpf libbpf-devel cmake pkg-config glibc-devel libstdc++-devel dwarves) # Install each missing package for pkg in "${packages[@]}"; do @@ -104,6 +104,32 @@ function kmesh_set_env() { export EXTRA_CFLAGS="-O0 -g" } +function set_config() { + sed -i -r -e "s/($1)([ \t]*)([0-9]+)/\1\2$2/" config/kmesh_marcos_def.h +} + +detect_config() { + local kernel_version=$(uname -r) + + if [ -f "/proc/config.gz" ]; then + zcat /proc/config.gz 2>/dev/null + return $? + fi + + if [ -f "/boot/config-$kernel_version" ]; then + cat "/boot/config-$kernel_version" 2>/dev/null + return $? + fi +} + +CONFIG_CONTENT=$(detect_config) + +check_config() { + local config_name=$1 + value=$(echo "$CONFIG_CONTENT" | grep -w "$config_name" | cut -d= -f2) + echo "$value" +} + function set_enhanced_kernel_env() { # we use /usr/include/linux/bpf.h to determine the runtime environment’s # support for kmesh. Considering the case of online image compilation, a @@ -118,8 +144,17 @@ function set_enhanced_kernel_env() { export KERNEL_HEADER_LINUX_BPF=/usr/include/linux/bpf.h fi - if grep -q "FN(parse_header_msg)" $KERNEL_HEADER_LINUX_BPF; then - export ENHANCED_KERNEL="enhanced" + KERNEL_MAJOR=$(uname -r | awk -F '.' '{print $1}') + + zcat /proc/config.gz | grep BTF + cat "/boot/config-$(uname -r)" | grep BTF + check_config "CONFIG_DEBUG_INFO_BTF_MODULES" + check_config "CONFIG_DEBUG_INFO_BTF" + if grep -q "FN(parse_header_msg)" $KERNEL_HEADER_LINUX_BPF || + [ "$(check_config "CONFIG_DEBUG_INFO_BTF_MODULES")" == "y" ] && + [ "$(check_config "CONFIG_DEBUG_INFO_BTF")" == "y" ] && + [ "$KERNEL_MAJOR" -ge 6 ]; then + export ENHANCED_KERNEL="normal" else export ENHANCED_KERNEL="normal" fi diff --git a/kmesh_macros_env.sh b/kmesh_macros_env.sh index 9c5cd0608..592b09601 100644 --- a/kmesh_macros_env.sh +++ b/kmesh_macros_env.sh @@ -1,11 +1,7 @@ #!/bin/bash -VERSION=$(uname -r | cut -d '.' -f 1) -KERNEL_VERSION=$(uname -r | cut -d '-' -f 1) - -function set_config() { - sed -i -r -e "s/($1)([ \t]*)([0-9]+)/\1\2$2/" config/kmesh_marcos_def.h -} +source ./kmesh_compile_env_pre.sh +KERNEL_VERSION=$(uname -r | cut -d '.' -f 1) # MDA_LOOPBACK_ADDR if grep -q "FN(get_netns_cookie)" $KERNEL_HEADER_LINUX_BPF; then @@ -28,27 +24,6 @@ else set_config MDA_GID_UID_FILTER 0 fi -# OE_23_03 -if (uname -r | grep oe2303); then - set_config OE_23_03 1 -else - set_config OE_23_03 0 -fi - -# ITER_TYPE_IS_UBUF -if [ "$VERSION" -ge 6 ]; then - set_config ITER_TYPE_IS_UBUF 1 -else - set_config ITER_TYPE_IS_UBUF 0 -fi - -# ENHANCED_KERNEL -if grep -q "FN(parse_header_msg)" $KERNEL_HEADER_LINUX_BPF; then - set_config ENHANCED_KERNEL 1 -else - set_config ENHANCED_KERNEL 0 -fi - # Determine libbpf version if command -v apt >/dev/null; then LIBBPF_VERSION=$(ls /usr/lib/x86_64-linux-gnu | grep -P 'libbpf\.so\.\d+\.\d+\.\d+$' | sed -n -e 's/^.*libbpf.so.\(.*\)$/\1/p') diff --git a/kmesh_macros_env_kernel.sh b/kmesh_macros_env_kernel.sh index 3bc70ce62..06a71235b 100755 --- a/kmesh_macros_env_kernel.sh +++ b/kmesh_macros_env_kernel.sh @@ -1,13 +1,9 @@ #!/bin/bash -VERSION=$(uname -r | cut -d '.' -f 1) -KERNEL_VERSION=$(uname -r | cut -d '-' -f 1) +source ./kmesh_compile_env_pre.sh +KERNEL_VERSION=$(uname -r | cut -d '.' -f 1) KERNEL_HEADER_LINUX_BPF=/usr/include/linux/bpf.h -function set_config() { - sed -i -r -e "s/($1)([ \t]*)([0-9]+)/\1\2$2/" config/kmesh_marcos_def.h -} - # MDA_LOOPBACK_ADDR if grep -q "FN(get_netns_cookie)" $KERNEL_HEADER_LINUX_BPF; then set_config MDA_LOOPBACK_ADDR 1 @@ -29,24 +25,31 @@ else set_config MDA_GID_UID_FILTER 0 fi -# ITER_TYPE_IS_UBUF -if [ "$VERSION" -ge 6 ]; then - set_config ITER_TYPE_IS_UBUF 1 +# KERNEL_VERISON6 +if [ "$KERNEL_VERSION" -ge 6 ]; then + set_config KERNEL_VERISON6 1 else - set_config ITER_TYPE_IS_UBUF 0 + set_config KERNEL_VERISON6 0 fi # ENHANCED_KERNEL if grep -q "FN(parse_header_msg)" $KERNEL_HEADER_LINUX_BPF; then - set_config ENHANCED_KERNEL 1 + set_config ENHANCED_KERNEL 0 else set_config ENHANCED_KERNEL 0 fi +zcat /proc/config.gz | grep BTF +cat "/boot/config-$(uname -r)" | grep BTF # KERNEL_KFUNC -if [ "$VERSION" -ge 6 ]; then - set_config ENHANCED_KERNEL 1 - set_config KERNEL_KFUNC 1 +if [ "$(check_config "CONFIG_DEBUG_INFO_BTF_MODULES")" == "y" ] && + [ "$(check_config "CONFIG_DEBUG_INFO_BTF")" == "y" ] && + [ "$KERNEL_VERSION" -ge 6 ]; then + set_config ENHANCED_KERNEL 0 + set_config KERNEL_KFUNC 0 + cp /sys/kernel/btf/vmlinux /lib/modules/$(uname -r)/build else set_config KERNEL_KFUNC 0 fi + +cat config/kmesh_marcos_def.h