]>
Commit | Line | Data |
---|---|---|
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> | |
c15952dc | 11 | #include <linux/bpf_common.h> |
daedfb22 AS |
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 */ | |
40 | enum { | |
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 | ||
58 | struct 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 | ||
b95a5c4d DM |
66 | /* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */ |
67 | struct bpf_lpm_trie_key { | |
68 | __u32 prefixlen; /* up to 32 for AF_INET, 128 for AF_INET6 */ | |
69 | __u8 data[0]; /* Arbitrary size */ | |
70 | }; | |
71 | ||
b2197755 | 72 | /* BPF syscall commands, see bpf(2) man-page for details. */ |
99c55f7d | 73 | enum bpf_cmd { |
99c55f7d | 74 | BPF_MAP_CREATE, |
db20fd2b | 75 | BPF_MAP_LOOKUP_ELEM, |
db20fd2b | 76 | BPF_MAP_UPDATE_ELEM, |
db20fd2b | 77 | BPF_MAP_DELETE_ELEM, |
db20fd2b | 78 | BPF_MAP_GET_NEXT_KEY, |
09756af4 | 79 | BPF_PROG_LOAD, |
b2197755 DB |
80 | BPF_OBJ_PIN, |
81 | BPF_OBJ_GET, | |
f4324551 DM |
82 | BPF_PROG_ATTACH, |
83 | BPF_PROG_DETACH, | |
99c55f7d AS |
84 | }; |
85 | ||
86 | enum bpf_map_type { | |
87 | BPF_MAP_TYPE_UNSPEC, | |
0f8e4bd8 | 88 | BPF_MAP_TYPE_HASH, |
28fbcfa0 | 89 | BPF_MAP_TYPE_ARRAY, |
04fd61ab | 90 | BPF_MAP_TYPE_PROG_ARRAY, |
ea317b26 | 91 | BPF_MAP_TYPE_PERF_EVENT_ARRAY, |
824bd0ce | 92 | BPF_MAP_TYPE_PERCPU_HASH, |
a10423b8 | 93 | BPF_MAP_TYPE_PERCPU_ARRAY, |
d5a3b1f6 | 94 | BPF_MAP_TYPE_STACK_TRACE, |
4ed8ec52 | 95 | BPF_MAP_TYPE_CGROUP_ARRAY, |
29ba732a | 96 | BPF_MAP_TYPE_LRU_HASH, |
8f844938 | 97 | BPF_MAP_TYPE_LRU_PERCPU_HASH, |
b95a5c4d | 98 | BPF_MAP_TYPE_LPM_TRIE, |
99c55f7d AS |
99 | }; |
100 | ||
09756af4 AS |
101 | enum bpf_prog_type { |
102 | BPF_PROG_TYPE_UNSPEC, | |
ddd872bc | 103 | BPF_PROG_TYPE_SOCKET_FILTER, |
2541517c | 104 | BPF_PROG_TYPE_KPROBE, |
96be4325 | 105 | BPF_PROG_TYPE_SCHED_CLS, |
94caee8c | 106 | BPF_PROG_TYPE_SCHED_ACT, |
98b5c2c6 | 107 | BPF_PROG_TYPE_TRACEPOINT, |
6a773a15 | 108 | BPF_PROG_TYPE_XDP, |
0515e599 | 109 | BPF_PROG_TYPE_PERF_EVENT, |
0e33661d | 110 | BPF_PROG_TYPE_CGROUP_SKB, |
61023658 | 111 | BPF_PROG_TYPE_CGROUP_SOCK, |
3a0af8fd TG |
112 | BPF_PROG_TYPE_LWT_IN, |
113 | BPF_PROG_TYPE_LWT_OUT, | |
114 | BPF_PROG_TYPE_LWT_XMIT, | |
09756af4 AS |
115 | }; |
116 | ||
0e33661d DM |
117 | enum bpf_attach_type { |
118 | BPF_CGROUP_INET_INGRESS, | |
119 | BPF_CGROUP_INET_EGRESS, | |
61023658 | 120 | BPF_CGROUP_INET_SOCK_CREATE, |
0e33661d DM |
121 | __MAX_BPF_ATTACH_TYPE |
122 | }; | |
123 | ||
124 | #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE | |
125 | ||
7f677633 AS |
126 | /* If BPF_F_ALLOW_OVERRIDE flag is used in BPF_PROG_ATTACH command |
127 | * to the given target_fd cgroup the descendent cgroup will be able to | |
128 | * override effective bpf program that was inherited from this cgroup | |
129 | */ | |
130 | #define BPF_F_ALLOW_OVERRIDE (1U << 0) | |
131 | ||
f1a66f85 DB |
132 | #define BPF_PSEUDO_MAP_FD 1 |
133 | ||
3274f520 AS |
134 | /* flags for BPF_MAP_UPDATE_ELEM command */ |
135 | #define BPF_ANY 0 /* create new element or update existing */ | |
136 | #define BPF_NOEXIST 1 /* create new element if it didn't exist */ | |
137 | #define BPF_EXIST 2 /* update existing element */ | |
138 | ||
6c905981 | 139 | #define BPF_F_NO_PREALLOC (1U << 0) |
29ba732a | 140 | /* Instead of having one common LRU list in the |
8f844938 | 141 | * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list |
29ba732a MKL |
142 | * which can scale and perform better. |
143 | * Note, the LRU nodes (including free nodes) cannot be moved | |
144 | * across different LRU lists. | |
145 | */ | |
146 | #define BPF_F_NO_COMMON_LRU (1U << 1) | |
6c905981 | 147 | |
99c55f7d AS |
148 | union bpf_attr { |
149 | struct { /* anonymous struct used by BPF_MAP_CREATE command */ | |
150 | __u32 map_type; /* one of enum bpf_map_type */ | |
151 | __u32 key_size; /* size of key in bytes */ | |
152 | __u32 value_size; /* size of value in bytes */ | |
153 | __u32 max_entries; /* max number of entries in a map */ | |
6c905981 | 154 | __u32 map_flags; /* prealloc or not */ |
99c55f7d | 155 | }; |
db20fd2b AS |
156 | |
157 | struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */ | |
158 | __u32 map_fd; | |
159 | __aligned_u64 key; | |
160 | union { | |
161 | __aligned_u64 value; | |
162 | __aligned_u64 next_key; | |
163 | }; | |
3274f520 | 164 | __u64 flags; |
db20fd2b | 165 | }; |
09756af4 AS |
166 | |
167 | struct { /* anonymous struct used by BPF_PROG_LOAD command */ | |
168 | __u32 prog_type; /* one of enum bpf_prog_type */ | |
169 | __u32 insn_cnt; | |
170 | __aligned_u64 insns; | |
171 | __aligned_u64 license; | |
cbd35700 AS |
172 | __u32 log_level; /* verbosity level of verifier */ |
173 | __u32 log_size; /* size of user buffer */ | |
174 | __aligned_u64 log_buf; /* user supplied buffer */ | |
2541517c | 175 | __u32 kern_version; /* checked when prog_type=kprobe */ |
09756af4 | 176 | }; |
b2197755 DB |
177 | |
178 | struct { /* anonymous struct used by BPF_OBJ_* commands */ | |
179 | __aligned_u64 pathname; | |
180 | __u32 bpf_fd; | |
181 | }; | |
f4324551 DM |
182 | |
183 | struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */ | |
184 | __u32 target_fd; /* container object to attach to */ | |
185 | __u32 attach_bpf_fd; /* eBPF program to attach */ | |
186 | __u32 attach_type; | |
7f677633 | 187 | __u32 attach_flags; |
f4324551 | 188 | }; |
99c55f7d AS |
189 | } __attribute__((aligned(8))); |
190 | ||
ebb676da TG |
191 | /* BPF helper function descriptions: |
192 | * | |
193 | * void *bpf_map_lookup_elem(&map, &key) | |
194 | * Return: Map value or NULL | |
195 | * | |
196 | * int bpf_map_update_elem(&map, &key, &value, flags) | |
197 | * Return: 0 on success or negative error | |
198 | * | |
199 | * int bpf_map_delete_elem(&map, &key) | |
200 | * Return: 0 on success or negative error | |
201 | * | |
202 | * int bpf_probe_read(void *dst, int size, void *src) | |
203 | * Return: 0 on success or negative error | |
204 | * | |
205 | * u64 bpf_ktime_get_ns(void) | |
206 | * Return: current ktime | |
207 | * | |
208 | * int bpf_trace_printk(const char *fmt, int fmt_size, ...) | |
209 | * Return: length of buffer written or negative error | |
210 | * | |
211 | * u32 bpf_prandom_u32(void) | |
212 | * Return: random value | |
213 | * | |
214 | * u32 bpf_raw_smp_processor_id(void) | |
215 | * Return: SMP processor ID | |
216 | * | |
217 | * int bpf_skb_store_bytes(skb, offset, from, len, flags) | |
218 | * store bytes into packet | |
219 | * @skb: pointer to skb | |
220 | * @offset: offset within packet from skb->mac_header | |
221 | * @from: pointer where to copy bytes from | |
222 | * @len: number of bytes to store into packet | |
223 | * @flags: bit 0 - if true, recompute skb->csum | |
224 | * other bits - reserved | |
225 | * Return: 0 on success or negative error | |
226 | * | |
227 | * int bpf_l3_csum_replace(skb, offset, from, to, flags) | |
228 | * recompute IP checksum | |
229 | * @skb: pointer to skb | |
230 | * @offset: offset within packet where IP checksum is located | |
231 | * @from: old value of header field | |
232 | * @to: new value of header field | |
233 | * @flags: bits 0-3 - size of header field | |
234 | * other bits - reserved | |
235 | * Return: 0 on success or negative error | |
236 | * | |
237 | * int bpf_l4_csum_replace(skb, offset, from, to, flags) | |
238 | * recompute TCP/UDP checksum | |
239 | * @skb: pointer to skb | |
240 | * @offset: offset within packet where TCP/UDP checksum is located | |
241 | * @from: old value of header field | |
242 | * @to: new value of header field | |
243 | * @flags: bits 0-3 - size of header field | |
244 | * bit 4 - is pseudo header | |
245 | * other bits - reserved | |
246 | * Return: 0 on success or negative error | |
247 | * | |
248 | * int bpf_tail_call(ctx, prog_array_map, index) | |
249 | * jump into another BPF program | |
250 | * @ctx: context pointer passed to next program | |
251 | * @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY | |
252 | * @index: index inside array that selects specific program to run | |
253 | * Return: 0 on success or negative error | |
254 | * | |
255 | * int bpf_clone_redirect(skb, ifindex, flags) | |
256 | * redirect to another netdev | |
257 | * @skb: pointer to skb | |
258 | * @ifindex: ifindex of the net device | |
259 | * @flags: bit 0 - if set, redirect to ingress instead of egress | |
260 | * other bits - reserved | |
261 | * Return: 0 on success or negative error | |
262 | * | |
263 | * u64 bpf_get_current_pid_tgid(void) | |
264 | * Return: current->tgid << 32 | current->pid | |
265 | * | |
266 | * u64 bpf_get_current_uid_gid(void) | |
267 | * Return: current_gid << 32 | current_uid | |
268 | * | |
269 | * int bpf_get_current_comm(char *buf, int size_of_buf) | |
270 | * stores current->comm into buf | |
271 | * Return: 0 on success or negative error | |
272 | * | |
273 | * u32 bpf_get_cgroup_classid(skb) | |
274 | * retrieve a proc's classid | |
275 | * @skb: pointer to skb | |
276 | * Return: classid if != 0 | |
277 | * | |
278 | * int bpf_skb_vlan_push(skb, vlan_proto, vlan_tci) | |
279 | * Return: 0 on success or negative error | |
280 | * | |
281 | * int bpf_skb_vlan_pop(skb) | |
282 | * Return: 0 on success or negative error | |
283 | * | |
284 | * int bpf_skb_get_tunnel_key(skb, key, size, flags) | |
285 | * int bpf_skb_set_tunnel_key(skb, key, size, flags) | |
286 | * retrieve or populate tunnel metadata | |
287 | * @skb: pointer to skb | |
288 | * @key: pointer to 'struct bpf_tunnel_key' | |
289 | * @size: size of 'struct bpf_tunnel_key' | |
290 | * @flags: room for future extensions | |
291 | * Return: 0 on success or negative error | |
292 | * | |
293 | * u64 bpf_perf_event_read(&map, index) | |
294 | * Return: Number events read or error code | |
295 | * | |
296 | * int bpf_redirect(ifindex, flags) | |
297 | * redirect to another netdev | |
298 | * @ifindex: ifindex of the net device | |
299 | * @flags: bit 0 - if set, redirect to ingress instead of egress | |
300 | * other bits - reserved | |
301 | * Return: TC_ACT_REDIRECT | |
302 | * | |
303 | * u32 bpf_get_route_realm(skb) | |
304 | * retrieve a dst's tclassid | |
305 | * @skb: pointer to skb | |
306 | * Return: realm if != 0 | |
307 | * | |
308 | * int bpf_perf_event_output(ctx, map, index, data, size) | |
309 | * output perf raw sample | |
310 | * @ctx: struct pt_regs* | |
311 | * @map: pointer to perf_event_array map | |
312 | * @index: index of event in the map | |
313 | * @data: data on stack to be output as raw data | |
314 | * @size: size of data | |
315 | * Return: 0 on success or negative error | |
316 | * | |
317 | * int bpf_get_stackid(ctx, map, flags) | |
318 | * walk user or kernel stack and return id | |
319 | * @ctx: struct pt_regs* | |
320 | * @map: pointer to stack_trace map | |
321 | * @flags: bits 0-7 - numer of stack frames to skip | |
322 | * bit 8 - collect user stack instead of kernel | |
323 | * bit 9 - compare stacks by hash only | |
324 | * bit 10 - if two different stacks hash into the same stackid | |
325 | * discard old | |
326 | * other bits - reserved | |
327 | * Return: >= 0 stackid on success or negative error | |
328 | * | |
329 | * s64 bpf_csum_diff(from, from_size, to, to_size, seed) | |
330 | * calculate csum diff | |
331 | * @from: raw from buffer | |
332 | * @from_size: length of from buffer | |
333 | * @to: raw to buffer | |
334 | * @to_size: length of to buffer | |
335 | * @seed: optional seed | |
336 | * Return: csum result or negative error code | |
337 | * | |
338 | * int bpf_skb_get_tunnel_opt(skb, opt, size) | |
339 | * retrieve tunnel options metadata | |
340 | * @skb: pointer to skb | |
341 | * @opt: pointer to raw tunnel option data | |
342 | * @size: size of @opt | |
343 | * Return: option size | |
344 | * | |
345 | * int bpf_skb_set_tunnel_opt(skb, opt, size) | |
346 | * populate tunnel options metadata | |
347 | * @skb: pointer to skb | |
348 | * @opt: pointer to raw tunnel option data | |
349 | * @size: size of @opt | |
350 | * Return: 0 on success or negative error | |
351 | * | |
352 | * int bpf_skb_change_proto(skb, proto, flags) | |
353 | * Change protocol of the skb. Currently supported is v4 -> v6, | |
354 | * v6 -> v4 transitions. The helper will also resize the skb. eBPF | |
355 | * program is expected to fill the new headers via skb_store_bytes | |
356 | * and lX_csum_replace. | |
357 | * @skb: pointer to skb | |
358 | * @proto: new skb->protocol type | |
359 | * @flags: reserved | |
360 | * Return: 0 on success or negative error | |
361 | * | |
362 | * int bpf_skb_change_type(skb, type) | |
363 | * Change packet type of skb. | |
364 | * @skb: pointer to skb | |
365 | * @type: new skb->pkt_type type | |
366 | * Return: 0 on success or negative error | |
367 | * | |
368 | * int bpf_skb_under_cgroup(skb, map, index) | |
369 | * Check cgroup2 membership of skb | |
370 | * @skb: pointer to skb | |
371 | * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type | |
372 | * @index: index of the cgroup in the bpf_map | |
373 | * Return: | |
374 | * == 0 skb failed the cgroup2 descendant test | |
375 | * == 1 skb succeeded the cgroup2 descendant test | |
376 | * < 0 error | |
377 | * | |
378 | * u32 bpf_get_hash_recalc(skb) | |
379 | * Retrieve and possibly recalculate skb->hash. | |
380 | * @skb: pointer to skb | |
381 | * Return: hash | |
382 | * | |
383 | * u64 bpf_get_current_task(void) | |
384 | * Returns current task_struct | |
385 | * Return: current | |
386 | * | |
387 | * int bpf_probe_write_user(void *dst, void *src, int len) | |
388 | * safely attempt to write to a location | |
389 | * @dst: destination address in userspace | |
390 | * @src: source address on stack | |
391 | * @len: number of bytes to copy | |
392 | * Return: 0 on success or negative error | |
393 | * | |
394 | * int bpf_current_task_under_cgroup(map, index) | |
395 | * Check cgroup2 membership of current task | |
396 | * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type | |
397 | * @index: index of the cgroup in the bpf_map | |
398 | * Return: | |
399 | * == 0 current failed the cgroup2 descendant test | |
400 | * == 1 current succeeded the cgroup2 descendant test | |
401 | * < 0 error | |
402 | * | |
403 | * int bpf_skb_change_tail(skb, len, flags) | |
404 | * The helper will resize the skb to the given new size, to be used f.e. | |
405 | * with control messages. | |
406 | * @skb: pointer to skb | |
407 | * @len: new skb length | |
408 | * @flags: reserved | |
409 | * Return: 0 on success or negative error | |
410 | * | |
411 | * int bpf_skb_pull_data(skb, len) | |
412 | * The helper will pull in non-linear data in case the skb is non-linear | |
413 | * and not all of len are part of the linear section. Only needed for | |
414 | * read/write with direct packet access. | |
415 | * @skb: pointer to skb | |
416 | * @len: len to make read/writeable | |
417 | * Return: 0 on success or negative error | |
418 | * | |
419 | * s64 bpf_csum_update(skb, csum) | |
420 | * Adds csum into skb->csum in case of CHECKSUM_COMPLETE. | |
421 | * @skb: pointer to skb | |
422 | * @csum: csum to add | |
423 | * Return: csum on success or negative error | |
424 | * | |
425 | * void bpf_set_hash_invalid(skb) | |
426 | * Invalidate current skb->hash. | |
427 | * @skb: pointer to skb | |
428 | * | |
429 | * int bpf_get_numa_node_id() | |
430 | * Return: Id of current NUMA node. | |
3a0af8fd TG |
431 | * |
432 | * int bpf_skb_change_head() | |
433 | * Grows headroom of skb and adjusts MAC header offset accordingly. | |
434 | * Will extends/reallocae as required automatically. | |
435 | * May change skb data pointer and will thus invalidate any check | |
436 | * performed for direct packet access. | |
437 | * @skb: pointer to skb | |
438 | * @len: length of header to be pushed in front | |
439 | * @flags: Flags (unused for now) | |
440 | * Return: 0 on success or negative error | |
17bedab2 MKL |
441 | * |
442 | * int bpf_xdp_adjust_head(xdp_md, delta) | |
443 | * Adjust the xdp_md.data by delta | |
444 | * @xdp_md: pointer to xdp_md | |
445 | * @delta: An positive/negative integer to be added to xdp_md.data | |
446 | * Return: 0 on success or negative on error | |
a5e8c070 GB |
447 | * |
448 | * int bpf_probe_read_str(void *dst, int size, const void *unsafe_ptr) | |
449 | * Copy a NUL terminated string from unsafe address. In case the string | |
450 | * length is smaller than size, the target is not padded with further NUL | |
451 | * bytes. In case the string length is larger than size, just count-1 | |
452 | * bytes are copied and the last byte is set to NUL. | |
453 | * @dst: destination address | |
454 | * @size: maximum number of bytes to copy, including the trailing NUL | |
455 | * @unsafe_ptr: unsafe address | |
456 | * Return: | |
457 | * > 0 length of the string including the trailing NUL on success | |
458 | * < 0 error | |
ebb676da TG |
459 | */ |
460 | #define __BPF_FUNC_MAPPER(FN) \ | |
461 | FN(unspec), \ | |
462 | FN(map_lookup_elem), \ | |
463 | FN(map_update_elem), \ | |
464 | FN(map_delete_elem), \ | |
465 | FN(probe_read), \ | |
466 | FN(ktime_get_ns), \ | |
467 | FN(trace_printk), \ | |
468 | FN(get_prandom_u32), \ | |
469 | FN(get_smp_processor_id), \ | |
470 | FN(skb_store_bytes), \ | |
471 | FN(l3_csum_replace), \ | |
472 | FN(l4_csum_replace), \ | |
473 | FN(tail_call), \ | |
474 | FN(clone_redirect), \ | |
475 | FN(get_current_pid_tgid), \ | |
476 | FN(get_current_uid_gid), \ | |
477 | FN(get_current_comm), \ | |
478 | FN(get_cgroup_classid), \ | |
479 | FN(skb_vlan_push), \ | |
480 | FN(skb_vlan_pop), \ | |
481 | FN(skb_get_tunnel_key), \ | |
482 | FN(skb_set_tunnel_key), \ | |
483 | FN(perf_event_read), \ | |
484 | FN(redirect), \ | |
485 | FN(get_route_realm), \ | |
486 | FN(perf_event_output), \ | |
487 | FN(skb_load_bytes), \ | |
488 | FN(get_stackid), \ | |
489 | FN(csum_diff), \ | |
490 | FN(skb_get_tunnel_opt), \ | |
491 | FN(skb_set_tunnel_opt), \ | |
492 | FN(skb_change_proto), \ | |
493 | FN(skb_change_type), \ | |
494 | FN(skb_under_cgroup), \ | |
495 | FN(get_hash_recalc), \ | |
496 | FN(get_current_task), \ | |
497 | FN(probe_write_user), \ | |
498 | FN(current_task_under_cgroup), \ | |
499 | FN(skb_change_tail), \ | |
500 | FN(skb_pull_data), \ | |
501 | FN(csum_update), \ | |
502 | FN(set_hash_invalid), \ | |
3a0af8fd | 503 | FN(get_numa_node_id), \ |
17bedab2 | 504 | FN(skb_change_head), \ |
a5e8c070 GB |
505 | FN(xdp_adjust_head), \ |
506 | FN(probe_read_str), | |
ebb676da | 507 | |
09756af4 AS |
508 | /* integer value in 'imm' field of BPF_CALL instruction selects which helper |
509 | * function eBPF program intends to call | |
510 | */ | |
ebb676da | 511 | #define __BPF_ENUM_FN(x) BPF_FUNC_ ## x |
09756af4 | 512 | enum bpf_func_id { |
ebb676da | 513 | __BPF_FUNC_MAPPER(__BPF_ENUM_FN) |
09756af4 AS |
514 | __BPF_FUNC_MAX_ID, |
515 | }; | |
ebb676da | 516 | #undef __BPF_ENUM_FN |
09756af4 | 517 | |
781c53bc DB |
518 | /* All flags used by eBPF helper functions, placed here. */ |
519 | ||
520 | /* BPF_FUNC_skb_store_bytes flags. */ | |
521 | #define BPF_F_RECOMPUTE_CSUM (1ULL << 0) | |
8afd54c8 | 522 | #define BPF_F_INVALIDATE_HASH (1ULL << 1) |
781c53bc DB |
523 | |
524 | /* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags. | |
525 | * First 4 bits are for passing the header field size. | |
526 | */ | |
527 | #define BPF_F_HDR_FIELD_MASK 0xfULL | |
528 | ||
529 | /* BPF_FUNC_l4_csum_replace flags. */ | |
530 | #define BPF_F_PSEUDO_HDR (1ULL << 4) | |
2f72959a | 531 | #define BPF_F_MARK_MANGLED_0 (1ULL << 5) |
d1b662ad | 532 | #define BPF_F_MARK_ENFORCE (1ULL << 6) |
781c53bc DB |
533 | |
534 | /* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */ | |
535 | #define BPF_F_INGRESS (1ULL << 0) | |
536 | ||
c6c33454 DB |
537 | /* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */ |
538 | #define BPF_F_TUNINFO_IPV6 (1ULL << 0) | |
539 | ||
d5a3b1f6 AS |
540 | /* BPF_FUNC_get_stackid flags. */ |
541 | #define BPF_F_SKIP_FIELD_MASK 0xffULL | |
542 | #define BPF_F_USER_STACK (1ULL << 8) | |
543 | #define BPF_F_FAST_STACK_CMP (1ULL << 9) | |
544 | #define BPF_F_REUSE_STACKID (1ULL << 10) | |
545 | ||
2da897e5 DB |
546 | /* BPF_FUNC_skb_set_tunnel_key flags. */ |
547 | #define BPF_F_ZERO_CSUM_TX (1ULL << 1) | |
22080870 | 548 | #define BPF_F_DONT_FRAGMENT (1ULL << 2) |
2da897e5 | 549 | |
6816a7ff | 550 | /* BPF_FUNC_perf_event_output and BPF_FUNC_perf_event_read flags. */ |
1e33759c DB |
551 | #define BPF_F_INDEX_MASK 0xffffffffULL |
552 | #define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK | |
555c8a86 DB |
553 | /* BPF_FUNC_perf_event_output for sk_buff input context. */ |
554 | #define BPF_F_CTXLEN_MASK (0xfffffULL << 32) | |
1e33759c | 555 | |
9bac3d6d AS |
556 | /* user accessible mirror of in-kernel sk_buff. |
557 | * new fields can only be added to the end of this structure | |
558 | */ | |
559 | struct __sk_buff { | |
560 | __u32 len; | |
561 | __u32 pkt_type; | |
562 | __u32 mark; | |
563 | __u32 queue_mapping; | |
c2497395 AS |
564 | __u32 protocol; |
565 | __u32 vlan_present; | |
566 | __u32 vlan_tci; | |
27cd5452 | 567 | __u32 vlan_proto; |
bcad5718 | 568 | __u32 priority; |
37e82c2f AS |
569 | __u32 ingress_ifindex; |
570 | __u32 ifindex; | |
d691f9e8 AS |
571 | __u32 tc_index; |
572 | __u32 cb[5]; | |
ba7591d8 | 573 | __u32 hash; |
045efa82 | 574 | __u32 tc_classid; |
969bf05e AS |
575 | __u32 data; |
576 | __u32 data_end; | |
9bac3d6d AS |
577 | }; |
578 | ||
d3aa45ce AS |
579 | struct bpf_tunnel_key { |
580 | __u32 tunnel_id; | |
c6c33454 DB |
581 | union { |
582 | __u32 remote_ipv4; | |
583 | __u32 remote_ipv6[4]; | |
584 | }; | |
585 | __u8 tunnel_tos; | |
586 | __u8 tunnel_ttl; | |
c0e760c9 | 587 | __u16 tunnel_ext; |
4018ab18 | 588 | __u32 tunnel_label; |
d3aa45ce AS |
589 | }; |
590 | ||
3a0af8fd TG |
591 | /* Generic BPF return codes which all BPF program types may support. |
592 | * The values are binary compatible with their TC_ACT_* counter-part to | |
593 | * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT | |
594 | * programs. | |
595 | * | |
596 | * XDP is handled seprately, see XDP_*. | |
597 | */ | |
598 | enum bpf_ret_code { | |
599 | BPF_OK = 0, | |
600 | /* 1 reserved */ | |
601 | BPF_DROP = 2, | |
602 | /* 3-6 reserved */ | |
603 | BPF_REDIRECT = 7, | |
604 | /* >127 are reserved for prog type specific return codes */ | |
605 | }; | |
606 | ||
61023658 DA |
607 | struct bpf_sock { |
608 | __u32 bound_dev_if; | |
aa4c1037 DA |
609 | __u32 family; |
610 | __u32 type; | |
611 | __u32 protocol; | |
61023658 DA |
612 | }; |
613 | ||
17bedab2 MKL |
614 | #define XDP_PACKET_HEADROOM 256 |
615 | ||
6a773a15 BB |
616 | /* User return codes for XDP prog type. |
617 | * A valid XDP program must return one of these defined values. All other | |
618 | * return codes are reserved for future use. Unknown return codes will result | |
619 | * in packet drop. | |
620 | */ | |
621 | enum xdp_action { | |
622 | XDP_ABORTED = 0, | |
623 | XDP_DROP, | |
624 | XDP_PASS, | |
6ce96ca3 | 625 | XDP_TX, |
6a773a15 BB |
626 | }; |
627 | ||
628 | /* user accessible metadata for XDP packet hook | |
629 | * new fields must be added to the end of this structure | |
630 | */ | |
631 | struct xdp_md { | |
632 | __u32 data; | |
633 | __u32 data_end; | |
634 | }; | |
635 | ||
daedfb22 | 636 | #endif /* _UAPI__LINUX_BPF_H__ */ |