summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2016-05-13 13:08:26 -0400
committerDavid S. Miller <davem@davemloft.net>2016-05-16 13:49:31 -0400
commit4936e3528e3e272c567fe4ff0abb7ce3e1500575 (patch)
treefe605512827310535b99290d24ccc9fe0c57afef /net
parent553eb544444e28749e2d752dee11e2ae4a3ecfb6 (diff)
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: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/core/filter.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/net/core/filter.c b/net/core/filter.c
index 71c2a1f473ad..ea51b479cf02 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2069,16 +2069,12 @@ tc_cls_act_func_proto(enum bpf_func_id func_id)
2069 2069
2070static bool __is_valid_access(int off, int size, enum bpf_access_type type) 2070static bool __is_valid_access(int off, int size, enum bpf_access_type type)
2071{ 2071{
2072 /* check bounds */
2073 if (off < 0 || off >= sizeof(struct __sk_buff)) 2072 if (off < 0 || off >= sizeof(struct __sk_buff))
2074 return false; 2073 return false;
2075 2074 /* The verifier guarantees that size > 0. */
2076 /* disallow misaligned access */
2077 if (off % size != 0) 2075 if (off % size != 0)
2078 return false; 2076 return false;
2079 2077 if (size != sizeof(__u32))
2080 /* all __sk_buff fields are __u32 */
2081 if (size != 4)
2082 return false; 2078 return false;
2083 2079
2084 return true; 2080 return true;
@@ -2097,7 +2093,7 @@ static bool sk_filter_is_valid_access(int off, int size,
2097 if (type == BPF_WRITE) { 2093 if (type == BPF_WRITE) {
2098 switch (off) { 2094 switch (off) {
2099 case offsetof(struct __sk_buff, cb[0]) ... 2095 case offsetof(struct __sk_buff, cb[0]) ...
2100 offsetof(struct __sk_buff, cb[4]): 2096 offsetof(struct __sk_buff, cb[4]):
2101 break; 2097 break;
2102 default: 2098 default:
2103 return false; 2099 return false;
@@ -2278,30 +2274,30 @@ static u32 bpf_net_convert_ctx_access(enum bpf_access_type type, int dst_reg,
2278} 2274}
2279 2275
2280static const struct bpf_verifier_ops sk_filter_ops = { 2276static const struct bpf_verifier_ops sk_filter_ops = {
2281 .get_func_proto = sk_filter_func_proto, 2277 .get_func_proto = sk_filter_func_proto,
2282 .is_valid_access = sk_filter_is_valid_access, 2278 .is_valid_access = sk_filter_is_valid_access,
2283 .convert_ctx_access = bpf_net_convert_ctx_access, 2279 .convert_ctx_access = bpf_net_convert_ctx_access,
2284}; 2280};
2285 2281
2286static const struct bpf_verifier_ops tc_cls_act_ops = { 2282static const struct bpf_verifier_ops tc_cls_act_ops = {
2287 .get_func_proto = tc_cls_act_func_proto, 2283 .get_func_proto = tc_cls_act_func_proto,
2288 .is_valid_access = tc_cls_act_is_valid_access, 2284 .is_valid_access = tc_cls_act_is_valid_access,
2289 .convert_ctx_access = bpf_net_convert_ctx_access, 2285 .convert_ctx_access = bpf_net_convert_ctx_access,
2290}; 2286};
2291 2287
2292static struct bpf_prog_type_list sk_filter_type __read_mostly = { 2288static struct bpf_prog_type_list sk_filter_type __read_mostly = {
2293 .ops = &sk_filter_ops, 2289 .ops = &sk_filter_ops,
2294 .type = BPF_PROG_TYPE_SOCKET_FILTER, 2290 .type = BPF_PROG_TYPE_SOCKET_FILTER,
2295}; 2291};
2296 2292
2297static struct bpf_prog_type_list sched_cls_type __read_mostly = { 2293static struct bpf_prog_type_list sched_cls_type __read_mostly = {
2298 .ops = &tc_cls_act_ops, 2294 .ops = &tc_cls_act_ops,
2299 .type = BPF_PROG_TYPE_SCHED_CLS, 2295 .type = BPF_PROG_TYPE_SCHED_CLS,
2300}; 2296};
2301 2297
2302static struct bpf_prog_type_list sched_act_type __read_mostly = { 2298static struct bpf_prog_type_list sched_act_type __read_mostly = {
2303 .ops = &tc_cls_act_ops, 2299 .ops = &tc_cls_act_ops,
2304 .type = BPF_PROG_TYPE_SCHED_ACT, 2300 .type = BPF_PROG_TYPE_SCHED_ACT,
2305}; 2301};
2306 2302
2307static int __init register_sk_filter_ops(void) 2303static int __init register_sk_filter_ops(void)