Open
修复两个oncn-mda的问题 #31
bitcoffeeAdd on Dec 12, 2024
修复两个oncn-mda的问题 #31
Open
bitcoffeeAdd on Dec 12, 2024
Merged fromrefs/pull/31/headintoopenEuler-24.03-LTS
Total: 3 files changed+302-3
@@ -1,7 +1,7 @@
1%global codepath kmesh1%global codepath kmesh
2Name: Kmesh2Name: Kmesh
3Version: 0.4.13Version: 0.4.1
4-Release: 24+Release: 3
5Summary: %{name} is a eBPF-based service mesh kernel solution5Summary: %{name} is a eBPF-based service mesh kernel solution
6License: ASL 2.0 and GPL-2.06License: ASL 2.0 and GPL-2.0
7URL: https://github.com/kmesh-net7URL: https://github.com/kmesh-net
@@ -12,16 +12,16 @@ BuildRequires: protobuf protobuf-c protobuf-c-devel
12BuildRequires: golang >= 1.21.412BuildRequires: golang >= 1.21.4
13BuildRequires: clang >= 10.0.1 llvm >= 10.0.113BuildRequires: clang >= 10.0.1 llvm >= 10.0.1
14BuildRequires: libbpf-devel kernel-devel >= 5.1014BuildRequires: libbpf-devel kernel-devel >= 5.10
15-BuildRequires: libboundscheck
16BuildRequires: uname-build-checks15BuildRequires: uname-build-checks
17 16 
18Requires: bpftool17Requires: bpftool
19Requires: libbpf18Requires: libbpf
20-Requires: libboundscheck
21 19 
22Patch0001: Downgrade-go-version-to-v1.21.4.patch20Patch0001: Downgrade-go-version-to-v1.21.4.patch
23Patch0002: Remove-useless-tag-in-Makefile.patch21Patch0002: Remove-useless-tag-in-Makefile.patch
24Patch0003: Support-uid-gid.patch22Patch0003: Support-uid-gid.patch
23+Patch0004: fix-oncn-mda-don-t-support-use-ipv6-family-in-sockop.patch
24+Patch0005: remove-libboundscheck-dependency.patch
25 25 
26%description26%description
27%{name} is a eBPF-based service mesh kernel solution.27%{name} is a eBPF-based service mesh kernel solution.
@@ -121,6 +121,10 @@ rm -rf %{buildroot}
121%attr(0500,root,root) /kmesh/start_kmesh.sh121%attr(0500,root,root) /kmesh/start_kmesh.sh
122 122 
123%changelog123%changelog
124+* Thu Dec 12 2024 bitcoffee<liuxin350@huawei.com> - 0.4.1-3
125+- 1. fix oncn-mda don't support ipv4 mapped ipv6
126+ 2. remove libboundscheck dependence
127+ 
124* Mon Nov 25 2024 weli-l<1289113577@qq.com> - 0.4.1-2128* Mon Nov 25 2024 weli-l<1289113577@qq.com> - 0.4.1-2
125- add dockerfile for Kmesh129- add dockerfile for Kmesh
126 130 
@@ -0,0 +1,26 @@
1+From 3ec7e0af60ea52a1db143a5cb001c0cf171da064 Mon Sep 17 00:00:00 2001
2+From: bitcoffee <liuxin350@huawei.com>
3+Date: Thu, 12 Dec 2024 19:13:53 +0800
4+Subject: [PATCH] fix oncn-mda don't support use ipv6 family in sockops
5+ 
6+Signed-off-by: bitcoffee <liuxin350@huawei.com>
7+---
8+ oncn-mda/ebpf_src/sock_ops.c | 2 +-
9+ 1 file changed, 1 insertion(+), 1 deletion(-)
10+ 
11+diff --git a/oncn-mda/ebpf_src/sock_ops.c b/oncn-mda/ebpf_src/sock_ops.c
12+index f5ab001..92840cc 100644
13+--- a/oncn-mda/ebpf_src/sock_ops.c
14++++ b/oncn-mda/ebpf_src/sock_ops.c
15+@@ -397,7 +397,7 @@ static void clean_ops_map(struct bpf_sock_ops *const skops)
16+ SEC("sockops")
17+ int SOCK_OPS_NAME(struct bpf_sock_ops *const skops)
18+ {
19+- if (skops->family != AF_INET)
20++ if ((skops->family != AF_INET) && (skops->family != AF_INET6))
21+ return 0;
22+
23+ switch (skops->op) {
24+--
25+2.33.0
26+ 
@@ -0,0 +1,269 @@
1+From 66c6cd8aa818fc1b31f0d646817b7577c11396fc Mon Sep 17 00:00:00 2001
2+From: bitcoffee <liuxin350@huawei.com>
3+Date: Thu, 12 Dec 2024 19:41:12 +0800
4+Subject: [PATCH] remove libboundscheck dependency
5+ 
6+Signed-off-by: bitcoffee <liuxin350@huawei.com>
7+---
8+ oncn-mda/cli_src/CMakeLists.txt | 2 +-
9+ oncn-mda/cli_src/func/chain.c | 23 ++++----------
10+ oncn-mda/cli_src/func/global.c | 53 +++++++++------------------------
11+ oncn-mda/cli_src/func/log.c | 2 +-
12+ oncn-mda/cli_src/func/switch.c | 16 ++++------
13+ oncn-mda/include/log.h | 1 -
14+ oncn-mda/include/macli.h | 1 -
15+ 7 files changed, 28 insertions(+), 70 deletions(-)
16+ 
17+diff --git a/oncn-mda/cli_src/CMakeLists.txt b/oncn-mda/cli_src/CMakeLists.txt
18+index 471da73..5bf849f 100644
19+--- a/oncn-mda/cli_src/CMakeLists.txt
20++++ b/oncn-mda/cli_src/CMakeLists.txt
21+@@ -14,6 +14,6 @@ if($ENV{HS_COVERAGE_ENABLE})
22+ endif($ENV{HS_COVERAGE_ENABLE})
23+
24+ add_executable(mdacore mdacore.c ${SRC_LIST})
25+-target_link_libraries(mdacore -lbpf -lboundscheck -lelf -lz -lm)
26++target_link_libraries(mdacore -lbpf -lelf -lz -lm)
27+
28+ MESSAGE("======================Leave cli folder=======================")
29+diff --git a/oncn-mda/cli_src/func/chain.c b/oncn-mda/cli_src/func/chain.c
30+index 3890606..4cf2988 100644
31+--- a/oncn-mda/cli_src/func/chain.c
32++++ b/oncn-mda/cli_src/func/chain.c
33+@@ -32,14 +32,9 @@ static int get_input_ip(const char *const src, struct input_filter_rule *const i
34+ macli_log(ERR, "over the max cidrs set num, max is %d\n", MAX_PARAM_LENGTH);
35+ return FAILED;
36+ }
37+- int ret = strcpy_s(input_filter_rules->input_ip[(input_filter_rules->input_ip_num)++], MAX_CIDR_LENGTH, src);
38+- if (ret == ERANGE_AND_RESET) {
39+- macli_log(ERR, "input cidr string too long!\n");
40+- return FAILED;
41+- } else if (ret != EOK) {
42+- macli_log(ERR, "get filter rules failed! errno:%d\n", ret);
43+- return FAILED;
44+- }
45++ (void)memset(input_filter_rules->input_ip[(input_filter_rules->input_ip_num)], 0x0, MAX_CIDR_LENGTH);
46++ (void)strncpy(input_filter_rules->input_ip[(input_filter_rules->input_ip_num)++], src, MAX_CIDR_LENGTH - 1);
47++
48+ return SUCCESS;
49+ }
50+
51+@@ -49,15 +44,9 @@ static int get_input_port(const char *const src, struct input_filter_rule *const
52+ macli_log(ERR, "over the max ports set num, max is %d\n", MAX_PARAM_LENGTH);
53+ return FAILED;
54+ }
55+- int ret =
56+- strcpy_s(input_filter_rules->input_port[(input_filter_rules->input_port_num)++], MAX_PORT_RANGE_LENGTH, src);
57+- if (ret == ERANGE_AND_RESET) {
58+- macli_log(ERR, "input port string is too long!\n");
59+- return FAILED;
60+- } else if (ret != EOK) {
61+- macli_log(ERR, "get filter rules failed! errno:%d\n", ret);
62+- return FAILED;
63+- }
64++ (void)memset(input_filter_rules->input_port[(input_filter_rules->input_port_num)], 0x0, MAX_PORT_RANGE_LENGTH);
65++ (void)strncpy(input_filter_rules->input_port[(input_filter_rules->input_port_num)++], src, MAX_PORT_RANGE_LENGTH - 1);
66++
67+ return SUCCESS;
68+ }
69+
70+diff --git a/oncn-mda/cli_src/func/global.c b/oncn-mda/cli_src/func/global.c
71+index 2579078..a0f17ab 100644
72+--- a/oncn-mda/cli_src/func/global.c
73++++ b/oncn-mda/cli_src/func/global.c
74+@@ -113,10 +113,8 @@ static int get_prog_fd(const char *const prog_name, int *const fd)
75+ __u32 obj_id = 0;
76+ __u32 info_length = sizeof(struct bpf_prog_info);
77+ while (true) {
78+- if (memset_s(&prog_info, info_length, 0x0, info_length) != EOK) {
79+- macli_log(ERR, "system memset failed!\n");
80+- return FAILED;
81+- }
82++ (void)memset(&prog_info, 0x0, info_length);
83++
84+ if (bpf_prog_get_next_id(obj_id, &obj_id)) {
85+ if (errno == ENOENT)
86+ break;
87+@@ -151,10 +149,7 @@ static int get_map_fd(const char *const map_name, int *const fd)
88+ __u32 obj_id = 0;
89+ __u32 info_length = sizeof(struct bpf_map_info);
90+ while (true) {
91+- if (memset_s(&map_info, info_length, 0x0, info_length) != EOK) {
92+- macli_log(ERR, "system memset failed!\n");
93+- return FAILED;
94+- }
95++ (void)memset(&map_info, 0x0, info_length);
96+ if (bpf_map_get_next_id(obj_id, &obj_id)) {
97+ if (errno == ENOENT)
98+ break;
99+@@ -192,13 +187,10 @@ static int init_mesh_map(
100+ struct bpf_create_map_attr *const map_attr)
101+ #endif
102+ {
103+- int ret = EOK;
104+- ret += strcpy_s(fds_map->name, BPF_OBJ_NAME_LEN, map_name);
105+- ret += strcpy_s(fds_map->pin_file_path, PATH_MAX, pin_file_path);
106+- if (ret != EOK) {
107+- macli_log(ERR, "system copy string failed!");
108+- return FAILED;
109+- }
110++ (void)memset(fds_map->name, 0x0, BPF_OBJ_NAME_LEN);
111++ (void)strncpy(fds_map->name, map_name, BPF_OBJ_NAME_LEN - 1);
112++ (void)memset(fds_map->pin_file_path, 0x0, PATH_MAX);
113++ (void)strncpy(fds_map->pin_file_path, pin_file_path, PATH_MAX - 1);
114+ if (get_map_fd(fds_map->name, &(fds_map->fd)) != SUCCESS)
115+ return FAILED;
116+ fds_map->xattr = map_attr;
117+@@ -212,12 +204,8 @@ static int init_mesh_prog(
118+ enum bpf_attach_type attach_type,
119+ int attach_fd)
120+ {
121+- int ret = EOK;
122+- ret = strcpy_s(fds_prog->name, BPF_OBJ_NAME_LEN, prog_name);
123+- if (ret != EOK) {
124+- macli_log(ERR, "system copy string failed!");
125+- return FAILED;
126+- }
127++ (void)memset(fds_prog->name, 0x0, BPF_OBJ_NAME_LEN);
128++ (void)strncpy(fds_prog->name, prog_name, BPF_OBJ_NAME_LEN - 1);
129+ if (get_prog_fd(fds_prog->name, &(fds_prog->fd)) != SUCCESS)
130+ return FAILED;
131+ fds_prog->attach_type = attach_type;
132+@@ -228,13 +216,8 @@ static int init_mesh_prog(
133+
134+ static int init_mesh_prog_pin_file(struct mesh_prog_info *const fds_prog, const char *const pin_file_path)
135+ {
136+- int ret = EOK;
137+- ret = strcpy_s(fds_prog->pin_file_path, PATH_MAX, pin_file_path);
138+- if (ret != EOK) {
139+- macli_log(ERR, "system copy string failed!");
140+- return FAILED;
141+- }
142+-
143++ (void)memset(fds_prog->pin_file_path, 0x0, PATH_MAX);
144++ (void)strncpy(fds_prog->pin_file_path, pin_file_path, PATH_MAX - 1);
145+ return SUCCESS;
146+ }
147+
148+@@ -318,7 +301,7 @@ int get_u32_num(const char *const src, __u32 *const ret)
149+ const int convert_base = 10;
150+ char tmp_buff[TMP_BUF_SIZE] = {0};
151+ unsigned long tmp = strtoul(src, NULL, convert_base);
152+- if (sprintf_s(tmp_buff, sizeof(tmp_buff), "%lu", tmp) < 0) {
153++ if (snprintf(tmp_buff, sizeof(tmp_buff), "%lu", tmp) < 0) {
154+ macli_log(ERR, "system sprintf string failed!\n");
155+ return FAILED;
156+ }
157+@@ -332,12 +315,8 @@ int get_u32_num(const char *const src, __u32 *const ret)
158+
159+ int check_cidr(const char *const src, __u32 *const ip, __u32 *const mask)
160+ {
161+- int ret = EOK;
162+ char tmp_buff[MAX_CIDR_LENGTH] = {0};
163+- if ((ret = strcpy_s(tmp_buff, sizeof(tmp_buff), src)) != EOK) {
164+- macli_log(ERR, "system copy string failed! errno:%d\n", ret);
165+- return FAILED;
166+- }
167++ (void)strncpy(tmp_buff, src, sizeof(tmp_buff) - 1);
168+ char *ip_part = tmp_buff;
169+ char *p = strrchr(tmp_buff, '/');
170+ if (p == NULL)
171+@@ -358,12 +337,8 @@ int check_cidr(const char *const src, __u32 *const ip, __u32 *const mask)
172+
173+ int check_port(const char *const src, __u32 *const begin_port, __u32 *const end_port)
174+ {
175+- int ret = EOK;
176+ char tmp_buff[MAX_PORT_RANGE_LENGTH] = {0};
177+- if ((ret = strcpy_s(tmp_buff, sizeof(tmp_buff), src)) != EOK) {
178+- macli_log(ERR, "system copy string failed! errno:%d\n", ret);
179+- return FAILED;
180+- }
181++ (void)strncpy(tmp_buff, src, sizeof(tmp_buff) - 1);
182+ // support 80-90
183+ // support 80
184+ char *num1 = tmp_buff;
185+diff --git a/oncn-mda/cli_src/func/log.c b/oncn-mda/cli_src/func/log.c
186+index 9381c7e..b7b8287 100644
187+--- a/oncn-mda/cli_src/func/log.c
188++++ b/oncn-mda/cli_src/func/log.c
189+@@ -20,7 +20,7 @@ void ma_log(enum LOG_LEVEL level, const char *format, ...)
190+ va_list ap;
191+ va_start(ap, format);
192+ char fmt_str[MAX_FMT_STR_LENGTH] = {0};
193+- if (vsnprintf_s(fmt_str, sizeof(fmt_str), sizeof(fmt_str) - 1, format, ap) == -1) {
194++ if (vsnprintf(fmt_str, sizeof(fmt_str), format, ap) < 0) {
195+ va_end(ap);
196+ return;
197+ }
198+diff --git a/oncn-mda/cli_src/func/switch.c b/oncn-mda/cli_src/func/switch.c
199+index 416f00e..3974ba8 100644
200+--- a/oncn-mda/cli_src/func/switch.c
201++++ b/oncn-mda/cli_src/func/switch.c
202+@@ -365,7 +365,6 @@ static int check_file_access(const char *const config_path)
203+
204+ static int read_chain_config(const char *const config_path, struct sock_param *const filter_rules)
205+ {
206+- int ret;
207+ if (check_file_access(config_path) != SUCCESS)
208+ return FAILED;
209+ FILE *config_file = fopen(config_path, "r");
210+@@ -384,10 +383,10 @@ static int read_chain_config(const char *const config_path, struct sock_param *c
211+ if (*p == '#' || *p == '\0')
212+ continue;
213+
214+- if ((ret = strcpy_s(buf_save, sizeof(buf_save), buf)) != EOK) {
215+- macli_log(ERR, "system copy string failed! errno:%d\n", ret);
216+- continue;
217+- }
218++ (void)memset(buf_save, 0x0, sizeof(buf_save));
219++ (void)strncpy(buf_save, buf, sizeof(buf_save));
220++ buf_save[MAX_BUFSIZE - 1] = 0;
221++
222+ char *chain_argv[MAX_INPUT] = {0};
223+ int chain_argc = 0;
224+ if (parser_arg(buf, (int)strlen(buf), &chain_argc, chain_argv) != SUCCESS)
225+@@ -519,15 +518,12 @@ int do_enable(int argc, char *const *argv)
226+ char config_path[PATH_MAX] = {0};
227+ struct sock_param filter_rules = {0};
228+ struct mesh_service_info fds = {0};
229+- int ret;
230+
231+ if (set_rlimit() != SUCCESS)
232+ return FAILED;
233+
234+- if ((ret = strcpy_s(config_path, PATH_MAX, CONFIGFILE_PATH)) != EOK) {
235+- macli_log(ERR, "system copy string failed! errno:%d\n", ret);
236+- return FAILED;
237+- }
238++ (void)memset(config_path, 0x0, PATH_MAX);
239++ (void)strncpy(config_path, CONFIGFILE_PATH, PATH_MAX - 1);
240+
241+ if (enable_get_opt(argc, argv, config_path, &is_help) != SUCCESS)
242+ return FAILED;
243+diff --git a/oncn-mda/include/log.h b/oncn-mda/include/log.h
244+index bfc026f..86162e0 100644
245+--- a/oncn-mda/include/log.h
246++++ b/oncn-mda/include/log.h
247+@@ -8,7 +8,6 @@
248+ #include <stdlib.h>
249+ #include <time.h>
250+ #include <stdarg.h>
251+-#include "securec.h"
252+
253+ enum LOG_LEVEL { FATAL = 0, ERR, WARN, INFO, DEBUG };
254+
255+diff --git a/oncn-mda/include/macli.h b/oncn-mda/include/macli.h
256+index ebe8f69..1db7e7a 100644
257+--- a/oncn-mda/include/macli.h
258++++ b/oncn-mda/include/macli.h
259+@@ -20,7 +20,6 @@
260+ #include <netinet/in.h>
261+ #include <arpa/inet.h>
262+ #include <sys/stat.h>
263+-#include "securec.h"
264+ #include "data.h"
265+ #include "log.h"
266+
267+--
268+2.33.0
269+