提交 4936e352 编写于 作者: D Daniel Borkmann 提交者: David S. Miller

bpf: minor cleanups in ebpf code

Besides others, remove redundant comments where the code is self
documenting enough, and properly indent various bpf_verifier_ops
and bpf_prog_type_list declarations. Moreover, remove two exports
that actually have no module user.
Signed-off-by: NDaniel Borkmann <daniel@iogearbox.net>
Acked-by: NAlexei Starovoitov <ast@kernel.org>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 553eb544
...@@ -129,14 +129,12 @@ struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size, ...@@ -129,14 +129,12 @@ struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
return fp; return fp;
} }
EXPORT_SYMBOL_GPL(bpf_prog_realloc);
void __bpf_prog_free(struct bpf_prog *fp) void __bpf_prog_free(struct bpf_prog *fp)
{ {
kfree(fp->aux); kfree(fp->aux);
vfree(fp); vfree(fp);
} }
EXPORT_SYMBOL_GPL(__bpf_prog_free);
#ifdef CONFIG_BPF_JIT #ifdef CONFIG_BPF_JIT
struct bpf_binary_header * struct bpf_binary_header *
......
...@@ -2069,16 +2069,12 @@ tc_cls_act_func_proto(enum bpf_func_id func_id) ...@@ -2069,16 +2069,12 @@ tc_cls_act_func_proto(enum bpf_func_id func_id)
static bool __is_valid_access(int off, int size, enum bpf_access_type type) static bool __is_valid_access(int off, int size, enum bpf_access_type type)
{ {
/* check bounds */
if (off < 0 || off >= sizeof(struct __sk_buff)) if (off < 0 || off >= sizeof(struct __sk_buff))
return false; return false;
/* The verifier guarantees that size > 0. */
/* disallow misaligned access */
if (off % size != 0) if (off % size != 0)
return false; return false;
if (size != sizeof(__u32))
/* all __sk_buff fields are __u32 */
if (size != 4)
return false; return false;
return true; return true;
...@@ -2097,7 +2093,7 @@ static bool sk_filter_is_valid_access(int off, int size, ...@@ -2097,7 +2093,7 @@ static bool sk_filter_is_valid_access(int off, int size,
if (type == BPF_WRITE) { if (type == BPF_WRITE) {
switch (off) { switch (off) {
case offsetof(struct __sk_buff, cb[0]) ... case offsetof(struct __sk_buff, cb[0]) ...
offsetof(struct __sk_buff, cb[4]): offsetof(struct __sk_buff, cb[4]):
break; break;
default: default:
return false; return false;
...@@ -2278,30 +2274,30 @@ static u32 bpf_net_convert_ctx_access(enum bpf_access_type type, int dst_reg, ...@@ -2278,30 +2274,30 @@ static u32 bpf_net_convert_ctx_access(enum bpf_access_type type, int dst_reg,
} }
static const struct bpf_verifier_ops sk_filter_ops = { static const struct bpf_verifier_ops sk_filter_ops = {
.get_func_proto = sk_filter_func_proto, .get_func_proto = sk_filter_func_proto,
.is_valid_access = sk_filter_is_valid_access, .is_valid_access = sk_filter_is_valid_access,
.convert_ctx_access = bpf_net_convert_ctx_access, .convert_ctx_access = bpf_net_convert_ctx_access,
}; };
static const struct bpf_verifier_ops tc_cls_act_ops = { static const struct bpf_verifier_ops tc_cls_act_ops = {
.get_func_proto = tc_cls_act_func_proto, .get_func_proto = tc_cls_act_func_proto,
.is_valid_access = tc_cls_act_is_valid_access, .is_valid_access = tc_cls_act_is_valid_access,
.convert_ctx_access = bpf_net_convert_ctx_access, .convert_ctx_access = bpf_net_convert_ctx_access,
}; };
static struct bpf_prog_type_list sk_filter_type __read_mostly = { static struct bpf_prog_type_list sk_filter_type __read_mostly = {
.ops = &sk_filter_ops, .ops = &sk_filter_ops,
.type = BPF_PROG_TYPE_SOCKET_FILTER, .type = BPF_PROG_TYPE_SOCKET_FILTER,
}; };
static struct bpf_prog_type_list sched_cls_type __read_mostly = { static struct bpf_prog_type_list sched_cls_type __read_mostly = {
.ops = &tc_cls_act_ops, .ops = &tc_cls_act_ops,
.type = BPF_PROG_TYPE_SCHED_CLS, .type = BPF_PROG_TYPE_SCHED_CLS,
}; };
static struct bpf_prog_type_list sched_act_type __read_mostly = { static struct bpf_prog_type_list sched_act_type __read_mostly = {
.ops = &tc_cls_act_ops, .ops = &tc_cls_act_ops,
.type = BPF_PROG_TYPE_SCHED_ACT, .type = BPF_PROG_TYPE_SCHED_ACT,
}; };
static int __init register_sk_filter_ops(void) static int __init register_sk_filter_ops(void)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册