caif_usb: use target structure member in memset
[deliverable/linux.git] / include / uapi / linux / bpf.h
CommitLineData
daedfb22
AS
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
99c55f7d
AS
65/* BPF syscall commands */
66enum bpf_cmd {
67 /* create a map with given type and attributes
68 * fd = bpf(BPF_MAP_CREATE, union bpf_attr *, u32 size)
69 * returns fd or negative error
70 * map is deleted when fd is closed
71 */
72 BPF_MAP_CREATE,
db20fd2b
AS
73
74 /* lookup key in a given map
75 * err = bpf(BPF_MAP_LOOKUP_ELEM, union bpf_attr *attr, u32 size)
76 * Using attr->map_fd, attr->key, attr->value
77 * returns zero and stores found elem into value
78 * or negative error
79 */
80 BPF_MAP_LOOKUP_ELEM,
81
82 /* create or update key/value pair in a given map
83 * err = bpf(BPF_MAP_UPDATE_ELEM, union bpf_attr *attr, u32 size)
84 * Using attr->map_fd, attr->key, attr->value
85 * returns zero or negative error
86 */
87 BPF_MAP_UPDATE_ELEM,
88
89 /* find and delete elem by key in a given map
90 * err = bpf(BPF_MAP_DELETE_ELEM, union bpf_attr *attr, u32 size)
91 * Using attr->map_fd, attr->key
92 * returns zero or negative error
93 */
94 BPF_MAP_DELETE_ELEM,
95
96 /* lookup key in a given map and return next key
97 * err = bpf(BPF_MAP_GET_NEXT_KEY, union bpf_attr *attr, u32 size)
98 * Using attr->map_fd, attr->key, attr->next_key
99 * returns zero and stores next key or negative error
100 */
101 BPF_MAP_GET_NEXT_KEY,
09756af4
AS
102
103 /* verify and load eBPF program
104 * prog_fd = bpf(BPF_PROG_LOAD, union bpf_attr *attr, u32 size)
105 * Using attr->prog_type, attr->insns, attr->license
106 * returns fd or negative error
107 */
108 BPF_PROG_LOAD,
99c55f7d
AS
109};
110
111enum bpf_map_type {
112 BPF_MAP_TYPE_UNSPEC,
113};
114
09756af4
AS
115enum bpf_prog_type {
116 BPF_PROG_TYPE_UNSPEC,
117};
118
99c55f7d
AS
119union bpf_attr {
120 struct { /* anonymous struct used by BPF_MAP_CREATE command */
121 __u32 map_type; /* one of enum bpf_map_type */
122 __u32 key_size; /* size of key in bytes */
123 __u32 value_size; /* size of value in bytes */
124 __u32 max_entries; /* max number of entries in a map */
125 };
db20fd2b
AS
126
127 struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
128 __u32 map_fd;
129 __aligned_u64 key;
130 union {
131 __aligned_u64 value;
132 __aligned_u64 next_key;
133 };
134 };
09756af4
AS
135
136 struct { /* anonymous struct used by BPF_PROG_LOAD command */
137 __u32 prog_type; /* one of enum bpf_prog_type */
138 __u32 insn_cnt;
139 __aligned_u64 insns;
140 __aligned_u64 license;
cbd35700
AS
141 __u32 log_level; /* verbosity level of verifier */
142 __u32 log_size; /* size of user buffer */
143 __aligned_u64 log_buf; /* user supplied buffer */
09756af4 144 };
99c55f7d
AS
145} __attribute__((aligned(8)));
146
09756af4
AS
147/* integer value in 'imm' field of BPF_CALL instruction selects which helper
148 * function eBPF program intends to call
149 */
150enum bpf_func_id {
151 BPF_FUNC_unspec,
152 __BPF_FUNC_MAX_ID,
153};
154
daedfb22 155#endif /* _UAPI__LINUX_BPF_H__ */
This page took 0.061614 seconds and 5 git commands to generate.