History

net: filter: split filter.h and expose eBPF to user space

allow user space to generate eBPF programs uapi/linux/bpf.h: eBPF instruction set definition linux/filter.h: the rest This patch only moves macro definitions, but practically it freezes existing eBPF instruction set, though new instructions can still be added in the future. These eBPF definitions cannot go into uapi/linux/filter.h, since the names may conflict with existing applications. Full eBPF ISA description is in Documentation/networking/filter.txt

Alexei Starovoitov committed 12 years ago

Commit daedfb21 parent 02ab6953 files · +67 −55Browse files

Unified · Split

3 files
  1. include/linux/filter.h +1 −55
  2. include/uapi/linux/Kbuild +1 −0
  3. include/uapi/linux/bpf.h +65 −0
include/linux/filter.h+1−55
@@ -10,58 +10,12 @@ · 9 unmodified lines
10#include <linux/workqueue.h>10#include <linux/workqueue.h>
11#include <uapi/linux/filter.h>11#include <uapi/linux/filter.h>
12#include <asm/cacheflush.h>12#include <asm/cacheflush.h>
13#include <uapi/linux/bpf.h>
13 14
14struct sk_buff;15struct sk_buff;
15struct sock;16struct sock;
16struct seccomp_data;17struct seccomp_data;
17 18
18/* Internally used and optimized filter representation with extended
19 * instruction set based on top of classic BPF.
20 */
21
22/* instruction classes */
23#define BPF_ALU64 0x07 /* alu mode in double word width */
24
25/* ld/ldx fields */
26#define BPF_DW 0x18 /* double word */
27#define BPF_XADD 0xc0 /* exclusive add */
28
29/* alu/jmp fields */
30#define BPF_MOV 0xb0 /* mov reg to reg */
31#define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */
32
33/* change endianness of a register */
34#define BPF_END 0xd0 /* flags for endianness conversion: */
35#define BPF_TO_LE 0x00 /* convert to little-endian */
36#define BPF_TO_BE 0x08 /* convert to big-endian */
37#define BPF_FROM_LE BPF_TO_LE
38#define BPF_FROM_BE BPF_TO_BE
39
40#define BPF_JNE 0x50 /* jump != */
41#define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */
42#define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */
43#define BPF_CALL 0x80 /* function call */
44#define BPF_EXIT 0x90 /* function return */
45
46/* Register numbers */
47enum {
48 BPF_REG_0 = 0,
49 BPF_REG_1,
50 BPF_REG_2,
51 BPF_REG_3,
52 BPF_REG_4,
53 BPF_REG_5,
54 BPF_REG_6,
55 BPF_REG_7,
56 BPF_REG_8,
57 BPF_REG_9,
58 BPF_REG_10,
59 __MAX_BPF_REG,
60};
61
62/* BPF has 10 general purpose 64-bit registers and stack frame. */
63#define MAX_BPF_REG __MAX_BPF_REG
64
65/* ArgX, context and stack frame pointer register positions. Note,19/* ArgX, context and stack frame pointer register positions. Note,
66 * Arg1, Arg2, Arg3, etc are used as argument mappings of function20 * Arg1, Arg2, Arg3, etc are used as argument mappings of function
67 * calls in BPF_CALL instruction.21 * calls in BPF_CALL instruction.
@@ -322,14 +276,6 @@ enum { · 254 unmodified lines
322#define SK_RUN_FILTER(filter, ctx) \276#define SK_RUN_FILTER(filter, ctx) \
323 (*filter->prog->bpf_func)(ctx, filter->prog->insnsi)277 (*filter->prog->bpf_func)(ctx, filter->prog->insnsi)
324 278
325struct bpf_insn {
326 __u8 code; /* opcode */
327 __u8 dst_reg:4; /* dest register */
328 __u8 src_reg:4; /* source register */
329 __s16 off; /* signed offset */
330 __s32 imm; /* signed immediate constant */
331};
332
333#ifdef CONFIG_COMPAT279#ifdef CONFIG_COMPAT
334/* A struct sock_filter is architecture independent. */280/* A struct sock_filter is architecture independent. */
335struct compat_sock_fprog {281struct compat_sock_fprog {
include/uapi/linux/Kbuild+1−0
@@ -67,6 +67,7 @@ header-y += bfs_fs.h · 66 unmodified lines
67header-y += binfmts.h67header-y += binfmts.h
68header-y += blkpg.h68header-y += blkpg.h
69header-y += blktrace_api.h69header-y += blktrace_api.h
70header-y += bpf.h
70header-y += bpqether.h71header-y += bpqether.h
71header-y += bsg.h72header-y += bsg.h
72header-y += btrfs.h73header-y += btrfs.h
include/uapi/linux/bpf.h+65−0
@@ -0,0 +1,65 @@
1/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
6 */
7#ifndef _UAPI__LINUX_BPF_H__
8#define _UAPI__LINUX_BPF_H__
9
10#include <linux/types.h>
11
12/* Extended instruction set based on top of classic BPF */
13
14/* instruction classes */
15#define BPF_ALU64 0x07 /* alu mode in double word width */
16
17/* ld/ldx fields */
18#define BPF_DW 0x18 /* double word */
19#define BPF_XADD 0xc0 /* exclusive add */
20
21/* alu/jmp fields */
22#define BPF_MOV 0xb0 /* mov reg to reg */
23#define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */
24
25/* change endianness of a register */
26#define BPF_END 0xd0 /* flags for endianness conversion: */
27#define BPF_TO_LE 0x00 /* convert to little-endian */
28#define BPF_TO_BE 0x08 /* convert to big-endian */
29#define BPF_FROM_LE BPF_TO_LE
30#define BPF_FROM_BE BPF_TO_BE
31
32#define BPF_JNE 0x50 /* jump != */
33#define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */
34#define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */
35#define BPF_CALL 0x80 /* function call */
36#define BPF_EXIT 0x90 /* function return */
37
38/* Register numbers */
39enum {
40 BPF_REG_0 = 0,
41 BPF_REG_1,
42 BPF_REG_2,
43 BPF_REG_3,
44 BPF_REG_4,
45 BPF_REG_5,
46 BPF_REG_6,
47 BPF_REG_7,
48 BPF_REG_8,
49 BPF_REG_9,
50 BPF_REG_10,
51 __MAX_BPF_REG,
52};
53
54/* BPF has 10 general purpose 64-bit registers and stack frame. */
55#define MAX_BPF_REG __MAX_BPF_REG
56
57struct bpf_insn {
58 __u8 code; /* opcode */
59 __u8 dst_reg:4; /* dest register */
60 __u8 src_reg:4; /* source register */
61 __s16 off; /* signed offset */
62 __s32 imm; /* signed immediate constant */
63};
64
65#endif /* _UAPI__LINUX_BPF_H__ */