Skip to content

Commit 231a1f0

Browse files
author
lec-bit
committed
opt
Signed-off-by: lec-bit <glfhzmy@126.com>
1 parent 5ef0990 commit 231a1f0

File tree

14 files changed

+1060
-60
lines changed

14 files changed

+1060
-60
lines changed

bpf/include/common.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#define _COMMON_H_
66

77
#include "../../config/kmesh_marcos_def.h"
8+
#include <linux/in.h>
89
#include <stddef.h>
910
#include <stdbool.h>
1011
#include <stdint.h>
@@ -17,7 +18,17 @@
1718
#include "errno.h"
1819

1920
#if ENHANCED_KERNEL
20-
#include <bpf_helper_defs_ext.h>
21+
#if KERNEL_KFUNC
22+
#include "bpf_kfunc.h"
23+
#else
24+
struct bpf_mem_ptr {
25+
void *ptr;
26+
__u32 size;
27+
};
28+
#include "bpf_helper_defs_ext.h"
29+
#define bpf_km_setsockopt bpf_setsockopt
30+
#define bpf_km_getsockopt bpf_getsockopt
31+
#endif
2132
#endif
2233

2334
#define bpf_unused __attribute__((__unused__))

bpf/kmesh/ads/cgroup_sock.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
#if ENHANCED_KERNEL
1616
#include "route_config.h"
17+
static const char kmesh_module_ulp_name[] = KMESH_MODULE_ULP_NAME;
1718
#endif
1819
#if KMESH_ENABLE_IPV4
1920
#if KMESH_ENABLE_HTTP
2021

21-
static const char kmesh_module_name[] = "kmesh_defer";
2222
static char kmesh_module_name_get[KMESH_MODULE_NAME_LEN] = "";
2323
static inline int sock4_traffic_control(struct bpf_sock_addr *ctx)
2424
{
@@ -42,9 +42,10 @@ static inline int sock4_traffic_control(struct bpf_sock_addr *ctx)
4242
BPF_LOG(DEBUG, KMESH, "bpf find listener addr=[%s:%u]\n", ip2str(&ip, 1), bpf_ntohs(ctx->user_port));
4343

4444
#if ENHANCED_KERNEL
45-
ret = bpf_getsockopt(ctx, IPPROTO_TCP, TCP_ULP, (void *)kmesh_module_name_get, KMESH_MODULE_NAME_LEN);
46-
if (CHECK_MODULE_NAME_NULL(ret) || bpf__strncmp(kmesh_module_name_get, KMESH_MODULE_NAME_LEN, kmesh_module_name)) {
47-
ret = bpf_setsockopt(ctx, IPPROTO_TCP, TCP_ULP, (void *)kmesh_module_name, sizeof(kmesh_module_name));
45+
ret = bpf_km_getsockopt(ctx, IPPROTO_TCP, TCP_ULP, kmesh_module_ulp_name_get, KMESH_MODULE_NAME_LEN);
46+
if (CHECK_MODULE_NAME_NULL(ret)
47+
|| bpf__strncmp(kmesh_module_ulp_name_get, KMESH_MODULE_NAME_LEN, kmesh_module_ulp_name)) {
48+
ret = bpf_km_setsockopt(ctx, IPPROTO_TCP, TCP_ULP, kmesh_module_ulp_name, sizeof(kmesh_module_ulp_name));
4849
if (ret)
4950
BPF_LOG(ERR, KMESH, "bpf set sockopt failed! ret %d\n", ret);
5051
return 0;

bpf/kmesh/ads/include/kmesh_common.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131
val; \
3232
})
3333

34-
struct bpf_mem_ptr {
35-
void *ptr;
36-
__u32 size;
37-
};
38-
3934
static inline int bpf__strncmp(const char *dst, int n, const char *src)
4035
{
4136
if (dst == NULL || src == NULL)

bpf/kmesh/bpf2go/kernelnative/enhanced/kmeshcgroupsock_bpfeb.go

Lines changed: 242 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)