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