mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-05 08:09:07 +08:00
libbpf: Support creating and destroying qdisc
Extend struct bpf_tc_hook with handle, qdisc name and a new attach type, BPF_TC_QDISC, to allow users to add or remove any qdisc specified in addition to clsact. Signed-off-by: Amery Hung <amery.hung@bytedance.com> Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org> Acked-by: Toke Høiland-Jørgensen <toke@redhat.com> Link: https://patch.msgid.link/20250409214606.2000194-8-ameryhung@gmail.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
52b9b38a22
commit
f580871b42
@@ -1289,6 +1289,7 @@ enum bpf_tc_attach_point {
|
|||||||
BPF_TC_INGRESS = 1 << 0,
|
BPF_TC_INGRESS = 1 << 0,
|
||||||
BPF_TC_EGRESS = 1 << 1,
|
BPF_TC_EGRESS = 1 << 1,
|
||||||
BPF_TC_CUSTOM = 1 << 2,
|
BPF_TC_CUSTOM = 1 << 2,
|
||||||
|
BPF_TC_QDISC = 1 << 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BPF_TC_PARENT(a, b) \
|
#define BPF_TC_PARENT(a, b) \
|
||||||
@@ -1303,9 +1304,11 @@ struct bpf_tc_hook {
|
|||||||
int ifindex;
|
int ifindex;
|
||||||
enum bpf_tc_attach_point attach_point;
|
enum bpf_tc_attach_point attach_point;
|
||||||
__u32 parent;
|
__u32 parent;
|
||||||
|
__u32 handle;
|
||||||
|
const char *qdisc;
|
||||||
size_t :0;
|
size_t :0;
|
||||||
};
|
};
|
||||||
#define bpf_tc_hook__last_field parent
|
#define bpf_tc_hook__last_field qdisc
|
||||||
|
|
||||||
struct bpf_tc_opts {
|
struct bpf_tc_opts {
|
||||||
size_t sz;
|
size_t sz;
|
||||||
|
|||||||
@@ -529,9 +529,9 @@ int bpf_xdp_query_id(int ifindex, int flags, __u32 *prog_id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef int (*qdisc_config_t)(struct libbpf_nla_req *req);
|
typedef int (*qdisc_config_t)(struct libbpf_nla_req *req, const struct bpf_tc_hook *hook);
|
||||||
|
|
||||||
static int clsact_config(struct libbpf_nla_req *req)
|
static int clsact_config(struct libbpf_nla_req *req, const struct bpf_tc_hook *hook)
|
||||||
{
|
{
|
||||||
req->tc.tcm_parent = TC_H_CLSACT;
|
req->tc.tcm_parent = TC_H_CLSACT;
|
||||||
req->tc.tcm_handle = TC_H_MAKE(TC_H_CLSACT, 0);
|
req->tc.tcm_handle = TC_H_MAKE(TC_H_CLSACT, 0);
|
||||||
@@ -539,6 +539,16 @@ static int clsact_config(struct libbpf_nla_req *req)
|
|||||||
return nlattr_add(req, TCA_KIND, "clsact", sizeof("clsact"));
|
return nlattr_add(req, TCA_KIND, "clsact", sizeof("clsact"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int qdisc_config(struct libbpf_nla_req *req, const struct bpf_tc_hook *hook)
|
||||||
|
{
|
||||||
|
const char *qdisc = OPTS_GET(hook, qdisc, NULL);
|
||||||
|
|
||||||
|
req->tc.tcm_parent = OPTS_GET(hook, parent, TC_H_ROOT);
|
||||||
|
req->tc.tcm_handle = OPTS_GET(hook, handle, 0);
|
||||||
|
|
||||||
|
return nlattr_add(req, TCA_KIND, qdisc, strlen(qdisc) + 1);
|
||||||
|
}
|
||||||
|
|
||||||
static int attach_point_to_config(struct bpf_tc_hook *hook,
|
static int attach_point_to_config(struct bpf_tc_hook *hook,
|
||||||
qdisc_config_t *config)
|
qdisc_config_t *config)
|
||||||
{
|
{
|
||||||
@@ -552,6 +562,9 @@ static int attach_point_to_config(struct bpf_tc_hook *hook,
|
|||||||
return 0;
|
return 0;
|
||||||
case BPF_TC_CUSTOM:
|
case BPF_TC_CUSTOM:
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
case BPF_TC_QDISC:
|
||||||
|
*config = &qdisc_config;
|
||||||
|
return 0;
|
||||||
default:
|
default:
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
@@ -596,7 +609,7 @@ static int tc_qdisc_modify(struct bpf_tc_hook *hook, int cmd, int flags)
|
|||||||
req.tc.tcm_family = AF_UNSPEC;
|
req.tc.tcm_family = AF_UNSPEC;
|
||||||
req.tc.tcm_ifindex = OPTS_GET(hook, ifindex, 0);
|
req.tc.tcm_ifindex = OPTS_GET(hook, ifindex, 0);
|
||||||
|
|
||||||
ret = config(&req);
|
ret = config(&req, hook);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@@ -639,6 +652,7 @@ int bpf_tc_hook_destroy(struct bpf_tc_hook *hook)
|
|||||||
case BPF_TC_INGRESS:
|
case BPF_TC_INGRESS:
|
||||||
case BPF_TC_EGRESS:
|
case BPF_TC_EGRESS:
|
||||||
return libbpf_err(__bpf_tc_detach(hook, NULL, true));
|
return libbpf_err(__bpf_tc_detach(hook, NULL, true));
|
||||||
|
case BPF_TC_QDISC:
|
||||||
case BPF_TC_INGRESS | BPF_TC_EGRESS:
|
case BPF_TC_INGRESS | BPF_TC_EGRESS:
|
||||||
return libbpf_err(tc_qdisc_delete(hook));
|
return libbpf_err(tc_qdisc_delete(hook));
|
||||||
case BPF_TC_CUSTOM:
|
case BPF_TC_CUSTOM:
|
||||||
|
|||||||
Reference in New Issue
Block a user