diff options
Diffstat (limited to 'include')
| -rw-r--r-- | include/linux/filter.h | 56 | ||||
| -rw-r--r-- | include/uapi/linux/Kbuild | 1 | ||||
| -rw-r--r-- | include/uapi/linux/bpf.h | 65 |
3 files changed, 67 insertions, 55 deletions
diff --git a/include/linux/filter.h b/include/linux/filter.h index bf323da77950..8f82ef3f1cdd 100644 --- a/include/linux/filter.h +++ b/include/linux/filter.h | |||
| @@ -10,58 +10,12 @@ | |||
| 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 | ||
| 14 | struct sk_buff; | 15 | struct sk_buff; |
| 15 | struct sock; | 16 | struct sock; |
| 16 | struct seccomp_data; | 17 | struct 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 */ | ||
| 47 | enum { | ||
| 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 function | 20 | * 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 { | |||
| 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 | ||
| 325 | struct 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_COMPAT | 279 | #ifdef CONFIG_COMPAT |
| 334 | /* A struct sock_filter is architecture independent. */ | 280 | /* A struct sock_filter is architecture independent. */ |
| 335 | struct compat_sock_fprog { | 281 | struct compat_sock_fprog { |
diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild index 24e9033f8b3f..fb3f7b675229 100644 --- a/include/uapi/linux/Kbuild +++ b/include/uapi/linux/Kbuild | |||
| @@ -67,6 +67,7 @@ header-y += bfs_fs.h | |||
| 67 | header-y += binfmts.h | 67 | header-y += binfmts.h |
| 68 | header-y += blkpg.h | 68 | header-y += blkpg.h |
| 69 | header-y += blktrace_api.h | 69 | header-y += blktrace_api.h |
| 70 | header-y += bpf.h | ||
| 70 | header-y += bpqether.h | 71 | header-y += bpqether.h |
| 71 | header-y += bsg.h | 72 | header-y += bsg.h |
| 72 | header-y += btrfs.h | 73 | header-y += btrfs.h |
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h new file mode 100644 index 000000000000..479ed0b6be16 --- /dev/null +++ b/include/uapi/linux/bpf.h | |||
| @@ -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 */ | ||
| 39 | enum { | ||
| 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 | |||
| 57 | struct 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__ */ | ||
