aboutsummaryrefslogtreecommitdiffstats
path: root/tools/include/uapi
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2016-07-11 15:38:05 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-07-12 14:20:32 -0400
commit971e827bffef781dd089a402fe602ff20c1f1819 (patch)
tree91052dc27d4b33318ff6e728e8e660fb2235d1a0 /tools/include/uapi
parent7d7d1bf1d1dabe435ef50efb051724b8664749cb (diff)
tools lib bpf: Copy bpf.h and bpf_common.h from the kernel
To allow the build to complete on older systems, where those files are either not uptodate, lacking some recent additions or not present at all. And check if the copy drifts from the kernel, as in this synthetic test: BUILD: Doing 'make -j4' parallel build Warning: tools/include/linux/bpf.h differs from kernel Warning: tools/include/linux/bpf_common.h differs from kernel Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-5plvi2gq4x469dcyybiu226q@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/include/uapi')
-rw-r--r--tools/include/uapi/linux/bpf.h389
-rw-r--r--tools/include/uapi/linux/bpf_common.h55
2 files changed, 444 insertions, 0 deletions
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
new file mode 100644
index 000000000000..406459b935a2
--- /dev/null
+++ b/tools/include/uapi/linux/bpf.h
@@ -0,0 +1,389 @@
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#include <linux/bpf_common.h>
12
13/* Extended instruction set based on top of classic BPF */
14
15/* instruction classes */
16#define BPF_ALU64 0x07 /* alu mode in double word width */
17
18/* ld/ldx fields */
19#define BPF_DW 0x18 /* double word */
20#define BPF_XADD 0xc0 /* exclusive add */
21
22/* alu/jmp fields */
23#define BPF_MOV 0xb0 /* mov reg to reg */
24#define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */
25
26/* change endianness of a register */
27#define BPF_END 0xd0 /* flags for endianness conversion: */
28#define BPF_TO_LE 0x00 /* convert to little-endian */
29#define BPF_TO_BE 0x08 /* convert to big-endian */
30#define BPF_FROM_LE BPF_TO_LE
31#define BPF_FROM_BE BPF_TO_BE
32
33#define BPF_JNE 0x50 /* jump != */
34#define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */
35#define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */
36#define BPF_CALL 0x80 /* function call */
37#define BPF_EXIT 0x90 /* function return */
38
39/* Register numbers */
40enum {
41 BPF_REG_0 = 0,
42 BPF_REG_1,
43 BPF_REG_2,
44 BPF_REG_3,
45 BPF_REG_4,
46 BPF_REG_5,
47 BPF_REG_6,
48 BPF_REG_7,
49 BPF_REG_8,
50 BPF_REG_9,
51 BPF_REG_10,
52 __MAX_BPF_REG,
53};
54
55/* BPF has 10 general purpose 64-bit registers and stack frame. */
56#define MAX_BPF_REG __MAX_BPF_REG
57
58struct bpf_insn {
59 __u8 code; /* opcode */
60 __u8 dst_reg:4; /* dest register */
61 __u8 src_reg:4; /* source register */
62 __s16 off; /* signed offset */
63 __s32 imm; /* signed immediate constant */
64};
65
66/* BPF syscall commands, see bpf(2) man-page for details. */
67enum bpf_cmd {
68 BPF_MAP_CREATE,
69 BPF_MAP_LOOKUP_ELEM,
70 BPF_MAP_UPDATE_ELEM,
71 BPF_MAP_DELETE_ELEM,
72 BPF_MAP_GET_NEXT_KEY,
73 BPF_PROG_LOAD,
74 BPF_OBJ_PIN,
75 BPF_OBJ_GET,
76};
77
78enum bpf_map_type {
79 BPF_MAP_TYPE_UNSPEC,
80 BPF_MAP_TYPE_HASH,
81 BPF_MAP_TYPE_ARRAY,
82 BPF_MAP_TYPE_PROG_ARRAY,
83 BPF_MAP_TYPE_PERF_EVENT_ARRAY,
84 BPF_MAP_TYPE_PERCPU_HASH,
85 BPF_MAP_TYPE_PERCPU_ARRAY,
86 BPF_MAP_TYPE_STACK_TRACE,
87};
88
89enum bpf_prog_type {
90 BPF_PROG_TYPE_UNSPEC,
91 BPF_PROG_TYPE_SOCKET_FILTER,
92 BPF_PROG_TYPE_KPROBE,
93 BPF_PROG_TYPE_SCHED_CLS,
94 BPF_PROG_TYPE_SCHED_ACT,
95 BPF_PROG_TYPE_TRACEPOINT,
96};
97
98#define BPF_PSEUDO_MAP_FD 1
99
100/* flags for BPF_MAP_UPDATE_ELEM command */
101#define BPF_ANY 0 /* create new element or update existing */
102#define BPF_NOEXIST 1 /* create new element if it didn't exist */
103#define BPF_EXIST 2 /* update existing element */
104
105#define BPF_F_NO_PREALLOC (1U << 0)
106
107union bpf_attr {
108 struct { /* anonymous struct used by BPF_MAP_CREATE command */
109 __u32 map_type; /* one of enum bpf_map_type */
110 __u32 key_size; /* size of key in bytes */
111 __u32 value_size; /* size of value in bytes */
112 __u32 max_entries; /* max number of entries in a map */
113 __u32 map_flags; /* prealloc or not */
114 };
115
116 struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
117 __u32 map_fd;
118 __aligned_u64 key;
119 union {
120 __aligned_u64 value;
121 __aligned_u64 next_key;
122 };
123 __u64 flags;
124 };
125
126 struct { /* anonymous struct used by BPF_PROG_LOAD command */
127 __u32 prog_type; /* one of enum bpf_prog_type */
128 __u32 insn_cnt;
129 __aligned_u64 insns;
130 __aligned_u64 license;
131 __u32 log_level; /* verbosity level of verifier */
132 __u32 log_size; /* size of user buffer */
133 __aligned_u64 log_buf; /* user supplied buffer */
134 __u32 kern_version; /* checked when prog_type=kprobe */
135 };
136
137 struct { /* anonymous struct used by BPF_OBJ_* commands */
138 __aligned_u64 pathname;
139 __u32 bpf_fd;
140 };
141} __attribute__((aligned(8)));
142
143/* integer value in 'imm' field of BPF_CALL instruction selects which helper
144 * function eBPF program intends to call
145 */
146enum bpf_func_id {
147 BPF_FUNC_unspec,
148 BPF_FUNC_map_lookup_elem, /* void *map_lookup_elem(&map, &key) */
149 BPF_FUNC_map_update_elem, /* int map_update_elem(&map, &key, &value, flags) */
150 BPF_FUNC_map_delete_elem, /* int map_delete_elem(&map, &key) */
151 BPF_FUNC_probe_read, /* int bpf_probe_read(void *dst, int size, void *src) */
152 BPF_FUNC_ktime_get_ns, /* u64 bpf_ktime_get_ns(void) */
153 BPF_FUNC_trace_printk, /* int bpf_trace_printk(const char *fmt, int fmt_size, ...) */
154 BPF_FUNC_get_prandom_u32, /* u32 prandom_u32(void) */
155 BPF_FUNC_get_smp_processor_id, /* u32 raw_smp_processor_id(void) */
156
157 /**
158 * skb_store_bytes(skb, offset, from, len, flags) - store bytes into packet
159 * @skb: pointer to skb
160 * @offset: offset within packet from skb->mac_header
161 * @from: pointer where to copy bytes from
162 * @len: number of bytes to store into packet
163 * @flags: bit 0 - if true, recompute skb->csum
164 * other bits - reserved
165 * Return: 0 on success
166 */
167 BPF_FUNC_skb_store_bytes,
168
169 /**
170 * l3_csum_replace(skb, offset, from, to, flags) - recompute IP checksum
171 * @skb: pointer to skb
172 * @offset: offset within packet where IP checksum is located
173 * @from: old value of header field
174 * @to: new value of header field
175 * @flags: bits 0-3 - size of header field
176 * other bits - reserved
177 * Return: 0 on success
178 */
179 BPF_FUNC_l3_csum_replace,
180
181 /**
182 * l4_csum_replace(skb, offset, from, to, flags) - recompute TCP/UDP checksum
183 * @skb: pointer to skb
184 * @offset: offset within packet where TCP/UDP checksum is located
185 * @from: old value of header field
186 * @to: new value of header field
187 * @flags: bits 0-3 - size of header field
188 * bit 4 - is pseudo header
189 * other bits - reserved
190 * Return: 0 on success
191 */
192 BPF_FUNC_l4_csum_replace,
193
194 /**
195 * bpf_tail_call(ctx, prog_array_map, index) - jump into another BPF program
196 * @ctx: context pointer passed to next program
197 * @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY
198 * @index: index inside array that selects specific program to run
199 * Return: 0 on success
200 */
201