diff --git a/bpf/include/bpf_kfunc.h b/bpf/include/bpf_kfunc.h new file mode 100644 index 000000000..0626428df --- /dev/null +++ b/bpf/include/bpf_kfunc.h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ +/* Copyright Authors of Kmesh */ + +#include "../../config/kmesh_marcos_def.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "map_config.h" + +#include "errno.h" + +struct bpf_mem_ptr { + void *ptr; + __u32 size; +}; + +#define KMESH_MODULE_ULP_NAME "kmesh_defer" + +extern int bpf_parse_header_msg_func(void *src, int src__sz) __ksym; +extern int bpf_km_header_strnstr_func(void *ctx, int ctx__sz, const char *key, int key__sz, const char *subptr) __ksym; +extern int bpf_km_header_strncmp_func(const char *key, int key__sz, const char *target, int target__sz, int opt) __ksym; +extern int bpf_setsockopt_func(void *bpf_mem, int bpf_mem__sz, int optname, const char *optval, int optval__sz) __ksym; +extern int bpf_getsockopt_func(void *bpf_mem, int bpf_mem__sz, int optname, char *optval, int optval__sz) __ksym; + +#define bpf_km_header_strncmp bpf_km_header_strncmp_func + +static int bpf_km_header_strnstr(void *ctx, const char *key, int key__sz, const char *subptr, int subptr__sz) +{ + struct bpf_mem_ptr msg_tmp = {.ptr = ctx, .size = sizeof(struct bpf_sock_addr)}; + return bpf_km_header_strnstr_func(&msg_tmp, sizeof(struct bpf_mem_ptr), key, key__sz, subptr); +} + +static int bpf_parse_header_msg(struct bpf_sock_addr *ctx) +{ + struct bpf_mem_ptr msg_tmp = {.ptr = ctx, .size = sizeof(struct bpf_sock_addr)}; + return bpf_parse_header_msg_func(&msg_tmp, sizeof(struct bpf_mem_ptr)); +} + +// Due to the limitation of bpf verifier, optval and optval__sz are required to correspond. +// The strnlen function cannot be used here, so the string is redefined. +static int bpf_km_setsockopt(struct bpf_sock_addr *ctx, int level, int optname, const char *optval, int optval__sz) +{ + const char kmesh_module_ulp_name[] = KMESH_MODULE_ULP_NAME; + if (level != IPPROTO_TCP || optval__sz != sizeof(kmesh_module_ulp_name)) + return -1; + + struct bpf_mem_ptr msg_tmp = {.ptr = ctx, .size = sizeof(struct bpf_sock_addr)}; + return bpf_setsockopt_func( + &msg_tmp, sizeof(struct bpf_mem_ptr), optname, (void *)kmesh_module_ulp_name, sizeof(kmesh_module_ulp_name)); +} + +static int bpf_km_getsockopt(struct bpf_sock_addr *ctx, int level, int optname, char *optval, int optval__sz) +{ + if (level != IPPROTO_TCP) { + return -1; + } + struct bpf_mem_ptr msg_tmp = {.ptr = ctx, .size = sizeof(struct bpf_sock_addr)}; + return bpf_getsockopt_func(&msg_tmp, sizeof(struct bpf_mem_ptr), optname, (void *)optval, optval__sz); +} diff --git a/bpf/include/common.h b/bpf/include/common.h index 95249f8b6..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__)) @@ -113,14 +124,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/cgroup_sock.c b/bpf/kmesh/ads/cgroup_sock.c index ca125cda8..d041d6e65 100644 --- a/bpf/kmesh/ads/cgroup_sock.c +++ b/bpf/kmesh/ads/cgroup_sock.c @@ -14,16 +14,15 @@ #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) { int ret; - + char kmesh_module_ulp_name_get[KMESH_MODULE_NAME_LEN] = ""; Listener__Listener *listener = NULL; if (ctx->protocol != IPPROTO_TCP) @@ -42,9 +41,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/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/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/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsock_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsock_bpfeb.go new file mode 100644 index 000000000..d00cf2d3c --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsock_bpfeb.go @@ -0,0 +1,242 @@ +// Code generated by bpf2go; DO NOT EDIT. +//go:build mips || mips64 || ppc64 || s390x + +package enhanced + +import ( + "bytes" + _ "embed" + "fmt" + "io" + + "github.com/cilium/ebpf" +) + +type KmeshCgroupSockBuf struct{ Data [40]int8 } + +type KmeshCgroupSockClusterSockData struct{ ClusterId uint32 } + +type KmeshCgroupSockManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockRatelimitKey struct { + Key struct { + SkSkb struct { + Netns uint64 + Ipv4 uint32 + Port uint32 + Family uint32 + _ [4]byte + } + } +} + +type KmeshCgroupSockRatelimitValue struct { + LastTopup uint64 + Tokens uint64 +} + +type KmeshCgroupSockSockStorageData struct { + ConnectNs uint64 + LastReportNs uint64 + Direction uint8 + ConnectSuccess uint8 + ViaWaypoint bool + HasEncoded bool + HasSetIp bool + _ [3]byte + SkTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte + } + _ [4]byte +} + +// LoadKmeshCgroupSock returns the embedded CollectionSpec for KmeshCgroupSock. +func LoadKmeshCgroupSock() (*ebpf.CollectionSpec, error) { + reader := bytes.NewReader(_KmeshCgroupSockBytes) + spec, err := ebpf.LoadCollectionSpecFromReader(reader) + if err != nil { + return nil, fmt.Errorf("can't load KmeshCgroupSock: %w", err) + } + + return spec, err +} + +// LoadKmeshCgroupSockObjects loads KmeshCgroupSock and converts it into a struct. +// +// The following types are suitable as obj argument: +// +// *KmeshCgroupSockObjects +// *KmeshCgroupSockPrograms +// *KmeshCgroupSockMaps +// +// See ebpf.CollectionSpec.LoadAndAssign documentation for details. +func LoadKmeshCgroupSockObjects(obj interface{}, opts *ebpf.CollectionOptions) error { + spec, err := LoadKmeshCgroupSock() + if err != nil { + return err + } + + return spec.LoadAndAssign(obj, opts) +} + +// KmeshCgroupSockSpecs contains maps and programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockSpecs struct { + KmeshCgroupSockProgramSpecs + KmeshCgroupSockMapSpecs + KmeshCgroupSockVariableSpecs +} + +// KmeshCgroupSockProgramSpecs contains programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockProgramSpecs struct { + CgroupConnect4Prog *ebpf.ProgramSpec `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` + FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` + FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` +} + +// KmeshCgroupSockMapSpecs contains maps before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockMapSpecs struct { + KmCgrptailcall *ebpf.MapSpec `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.MapSpec `ebpf:"km_cluster"` + KmClusterEps *ebpf.MapSpec `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmEpsData *ebpf.MapSpec `ebpf:"km_eps_data"` + KmListener *ebpf.MapSpec `ebpf:"km_listener"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` +} + +// KmeshCgroupSockVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockObjects contains all objects after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockObjects struct { + KmeshCgroupSockPrograms + KmeshCgroupSockMaps + KmeshCgroupSockVariables +} + +func (o *KmeshCgroupSockObjects) Close() error { + return _KmeshCgroupSockClose( + &o.KmeshCgroupSockPrograms, + &o.KmeshCgroupSockMaps, + ) +} + +// KmeshCgroupSockMaps contains all maps after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockMaps struct { + KmCgrptailcall *ebpf.Map `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.Map `ebpf:"km_cluster"` + KmClusterEps *ebpf.Map `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmEpsData *ebpf.Map `ebpf:"km_eps_data"` + KmListener *ebpf.Map `ebpf:"km_listener"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` +} + +func (m *KmeshCgroupSockMaps) Close() error { + return _KmeshCgroupSockClose( + m.KmCgrptailcall, + m.KmCluster, + m.KmClusterEps, + m.KmClusterSock, + m.KmClusterstats, + m.KmEpsData, + m.KmListener, + m.KmLogEvent, + m.KmMaglevOuter, + m.KmManage, + m.KmRatelimit, + m.KmSockstorage, + m.KmTailcallCtx, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + ) +} + +// KmeshCgroupSockVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockPrograms contains all programs after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockPrograms struct { + CgroupConnect4Prog *ebpf.Program `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.Program `ebpf:"cluster_manager"` + FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` + FilterManager *ebpf.Program `ebpf:"filter_manager"` +} + +func (p *KmeshCgroupSockPrograms) Close() error { + return _KmeshCgroupSockClose( + p.CgroupConnect4Prog, + p.ClusterManager, + p.FilterChainManager, + p.FilterManager, + ) +} + +func _KmeshCgroupSockClose(closers ...io.Closer) error { + for _, closer := range closers { + if err := closer.Close(); err != nil { + return err + } + } + return nil +} + +// Do not access this directly. +// +//go:embed kmeshcgroupsock_bpfeb.o +var _KmeshCgroupSockBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsock_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsock_bpfel.go new file mode 100644 index 000000000..5e0536451 --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsock_bpfel.go @@ -0,0 +1,242 @@ +// Code generated by bpf2go; DO NOT EDIT. +//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64 + +package enhanced + +import ( + "bytes" + _ "embed" + "fmt" + "io" + + "github.com/cilium/ebpf" +) + +type KmeshCgroupSockBuf struct{ Data [40]int8 } + +type KmeshCgroupSockClusterSockData struct{ ClusterId uint32 } + +type KmeshCgroupSockManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockRatelimitKey struct { + Key struct { + SkSkb struct { + Netns uint64 + Ipv4 uint32 + Port uint32 + Family uint32 + _ [4]byte + } + } +} + +type KmeshCgroupSockRatelimitValue struct { + LastTopup uint64 + Tokens uint64 +} + +type KmeshCgroupSockSockStorageData struct { + ConnectNs uint64 + LastReportNs uint64 + Direction uint8 + ConnectSuccess uint8 + ViaWaypoint bool + HasEncoded bool + HasSetIp bool + _ [3]byte + SkTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte + } + _ [4]byte +} + +// LoadKmeshCgroupSock returns the embedded CollectionSpec for KmeshCgroupSock. +func LoadKmeshCgroupSock() (*ebpf.CollectionSpec, error) { + reader := bytes.NewReader(_KmeshCgroupSockBytes) + spec, err := ebpf.LoadCollectionSpecFromReader(reader) + if err != nil { + return nil, fmt.Errorf("can't load KmeshCgroupSock: %w", err) + } + + return spec, err +} + +// LoadKmeshCgroupSockObjects loads KmeshCgroupSock and converts it into a struct. +// +// The following types are suitable as obj argument: +// +// *KmeshCgroupSockObjects +// *KmeshCgroupSockPrograms +// *KmeshCgroupSockMaps +// +// See ebpf.CollectionSpec.LoadAndAssign documentation for details. +func LoadKmeshCgroupSockObjects(obj interface{}, opts *ebpf.CollectionOptions) error { + spec, err := LoadKmeshCgroupSock() + if err != nil { + return err + } + + return spec.LoadAndAssign(obj, opts) +} + +// KmeshCgroupSockSpecs contains maps and programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockSpecs struct { + KmeshCgroupSockProgramSpecs + KmeshCgroupSockMapSpecs + KmeshCgroupSockVariableSpecs +} + +// KmeshCgroupSockProgramSpecs contains programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockProgramSpecs struct { + CgroupConnect4Prog *ebpf.ProgramSpec `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` + FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` + FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` +} + +// KmeshCgroupSockMapSpecs contains maps before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockMapSpecs struct { + KmCgrptailcall *ebpf.MapSpec `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.MapSpec `ebpf:"km_cluster"` + KmClusterEps *ebpf.MapSpec `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmEpsData *ebpf.MapSpec `ebpf:"km_eps_data"` + KmListener *ebpf.MapSpec `ebpf:"km_listener"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` +} + +// KmeshCgroupSockVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockObjects contains all objects after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockObjects struct { + KmeshCgroupSockPrograms + KmeshCgroupSockMaps + KmeshCgroupSockVariables +} + +func (o *KmeshCgroupSockObjects) Close() error { + return _KmeshCgroupSockClose( + &o.KmeshCgroupSockPrograms, + &o.KmeshCgroupSockMaps, + ) +} + +// KmeshCgroupSockMaps contains all maps after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockMaps struct { + KmCgrptailcall *ebpf.Map `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.Map `ebpf:"km_cluster"` + KmClusterEps *ebpf.Map `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmEpsData *ebpf.Map `ebpf:"km_eps_data"` + KmListener *ebpf.Map `ebpf:"km_listener"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` +} + +func (m *KmeshCgroupSockMaps) Close() error { + return _KmeshCgroupSockClose( + m.KmCgrptailcall, + m.KmCluster, + m.KmClusterEps, + m.KmClusterSock, + m.KmClusterstats, + m.KmEpsData, + m.KmListener, + m.KmLogEvent, + m.KmMaglevOuter, + m.KmManage, + m.KmRatelimit, + m.KmSockstorage, + m.KmTailcallCtx, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + ) +} + +// KmeshCgroupSockVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockPrograms contains all programs after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockPrograms struct { + CgroupConnect4Prog *ebpf.Program `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.Program `ebpf:"cluster_manager"` + FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` + FilterManager *ebpf.Program `ebpf:"filter_manager"` +} + +func (p *KmeshCgroupSockPrograms) Close() error { + return _KmeshCgroupSockClose( + p.CgroupConnect4Prog, + p.ClusterManager, + p.FilterChainManager, + p.FilterManager, + ) +} + +func _KmeshCgroupSockClose(closers ...io.Closer) error { + for _, closer := range closers { + if err := closer.Close(); err != nil { + return err + } + } + return nil +} + +// Do not access this directly. +// +//go:embed kmeshcgroupsock_bpfel.o +var _KmeshCgroupSockBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsockcompat_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsockcompat_bpfeb.go new file mode 100644 index 000000000..3a0482e87 --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsockcompat_bpfeb.go @@ -0,0 +1,242 @@ +// Code generated by bpf2go; DO NOT EDIT. +//go:build mips || mips64 || ppc64 || s390x + +package enhanced + +import ( + "bytes" + _ "embed" + "fmt" + "io" + + "github.com/cilium/ebpf" +) + +type KmeshCgroupSockCompatBuf struct{ Data [40]int8 } + +type KmeshCgroupSockCompatClusterSockData struct{ ClusterId uint32 } + +type KmeshCgroupSockCompatManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockCompatRatelimitKey struct { + Key struct { + SkSkb struct { + Netns uint64 + Ipv4 uint32 + Port uint32 + Family uint32 + _ [4]byte + } + } +} + +type KmeshCgroupSockCompatRatelimitValue struct { + LastTopup uint64 + Tokens uint64 +} + +type KmeshCgroupSockCompatSockStorageData struct { + ConnectNs uint64 + LastReportNs uint64 + Direction uint8 + ConnectSuccess uint8 + ViaWaypoint bool + HasEncoded bool + HasSetIp bool + _ [3]byte + SkTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte + } + _ [4]byte +} + +// LoadKmeshCgroupSockCompat returns the embedded CollectionSpec for KmeshCgroupSockCompat. +func LoadKmeshCgroupSockCompat() (*ebpf.CollectionSpec, error) { + reader := bytes.NewReader(_KmeshCgroupSockCompatBytes) + spec, err := ebpf.LoadCollectionSpecFromReader(reader) + if err != nil { + return nil, fmt.Errorf("can't load KmeshCgroupSockCompat: %w", err) + } + + return spec, err +} + +// LoadKmeshCgroupSockCompatObjects loads KmeshCgroupSockCompat and converts it into a struct. +// +// The following types are suitable as obj argument: +// +// *KmeshCgroupSockCompatObjects +// *KmeshCgroupSockCompatPrograms +// *KmeshCgroupSockCompatMaps +// +// See ebpf.CollectionSpec.LoadAndAssign documentation for details. +func LoadKmeshCgroupSockCompatObjects(obj interface{}, opts *ebpf.CollectionOptions) error { + spec, err := LoadKmeshCgroupSockCompat() + if err != nil { + return err + } + + return spec.LoadAndAssign(obj, opts) +} + +// KmeshCgroupSockCompatSpecs contains maps and programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatSpecs struct { + KmeshCgroupSockCompatProgramSpecs + KmeshCgroupSockCompatMapSpecs + KmeshCgroupSockCompatVariableSpecs +} + +// KmeshCgroupSockCompatProgramSpecs contains programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatProgramSpecs struct { + CgroupConnect4Prog *ebpf.ProgramSpec `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` + FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` + FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` +} + +// KmeshCgroupSockCompatMapSpecs contains maps before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatMapSpecs struct { + KmCgrptailcall *ebpf.MapSpec `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.MapSpec `ebpf:"km_cluster"` + KmClusterEps *ebpf.MapSpec `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmEpsData *ebpf.MapSpec `ebpf:"km_eps_data"` + KmListener *ebpf.MapSpec `ebpf:"km_listener"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` +} + +// KmeshCgroupSockCompatVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockCompatObjects contains all objects after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatObjects struct { + KmeshCgroupSockCompatPrograms + KmeshCgroupSockCompatMaps + KmeshCgroupSockCompatVariables +} + +func (o *KmeshCgroupSockCompatObjects) Close() error { + return _KmeshCgroupSockCompatClose( + &o.KmeshCgroupSockCompatPrograms, + &o.KmeshCgroupSockCompatMaps, + ) +} + +// KmeshCgroupSockCompatMaps contains all maps after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatMaps struct { + KmCgrptailcall *ebpf.Map `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.Map `ebpf:"km_cluster"` + KmClusterEps *ebpf.Map `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmEpsData *ebpf.Map `ebpf:"km_eps_data"` + KmListener *ebpf.Map `ebpf:"km_listener"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` +} + +func (m *KmeshCgroupSockCompatMaps) Close() error { + return _KmeshCgroupSockCompatClose( + m.KmCgrptailcall, + m.KmCluster, + m.KmClusterEps, + m.KmClusterSock, + m.KmClusterstats, + m.KmEpsData, + m.KmListener, + m.KmLogEvent, + m.KmMaglevOuter, + m.KmManage, + m.KmRatelimit, + m.KmSockstorage, + m.KmTailcallCtx, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + ) +} + +// KmeshCgroupSockCompatVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockCompatPrograms contains all programs after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatPrograms struct { + CgroupConnect4Prog *ebpf.Program `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.Program `ebpf:"cluster_manager"` + FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` + FilterManager *ebpf.Program `ebpf:"filter_manager"` +} + +func (p *KmeshCgroupSockCompatPrograms) Close() error { + return _KmeshCgroupSockCompatClose( + p.CgroupConnect4Prog, + p.ClusterManager, + p.FilterChainManager, + p.FilterManager, + ) +} + +func _KmeshCgroupSockCompatClose(closers ...io.Closer) error { + for _, closer := range closers { + if err := closer.Close(); err != nil { + return err + } + } + return nil +} + +// Do not access this directly. +// +//go:embed kmeshcgroupsockcompat_bpfeb.o +var _KmeshCgroupSockCompatBytes []byte diff --git a/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsockcompat_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsockcompat_bpfel.go new file mode 100644 index 000000000..e25d36238 --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsockcompat_bpfel.go @@ -0,0 +1,242 @@ +// Code generated by bpf2go; DO NOT EDIT. +//go:build 386 || amd64 || arm || arm64 || loong64 || mips64le || mipsle || ppc64le || riscv64 + +package enhanced + +import ( + "bytes" + _ "embed" + "fmt" + "io" + + "github.com/cilium/ebpf" +) + +type KmeshCgroupSockCompatBuf struct{ Data [40]int8 } + +type KmeshCgroupSockCompatClusterSockData struct{ ClusterId uint32 } + +type KmeshCgroupSockCompatManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockCompatRatelimitKey struct { + Key struct { + SkSkb struct { + Netns uint64 + Ipv4 uint32 + Port uint32 + Family uint32 + _ [4]byte + } + } +} + +type KmeshCgroupSockCompatRatelimitValue struct { + LastTopup uint64 + Tokens uint64 +} + +type KmeshCgroupSockCompatSockStorageData struct { + ConnectNs uint64 + LastReportNs uint64 + Direction uint8 + ConnectSuccess uint8 + ViaWaypoint bool + HasEncoded bool + HasSetIp bool + _ [3]byte + SkTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte + } + _ [4]byte +} + +// LoadKmeshCgroupSockCompat returns the embedded CollectionSpec for KmeshCgroupSockCompat. +func LoadKmeshCgroupSockCompat() (*ebpf.CollectionSpec, error) { + reader := bytes.NewReader(_KmeshCgroupSockCompatBytes) + spec, err := ebpf.LoadCollectionSpecFromReader(reader) + if err != nil { + return nil, fmt.Errorf("can't load KmeshCgroupSockCompat: %w", err) + } + + return spec, err +} + +// LoadKmeshCgroupSockCompatObjects loads KmeshCgroupSockCompat and converts it into a struct. +// +// The following types are suitable as obj argument: +// +// *KmeshCgroupSockCompatObjects +// *KmeshCgroupSockCompatPrograms +// *KmeshCgroupSockCompatMaps +// +// See ebpf.CollectionSpec.LoadAndAssign documentation for details. +func LoadKmeshCgroupSockCompatObjects(obj interface{}, opts *ebpf.CollectionOptions) error { + spec, err := LoadKmeshCgroupSockCompat() + if err != nil { + return err + } + + return spec.LoadAndAssign(obj, opts) +} + +// KmeshCgroupSockCompatSpecs contains maps and programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatSpecs struct { + KmeshCgroupSockCompatProgramSpecs + KmeshCgroupSockCompatMapSpecs + KmeshCgroupSockCompatVariableSpecs +} + +// KmeshCgroupSockCompatProgramSpecs contains programs before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatProgramSpecs struct { + CgroupConnect4Prog *ebpf.ProgramSpec `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` + FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` + FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` +} + +// KmeshCgroupSockCompatMapSpecs contains maps before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatMapSpecs struct { + KmCgrptailcall *ebpf.MapSpec `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.MapSpec `ebpf:"km_cluster"` + KmClusterEps *ebpf.MapSpec `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmEpsData *ebpf.MapSpec `ebpf:"km_eps_data"` + KmListener *ebpf.MapSpec `ebpf:"km_listener"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.MapSpec `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.MapSpec `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.MapSpec `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.MapSpec `ebpf:"kmesh_map64"` +} + +// KmeshCgroupSockCompatVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshCgroupSockCompatVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockCompatObjects contains all objects after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatObjects struct { + KmeshCgroupSockCompatPrograms + KmeshCgroupSockCompatMaps + KmeshCgroupSockCompatVariables +} + +func (o *KmeshCgroupSockCompatObjects) Close() error { + return _KmeshCgroupSockCompatClose( + &o.KmeshCgroupSockCompatPrograms, + &o.KmeshCgroupSockCompatMaps, + ) +} + +// KmeshCgroupSockCompatMaps contains all maps after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatMaps struct { + KmCgrptailcall *ebpf.Map `ebpf:"km_cgrptailcall"` + KmCluster *ebpf.Map `ebpf:"km_cluster"` + KmClusterEps *ebpf.Map `ebpf:"km_cluster_eps"` + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmEpsData *ebpf.Map `ebpf:"km_eps_data"` + KmListener *ebpf.Map `ebpf:"km_listener"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmeshMap1600 *ebpf.Map `ebpf:"kmesh_map1600"` + KmeshMap192 *ebpf.Map `ebpf:"kmesh_map192"` + KmeshMap296 *ebpf.Map `ebpf:"kmesh_map296"` + KmeshMap64 *ebpf.Map `ebpf:"kmesh_map64"` +} + +func (m *KmeshCgroupSockCompatMaps) Close() error { + return _KmeshCgroupSockCompatClose( + m.KmCgrptailcall, + m.KmCluster, + m.KmClusterEps, + m.KmClusterSock, + m.KmClusterstats, + m.KmEpsData, + m.KmListener, + m.KmLogEvent, + m.KmMaglevOuter, + m.KmManage, + m.KmRatelimit, + m.KmSockstorage, + m.KmTailcallCtx, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + ) +} + +// KmeshCgroupSockCompatVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + +// KmeshCgroupSockCompatPrograms contains all programs after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshCgroupSockCompatPrograms struct { + CgroupConnect4Prog *ebpf.Program `ebpf:"cgroup_connect4_prog"` + ClusterManager *ebpf.Program `ebpf:"cluster_manager"` + FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` + FilterManager *ebpf.Program `ebpf:"filter_manager"` +} + +func (p *KmeshCgroupSockCompatPrograms) Close() error { + return _KmeshCgroupSockCompatClose( + p.CgroupConnect4Prog, + p.ClusterManager, + p.FilterChainManager, + p.FilterManager, + ) +} + +func _KmeshCgroupSockCompatClose(closers ...io.Closer) error { + for _, closer := range closers { + if err := closer.Close(); err != nil { + return err + } + } + return nil +} + +// Do not access this directly. +// +//go:embed kmeshcgroupsockcompat_bpfel.o +var _KmeshCgroupSockCompatBytes []byte diff --git a/build.sh b/build.sh index 1d40a7b3e..324183638 100755 --- a/build.sh +++ b/build.sh @@ -48,6 +48,14 @@ 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 + install + 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..230fb59e2 100644 --- a/config/kmesh_marcos_def.h +++ b/config/kmesh_marcos_def.h @@ -24,33 +24,11 @@ */ #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. */ -#define ITER_TYPE_IS_UBUF 0 +#define KERNEL_VERISON6 0 /* * Kmesh’s Layer 7 acceleration proxy capability relies on kernel enhancements. @@ -68,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 \ No newline at end of file diff --git a/hack/gen_bpf_specs.go b/hack/gen_bpf_specs.go index ff7a84040..d9c8f3649 100644 --- a/hack/gen_bpf_specs.go +++ b/hack/gen_bpf_specs.go @@ -167,7 +167,10 @@ 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/Makefile b/kernel/ko_src/kmesh/Makefile index 264a37b80..c61a97906 100644 --- a/kernel/ko_src/kmesh/Makefile +++ b/kernel/ko_src/kmesh/Makefile @@ -10,7 +10,7 @@ obj-m := kmesh.o kmesh-objs = kmesh_main.o defer_connect.o \ kmesh_parse_protocol_data.o \ - kmesh_parse_http_1_1.o + kmesh_parse_http_1_1.o kmesh_func.o KERNELDIR ?= /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) diff --git a/kernel/ko_src/kmesh/defer_connect.c b/kernel/ko_src/kmesh/defer_connect.c index 412419b7d..5873b5d54 100644 --- a/kernel/ko_src/kmesh/defer_connect.c +++ b/kernel/ko_src/kmesh/defer_connect.c @@ -1,7 +1,6 @@ // SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) /* Copyright Authors of Kmesh */ -#include "../../../config/kmesh_marcos_def.h" #include #include #include @@ -20,10 +19,27 @@ #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) \ +#if KERNEL_KFUNC +#define BPF_CGROUP_RUN_PROG_INET4_CONNECT_KMESH(sk, uaddr, uaddrlen, t_ctx) \ + ({ \ + int __ret = -1; \ + if (t_ctx == NULL) { \ + __ret = -EINVAL; \ + } else { \ + __ret = __cgroup_bpf_run_filter_sock_addr(sk, uaddr, uaddrlen, CGROUP_INET4_CONNECT, t_ctx, NULL); \ + } \ + __ret; \ + }) + +#define SET_DEFER_CONNECT_ON(sk) (inet_set_bit(DEFER_CONNECT, sk)) +#define SET_DEFER_CONNECT_OFF(sk) (inet_clear_bit(DEFER_CONNECT, sk)) +#define IS_DEFER_CONNECT(sk) (inet_test_bit(DEFER_CONNECT, sk)) +#else +#define BPF_CGROUP_RUN_PROG_INET4_CONNECT_KMESH(sk, uaddr, uaddrlen, t_ctx) \ ({ \ int __ret = -1; \ if (t_ctx == NULL) { \ @@ -34,6 +50,11 @@ static struct proto *kmesh_defer_proto = NULL; __ret; \ }) +#define SET_DEFER_CONNECT_ON(sk) (inet_sk(sk)->defer_connect = 1) +#define SET_DEFER_CONNECT_OFF(sk) (inet_sk(sk)->defer_connect = 0) +#define IS_DEFER_CONNECT(sk) (inet_sk(sk)->defer_connect == 1) +#endif + static int defer_connect(struct sock *sk, struct msghdr *msg, size_t size) { struct bpf_mem_ptr tmpMem = {0}; @@ -43,6 +64,7 @@ static int defer_connect(struct sock *sk, struct msghdr *msg, size_t size) const struct iovec *iov; struct bpf_sock_addr_kern sock_addr; struct sockaddr_in uaddr; + int uaddrlen = sizeof(struct sockaddr_in); void __user *ubase; int err; u32 dport, daddr; @@ -54,14 +76,19 @@ 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; @@ -79,31 +106,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 + err = BPF_CGROUP_RUN_PROG_INET4_CONNECT_KMESH(sk, (struct sockaddr *)&uaddr, &uaddrlen, &tmpMem); + connect: err = sk->sk_prot->connect(sk, (struct sockaddr *)&uaddr, sizeof(struct sockaddr_in)); if (unlikely(err)) { @@ -113,7 +120,7 @@ static int defer_connect(struct sock *sk, struct msghdr *msg, size_t size) inet_sk(sk)->inet_dport = 0; goto out; } - inet_sk(sk)->defer_connect = 0; + SET_DEFER_CONNECT_OFF(sk); if ((((__u32)1 << sk->sk_state) & ~(__u32)(TCPF_ESTABLISHED | TCPF_CLOSE_WAIT)) && !tcp_passive_fastopen(sk)) { sk_stream_wait_connect(sk, &timeo); @@ -128,7 +135,7 @@ static int defer_connect_and_sendmsg(struct sock *sk, struct msghdr *msg, size_t struct socket *sock; int err = 0; - if (unlikely(inet_sk(sk)->defer_connect == 1)) { + if (unlikely(IS_DEFER_CONNECT(sk))) { lock_sock(sk); err = defer_connect(sk, msg, size); @@ -163,9 +170,9 @@ static int defer_tcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_l * of defer_connect should be 1 and the normal connect function * needs to be used. */ - if (inet_sk(sk)->defer_connect) + if (IS_DEFER_CONNECT(sk)) return tcp_v4_connect(sk, uaddr, addr_len); - inet_sk(sk)->defer_connect = 1; + SET_DEFER_CONNECT_ON(sk); sk->sk_dport = ((struct sockaddr_in *)uaddr)->sin_port; sk_daddr_set(sk, ((struct sockaddr_in *)uaddr)->sin_addr.s_addr); sk->sk_socket->state = SS_CONNECTING; @@ -188,7 +195,7 @@ static int kmesh_defer_init(struct sock *sk) } static struct tcp_ulp_ops kmesh_defer_ulp_ops __read_mostly = { - .name = "kmesh_defer", + .name = KMESH_MODULE_ULP_NAME, .owner = THIS_MODULE, .init = kmesh_defer_init, }; diff --git a/kernel/ko_src/kmesh/kmesh_func.c b/kernel/ko_src/kmesh/kmesh_func.c new file mode 100644 index 000000000..8f5600951 --- /dev/null +++ b/kernel/ko_src/kmesh/kmesh_func.c @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +/* Copyright Authors of Kmesh */ +#include +#include +#include +#include +#include +#include +#include +#include +#include "kmesh_func.h" + +#define HOST_KEY_LEN 5 + +#if KERNEL_KFUNC +__diag_push(); +__diag_ignore_all("-Wmissing-prototypes", "Global functions as their definitions will be in BTF"); + +__bpf_kfunc int bpf_km_header_strnstr_func(void *ctx, int ctx__sz, const char *key, int key__sz, const char *subptr) +{ + struct bpf_sock_addr_kern *sa_kern = ctx; + int subptr__sz = HOST_KEY_LEN; + return bpf_km_header_strnstr_impl(ctx, key, key__sz, subptr, subptr__sz); +} + +__bpf_kfunc int bpf_km_header_strncmp_func(const char *key, int key_sz, const char *target, int target_len, int opt) +{ + return bpf_km_header_strncmp_impl(key, key_sz, target, target_len, opt); +} + +__bpf_kfunc int bpf_parse_header_msg_func(void *bpf_mem, int src__sz) +{ + struct bpf_mem_ptr *tmp = bpf_mem; + struct bpf_sock_addr_kern *ctx = tmp->ptr; + return parse_protocol_impl(ctx); +} + +__bpf_kfunc int bpf_setsockopt_func(void *bpf_mem, int bpf_socket__sz, int optname, const char *optval, int optval__sz) +{ + struct bpf_mem_ptr *tmp = bpf_mem; + struct bpf_sock_addr_kern *ctx = tmp->ptr; + struct sock *sk = ctx->sk; + + if (sk == NULL) { + LOG(KERN_ERR, "sk is NULL\n"); + return -1; + } + return tcp_setsockopt(sk, SOL_TCP, optname, KERNEL_SOCKPTR(optval), optval__sz); +} + +__bpf_kfunc int bpf_getsockopt_func(void *bpf_mem, int bpf_socket__sz, int optname, char *opt, int opt__sz) +{ + struct bpf_mem_ptr *tmp = bpf_mem; + struct bpf_sock_addr_kern *ctx = tmp->ptr; + struct sock *sk = ctx->sk; + + struct inet_connection_sock *icsk = inet_csk(sk); + int len; + + sockptr_t optval = KERNEL_SOCKPTR(opt); + sockptr_t optlen = KERNEL_SOCKPTR(&opt__sz); + + if (copy_from_sockptr(&len, optlen, sizeof(int))) + return -EFAULT; + + if (len < 0) + return -EINVAL; + + len = min_t(unsigned int, len, TCP_ULP_NAME_MAX); + if (!icsk->icsk_ulp_ops) { + len = 0; + if (copy_to_sockptr(optlen, &len, sizeof(int))) + return -EFAULT; + return -EINVAL; + } + if (copy_to_sockptr(optlen, &len, sizeof(int))) + return -EFAULT; + if (copy_to_sockptr(optval, icsk->icsk_ulp_ops->name, len)) + return -EFAULT; + return 0; +} + +__diag_pop(); + +BTF_SET8_START(bpf_kmesh_kfunc) +BTF_ID_FLAGS(func, bpf_km_header_strnstr_func) +BTF_ID_FLAGS(func, bpf_km_header_strncmp_func) +BTF_ID_FLAGS(func, bpf_parse_header_msg_func) +BTF_ID_FLAGS(func, bpf_setsockopt_func) +BTF_ID_FLAGS(func, bpf_getsockopt_func) +BTF_SET8_END(bpf_kmesh_kfunc) + +static const struct btf_kfunc_id_set bpf_kmesh_kfunc_set = { + .owner = THIS_MODULE, + .set = &bpf_kmesh_kfunc, +}; + +int __init kmesh_func_init(void) +{ + int ret; + ret = register_btf_kfunc_id_set(BPF_PROG_TYPE_UNSPEC, &bpf_kmesh_kfunc_set); + if (ret < 0) { + pr_err("ret is not zero:%d\n", ret); + return ret; + } + return 0; +} + +void __exit kmesh_func_exit(void) +{ + return; +} + +#else +typedef int (*bpf_parse_protocol_func)(struct bpf_sock_addr_kern *ctx); +extern bpf_parse_protocol_func parse_protocol_func; + +typedef int (*bpf_km_header_strnstr_func)( + struct bpf_sock_addr_kern *ctx, const char *key, int key_sz, const char *subptr, int subptr_sz); +extern bpf_km_header_strnstr_func km_header_strnstr_func; + +typedef int (*bpf_km_header_strncmp_func)(const char *key, int key_sz, const char *target, int target_sz, int opt); +extern bpf_km_header_strncmp_func km_header_strncmp_func; + +int __init kmesh_func_init(void) +{ + parse_protocol_func = parse_protocol_impl; + km_header_strnstr_func = bpf_km_header_strnstr_impl; + km_header_strncmp_func = bpf_km_header_strncmp_impl; + return 0; +} + +void __exit kmesh_func_exit(void) +{ + parse_protocol_func = NULL; + km_header_strnstr_func = NULL; + km_header_strncmp_func = NULL; +} + +#endif +MODULE_LICENSE("Dual BSD/GPL"); diff --git a/kernel/ko_src/kmesh/kmesh_func.h b/kernel/ko_src/kmesh/kmesh_func.h new file mode 100644 index 000000000..e6bf33f5f --- /dev/null +++ b/kernel/ko_src/kmesh/kmesh_func.h @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +/* Copyright Authors of Kmesh */ +#include "kmesh_parse_protocol_data.h" + +int __init kmesh_func_init(void); +void __exit kmesh_func_exit(void); diff --git a/kernel/ko_src/kmesh/kmesh_main.c b/kernel/ko_src/kmesh/kmesh_main.c index 7a7ba332e..c58804ba3 100644 --- a/kernel/ko_src/kmesh/kmesh_main.c +++ b/kernel/ko_src/kmesh/kmesh_main.c @@ -13,6 +13,7 @@ #include "defer_connect.h" #include "kmesh_parse_protocol_data.h" #include "kmesh_parse_http_1_1.h" +#include "kmesh_func.h" static int __init kmesh_init(void) { @@ -23,7 +24,7 @@ static int __init kmesh_init(void) LOG(KERN_ERR, "defer_conn_init failed:%d\n", ret); return ret; } - + kmesh_func_init(); ret = proto_common_init(); if (ret) { LOG(KERN_ERR, "proto_common_init failed:%d\n", ret); @@ -37,6 +38,7 @@ static int __init kmesh_init(void) static void __exit kmesh_exit(void) { defer_conn_exit(); + kmesh_func_exit(); proto_common_exit(); } diff --git a/kernel/ko_src/kmesh/kmesh_parse_protocol_data.c b/kernel/ko_src/kmesh/kmesh_parse_protocol_data.c index cc2a831aa..e3c5e9ae8 100644 --- a/kernel/ko_src/kmesh/kmesh_parse_protocol_data.c +++ b/kernel/ko_src/kmesh/kmesh_parse_protocol_data.c @@ -118,17 +118,7 @@ void kmesh_protocol_data_clean_allcpu(void) } } -typedef int (*bpf_parse_protocol_func)(struct bpf_sock_addr_kern *ctx); -extern bpf_parse_protocol_func parse_protocol_func; - -typedef int (*bpf_km_header_strnstr_func)( - struct bpf_sock_addr_kern *ctx, const char *key, int key_sz, const char *subptr, int subptr_sz); -extern bpf_km_header_strnstr_func km_header_strnstr_func; - -typedef int (*bpf_km_header_strncmp_func)(const char *key, int key_sz, const char *target, int target_sz, int opt); -extern bpf_km_header_strncmp_func km_header_strncmp_func; - -static int parse_protocol_impl(struct bpf_sock_addr_kern *ctx) +int parse_protocol_impl(struct bpf_sock_addr_kern *ctx) { int ret; struct msg_protocol *cur; @@ -144,7 +134,7 @@ static int parse_protocol_impl(struct bpf_sock_addr_kern *ctx) return ret; } -static int bpf_km_header_strnstr_impl( +int bpf_km_header_strnstr_impl( struct bpf_sock_addr_kern *ctx, const char *key, int key_sz, const char *subptr, int subptr_len) { struct bpf_mem_ptr *msg = NULL; @@ -159,7 +149,7 @@ static int bpf_km_header_strnstr_impl( return 0; } -static int bpf_km_header_strncmp_impl(const char *key, int key_sz, const char *target, int target_len, int opt) +int bpf_km_header_strncmp_impl(const char *key, int key_sz, const char *target, int target_len, int opt) { struct kmesh_data_node *data = NULL; target_len = strnlen(target, target_len); @@ -179,9 +169,6 @@ static int bpf_km_header_strncmp_impl(const char *key, int key_sz, const char *t int __init proto_common_init(void) { - parse_protocol_func = parse_protocol_impl; - km_header_strnstr_func = bpf_km_header_strnstr_impl; - km_header_strncmp_func = bpf_km_header_strncmp_impl; /* add protocol list */ g_kmesh_data_root = alloc_percpu(struct rb_root); if (!g_kmesh_data_root) @@ -191,9 +178,6 @@ int __init proto_common_init(void) void __exit proto_common_exit(void) { - parse_protocol_func = NULL; - km_header_strnstr_func = NULL; - km_header_strncmp_func = NULL; kmesh_protocol_data_clean_allcpu(); free_percpu(g_kmesh_data_root); } diff --git a/kernel/ko_src/kmesh/kmesh_parse_protocol_data.h b/kernel/ko_src/kmesh/kmesh_parse_protocol_data.h index f6569a516..e4a1ef5c3 100644 --- a/kernel/ko_src/kmesh/kmesh_parse_protocol_data.h +++ b/kernel/ko_src/kmesh/kmesh_parse_protocol_data.h @@ -8,6 +8,7 @@ #ifndef KMESH_PARSE_PROTOCOL_DATA #define KMESH_PARSE_PROTOCOL_DATA +#include "../../../config/kmesh_marcos_def.h" #include #include #include @@ -59,6 +60,11 @@ void kmesh_protocol_data_clean_all(void); void kmesh_protocol_data_clean_allcpu(void); +int bpf_km_header_strnstr_impl( + struct bpf_sock_addr_kern *ctx, const char *key, int key_sz, const char *subptr, int subptr_len); +int bpf_km_header_strncmp_impl(const char *key, int key_sz, const char *target, int target_len, int opt); +int parse_protocol_impl(struct bpf_sock_addr_kern *ctx); + int __init proto_common_init(void); void __exit proto_common_exit(void); diff --git a/kmesh_compile_env_pre.sh b/kmesh_compile_env_pre.sh index fc28bc96e..a6593ddb7 100644 --- a/kmesh_compile_env_pre.sh +++ b/kmesh_compile_env_pre.sh @@ -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,7 +144,12 @@ 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 + KERNEL_MAJOR=$(uname -r | awk -F '.' '{print $1}') + + 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="enhanced" else export ENHANCED_KERNEL="normal" diff --git a/kmesh_macros_env.sh b/kmesh_macros_env.sh index 9c5cd0608..7c9d79056 100644 --- a/kmesh_macros_env.sh +++ b/kmesh_macros_env.sh @@ -1,11 +1,8 @@ #!/bin/bash -VERSION=$(uname -r | cut -d '.' -f 1) -KERNEL_VERSION=$(uname -r | cut -d '-' -f 1) +source ./kmesh_compile_env_pre.sh -function set_config() { - sed -i -r -e "s/($1)([ \t]*)([0-9]+)/\1\2$2/" config/kmesh_marcos_def.h -} +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 +25,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..bfc856c0a 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,11 +25,11 @@ 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 @@ -44,7 +40,9 @@ else fi # KERNEL_KFUNC -if [ "$VERSION" -ge 6 ]; then +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 1 set_config KERNEL_KFUNC 1 else 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) }