[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250501223025.569020-4-ameryhung@gmail.com>
Date: Thu, 1 May 2025 15:30:23 -0700
From: Amery Hung <ameryhung@...il.com>
To: bpf@...r.kernel.org
Cc: netdev@...r.kernel.org,
alexei.starovoitov@...il.com,
andrii@...nel.org,
daniel@...earbox.net,
martin.lau@...nel.org,
xiyou.wangcong@...il.com,
kernel-team@...a.com
Subject: [PATCH bpf-next/net v1 3/5] bpf: net_sched: Make some Qdisc_ops ops mandatory
The patch makes all currently supported Qdisc_ops (i.e., .enqueue,
.dequeue, .init, .reser, and .destroy) mandatory.
Make .init, .reset and .destroy mandatory as bpf qdisc relies on prologue
and epilogue to check attach points and correctly initialize/cleanup
resources. The prologue/epilogue will only be generated for an struct_ops
operator only if users implement the operator.
Make .enqueue and .dequeue mandatory as bpf qdisc infra does not provide
a default data path.
Fixes: Fixes: c8240344956e ("bpf: net_sched: Support implementation of Qdisc_ops in bpf")
Signed-off-by: Amery Hung <ameryhung@...il.com>
---
net/sched/bpf_qdisc.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/net/sched/bpf_qdisc.c b/net/sched/bpf_qdisc.c
index a8efc3ff2b7e..7ea8b54b2ab1 100644
--- a/net/sched/bpf_qdisc.c
+++ b/net/sched/bpf_qdisc.c
@@ -395,6 +395,17 @@ static void bpf_qdisc_unreg(void *kdata, struct bpf_link *link)
return unregister_qdisc(kdata);
}
+static int bpf_qdisc_validate(void *kdata)
+{
+ struct Qdisc_ops *ops = (struct Qdisc_ops *)kdata;
+
+ if (!ops->enqueue || !ops->dequeue || !ops->init ||
+ !ops->reset || !ops->destroy)
+ return -EINVAL;
+
+ return 0;
+}
+
static int Qdisc_ops__enqueue(struct sk_buff *skb__ref, struct Qdisc *sch,
struct sk_buff **to_free)
{
@@ -432,6 +443,7 @@ static struct bpf_struct_ops bpf_Qdisc_ops = {
.verifier_ops = &bpf_qdisc_verifier_ops,
.reg = bpf_qdisc_reg,
.unreg = bpf_qdisc_unreg,
+ .validate = bpf_qdisc_validate,
.init_member = bpf_qdisc_init_member,
.init = bpf_qdisc_init,
.name = "Qdisc_ops",
--
2.47.1
Powered by blists - more mailing lists