diff --git a/bpf/include/bpf_common.h b/bpf/include/bpf_common.h index 2a739fe14..edb958738 100644 --- a/bpf/include/bpf_common.h +++ b/bpf/include/bpf_common.h @@ -23,6 +23,9 @@ 192 /* this value should be \ small that make compile success */ +#define RINGBUF_SIZE (1 << 12) +#define MAP_SIZE_OF_DSTINFO 8192 + struct manager_key { union { __u64 netns_cookie; @@ -46,6 +49,8 @@ struct sock_storage_data { __u64 connect_ns; __u8 direction; __u8 connect_success; + __u32 pid_tgid; + char dst_svc_name[BPF_DATA_MAX_LEN]; }; struct { @@ -87,6 +92,14 @@ struct { __uint(map_flags, BPF_F_NO_PREALLOC); } kmesh_map1600 SEC(".maps"); +struct { + __uint(type, BPF_MAP_TYPE_HASH); + __type(key, __u64); + __type(value, struct bpf_sock_tuple); + __uint(max_entries, MAP_SIZE_OF_DSTINFO); + __uint(map_flags, BPF_F_NO_PREALLOC); +} map_of_orig_dst SEC(".maps"); + /* * From v5.4, bpf_get_netns_cookie can be called for bpf cgroup hooks, from v5.15, it can be called for bpf sockops * hook. Therefore, ensure that function is correctly used. @@ -305,4 +318,24 @@ static inline bool is_managed_by_kmesh(struct bpf_sock_ops *skops) return (*value == 0); } -#endif \ No newline at end of file +static inline char *bpf_strncpy(char *dst, int n, const char *src) +{ + int isEnd = 0; + if (src == NULL) + return 0; + +#pragma unroll + for (int i = 0; i < BPF_DATA_MAX_LEN; i++) { + if (src[i] == '\0') + isEnd = 1; + if (isEnd == 1) + dst[i] = '\0'; + else + dst[i] = src[i]; + if (i == n - 1) + break; + } + return dst; +} + +#endif diff --git a/bpf/include/map_config.h b/bpf/include/map_config.h index ce688d8e5..33e6df126 100644 --- a/bpf/include/map_config.h +++ b/bpf/include/map_config.h @@ -10,5 +10,7 @@ #define tmp_buf km_tmpbuf #define kmesh_log_events km_log_event #define map_of_nodeinfo km_nodeinfo +#define map_of_tcp_probe km_tcp_probe +#define map_of_orig_dst km_orig_dst #endif // _MAP_CONFIG_H_ \ No newline at end of file diff --git a/bpf/kmesh/ads/cgroup_sock.c b/bpf/kmesh/ads/cgroup_sock.c index ca125cda8..9fc9cb63d 100644 --- a/bpf/kmesh/ads/cgroup_sock.c +++ b/bpf/kmesh/ads/cgroup_sock.c @@ -11,6 +11,8 @@ #include "filter.h" #include "cluster.h" #include "bpf_common.h" +#include "probe.h" +#include "config.h" #if ENHANCED_KERNEL #include "route_config.h" @@ -54,7 +56,6 @@ static inline int sock4_traffic_control(struct bpf_sock_addr *ctx) if (ret != 0) { BPF_LOG(ERR, KMESH, "listener_manager failed, ret %d\n", ret); } - return 0; } @@ -70,7 +71,9 @@ int cgroup_connect4_prog(struct bpf_sock_addr *ctx) if (handle_kmesh_manage_process(&kmesh_ctx) || !is_kmesh_enabled(ctx)) { return CGROUP_SOCK_OK; } + observe_on_pre_connect(ctx->sk); int ret = sock4_traffic_control(ctx); + return CGROUP_SOCK_OK; } diff --git a/bpf/kmesh/ads/include/cluster.h b/bpf/kmesh/ads/include/cluster.h index 35174625d..08af1d6ff 100644 --- a/bpf/kmesh/ads/include/cluster.h +++ b/bpf/kmesh/ads/include/cluster.h @@ -10,6 +10,7 @@ #include "cluster/cluster.pb-c.h" #include "endpoint/endpoint.pb-c.h" #include "circuit_breaker.h" +#include "probe.h" #define CLUSTER_NAME_MAX_LEN BPF_DATA_MAX_LEN #define MAGLEV_TABLE_SIZE 16381 @@ -310,7 +311,7 @@ static inline int cluster_handle_loadbalance(Cluster__Cluster *cluster, address_ BPF_LOG(ERR, CLUSTER, "ep get sock addr failed, %ld\n", (__s64)ep_identity); return -EAGAIN; } - + observe_on_connect(ctx->sk, name); BPF_LOG( INFO, CLUSTER, diff --git a/bpf/kmesh/ads/include/kmesh_common.h b/bpf/kmesh/ads/include/kmesh_common.h index b1a35d91f..6c2c5962d 100644 --- a/bpf/kmesh/ads/include/kmesh_common.h +++ b/bpf/kmesh/ads/include/kmesh_common.h @@ -51,26 +51,6 @@ static inline int bpf__strncmp(const char *dst, int n, const char *src) return 0; }; -static inline char *bpf_strncpy(char *dst, int n, const char *src) -{ - int isEnd = 0; - if (src == NULL) - return 0; - -#pragma unroll - for (int i = 0; i < BPF_DATA_MAX_LEN; i++) { - if (src[i] == '\0') - isEnd = 1; - if (isEnd == 1) - dst[i] = '\0'; - else - dst[i] = src[i]; - if (i == n - 1) - break; - } - return dst; -} - typedef Core__SocketAddress address_t; // bpf return value diff --git a/bpf/kmesh/ads/sockops.c b/bpf/kmesh/ads/sockops.c index 20c12e5fc..6a1c1f3d6 100644 --- a/bpf/kmesh/ads/sockops.c +++ b/bpf/kmesh/ads/sockops.c @@ -5,6 +5,7 @@ #include "bpf_log.h" #include "ctx/sock_ops.h" #include "circuit_breaker.h" +#include "probe.h" #if KMESH_ENABLE_IPV4 #if KMESH_ENABLE_HTTP @@ -17,7 +18,6 @@ int sockops_prog(struct bpf_sock_ops *skops) if (skops->family != AF_INET) return BPF_OK; - switch (skops->op) { case BPF_SOCK_OPS_TCP_CONNECT_CB: skops_handle_kmesh_managed_process(skops); @@ -31,13 +31,24 @@ int sockops_prog(struct bpf_sock_ops *skops) } else { on_cluster_sock_connect(skops); } + observe_on_connect_established(skops->sk, OUTBOUND); + break; + case BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB: + if (!is_managed_by_kmesh(skops)) + break; + + observe_on_connect_established(skops->sk, INBOUND); + if (bpf_sock_ops_cb_flags_set(skops, BPF_SOCK_OPS_STATE_CB_FLAG) != 0) + BPF_LOG(ERR, SOCKOPS, "set sockops cb failed!\n"); break; case BPF_SOCK_OPS_STATE_CB: if (skops->args[1] == BPF_TCP_CLOSE) { + observe_on_close(skops->sk); on_cluster_sock_close(skops); } break; } + return BPF_OK; } diff --git a/bpf/kmesh/bpf2go/bpf2go.go b/bpf/kmesh/bpf2go/bpf2go.go index f79735de3..5ceedb2fb 100644 --- a/bpf/kmesh/bpf2go/bpf2go.go +++ b/bpf/kmesh/bpf2go/bpf2go.go @@ -18,18 +18,18 @@ package bpf2go // go run github.com/cilium/ebpf/cmd/bpf2go --help -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir kernelnative/$ENHANCED_KERNEL --go-package $ENHANCED_KERNEL -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshCgroupSock ../ads/cgroup_sock.c -- -I../ads/include -I../../include -I../../../api/v2-c -DCGROUP_SOCK_MANAGE -DKERNEL_VERSION_HIGHER_5_13_0=1 +//go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir kernelnative/$ENHANCED_KERNEL --go-package $ENHANCED_KERNEL -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshCgroupSock ../ads/cgroup_sock.c -- -I../ads/include -I../../include -I../../../api/v2-c -I../probes -DCGROUP_SOCK_MANAGE -DKERNEL_VERSION_HIGHER_5_13_0=1 //go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir dualengine --go-package dualengine -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshCgroupSockWorkload ../workload/cgroup_sock.c -- -I../workload/include -I../../include -I../probes -DKERNEL_VERSION_HIGHER_5_13_0=1 -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir kernelnative/$ENHANCED_KERNEL --go-package $ENHANCED_KERNEL -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshSockops ../ads/sockops.c -- -I../ads/include -I../../include -I../../../api/v2-c -DKERNEL_VERSION_HIGHER_5_13_0=1 +//go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir kernelnative/$ENHANCED_KERNEL --go-package $ENHANCED_KERNEL -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshSockops ../ads/sockops.c -- -I../ads/include -I../../include -I../../../api/v2-c -I../probes -DKERNEL_VERSION_HIGHER_5_13_0=1 //go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir dualengine --go-package dualengine -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshSockopsWorkload ../workload/sockops.c -- -I../workload/include -I../../include -I../probes -DKERNEL_VERSION_HIGHER_5_13_0=1 //go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir dualengine --go-package dualengine -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshXDPAuth ../workload/xdp.c -- -I../workload/include -I../../include -I../../../api/v2-c -DKERNEL_VERSION_HIGHER_5_13_0=1 //go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir dualengine --go-package dualengine -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshSendmsg ../workload/sendmsg.c -- -I../workload/include -I../../include -DKERNEL_VERSION_HIGHER_5_13_0=1 //go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir general --go-package general -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshTcMarkEncrypt ../general/tc_mark_encrypt.c -- -I../general/include -I../../include -DKERNEL_VERSION_HIGHER_5_13_0=1 //go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir general --go-package general -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshTcMarkDecrypt ../general/tc_mark_decrypt.c -- -I../general/include -I../../include -DKERNEL_VERSION_HIGHER_5_13_0=1 -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir kernelnative/$ENHANCED_KERNEL --go-package $ENHANCED_KERNEL -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshCgroupSockCompat ../ads/cgroup_sock.c -- -I../ads/include -I../../include -I../../../api/v2-c -DCGROUP_SOCK_MANAGE -DKERNEL_VERSION_HIGHER_5_13_0=0 +//go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir kernelnative/$ENHANCED_KERNEL --go-package $ENHANCED_KERNEL -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshCgroupSockCompat ../ads/cgroup_sock.c -- -I../ads/include -I../../include -I../../../api/v2-c -I../probes -DCGROUP_SOCK_MANAGE -DKERNEL_VERSION_HIGHER_5_13_0=0 //go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir dualengine --go-package dualengine -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshCgroupSockWorkloadCompat ../workload/cgroup_sock.c -- -I../workload/include -I../../include -I../probes -DKERNEL_VERSION_HIGHER_5_13_0=0 -//go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir kernelnative/$ENHANCED_KERNEL --go-package $ENHANCED_KERNEL -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshSockopsCompat ../ads/sockops.c -- -I../ads/include -I../../include -I../../../api/v2-c -DKERNEL_VERSION_HIGHER_5_13_0=0 +//go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir kernelnative/$ENHANCED_KERNEL --go-package $ENHANCED_KERNEL -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshSockopsCompat ../ads/sockops.c -- -I../ads/include -I../../include -I../../../api/v2-c -I../probes -DKERNEL_VERSION_HIGHER_5_13_0=0 //go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir dualengine --go-package dualengine -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshSockopsWorkloadCompat ../workload/sockops.c -- -I../workload/include -I../../include -I../probes -DKERNEL_VERSION_HIGHER_5_13_0=0 //go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir dualengine --go-package dualengine -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshXDPAuthCompat ../workload/xdp.c -- -I../workload/include -I../../include -I../../../api/v2-c -DKERNEL_VERSION_HIGHER_5_13_0=0 //go:generate go run github.com/cilium/ebpf/cmd/bpf2go --output-dir dualengine --go-package dualengine -cc clang --cflags $EXTRA_CFLAGS --cflags $EXTRA_CDEFINE KmeshSendmsgCompat ../workload/sendmsg.c -- -I../workload/include -I../../include -DKERNEL_VERSION_HIGHER_5_13_0=0 diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkload_bpfeb.go b/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkload_bpfeb.go index ff175193b..6d6339bbb 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkload_bpfeb.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkload_bpfeb.go @@ -47,7 +47,9 @@ type KmeshCgroupSockWorkloadSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshCgroupSockWorkload returns the embedded CollectionSpec for KmeshCgroupSockWorkload. diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkload_bpfel.go b/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkload_bpfel.go index d0ffd5df7..daca16413 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkload_bpfel.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkload_bpfel.go @@ -47,7 +47,9 @@ type KmeshCgroupSockWorkloadSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshCgroupSockWorkload returns the embedded CollectionSpec for KmeshCgroupSockWorkload. diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkloadcompat_bpfeb.go b/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkloadcompat_bpfeb.go index 4119e6e7d..0d309244d 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkloadcompat_bpfeb.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkloadcompat_bpfeb.go @@ -47,7 +47,9 @@ type KmeshCgroupSockWorkloadCompatSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshCgroupSockWorkloadCompat returns the embedded CollectionSpec for KmeshCgroupSockWorkloadCompat. diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkloadcompat_bpfel.go b/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkloadcompat_bpfel.go index 8d17ea3cb..c456bca29 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkloadcompat_bpfel.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshcgroupsockworkloadcompat_bpfel.go @@ -47,7 +47,9 @@ type KmeshCgroupSockWorkloadCompatSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshCgroupSockWorkloadCompat returns the embedded CollectionSpec for KmeshCgroupSockWorkloadCompat. diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshsendmsg_bpfeb.go b/bpf/kmesh/bpf2go/dualengine/kmeshsendmsg_bpfeb.go index f816fafaa..b35b0db1c 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshsendmsg_bpfeb.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshsendmsg_bpfeb.go @@ -24,6 +24,20 @@ type KmeshSendmsgBpfSockTuple struct { type KmeshSendmsgBuf struct{ Data [40]int8 } +type KmeshSendmsgManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshSendmsgSockStorageData struct { + ConnectNs uint64 + Direction uint8 + ConnectSuccess uint8 + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 +} + // LoadKmeshSendmsg returns the embedded CollectionSpec for KmeshSendmsg. func LoadKmeshSendmsg() (*ebpf.CollectionSpec, error) { reader := bytes.NewReader(_KmeshSendmsgBytes) @@ -73,9 +87,15 @@ type KmeshSendmsgProgramSpecs struct { // // It can be passed ebpf.CollectionSpec.Assign. type KmeshSendmsgMapSpecs struct { - KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` - KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` - KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` + 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"` } // KmeshSendmsgVariableSpecs contains global variables before they are loaded into the kernel. @@ -105,16 +125,28 @@ func (o *KmeshSendmsgObjects) Close() error { // // It can be passed to LoadKmeshSendmsgObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSendmsgMaps struct { - KmLogEvent *ebpf.Map `ebpf:"km_log_event"` - KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` - KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` + 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 *KmeshSendmsgMaps) Close() error { return _KmeshSendmsgClose( m.KmLogEvent, + m.KmManage, m.KmOrigDst, + m.KmSockstorage, m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, ) } diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshsendmsg_bpfel.go b/bpf/kmesh/bpf2go/dualengine/kmeshsendmsg_bpfel.go index 78117dd27..bd684bc8c 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshsendmsg_bpfel.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshsendmsg_bpfel.go @@ -24,6 +24,20 @@ type KmeshSendmsgBpfSockTuple struct { type KmeshSendmsgBuf struct{ Data [40]int8 } +type KmeshSendmsgManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshSendmsgSockStorageData struct { + ConnectNs uint64 + Direction uint8 + ConnectSuccess uint8 + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 +} + // LoadKmeshSendmsg returns the embedded CollectionSpec for KmeshSendmsg. func LoadKmeshSendmsg() (*ebpf.CollectionSpec, error) { reader := bytes.NewReader(_KmeshSendmsgBytes) @@ -73,9 +87,15 @@ type KmeshSendmsgProgramSpecs struct { // // It can be passed ebpf.CollectionSpec.Assign. type KmeshSendmsgMapSpecs struct { - KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` - KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` - KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` + 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"` } // KmeshSendmsgVariableSpecs contains global variables before they are loaded into the kernel. @@ -105,16 +125,28 @@ func (o *KmeshSendmsgObjects) Close() error { // // It can be passed to LoadKmeshSendmsgObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSendmsgMaps struct { - KmLogEvent *ebpf.Map `ebpf:"km_log_event"` - KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` - KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` + 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 *KmeshSendmsgMaps) Close() error { return _KmeshSendmsgClose( m.KmLogEvent, + m.KmManage, m.KmOrigDst, + m.KmSockstorage, m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, ) } diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshsendmsgcompat_bpfeb.go b/bpf/kmesh/bpf2go/dualengine/kmeshsendmsgcompat_bpfeb.go index f0152cb60..d5acb3be8 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshsendmsgcompat_bpfeb.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshsendmsgcompat_bpfeb.go @@ -24,6 +24,20 @@ type KmeshSendmsgCompatBpfSockTuple struct { type KmeshSendmsgCompatBuf struct{ Data [40]int8 } +type KmeshSendmsgCompatManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshSendmsgCompatSockStorageData struct { + ConnectNs uint64 + Direction uint8 + ConnectSuccess uint8 + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 +} + // LoadKmeshSendmsgCompat returns the embedded CollectionSpec for KmeshSendmsgCompat. func LoadKmeshSendmsgCompat() (*ebpf.CollectionSpec, error) { reader := bytes.NewReader(_KmeshSendmsgCompatBytes) @@ -73,9 +87,15 @@ type KmeshSendmsgCompatProgramSpecs struct { // // It can be passed ebpf.CollectionSpec.Assign. type KmeshSendmsgCompatMapSpecs struct { - KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` - KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` - KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` + 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"` } // KmeshSendmsgCompatVariableSpecs contains global variables before they are loaded into the kernel. @@ -105,16 +125,28 @@ func (o *KmeshSendmsgCompatObjects) Close() error { // // It can be passed to LoadKmeshSendmsgCompatObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSendmsgCompatMaps struct { - KmLogEvent *ebpf.Map `ebpf:"km_log_event"` - KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` - KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` + 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 *KmeshSendmsgCompatMaps) Close() error { return _KmeshSendmsgCompatClose( m.KmLogEvent, + m.KmManage, m.KmOrigDst, + m.KmSockstorage, m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, ) } diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshsendmsgcompat_bpfel.go b/bpf/kmesh/bpf2go/dualengine/kmeshsendmsgcompat_bpfel.go index 00fe16489..a6026172d 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshsendmsgcompat_bpfel.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshsendmsgcompat_bpfel.go @@ -24,6 +24,20 @@ type KmeshSendmsgCompatBpfSockTuple struct { type KmeshSendmsgCompatBuf struct{ Data [40]int8 } +type KmeshSendmsgCompatManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshSendmsgCompatSockStorageData struct { + ConnectNs uint64 + Direction uint8 + ConnectSuccess uint8 + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 +} + // LoadKmeshSendmsgCompat returns the embedded CollectionSpec for KmeshSendmsgCompat. func LoadKmeshSendmsgCompat() (*ebpf.CollectionSpec, error) { reader := bytes.NewReader(_KmeshSendmsgCompatBytes) @@ -73,9 +87,15 @@ type KmeshSendmsgCompatProgramSpecs struct { // // It can be passed ebpf.CollectionSpec.Assign. type KmeshSendmsgCompatMapSpecs struct { - KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` - KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` - KmTmpbuf *ebpf.MapSpec `ebpf:"km_tmpbuf"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` + 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"` } // KmeshSendmsgCompatVariableSpecs contains global variables before they are loaded into the kernel. @@ -105,16 +125,28 @@ func (o *KmeshSendmsgCompatObjects) Close() error { // // It can be passed to LoadKmeshSendmsgCompatObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSendmsgCompatMaps struct { - KmLogEvent *ebpf.Map `ebpf:"km_log_event"` - KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` - KmTmpbuf *ebpf.Map `ebpf:"km_tmpbuf"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` + 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 *KmeshSendmsgCompatMaps) Close() error { return _KmeshSendmsgCompatClose( m.KmLogEvent, + m.KmManage, m.KmOrigDst, + m.KmSockstorage, m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, ) } diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkload_bpfeb.go b/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkload_bpfeb.go index addd01706..3ef6dfc57 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkload_bpfeb.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkload_bpfeb.go @@ -47,7 +47,9 @@ type KmeshSockopsWorkloadSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshSockopsWorkload returns the embedded CollectionSpec for KmeshSockopsWorkload. diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkload_bpfel.go b/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkload_bpfel.go index 75afab784..741a5ed70 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkload_bpfel.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkload_bpfel.go @@ -47,7 +47,9 @@ type KmeshSockopsWorkloadSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshSockopsWorkload returns the embedded CollectionSpec for KmeshSockopsWorkload. diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkloadcompat_bpfeb.go b/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkloadcompat_bpfeb.go index f1bfa8779..7325662c7 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkloadcompat_bpfeb.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkloadcompat_bpfeb.go @@ -47,7 +47,9 @@ type KmeshSockopsWorkloadCompatSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshSockopsWorkloadCompat returns the embedded CollectionSpec for KmeshSockopsWorkloadCompat. diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkloadcompat_bpfel.go b/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkloadcompat_bpfel.go index 9729ab032..0305a6c35 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkloadcompat_bpfel.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshsockopsworkloadcompat_bpfel.go @@ -47,7 +47,9 @@ type KmeshSockopsWorkloadCompatSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshSockopsWorkloadCompat returns the embedded CollectionSpec for KmeshSockopsWorkloadCompat. diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshxdpauth_bpfeb.go b/bpf/kmesh/bpf2go/dualengine/kmeshxdpauth_bpfeb.go index fe2491c8e..1f22c434d 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshxdpauth_bpfeb.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshxdpauth_bpfeb.go @@ -33,7 +33,9 @@ type KmeshXDPAuthSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshXDPAuth returns the embedded CollectionSpec for KmeshXDPAuth. @@ -97,6 +99,7 @@ type KmeshXDPAuthMapSpecs struct { KmFrontend *ebpf.MapSpec `ebpf:"km_frontend"` KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` KmService *ebpf.MapSpec `ebpf:"km_service"` KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` KmTcargs *ebpf.MapSpec `ebpf:"km_tcargs"` @@ -146,6 +149,7 @@ type KmeshXDPAuthMaps struct { KmFrontend *ebpf.Map `ebpf:"km_frontend"` KmLogEvent *ebpf.Map `ebpf:"km_log_event"` KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` KmService *ebpf.Map `ebpf:"km_service"` KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` KmTcargs *ebpf.Map `ebpf:"km_tcargs"` @@ -169,6 +173,7 @@ func (m *KmeshXDPAuthMaps) Close() error { m.KmFrontend, m.KmLogEvent, m.KmManage, + m.KmOrigDst, m.KmService, m.KmSockstorage, m.KmTcargs, diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshxdpauth_bpfel.go b/bpf/kmesh/bpf2go/dualengine/kmeshxdpauth_bpfel.go index c6fcae426..567f46c7c 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshxdpauth_bpfel.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshxdpauth_bpfel.go @@ -33,7 +33,9 @@ type KmeshXDPAuthSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshXDPAuth returns the embedded CollectionSpec for KmeshXDPAuth. @@ -97,6 +99,7 @@ type KmeshXDPAuthMapSpecs struct { KmFrontend *ebpf.MapSpec `ebpf:"km_frontend"` KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` KmService *ebpf.MapSpec `ebpf:"km_service"` KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` KmTcargs *ebpf.MapSpec `ebpf:"km_tcargs"` @@ -146,6 +149,7 @@ type KmeshXDPAuthMaps struct { KmFrontend *ebpf.Map `ebpf:"km_frontend"` KmLogEvent *ebpf.Map `ebpf:"km_log_event"` KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` KmService *ebpf.Map `ebpf:"km_service"` KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` KmTcargs *ebpf.Map `ebpf:"km_tcargs"` @@ -169,6 +173,7 @@ func (m *KmeshXDPAuthMaps) Close() error { m.KmFrontend, m.KmLogEvent, m.KmManage, + m.KmOrigDst, m.KmService, m.KmSockstorage, m.KmTcargs, diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshxdpauthcompat_bpfeb.go b/bpf/kmesh/bpf2go/dualengine/kmeshxdpauthcompat_bpfeb.go index ee1f32ca3..99a8cfd52 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshxdpauthcompat_bpfeb.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshxdpauthcompat_bpfeb.go @@ -33,7 +33,9 @@ type KmeshXDPAuthCompatSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshXDPAuthCompat returns the embedded CollectionSpec for KmeshXDPAuthCompat. @@ -97,6 +99,7 @@ type KmeshXDPAuthCompatMapSpecs struct { KmFrontend *ebpf.MapSpec `ebpf:"km_frontend"` KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` KmService *ebpf.MapSpec `ebpf:"km_service"` KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` KmTcargs *ebpf.MapSpec `ebpf:"km_tcargs"` @@ -146,6 +149,7 @@ type KmeshXDPAuthCompatMaps struct { KmFrontend *ebpf.Map `ebpf:"km_frontend"` KmLogEvent *ebpf.Map `ebpf:"km_log_event"` KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` KmService *ebpf.Map `ebpf:"km_service"` KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` KmTcargs *ebpf.Map `ebpf:"km_tcargs"` @@ -169,6 +173,7 @@ func (m *KmeshXDPAuthCompatMaps) Close() error { m.KmFrontend, m.KmLogEvent, m.KmManage, + m.KmOrigDst, m.KmService, m.KmSockstorage, m.KmTcargs, diff --git a/bpf/kmesh/bpf2go/dualengine/kmeshxdpauthcompat_bpfel.go b/bpf/kmesh/bpf2go/dualengine/kmeshxdpauthcompat_bpfel.go index c49500048..b39d09a7a 100644 --- a/bpf/kmesh/bpf2go/dualengine/kmeshxdpauthcompat_bpfel.go +++ b/bpf/kmesh/bpf2go/dualengine/kmeshxdpauthcompat_bpfel.go @@ -33,7 +33,9 @@ type KmeshXDPAuthCompatSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshXDPAuthCompat returns the embedded CollectionSpec for KmeshXDPAuthCompat. @@ -97,6 +99,7 @@ type KmeshXDPAuthCompatMapSpecs struct { KmFrontend *ebpf.MapSpec `ebpf:"km_frontend"` KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` KmService *ebpf.MapSpec `ebpf:"km_service"` KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` KmTcargs *ebpf.MapSpec `ebpf:"km_tcargs"` @@ -146,6 +149,7 @@ type KmeshXDPAuthCompatMaps struct { KmFrontend *ebpf.Map `ebpf:"km_frontend"` KmLogEvent *ebpf.Map `ebpf:"km_log_event"` KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` KmService *ebpf.Map `ebpf:"km_service"` KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` KmTcargs *ebpf.Map `ebpf:"km_tcargs"` @@ -169,6 +173,7 @@ func (m *KmeshXDPAuthCompatMaps) Close() error { m.KmFrontend, m.KmLogEvent, m.KmManage, + m.KmOrigDst, m.KmService, m.KmSockstorage, m.KmTcargs, 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..9998624c2 --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsock_bpfeb.go @@ -0,0 +1,254 @@ +// 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 KmeshCgroupSockBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + +type KmeshCgroupSockBuf struct{ Data [40]int8 } + +type KmeshCgroupSockClusterSockData struct{ ClusterId uint32 } + +type KmeshCgroupSockManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshCgroupSockOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshCgroupSockSockStorageData struct { + ConnectNs uint64 + Direction uint8 + ConnectSuccess uint8 + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 +} + +// 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"` + 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"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` + KmRouterconfig *ebpf.MapSpec `ebpf:"km_routerconfig"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` +} + +// 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"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` +} + +// 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"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` + KmRouterconfig *ebpf.Map `ebpf:"km_routerconfig"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` +} + +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.KmOrigDst, + m.KmRouterconfig, + m.KmSockstorage, + m.KmTailcallCtx, + m.KmTcpProbe, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, + ) +} + +// 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"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` +} + +// 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..613089af9 --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsock_bpfel.go @@ -0,0 +1,254 @@ +// 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 KmeshCgroupSockBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + +type KmeshCgroupSockBuf struct{ Data [40]int8 } + +type KmeshCgroupSockClusterSockData struct{ ClusterId uint32 } + +type KmeshCgroupSockManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshCgroupSockOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshCgroupSockSockStorageData struct { + ConnectNs uint64 + Direction uint8 + ConnectSuccess uint8 + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 +} + +// 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"` + 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"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` + KmRouterconfig *ebpf.MapSpec `ebpf:"km_routerconfig"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` +} + +// 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"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` +} + +// 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"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` + KmRouterconfig *ebpf.Map `ebpf:"km_routerconfig"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` +} + +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.KmOrigDst, + m.KmRouterconfig, + m.KmSockstorage, + m.KmTailcallCtx, + m.KmTcpProbe, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, + ) +} + +// 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"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` +} + +// 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..e1e365524 --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsockcompat_bpfeb.go @@ -0,0 +1,254 @@ +// 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 KmeshCgroupSockCompatBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + +type KmeshCgroupSockCompatBuf struct{ Data [40]int8 } + +type KmeshCgroupSockCompatClusterSockData struct{ ClusterId uint32 } + +type KmeshCgroupSockCompatManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockCompatOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshCgroupSockCompatOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshCgroupSockCompatSockStorageData struct { + ConnectNs uint64 + Direction uint8 + ConnectSuccess uint8 + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 +} + +// 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"` + 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"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` + KmRouterconfig *ebpf.MapSpec `ebpf:"km_routerconfig"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` +} + +// 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"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` +} + +// 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"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` + KmRouterconfig *ebpf.Map `ebpf:"km_routerconfig"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` +} + +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.KmOrigDst, + m.KmRouterconfig, + m.KmSockstorage, + m.KmTailcallCtx, + m.KmTcpProbe, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, + ) +} + +// 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"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` +} + +// 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..330d4bf3b --- /dev/null +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsockcompat_bpfel.go @@ -0,0 +1,254 @@ +// 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 KmeshCgroupSockCompatBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + +type KmeshCgroupSockCompatBuf struct{ Data [40]int8 } + +type KmeshCgroupSockCompatClusterSockData struct{ ClusterId uint32 } + +type KmeshCgroupSockCompatManagerKey struct { + NetnsCookie uint64 + _ [8]byte +} + +type KmeshCgroupSockCompatOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshCgroupSockCompatOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshCgroupSockCompatSockStorageData struct { + ConnectNs uint64 + Direction uint8 + ConnectSuccess uint8 + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 +} + +// 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"` + 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"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` + KmRouterconfig *ebpf.MapSpec `ebpf:"km_routerconfig"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` +} + +// 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"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` +} + +// 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"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` + KmRouterconfig *ebpf.Map `ebpf:"km_routerconfig"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` +} + +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.KmOrigDst, + m.KmRouterconfig, + m.KmSockstorage, + m.KmTailcallCtx, + m.KmTcpProbe, + m.KmTmpbuf, + m.KmeshMap1600, + m.KmeshMap192, + m.KmeshMap296, + m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, + ) +} + +// 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"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` +} + +// 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..0e5929b78 100644 --- a/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockops_bpfeb.go +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockops_bpfeb.go @@ -12,28 +12,46 @@ import ( "github.com/cilium/ebpf" ) +type KmeshSockopsBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + type KmeshSockopsBuf struct{ Data [40]int8 } type KmeshSockopsClusterSockData struct{ ClusterId uint32 } -type KmeshSockopsKmeshConfig struct { - BpfLogLevel uint32 - NodeIp [4]uint32 - PodGateway [4]uint32 - AuthzOffload uint32 - EnableMonitoring uint32 -} - type KmeshSockopsManagerKey struct { NetnsCookie uint64 _ [8]byte } +type KmeshSockopsOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshSockopsOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + type KmeshSockopsSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshSockops returns the embedded CollectionSpec for KmeshSockops. @@ -71,42 +89,42 @@ 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"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` +} + +// 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"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` } // KmeshSockopsObjects contains all objects after they have been loaded into the kernel. @@ -115,6 +133,7 @@ type KmeshSockopsMapSpecs struct { type KmeshSockopsObjects struct { KmeshSockopsPrograms KmeshSockopsMaps + KmeshSockopsVariables } func (o *KmeshSockopsObjects) Close() error { @@ -128,68 +147,58 @@ 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"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` } 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.KmOrigDst, m.KmSockstorage, - m.KmTailcallCtx, + m.KmTcpProbe, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, m.KmeshMap296, m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, ) } +// 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"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` +} + // 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..7d60c48da 100644 --- a/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockops_bpfel.go +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockops_bpfel.go @@ -12,28 +12,46 @@ import ( "github.com/cilium/ebpf" ) +type KmeshSockopsBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + type KmeshSockopsBuf struct{ Data [40]int8 } type KmeshSockopsClusterSockData struct{ ClusterId uint32 } -type KmeshSockopsKmeshConfig struct { - BpfLogLevel uint32 - NodeIp [4]uint32 - PodGateway [4]uint32 - AuthzOffload uint32 - EnableMonitoring uint32 -} - type KmeshSockopsManagerKey struct { NetnsCookie uint64 _ [8]byte } +type KmeshSockopsOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshSockopsOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + type KmeshSockopsSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshSockops returns the embedded CollectionSpec for KmeshSockops. @@ -71,42 +89,42 @@ 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"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` +} + +// 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"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` } // KmeshSockopsObjects contains all objects after they have been loaded into the kernel. @@ -115,6 +133,7 @@ type KmeshSockopsMapSpecs struct { type KmeshSockopsObjects struct { KmeshSockopsPrograms KmeshSockopsMaps + KmeshSockopsVariables } func (o *KmeshSockopsObjects) Close() error { @@ -128,68 +147,58 @@ 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"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` } 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.KmOrigDst, m.KmSockstorage, - m.KmTailcallCtx, + m.KmTcpProbe, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, m.KmeshMap296, m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, ) } +// 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"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` +} + // 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..d95b4d1bd 100644 --- a/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockopscompat_bpfeb.go +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockopscompat_bpfeb.go @@ -12,28 +12,46 @@ import ( "github.com/cilium/ebpf" ) +type KmeshSockopsCompatBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + type KmeshSockopsCompatBuf struct{ Data [40]int8 } type KmeshSockopsCompatClusterSockData struct{ ClusterId uint32 } -type KmeshSockopsCompatKmeshConfig struct { - BpfLogLevel uint32 - NodeIp [4]uint32 - PodGateway [4]uint32 - AuthzOffload uint32 - EnableMonitoring uint32 -} - type KmeshSockopsCompatManagerKey struct { NetnsCookie uint64 _ [8]byte } +type KmeshSockopsCompatOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshSockopsCompatOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + type KmeshSockopsCompatSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshSockopsCompat returns the embedded CollectionSpec for KmeshSockopsCompat. @@ -71,42 +89,42 @@ 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"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` +} + +// 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"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` } // KmeshSockopsCompatObjects contains all objects after they have been loaded into the kernel. @@ -115,6 +133,7 @@ type KmeshSockopsCompatMapSpecs struct { type KmeshSockopsCompatObjects struct { KmeshSockopsCompatPrograms KmeshSockopsCompatMaps + KmeshSockopsCompatVariables } func (o *KmeshSockopsCompatObjects) Close() error { @@ -128,68 +147,58 @@ 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"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` } 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.KmOrigDst, m.KmSockstorage, - m.KmTailcallCtx, + m.KmTcpProbe, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, m.KmeshMap296, m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, ) } +// 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"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` +} + // 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..b102d27e6 100644 --- a/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockopscompat_bpfel.go +++ b/bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshsockopscompat_bpfel.go @@ -12,28 +12,46 @@ import ( "github.com/cilium/ebpf" ) +type KmeshSockopsCompatBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + type KmeshSockopsCompatBuf struct{ Data [40]int8 } type KmeshSockopsCompatClusterSockData struct{ ClusterId uint32 } -type KmeshSockopsCompatKmeshConfig struct { - BpfLogLevel uint32 - NodeIp [4]uint32 - PodGateway [4]uint32 - AuthzOffload uint32 - EnableMonitoring uint32 -} - type KmeshSockopsCompatManagerKey struct { NetnsCookie uint64 _ [8]byte } +type KmeshSockopsCompatOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshSockopsCompatOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + type KmeshSockopsCompatSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshSockopsCompat returns the embedded CollectionSpec for KmeshSockopsCompat. @@ -71,42 +89,42 @@ 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"` + KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` + KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` + KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` +} + +// 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"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` } // KmeshSockopsCompatObjects contains all objects after they have been loaded into the kernel. @@ -115,6 +133,7 @@ type KmeshSockopsCompatMapSpecs struct { type KmeshSockopsCompatObjects struct { KmeshSockopsCompatPrograms KmeshSockopsCompatMaps + KmeshSockopsCompatVariables } func (o *KmeshSockopsCompatObjects) Close() error { @@ -128,68 +147,58 @@ 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"` + KmLogEvent *ebpf.Map `ebpf:"km_log_event"` + KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` + KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` + 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` } 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.KmOrigDst, m.KmSockstorage, - m.KmTailcallCtx, + m.KmTcpProbe, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, m.KmeshMap296, m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, ) } +// 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"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` +} + // 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/normal/kmeshcgroupsock_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsock_bpfeb.go index 663d99c94..fb43e6bb8 100644 --- a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsock_bpfeb.go +++ b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsock_bpfeb.go @@ -12,6 +12,16 @@ import ( "github.com/cilium/ebpf" ) +type KmeshCgroupSockBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + type KmeshCgroupSockBuf struct{ Data [40]int8 } type KmeshCgroupSockClusterSockData struct{ ClusterId uint32 } @@ -21,6 +31,20 @@ type KmeshCgroupSockManagerKey struct { _ [8]byte } +type KmeshCgroupSockOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshCgroupSockOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + type KmeshCgroupSockRatelimitKey struct { Key struct { SkSkb struct { @@ -42,7 +66,9 @@ type KmeshCgroupSockSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshCgroupSock returns the embedded CollectionSpec for KmeshCgroupSock. @@ -107,21 +133,26 @@ type KmeshCgroupSockMapSpecs struct { KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` } // 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"` + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` } // KmeshCgroupSockObjects contains all objects after they have been loaded into the kernel. @@ -154,14 +185,18 @@ type KmeshCgroupSockMaps struct { KmLogEvent *ebpf.Map `ebpf:"km_log_event"` KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` } func (m *KmeshCgroupSockMaps) Close() error { @@ -176,14 +211,18 @@ func (m *KmeshCgroupSockMaps) Close() error { m.KmLogEvent, m.KmMaglevOuter, m.KmManage, + m.KmOrigDst, m.KmRatelimit, m.KmSockstorage, m.KmTailcallCtx, + m.KmTcpProbe, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, m.KmeshMap296, m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, ) } @@ -191,7 +230,8 @@ func (m *KmeshCgroupSockMaps) Close() error { // // It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshCgroupSockVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` } // KmeshCgroupSockPrograms contains all programs after they have been loaded into the kernel. diff --git a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsock_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsock_bpfel.go index 8f81872ab..2cd6adc79 100644 --- a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsock_bpfel.go +++ b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsock_bpfel.go @@ -12,6 +12,16 @@ import ( "github.com/cilium/ebpf" ) +type KmeshCgroupSockBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + type KmeshCgroupSockBuf struct{ Data [40]int8 } type KmeshCgroupSockClusterSockData struct{ ClusterId uint32 } @@ -21,6 +31,20 @@ type KmeshCgroupSockManagerKey struct { _ [8]byte } +type KmeshCgroupSockOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshCgroupSockOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + type KmeshCgroupSockRatelimitKey struct { Key struct { SkSkb struct { @@ -42,7 +66,9 @@ type KmeshCgroupSockSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshCgroupSock returns the embedded CollectionSpec for KmeshCgroupSock. @@ -107,21 +133,26 @@ type KmeshCgroupSockMapSpecs struct { KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` } // 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"` + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` } // KmeshCgroupSockObjects contains all objects after they have been loaded into the kernel. @@ -154,14 +185,18 @@ type KmeshCgroupSockMaps struct { KmLogEvent *ebpf.Map `ebpf:"km_log_event"` KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` } func (m *KmeshCgroupSockMaps) Close() error { @@ -176,14 +211,18 @@ func (m *KmeshCgroupSockMaps) Close() error { m.KmLogEvent, m.KmMaglevOuter, m.KmManage, + m.KmOrigDst, m.KmRatelimit, m.KmSockstorage, m.KmTailcallCtx, + m.KmTcpProbe, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, m.KmeshMap296, m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, ) } @@ -191,7 +230,8 @@ func (m *KmeshCgroupSockMaps) Close() error { // // It can be passed to LoadKmeshCgroupSockObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshCgroupSockVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` } // KmeshCgroupSockPrograms contains all programs after they have been loaded into the kernel. diff --git a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsockcompat_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsockcompat_bpfeb.go index 9b96b5422..50f8c90b0 100644 --- a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsockcompat_bpfeb.go +++ b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsockcompat_bpfeb.go @@ -12,6 +12,16 @@ import ( "github.com/cilium/ebpf" ) +type KmeshCgroupSockCompatBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + type KmeshCgroupSockCompatBuf struct{ Data [40]int8 } type KmeshCgroupSockCompatClusterSockData struct{ ClusterId uint32 } @@ -21,6 +31,20 @@ type KmeshCgroupSockCompatManagerKey struct { _ [8]byte } +type KmeshCgroupSockCompatOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshCgroupSockCompatOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + type KmeshCgroupSockCompatRatelimitKey struct { Key struct { SkSkb struct { @@ -42,7 +66,9 @@ type KmeshCgroupSockCompatSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshCgroupSockCompat returns the embedded CollectionSpec for KmeshCgroupSockCompat. @@ -107,21 +133,26 @@ type KmeshCgroupSockCompatMapSpecs struct { KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` } // 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"` + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` } // KmeshCgroupSockCompatObjects contains all objects after they have been loaded into the kernel. @@ -154,14 +185,18 @@ type KmeshCgroupSockCompatMaps struct { KmLogEvent *ebpf.Map `ebpf:"km_log_event"` KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` } func (m *KmeshCgroupSockCompatMaps) Close() error { @@ -176,14 +211,18 @@ func (m *KmeshCgroupSockCompatMaps) Close() error { m.KmLogEvent, m.KmMaglevOuter, m.KmManage, + m.KmOrigDst, m.KmRatelimit, m.KmSockstorage, m.KmTailcallCtx, + m.KmTcpProbe, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, m.KmeshMap296, m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, ) } @@ -191,7 +230,8 @@ func (m *KmeshCgroupSockCompatMaps) Close() error { // // It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshCgroupSockCompatVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` } // KmeshCgroupSockCompatPrograms contains all programs after they have been loaded into the kernel. diff --git a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsockcompat_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsockcompat_bpfel.go index 5b52df92a..f103cd943 100644 --- a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsockcompat_bpfel.go +++ b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshcgroupsockcompat_bpfel.go @@ -12,6 +12,16 @@ import ( "github.com/cilium/ebpf" ) +type KmeshCgroupSockCompatBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + type KmeshCgroupSockCompatBuf struct{ Data [40]int8 } type KmeshCgroupSockCompatClusterSockData struct{ ClusterId uint32 } @@ -21,6 +31,20 @@ type KmeshCgroupSockCompatManagerKey struct { _ [8]byte } +type KmeshCgroupSockCompatOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshCgroupSockCompatOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + type KmeshCgroupSockCompatRatelimitKey struct { Key struct { SkSkb struct { @@ -42,7 +66,9 @@ type KmeshCgroupSockCompatSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshCgroupSockCompat returns the embedded CollectionSpec for KmeshCgroupSockCompat. @@ -107,21 +133,26 @@ type KmeshCgroupSockCompatMapSpecs struct { KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` KmMaglevOuter *ebpf.MapSpec `ebpf:"km_maglev_outer"` KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` KmRatelimit *ebpf.MapSpec `ebpf:"km_ratelimit"` KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` KmTailcallCtx *ebpf.MapSpec `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` } // 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"` + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` } // KmeshCgroupSockCompatObjects contains all objects after they have been loaded into the kernel. @@ -154,14 +185,18 @@ type KmeshCgroupSockCompatMaps struct { KmLogEvent *ebpf.Map `ebpf:"km_log_event"` KmMaglevOuter *ebpf.Map `ebpf:"km_maglev_outer"` KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` KmRatelimit *ebpf.Map `ebpf:"km_ratelimit"` KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` KmTailcallCtx *ebpf.Map `ebpf:"km_tailcall_ctx"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` } func (m *KmeshCgroupSockCompatMaps) Close() error { @@ -176,14 +211,18 @@ func (m *KmeshCgroupSockCompatMaps) Close() error { m.KmLogEvent, m.KmMaglevOuter, m.KmManage, + m.KmOrigDst, m.KmRatelimit, m.KmSockstorage, m.KmTailcallCtx, + m.KmTcpProbe, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, m.KmeshMap296, m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, ) } @@ -191,7 +230,8 @@ func (m *KmeshCgroupSockCompatMaps) Close() error { // // It can be passed to LoadKmeshCgroupSockCompatObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshCgroupSockCompatVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` } // KmeshCgroupSockCompatPrograms contains all programs after they have been loaded into the kernel. diff --git a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockops_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockops_bpfeb.go index 523ecac8c..5d1eae936 100644 --- a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockops_bpfeb.go +++ b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockops_bpfeb.go @@ -12,6 +12,16 @@ import ( "github.com/cilium/ebpf" ) +type KmeshSockopsBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + type KmeshSockopsBuf struct{ Data [40]int8 } type KmeshSockopsClusterSockData struct{ ClusterId uint32 } @@ -21,11 +31,27 @@ type KmeshSockopsManagerKey struct { _ [8]byte } +type KmeshSockopsOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshSockopsOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + type KmeshSockopsSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshSockops returns the embedded CollectionSpec for KmeshSockops. @@ -81,19 +107,24 @@ type KmeshSockopsMapSpecs struct { KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` } // 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"` + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` } // KmeshSockopsObjects contains all objects after they have been loaded into the kernel. @@ -120,12 +151,16 @@ type KmeshSockopsMaps struct { KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` KmLogEvent *ebpf.Map `ebpf:"km_log_event"` KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` } func (m *KmeshSockopsMaps) Close() error { @@ -134,12 +169,16 @@ func (m *KmeshSockopsMaps) Close() error { m.KmClusterstats, m.KmLogEvent, m.KmManage, + m.KmOrigDst, m.KmSockstorage, + m.KmTcpProbe, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, m.KmeshMap296, m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, ) } @@ -147,7 +186,8 @@ func (m *KmeshSockopsMaps) Close() error { // // It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSockopsVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` } // KmeshSockopsPrograms contains all programs after they have been loaded into the kernel. diff --git a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockops_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockops_bpfel.go index 61b22b6ee..8ee7e7454 100644 --- a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockops_bpfel.go +++ b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockops_bpfel.go @@ -12,6 +12,16 @@ import ( "github.com/cilium/ebpf" ) +type KmeshSockopsBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + type KmeshSockopsBuf struct{ Data [40]int8 } type KmeshSockopsClusterSockData struct{ ClusterId uint32 } @@ -21,11 +31,27 @@ type KmeshSockopsManagerKey struct { _ [8]byte } +type KmeshSockopsOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshSockopsOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + type KmeshSockopsSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshSockops returns the embedded CollectionSpec for KmeshSockops. @@ -81,19 +107,24 @@ type KmeshSockopsMapSpecs struct { KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` } // 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"` + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` } // KmeshSockopsObjects contains all objects after they have been loaded into the kernel. @@ -120,12 +151,16 @@ type KmeshSockopsMaps struct { KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` KmLogEvent *ebpf.Map `ebpf:"km_log_event"` KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` } func (m *KmeshSockopsMaps) Close() error { @@ -134,12 +169,16 @@ func (m *KmeshSockopsMaps) Close() error { m.KmClusterstats, m.KmLogEvent, m.KmManage, + m.KmOrigDst, m.KmSockstorage, + m.KmTcpProbe, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, m.KmeshMap296, m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, ) } @@ -147,7 +186,8 @@ func (m *KmeshSockopsMaps) Close() error { // // It can be passed to LoadKmeshSockopsObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSockopsVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` } // KmeshSockopsPrograms contains all programs after they have been loaded into the kernel. diff --git a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockopscompat_bpfeb.go b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockopscompat_bpfeb.go index 08981a5ed..ac446dfee 100644 --- a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockopscompat_bpfeb.go +++ b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockopscompat_bpfeb.go @@ -12,6 +12,16 @@ import ( "github.com/cilium/ebpf" ) +type KmeshSockopsCompatBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + type KmeshSockopsCompatBuf struct{ Data [40]int8 } type KmeshSockopsCompatClusterSockData struct{ ClusterId uint32 } @@ -21,11 +31,27 @@ type KmeshSockopsCompatManagerKey struct { _ [8]byte } +type KmeshSockopsCompatOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshSockopsCompatOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + type KmeshSockopsCompatSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshSockopsCompat returns the embedded CollectionSpec for KmeshSockopsCompat. @@ -81,19 +107,24 @@ type KmeshSockopsCompatMapSpecs struct { KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` } // 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"` + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` } // KmeshSockopsCompatObjects contains all objects after they have been loaded into the kernel. @@ -120,12 +151,16 @@ type KmeshSockopsCompatMaps struct { KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` KmLogEvent *ebpf.Map `ebpf:"km_log_event"` KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` } func (m *KmeshSockopsCompatMaps) Close() error { @@ -134,12 +169,16 @@ func (m *KmeshSockopsCompatMaps) Close() error { m.KmClusterstats, m.KmLogEvent, m.KmManage, + m.KmOrigDst, m.KmSockstorage, + m.KmTcpProbe, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, m.KmeshMap296, m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, ) } @@ -147,7 +186,8 @@ func (m *KmeshSockopsCompatMaps) Close() error { // // It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSockopsCompatVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` } // KmeshSockopsCompatPrograms contains all programs after they have been loaded into the kernel. diff --git a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockopscompat_bpfel.go b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockopscompat_bpfel.go index 1acbb6d5c..4de078212 100644 --- a/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockopscompat_bpfel.go +++ b/bpf/kmesh/bpf2go/kernelnative/normal/kmeshsockopscompat_bpfel.go @@ -12,6 +12,16 @@ import ( "github.com/cilium/ebpf" ) +type KmeshSockopsCompatBpfSockTuple struct { + Ipv4 struct { + Saddr uint32 + Daddr uint32 + Sport uint16 + Dport uint16 + } + _ [24]byte +} + type KmeshSockopsCompatBuf struct{ Data [40]int8 } type KmeshSockopsCompatClusterSockData struct{ ClusterId uint32 } @@ -21,11 +31,27 @@ type KmeshSockopsCompatManagerKey struct { _ [8]byte } +type KmeshSockopsCompatOperationUsageData struct { + StartTime uint64 + EndTime uint64 + PidTgid uint64 + OperationType uint32 + _ [4]byte +} + +type KmeshSockopsCompatOperationUsageKey struct { + SocketCookie uint64 + OperationType uint32 + _ [4]byte +} + type KmeshSockopsCompatSockStorageData struct { ConnectNs uint64 Direction uint8 ConnectSuccess uint8 - _ [6]byte + _ [2]byte + PidTgid uint32 + DstSvcName [192]int8 } // LoadKmeshSockopsCompat returns the embedded CollectionSpec for KmeshSockopsCompat. @@ -81,19 +107,24 @@ type KmeshSockopsCompatMapSpecs struct { KmClusterstats *ebpf.MapSpec `ebpf:"km_clusterstats"` KmLogEvent *ebpf.MapSpec `ebpf:"km_log_event"` KmManage *ebpf.MapSpec `ebpf:"km_manage"` + KmOrigDst *ebpf.MapSpec `ebpf:"km_orig_dst"` KmSockstorage *ebpf.MapSpec `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.MapSpec `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.MapSpec `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.MapSpec `ebpf:"kmesh_perf_map"` } // 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"` + BpfLogLevel *ebpf.VariableSpec `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.VariableSpec `ebpf:"enable_monitoring"` } // KmeshSockopsCompatObjects contains all objects after they have been loaded into the kernel. @@ -120,12 +151,16 @@ type KmeshSockopsCompatMaps struct { KmClusterstats *ebpf.Map `ebpf:"km_clusterstats"` KmLogEvent *ebpf.Map `ebpf:"km_log_event"` KmManage *ebpf.Map `ebpf:"km_manage"` + KmOrigDst *ebpf.Map `ebpf:"km_orig_dst"` KmSockstorage *ebpf.Map `ebpf:"km_sockstorage"` + KmTcpProbe *ebpf.Map `ebpf:"km_tcp_probe"` 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"` + KmeshPerfInfo *ebpf.Map `ebpf:"kmesh_perf_info"` + KmeshPerfMap *ebpf.Map `ebpf:"kmesh_perf_map"` } func (m *KmeshSockopsCompatMaps) Close() error { @@ -134,12 +169,16 @@ func (m *KmeshSockopsCompatMaps) Close() error { m.KmClusterstats, m.KmLogEvent, m.KmManage, + m.KmOrigDst, m.KmSockstorage, + m.KmTcpProbe, m.KmTmpbuf, m.KmeshMap1600, m.KmeshMap192, m.KmeshMap296, m.KmeshMap64, + m.KmeshPerfInfo, + m.KmeshPerfMap, ) } @@ -147,7 +186,8 @@ func (m *KmeshSockopsCompatMaps) Close() error { // // It can be passed to LoadKmeshSockopsCompatObjects or ebpf.CollectionSpec.LoadAndAssign. type KmeshSockopsCompatVariables struct { - BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + BpfLogLevel *ebpf.Variable `ebpf:"bpf_log_level"` + EnableMonitoring *ebpf.Variable `ebpf:"enable_monitoring"` } // KmeshSockopsCompatPrograms contains all programs after they have been loaded into the kernel. diff --git a/bpf/kmesh/probes/probe.h b/bpf/kmesh/probes/probe.h index 1b1c46ec6..7d57126a2 100644 --- a/bpf/kmesh/probes/probe.h +++ b/bpf/kmesh/probes/probe.h @@ -30,6 +30,21 @@ static inline void observe_on_pre_connect(struct bpf_sock *sk) return; } +static inline void observe_on_connect(struct bpf_sock *sk, const char *dst_svc_name) +{ + struct sock_storage_data *storage = NULL; + if (!sk) + return; + + storage = bpf_sk_storage_get(&map_of_sock_storage, sk, 0, BPF_LOCAL_STORAGE_GET_F_CREATE); + if (!storage) { + BPF_LOG(ERR, PROBE, "pre_connect bpf_sk_storage_get failed\n"); + return; + } + bpf_strncpy(storage->dst_svc_name, sizeof(storage->dst_svc_name), dst_svc_name); + return; +} + static inline void observe_on_connect_established(struct bpf_sock *sk, __u8 direction) { if (!is_monitoring_enable()) { @@ -66,6 +81,7 @@ static inline void observe_on_close(struct bpf_sock *sk) if (!is_monitoring_enable()) { return; } + struct bpf_tcp_sock *tcp_sock = NULL; struct sock_storage_data *storage = NULL; if (!sk) diff --git a/bpf/kmesh/probes/tcp_probe.h b/bpf/kmesh/probes/tcp_probe.h index 831604f02..dc3e0745a 100644 --- a/bpf/kmesh/probes/tcp_probe.h +++ b/bpf/kmesh/probes/tcp_probe.h @@ -47,6 +47,7 @@ struct tcp_probe_info { __u32 rtt_min; __u32 total_retrans; /* Total retransmits for entire connection */ __u32 lost_out; /* Lost packets */ + char dst_svc_name[BPF_DATA_MAX_LEN]; }; struct { @@ -138,7 +139,6 @@ tcp_report(struct bpf_sock *sk, struct bpf_tcp_sock *tcp_sock, struct sock_stora { // struct connect_info *info = NULL; struct tcp_probe_info *info = NULL; - // store tuple info = bpf_ringbuf_reserve(&map_of_tcp_probe, sizeof(struct tcp_probe_info), 0); if (!info) { @@ -154,6 +154,7 @@ tcp_report(struct bpf_sock *sk, struct bpf_tcp_sock *tcp_sock, struct sock_stora info->duration = info->close_ns - storage->connect_ns; } info->conn_success = storage->connect_success; + bpf_strncpy(info->dst_svc_name, sizeof(info->dst_svc_name), storage->dst_svc_name); get_tcp_probe_info(tcp_sock, info); (*info).type = (sk->family == AF_INET) ? IPV4 : IPV6; if (is_ipv4_mapped_addr(sk->dst_ip6)) { diff --git a/bpf/kmesh/workload/include/backend.h b/bpf/kmesh/workload/include/backend.h index 2c22b8f21..7d3759c2d 100644 --- a/bpf/kmesh/workload/include/backend.h +++ b/bpf/kmesh/workload/include/backend.h @@ -5,7 +5,6 @@ #define __ROUTE_BACKEND_H__ #include "workload_common.h" -#include "encoder.h" #include "tail_call.h" static inline backend_value *map_lookup_backend(const backend_key *key) diff --git a/bpf/kmesh/workload/include/encoder.h b/bpf/kmesh/workload/include/encoder.h deleted file mode 100644 index 3c3481fd6..000000000 --- a/bpf/kmesh/workload/include/encoder.h +++ /dev/null @@ -1,18 +0,0 @@ -/* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ -/* Copyright Authors of Kmesh */ - -#ifndef __ENCODER_H__ -#define __ENCODER_H__ - -#include "config.h" -#include "common.h" - -struct { - __uint(type, BPF_MAP_TYPE_HASH); - __type(key, __u64); - __type(value, struct bpf_sock_tuple); - __uint(max_entries, MAP_SIZE_OF_DSTINFO); - __uint(map_flags, BPF_F_NO_PREALLOC); -} map_of_orig_dst SEC(".maps"); - -#endif /*__ENCODER_H__*/ \ No newline at end of file diff --git a/bpf/kmesh/workload/include/workload.h b/bpf/kmesh/workload/include/workload.h index 28e1ea64b..ca857f883 100644 --- a/bpf/kmesh/workload/include/workload.h +++ b/bpf/kmesh/workload/include/workload.h @@ -9,7 +9,6 @@ #define MAX_PORT_COUNT 10 #define MAX_SERVICE_COUNT 10 -#define RINGBUF_SIZE (1 << 12) #define PRIO_COUNT 7 #define MAX_MEMBER_NUM_PER_POLICY 4 diff --git a/bpf/kmesh/workload/sendmsg.c b/bpf/kmesh/workload/sendmsg.c index edaab9bf9..577b626fb 100644 --- a/bpf/kmesh/workload/sendmsg.c +++ b/bpf/kmesh/workload/sendmsg.c @@ -6,7 +6,7 @@ #include #include #include "bpf_log.h" -#include "encoder.h" +#include "bpf_common.h" /* * sk msg is used to encode metadata into the payload when the client sends diff --git a/bpf/kmesh/workload/sockops.c b/bpf/kmesh/workload/sockops.c index 2745c394e..e816d3e40 100644 --- a/bpf/kmesh/workload/sockops.c +++ b/bpf/kmesh/workload/sockops.c @@ -9,10 +9,8 @@ #include "bpf_log.h" #include "workload.h" #include "config.h" -#include "encoder.h" #include "bpf_common.h" #include "probe.h" -#include "config.h" #define FORMAT_IP_LENGTH (16) diff --git a/pkg/bpf/ads/loader.go b/pkg/bpf/ads/loader.go index 170ac7ab5..194d1e491 100644 --- a/pkg/bpf/ads/loader.go +++ b/pkg/bpf/ads/loader.go @@ -134,7 +134,8 @@ func (sc *BpfAds) Start() error { func (sc *BpfAds) GetBpfConfigVariable() factory.KmeshBpfConfig { return factory.KmeshBpfConfig{ - BpfLogLevel: sc.SockConn.BpfLogLevel, + BpfLogLevel: sc.SockConn.BpfLogLevel, + EnableMonitoring: sc.SockOps.EnableMonitoring, } } diff --git a/pkg/bpf/ads/loader_enhanced.go b/pkg/bpf/ads/loader_enhanced.go index 207da379b..d29fc99f4 100644 --- a/pkg/bpf/ads/loader_enhanced.go +++ b/pkg/bpf/ads/loader_enhanced.go @@ -31,6 +31,7 @@ import ( bpf2go "kmesh.net/kmesh/bpf/kmesh/bpf2go/kernelnative/enhanced" "kmesh.net/kmesh/daemon/options" + "kmesh.net/kmesh/pkg/bpf/factory" "kmesh.net/kmesh/pkg/bpf/general" "kmesh.net/kmesh/pkg/bpf/utils" "kmesh.net/kmesh/pkg/logger" @@ -126,6 +127,13 @@ func (sc *BpfAds) Start() error { return nil } +func (sc *BpfAds) GetBpfConfigVariable() factory.KmeshBpfConfig { + return factory.KmeshBpfConfig{ + BpfLogLevel: sc.SockConn.BpfLogLevel, + EnableMonitoring: sc.SockOps.EnableMonitoring, + } +} + func (sc *BpfAds) Stop() error { C.deserial_uninit() if err := sc.Detach(); err != nil { diff --git a/pkg/bpf/bpf.go b/pkg/bpf/bpf.go index 121f169b9..c38fb76a1 100644 --- a/pkg/bpf/bpf.go +++ b/pkg/bpf/bpf.go @@ -90,6 +90,7 @@ func (l *BpfLoader) Start() error { return err } l.KmeshBpfConfig = l.obj.GetBpfConfigVariable() + l.setAdsBpfProgOptions() } else if l.config.DualEngineEnabled() { if l.workloadObj, err = workload.NewBpfWorkload(l.config); err != nil { return err @@ -313,6 +314,16 @@ func (l *BpfLoader) setBpfProgOptions() { } } +func (l *BpfLoader) setAdsBpfProgOptions() { + + if restart.GetStartType() == restart.Normal { + if err := l.EnableMonitoring.Set(constants.ENABLED); err != nil { + log.Error("set EnableMonitoring failed ", err) + return + } + } +} + func getNodeIPAddress(node *corev1.Node) [16]byte { var nodeIPStr string nodeAddresses := node.Status.Addresses diff --git a/pkg/controller/ads/ads_controller.go b/pkg/controller/ads/ads_controller.go index c555b55a9..1786351e0 100644 --- a/pkg/controller/ads/ads_controller.go +++ b/pkg/controller/ads/ads_controller.go @@ -25,6 +25,7 @@ import ( "istio.io/istio/pkg/channels" bpfads "kmesh.net/kmesh/pkg/bpf/ads" + "kmesh.net/kmesh/pkg/controller/adstelemetry" "kmesh.net/kmesh/pkg/logger" ) @@ -33,9 +34,11 @@ var ( ) type Controller struct { - Processor *processor + Processor *processor dnsResolverController *dnsController - con *connection + con *connection + MetricController *adstelemetry.MetricController + bpfAdsObj *bpfads.BpfAds } type connection struct { @@ -44,7 +47,7 @@ type connection struct { stopCh chan struct{} } -func NewController(bpfAds *bpfads.BpfAds) *Controller { +func NewController(bpfAds *bpfads.BpfAds, enableMonitoring bool, managerCache map[string]string) *Controller { processor := newProcessor(bpfAds) // create kernel-native mode ads resolver controller dnsResolverController, err := NewDnsController(processor.Cache) @@ -54,10 +57,18 @@ func NewController(bpfAds *bpfads.BpfAds) *Controller { } processor.DnsResolverChan = dnsResolverController.clustersChan - return &Controller{ + c := &Controller{ dnsResolverController: dnsResolverController, Processor: processor, + bpfAdsObj: bpfAds, } + c.MetricController = adstelemetry.NewMetric(c.Processor.Cache, enableMonitoring, managerCache) + log.Printf("ads controller created:%v", enableMonitoring) + return c +} + +func (c *Controller) Run(ctx context.Context) { + go c.MetricController.Run(ctx, c.bpfAdsObj.SockConn.KmTcpProbe) } func (c *Controller) AdsStreamCreateAndSend(client service_discovery_v3.AggregatedDiscoveryServiceClient, ctx context.Context) error { diff --git a/pkg/controller/ads/ads_controller_test.go b/pkg/controller/ads/ads_controller_test.go index f6aa72775..f0b497fd3 100644 --- a/pkg/controller/ads/ads_controller_test.go +++ b/pkg/controller/ads/ads_controller_test.go @@ -117,7 +117,7 @@ func TestHandleAdsStream(t *testing.T) { } defer fakeClient.Cleanup() - adsStream := NewController(nil) + adsStream := NewController(nil, false, nil) adsStream.con = &connection{Stream: fakeClient.AdsClient, requestsChan: channels.NewUnbounded[*service_discovery_v3.DiscoveryRequest](), stopCh: make(chan struct{})} adsStream.dnsResolverController.Run(make(chan struct{})) patches1 := gomonkey.NewPatches() diff --git a/pkg/controller/ads/ads_processor.go b/pkg/controller/ads/ads_processor.go index 5892ab586..18d8e9b0f 100644 --- a/pkg/controller/ads/ads_processor.go +++ b/pkg/controller/ads/ads_processor.go @@ -34,6 +34,7 @@ import ( core_v2 "kmesh.net/kmesh/api/v2/core" bpfads "kmesh.net/kmesh/pkg/bpf/ads" "kmesh.net/kmesh/pkg/constants" + "kmesh.net/kmesh/pkg/controller/ads/cache" "kmesh.net/kmesh/pkg/controller/config" "kmesh.net/kmesh/pkg/utils/hash" ) @@ -49,7 +50,7 @@ type lastNonce struct { rdsNonce string } type processor struct { - Cache *AdsCache + Cache *cache.AdsCache ack *service_discovery_v3.DiscoveryRequest req *service_discovery_v3.DiscoveryRequest lastNonce *lastNonce @@ -59,7 +60,7 @@ type processor struct { func newProcessor(bpfAds *bpfads.BpfAds) *processor { return &processor{ - Cache: NewAdsCache(bpfAds), + Cache: cache.NewAdsCache(bpfAds), ack: nil, req: nil, lastNonce: &lastNonce{}, @@ -127,8 +128,8 @@ func (p *processor) processAdsResponse(resp *service_discovery_v3.DiscoveryRespo func (p *processor) handleCdsResponse(resp *service_discovery_v3.DiscoveryResponse) error { p.lastNonce.cdsNonce = resp.Nonce current := sets.New[string]() - lastEdsClusterNames := p.Cache.edsClusterNames - p.Cache.edsClusterNames = nil + lastEdsClusterNames := p.Cache.EdsClusterNames + p.Cache.EdsClusterNames = nil dnsClusters := []*config_cluster_v3.Cluster{} for _, resource := range resp.GetResources() { cluster := &config_cluster_v3.Cluster{} @@ -139,7 +140,7 @@ func (p *processor) handleCdsResponse(resp *service_discovery_v3.DiscoveryRespon current.Insert(cluster.GetName()) if cluster.GetType() == config_cluster_v3.Cluster_EDS { - p.Cache.edsClusterNames = append(p.Cache.edsClusterNames, cluster.GetName()) + p.Cache.EdsClusterNames = append(p.Cache.EdsClusterNames, cluster.GetName()) } else if cluster.GetType() == config_cluster_v3.Cluster_STRICT_DNS || cluster.GetType() == config_cluster_v3.Cluster_LOGICAL_DNS { dnsClusters = append(dnsClusters, cluster) @@ -186,11 +187,11 @@ func (p *processor) handleCdsResponse(resp *service_discovery_v3.DiscoveryRespon p.Cache.ClusterCache.Flush() // when the list of eds typed clusters subscribed changed, we should resubscrbe to new eds. - if !slices.EqualUnordered(p.Cache.edsClusterNames, lastEdsClusterNames) { + if !slices.EqualUnordered(p.Cache.EdsClusterNames, lastEdsClusterNames) { // we cannot set the nonce here. // There is a race: when xds server has pushed eds, but kmesh hasn't a chance to receive and process // Then it will lead to this request been ignored, we will lose the new eds resource - p.req = newAdsRequest(resource_v3.EndpointType, p.Cache.edsClusterNames, "") + p.req = newAdsRequest(resource_v3.EndpointType, p.Cache.EdsClusterNames, "") } return nil @@ -226,7 +227,7 @@ func (p *processor) handleEdsResponse(resp *service_discovery_v3.DiscoveryRespon // EDS ack should contain all the eds cluster names, and since istiod can send partial eds to us, we use those set by handleCdsResponse // Ad xds protocol spec, the non wildcard resource ack should contain all the names - p.ack.ResourceNames = p.Cache.edsClusterNames + p.ack.ResourceNames = p.Cache.EdsClusterNames if p.lastNonce.ldsNonce == "" { // subscribe to lds only once per stream @@ -246,8 +247,8 @@ func (p *processor) handleLdsResponse(resp *service_discovery_v3.DiscoveryRespon p.lastNonce.ldsNonce = resp.Nonce current := sets.New[string]() - lastRouteNames := p.Cache.routeNames - p.Cache.routeNames = []string{} + lastRouteNames := p.Cache.RouteNames + p.Cache.RouteNames = []string{} for _, resource := range resp.GetResources() { if err = anypb.UnmarshalTo(resource, listener, proto.UnmarshalOptions{}); err != nil { continue @@ -276,11 +277,11 @@ func (p *processor) handleLdsResponse(resp *service_discovery_v3.DiscoveryRespon p.Cache.ListenerCache.Flush() - if !slices.EqualUnordered(p.Cache.routeNames, lastRouteNames) { + if !slices.EqualUnordered(p.Cache.RouteNames, lastRouteNames) { // we cannot set the nonce here. // There is a race: when xds server has pushed rds, but kmesh hasn't a chance to receive and process // Then it will lead to this request been ignored, we will lose the new rds resource - p.req = newAdsRequest(resource_v3.RouteType, p.Cache.routeNames, "") + p.req = newAdsRequest(resource_v3.RouteType, p.Cache.RouteNames, "") } return err } @@ -323,8 +324,8 @@ func (p *processor) Reset() { return } p.lastNonce = &lastNonce{} - p.Cache.routeNames = nil - p.Cache.edsClusterNames = nil + p.Cache.RouteNames = nil + p.Cache.EdsClusterNames = nil } func ConfigResourcesIsEmpty(resources *admin_v2.ConfigResources) bool { diff --git a/pkg/controller/ads/ads_processor_test.go b/pkg/controller/ads/ads_processor_test.go index 278e0dbc5..93941a910 100644 --- a/pkg/controller/ads/ads_processor_test.go +++ b/pkg/controller/ads/ads_processor_test.go @@ -36,6 +36,7 @@ import ( "kmesh.net/kmesh/daemon/options" cache_v2 "kmesh.net/kmesh/pkg/cache/v2" "kmesh.net/kmesh/pkg/constants" + "kmesh.net/kmesh/pkg/controller/ads/cache" "kmesh.net/kmesh/pkg/utils" "kmesh.net/kmesh/pkg/utils/hash" "kmesh.net/kmesh/pkg/utils/test" @@ -68,7 +69,7 @@ func TestHandleCdsResponse(t *testing.T) { } err = p.handleCdsResponse(rsp) assert.NoError(t, err) - assert.Equal(t, []string{"ut-cluster"}, p.Cache.edsClusterNames) + assert.Equal(t, []string{"ut-cluster"}, p.Cache.EdsClusterNames) wantHash := hash.Sum64String(anyCluster.String()) actualHash := p.Cache.ClusterCache.GetCdsHash(cluster.GetName()) assert.Equal(t, wantHash, actualHash) @@ -98,7 +99,7 @@ func TestHandleCdsResponse(t *testing.T) { assert.NoError(t, err) dnsClusters := <-p.DnsResolverChan assert.Equal(t, len(dnsClusters), 1) - assert.Empty(t, p.Cache.edsClusterNames) + assert.Empty(t, p.Cache.EdsClusterNames) wantHash := hash.Sum64String(anyCluster.String()) actualHash := p.Cache.ClusterCache.GetCdsHash(cluster.GetName()) assert.Equal(t, wantHash, actualHash) @@ -150,7 +151,7 @@ func TestHandleCdsResponse(t *testing.T) { } err = p.handleCdsResponse(rsp) assert.NoError(t, err) - assert.Equal(t, []string{"ut-cluster"}, p.Cache.edsClusterNames) + assert.Equal(t, []string{"ut-cluster"}, p.Cache.EdsClusterNames) wantHash := hash.Sum64String(anyCluster.String()) actualHash := p.Cache.ClusterCache.GetCdsHash(cluster.GetName()) assert.Equal(t, wantHash, actualHash) @@ -227,7 +228,7 @@ func TestHandleCdsResponse(t *testing.T) { assert.NoError(t, err) dnsClusters = <-p.DnsResolverChan assert.Equal(t, len(dnsClusters), 1) - assert.Equal(t, []string{"ut-cluster2", "new-ut-cluster"}, p.Cache.edsClusterNames) + assert.Equal(t, []string{"ut-cluster2", "new-ut-cluster"}, p.Cache.EdsClusterNames) wantHash := hash.Sum64String(anyCluster.String()) actualHash := p.Cache.ClusterCache.GetCdsHash(newCluster.GetName()) assert.Equal(t, wantHash, actualHash) @@ -283,7 +284,7 @@ func TestHandleCdsResponse(t *testing.T) { dnsClusters = <-p.DnsResolverChan assert.Equal(t, len(dnsClusters), 0) // only cluster2 is eds typed - assert.Equal(t, []string{"new-ut-cluster1"}, p.Cache.edsClusterNames) + assert.Equal(t, []string{"new-ut-cluster1"}, p.Cache.EdsClusterNames) wantHash1 := hash.Sum64String(anyCluster1.String()) actualHash1 := p.Cache.ClusterCache.GetCdsHash(newCluster1.GetName()) assert.Equal(t, wantHash1, actualHash1) @@ -303,7 +304,7 @@ func TestHandleEdsResponse(t *testing.T) { t.Cleanup(cleanup) t.Run("cluster's apiStatus is UPDATE", func(t *testing.T) { p := newProcessor(nil) - adsLoader := NewAdsCache(nil) + adsLoader := cache.NewAdsCache(nil) adsLoader.ClusterCache = cache_v2.NewClusterCache(nil, utils.NewHashName()) cluster := &cluster_v2.Cluster{ Name: "ut-cluster", @@ -327,7 +328,7 @@ func TestHandleEdsResponse(t *testing.T) { }, } // simulate we have received and processed cluster response - p.Cache.edsClusterNames = []string{"ut-far", "ut-cluster"} + p.Cache.EdsClusterNames = []string{"ut-far", "ut-cluster"} err = p.handleEdsResponse(rsp) assert.NoError(t, err) assert.Equal(t, p.Cache.ClusterCache.GetApiCluster("ut-cluster").ApiStatus, core_v2.ApiStatus_NONE) @@ -336,7 +337,7 @@ func TestHandleEdsResponse(t *testing.T) { t.Run("cluster's apiStatus is Waiting", func(t *testing.T) { p := newProcessor(nil) - adsLoader := NewAdsCache(nil) + adsLoader := cache.NewAdsCache(nil) adsLoader.ClusterCache = cache_v2.NewClusterCache(nil, utils.NewHashName()) cluster := &cluster_v2.Cluster{ Name: "ut-cluster", @@ -355,7 +356,7 @@ func TestHandleEdsResponse(t *testing.T) { }, } p.ack = newAckRequest(rsp) - p.Cache.edsClusterNames = []string{"ut-cluster"} + p.Cache.EdsClusterNames = []string{"ut-cluster"} err = p.handleEdsResponse(rsp) assert.NoError(t, err) assert.Equal(t, p.Cache.ClusterCache.GetApiCluster("ut-cluster").ApiStatus, core_v2.ApiStatus_NONE) @@ -363,7 +364,7 @@ func TestHandleEdsResponse(t *testing.T) { }) t.Run("not apiStatus_UPDATE", func(t *testing.T) { - adsLoader := NewAdsCache(nil) + adsLoader := cache.NewAdsCache(nil) adsLoader.ClusterCache = cache_v2.NewClusterCache(nil, utils.NewHashName()) cluster := &cluster_v2.Cluster{ Name: "ut-cluster", @@ -384,7 +385,7 @@ func TestHandleEdsResponse(t *testing.T) { }, } p.ack = newAckRequest(rsp) - p.Cache.edsClusterNames = []string{"ut-far", "ut-cluster"} + p.Cache.EdsClusterNames = []string{"ut-far", "ut-cluster"} err = p.handleEdsResponse(rsp) assert.NoError(t, err) assert.Equal(t, p.Cache.ClusterCache.GetApiCluster("ut-cluster").ApiStatus, core_v2.ApiStatus_NONE) @@ -392,7 +393,7 @@ func TestHandleEdsResponse(t *testing.T) { }) t.Run("already have cluster, not update", func(t *testing.T) { - adsLoader := NewAdsCache(nil) + adsLoader := cache.NewAdsCache(nil) adsLoader.ClusterCache = cache_v2.NewClusterCache(nil, utils.NewHashName()) cluster := &cluster_v2.Cluster{ Name: "ut-cluster", @@ -415,7 +416,7 @@ func TestHandleEdsResponse(t *testing.T) { }, } p.ack = newAckRequest(rsp) - p.Cache.edsClusterNames = []string{"ut-cluster"} + p.Cache.EdsClusterNames = []string{"ut-cluster"} err = p.handleEdsResponse(rsp) assert.NoError(t, err) assert.Equal(t, p.Cache.ClusterCache.GetApiCluster("ut-cluster").ApiStatus, core_v2.ApiStatus_NONE) @@ -423,7 +424,7 @@ func TestHandleEdsResponse(t *testing.T) { }) t.Run("no apicluster, p.ack not be changed", func(t *testing.T) { - adsLoader := NewAdsCache(nil) + adsLoader := cache.NewAdsCache(nil) adsLoader.ClusterCache = cache_v2.NewClusterCache(nil, utils.NewHashName()) cluster := &cluster_v2.Cluster{} adsLoader.ClusterCache.SetApiCluster("", cluster) @@ -441,14 +442,14 @@ func TestHandleEdsResponse(t *testing.T) { } p.ack = newAckRequest(rsp) // previously no eds cluster, but we received a eds response, not common - p.Cache.edsClusterNames = nil + p.Cache.EdsClusterNames = nil err = p.handleEdsResponse(rsp) assert.NoError(t, err) assert.Nil(t, p.ack.ResourceNames) }) t.Run("empty loadAssignment", func(t *testing.T) { - adsLoader := NewAdsCache(nil) + adsLoader := cache.NewAdsCache(nil) adsLoader.ClusterCache = cache_v2.NewClusterCache(nil, utils.NewHashName()) cluster := &cluster_v2.Cluster{ Name: "ut-cluster", @@ -468,7 +469,7 @@ func TestHandleEdsResponse(t *testing.T) { }, } p.ack = newAckRequest(rsp) - p.Cache.edsClusterNames = []string{"ut-cluster"} + p.Cache.EdsClusterNames = []string{"ut-cluster"} err = p.handleEdsResponse(rsp) assert.NoError(t, err) assert.Equal(t, p.Cache.ClusterCache.GetApiCluster("ut-cluster").ApiStatus, core_v2.ApiStatus_NONE) @@ -484,8 +485,8 @@ func TestHandleLdsResponse(t *testing.T) { } _, loader := test.InitBpfMap(t, config) t.Run("normal function test", func(t *testing.T) { - adsLoader := NewAdsCache(nil) - adsLoader.routeNames = []string{ + adsLoader := cache.NewAdsCache(nil) + adsLoader.RouteNames = []string{ "ut-route-to-client", "ut-route-to-service", } @@ -544,8 +545,8 @@ func TestHandleLdsResponse(t *testing.T) { }) t.Run("listenerCache already has resource and it has not been changed", func(t *testing.T) { - adsLoader := NewAdsCache(nil) - adsLoader.routeNames = []string{ + adsLoader := cache.NewAdsCache(nil) + adsLoader.RouteNames = []string{ "ut-route-to-client", "ut-route-to-service", } @@ -583,8 +584,8 @@ func TestHandleLdsResponse(t *testing.T) { }) t.Run("listenerCache already has resource and it has been changed", func(t *testing.T) { - adsLoader := NewAdsCache(nil) - adsLoader.routeNames = []string{ + adsLoader := cache.NewAdsCache(nil) + adsLoader.RouteNames = []string{ "ut-route-to-client", "ut-route-to-service", } diff --git a/pkg/controller/ads/cache.go b/pkg/controller/ads/cache/cache.go similarity index 95% rename from pkg/controller/ads/cache.go rename to pkg/controller/ads/cache/cache.go index fcd61f642..1852b210c 100644 --- a/pkg/controller/ads/cache.go +++ b/pkg/controller/ads/cache/cache.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package ads +package cache import ( config_cluster_v3 "github.com/envoyproxy/go-control-plane/envoy/config/cluster/v3" @@ -28,6 +28,7 @@ import ( pkg_wellknown "github.com/envoyproxy/go-control-plane/pkg/wellknown" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/anypb" + "istio.io/pkg/log" cluster_v2 "kmesh.net/kmesh/api/v2/cluster" core_v2 "kmesh.net/kmesh/api/v2/core" @@ -43,14 +44,56 @@ import ( type AdsCache struct { // eds names to be subscribed, which is inferred from cluster - edsClusterNames []string + EdsClusterNames []string // route names to be subscribed, which is inferred from listener - routeNames []string + RouteNames []string ListenerCache cache_v2.ListenerCache ClusterCache cache_v2.ClusterCache RouteCache cache_v2.RouteConfigCache } +type Adsconfig struct { + Name string + Namespace string + Address string + Port string +} + +func (x *Adsconfig) GetAdsconfigPort() string { + if x != nil { + return x.Port + } + return "" +} + +func (x *Adsconfig) GetAdsconfigAddress() string { + if x != nil { + return x.Address + } + return "" +} + +func (x *Adsconfig) GetAdsconfigSvcName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Adsconfig) GetAdsconfigName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Adsconfig) GetAdsconfigNamespace() string { + if x != nil { + return x.Namespace + } + return "" +} + func NewAdsCache(bpfAds *bpfads.BpfAds) *AdsCache { hashName := utils.NewHashName() return &AdsCache{ @@ -216,7 +259,7 @@ func (load *AdsCache) CreateApiListenerByLds(status core_v2.ApiStatus, listener apiFilterChain.Filters = append(apiFilterChain.Filters, apiFilter) } if routeName != "" { - load.routeNames = append(load.routeNames, routeName) + load.RouteNames = append(load.RouteNames, routeName) } } @@ -272,7 +315,7 @@ func newApiFilterAndRouteName(filter *config_listener_v3.Filter) (*listener_v2.F } apiFilter.ConfigType = &listener_v2.Filter_TcpProxy{ - TcpProxy: newFilterTcpProxy(filterTcp), + TcpProxy: NewFilterTcpProxy(filterTcp), } case pkg_wellknown.HTTPConnectionManager: var apiFilterHttp listener_v2.Filter_HttpConnectionManager diff --git a/pkg/controller/ads/cache_test.go b/pkg/controller/ads/cache/cache_test.go similarity index 97% rename from pkg/controller/ads/cache_test.go rename to pkg/controller/ads/cache/cache_test.go index 195341bb3..ff502c6d6 100644 --- a/pkg/controller/ads/cache_test.go +++ b/pkg/controller/ads/cache/cache_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package ads +package cache import ( "testing" @@ -422,7 +422,7 @@ func TestNewApiSocketAddress(t *testing.T) { func TestCreateApiListenerByLds(t *testing.T) { t.Run("listener filter configtype is filter_typedconfig", func(t *testing.T) { loader := NewAdsCache(nil) - loader.routeNames = []string{ + loader.RouteNames = []string{ "ut-route", } status := core_v2.ApiStatus_UPDATE @@ -467,15 +467,15 @@ func TestCreateApiListenerByLds(t *testing.T) { assert.Equal(t, apiListener.ApiStatus, status) apiConfigType := apiListener.FilterChains[0].Filters[0].ConfigType configType := &listener_v2.Filter_TcpProxy{ - TcpProxy: newFilterTcpProxy(typedConfig), + TcpProxy: NewFilterTcpProxy(typedConfig), } assert.Equal(t, configType, apiConfigType) - assert.Equal(t, []string{"ut-route"}, loader.routeNames) + assert.Equal(t, []string{"ut-route"}, loader.RouteNames) }) t.Run("listener filter configtype is filter_ConfigDiscover", func(t *testing.T) { loader := NewAdsCache(nil) - loader.routeNames = []string{ + loader.RouteNames = []string{ "ut-route", } status := core_v2.ApiStatus_UPDATE @@ -522,12 +522,12 @@ func TestCreateApiListenerByLds(t *testing.T) { assert.Equal(t, apiListener.ApiStatus, status) filterChain := apiListener.FilterChains[0].Filters assert.Nil(t, filterChain) - assert.Equal(t, []string{"ut-route"}, loader.routeNames) + assert.Equal(t, []string{"ut-route"}, loader.RouteNames) }) t.Run("status is UNCHANGED", func(t *testing.T) { loader := NewAdsCache(nil) - loader.routeNames = []string{ + loader.RouteNames = []string{ "ut-route", } status := core_v2.ApiStatus_UNCHANGED @@ -570,12 +570,12 @@ func TestCreateApiListenerByLds(t *testing.T) { loader.CreateApiListenerByLds(status, listener) apiListener := loader.ListenerCache.GetApiListener(listener.GetName()) assert.Nil(t, apiListener) - assert.Equal(t, []string{"ut-route"}, loader.routeNames) + assert.Equal(t, []string{"ut-route"}, loader.RouteNames) }) t.Run("status is UNCHANGED, filterName is pkg_wellknown.HTTPConnectionManager", func(t *testing.T) { loader := NewAdsCache(nil) - loader.routeNames = []string{ + loader.RouteNames = []string{ "ut-route", } status := core_v2.ApiStatus_UNCHANGED @@ -617,6 +617,6 @@ func TestCreateApiListenerByLds(t *testing.T) { loader.CreateApiListenerByLds(status, listener) apiListener := loader.ListenerCache.GetApiListener(listener.GetName()) assert.Nil(t, apiListener) - assert.Equal(t, []string{"ut-route", "new-ut-route"}, loader.routeNames) + assert.Equal(t, []string{"ut-route", "new-ut-route"}, loader.RouteNames) }) } diff --git a/pkg/controller/ads/convert_filter.go b/pkg/controller/ads/cache/convert_filter.go similarity index 95% rename from pkg/controller/ads/convert_filter.go rename to pkg/controller/ads/cache/convert_filter.go index 21cf0b80a..1e35649d2 100644 --- a/pkg/controller/ads/convert_filter.go +++ b/pkg/controller/ads/cache/convert_filter.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package ads +package cache import ( envoy_filters_tcp_proxy "github.com/envoyproxy/go-control-plane/envoy/extensions/filters/network/tcp_proxy/v3" @@ -22,7 +22,7 @@ import ( "kmesh.net/kmesh/api/v2/filter" ) -func newFilterTcpProxy(envoyTcpProxy *envoy_filters_tcp_proxy.TcpProxy) *filter.TcpProxy { +func NewFilterTcpProxy(envoyTcpProxy *envoy_filters_tcp_proxy.TcpProxy) *filter.TcpProxy { tcpProxy := &filter.TcpProxy{ StatPrefix: envoyTcpProxy.GetStatPrefix(), ClusterSpecifier: nil, diff --git a/pkg/controller/ads/convert_filter_test.go b/pkg/controller/ads/cache/convert_filter_test.go similarity index 95% rename from pkg/controller/ads/convert_filter_test.go rename to pkg/controller/ads/cache/convert_filter_test.go index c60b5deb4..e1babfe3a 100644 --- a/pkg/controller/ads/convert_filter_test.go +++ b/pkg/controller/ads/cache/convert_filter_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package ads +package cache import ( "testing" @@ -38,7 +38,7 @@ func TestNewFilterTcpProxy(t *testing.T) { Cluster: "ut-cluster", }, } - tcpProxy := newFilterTcpProxy(envoyTcpProxy) + tcpProxy := NewFilterTcpProxy(envoyTcpProxy) require.NotNil(t, tcpProxy) assert.Equal(t, tcpProxy.GetCluster(), "ut-cluster") }) @@ -64,7 +64,7 @@ func TestNewFilterTcpProxy(t *testing.T) { }, }, } - tcpProxy := newFilterTcpProxy(envoyTcpProxy) + tcpProxy := NewFilterTcpProxy(envoyTcpProxy) require.NotNil(t, tcpProxy) weightedClustersSpecifier, ok := tcpProxy.ClusterSpecifier.(*filter.TcpProxy_WeightedClusters) require.True(t, ok) diff --git a/pkg/controller/ads/dns.go b/pkg/controller/ads/dns.go index 4466a7e90..ab768c8f3 100644 --- a/pkg/controller/ads/dns.go +++ b/pkg/controller/ads/dns.go @@ -31,13 +31,14 @@ import ( "google.golang.org/protobuf/types/known/wrapperspb" core_v2 "kmesh.net/kmesh/api/v2/core" + "kmesh.net/kmesh/pkg/controller/ads/cache" "kmesh.net/kmesh/pkg/dns" ) // adsDnsResolver is DNS resolver of Kernel Native type dnsController struct { clustersChan chan []*clusterv3.Cluster - cache *AdsCache + cache *cache.AdsCache dnsResolver *dns.DNSResolver // Store the copy of pendingResolveDomain. clusterCache map[string]*pendingResolveDomain @@ -53,7 +54,7 @@ type pendingResolveDomain struct { RefreshRate time.Duration } -func NewDnsController(adsCache *AdsCache) (*dnsController, error) { +func NewDnsController(adsCache *cache.AdsCache) (*dnsController, error) { resolver, err := dns.NewDNSResolver() if err != nil { return nil, err diff --git a/pkg/controller/ads/dns_test.go b/pkg/controller/ads/dns_test.go index 34c5ef87a..1210b1c3c 100644 --- a/pkg/controller/ads/dns_test.go +++ b/pkg/controller/ads/dns_test.go @@ -74,7 +74,7 @@ func TestOverwriteDNSCluster(t *testing.T) { }, } - p := NewController(nil).Processor + p := NewController(nil, false, nil).Processor stopCh := make(chan struct{}) defer close(stopCh) dnsResolver, err := NewDnsController(p.Cache) @@ -221,7 +221,7 @@ func TestHandleCdsResponseWithDns(t *testing.T) { }, } - p := NewController(nil).Processor + p := NewController(nil, false, nil).Processor stopCh := make(chan struct{}) defer close(stopCh) dnsResolver, err := NewDnsController(p.Cache) diff --git a/pkg/controller/adstelemetry/accesslog.go b/pkg/controller/adstelemetry/accesslog.go new file mode 100644 index 000000000..cfc7452b0 --- /dev/null +++ b/pkg/controller/adstelemetry/accesslog.go @@ -0,0 +1,87 @@ +/* + * Copyright The Kmesh Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package adstelemetry + +import ( + "fmt" + "syscall" + "time" +) + +type logInfo struct { + direction string + sourceAddress string + sourceWorkload string + sourceNamespace string + + destinationAddress string + destinationService string + destinationWorkload string + destinationNamespace string +} + +func NewLogInfo() *logInfo { + return &logInfo{ + direction: DEFAULT_UNKNOWN, + sourceAddress: DEFAULT_UNKNOWN, + sourceWorkload: DEFAULT_UNKNOWN, + sourceNamespace: DEFAULT_UNKNOWN, + destinationAddress: DEFAULT_UNKNOWN, + destinationService: DEFAULT_UNKNOWN, + destinationWorkload: DEFAULT_UNKNOWN, + destinationNamespace: DEFAULT_UNKNOWN, + } +} + +func OutputAccesslog(data requestMetric, accesslog logInfo) { + logStr := buildAccesslog(data, accesslog) + fmt.Println("accesslog:", logStr) +} + +func buildAccesslog(data requestMetric, accesslog logInfo) string { + closeTime := data.closeTime + uptime := calculateUptime(osStartTime, closeTime) + + timeInfo := fmt.Sprintf("%v", uptime) + sourceInfo := fmt.Sprintf("src.addr=%s, src.workload=%s, src.namespace=%s", accesslog.sourceAddress, accesslog.sourceWorkload, accesslog.sourceNamespace) + destinationInfo := fmt.Sprintf("dst.addr=%s, dst.service=%s, dst.workload=%s, dst.namespace=%s", accesslog.destinationAddress, accesslog.destinationService, accesslog.destinationWorkload, accesslog.destinationNamespace) + connectionInfo := fmt.Sprintf("direction=%s, sent_bytes=%d, received_bytes=%d, srtt=%dus, min_rtt=%dus, duration=%vms", accesslog.direction, data.sentBytes, data.receivedBytes, data.srtt, data.minRtt, (float64(data.duration) / 1000000.0)) + + logResult := fmt.Sprintf("%s %s, %s, %s", timeInfo, sourceInfo, destinationInfo, connectionInfo) + return logResult +} + +func getOSBootTime() (time.Time, error) { + now := time.Now() + now = now.Round(time.Duration(now.Second())) + + sysinfo := &syscall.Sysinfo_t{} + if err := syscall.Sysinfo(sysinfo); err != nil { + return time.Time{}, err + } + + uptime := time.Duration(sysinfo.Uptime) * time.Second + lastRebootTime := now.Add(-uptime) + + return lastRebootTime, nil +} + +func calculateUptime(startTime time.Time, elapsedTimeNs uint64) time.Time { + elapsedDuration := time.Duration(elapsedTimeNs) * time.Nanosecond + currentTime := startTime.Add(elapsedDuration) + return currentTime +} diff --git a/pkg/controller/adstelemetry/metric.go b/pkg/controller/adstelemetry/metric.go new file mode 100644 index 000000000..3101edcdc --- /dev/null +++ b/pkg/controller/adstelemetry/metric.go @@ -0,0 +1,444 @@ +/* + * Copyright The Kmesh Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package adstelemetry + +import ( + "bytes" + "context" + "encoding/binary" + "fmt" + "net" + "reflect" + "sync" + "sync/atomic" + "time" + "unsafe" + + "github.com/cilium/ebpf" + "github.com/cilium/ebpf/ringbuf" + + "kmesh.net/kmesh/pkg/constants" + "kmesh.net/kmesh/pkg/controller/ads/cache" +) + +const ( + TCP_ESTABLISHED = uint32(1) + TCP_CLOSTED = uint32(7) + + connection_success = uint32(1) + + MSG_LEN = 96 + + metricFlushInterval = 5 * time.Second + + DEFAULT_UNKNOWN = "-" +) + +var osStartTime time.Time + +type MetricController struct { + EnableAccesslog atomic.Bool + EnableMonitoring atomic.Bool + EnableWorkloadMetric atomic.Bool + adsMetricCache map[adsMetricLabels]*adsMetricInfo + NameByAddr map[string]string + mutex sync.RWMutex +} +type adsMetricInfo struct { + SocketConnOpened float64 + SocketConnClosed float64 + SocketConnSentBytes float64 + SocketConnReceivedBytes float64 + SocketConnFailed float64 +} +type statistics struct { + SentBytes uint32 + ReceivedBytes uint32 + ConnectSuccess uint32 + Direction uint32 + State uint32 + Duration uint64 + CloseTime uint64 + // TODO: statistics below are not used for now + Protocol uint32 + SRttTime uint32 + RttMin uint32 + Retransmits uint32 + LostPackets uint32 + Dst_svc_name [192]byte +} + +// connectionDataV4 read from ebpf ringbuf and padding with `_` +type connectionDataV4 struct { + SrcAddr uint32 + DstAddr uint32 + SrcPort uint16 + DstPort uint16 + _ [6]uint32 + OriginalAddr uint32 + OriginalPort uint16 + _ uint16 + _ [3]uint32 + statistics +} + +type requestMetric struct { + src [4]uint32 + dst [4]uint32 + srcPort uint16 + dstPort uint16 + origDstAddr [4]uint32 + origDstPort uint16 + direction uint32 + receivedBytes uint32 + sentBytes uint32 + state uint32 + success uint32 + duration uint64 + closeTime uint64 + srtt uint32 + minRtt uint32 + totalRetrans uint32 + PacketLost uint32 + Dst_svc_name [192]byte +} +type adsMetricLabels struct { + reporter string + + sourcePodAddress string + sourcePodPort string + sourcePodName string + destinationPodAddress string + destinationPodPort string + destinationSvcName string +} + +func NewAdsMetricLabel() *adsMetricLabels { + return &adsMetricLabels{} +} + +func (w *adsMetricLabels) withSource(adsconfig *cache.Adsconfig) *adsMetricLabels { + if adsconfig == nil { + return w + } + + w.sourcePodAddress = adsconfig.GetAdsconfigAddress() + w.sourcePodPort = adsconfig.GetAdsconfigPort() + w.sourcePodName = adsconfig.GetAdsconfigName() + return w +} + +func (w *adsMetricLabels) withDestination(adsconfig *cache.Adsconfig) *adsMetricLabels { + if adsconfig == nil { + return w + } + + w.destinationPodPort = adsconfig.GetAdsconfigPort() + w.destinationPodAddress = adsconfig.GetAdsconfigAddress() + w.destinationSvcName = adsconfig.GetAdsconfigSvcName() + + return w +} + +func NewMetric(AdsCache *cache.AdsCache, enableMonitoring bool, managerCache map[string]string) *MetricController { + m := &MetricController{ + adsMetricCache: map[adsMetricLabels]*adsMetricInfo{}, + NameByAddr: managerCache, + } + m.EnableMonitoring.Store(enableMonitoring) + m.EnableAccesslog.Store(false) + m.EnableWorkloadMetric.Store(false) + return m +} + +func (m *MetricController) Run(ctx context.Context, mapOfTcpInfo *ebpf.Map) { + if m == nil { + return + } + log.Printf("MetricController RUN") + var err error + osStartTime, err = getOSBootTime() + if err != nil { + log.Errorf("get latest os boot time for accesslog failed: %v", err) + } + + reader, err := ringbuf.NewReader(mapOfTcpInfo) + if err != nil { + log.Errorf("open metric notify ringbuf map FAILED, err: %v", err) + return + } + defer func() { + if err := reader.Close(); err != nil { + log.Errorf("ringbuf reader Close FAILED, err: %v", err) + } + }() + + // Register metrics to Prometheus and start Prometheus server + go RunPrometheusClient(ctx) + go func() { + for { + select { + case <-ctx.Done(): + return + default: + // Metrics updated every 5 seconds + time.Sleep(metricFlushInterval) + m.updatePrometheusMetric() + } + } + }() + + for { + select { + case <-ctx.Done(): + return + default: + log.Printf("MetricController LOAD") + if !m.EnableMonitoring.Load() { + continue + } + log.Printf("MetricController ENABLED") + data := requestMetric{} + rec := ringbuf.Record{} + if err := reader.ReadInto(&rec); err != nil { + log.Errorf("ringbuf reader FAILED to read, err: %v", err) + continue + } + if len(rec.RawSample) != int(unsafe.Sizeof(connectionDataV4{})) { + log.Errorf("wrong length %v of a msg, should be %v", len(rec.RawSample), int(unsafe.Sizeof(connectionDataV4{}))) + continue + } + connectType := binary.LittleEndian.Uint32(rec.RawSample) + originInfo := rec.RawSample[unsafe.Sizeof(connectType):] + buf := bytes.NewBuffer(originInfo) + switch connectType { + case constants.MSG_TYPE_IPV4: + data, err = buildV4Metric(buf) + default: + log.Errorf("get connection info failed: %v", err) + continue + } + log.Printf("data: %v", data) + // serviceLabels, accesslog := m.buildServiceMetric(&data) + // OutputAccesslog(data, accesslog) + adsLabels := m.buildAdsMetric(&data) + + m.mutex.Lock() + m.updateAdsMetricCache(data, adsLabels) + m.mutex.Unlock() + } + } +} + +func buildV4Metric(buf *bytes.Buffer) (requestMetric, error) { + data := requestMetric{} + connectData := connectionDataV4{} + if err := binary.Read(buf, binary.LittleEndian, &connectData); err != nil { + return data, err + } + + data.src[0] = connectData.SrcAddr + data.dst[0] = connectData.DstAddr + data.direction = connectData.Direction + data.dstPort = connectData.DstPort + data.srcPort = connectData.SrcPort + + // original addr is 0 indicates the connection is + // workload-type or and not redirected, + // so we just take from the actual destination + if connectData.OriginalAddr == 0 { + data.origDstAddr[0] = data.dst[0] + data.origDstPort = data.dstPort + } else { + data.origDstAddr[0] = connectData.OriginalAddr + data.origDstPort = connectData.OriginalPort + } + + data.sentBytes = connectData.SentBytes + data.receivedBytes = connectData.ReceivedBytes + data.state = connectData.State + data.success = connectData.ConnectSuccess + data.duration = connectData.Duration + data.closeTime = connectData.CloseTime + data.srtt = connectData.statistics.SRttTime + data.minRtt = connectData.statistics.RttMin + data.totalRetrans = connectData.statistics.Retransmits + data.PacketLost = connectData.statistics.LostPackets + data.Dst_svc_name = connectData.statistics.Dst_svc_name + + return data, nil +} + +func NewAdsDstConfig(addr []byte, port uint16, name string) *cache.Adsconfig { + address := net.IPv4(addr[0], addr[1], addr[2], addr[3]).String() + //portstring := strconv.FormatUint(uint64(binary.BigEndian.Uint16([]byte{byte(port), byte(port >> 8)})), 10) + + return &cache.Adsconfig{ + Address: address, + Port: DEFAULT_UNKNOWN, + Name: name, + } +} + +func NewAdsSrcConfig(addr []byte, port uint16, manageCache map[string]string) *cache.Adsconfig { + address := net.IPv4(addr[0], addr[1], addr[2], addr[3]).String() + //portstring := strconv.FormatUint(uint64(binary.BigEndian.Uint16([]byte{byte(port), byte(port >> 8)})), 10) + name := manageCache[address] + if name == "" { + name = DEFAULT_UNKNOWN + } + return &cache.Adsconfig{ + Address: address, + Port: DEFAULT_UNKNOWN, + Name: name, + } +} + +func byteArrayToString(b [192]byte) string { + // 查找第一个结束符的位置 + end := bytes.IndexByte(b[:], 0x00) + if end == -1 { + end = len(b) // 若无结束符,则转换整个数组 + } + // 转换为字符串(自动处理内存复制) + return string(b[:end]) +} + +func (m *MetricController) buildAdsMetric(data *requestMetric) adsMetricLabels { + var dstAddr, srcAddr []byte + for i := range data.dst { + dstAddr = binary.LittleEndian.AppendUint32(dstAddr, data.dst[i]) + srcAddr = binary.LittleEndian.AppendUint32(srcAddr, data.src[i]) + } + dstAdsConfig := NewAdsDstConfig(restoreIPv4(dstAddr), data.dstPort, byteArrayToString(data.Dst_svc_name)) + srcAdsConfig := NewAdsSrcConfig(restoreIPv4(srcAddr), data.srcPort, m.NameByAddr) + + trafficLabels := NewAdsMetricLabel() + trafficLabels.withSource(srcAdsConfig).withDestination(dstAdsConfig) + + switch data.direction { + case constants.INBOUND: + trafficLabels.reporter = "destination" + case constants.OUTBOUND: + trafficLabels.reporter = "source" + } + + return *trafficLabels +} + +func (m *MetricController) updateAdsMetricCache(data requestMetric, labels adsMetricLabels) { + v, ok := m.adsMetricCache[labels] + if ok { + if data.state == TCP_ESTABLISHED { + v.SocketConnOpened = v.SocketConnOpened + 1 + } + if data.state == TCP_CLOSTED { + v.SocketConnClosed = v.SocketConnClosed + 1 + } + if data.success != connection_success { + v.SocketConnFailed = v.SocketConnFailed + 1 + } + v.SocketConnReceivedBytes = v.SocketConnReceivedBytes + float64(data.receivedBytes) + v.SocketConnSentBytes = v.SocketConnSentBytes + float64(data.sentBytes) + } else { + newAdsMetricInfo := adsMetricInfo{} + if data.state == TCP_ESTABLISHED { + newAdsMetricInfo.SocketConnOpened = 1 + } + if data.state == TCP_CLOSTED { + newAdsMetricInfo.SocketConnClosed = 1 + } + if data.success != connection_success { + newAdsMetricInfo.SocketConnFailed = 1 + } + newAdsMetricInfo.SocketConnReceivedBytes = float64(data.receivedBytes) + newAdsMetricInfo.SocketConnSentBytes = float64(data.sentBytes) + m.adsMetricCache[labels] = &newAdsMetricInfo + } +} + +func (m *MetricController) updatePrometheusMetric() { + m.mutex.Lock() + adsInfoCache := m.adsMetricCache + m.adsMetricCache = map[adsMetricLabels]*adsMetricInfo{} + m.mutex.Unlock() + + log.Infof("update prometheus metric") + for k, v := range adsInfoCache { + adsLabels := struct2map(k) + log.Infof("adsLabels: %v", adsLabels) + tcpConnectionOpenedInAds.With(adsLabels).Add(v.SocketConnOpened) + tcpConnectionClosedInAds.With(adsLabels).Add(v.SocketConnClosed) + tcpConnectionFailedInAds.With(adsLabels).Add(v.SocketConnFailed) + tcpReceivedBytesInAds.With(adsLabels).Add(v.SocketConnReceivedBytes) + tcpSentBytesInAds.With(adsLabels).Add(v.SocketConnSentBytes) + } + + // delete metrics + deleteLock.Lock() + // Creating a copy reduces the amount of time spent adding locks in the programme + adsReplica := deleteAds + deleteAds = nil + deleteLock.Unlock() + + for i := 0; i < len(adsReplica); i++ { + deleteAdsMetricInPrometheus(adsReplica[i]) + } +} + +func struct2map(labels interface{}) map[string]string { + if reflect.TypeOf(labels).Kind() == reflect.Struct { + trafficLabelsMap := make(map[string]string) + val := reflect.ValueOf(labels) + num := val.NumField() + fmt.Printf("fieldInfo: %v\n", num) + for i := 0; i < num; i++ { + fieldInfo := val.Type().Field(i) + fmt.Printf("fieldInfo: %v\n", fieldInfo.Name) + if val.Field(i).String() == "" { + trafficLabelsMap[labelsMap[fieldInfo.Name]] = DEFAULT_UNKNOWN + } else { + trafficLabelsMap[labelsMap[fieldInfo.Name]] = val.Field(i).String() + } + } + + return trafficLabelsMap + } else { + log.Error("failed to convert struct to map") + } + return nil +} + +// Converting IPv4 data reported in IPv6 form to IPv4 +func restoreIPv4(bytes []byte) []byte { + for i := 4; i < 16; i++ { + if bytes[i] != 0 { + return bytes + } + } + + return bytes[:4] +} + +func isOrigDstSet(addr [4]uint32) bool { + for _, v := range addr { + if v != 0 { + return true + } + } + return false +} diff --git a/pkg/controller/adstelemetry/metric_test.go b/pkg/controller/adstelemetry/metric_test.go new file mode 100644 index 000000000..b58d0ed42 --- /dev/null +++ b/pkg/controller/adstelemetry/metric_test.go @@ -0,0 +1,137 @@ +/* + * Copyright The Kmesh Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package adstelemetry + +import ( + "reflect" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestCommonTrafficLabels2map(t *testing.T) { + type args struct { + labels interface{} + } + tests := []struct { + name string + args args + want map[string]string + }{ + { + name: "normal commonTrafficLabels to map test", + args: args{ + labels: adsMetricLabels{ + reporter: "destination", + sourcePodAddress: "-", + destinationPodAddress: "192.168.10.24", + }, + }, + want: map[string]string{ + "reporter": "destination", + "source_pod_address": "-", + "source_pod_port": "-", + "destination_pod_address": "192.168.10.24", + "destination_pod_port": "-", + }, + }, + { + name: "empty commonTrafficLabels to map test", + args: args{ + labels: adsMetricLabels{}, + }, + want: map[string]string{ + "reporter": "-", + "source_pod_address": "-", + "source_pod_port": "-", + "destination_pod_address": "-", + "destination_pod_port": "-", + }, + }, + { + name: "Only some fields in the commonTrafficLabels have values", + args: args{ + labels: adsMetricLabels{ + reporter: "source", + sourcePodAddress: "192.168.10.24", + destinationPodAddress: "192.168.10.23", + }, + }, + want: map[string]string{ + "reporter": "source", + "source_pod_address": "192.168.10.24", + "source_pod_port": "-", + "destination_pod_address": "192.168.10.23", + "destination_pod_port": "-", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := struct2map(tt.args.labels); !reflect.DeepEqual(got, tt.want) { + assert.Equal(t, tt.want, got) + t.Errorf("struct2map() = %v, want %v", got, tt.want) + } + }) + } +} + +func TestBuildAdsMetric(t *testing.T) { + type args struct { + data *requestMetric + } + tests := []struct { + name string + args args + want adsMetricLabels + wantErr bool + }{ + { + name: "normal capability test", + args: args{ + data: &requestMetric{ + src: [4]uint32{521736970, 0, 0, 0}, + dst: [4]uint32{383822016, 0, 0, 0}, + srcPort: uint16(36895), + dstPort: uint16(37151), + sentBytes: uint32(156), + receivedBytes: uint32(1024), + }, + }, + want: adsMetricLabels{ + sourcePodAddress: "10.19.25.31", + sourcePodPort: "8080", + destinationPodAddress: "192.168.224.22", + destinationPodPort: "8081", + reporter: "", + }, + wantErr: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + m := MetricController{ + adsMetricCache: map[adsMetricLabels]*adsMetricInfo{}, + } + + got := m.buildAdsMetric(tt.args.data) + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("Metric.buildMetric() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/pkg/controller/adstelemetry/utils.go b/pkg/controller/adstelemetry/utils.go new file mode 100644 index 000000000..6f47e2159 --- /dev/null +++ b/pkg/controller/adstelemetry/utils.go @@ -0,0 +1,148 @@ +/* + * Copyright The Kmesh Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package adstelemetry + +import ( + "context" + "net/http" + "sync" + + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promhttp" + + "kmesh.net/kmesh/pkg/controller/ads/cache" + "kmesh.net/kmesh/pkg/logger" +) + +var ( + log = logger.NewLoggerScope("adstelemetry") + // ensure not occur matche the same requests as /status/metric panic in unit test + mu sync.Mutex + // Ensure concurrency security when removing metriclabels from workloads and services. + deleteLock sync.Mutex + deleteAds = []*cache.Adsconfig{} + deleteService = []string{} + + adsLabels = []string{ + "reporter", + "source_pod_address", + "source_pod_port", + "source_pod_name", + "destination_pod_address", + "destination_pod_port", + "destination_svc_name", + } + + labelsMap = map[string]string{ + "reporter": "reporter", + "sourcePodAddress": "source_pod_address", + "sourcePodPort": "source_pod_port", + "sourcePodName": "source_pod_name", + "destinationPodAddress": "destination_pod_address", + "destinationPodPort": "destination_pod_port", + "destinationSvcName": "destination_svc_name", + } +) + +var ( + tcpConnectionOpenedInAds = prometheus.NewGaugeVec(prometheus.GaugeOpts{ + Name: "kmesh_tcp_ads_connections_opened_total", + Help: "The total number of TCP connections opened to a ads", + }, adsLabels) + + tcpConnectionClosedInAds = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "kmesh_tcp_ads_connections_closed_total", + Help: "The total number of TCP connections closed to a ads", + }, adsLabels) + + tcpReceivedBytesInAds = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "kmesh_tcp_ads_received_bytes_total", + Help: "The size of the total number of bytes received in response to a ads over a TCP connection.", + }, adsLabels) + + tcpSentBytesInAds = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "kmesh_tcp_ads_sent_bytes_total", + Help: "The size of the total number of bytes sent in response to a ads over a TCP connection.", + }, adsLabels) + + tcpConnectionFailedInAds = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "kmesh_tcp_ads_conntections_failed_total", + Help: "The total number of TCP connections failed to a ads.", + }, adsLabels) + + tcpConnectionTotalRetransInAds = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "kmesh_tcp_retrans_total", + Help: "Total number of retransmissions of the ads over the TCP connection.", + }, adsLabels) +) + +func RunPrometheusClient(ctx context.Context) { + registry := prometheus.NewRegistry() + for { + select { + case <-ctx.Done(): + return + default: + runPrometheusClient(registry) + } + } +} + +func runPrometheusClient(registry *prometheus.Registry) { + // ensure not occur matche the same requests as /status/metric panic in unit test + mu.Lock() + defer mu.Unlock() + registry.MustRegister(tcpConnectionOpenedInAds, tcpConnectionClosedInAds, tcpReceivedBytesInAds, tcpSentBytesInAds, tcpConnectionTotalRetransInAds) + + http.Handle("/status/metric", promhttp.HandlerFor(registry, promhttp.HandlerOpts{ + Registry: registry, + })) + if err := http.ListenAndServe(":15020", nil); err != nil { + log.Fatalf("start prometheus client port failed: %v", err) + } +} + +func DeleteAdsMetric(adsconfig *cache.Adsconfig) { + if adsconfig == nil { + return + } + deleteLock.Lock() + deleteAds = append(deleteAds, adsconfig) + deleteLock.Unlock() +} + +func deleteAdsMetricInPrometheus(ads *cache.Adsconfig) { + // delete destination ads metric labels + _ = tcpConnectionClosedInAds.DeletePartialMatch(prometheus.Labels{"destination_address": ads.Address, "destination_pod_namespace": ads.Namespace}) + _ = tcpConnectionFailedInAds.DeletePartialMatch(prometheus.Labels{"destination_address": ads.Address, "destination_addressspace": ads.Namespace}) + _ = tcpConnectionOpenedInAds.DeletePartialMatch(prometheus.Labels{"destination_address": ads.Address, "destination_addressspace": ads.Namespace}) + _ = tcpReceivedBytesInAds.DeletePartialMatch(prometheus.Labels{"destination_address": ads.Address, "destination_addressspace": ads.Namespace}) + _ = tcpSentBytesInAds.DeletePartialMatch(prometheus.Labels{"destination_address": ads.Address, "destination_addressspace": ads.Namespace}) + _ = tcpConnectionTotalRetransInAds.DeletePartialMatch(prometheus.Labels{"destination_address": ads.Address, "destination_addressspace": ads.Namespace}) + // delete source ads metric labels + _ = tcpConnectionClosedInAds.DeletePartialMatch(prometheus.Labels{"source_workload": ads.Name, "source_workload_namespace": ads.Namespace}) + _ = tcpConnectionFailedInAds.DeletePartialMatch(prometheus.Labels{"source_workload": ads.Name, "source_workload_namespace": ads.Namespace}) + _ = tcpConnectionOpenedInAds.DeletePartialMatch(prometheus.Labels{"source_workload": ads.Name, "source_workload_namespace": ads.Namespace}) + _ = tcpReceivedBytesInAds.DeletePartialMatch(prometheus.Labels{"source_workload": ads.Name, "source_workload_namespace": ads.Namespace}) + _ = tcpSentBytesInAds.DeletePartialMatch(prometheus.Labels{"source_workload": ads.Name, "source_workload_namespace": ads.Namespace}) + _ = tcpConnectionTotalRetransInAds.DeletePartialMatch(prometheus.Labels{"source_workload": ads.Name, "source_workload_namespace": ads.Namespace}) +} diff --git a/pkg/controller/client.go b/pkg/controller/client.go index 8ea1b33a4..955f04db2 100644 --- a/pkg/controller/client.go +++ b/pkg/controller/client.go @@ -50,18 +50,26 @@ type XdsClient struct { xdsConfig *config.XdsConfig } -func NewXdsClient(mode string, bpfAds *bpfads.BpfAds, bpfWorkload *bpfwl.BpfWorkload, enableMonitoring, enableProfiling bool) *XdsClient { +func NewAdsXdsClient(bpfAds *bpfads.BpfAds, enableMonitoring bool, managerCache map[string]string) *XdsClient { client := &XdsClient{ - mode: mode, - xdsConfig: config.GetConfig(mode), + mode: constants.KernelNativeMode, + xdsConfig: config.GetConfig(constants.KernelNativeMode), } - if mode == constants.DualEngineMode { - client.WorkloadController = workload.NewController(bpfWorkload, enableMonitoring, enableProfiling) - } else if mode == constants.KernelNativeMode { - client.AdsController = ads.NewController(bpfAds) + client.AdsController = ads.NewController(bpfAds, enableMonitoring, managerCache) + client.ctx, client.cancel = context.WithCancel(context.Background()) + client.ctx = metadata.AppendToOutgoingContext(client.ctx, "ClusterID", client.xdsConfig.Metadata.ClusterID.String()) + return client +} + +func NewWorkloadXdsClient(bpfWorkload *bpfwl.BpfWorkload, enableMonitoring, enableProfiling bool) *XdsClient { + client := &XdsClient{ + mode: constants.DualEngineMode, + xdsConfig: config.GetConfig(constants.DualEngineMode), } + client.WorkloadController = workload.NewController(bpfWorkload, enableMonitoring, enableProfiling) + client.ctx, client.cancel = context.WithCancel(context.Background()) client.ctx = metadata.AppendToOutgoingContext(client.ctx, "ClusterID", client.xdsConfig.Metadata.ClusterID.String()) return client diff --git a/pkg/controller/client_test.go b/pkg/controller/client_test.go index df300115c..f7575451a 100644 --- a/pkg/controller/client_test.go +++ b/pkg/controller/client_test.go @@ -30,7 +30,6 @@ import ( bpfads "kmesh.net/kmesh/pkg/bpf/ads" bpfwl "kmesh.net/kmesh/pkg/bpf/workload" - "kmesh.net/kmesh/pkg/constants" "kmesh.net/kmesh/pkg/controller/workload" "kmesh.net/kmesh/pkg/controller/xdstest" "kmesh.net/kmesh/pkg/nets" @@ -38,7 +37,7 @@ import ( func TestRecoverConnection(t *testing.T) { t.Run("test reconnect success", func(t *testing.T) { - utClient := NewXdsClient(constants.KernelNativeMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false, false) + utClient := NewAdsXdsClient(&bpfads.BpfAds{}, false, nil) patches := gomonkey.NewPatches() defer patches.Reset() iteration := 0 @@ -79,7 +78,7 @@ func TestClientResponseProcess(t *testing.T) { })) }) - utClient := NewXdsClient(constants.KernelNativeMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false, false) + utClient := NewAdsXdsClient(&bpfads.BpfAds{}, false, nil) err := utClient.createGrpcStreamClient() assert.NoError(t, err) @@ -126,7 +125,7 @@ func TestClientResponseProcess(t *testing.T) { })) }) - utClient := NewXdsClient(constants.DualEngineMode, &bpfads.BpfAds{}, &bpfwl.BpfWorkload{}, false, false) + utClient := NewWorkloadXdsClient(&bpfwl.BpfWorkload{}, false, false) err := utClient.createGrpcStreamClient() assert.NoError(t, err) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 48f936c9f..22aff4c99 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -145,12 +145,17 @@ func (c *Controller) Start(stopCh <-chan struct{}) error { } } - c.client = NewXdsClient(c.mode, c.bpfAdsObj, c.bpfWorkloadObj, c.bpfConfig.EnableMonitoring, c.bpfConfig.EnableProfiling) - - if c.client.WorkloadController != nil { - c.client.WorkloadController.Run(ctx) - } else { - c.client.AdsController.StartDnsController(stopCh) + if c.mode == constants.DualEngineMode { + c.client = NewWorkloadXdsClient(c.bpfWorkloadObj, c.bpfConfig.EnableMonitoring, c.bpfConfig.EnableProfiling) + if c.client.WorkloadController != nil { + c.client.WorkloadController.Run(ctx) + } + } else if c.mode == constants.KernelNativeMode { + c.client = NewAdsXdsClient(c.bpfAdsObj, c.bpfConfig.EnableMonitoring, kmeshManageController.NameByAddr) + if c.client.AdsController != nil { + c.client.AdsController.StartDnsController(stopCh) + c.client.AdsController.Run(ctx) + } } return c.client.Run(stopCh) diff --git a/pkg/controller/manage/manage_controller.go b/pkg/controller/manage/manage_controller.go index d9d781122..1bf96c2f6 100644 --- a/pkg/controller/manage/manage_controller.go +++ b/pkg/controller/manage/manage_controller.go @@ -69,6 +69,7 @@ type KmeshManageController struct { xdpProgFd int tcProgFd int mode string + NameByAddr map[string]string } func isPodReady(pod *corev1.Pod) bool { @@ -102,6 +103,7 @@ func NewKmeshManageController(client kubernetes.Interface, sm *kmeshsecurity.Sec xdpProgFd: xdpProgFd, tcProgFd: tcProgFd, mode: mode, + NameByAddr: make(map[string]string), } if _, err := podInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{ @@ -129,6 +131,18 @@ func NewKmeshManageController(client kubernetes.Interface, sm *kmeshsecurity.Sec return c, nil } +func (c *KmeshManageController) AddNameByAddr(pod *corev1.Pod) { + c.NameByAddr[pod.Status.PodIP] = pod.GetName() + "." + pod.GetNamespace() +} + +func (c *KmeshManageController) GetNameByAddr(addr string) string { + return c.NameByAddr[addr] +} + +func (c *KmeshManageController) DeleteNameByAddr(addr string) { + delete(c.NameByAddr, addr) +} + func (c *KmeshManageController) handlePodAdd(obj interface{}) { newPod, ok := obj.(*corev1.Pod) if !ok { @@ -228,7 +242,8 @@ func (c *KmeshManageController) enableKmeshManage(pod *corev1.Pod) { log.Debugf("Pod %s/%s is not ready, skipping Kmesh manage enable", pod.GetNamespace(), pod.GetName()) return } - log.Infof("%s/%s: enable Kmesh manage", pod.GetNamespace(), pod.GetName()) + c.AddNameByAddr(pod) + log.Infof("%s/%s/%s: enable Kmesh manage", pod.GetNamespace(), pod.GetName(), pod.Status.PodIP) nspath, _ := ns.GetPodNSpath(pod) if err := utils.HandleKmeshManage(nspath, true); err != nil { log.Errorf("failed to enable Kmesh manage") @@ -245,6 +260,7 @@ func (c *KmeshManageController) disableKmeshManage(pod *corev1.Pod) { log.Debugf("%s/%s is not ready, skipping Kmesh manage disable", pod.GetNamespace(), pod.GetName()) return } + c.DeleteNameByAddr(pod.Status.PodIP) log.Infof("%s/%s: disable Kmesh manage", pod.GetNamespace(), pod.GetName()) nspath, _ := ns.GetPodNSpath(pod) if err := utils.HandleKmeshManage(nspath, false); err != nil { diff --git a/pkg/dns/dns_test.go b/pkg/dns/dns_test.go index 4cb9523d9..1574b235d 100644 --- a/pkg/dns/dns_test.go +++ b/pkg/dns/dns_test.go @@ -22,8 +22,11 @@ import ( "sync" "testing" "time" + + "kmesh.net/kmesh/pkg/controller/ads/cache" ) + func TestDNS(t *testing.T) { fakeDNSServer := NewFakeDNSServer()