diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0fba1bba2..7f48df0db 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -41,6 +41,7 @@ jobs: run: | sudo env "PATH=$PATH" bash ./build.sh + # The kernel version of Ubuntu 22.04 is 6.8, so the access control check is enhanced by default. - name: Setup Enviroments run: | echo "PKG_CONFIG_PATH=$GITHUB_WORKSPACE/mk" >> $GITHUB_ENV @@ -54,12 +55,12 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v3.7.0 with: - args: "--config=common/config/.golangci.yaml --out-format colored-line-number" + args: "--build-tags=enhanced --config=common/config/.golangci.yaml --out-format colored-line-number" skip-pkg-cache: true - name: Go Test run: | - sudo env LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:$GITHUB_WORKSPACE/api/v2-c:$GITHUB_WORKSPACE/bpf/deserialization_to_bpf_map PKG_CONFIG_PATH=$GITHUB_WORKSPACE/mk go test -race -v -vet=off -coverprofile=coverage.out ./pkg/... + sudo env LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib:$GITHUB_WORKSPACE/api/v2-c:$GITHUB_WORKSPACE/bpf/deserialization_to_bpf_map PKG_CONFIG_PATH=$GITHUB_WORKSPACE/mk go test -tags=enhanced -race -v -vet=off -coverprofile=coverage.out ./pkg/... - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v4 diff --git a/bpf/include/common.h b/bpf/include/common.h index ee045c102..ea95c76e0 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 @@ -16,8 +17,60 @@ #include "errno.h" +struct bpf_mem_ptr { + void *ptr; + __u32 size; +}; + #if ENHANCED_KERNEL +#if KERNEL_KFUNC +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 + +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); +} + +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. +int bpf_km_setsockopt(struct bpf_sock_addr *ctx, int level, int optname, const char *optval, int optval__sz) +{ + const char kmesh_module_name[] = "kmesh_defer"; + if (level != IPPROTO_TCP || optval__sz != sizeof(kmesh_module_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_name, sizeof(kmesh_module_name)); +} + +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); +} + +#else #include +#define bpf_km_setsockopt bpf_setsockopt +#define bpf_km_getsockopt bpf_getsockopt +#endif #endif #define bpf_unused __attribute__((__unused__)) @@ -121,14 +174,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/include/inner_map_defs.h b/bpf/include/inner_map_defs.h index 028f59ca2..d770df4e3 100644 --- a/bpf/include/inner_map_defs.h +++ b/bpf/include/inner_map_defs.h @@ -33,4 +33,4 @@ typedef enum { MAP_TYPE_64, MAP_TYPE_192, MAP_TYPE_296, MAP_TYPE_1600, MAP_TYPE_ #define FLIP_BIT(bitmap, n) ((bitmap)[(n) / 8] ^= (1U << ((n) % 8))) -#endif // __INNER_MAP_H__ \ No newline at end of file +#endif // __INNER_MAP_H__ diff --git a/bpf/kmesh/ads/cgroup_sock.c b/bpf/kmesh/ads/cgroup_sock.c index ca125cda8..d84893c27 100644 --- a/bpf/kmesh/ads/cgroup_sock.c +++ b/bpf/kmesh/ads/cgroup_sock.c @@ -19,11 +19,10 @@ #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_name_get[KMESH_MODULE_NAME_LEN] = ""; Listener__Listener *listener = NULL; if (ctx->protocol != IPPROTO_TCP) @@ -42,9 +41,9 @@ 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); + ret = bpf_km_getsockopt(ctx, IPPROTO_TCP, TCP_ULP, 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_setsockopt(ctx, IPPROTO_TCP, TCP_ULP, kmesh_module_name, sizeof(kmesh_module_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 b1a35d91f..8b5bf0e2b 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..0624476d9 --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsock_bpfeb.go @@ -0,0 +1,225 @@ +// 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 KmeshCgroupSockKmeshConfig struct { + BpfLogLevel uint32 + NodeIp [4]uint32 + PodGateway [4]uint32 + AuthzOffload uint32 + EnableMonitoring uint32 +} + +type KmeshCgroupSockManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockSockStorageData struct { + ConnectNs uint64 + Direction uint8 + ConnectSuccess uint8 + _ [6]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"` + RouteConfigManager *ebpf.ProgramSpec `ebpf:"route_config_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"` + KmConfigmap *ebpf.MapSpec `ebpf:"km_configmap"` + 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"` + KmRouterconfig *ebpf.MapSpec `ebpf:"km_routerconfig"` + 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"` + KmConfigmap *ebpf.Map `ebpf:"km_configmap"` + 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"` + KmRouterconfig *ebpf.Map `ebpf:"km_routerconfig"` + 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.KmConfigmap, + m.KmEpsData, + m.KmListener, + m.KmLogEvent, + m.KmMaglevOuter, + m.KmManage, + m.KmRouterconfig, + 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"` + RouteConfigManager *ebpf.Program `ebpf:"route_config_manager"` +} + +func (p *KmeshCgroupSockPrograms) Close() error { + return _KmeshCgroupSockClose( + p.CgroupConnect4Prog, + p.ClusterManager, + p.FilterChainManager, + p.FilterManager, + p.RouteConfigManager, + ) +} + +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..24633e916 --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsock_bpfel.go @@ -0,0 +1,225 @@ +// 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 KmeshCgroupSockKmeshConfig struct { + BpfLogLevel uint32 + NodeIp [4]uint32 + PodGateway [4]uint32 + AuthzOffload uint32 + EnableMonitoring uint32 +} + +type KmeshCgroupSockManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockSockStorageData struct { + ConnectNs uint64 + Direction uint8 + ConnectSuccess uint8 + _ [6]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"` + RouteConfigManager *ebpf.ProgramSpec `ebpf:"route_config_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"` + KmConfigmap *ebpf.MapSpec `ebpf:"km_configmap"` + 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"` + KmRouterconfig *ebpf.MapSpec `ebpf:"km_routerconfig"` + 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"` + KmConfigmap *ebpf.Map `ebpf:"km_configmap"` + 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"` + KmRouterconfig *ebpf.Map `ebpf:"km_routerconfig"` + 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.KmConfigmap, + m.KmEpsData, + m.KmListener, + m.KmLogEvent, + m.KmMaglevOuter, + m.KmManage, + m.KmRouterconfig, + 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"` + RouteConfigManager *ebpf.Program `ebpf:"route_config_manager"` +} + +func (p *KmeshCgroupSockPrograms) Close() error { + return _KmeshCgroupSockClose( + p.CgroupConnect4Prog, + p.ClusterManager, + p.FilterChainManager, + p.FilterManager, + p.RouteConfigManager, + ) +} + +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..44dffc05d --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsockcompat_bpfeb.go @@ -0,0 +1,225 @@ +// 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 KmeshCgroupSockCompatKmeshConfig struct { + BpfLogLevel uint32 + NodeIp [4]uint32 + PodGateway [4]uint32 + AuthzOffload uint32 + EnableMonitoring uint32 +} + +type KmeshCgroupSockCompatManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockCompatSockStorageData struct { + ConnectNs uint64 + Direction uint8 + ConnectSuccess uint8 + _ [6]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"` + RouteConfigManager *ebpf.ProgramSpec `ebpf:"route_config_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"` + KmConfigmap *ebpf.MapSpec `ebpf:"km_configmap"` + 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"` + KmRouterconfig *ebpf.MapSpec `ebpf:"km_routerconfig"` + 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"` + KmConfigmap *ebpf.Map `ebpf:"km_configmap"` + 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"` + KmRouterconfig *ebpf.Map `ebpf:"km_routerconfig"` + 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.KmConfigmap, + m.KmEpsData, + m.KmListener, + m.KmLogEvent, + m.KmMaglevOuter, + m.KmManage, + m.KmRouterconfig, + 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"` + RouteConfigManager *ebpf.Program `ebpf:"route_config_manager"` +} + +func (p *KmeshCgroupSockCompatPrograms) Close() error { + return _KmeshCgroupSockCompatClose( + p.CgroupConnect4Prog, + p.ClusterManager, + p.FilterChainManager, + p.FilterManager, + p.RouteConfigManager, + ) +} + +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..521e442e4 --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsockcompat_bpfel.go @@ -0,0 +1,225 @@ +// 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 KmeshCgroupSockCompatKmeshConfig struct { + BpfLogLevel uint32 + NodeIp [4]uint32 + PodGateway [4]uint32 + AuthzOffload uint32 + EnableMonitoring uint32 +} + +type KmeshCgroupSockCompatManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockCompatSockStorageData struct { + ConnectNs uint64 + Direction uint8 + ConnectSuccess uint8 + _ [6]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"` + RouteConfigManager *ebpf.ProgramSpec `ebpf:"route_config_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"` + KmConfigmap *ebpf.MapSpec `ebpf:"km_configmap"` + 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"` + KmRouterconfig *ebpf.MapSpec `ebpf:"km_routerconfig"` + 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"` + KmConfigmap *ebpf.Map `ebpf:"km_configmap"` + 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"` + KmRouterconfig *ebpf.Map `ebpf:"km_routerconfig"` + 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.KmConfigmap, + m.KmEpsData, + m.KmListener, + m.KmLogEvent, + m.KmMaglevOuter, + m.KmManage, + m.KmRouterconfig, + 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"` + RouteConfigManager *ebpf.Program `ebpf:"route_config_manager"` +} + +func (p *KmeshCgroupSockCompatPrograms) Close() error { + return _KmeshCgroupSockCompatClose( + p.CgroupConnect4Prog, + p.ClusterManager, + p.FilterChainManager, + p.FilterManager, + p.RouteConfigManager, + ) +} + +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/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockops_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockops_bpfeb.go index 637e8e8e2..7727dc894 100644 --- a/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockops_bpfeb.go +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockops_bpfeb.go @@ -71,42 +71,38 @@ func LoadKmeshSockopsObjects(obj interface{}, opts *ebpf.CollectionOptions) erro type KmeshSockopsSpecs struct { KmeshSockopsProgramSpecs KmeshSockopsMapSpecs + KmeshSockopsVariableSpecs } -// KmeshSockopsSpecs contains programs before they are loaded into the kernel. +// KmeshSockopsProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type KmeshSockopsProgramSpecs struct { - ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` - FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` - FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` - RouteConfigManager *ebpf.ProgramSpec `ebpf:"route_config_manager"` - SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` + SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` } // KmeshSockopsMapSpecs contains maps before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type KmeshSockopsMapSpecs struct { - 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"` - KmConfigmap *ebpf.MapSpec `ebpf:"km_configmap"` - 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"` - KmRouterconfig *ebpf.MapSpec `ebpf:"km_routerconfig"` - KmSkopstailcall *ebpf.MapSpec `ebpf:"km_skopstailcall"` - 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"` + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmConfigmap *ebpf.MapSpec `ebpf:"km_configmap"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + 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"` +} + +// KmeshSockopsVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` } // KmeshSockopsObjects contains all objects after they have been loaded into the kernel. @@ -115,6 +111,7 @@ type KmeshSockopsMapSpecs struct { type KmeshSockopsObjects struct { KmeshSockopsPrograms KmeshSockopsMaps + KmeshSockopsVariables } func (o *KmeshSockopsObjects) Close() error { @@ -128,43 +125,27 @@ func (o *KmeshSockopsObjects) Close() error { // // It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSockopsMaps struct { - 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"` - KmConfigmap *ebpf.Map `ebpf:"km_configmap"` - 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"` - KmRouterconfig *ebpf.Map `ebpf:"km_routerconfig"` - KmSkopstailcall *ebpf.Map `ebpf:"km_skopstailcall"` - 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"` + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmConfigmap *ebpf.Map `ebpf:"km_configmap"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + 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 *KmeshSockopsMaps) Close() error { return _KmeshSockopsClose( - m.KmCluster, - m.KmClusterEps, m.KmClusterSock, m.KmClusterstats, m.KmConfigmap, - m.KmEpsData, - m.KmListener, m.KmLogEvent, - m.KmMaglevOuter, m.KmManage, - m.KmRouterconfig, - m.KmSkopstailcall, m.KmSockstorage, - m.KmTailcallCtx, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, @@ -173,23 +154,22 @@ func (m *KmeshSockopsMaps) Close() error { ) } +// KmeshSockopsVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + // KmeshSockopsPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSockopsPrograms struct { - ClusterManager *ebpf.Program `ebpf:"cluster_manager"` - FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` - FilterManager *ebpf.Program `ebpf:"filter_manager"` - RouteConfigManager *ebpf.Program `ebpf:"route_config_manager"` - SockopsProg *ebpf.Program `ebpf:"sockops_prog"` + SockopsProg *ebpf.Program `ebpf:"sockops_prog"` } func (p *KmeshSockopsPrograms) Close() error { return _KmeshSockopsClose( - p.ClusterManager, - p.FilterChainManager, - p.FilterManager, - p.RouteConfigManager, p.SockopsProg, ) } diff --git a/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockops_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockops_bpfel.go index 7366e1129..4603d056c 100644 --- a/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockops_bpfel.go +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockops_bpfel.go @@ -71,42 +71,38 @@ func LoadKmeshSockopsObjects(obj interface{}, opts *ebpf.CollectionOptions) erro type KmeshSockopsSpecs struct { KmeshSockopsProgramSpecs KmeshSockopsMapSpecs + KmeshSockopsVariableSpecs } -// KmeshSockopsSpecs contains programs before they are loaded into the kernel. +// KmeshSockopsProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type KmeshSockopsProgramSpecs struct { - ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` - FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` - FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` - RouteConfigManager *ebpf.ProgramSpec `ebpf:"route_config_manager"` - SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` + SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` } // KmeshSockopsMapSpecs contains maps before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type KmeshSockopsMapSpecs struct { - 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"` - KmConfigmap *ebpf.MapSpec `ebpf:"km_configmap"` - 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"` - KmRouterconfig *ebpf.MapSpec `ebpf:"km_routerconfig"` - KmSkopstailcall *ebpf.MapSpec `ebpf:"km_skopstailcall"` - 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"` + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmConfigmap *ebpf.MapSpec `ebpf:"km_configmap"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + 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"` +} + +// KmeshSockopsVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` } // KmeshSockopsObjects contains all objects after they have been loaded into the kernel. @@ -115,6 +111,7 @@ type KmeshSockopsMapSpecs struct { type KmeshSockopsObjects struct { KmeshSockopsPrograms KmeshSockopsMaps + KmeshSockopsVariables } func (o *KmeshSockopsObjects) Close() error { @@ -128,43 +125,27 @@ func (o *KmeshSockopsObjects) Close() error { // // It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSockopsMaps struct { - 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"` - KmConfigmap *ebpf.Map `ebpf:"km_configmap"` - 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"` - KmRouterconfig *ebpf.Map `ebpf:"km_routerconfig"` - KmSkopstailcall *ebpf.Map `ebpf:"km_skopstailcall"` - 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"` + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmConfigmap *ebpf.Map `ebpf:"km_configmap"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + 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 *KmeshSockopsMaps) Close() error { return _KmeshSockopsClose( - m.KmCluster, - m.KmClusterEps, m.KmClusterSock, m.KmClusterstats, m.KmConfigmap, - m.KmEpsData, - m.KmListener, m.KmLogEvent, - m.KmMaglevOuter, m.KmManage, - m.KmRouterconfig, - m.KmSkopstailcall, m.KmSockstorage, - m.KmTailcallCtx, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, @@ -173,23 +154,22 @@ func (m *KmeshSockopsMaps) Close() error { ) } +// KmeshSockopsVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + // KmeshSockopsPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSockopsPrograms struct { - ClusterManager *ebpf.Program `ebpf:"cluster_manager"` - FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` - FilterManager *ebpf.Program `ebpf:"filter_manager"` - RouteConfigManager *ebpf.Program `ebpf:"route_config_manager"` - SockopsProg *ebpf.Program `ebpf:"sockops_prog"` + SockopsProg *ebpf.Program `ebpf:"sockops_prog"` } func (p *KmeshSockopsPrograms) Close() error { return _KmeshSockopsClose( - p.ClusterManager, - p.FilterChainManager, - p.FilterManager, - p.RouteConfigManager, p.SockopsProg, ) } diff --git a/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockopscompat_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockopscompat_bpfeb.go index 7f14ce64c..78206f912 100644 --- a/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockopscompat_bpfeb.go +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockopscompat_bpfeb.go @@ -71,42 +71,38 @@ func LoadKmeshSockopsCompatObjects(obj interface{}, opts *ebpf.CollectionOptions type KmeshSockopsCompatSpecs struct { KmeshSockopsCompatProgramSpecs KmeshSockopsCompatMapSpecs + KmeshSockopsCompatVariableSpecs } -// KmeshSockopsCompatSpecs contains programs before they are loaded into the kernel. +// KmeshSockopsCompatProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type KmeshSockopsCompatProgramSpecs struct { - ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` - FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` - FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` - RouteConfigManager *ebpf.ProgramSpec `ebpf:"route_config_manager"` - SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` + SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` } // KmeshSockopsCompatMapSpecs contains maps before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type KmeshSockopsCompatMapSpecs struct { - 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"` - KmConfigmap *ebpf.MapSpec `ebpf:"km_configmap"` - 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"` - KmRouterconfig *ebpf.MapSpec `ebpf:"km_routerconfig"` - KmSkopstailcall *ebpf.MapSpec `ebpf:"km_skopstailcall"` - 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"` + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmConfigmap *ebpf.MapSpec `ebpf:"km_configmap"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + 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"` +} + +// KmeshSockopsCompatVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsCompatVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` } // KmeshSockopsCompatObjects contains all objects after they have been loaded into the kernel. @@ -115,6 +111,7 @@ type KmeshSockopsCompatMapSpecs struct { type KmeshSockopsCompatObjects struct { KmeshSockopsCompatPrograms KmeshSockopsCompatMaps + KmeshSockopsCompatVariables } func (o *KmeshSockopsCompatObjects) Close() error { @@ -128,43 +125,27 @@ func (o *KmeshSockopsCompatObjects) Close() error { // // It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSockopsCompatMaps struct { - 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"` - KmConfigmap *ebpf.Map `ebpf:"km_configmap"` - 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"` - KmRouterconfig *ebpf.Map `ebpf:"km_routerconfig"` - KmSkopstailcall *ebpf.Map `ebpf:"km_skopstailcall"` - 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"` + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmConfigmap *ebpf.Map `ebpf:"km_configmap"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + 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 *KmeshSockopsCompatMaps) Close() error { return _KmeshSockopsCompatClose( - m.KmCluster, - m.KmClusterEps, m.KmClusterSock, m.KmClusterstats, m.KmConfigmap, - m.KmEpsData, - m.KmListener, m.KmLogEvent, - m.KmMaglevOuter, m.KmManage, - m.KmRouterconfig, - m.KmSkopstailcall, m.KmSockstorage, - m.KmTailcallCtx, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, @@ -173,23 +154,22 @@ func (m *KmeshSockopsCompatMaps) Close() error { ) } +// KmeshSockopsCompatVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsCompatVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + // KmeshSockopsCompatPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSockopsCompatPrograms struct { - ClusterManager *ebpf.Program `ebpf:"cluster_manager"` - FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` - FilterManager *ebpf.Program `ebpf:"filter_manager"` - RouteConfigManager *ebpf.Program `ebpf:"route_config_manager"` - SockopsProg *ebpf.Program `ebpf:"sockops_prog"` + SockopsProg *ebpf.Program `ebpf:"sockops_prog"` } func (p *KmeshSockopsCompatPrograms) Close() error { return _KmeshSockopsCompatClose( - p.ClusterManager, - p.FilterChainManager, - p.FilterManager, - p.RouteConfigManager, p.SockopsProg, ) } diff --git a/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockopscompat_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockopscompat_bpfel.go index 8fa776acc..504cded68 100644 --- a/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockopscompat_bpfel.go +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockopscompat_bpfel.go @@ -71,42 +71,38 @@ func LoadKmeshSockopsCompatObjects(obj interface{}, opts *ebpf.CollectionOptions type KmeshSockopsCompatSpecs struct { KmeshSockopsCompatProgramSpecs KmeshSockopsCompatMapSpecs + KmeshSockopsCompatVariableSpecs } -// KmeshSockopsCompatSpecs contains programs before they are loaded into the kernel. +// KmeshSockopsCompatProgramSpecs contains programs before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type KmeshSockopsCompatProgramSpecs struct { - ClusterManager *ebpf.ProgramSpec `ebpf:"cluster_manager"` - FilterChainManager *ebpf.ProgramSpec `ebpf:"filter_chain_manager"` - FilterManager *ebpf.ProgramSpec `ebpf:"filter_manager"` - RouteConfigManager *ebpf.ProgramSpec `ebpf:"route_config_manager"` - SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` + SockopsProg *ebpf.ProgramSpec `ebpf:"sockops_prog"` } // KmeshSockopsCompatMapSpecs contains maps before they are loaded into the kernel. // // It can be passed ebpf.CollectionSpec.Assign. type KmeshSockopsCompatMapSpecs struct { - 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"` - KmConfigmap *ebpf.MapSpec `ebpf:"km_configmap"` - 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"` - KmRouterconfig *ebpf.MapSpec `ebpf:"km_routerconfig"` - KmSkopstailcall *ebpf.MapSpec `ebpf:"km_skopstailcall"` - 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"` + KmClusterSock *ebpf.MapSpec `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` + KmConfigmap *ebpf.MapSpec `ebpf:"km_configmap"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + 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"` +} + +// KmeshSockopsCompatVariableSpecs contains global variables before they are loaded into the kernel. +// +// It can be passed ebpf.CollectionSpec.Assign. +type KmeshSockopsCompatVariableSpecs struct { + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` } // KmeshSockopsCompatObjects contains all objects after they have been loaded into the kernel. @@ -115,6 +111,7 @@ type KmeshSockopsCompatMapSpecs struct { type KmeshSockopsCompatObjects struct { KmeshSockopsCompatPrograms KmeshSockopsCompatMaps + KmeshSockopsCompatVariables } func (o *KmeshSockopsCompatObjects) Close() error { @@ -128,43 +125,27 @@ func (o *KmeshSockopsCompatObjects) Close() error { // // It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSockopsCompatMaps struct { - 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"` - KmConfigmap *ebpf.Map `ebpf:"km_configmap"` - 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"` - KmRouterconfig *ebpf.Map `ebpf:"km_routerconfig"` - KmSkopstailcall *ebpf.Map `ebpf:"km_skopstailcall"` - 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"` + KmClusterSock *ebpf.Map `ebpf:"km_cluster_sock"` + KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` + KmConfigmap *ebpf.Map `ebpf:"km_configmap"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + 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 *KmeshSockopsCompatMaps) Close() error { return _KmeshSockopsCompatClose( - m.KmCluster, - m.KmClusterEps, m.KmClusterSock, m.KmClusterstats, m.KmConfigmap, - m.KmEpsData, - m.KmListener, m.KmLogEvent, - m.KmMaglevOuter, m.KmManage, - m.KmRouterconfig, - m.KmSkopstailcall, m.KmSockstorage, - m.KmTailcallCtx, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, @@ -173,23 +154,22 @@ func (m *KmeshSockopsCompatMaps) Close() error { ) } +// KmeshSockopsCompatVariables contains all global variables after they have been loaded into the kernel. +// +// It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. +type KmeshSockopsCompatVariables struct { + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` +} + // KmeshSockopsCompatPrograms contains all programs after they have been loaded into the kernel. // // It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSockopsCompatPrograms struct { - ClusterManager *ebpf.Program `ebpf:"cluster_manager"` - FilterChainManager *ebpf.Program `ebpf:"filter_chain_manager"` - FilterManager *ebpf.Program `ebpf:"filter_manager"` - RouteConfigManager *ebpf.Program `ebpf:"route_config_manager"` - SockopsProg *ebpf.Program `ebpf:"sockops_prog"` + SockopsProg *ebpf.Program `ebpf:"sockops_prog"` } func (p *KmeshSockopsCompatPrograms) Close() error { return _KmeshSockopsCompatClose( - p.ClusterManager, - p.FilterChainManager, - p.FilterManager, - p.RouteConfigManager, p.SockopsProg, ) } diff --git a/build/docker/builder.dockerfile b/build/docker/builder.dockerfile index c8f8b1c57..3b8774d74 100644 --- a/build/docker/builder.dockerfile +++ b/build/docker/builder.dockerfile @@ -5,10 +5,10 @@ # # base image -FROM openeuler/openeuler:23.09 +FROM openeuler/openeuler:24.03 # Setup Go -COPY --from=golang:1.23.2 /usr/local/go/ /usr/local/go/ +COPY --from=golang:latest /usr/local/go/ /usr/local/go/ RUN mkdir -p /go ENV GOROOT /usr/local/go ENV GOPATH /go diff --git a/build/docker/dockerfile b/build/docker/dockerfile index 7c865e10c..47d2fbf1b 100644 --- a/build/docker/dockerfile +++ b/build/docker/dockerfile @@ -1,7 +1,7 @@ # Usage: # docker run -itd --privileged=true -v /etc/cni/net.d:/etc/cni/net.d -v /opt/cni/bin:/opt/cni/bin -v /mnt:/mnt -v /sys/fs/bpf:/sys/fs/bpf -v /lib/modules:/lib/modules --name kmesh kmesh:latest # -FROM openeuler/openeuler:23.09 +FROM openeuler/openeuler:24.03 WORKDIR /kmesh diff --git a/config/kmesh_marcos_def.h b/config/kmesh_marcos_def.h index 4daf23236..4e66007ee 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. @@ -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/golangci-lint-prepare.sh b/hack/golangci-lint-prepare.sh index c602f41e0..c7ed3a7a4 100755 --- a/hack/golangci-lint-prepare.sh +++ b/hack/golangci-lint-prepare.sh @@ -1,13 +1,17 @@ #!/bin/bash ROOT_DIR=$(git rev-parse --show-toplevel) -TARGET_DIR="$ROOT_DIR/bpf/kmesh/bpf2go/kernelnative/enhanced" +TARGET_DIR="$ROOT_DIR/bpf/kmesh/bpf2go/kernelnative/normal" FILES=( "kmeshsockops_bpfel.o" "kmeshsockops_bpfeb.o" "kmeshsockopscompat_bpfeb.o" "kmeshsockopscompat_bpfel.o" + "kmeshcgroupsock_bpfeb.o" + "kmeshcgroupsock_bpfel.o" + "kmeshcgroupsockcompat_bpfeb.o" + "kmeshcgroupsockcompat_bpfel.o" ) mkdir -p "$TARGET_DIR" 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..a5e86cbd4 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 @@ -21,9 +20,24 @@ #include "defer_connect.h" static struct proto *kmesh_defer_proto = NULL; -#define KMESH_DELAY_ERROR -1000 -#define BPF_CGROUP_RUN_PROG_INET4_CONNECT_KMESH(sk, uaddr, t_ctx) \ +#ifdef 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_FDEFER_CONNECT_ON(sk) (inet_set_bit(DEFER_CONNECT, sk)) +#define SET_FDEFER_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 +48,11 @@ static struct proto *kmesh_defer_proto = NULL; __ret; \ }) +#define SET_FDEFER_CONNECT_ON(sk) (inet_sk(sk)->defer_connect = 1) +#define SET_FDEFER_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 +62,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,7 +74,11 @@ 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)) { +#ifdef KERNEL_KFUNC + iov = msg->msg_iter.__iov; +#else iov = msg->msg_iter.iov; +#endif ubase = iov->iov_base; kbuf_size = iov->iov_len; #if ITER_TYPE_IS_UBUF @@ -79,31 +103,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 +117,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_FDEFER_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 +132,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 +167,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_FDEFER_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; diff --git a/kernel/ko_src/kmesh/kmesh_func.c b/kernel/ko_src/kmesh/kmesh_func.c new file mode 100644 index 000000000..47c693d8e --- /dev/null +++ b/kernel/ko_src/kmesh/kmesh_func.c @@ -0,0 +1,142 @@ +// 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" + +#ifdef 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 = 5; + 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; + int ret = 0; + + 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); + struct tcp_sock *tp = tcp_sk(sk); + struct net *net = sock_net(sk); + int val, 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 20c8c86b3..d13fd2fa1 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 523c97b9c..443204ab5 100644 --- a/kmesh_compile_env_pre.sh +++ b/kmesh_compile_env_pre.sh @@ -110,6 +110,7 @@ function kmesh_set_env(){ } 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 # variable KERNEL_HEADER_LINUX_BPF is used here to specify the path of the @@ -123,7 +124,10 @@ 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 + # The 6.x Linux kernel already has complete support for kfunc capabilities, + # allowing all features of kmesh to run directly. + KERNEL_MAJOR=$(uname -r | awk -F '.' '{print $1}') + if grep -q "FN(parse_header_msg)" $KERNEL_HEADER_LINUX_BPF || [ $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 2f7a94762..1963f99aa 100644 --- a/kmesh_macros_env.sh +++ b/kmesh_macros_env.sh @@ -28,13 +28,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 @@ -61,3 +54,11 @@ if [[ "$LIBBPF_VERSION" < "0.6.0" ]]; then else set_config LIBBPF_HIGHER_0_6_0_VERSION 1 fi + +# KERNEL_KFUNC +if [ "$VERSION" -ge 6 ]; then + set_config ENHANCED_KERNEL 1 + set_config KERNEL_KFUNC 1 +else + set_config KERNEL_KFUNC 0 +fi \ No newline at end of file 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, ...) \