Compare commits

..

No commits in common. "2f6de32f125b7c61160bbb557ac0a09bbe0de5a7" and "812e58054e4d01b52c3de8ee2d2f099e6feb6ed6" have entirely different histories.

6 changed files with 6 additions and 325 deletions

View File

@ -1,95 +0,0 @@
From b928100cf448012a54b95fe1a983c7ff7a0c8823 Mon Sep 17 00:00:00 2001
From: JofDiamonds <kwb0523@163.com>
Date: Fri, 19 May 2023 18:28:09 +0800
Subject: [PATCH] fix offline packets block
---
bpf/bwm_tc.c | 15 ++++++++++-----
bpf/bwm_tc.h | 6 ++++++
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/bpf/bwm_tc.c b/bpf/bwm_tc.c
index 286783a..d04d454 100644
--- a/bpf/bwm_tc.c
+++ b/bpf/bwm_tc.c
@@ -68,12 +68,13 @@ static void bwm_online(const struct __sk_buff *skb, struct edt_throttle *throttl
__sync_fetch_and_add(&throttle->stats.online_pkts, 1);
}
-static void bwm_offline(struct __sk_buff *skb, struct edt_throttle *throttle)
+static int bwm_offline(struct __sk_buff *skb, struct edt_throttle *throttle)
{
unsigned long long t_cur;
unsigned long long t_send;
unsigned long long t_delay;
unsigned long long t_next;
+ unsigned long long t_last = throttle->t_last;
__sync_fetch_and_add(&throttle->tx_bytes, skb->len);
__sync_fetch_and_add(&throttle->stats.offline_pkts, 1);
@@ -85,17 +86,20 @@ static void bwm_offline(struct __sk_buff *skb, struct edt_throttle *throttle)
if (t_send < t_cur)
t_send = t_cur;
+ if ((skb->sk) && (bpf_tcp_sock(skb->sk) == NULL) && (t_last > t_cur) && ((t_last - t_cur) > MAX_DELAY_STAMP))
+ return TC_ACT_SHOT;
+
t_delay = skb->len * NSEC_PER_SEC / throttle->rate;
t_next = throttle->t_last + t_delay;
if (t_next <= t_send) {
throttle->t_last = t_send;
- return;
+ return TC_ACT_OK;
}
skb->tstamp = t_next;
throttle->t_last = t_next;
- return;
+ return TC_ACT_OK;
}
@@ -141,6 +145,7 @@ int bwm_tc(struct __sk_buff *skb)
struct edt_throttle_cfg * cfg = NULL;
unsigned int map_index = 0;
unsigned int priority_index = 0;
+ int ret = TC_ACT_OK;
cfg = bpf_map_lookup_elem(&throttle_cfg, &map_index);
if (cfg == NULL)
@@ -161,12 +166,12 @@ int bwm_tc(struct __sk_buff *skb)
if (skb->priority != OFFLINE_PRIO)
bwm_online(skb_con, throttle);
else
- bwm_offline(skb, throttle);
+ ret = bwm_offline(skb, throttle);
adjust_rate(cfg_con, throttle);
bpf_printk("[tc.c]prio=%u\n", skb->priority);
- return TC_ACT_OK;
+ return ret;
}
char _license[] SEC("license") = "GPL";
diff --git a/bpf/bwm_tc.h b/bpf/bwm_tc.h
index ff60f66..5f5ee8a 100644
--- a/bpf/bwm_tc.h
+++ b/bpf/bwm_tc.h
@@ -14,6 +14,12 @@
#define NSEC_PER_SEC (1000000000ULL)
#define NSEC_PER_MSEC (1000000ULL) // NSEC_PER_MSEC * 10 = 1s
+/*
+ * NSEC_PER_MSEC * 10 = 10s, when the offline packets overstocked exceeds this value,
+ * actively discarding non tcp packets.
+*/
+#define MAX_DELAY_STAMP (10000000000ULL)
+
#define DEFAULT_LOW_BANDWIDTH (20LL * 1024 * 1024)
#define DEFAULT_HIGH_BANDWIDTH (1LL * 1024 * 1024 * 1024)
#define DEFAULT_WATERLINE (20LL * 1024 * 1024)
--
2.33.0

View File

@ -1,148 +0,0 @@
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

View File

@ -1,25 +0,0 @@
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

View File

@ -1,28 +0,0 @@
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

View File

@ -315,10 +315,9 @@ echo '{
esac
```
## 约束限制
## 注意事项
1. 命令行接口和proc文件接口在设置离线业务带宽和在线业务水线上存在不同步的问题通过proc文件接口设置的结果可以用命令行接口查询到而通过命令行设置的结果不可以通过proc文件接口查询到。
2. 实际使用过程中带宽限速有可能造成协议栈内存积压此时依赖传输层协议自行反压对于udp等无反压机制的协议场景可能出现丢包、ENOBUFS、限速有偏差等问题。
## 参与贡献

View File

@ -1,6 +1,6 @@
Name: oncn-bwm
Version: 1.1
Release: 8
Release: 3
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
@ -17,10 +17,6 @@ Requires: libboundscheck
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
%description
Pod bandwidth management in mixed deployment scenarios of online and offline services
@ -45,8 +41,8 @@ make
%install
mkdir -p %{buildroot}/%{_bindir}/%{name}
mkdir -p %{buildroot}/usr/share/bwmcli
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/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 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
@ -105,8 +101,8 @@ depmod -a
%defattr(-,root,root)
%attr(0500,root,root) %{_bindir}/bwmcli
%attr(0500,root,root) /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(0500,root,root) /usr/share/bwmcli/bwm_prio_kern.o
%attr(0500,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
@ -115,24 +111,6 @@ depmod -a
%changelog
* Tue Dec 24 2024 liwei <1289113577@qq.com> - 1.1-8
- modify ebpf prog permisssions
* 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
* Fri May 19 2023 JofDiamonds <kwb0523@163.com> - 1.1-3
- adapt libbpf-0.8.1: prog_load_xattr will deprecated and use another way to load bpf prog