20 Star 0 Fork 8

openEuler-RISC-V/oncn-bwm

forked from src-openEuler/oncn-bwm 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0001-adapt-libbpf-0.8.1.patch 3.15 KB
一键复制 编辑 原始数据 按行查看 历史
From 5e488bdb1ebb14cd16e2df640e90e7eb39ff9efa Mon Sep 17 00:00:00 2001
From: JofDiamonds <kwb0523@163.com>
Date: Sat, 20 May 2023 16:38:45 +0800
Subject: [PATCH] adapt libbpf-0.8.1
---
bpf/bwm_prio_kern.c | 14 +++++++-------
bwmcli.c | 41 +++++++++++++++++++++++++++++------------
2 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/bpf/bwm_prio_kern.c b/bpf/bwm_prio_kern.c
index 1c59322..68127f9 100644
--- a/bpf/bwm_prio_kern.c
+++ b/bpf/bwm_prio_kern.c
@@ -20,13 +20,13 @@
#define DEFAULT_CGP_PRIO 0
-struct bpf_map_def cgrp_prio SEC("maps") = {
- .type = BPF_MAP_TYPE_ARRAY,
- .key_size = sizeof(unsigned int),
- .value_size = sizeof(unsigned int),
- .max_entries = 1,
- .map_flags = 0,
-};
+struct {
+ __uint(type, BPF_MAP_TYPE_ARRAY);
+ __type(key, unsigned int);
+ __type(value, unsigned int);
+ __uint(max_entries, 1);
+ __uint(map_flags, 0);
+} cgrp_prio SEC(".maps");
SEC("cgroup_skb/egress")
int _bwm_out_cg(struct __sk_buff *skb)
diff --git a/bwmcli.c b/bwmcli.c
index f087ea6..c9fe698 100644
--- a/bwmcli.c
+++ b/bwmcli.c
@@ -212,40 +212,57 @@ static int BreakArgs(char *s, char *arg1, char *arg2, unsigned long arg1Len, uns
return EXIT_OK;
}
-static int ProgLoad(char *prog, struct bpf_object ** obj, int * bpfprogFd)
+static int ProgLoad(char *prog, struct bpf_object **obj, int * bpfprogFd)
{
- struct bpf_prog_load_attr progLoadAttr = {
- .prog_type = BPF_PROG_TYPE_CGROUP_SKB,
- .file = prog,
- .expected_attach_type = BPF_CGROUP_INET_EGRESS,
- .ifindex = 0,
- .log_level = 0,
- };
int mapFd;
struct bpf_map *map = NULL;
+ struct bpf_program *program = NULL;
if (access(prog, O_RDONLY) < 0) {
BWM_LOG_ERR("Error accessing file %s\n", prog);
return -1;
}
- if (bpf_prog_load_xattr(&progLoadAttr, &(*obj), bpfprogFd)) {
- BWM_LOG_ERR("ERROR: bpf_prog_load_xattr failed for: %s. errno:%d\n", prog, errno);
+
+ *obj = bpf_object__open(prog);
+ if (libbpf_get_error(*obj)) {
+ BWM_LOG_ERR("ERROR: bpf_object__open failed for: %s. errno:%d\n", prog, errno);
return -1;
}
+ program = bpf_object__next_program(*obj, NULL);
+ if (!program) {
+ BWM_LOG_ERR("ERROR: bpf_object__next_program failed for: %s. errno:%d\n", prog, errno);
+ goto err;
+ }
+
+ bpf_program__set_type(program, BPF_PROG_TYPE_CGROUP_SKB);
+
+ if (bpf_object__load(*obj)) {
+ BWM_LOG_ERR("ERROR: bpf_object__load failed for: %s. errno:%d\n", prog, errno);
+ goto err;
+ }
+
+ *bpfprogFd = bpf_program__fd(program);
+ if (*bpfprogFd < 0) {
+ BWM_LOG_ERR("Failed to get program fd. errno:%d\n", errno);
+ goto err;
+ }
+
map = bpf_object__find_map_by_name(*obj, "cgrp_prio");
if (!map) {
BWM_LOG_ERR("Failed to load map cgrp_prio from bpf prog. errno:%d\n", errno);
- return -1;
+ goto err;
}
mapFd = bpf_map__fd(map);
if (mapFd < 0) {
BWM_LOG_ERR("Map not found: %d. errno:%d\n", mapFd, errno);
- return -1;
+ goto err;
}
return mapFd;
+err:
+ return -1;
}
static int GetMapFdByProgId(__u32 progId)
--
2.33.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openeuler-risc-v/oncn-bwm.git
git@gitee.com:openeuler-risc-v/oncn-bwm.git
openeuler-risc-v
oncn-bwm
oncn-bwm
master

搜索帮助