Compare commits
10 Commits
a3b6c65ae7
...
0e77cc0909
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0e77cc0909 | ||
|
|
483829d9ae | ||
|
|
d62764f0a7 | ||
|
|
40468d9e2b | ||
|
|
2e68aafcaf | ||
|
|
d93f8041ee | ||
|
|
5da42ada1d | ||
|
|
dcafd39f3f | ||
|
|
05022d4e54 | ||
|
|
d309c7039f |
148
0005-fix-some-review-issues.patch
Normal file
148
0005-fix-some-review-issues.patch
Normal file
@ -0,0 +1,148 @@
|
||||
From 569ff66dc15ad3dca45e8297c7ab5b5425901f97 Mon Sep 17 00:00:00 2001
|
||||
From: kwb0523 <kwb0523@163.com>
|
||||
Date: Wed, 13 Sep 2023 11:11:32 +0800
|
||||
Subject: [PATCH] fix some review issues
|
||||
|
||||
1.fix segment fault triggered by unsupported command operations
|
||||
2.fix incorrect use of securec function parameters
|
||||
3.remove redundant cmd option 'V'
|
||||
---
|
||||
bwmcli.c | 37 +++++++++++++++++++++++--------------
|
||||
1 file changed, 23 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/bwmcli.c b/bwmcli.c
|
||||
index 8ea17d6..b878fc7 100644
|
||||
--- a/bwmcli.c
|
||||
+++ b/bwmcli.c
|
||||
@@ -315,7 +315,7 @@ static bool CheckCgrpV1PathLegal(const char *cgrpPath, char *trustedPath)
|
||||
return false;
|
||||
}
|
||||
|
||||
- int ret = snprintf_s(trustedPath, PATH_MAX + 1, PATH_MAX + 1, "%s/%s", trustedCgrpPath, "net_cls.classid");
|
||||
+ int ret = snprintf_s(trustedPath, PATH_MAX + 1, PATH_MAX, "%s/%s", trustedCgrpPath, "net_cls.classid");
|
||||
if (ret < 0 || stat(trustedPath, &st) < 0 || (st.st_mode & S_IFMT) != S_IFREG) {
|
||||
BWM_LOG_ERR("CgrpV1Prio get realPath failed. ret: %d\n", ret);
|
||||
return false;
|
||||
@@ -348,7 +348,7 @@ static int CgrpV1Prio(const char *cgrpPath, int prio, int op)
|
||||
|
||||
switch (op) {
|
||||
case PRIO_SET:
|
||||
- ret = snprintf_s(buf, BUF_SIZE, BUF_SIZE, "%u\n", (__u32)prio);
|
||||
+ ret = snprintf_s(buf, BUF_SIZE, BUF_SIZE - 1, "%u\n", (__u32)prio);
|
||||
if (ret < 0) {
|
||||
BWM_LOG_ERR("CgrpV1Prio snprintf_s prio failed. ret: %d.\n", ret);
|
||||
(void)close(fd);
|
||||
@@ -501,7 +501,7 @@ end:
|
||||
static int NetdevEnabledSub(const char *format, const char *ethdev)
|
||||
{
|
||||
int ret;
|
||||
- ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN, format, ethdev);
|
||||
+ ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN - 1, format, ethdev);
|
||||
if (ret < 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -547,7 +547,7 @@ static int DisableSpecificNetdevice(const char *ethdev, const void *unused)
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(g_disableSeq) / sizeof(struct TcCmd); i++) {
|
||||
- ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN, g_disableSeq[i].cmdStr, ethdev);
|
||||
+ ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN - 1, g_disableSeq[i].cmdStr, ethdev);
|
||||
if (ret < 0 || g_cmdBuf[MAX_CMD_LEN - 1] != '\0') {
|
||||
BWM_LOG_ERR("Invalid net device: %s\n", ethdev);
|
||||
return EXIT_FAIL_OPTION;
|
||||
@@ -574,7 +574,7 @@ static bool execute_cmd(const char *format, const char *ethdev, const char *sear
|
||||
{
|
||||
int ret;
|
||||
|
||||
- ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN, format, ethdev, search);
|
||||
+ ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN - 1, format, ethdev, search);
|
||||
if (ret < 0 || g_cmdBuf[MAX_CMD_LEN - 1] != '\0') {
|
||||
g_cmdBuf[MAX_CMD_LEN - 1] = '\0';
|
||||
BWM_LOG_ERR("Invalid cmd: %s\n", g_cmdBuf);
|
||||
@@ -652,7 +652,7 @@ static int EnableSpecificNetdevice(const char *ethdev, const void *unused)
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(g_enableSeq) / sizeof(struct TcCmd); i++) {
|
||||
- ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN, g_enableSeq[i].cmdStr, ethdev);
|
||||
+ ret = snprintf_s(g_cmdBuf, MAX_CMD_LEN, MAX_CMD_LEN - 1, g_enableSeq[i].cmdStr, ethdev);
|
||||
if (ret < 0 || g_cmdBuf[MAX_CMD_LEN - 1] != '\0') {
|
||||
BWM_LOG_ERR("Invalid net device: %s\n", ethdev);
|
||||
return EXIT_FAIL_OPTION;
|
||||
@@ -817,7 +817,12 @@ static int GetCfgsInfo(char *cfg, int cfgLen)
|
||||
struct CfgOption *option;
|
||||
|
||||
option = FindOptions(cfg);
|
||||
- return option->op.getCfg(cfg);
|
||||
+ if (option->op.getCfg) {
|
||||
+ return option->op.getCfg(cfg);
|
||||
+ }
|
||||
+
|
||||
+ (void)fprintf(stderr, "invalid operation: %s can't support get operation\n", option->name);
|
||||
+ return EXIT_FAIL;
|
||||
}
|
||||
|
||||
static int SetCfgsInfo(char *cfg, int cfgLen, char *args, int argsLen)
|
||||
@@ -825,7 +830,12 @@ static int SetCfgsInfo(char *cfg, int cfgLen, char *args, int argsLen)
|
||||
struct CfgOption *option;
|
||||
|
||||
option = FindOptions(cfg);
|
||||
- return option->op.setCfg(cfg, args);
|
||||
+ if (option->op.setCfg) {
|
||||
+ return option->op.setCfg(cfg, args);
|
||||
+ }
|
||||
+
|
||||
+ (void)fprintf(stderr, "invalid operation: %s can't support set operation\n", option->name);
|
||||
+ return EXIT_FAIL;
|
||||
}
|
||||
|
||||
static int BreakMultiArgs(char *args, char arg1[], char arg2[], int mutilArgs)
|
||||
@@ -919,7 +929,7 @@ static int CfgsInfo(int argc, char *const *argv, int isSet)
|
||||
char option[PATH_MAX + 1] = {0};
|
||||
char args[PRIO_LEN] = {0};
|
||||
|
||||
- rc = strncpy_s(option, PATH_MAX + 1, optarg, PATH_MAX + 1);
|
||||
+ rc = strncpy_s(option, PATH_MAX + 1, optarg, PATH_MAX);
|
||||
if (rc != EOK || option[PATH_MAX] != '\0') {
|
||||
(void)fprintf(stderr, "invalid option, too long: %s\n", optarg);
|
||||
return EXIT_FAIL_OPTION;
|
||||
@@ -934,7 +944,7 @@ static int CfgsInfo(int argc, char *const *argv, int isSet)
|
||||
return ret;
|
||||
}
|
||||
|
||||
- rc = strncpy_s(args, PRIO_LEN, argv[optind], strlen(argv[optind]));
|
||||
+ rc = strncpy_s(args, PRIO_LEN, argv[optind], PRIO_LEN - 1);
|
||||
if (rc != EOK || args[PRIO_LEN - 1] != '\0') {
|
||||
(void)fprintf(stderr, "invalid args, too long: %s\n", argv[optind]);
|
||||
return EXIT_FAIL_OPTION;
|
||||
@@ -974,9 +984,9 @@ static int ChangeNetdeviceStatus(int argc, char *const *argv, int enable)
|
||||
}
|
||||
|
||||
if (optarg != NULL) {
|
||||
- rc = strncpy_s(ethdev, NAME_MAX + 1, optarg, NAME_MAX + 1);
|
||||
+ rc = strncpy_s(ethdev, NAME_MAX + 1, optarg, NAME_MAX);
|
||||
} else {
|
||||
- rc = strncpy_s(ethdev, NAME_MAX + 1, argv[optind], NAME_MAX + 1);
|
||||
+ rc = strncpy_s(ethdev, NAME_MAX + 1, argv[optind], NAME_MAX);
|
||||
optind++;
|
||||
}
|
||||
|
||||
@@ -1266,7 +1276,7 @@ int main(int argc, char **argv)
|
||||
return EXIT_FAIL_OPTION;
|
||||
}
|
||||
|
||||
- while ((opt = getopt_long(argc, argv, "vVhe::d::p:s:", g_longOptions, &longindex)) != -1) {
|
||||
+ while ((opt = getopt_long(argc, argv, "vhe::d::p:s:", g_longOptions, &longindex)) != -1) {
|
||||
hasOptions = 1;
|
||||
isSet = 1;
|
||||
enable = 1;
|
||||
@@ -1274,7 +1284,6 @@ int main(int argc, char **argv)
|
||||
|
||||
switch (opt) {
|
||||
case 'v':
|
||||
- case 'V':
|
||||
BWM_LOG_INFO("version: %s\n", BWM_VERSION);
|
||||
break;
|
||||
case 'p':
|
||||
--
|
||||
2.33.0
|
||||
|
||||
25
0006-fix-input-options-unused-warning.patch
Normal file
25
0006-fix-input-options-unused-warning.patch
Normal file
@ -0,0 +1,25 @@
|
||||
From f54634902900764327a138e44c295b293b4f6650 Mon Sep 17 00:00:00 2001
|
||||
From: 15859157387 <977713017@qq.com>
|
||||
Date: Thu, 10 Aug 2023 14:34:00 +0800
|
||||
Subject: [PATCH] cmake change
|
||||
|
||||
---
|
||||
CMakeLists.txt | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index 70b47e7..d6560c1 100755
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -1,7 +1,7 @@
|
||||
cmake_minimum_required(VERSION 3.12.1)
|
||||
project(bwmcli LANGUAGES C )
|
||||
-set(CMAKE_C_FLAGS "-g -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Werror -ftrapv -O2 -Wl,-z,noexecstack \
|
||||
- -Wl,-z,relro -fPIE -pie -Wl,-z,now")
|
||||
+set(CMAKE_C_FLAGS "-g -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -Werror -ftrapv -O2")
|
||||
+set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-z,noexecstack -Wl,-z,relro -fPIE -pie -Wl,-z,now")
|
||||
|
||||
include_directories("${PROJECT_SOURCE_DIR}/")
|
||||
include_directories("${PROJECT_SOURCE_DIR}/bpf")
|
||||
--
|
||||
2.27.0
|
||||
28
0007-fix-net_qos_stats-warning-when-qos-not-enable.patch
Normal file
28
0007-fix-net_qos_stats-warning-when-qos-not-enable.patch
Normal file
@ -0,0 +1,28 @@
|
||||
From f10ec3e0c83efedb238f1ed55e007f4905410463 Mon Sep 17 00:00:00 2001
|
||||
From: kwb0523 <kwb0523@163.com>
|
||||
Date: Wed, 18 Oct 2023 16:29:50 +0800
|
||||
Subject: [PATCH] fix net_qos_stats warning when qos not enable
|
||||
|
||||
---
|
||||
ko/bwm.c | 4 ----
|
||||
1 file changed, 4 deletions(-)
|
||||
|
||||
diff --git a/ko/bwm.c b/ko/bwm.c
|
||||
index 6be6cbe..8951217 100644
|
||||
--- a/ko/bwm.c
|
||||
+++ b/ko/bwm.c
|
||||
@@ -310,11 +310,7 @@ static int proc_net_qos_stats_single_open(struct inode *inode, struct file *file
|
||||
ret = qos_cmd_upcall(cmd);
|
||||
if (ret != 0) {
|
||||
BWM_LOG_ERR("read net_qos_stats failed");
|
||||
- atomic_xchg(&stats_flag, 0);
|
||||
- return ret;
|
||||
}
|
||||
- single_open(file, proc_net_qos_stats_open, NULL);
|
||||
- return 0;
|
||||
}
|
||||
atomic_xchg(&stats_flag, 0);
|
||||
return single_open(file, proc_net_qos_stats_open, NULL);
|
||||
--
|
||||
2.33.0
|
||||
|
||||
70
0008-adapt-map-define-for-libbpf-1.2.2.patch
Normal file
70
0008-adapt-map-define-for-libbpf-1.2.2.patch
Normal file
@ -0,0 +1,70 @@
|
||||
From bc1ac8f89714535f3cdcae4aa970d4a82d5bcf5c Mon Sep 17 00:00:00 2001
|
||||
From: kwb0523 <kwb0523@163.com>
|
||||
Date: Wed, 24 Apr 2024 10:53:19 +0800
|
||||
Subject: [PATCH] adapt map define for libbpf-1.2.2
|
||||
|
||||
---
|
||||
bpf/bwm_tc.c | 47 +++++++++++++++++------------------------------
|
||||
1 file changed, 17 insertions(+), 30 deletions(-)
|
||||
|
||||
diff --git a/bpf/bwm_tc.c b/bpf/bwm_tc.c
|
||||
index d04d454..72bb944 100644
|
||||
--- a/bpf/bwm_tc.c
|
||||
+++ b/bpf/bwm_tc.c
|
||||
@@ -22,36 +22,23 @@
|
||||
#define PIN_GLOBAL_NS 2
|
||||
#define OFFLINE_PRIO ((unsigned int)-1)
|
||||
|
||||
-struct bpf_elf_map_t {
|
||||
- __u32 type;
|
||||
- __u32 key_size;
|
||||
- __u32 value_size;
|
||||
- __u32 max_elem;
|
||||
- __u32 flags;
|
||||
- __u32 id;
|
||||
- __u32 pinning;
|
||||
-};
|
||||
-
|
||||
-
|
||||
-struct bpf_elf_map_t SEC("maps") throttle_cfg = {
|
||||
- .type = BPF_MAP_TYPE_ARRAY,
|
||||
- .key_size = sizeof(unsigned int),
|
||||
- .value_size = sizeof(struct edt_throttle_cfg),
|
||||
- .pinning = PIN_GLOBAL_NS,
|
||||
- .max_elem = 1,
|
||||
- .flags = 0,
|
||||
- .id = 0,
|
||||
-};
|
||||
-
|
||||
-struct bpf_elf_map_t SEC("maps") throttle_map = {
|
||||
- .type = BPF_MAP_TYPE_ARRAY,
|
||||
- .key_size = sizeof(unsigned int),
|
||||
- .value_size = sizeof(struct edt_throttle),
|
||||
- .pinning = PIN_GLOBAL_NS,
|
||||
- .max_elem = 1,
|
||||
- .flags = 0,
|
||||
- .id = 0,
|
||||
-};
|
||||
+struct {
|
||||
+ __uint(type, BPF_MAP_TYPE_ARRAY);
|
||||
+ __uint(key_size, sizeof(unsigned int));
|
||||
+ __uint(value_size, sizeof(struct edt_throttle_cfg));
|
||||
+ __uint(max_entries, 1);
|
||||
+ __uint(map_flags, 0);
|
||||
+ __uint(pinning, LIBBPF_PIN_BY_NAME);
|
||||
+} throttle_cfg SEC(".maps");
|
||||
+
|
||||
+struct {
|
||||
+ __uint(type, BPF_MAP_TYPE_ARRAY);
|
||||
+ __uint(key_size, sizeof(unsigned int));
|
||||
+ __uint(value_size, sizeof(struct edt_throttle));
|
||||
+ __uint(max_entries, 1);
|
||||
+ __uint(map_flags, 0);
|
||||
+ __uint(pinning, LIBBPF_PIN_BY_NAME);
|
||||
+} throttle_map SEC(".maps");
|
||||
|
||||
static void throttle_init(const struct edt_throttle_cfg *cfg, struct edt_throttle *throttle)
|
||||
{
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
Name: oncn-bwm
|
||||
Version: 1.1
|
||||
Release: 4
|
||||
Release: 9
|
||||
Summary: Pod bandwidth management in mixed deployment scenarios of online and offline services
|
||||
License: GPL-2.0
|
||||
URL: https://gitee.com/src-openeuler/oncn-bwm
|
||||
@ -18,6 +18,10 @@ Patch9001: 0001-adapt-libbpf-0.8.1.patch
|
||||
Patch9002: 0002-clean-code-and-use-securec-function.patch
|
||||
Patch9003: 0003-add-proc-file-interface.patch
|
||||
Patch9004: 0004-fix-offline-packets-block.patch
|
||||
Patch9005: 0005-fix-some-review-issues.patch
|
||||
Patch9006: 0006-fix-input-options-unused-warning.patch
|
||||
Patch9007: 0007-fix-net_qos_stats-warning-when-qos-not-enable.patch
|
||||
Patch9008: 0008-adapt-map-define-for-libbpf-1.2.2.patch
|
||||
|
||||
%description
|
||||
Pod bandwidth management in mixed deployment scenarios of online and offline services
|
||||
@ -42,8 +46,8 @@ make
|
||||
%install
|
||||
mkdir -p %{buildroot}/%{_bindir}/%{name}
|
||||
mkdir -p %{buildroot}/usr/share/bwmcli
|
||||
install -Dpm 0500 %{_builddir}/%{name}-%{version}/build/bpf/CMakeFiles/bwm_prio_kern.dir/bwm_prio_kern.c.o %{buildroot}/usr/share/bwmcli/bwm_prio_kern.o
|
||||
install -Dpm 0500 %{_builddir}/%{name}-%{version}/build/bpf/CMakeFiles/bwm_tc.dir/bwm_tc.c.o %{buildroot}/usr/share/bwmcli/bwm_tc.o
|
||||
install -Dpm 0400 %{_builddir}/%{name}-%{version}/build/bpf/CMakeFiles/bwm_prio_kern.dir/bwm_prio_kern.c.o %{buildroot}/usr/share/bwmcli/bwm_prio_kern.o
|
||||
install -Dpm 0400 %{_builddir}/%{name}-%{version}/build/bpf/CMakeFiles/bwm_tc.dir/bwm_tc.c.o %{buildroot}/usr/share/bwmcli/bwm_tc.o
|
||||
install -Dpm 0500 %{_builddir}/%{name}-%{version}/build/bwmcli %{buildroot}/%{_bindir}
|
||||
install -Dpm 0500 %{_builddir}/%{name}-%{version}/tools/bwm_monitor.bt %{buildroot}/%{_bindir}
|
||||
mkdir -p %{buildroot}/lib/modules/bwm
|
||||
@ -101,9 +105,9 @@ depmod -a
|
||||
%files
|
||||
%defattr(-,root,root)
|
||||
%attr(0500,root,root) %{_bindir}/bwmcli
|
||||
%attr(0500,root,root) /usr/share/bwmcli
|
||||
%attr(0500,root,root) /usr/share/bwmcli/bwm_prio_kern.o
|
||||
%attr(0500,root,root) /usr/share/bwmcli/bwm_tc.o
|
||||
%attr(0500,root,root) %dir /usr/share/bwmcli
|
||||
%attr(0400,root,root) /usr/share/bwmcli/bwm_prio_kern.o
|
||||
%attr(0400,root,root) /usr/share/bwmcli/bwm_tc.o
|
||||
%attr(0550,root,root) %dir /lib/modules/bwm
|
||||
%attr(0440,root,root) /lib/modules/bwm/bwm.ko
|
||||
|
||||
@ -112,6 +116,24 @@ depmod -a
|
||||
|
||||
|
||||
%changelog
|
||||
* Tue Dec 17 2024 liwei <1289113577@qq.com> - 1.1-9
|
||||
- modify ebpf prog permissions
|
||||
|
||||
* Wed Apr 24 2024 JofDiamonds <kwb0523@163.com> - 1.1-8
|
||||
- adapt map define for libbpf-1.2.2
|
||||
|
||||
* Wed Oct 18 2023 JofDiamonds <kwb0523@163.com> - 1.1-7
|
||||
- fix net_qos_stats warning when qos not enable
|
||||
|
||||
* Mon Sep 25 2023 cf-zhao <zhaochuanfeng@huawei.com> - 1.1-6
|
||||
- fix input options unused warning to fix clang built error
|
||||
|
||||
* Wed Sep 13 2023 JofDiamonds <kwb0523@163.com> - 1.1-5
|
||||
- fix some review issues:
|
||||
1.fix segment fault triggered by unsupported command operations
|
||||
2.fix incorrect use of securec function parameters
|
||||
3.remove redundant cmd option 'V'
|
||||
|
||||
* Sat May 20 2023 JofDiamonds <kwb0523@163.com> - 1.1-4
|
||||
- fix offline packets block
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user