Skip to content

Commit d4052c4

Browse files
borkmanndavem330
authored andcommitted
ebpf: remove CONFIG_BPF_SYSCALL ifdefs in socket filter code
This gets rid of CONFIG_BPF_SYSCALL ifdefs in the socket filter code, now that the BPF internal header can deal with it. While going over it, I also changed eBPF related functions to a sk_filter prefix to be more consistent with the rest of the file. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Alexei Starovoitov <ast@plumgrid.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0fc174d commit d4052c4

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

net/core/filter.c

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,6 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
10931093
}
10941094
EXPORT_SYMBOL_GPL(sk_attach_filter);
10951095

1096-
#ifdef CONFIG_BPF_SYSCALL
10971096
int sk_attach_bpf(u32 ufd, struct sock *sk)
10981097
{
10991098
struct sk_filter *fp, *old_fp;
@@ -1107,7 +1106,6 @@ int sk_attach_bpf(u32 ufd, struct sock *sk)
11071106
return PTR_ERR(prog);
11081107

11091108
if (prog->aux->prog_type != BPF_PROG_TYPE_SOCKET_FILTER) {
1110-
/* valid fd, but invalid program type */
11111109
bpf_prog_put(prog);
11121110
return -EINVAL;
11131111
}
@@ -1117,8 +1115,8 @@ int sk_attach_bpf(u32 ufd, struct sock *sk)
11171115
bpf_prog_put(prog);
11181116
return -ENOMEM;
11191117
}
1120-
fp->prog = prog;
11211118

1119+
fp->prog = prog;
11221120
atomic_set(&fp->refcnt, 0);
11231121

11241122
if (!sk_filter_charge(sk, fp)) {
@@ -1136,10 +1134,8 @@ int sk_attach_bpf(u32 ufd, struct sock *sk)
11361134
return 0;
11371135
}
11381136

1139-
/* allow socket filters to call
1140-
* bpf_map_lookup_elem(), bpf_map_update_elem(), bpf_map_delete_elem()
1141-
*/
1142-
static const struct bpf_func_proto *sock_filter_func_proto(enum bpf_func_id func_id)
1137+
static const struct bpf_func_proto *
1138+
sk_filter_func_proto(enum bpf_func_id func_id)
11431139
{
11441140
switch (func_id) {
11451141
case BPF_FUNC_map_lookup_elem:
@@ -1153,34 +1149,30 @@ static const struct bpf_func_proto *sock_filter_func_proto(enum bpf_func_id func
11531149
}
11541150
}
11551151

1156-
static bool sock_filter_is_valid_access(int off, int size, enum bpf_access_type type)
1152+
static bool sk_filter_is_valid_access(int off, int size,
1153+
enum bpf_access_type type)
11571154
{
11581155
/* skb fields cannot be accessed yet */
11591156
return false;
11601157
}
11611158

1162-
static const struct bpf_verifier_ops sock_filter_ops = {
1163-
.get_func_proto = sock_filter_func_proto,
1164-
.is_valid_access = sock_filter_is_valid_access,
1159+
static const struct bpf_verifier_ops sk_filter_ops = {
1160+
.get_func_proto = sk_filter_func_proto,
1161+
.is_valid_access = sk_filter_is_valid_access,
11651162
};
11661163

1167-
static struct bpf_prog_type_list sock_filter_type __read_mostly = {
1168-
.ops = &sock_filter_ops,
1164+
static struct bpf_prog_type_list sk_filter_type __read_mostly = {
1165+
.ops = &sk_filter_ops,
11691166
.type = BPF_PROG_TYPE_SOCKET_FILTER,
11701167
};
11711168

1172-
static int __init register_sock_filter_ops(void)
1169+
static int __init register_sk_filter_ops(void)
11731170
{
1174-
bpf_register_prog_type(&sock_filter_type);
1171+
bpf_register_prog_type(&sk_filter_type);
11751172
return 0;
11761173
}
1177-
late_initcall(register_sock_filter_ops);
1178-
#else
1179-
int sk_attach_bpf(u32 ufd, struct sock *sk)
1180-
{
1181-
return -EOPNOTSUPP;
1182-
}
1183-
#endif
1174+
late_initcall(register_sk_filter_ops);
1175+
11841176
int sk_detach_filter(struct sock *sk)
11851177
{
11861178
int ret = -ENOENT;

0 commit comments

Comments
 (0)