xref: /linux/include/uapi/linux/bpf.h (revision b0b9395d865e3060d97658fbc9ba3f77fecc8da1)
1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2daedfb22SAlexei Starovoitov /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
3daedfb22SAlexei Starovoitov  *
4daedfb22SAlexei Starovoitov  * This program is free software; you can redistribute it and/or
5daedfb22SAlexei Starovoitov  * modify it under the terms of version 2 of the GNU General Public
6daedfb22SAlexei Starovoitov  * License as published by the Free Software Foundation.
7daedfb22SAlexei Starovoitov  */
8daedfb22SAlexei Starovoitov #ifndef _UAPI__LINUX_BPF_H__
9daedfb22SAlexei Starovoitov #define _UAPI__LINUX_BPF_H__
10daedfb22SAlexei Starovoitov 
11daedfb22SAlexei Starovoitov #include <linux/types.h>
12c15952dcSAlexei Starovoitov #include <linux/bpf_common.h>
13daedfb22SAlexei Starovoitov 
14daedfb22SAlexei Starovoitov /* Extended instruction set based on top of classic BPF */
15daedfb22SAlexei Starovoitov 
16daedfb22SAlexei Starovoitov /* instruction classes */
17d405c740SJiong Wang #define BPF_JMP32	0x06	/* jmp mode in word width */
18daedfb22SAlexei Starovoitov #define BPF_ALU64	0x07	/* alu mode in double word width */
19daedfb22SAlexei Starovoitov 
20daedfb22SAlexei Starovoitov /* ld/ldx fields */
21cb5f7334SJesper Dangaard Brouer #define BPF_DW		0x18	/* double word (64-bit) */
22daedfb22SAlexei Starovoitov #define BPF_XADD	0xc0	/* exclusive add */
23daedfb22SAlexei Starovoitov 
24daedfb22SAlexei Starovoitov /* alu/jmp fields */
25daedfb22SAlexei Starovoitov #define BPF_MOV		0xb0	/* mov reg to reg */
26daedfb22SAlexei Starovoitov #define BPF_ARSH	0xc0	/* sign extending arithmetic shift right */
27daedfb22SAlexei Starovoitov 
28daedfb22SAlexei Starovoitov /* change endianness of a register */
29daedfb22SAlexei Starovoitov #define BPF_END		0xd0	/* flags for endianness conversion: */
30daedfb22SAlexei Starovoitov #define BPF_TO_LE	0x00	/* convert to little-endian */
31daedfb22SAlexei Starovoitov #define BPF_TO_BE	0x08	/* convert to big-endian */
32daedfb22SAlexei Starovoitov #define BPF_FROM_LE	BPF_TO_LE
33daedfb22SAlexei Starovoitov #define BPF_FROM_BE	BPF_TO_BE
34daedfb22SAlexei Starovoitov 
3592b31a9aSDaniel Borkmann /* jmp encodings */
36daedfb22SAlexei Starovoitov #define BPF_JNE		0x50	/* jump != */
3792b31a9aSDaniel Borkmann #define BPF_JLT		0xa0	/* LT is unsigned, '<' */
3892b31a9aSDaniel Borkmann #define BPF_JLE		0xb0	/* LE is unsigned, '<=' */
39daedfb22SAlexei Starovoitov #define BPF_JSGT	0x60	/* SGT is signed '>', GT in x86 */
40daedfb22SAlexei Starovoitov #define BPF_JSGE	0x70	/* SGE is signed '>=', GE in x86 */
4192b31a9aSDaniel Borkmann #define BPF_JSLT	0xc0	/* SLT is signed, '<' */
4292b31a9aSDaniel Borkmann #define BPF_JSLE	0xd0	/* SLE is signed, '<=' */
43daedfb22SAlexei Starovoitov #define BPF_CALL	0x80	/* function call */
44daedfb22SAlexei Starovoitov #define BPF_EXIT	0x90	/* function return */
45daedfb22SAlexei Starovoitov 
46daedfb22SAlexei Starovoitov /* Register numbers */
47daedfb22SAlexei Starovoitov enum {
48daedfb22SAlexei Starovoitov 	BPF_REG_0 = 0,
49daedfb22SAlexei Starovoitov 	BPF_REG_1,
50daedfb22SAlexei Starovoitov 	BPF_REG_2,
51daedfb22SAlexei Starovoitov 	BPF_REG_3,
52daedfb22SAlexei Starovoitov 	BPF_REG_4,
53daedfb22SAlexei Starovoitov 	BPF_REG_5,
54daedfb22SAlexei Starovoitov 	BPF_REG_6,
55daedfb22SAlexei Starovoitov 	BPF_REG_7,
56daedfb22SAlexei Starovoitov 	BPF_REG_8,
57daedfb22SAlexei Starovoitov 	BPF_REG_9,
58daedfb22SAlexei Starovoitov 	BPF_REG_10,
59daedfb22SAlexei Starovoitov 	__MAX_BPF_REG,
60daedfb22SAlexei Starovoitov };
61daedfb22SAlexei Starovoitov 
62daedfb22SAlexei Starovoitov /* BPF has 10 general purpose 64-bit registers and stack frame. */
63daedfb22SAlexei Starovoitov #define MAX_BPF_REG	__MAX_BPF_REG
64daedfb22SAlexei Starovoitov 
65daedfb22SAlexei Starovoitov struct bpf_insn {
66daedfb22SAlexei Starovoitov 	__u8	code;		/* opcode */
67daedfb22SAlexei Starovoitov 	__u8	dst_reg:4;	/* dest register */
68daedfb22SAlexei Starovoitov 	__u8	src_reg:4;	/* source register */
69daedfb22SAlexei Starovoitov 	__s16	off;		/* signed offset */
70daedfb22SAlexei Starovoitov 	__s32	imm;		/* signed immediate constant */
71daedfb22SAlexei Starovoitov };
72daedfb22SAlexei Starovoitov 
73b95a5c4dSDaniel Mack /* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */
74b95a5c4dSDaniel Mack struct bpf_lpm_trie_key {
75b95a5c4dSDaniel Mack 	__u32	prefixlen;	/* up to 32 for AF_INET, 128 for AF_INET6 */
76b95a5c4dSDaniel Mack 	__u8	data[0];	/* Arbitrary size */
77b95a5c4dSDaniel Mack };
78b95a5c4dSDaniel Mack 
79de9cbbaaSRoman Gushchin struct bpf_cgroup_storage_key {
80de9cbbaaSRoman Gushchin 	__u64	cgroup_inode_id;	/* cgroup inode id */
81de9cbbaaSRoman Gushchin 	__u32	attach_type;		/* program attach type */
82de9cbbaaSRoman Gushchin };
83de9cbbaaSRoman Gushchin 
84b2197755SDaniel Borkmann /* BPF syscall commands, see bpf(2) man-page for details. */
8599c55f7dSAlexei Starovoitov enum bpf_cmd {
8699c55f7dSAlexei Starovoitov 	BPF_MAP_CREATE,
87db20fd2bSAlexei Starovoitov 	BPF_MAP_LOOKUP_ELEM,
88db20fd2bSAlexei Starovoitov 	BPF_MAP_UPDATE_ELEM,
89db20fd2bSAlexei Starovoitov 	BPF_MAP_DELETE_ELEM,
90db20fd2bSAlexei Starovoitov 	BPF_MAP_GET_NEXT_KEY,
9109756af4SAlexei Starovoitov 	BPF_PROG_LOAD,
92b2197755SDaniel Borkmann 	BPF_OBJ_PIN,
93b2197755SDaniel Borkmann 	BPF_OBJ_GET,
94f4324551SDaniel Mack 	BPF_PROG_ATTACH,
95f4324551SDaniel Mack 	BPF_PROG_DETACH,
961cf1cae9SAlexei Starovoitov 	BPF_PROG_TEST_RUN,
9734ad5580SMartin KaFai Lau 	BPF_PROG_GET_NEXT_ID,
9834ad5580SMartin KaFai Lau 	BPF_MAP_GET_NEXT_ID,
99b16d9aa4SMartin KaFai Lau 	BPF_PROG_GET_FD_BY_ID,
100bd5f5f4eSMartin KaFai Lau 	BPF_MAP_GET_FD_BY_ID,
1011e270976SMartin KaFai Lau 	BPF_OBJ_GET_INFO_BY_FD,
102468e2f64SAlexei Starovoitov 	BPF_PROG_QUERY,
103c4f6699dSAlexei Starovoitov 	BPF_RAW_TRACEPOINT_OPEN,
104f56a653cSMartin KaFai Lau 	BPF_BTF_LOAD,
10578958fcaSMartin KaFai Lau 	BPF_BTF_GET_FD_BY_ID,
10641bdc4b4SYonghong Song 	BPF_TASK_FD_QUERY,
107bd513cd0SMauricio Vasquez B 	BPF_MAP_LOOKUP_AND_DELETE_ELEM,
10887df15deSDaniel Borkmann 	BPF_MAP_FREEZE,
10999c55f7dSAlexei Starovoitov };
11099c55f7dSAlexei Starovoitov 
11199c55f7dSAlexei Starovoitov enum bpf_map_type {
11299c55f7dSAlexei Starovoitov 	BPF_MAP_TYPE_UNSPEC,
1130f8e4bd8SAlexei Starovoitov 	BPF_MAP_TYPE_HASH,
11428fbcfa0SAlexei Starovoitov 	BPF_MAP_TYPE_ARRAY,
11504fd61abSAlexei Starovoitov 	BPF_MAP_TYPE_PROG_ARRAY,
116ea317b26SKaixu Xia 	BPF_MAP_TYPE_PERF_EVENT_ARRAY,
117824bd0ceSAlexei Starovoitov 	BPF_MAP_TYPE_PERCPU_HASH,
118a10423b8SAlexei Starovoitov 	BPF_MAP_TYPE_PERCPU_ARRAY,
119d5a3b1f6SAlexei Starovoitov 	BPF_MAP_TYPE_STACK_TRACE,
1204ed8ec52SMartin KaFai Lau 	BPF_MAP_TYPE_CGROUP_ARRAY,
12129ba732aSMartin KaFai Lau 	BPF_MAP_TYPE_LRU_HASH,
1228f844938SMartin KaFai Lau 	BPF_MAP_TYPE_LRU_PERCPU_HASH,
123b95a5c4dSDaniel Mack 	BPF_MAP_TYPE_LPM_TRIE,
12456f668dfSMartin KaFai Lau 	BPF_MAP_TYPE_ARRAY_OF_MAPS,
125bcc6b1b7SMartin KaFai Lau 	BPF_MAP_TYPE_HASH_OF_MAPS,
126546ac1ffSJohn Fastabend 	BPF_MAP_TYPE_DEVMAP,
127174a79ffSJohn Fastabend 	BPF_MAP_TYPE_SOCKMAP,
1286710e112SJesper Dangaard Brouer 	BPF_MAP_TYPE_CPUMAP,
129fbfc504aSBjörn Töpel 	BPF_MAP_TYPE_XSKMAP,
13081110384SJohn Fastabend 	BPF_MAP_TYPE_SOCKHASH,
131de9cbbaaSRoman Gushchin 	BPF_MAP_TYPE_CGROUP_STORAGE,
1325dc4c4b7SMartin KaFai Lau 	BPF_MAP_TYPE_REUSEPORT_SOCKARRAY,
133b741f163SRoman Gushchin 	BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE,
134f1a2e44aSMauricio Vasquez B 	BPF_MAP_TYPE_QUEUE,
135f1a2e44aSMauricio Vasquez B 	BPF_MAP_TYPE_STACK,
13699c55f7dSAlexei Starovoitov };
13799c55f7dSAlexei Starovoitov 
1386c4fc209SDaniel Borkmann /* Note that tracing related programs such as
1396c4fc209SDaniel Borkmann  * BPF_PROG_TYPE_{KPROBE,TRACEPOINT,PERF_EVENT,RAW_TRACEPOINT}
1406c4fc209SDaniel Borkmann  * are not subject to a stable API since kernel internal data
1416c4fc209SDaniel Borkmann  * structures can change from release to release and may
1426c4fc209SDaniel Borkmann  * therefore break existing tracing BPF programs. Tracing BPF
1436c4fc209SDaniel Borkmann  * programs correspond to /a/ specific kernel which is to be
1446c4fc209SDaniel Borkmann  * analyzed, and not /a/ specific kernel /and/ all future ones.
1456c4fc209SDaniel Borkmann  */
14609756af4SAlexei Starovoitov enum bpf_prog_type {
14709756af4SAlexei Starovoitov 	BPF_PROG_TYPE_UNSPEC,
148ddd872bcSAlexei Starovoitov 	BPF_PROG_TYPE_SOCKET_FILTER,
1492541517cSAlexei Starovoitov 	BPF_PROG_TYPE_KPROBE,
15096be4325SDaniel Borkmann 	BPF_PROG_TYPE_SCHED_CLS,
15194caee8cSDaniel Borkmann 	BPF_PROG_TYPE_SCHED_ACT,
15298b5c2c6SAlexei Starovoitov 	BPF_PROG_TYPE_TRACEPOINT,
1536a773a15SBrenden Blanco 	BPF_PROG_TYPE_XDP,
1540515e599SAlexei Starovoitov 	BPF_PROG_TYPE_PERF_EVENT,
1550e33661dSDaniel Mack 	BPF_PROG_TYPE_CGROUP_SKB,
15661023658SDavid Ahern 	BPF_PROG_TYPE_CGROUP_SOCK,
1573a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_IN,
1583a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_OUT,
1593a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_XMIT,
16040304b2aSLawrence Brakmo 	BPF_PROG_TYPE_SOCK_OPS,
161b005fd18SJohn Fastabend 	BPF_PROG_TYPE_SK_SKB,
162ebc614f6SRoman Gushchin 	BPF_PROG_TYPE_CGROUP_DEVICE,
1634f738adbSJohn Fastabend 	BPF_PROG_TYPE_SK_MSG,
164c4f6699dSAlexei Starovoitov 	BPF_PROG_TYPE_RAW_TRACEPOINT,
1654fbac77dSAndrey Ignatov 	BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
166004d4b27SMathieu Xhonneux 	BPF_PROG_TYPE_LWT_SEG6LOCAL,
167f4364dcfSSean Young 	BPF_PROG_TYPE_LIRC_MODE2,
1682dbb9b9eSMartin KaFai Lau 	BPF_PROG_TYPE_SK_REUSEPORT,
169d58e468bSPetar Penkov 	BPF_PROG_TYPE_FLOW_DISSECTOR,
17009756af4SAlexei Starovoitov };
17109756af4SAlexei Starovoitov 
1720e33661dSDaniel Mack enum bpf_attach_type {
1730e33661dSDaniel Mack 	BPF_CGROUP_INET_INGRESS,
1740e33661dSDaniel Mack 	BPF_CGROUP_INET_EGRESS,
17561023658SDavid Ahern 	BPF_CGROUP_INET_SOCK_CREATE,
17640304b2aSLawrence Brakmo 	BPF_CGROUP_SOCK_OPS,
177464bc0fdSJohn Fastabend 	BPF_SK_SKB_STREAM_PARSER,
178464bc0fdSJohn Fastabend 	BPF_SK_SKB_STREAM_VERDICT,
179ebc614f6SRoman Gushchin 	BPF_CGROUP_DEVICE,
1804f738adbSJohn Fastabend 	BPF_SK_MSG_VERDICT,
1814fbac77dSAndrey Ignatov 	BPF_CGROUP_INET4_BIND,
1824fbac77dSAndrey Ignatov 	BPF_CGROUP_INET6_BIND,
183d74bad4eSAndrey Ignatov 	BPF_CGROUP_INET4_CONNECT,
184d74bad4eSAndrey Ignatov 	BPF_CGROUP_INET6_CONNECT,
185aac3fc32SAndrey Ignatov 	BPF_CGROUP_INET4_POST_BIND,
186aac3fc32SAndrey Ignatov 	BPF_CGROUP_INET6_POST_BIND,
1871cedee13SAndrey Ignatov 	BPF_CGROUP_UDP4_SENDMSG,
1881cedee13SAndrey Ignatov 	BPF_CGROUP_UDP6_SENDMSG,
189f4364dcfSSean Young 	BPF_LIRC_MODE2,
190d58e468bSPetar Penkov 	BPF_FLOW_DISSECTOR,
1910e33661dSDaniel Mack 	__MAX_BPF_ATTACH_TYPE
1920e33661dSDaniel Mack };
1930e33661dSDaniel Mack 
1940e33661dSDaniel Mack #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
1950e33661dSDaniel Mack 
196324bda9eSAlexei Starovoitov /* cgroup-bpf attach flags used in BPF_PROG_ATTACH command
197324bda9eSAlexei Starovoitov  *
198324bda9eSAlexei Starovoitov  * NONE(default): No further bpf programs allowed in the subtree.
199324bda9eSAlexei Starovoitov  *
200324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_OVERRIDE: If a sub-cgroup installs some bpf program,
201324bda9eSAlexei Starovoitov  * the program in this cgroup yields to sub-cgroup program.
202324bda9eSAlexei Starovoitov  *
203324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_MULTI: If a sub-cgroup installs some bpf program,
204324bda9eSAlexei Starovoitov  * that cgroup program gets run in addition to the program in this cgroup.
205324bda9eSAlexei Starovoitov  *
206324bda9eSAlexei Starovoitov  * Only one program is allowed to be attached to a cgroup with
207324bda9eSAlexei Starovoitov  * NONE or BPF_F_ALLOW_OVERRIDE flag.
208324bda9eSAlexei Starovoitov  * Attaching another program on top of NONE or BPF_F_ALLOW_OVERRIDE will
209324bda9eSAlexei Starovoitov  * release old program and attach the new one. Attach flags has to match.
210324bda9eSAlexei Starovoitov  *
211324bda9eSAlexei Starovoitov  * Multiple programs are allowed to be attached to a cgroup with
212324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_MULTI flag. They are executed in FIFO order
213324bda9eSAlexei Starovoitov  * (those that were attached first, run first)
214324bda9eSAlexei Starovoitov  * The programs of sub-cgroup are executed first, then programs of
215324bda9eSAlexei Starovoitov  * this cgroup and then programs of parent cgroup.
216324bda9eSAlexei Starovoitov  * When children program makes decision (like picking TCP CA or sock bind)
217324bda9eSAlexei Starovoitov  * parent program has a chance to override it.
218324bda9eSAlexei Starovoitov  *
219324bda9eSAlexei Starovoitov  * A cgroup with MULTI or OVERRIDE flag allows any attach flags in sub-cgroups.
220324bda9eSAlexei Starovoitov  * A cgroup with NONE doesn't allow any programs in sub-cgroups.
221324bda9eSAlexei Starovoitov  * Ex1:
222324bda9eSAlexei Starovoitov  * cgrp1 (MULTI progs A, B) ->
223324bda9eSAlexei Starovoitov  *    cgrp2 (OVERRIDE prog C) ->
224324bda9eSAlexei Starovoitov  *      cgrp3 (MULTI prog D) ->
225324bda9eSAlexei Starovoitov  *        cgrp4 (OVERRIDE prog E) ->
226324bda9eSAlexei Starovoitov  *          cgrp5 (NONE prog F)
227324bda9eSAlexei Starovoitov  * the event in cgrp5 triggers execution of F,D,A,B in that order.
228324bda9eSAlexei Starovoitov  * if prog F is detached, the execution is E,D,A,B
229324bda9eSAlexei Starovoitov  * if prog F and D are detached, the execution is E,A,B
230324bda9eSAlexei Starovoitov  * if prog F, E and D are detached, the execution is C,A,B
231324bda9eSAlexei Starovoitov  *
232324bda9eSAlexei Starovoitov  * All eligible programs are executed regardless of return code from
233324bda9eSAlexei Starovoitov  * earlier programs.
2347f677633SAlexei Starovoitov  */
2357f677633SAlexei Starovoitov #define BPF_F_ALLOW_OVERRIDE	(1U << 0)
236324bda9eSAlexei Starovoitov #define BPF_F_ALLOW_MULTI	(1U << 1)
2377f677633SAlexei Starovoitov 
238e07b98d9SDavid S. Miller /* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the
239e07b98d9SDavid S. Miller  * verifier will perform strict alignment checking as if the kernel
240e07b98d9SDavid S. Miller  * has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set,
241e07b98d9SDavid S. Miller  * and NET_IP_ALIGN defined to 2.
242e07b98d9SDavid S. Miller  */
243e07b98d9SDavid S. Miller #define BPF_F_STRICT_ALIGNMENT	(1U << 0)
244e07b98d9SDavid S. Miller 
245e9ee9efcSDavid Miller /* If BPF_F_ANY_ALIGNMENT is used in BPF_PROF_LOAD command, the
246e9ee9efcSDavid Miller  * verifier will allow any alignment whatsoever.  On platforms
247e9ee9efcSDavid Miller  * with strict alignment requirements for loads ands stores (such
248e9ee9efcSDavid Miller  * as sparc and mips) the verifier validates that all loads and
249e9ee9efcSDavid Miller  * stores provably follow this requirement.  This flag turns that
250e9ee9efcSDavid Miller  * checking and enforcement off.
251e9ee9efcSDavid Miller  *
252e9ee9efcSDavid Miller  * It is mostly used for testing when we want to validate the
253e9ee9efcSDavid Miller  * context and memory access aspects of the verifier, but because
254e9ee9efcSDavid Miller  * of an unaligned access the alignment check would trigger before
255e9ee9efcSDavid Miller  * the one we are interested in.
256e9ee9efcSDavid Miller  */
257e9ee9efcSDavid Miller #define BPF_F_ANY_ALIGNMENT	(1U << 1)
258e9ee9efcSDavid Miller 
259d8eca5bbSDaniel Borkmann /* When BPF ldimm64's insn[0].src_reg != 0 then this can have
260d8eca5bbSDaniel Borkmann  * two extensions:
261d8eca5bbSDaniel Borkmann  *
262d8eca5bbSDaniel Borkmann  * insn[0].src_reg:  BPF_PSEUDO_MAP_FD   BPF_PSEUDO_MAP_VALUE
263d8eca5bbSDaniel Borkmann  * insn[0].imm:      map fd              map fd
264d8eca5bbSDaniel Borkmann  * insn[1].imm:      0                   offset into value
265d8eca5bbSDaniel Borkmann  * insn[0].off:      0                   0
266d8eca5bbSDaniel Borkmann  * insn[1].off:      0                   0
267d8eca5bbSDaniel Borkmann  * ldimm64 rewrite:  address of map      address of map[0]+offset
268d8eca5bbSDaniel Borkmann  * verifier type:    CONST_PTR_TO_MAP    PTR_TO_MAP_VALUE
269d8eca5bbSDaniel Borkmann  */
270f1a66f85SDaniel Borkmann #define BPF_PSEUDO_MAP_FD	1
271d8eca5bbSDaniel Borkmann #define BPF_PSEUDO_MAP_VALUE	2
272f1a66f85SDaniel Borkmann 
273cc8b0b92SAlexei Starovoitov /* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative
274cc8b0b92SAlexei Starovoitov  * offset to another bpf function
275cc8b0b92SAlexei Starovoitov  */
276cc8b0b92SAlexei Starovoitov #define BPF_PSEUDO_CALL		1
277cc8b0b92SAlexei Starovoitov 
2783274f520SAlexei Starovoitov /* flags for BPF_MAP_UPDATE_ELEM command */
2793274f520SAlexei Starovoitov #define BPF_ANY		0 /* create new element or update existing */
2803274f520SAlexei Starovoitov #define BPF_NOEXIST	1 /* create new element if it didn't exist */
2813274f520SAlexei Starovoitov #define BPF_EXIST	2 /* update existing element */
28296049f3aSAlexei Starovoitov #define BPF_F_LOCK	4 /* spin_lock-ed map_lookup/map_update */
2833274f520SAlexei Starovoitov 
28496eabe7aSMartin KaFai Lau /* flags for BPF_MAP_CREATE command */
2856c905981SAlexei Starovoitov #define BPF_F_NO_PREALLOC	(1U << 0)
28629ba732aSMartin KaFai Lau /* Instead of having one common LRU list in the
2878f844938SMartin KaFai Lau  * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list
28829ba732aSMartin KaFai Lau  * which can scale and perform better.
28929ba732aSMartin KaFai Lau  * Note, the LRU nodes (including free nodes) cannot be moved
29029ba732aSMartin KaFai Lau  * across different LRU lists.
29129ba732aSMartin KaFai Lau  */
29229ba732aSMartin KaFai Lau #define BPF_F_NO_COMMON_LRU	(1U << 1)
29396eabe7aSMartin KaFai Lau /* Specify numa node during map creation */
29496eabe7aSMartin KaFai Lau #define BPF_F_NUMA_NODE		(1U << 2)
2956c905981SAlexei Starovoitov 
296cb4d2b3fSMartin KaFai Lau #define BPF_OBJ_NAME_LEN 16U
297cb4d2b3fSMartin KaFai Lau 
298591fe988SDaniel Borkmann /* Flags for accessing BPF object from syscall side. */
2996e71b04aSChenbo Feng #define BPF_F_RDONLY		(1U << 3)
3006e71b04aSChenbo Feng #define BPF_F_WRONLY		(1U << 4)
3016e71b04aSChenbo Feng 
302615755a7SSong Liu /* Flag for stack_map, store build_id+offset instead of pointer */
303615755a7SSong Liu #define BPF_F_STACK_BUILD_ID	(1U << 5)
304615755a7SSong Liu 
30596b3b6c9SLorenz Bauer /* Zero-initialize hash function seed. This should only be used for testing. */
30696b3b6c9SLorenz Bauer #define BPF_F_ZERO_SEED		(1U << 6)
30796b3b6c9SLorenz Bauer 
308591fe988SDaniel Borkmann /* Flags for accessing BPF object from program side. */
309591fe988SDaniel Borkmann #define BPF_F_RDONLY_PROG	(1U << 7)
310591fe988SDaniel Borkmann #define BPF_F_WRONLY_PROG	(1U << 8)
311591fe988SDaniel Borkmann 
3122f183360SLorenz Bauer /* flags for BPF_PROG_QUERY */
3132f183360SLorenz Bauer #define BPF_F_QUERY_EFFECTIVE	(1U << 0)
3142f183360SLorenz Bauer 
315615755a7SSong Liu enum bpf_stack_build_id_status {
316615755a7SSong Liu 	/* user space need an empty entry to identify end of a trace */
317615755a7SSong Liu 	BPF_STACK_BUILD_ID_EMPTY = 0,
318615755a7SSong Liu 	/* with valid build_id and offset */
319615755a7SSong Liu 	BPF_STACK_BUILD_ID_VALID = 1,
320615755a7SSong Liu 	/* couldn't get build_id, fallback to ip */
321615755a7SSong Liu 	BPF_STACK_BUILD_ID_IP = 2,
322615755a7SSong Liu };
323615755a7SSong Liu 
324615755a7SSong Liu #define BPF_BUILD_ID_SIZE 20
325615755a7SSong Liu struct bpf_stack_build_id {
326615755a7SSong Liu 	__s32		status;
327615755a7SSong Liu 	unsigned char	build_id[BPF_BUILD_ID_SIZE];
328615755a7SSong Liu 	union {
329615755a7SSong Liu 		__u64	offset;
330615755a7SSong Liu 		__u64	ip;
331615755a7SSong Liu 	};
332615755a7SSong Liu };
333615755a7SSong Liu 
33499c55f7dSAlexei Starovoitov union bpf_attr {
33599c55f7dSAlexei Starovoitov 	struct { /* anonymous struct used by BPF_MAP_CREATE command */
33699c55f7dSAlexei Starovoitov 		__u32	map_type;	/* one of enum bpf_map_type */
33799c55f7dSAlexei Starovoitov 		__u32	key_size;	/* size of key in bytes */
33899c55f7dSAlexei Starovoitov 		__u32	value_size;	/* size of value in bytes */
33999c55f7dSAlexei Starovoitov 		__u32	max_entries;	/* max number of entries in a map */
34096eabe7aSMartin KaFai Lau 		__u32	map_flags;	/* BPF_MAP_CREATE related
34196eabe7aSMartin KaFai Lau 					 * flags defined above.
34296eabe7aSMartin KaFai Lau 					 */
34356f668dfSMartin KaFai Lau 		__u32	inner_map_fd;	/* fd pointing to the inner map */
34496eabe7aSMartin KaFai Lau 		__u32	numa_node;	/* numa node (effective only if
34596eabe7aSMartin KaFai Lau 					 * BPF_F_NUMA_NODE is set).
34696eabe7aSMartin KaFai Lau 					 */
347067cae47SMartin KaFai Lau 		char	map_name[BPF_OBJ_NAME_LEN];
348a3884572SJakub Kicinski 		__u32	map_ifindex;	/* ifindex of netdev to create on */
349a26ca7c9SMartin KaFai Lau 		__u32	btf_fd;		/* fd pointing to a BTF type data */
3509b2cf328SMartin KaFai Lau 		__u32	btf_key_type_id;	/* BTF type_id of the key */
3519b2cf328SMartin KaFai Lau 		__u32	btf_value_type_id;	/* BTF type_id of the value */
35299c55f7dSAlexei Starovoitov 	};
353db20fd2bSAlexei Starovoitov 
354db20fd2bSAlexei Starovoitov 	struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
355db20fd2bSAlexei Starovoitov 		__u32		map_fd;
356db20fd2bSAlexei Starovoitov 		__aligned_u64	key;
357db20fd2bSAlexei Starovoitov 		union {
358db20fd2bSAlexei Starovoitov 			__aligned_u64 value;
359db20fd2bSAlexei Starovoitov 			__aligned_u64 next_key;
360db20fd2bSAlexei Starovoitov 		};
3613274f520SAlexei Starovoitov 		__u64		flags;
362db20fd2bSAlexei Starovoitov 	};
36309756af4SAlexei Starovoitov 
36409756af4SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_LOAD command */
36509756af4SAlexei Starovoitov 		__u32		prog_type;	/* one of enum bpf_prog_type */
36609756af4SAlexei Starovoitov 		__u32		insn_cnt;
36709756af4SAlexei Starovoitov 		__aligned_u64	insns;
36809756af4SAlexei Starovoitov 		__aligned_u64	license;
369cbd35700SAlexei Starovoitov 		__u32		log_level;	/* verbosity level of verifier */
370cbd35700SAlexei Starovoitov 		__u32		log_size;	/* size of user buffer */
371cbd35700SAlexei Starovoitov 		__aligned_u64	log_buf;	/* user supplied buffer */
3726c4fc209SDaniel Borkmann 		__u32		kern_version;	/* not used */
373e07b98d9SDavid S. Miller 		__u32		prog_flags;
374067cae47SMartin KaFai Lau 		char		prog_name[BPF_OBJ_NAME_LEN];
3751f6f4cb7SJakub Kicinski 		__u32		prog_ifindex;	/* ifindex of netdev to prep for */
3765e43f899SAndrey Ignatov 		/* For some prog types expected attach type must be known at
3775e43f899SAndrey Ignatov 		 * load time to verify attach type specific parts of prog
3785e43f899SAndrey Ignatov 		 * (context accesses, allowed helpers, etc).
3795e43f899SAndrey Ignatov 		 */
3805e43f899SAndrey Ignatov 		__u32		expected_attach_type;
381838e9690SYonghong Song 		__u32		prog_btf_fd;	/* fd pointing to BTF type data */
382838e9690SYonghong Song 		__u32		func_info_rec_size;	/* userspace bpf_func_info size */
383838e9690SYonghong Song 		__aligned_u64	func_info;	/* func info */
384838e9690SYonghong Song 		__u32		func_info_cnt;	/* number of bpf_func_info records */
385c454a46bSMartin KaFai Lau 		__u32		line_info_rec_size;	/* userspace bpf_line_info size */
386c454a46bSMartin KaFai Lau 		__aligned_u64	line_info;	/* line info */
387c454a46bSMartin KaFai Lau 		__u32		line_info_cnt;	/* number of bpf_line_info records */
38809756af4SAlexei Starovoitov 	};
389b2197755SDaniel Borkmann 
390b2197755SDaniel Borkmann 	struct { /* anonymous struct used by BPF_OBJ_* commands */
391b2197755SDaniel Borkmann 		__aligned_u64	pathname;
392b2197755SDaniel Borkmann 		__u32		bpf_fd;
3936e71b04aSChenbo Feng 		__u32		file_flags;
394b2197755SDaniel Borkmann 	};
395f4324551SDaniel Mack 
396f4324551SDaniel Mack 	struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
397f4324551SDaniel Mack 		__u32		target_fd;	/* container object to attach to */
398f4324551SDaniel Mack 		__u32		attach_bpf_fd;	/* eBPF program to attach */
399f4324551SDaniel Mack 		__u32		attach_type;
4007f677633SAlexei Starovoitov 		__u32		attach_flags;
401f4324551SDaniel Mack 	};
4021cf1cae9SAlexei Starovoitov 
4031cf1cae9SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
4041cf1cae9SAlexei Starovoitov 		__u32		prog_fd;
4051cf1cae9SAlexei Starovoitov 		__u32		retval;
406b5a36b1eSLorenz Bauer 		__u32		data_size_in;	/* input: len of data_in */
407b5a36b1eSLorenz Bauer 		__u32		data_size_out;	/* input/output: len of data_out
408b5a36b1eSLorenz Bauer 						 *   returns ENOSPC if data_out
409b5a36b1eSLorenz Bauer 						 *   is too small.
410b5a36b1eSLorenz Bauer 						 */
4111cf1cae9SAlexei Starovoitov 		__aligned_u64	data_in;
4121cf1cae9SAlexei Starovoitov 		__aligned_u64	data_out;
4131cf1cae9SAlexei Starovoitov 		__u32		repeat;
4141cf1cae9SAlexei Starovoitov 		__u32		duration;
415*b0b9395dSStanislav Fomichev 		__u32		ctx_size_in;	/* input: len of ctx_in */
416*b0b9395dSStanislav Fomichev 		__u32		ctx_size_out;	/* input/output: len of ctx_out
417*b0b9395dSStanislav Fomichev 						 *   returns ENOSPC if ctx_out
418*b0b9395dSStanislav Fomichev 						 *   is too small.
419*b0b9395dSStanislav Fomichev 						 */
420*b0b9395dSStanislav Fomichev 		__aligned_u64	ctx_in;
421*b0b9395dSStanislav Fomichev 		__aligned_u64	ctx_out;
4221cf1cae9SAlexei Starovoitov 	} test;
42334ad5580SMartin KaFai Lau 
424b16d9aa4SMartin KaFai Lau 	struct { /* anonymous struct used by BPF_*_GET_*_ID */
425b16d9aa4SMartin KaFai Lau 		union {
42634ad5580SMartin KaFai Lau 			__u32		start_id;
427b16d9aa4SMartin KaFai Lau 			__u32		prog_id;
428bd5f5f4eSMartin KaFai Lau 			__u32		map_id;
42978958fcaSMartin KaFai Lau 			__u32		btf_id;
430b16d9aa4SMartin KaFai Lau 		};
43134ad5580SMartin KaFai Lau 		__u32		next_id;
4326e71b04aSChenbo Feng 		__u32		open_flags;
43334ad5580SMartin KaFai Lau 	};
4341e270976SMartin KaFai Lau 
4351e270976SMartin KaFai Lau 	struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
4361e270976SMartin KaFai Lau 		__u32		bpf_fd;
4371e270976SMartin KaFai Lau 		__u32		info_len;
4381e270976SMartin KaFai Lau 		__aligned_u64	info;
4391e270976SMartin KaFai Lau 	} info;
440468e2f64SAlexei Starovoitov 
441468e2f64SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_QUERY command */
442468e2f64SAlexei Starovoitov 		__u32		target_fd;	/* container object to query */
443468e2f64SAlexei Starovoitov 		__u32		attach_type;
444468e2f64SAlexei Starovoitov 		__u32		query_flags;
445468e2f64SAlexei Starovoitov 		__u32		attach_flags;
446468e2f64SAlexei Starovoitov 		__aligned_u64	prog_ids;
447468e2f64SAlexei Starovoitov 		__u32		prog_cnt;
448468e2f64SAlexei Starovoitov 	} query;
449c4f6699dSAlexei Starovoitov 
450c4f6699dSAlexei Starovoitov 	struct {
451c4f6699dSAlexei Starovoitov 		__u64 name;
452c4f6699dSAlexei Starovoitov 		__u32 prog_fd;
453c4f6699dSAlexei Starovoitov 	} raw_tracepoint;
454f56a653cSMartin KaFai Lau 
455f56a653cSMartin KaFai Lau 	struct { /* anonymous struct for BPF_BTF_LOAD */
456f56a653cSMartin KaFai Lau 		__aligned_u64	btf;
457f56a653cSMartin KaFai Lau 		__aligned_u64	btf_log_buf;
458f56a653cSMartin KaFai Lau 		__u32		btf_size;
459f56a653cSMartin KaFai Lau 		__u32		btf_log_size;
460f56a653cSMartin KaFai Lau 		__u32		btf_log_level;
461f56a653cSMartin KaFai Lau 	};
46241bdc4b4SYonghong Song 
46341bdc4b4SYonghong Song 	struct {
46441bdc4b4SYonghong Song 		__u32		pid;		/* input: pid */
46541bdc4b4SYonghong Song 		__u32		fd;		/* input: fd */
46641bdc4b4SYonghong Song 		__u32		flags;		/* input: flags */
46741bdc4b4SYonghong Song 		__u32		buf_len;	/* input/output: buf len */
46841bdc4b4SYonghong Song 		__aligned_u64	buf;		/* input/output:
46941bdc4b4SYonghong Song 						 *   tp_name for tracepoint
47041bdc4b4SYonghong Song 						 *   symbol for kprobe
47141bdc4b4SYonghong Song 						 *   filename for uprobe
47241bdc4b4SYonghong Song 						 */
47341bdc4b4SYonghong Song 		__u32		prog_id;	/* output: prod_id */
47441bdc4b4SYonghong Song 		__u32		fd_type;	/* output: BPF_FD_TYPE_* */
47541bdc4b4SYonghong Song 		__u64		probe_offset;	/* output: probe_offset */
47641bdc4b4SYonghong Song 		__u64		probe_addr;	/* output: probe_addr */
47741bdc4b4SYonghong Song 	} task_fd_query;
47899c55f7dSAlexei Starovoitov } __attribute__((aligned(8)));
47999c55f7dSAlexei Starovoitov 
48056a092c8SQuentin Monnet /* The description below is an attempt at providing documentation to eBPF
48156a092c8SQuentin Monnet  * developers about the multiple available eBPF helper functions. It can be
48256a092c8SQuentin Monnet  * parsed and used to produce a manual page. The workflow is the following,
48356a092c8SQuentin Monnet  * and requires the rst2man utility:
484ebb676daSThomas Graf  *
48556a092c8SQuentin Monnet  *     $ ./scripts/bpf_helpers_doc.py \
48656a092c8SQuentin Monnet  *             --filename include/uapi/linux/bpf.h > /tmp/bpf-helpers.rst
48756a092c8SQuentin Monnet  *     $ rst2man /tmp/bpf-helpers.rst > /tmp/bpf-helpers.7
48856a092c8SQuentin Monnet  *     $ man /tmp/bpf-helpers.7
489ebb676daSThomas Graf  *
49056a092c8SQuentin Monnet  * Note that in order to produce this external documentation, some RST
49156a092c8SQuentin Monnet  * formatting is used in the descriptions to get "bold" and "italics" in
49256a092c8SQuentin Monnet  * manual pages. Also note that the few trailing white spaces are
49356a092c8SQuentin Monnet  * intentional, removing them would break paragraphs for rst2man.
494ebb676daSThomas Graf  *
49556a092c8SQuentin Monnet  * Start of BPF helper function descriptions:
496ad4a5223SQuentin Monnet  *
497ad4a5223SQuentin Monnet  * void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)
498ad4a5223SQuentin Monnet  * 	Description
499ad4a5223SQuentin Monnet  * 		Perform a lookup in *map* for an entry associated to *key*.
500ad4a5223SQuentin Monnet  * 	Return
501ad4a5223SQuentin Monnet  * 		Map value associated to *key*, or **NULL** if no entry was
502ad4a5223SQuentin Monnet  * 		found.
503ad4a5223SQuentin Monnet  *
504ad4a5223SQuentin Monnet  * int bpf_map_update_elem(struct bpf_map *map, const void *key, const void *value, u64 flags)
505ad4a5223SQuentin Monnet  * 	Description
506ad4a5223SQuentin Monnet  * 		Add or update the value of the entry associated to *key* in
507ad4a5223SQuentin Monnet  * 		*map* with *value*. *flags* is one of:
508ad4a5223SQuentin Monnet  *
509ad4a5223SQuentin Monnet  * 		**BPF_NOEXIST**
510ad4a5223SQuentin Monnet  * 			The entry for *key* must not exist in the map.
511ad4a5223SQuentin Monnet  * 		**BPF_EXIST**
512ad4a5223SQuentin Monnet  * 			The entry for *key* must already exist in the map.
513ad4a5223SQuentin Monnet  * 		**BPF_ANY**
514ad4a5223SQuentin Monnet  * 			No condition on the existence of the entry for *key*.
515ad4a5223SQuentin Monnet  *
516ad4a5223SQuentin Monnet  * 		Flag value **BPF_NOEXIST** cannot be used for maps of types
517ad4a5223SQuentin Monnet  * 		**BPF_MAP_TYPE_ARRAY** or **BPF_MAP_TYPE_PERCPU_ARRAY**  (all
518ad4a5223SQuentin Monnet  * 		elements always exist), the helper would return an error.
519ad4a5223SQuentin Monnet  * 	Return
520ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
521ad4a5223SQuentin Monnet  *
522ad4a5223SQuentin Monnet  * int bpf_map_delete_elem(struct bpf_map *map, const void *key)
523ad4a5223SQuentin Monnet  * 	Description
524ad4a5223SQuentin Monnet  * 		Delete entry with *key* from *map*.
525ad4a5223SQuentin Monnet  * 	Return
526ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
527ad4a5223SQuentin Monnet  *
528ad4a5223SQuentin Monnet  * int bpf_probe_read(void *dst, u32 size, const void *src)
529ad4a5223SQuentin Monnet  * 	Description
530ad4a5223SQuentin Monnet  * 		For tracing programs, safely attempt to read *size* bytes from
531ad4a5223SQuentin Monnet  * 		address *src* and store the data in *dst*.
532ad4a5223SQuentin Monnet  * 	Return
533ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
534ad4a5223SQuentin Monnet  *
535ad4a5223SQuentin Monnet  * u64 bpf_ktime_get_ns(void)
536ad4a5223SQuentin Monnet  * 	Description
537ad4a5223SQuentin Monnet  * 		Return the time elapsed since system boot, in nanoseconds.
538ad4a5223SQuentin Monnet  * 	Return
539ad4a5223SQuentin Monnet  * 		Current *ktime*.
540ad4a5223SQuentin Monnet  *
541ad4a5223SQuentin Monnet  * int bpf_trace_printk(const char *fmt, u32 fmt_size, ...)
542ad4a5223SQuentin Monnet  * 	Description
543ad4a5223SQuentin Monnet  * 		This helper is a "printk()-like" facility for debugging. It
544ad4a5223SQuentin Monnet  * 		prints a message defined by format *fmt* (of size *fmt_size*)
545ad4a5223SQuentin Monnet  * 		to file *\/sys/kernel/debug/tracing/trace* from DebugFS, if
546ad4a5223SQuentin Monnet  * 		available. It can take up to three additional **u64**
547ad4a5223SQuentin Monnet  * 		arguments (as an eBPF helpers, the total number of arguments is
548ad4a5223SQuentin Monnet  * 		limited to five).
549ad4a5223SQuentin Monnet  *
550ad4a5223SQuentin Monnet  * 		Each time the helper is called, it appends a line to the trace.
551ad4a5223SQuentin Monnet  * 		The format of the trace is customizable, and the exact output
552ad4a5223SQuentin Monnet  * 		one will get depends on the options set in
553ad4a5223SQuentin Monnet  * 		*\/sys/kernel/debug/tracing/trace_options* (see also the
554ad4a5223SQuentin Monnet  * 		*README* file under the same directory). However, it usually
555ad4a5223SQuentin Monnet  * 		defaults to something like:
556ad4a5223SQuentin Monnet  *
557ad4a5223SQuentin Monnet  * 		::
558ad4a5223SQuentin Monnet  *
559ad4a5223SQuentin Monnet  * 			telnet-470   [001] .N.. 419421.045894: 0x00000001: <formatted msg>
560ad4a5223SQuentin Monnet  *
561ad4a5223SQuentin Monnet  * 		In the above:
562ad4a5223SQuentin Monnet  *
563ad4a5223SQuentin Monnet  * 			* ``telnet`` is the name of the current task.
564ad4a5223SQuentin Monnet  * 			* ``470`` is the PID of the current task.
565ad4a5223SQuentin Monnet  * 			* ``001`` is the CPU number on which the task is
566ad4a5223SQuentin Monnet  * 			  running.
567ad4a5223SQuentin Monnet  * 			* In ``.N..``, each character refers to a set of
568ad4a5223SQuentin Monnet  * 			  options (whether irqs are enabled, scheduling
569ad4a5223SQuentin Monnet  * 			  options, whether hard/softirqs are running, level of
570ad4a5223SQuentin Monnet  * 			  preempt_disabled respectively). **N** means that
571ad4a5223SQuentin Monnet  * 			  **TIF_NEED_RESCHED** and **PREEMPT_NEED_RESCHED**
572ad4a5223SQuentin Monnet  * 			  are set.
573ad4a5223SQuentin Monnet  * 			* ``419421.045894`` is a timestamp.
574ad4a5223SQuentin Monnet  * 			* ``0x00000001`` is a fake value used by BPF for the
575ad4a5223SQuentin Monnet  * 			  instruction pointer register.
576ad4a5223SQuentin Monnet  * 			* ``<formatted msg>`` is the message formatted with
577ad4a5223SQuentin Monnet  * 			  *fmt*.
578ad4a5223SQuentin Monnet  *
579ad4a5223SQuentin Monnet  * 		The conversion specifiers supported by *fmt* are similar, but
580ad4a5223SQuentin Monnet  * 		more limited than for printk(). They are **%d**, **%i**,
581ad4a5223SQuentin Monnet  * 		**%u**, **%x**, **%ld**, **%li**, **%lu**, **%lx**, **%lld**,
582ad4a5223SQuentin Monnet  * 		**%lli**, **%llu**, **%llx**, **%p**, **%s**. No modifier (size
583ad4a5223SQuentin Monnet  * 		of field, padding with zeroes, etc.) is available, and the
584ad4a5223SQuentin Monnet  * 		helper will return **-EINVAL** (but print nothing) if it
585ad4a5223SQuentin Monnet  * 		encounters an unknown specifier.
586ad4a5223SQuentin Monnet  *
587ad4a5223SQuentin Monnet  * 		Also, note that **bpf_trace_printk**\ () is slow, and should
588ad4a5223SQuentin Monnet  * 		only be used for debugging purposes. For this reason, a notice
589ad4a5223SQuentin Monnet  * 		bloc (spanning several lines) is printed to kernel logs and
590ad4a5223SQuentin Monnet  * 		states that the helper should not be used "for production use"
591ad4a5223SQuentin Monnet  * 		the first time this helper is used (or more precisely, when
592ad4a5223SQuentin Monnet  * 		**trace_printk**\ () buffers are allocated). For passing values
593ad4a5223SQuentin Monnet  * 		to user space, perf events should be preferred.
594ad4a5223SQuentin Monnet  * 	Return
595ad4a5223SQuentin Monnet  * 		The number of bytes written to the buffer, or a negative error
596ad4a5223SQuentin Monnet  * 		in case of failure.
597ad4a5223SQuentin Monnet  *
5981fdd08beSQuentin Monnet  * u32 bpf_get_prandom_u32(void)
5991fdd08beSQuentin Monnet  * 	Description
6001fdd08beSQuentin Monnet  * 		Get a pseudo-random number.
6011fdd08beSQuentin Monnet  *
6021fdd08beSQuentin Monnet  * 		From a security point of view, this helper uses its own
6031fdd08beSQuentin Monnet  * 		pseudo-random internal state, and cannot be used to infer the
6041fdd08beSQuentin Monnet  * 		seed of other random functions in the kernel. However, it is
6051fdd08beSQuentin Monnet  * 		essential to note that the generator used by the helper is not
6061fdd08beSQuentin Monnet  * 		cryptographically secure.
6071fdd08beSQuentin Monnet  * 	Return
6081fdd08beSQuentin Monnet  * 		A random 32-bit unsigned value.
6091fdd08beSQuentin Monnet  *
6101fdd08beSQuentin Monnet  * u32 bpf_get_smp_processor_id(void)
6111fdd08beSQuentin Monnet  * 	Description
6121fdd08beSQuentin Monnet  * 		Get the SMP (symmetric multiprocessing) processor id. Note that
6131fdd08beSQuentin Monnet  * 		all programs run with preemption disabled, which means that the
6141fdd08beSQuentin Monnet  * 		SMP processor id is stable during all the execution of the
6151fdd08beSQuentin Monnet  * 		program.
6161fdd08beSQuentin Monnet  * 	Return
6171fdd08beSQuentin Monnet  * 		The SMP id of the processor running the program.
6181fdd08beSQuentin Monnet  *
619ad4a5223SQuentin Monnet  * int bpf_skb_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len, u64 flags)
620ad4a5223SQuentin Monnet  * 	Description
621ad4a5223SQuentin Monnet  * 		Store *len* bytes from address *from* into the packet
622ad4a5223SQuentin Monnet  * 		associated to *skb*, at *offset*. *flags* are a combination of
623ad4a5223SQuentin Monnet  * 		**BPF_F_RECOMPUTE_CSUM** (automatically recompute the
624ad4a5223SQuentin Monnet  * 		checksum for the packet after storing the bytes) and
625ad4a5223SQuentin Monnet  * 		**BPF_F_INVALIDATE_HASH** (set *skb*\ **->hash**, *skb*\
626ad4a5223SQuentin Monnet  * 		**->swhash** and *skb*\ **->l4hash** to 0).
627ad4a5223SQuentin Monnet  *
628ad4a5223SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
629ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
630ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
631ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
632ad4a5223SQuentin Monnet  * 		direct packet access.
633ad4a5223SQuentin Monnet  * 	Return
634ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
635ad4a5223SQuentin Monnet  *
636ad4a5223SQuentin Monnet  * int bpf_l3_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 size)
637ad4a5223SQuentin Monnet  * 	Description
638ad4a5223SQuentin Monnet  * 		Recompute the layer 3 (e.g. IP) checksum for the packet
639ad4a5223SQuentin Monnet  * 		associated to *skb*. Computation is incremental, so the helper
640ad4a5223SQuentin Monnet  * 		must know the former value of the header field that was
641ad4a5223SQuentin Monnet  * 		modified (*from*), the new value of this field (*to*), and the
642ad4a5223SQuentin Monnet  * 		number of bytes (2 or 4) for this field, stored in *size*.
643ad4a5223SQuentin Monnet  * 		Alternatively, it is possible to store the difference between
644ad4a5223SQuentin Monnet  * 		the previous and the new values of the header field in *to*, by
645ad4a5223SQuentin Monnet  * 		setting *from* and *size* to 0. For both methods, *offset*
646ad4a5223SQuentin Monnet  * 		indicates the location of the IP checksum within the packet.
647ad4a5223SQuentin Monnet  *
648ad4a5223SQuentin Monnet  * 		This helper works in combination with **bpf_csum_diff**\ (),
649ad4a5223SQuentin Monnet  * 		which does not update the checksum in-place, but offers more
650ad4a5223SQuentin Monnet  * 		flexibility and can handle sizes larger than 2 or 4 for the
651ad4a5223SQuentin Monnet  * 		checksum to update.
652ad4a5223SQuentin Monnet  *
653ad4a5223SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
654ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
655ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
656ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
657ad4a5223SQuentin Monnet  * 		direct packet access.
658ad4a5223SQuentin Monnet  * 	Return
659ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
660ad4a5223SQuentin Monnet  *
661ad4a5223SQuentin Monnet  * int bpf_l4_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 flags)
662ad4a5223SQuentin Monnet  * 	Description
663ad4a5223SQuentin Monnet  * 		Recompute the layer 4 (e.g. TCP, UDP or ICMP) checksum for the
664ad4a5223SQuentin Monnet  * 		packet associated to *skb*. Computation is incremental, so the
665ad4a5223SQuentin Monnet  * 		helper must know the former value of the header field that was
666ad4a5223SQuentin Monnet  * 		modified (*from*), the new value of this field (*to*), and the
667ad4a5223SQuentin Monnet  * 		number of bytes (2 or 4) for this field, stored on the lowest
668ad4a5223SQuentin Monnet  * 		four bits of *flags*. Alternatively, it is possible to store
669ad4a5223SQuentin Monnet  * 		the difference between the previous and the new values of the
670ad4a5223SQuentin Monnet  * 		header field in *to*, by setting *from* and the four lowest
671ad4a5223SQuentin Monnet  * 		bits of *flags* to 0. For both methods, *offset* indicates the
672ad4a5223SQuentin Monnet  * 		location of the IP checksum within the packet. In addition to
673ad4a5223SQuentin Monnet  * 		the size of the field, *flags* can be added (bitwise OR) actual
674ad4a5223SQuentin Monnet  * 		flags. With **BPF_F_MARK_MANGLED_0**, a null checksum is left
675ad4a5223SQuentin Monnet  * 		untouched (unless **BPF_F_MARK_ENFORCE** is added as well), and
676ad4a5223SQuentin Monnet  * 		for updates resulting in a null checksum the value is set to
677ad4a5223SQuentin Monnet  * 		**CSUM_MANGLED_0** instead. Flag **BPF_F_PSEUDO_HDR** indicates
678ad4a5223SQuentin Monnet  * 		the checksum is to be computed against a pseudo-header.
679ad4a5223SQuentin Monnet  *
680ad4a5223SQuentin Monnet  * 		This helper works in combination with **bpf_csum_diff**\ (),
681ad4a5223SQuentin Monnet  * 		which does not update the checksum in-place, but offers more
682ad4a5223SQuentin Monnet  * 		flexibility and can handle sizes larger than 2 or 4 for the
683ad4a5223SQuentin Monnet  * 		checksum to update.
684ad4a5223SQuentin Monnet  *
685ad4a5223SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
686ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
687ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
688ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
689ad4a5223SQuentin Monnet  * 		direct packet access.
690ad4a5223SQuentin Monnet  * 	Return
691ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
692ad4a5223SQuentin Monnet  *
693ad4a5223SQuentin Monnet  * int bpf_tail_call(void *ctx, struct bpf_map *prog_array_map, u32 index)
694ad4a5223SQuentin Monnet  * 	Description
695ad4a5223SQuentin Monnet  * 		This special helper is used to trigger a "tail call", or in
696ad4a5223SQuentin Monnet  * 		other words, to jump into another eBPF program. The same stack
697ad4a5223SQuentin Monnet  * 		frame is used (but values on stack and in registers for the
698ad4a5223SQuentin Monnet  * 		caller are not accessible to the callee). This mechanism allows
699ad4a5223SQuentin Monnet  * 		for program chaining, either for raising the maximum number of
700ad4a5223SQuentin Monnet  * 		available eBPF instructions, or to execute given programs in
701ad4a5223SQuentin Monnet  * 		conditional blocks. For security reasons, there is an upper
702ad4a5223SQuentin Monnet  * 		limit to the number of successive tail calls that can be
703ad4a5223SQuentin Monnet  * 		performed.
704ad4a5223SQuentin Monnet  *
705ad4a5223SQuentin Monnet  * 		Upon call of this helper, the program attempts to jump into a
706ad4a5223SQuentin Monnet  * 		program referenced at index *index* in *prog_array_map*, a
707ad4a5223SQuentin Monnet  * 		special map of type **BPF_MAP_TYPE_PROG_ARRAY**, and passes
708ad4a5223SQuentin Monnet  * 		*ctx*, a pointer to the context.
709ad4a5223SQuentin Monnet  *
710ad4a5223SQuentin Monnet  * 		If the call succeeds, the kernel immediately runs the first
711ad4a5223SQuentin Monnet  * 		instruction of the new program. This is not a function call,
712ad4a5223SQuentin Monnet  * 		and it never returns to the previous program. If the call
713ad4a5223SQuentin Monnet  * 		fails, then the helper has no effect, and the caller continues
714ad4a5223SQuentin Monnet  * 		to run its subsequent instructions. A call can fail if the
715ad4a5223SQuentin Monnet  * 		destination program for the jump does not exist (i.e. *index*
716ad4a5223SQuentin Monnet  * 		is superior to the number of entries in *prog_array_map*), or
717ad4a5223SQuentin Monnet  * 		if the maximum number of tail calls has been reached for this
718ad4a5223SQuentin Monnet  * 		chain of programs. This limit is defined in the kernel by the
719ad4a5223SQuentin Monnet  * 		macro **MAX_TAIL_CALL_CNT** (not accessible to user space),
720ad4a5223SQuentin Monnet  * 		which is currently set to 32.
721ad4a5223SQuentin Monnet  * 	Return
722ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
723ad4a5223SQuentin Monnet  *
724ad4a5223SQuentin Monnet  * int bpf_clone_redirect(struct sk_buff *skb, u32 ifindex, u64 flags)
725ad4a5223SQuentin Monnet  * 	Description
726ad4a5223SQuentin Monnet  * 		Clone and redirect the packet associated to *skb* to another
727ad4a5223SQuentin Monnet  * 		net device of index *ifindex*. Both ingress and egress
728ad4a5223SQuentin Monnet  * 		interfaces can be used for redirection. The **BPF_F_INGRESS**
729ad4a5223SQuentin Monnet  * 		value in *flags* is used to make the distinction (ingress path
730ad4a5223SQuentin Monnet  * 		is selected if the flag is present, egress path otherwise).
731ad4a5223SQuentin Monnet  * 		This is the only flag supported for now.
732ad4a5223SQuentin Monnet  *
733ad4a5223SQuentin Monnet  * 		In comparison with **bpf_redirect**\ () helper,
734ad4a5223SQuentin Monnet  * 		**bpf_clone_redirect**\ () has the associated cost of
735ad4a5223SQuentin Monnet  * 		duplicating the packet buffer, but this can be executed out of
736ad4a5223SQuentin Monnet  * 		the eBPF program. Conversely, **bpf_redirect**\ () is more
737ad4a5223SQuentin Monnet  * 		efficient, but it is handled through an action code where the
738ad4a5223SQuentin Monnet  * 		redirection happens only after the eBPF program has returned.
739ad4a5223SQuentin Monnet  *
740ad4a5223SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
741ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
742ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
743ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
744ad4a5223SQuentin Monnet  * 		direct packet access.
745ad4a5223SQuentin Monnet  * 	Return
746ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
747c456dec4SQuentin Monnet  *
748c456dec4SQuentin Monnet  * u64 bpf_get_current_pid_tgid(void)
749c456dec4SQuentin Monnet  * 	Return
750c456dec4SQuentin Monnet  * 		A 64-bit integer containing the current tgid and pid, and
751c456dec4SQuentin Monnet  * 		created as such:
752c456dec4SQuentin Monnet  * 		*current_task*\ **->tgid << 32 \|**
753c456dec4SQuentin Monnet  * 		*current_task*\ **->pid**.
754c456dec4SQuentin Monnet  *
755c456dec4SQuentin Monnet  * u64 bpf_get_current_uid_gid(void)
756c456dec4SQuentin Monnet  * 	Return
757c456dec4SQuentin Monnet  * 		A 64-bit integer containing the current GID and UID, and
758c456dec4SQuentin Monnet  * 		created as such: *current_gid* **<< 32 \|** *current_uid*.
759c456dec4SQuentin Monnet  *
760c456dec4SQuentin Monnet  * int bpf_get_current_comm(char *buf, u32 size_of_buf)
761c456dec4SQuentin Monnet  * 	Description
762c456dec4SQuentin Monnet  * 		Copy the **comm** attribute of the current task into *buf* of
763c456dec4SQuentin Monnet  * 		*size_of_buf*. The **comm** attribute contains the name of
764c456dec4SQuentin Monnet  * 		the executable (excluding the path) for the current task. The
765c456dec4SQuentin Monnet  * 		*size_of_buf* must be strictly positive. On success, the
766c456dec4SQuentin Monnet  * 		helper makes sure that the *buf* is NUL-terminated. On failure,
767c456dec4SQuentin Monnet  * 		it is filled with zeroes.
768c456dec4SQuentin Monnet  * 	Return
769c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
770c456dec4SQuentin Monnet  *
7711fdd08beSQuentin Monnet  * u32 bpf_get_cgroup_classid(struct sk_buff *skb)
7721fdd08beSQuentin Monnet  * 	Description
7731fdd08beSQuentin Monnet  * 		Retrieve the classid for the current task, i.e. for the net_cls
7741fdd08beSQuentin Monnet  * 		cgroup to which *skb* belongs.
7751fdd08beSQuentin Monnet  *
7761fdd08beSQuentin Monnet  * 		This helper can be used on TC egress path, but not on ingress.
7771fdd08beSQuentin Monnet  *
7781fdd08beSQuentin Monnet  * 		The net_cls cgroup provides an interface to tag network packets
7791fdd08beSQuentin Monnet  * 		based on a user-provided identifier for all traffic coming from
7801fdd08beSQuentin Monnet  * 		the tasks belonging to the related cgroup. See also the related
7811fdd08beSQuentin Monnet  * 		kernel documentation, available from the Linux sources in file
7821fdd08beSQuentin Monnet  * 		*Documentation/cgroup-v1/net_cls.txt*.
7831fdd08beSQuentin Monnet  *
7841fdd08beSQuentin Monnet  * 		The Linux kernel has two versions for cgroups: there are
7851fdd08beSQuentin Monnet  * 		cgroups v1 and cgroups v2. Both are available to users, who can
7861fdd08beSQuentin Monnet  * 		use a mixture of them, but note that the net_cls cgroup is for
7871fdd08beSQuentin Monnet  * 		cgroup v1 only. This makes it incompatible with BPF programs
7881fdd08beSQuentin Monnet  * 		run on cgroups, which is a cgroup-v2-only feature (a socket can
7891fdd08beSQuentin Monnet  * 		only hold data for one version of cgroups at a time).
7901fdd08beSQuentin Monnet  *
7911fdd08beSQuentin Monnet  * 		This helper is only available is the kernel was compiled with
7921fdd08beSQuentin Monnet  * 		the **CONFIG_CGROUP_NET_CLASSID** configuration option set to
7931fdd08beSQuentin Monnet  * 		"**y**" or to "**m**".
7941fdd08beSQuentin Monnet  * 	Return
7951fdd08beSQuentin Monnet  * 		The classid, or 0 for the default unconfigured classid.
7961fdd08beSQuentin Monnet  *
797c456dec4SQuentin Monnet  * int bpf_skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)
798c456dec4SQuentin Monnet  * 	Description
799c456dec4SQuentin Monnet  * 		Push a *vlan_tci* (VLAN tag control information) of protocol
800c456dec4SQuentin Monnet  * 		*vlan_proto* to the packet associated to *skb*, then update
801c456dec4SQuentin Monnet  * 		the checksum. Note that if *vlan_proto* is different from
802c456dec4SQuentin Monnet  * 		**ETH_P_8021Q** and **ETH_P_8021AD**, it is considered to
803c456dec4SQuentin Monnet  * 		be **ETH_P_8021Q**.
804c456dec4SQuentin Monnet  *
805c456dec4SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
806c456dec4SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
807c456dec4SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
808c456dec4SQuentin Monnet  * 		performed again, if the helper is used in combination with
809c456dec4SQuentin Monnet  * 		direct packet access.
810c456dec4SQuentin Monnet  * 	Return
811c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
812c456dec4SQuentin Monnet  *
813c456dec4SQuentin Monnet  * int bpf_skb_vlan_pop(struct sk_buff *skb)
814c456dec4SQuentin Monnet  * 	Description
815c456dec4SQuentin Monnet  * 		Pop a VLAN header from the packet associated to *skb*.
816c456dec4SQuentin Monnet  *
817c456dec4SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
818c456dec4SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
819c456dec4SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
820c456dec4SQuentin Monnet  * 		performed again, if the helper is used in combination with
821c456dec4SQuentin Monnet  * 		direct packet access.
822c456dec4SQuentin Monnet  * 	Return
823c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
824c456dec4SQuentin Monnet  *
825c456dec4SQuentin Monnet  * int bpf_skb_get_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
826c456dec4SQuentin Monnet  * 	Description
827c456dec4SQuentin Monnet  * 		Get tunnel metadata. This helper takes a pointer *key* to an
828c456dec4SQuentin Monnet  * 		empty **struct bpf_tunnel_key** of **size**, that will be
829c456dec4SQuentin Monnet  * 		filled with tunnel metadata for the packet associated to *skb*.
830c456dec4SQuentin Monnet  * 		The *flags* can be set to **BPF_F_TUNINFO_IPV6**, which
831c456dec4SQuentin Monnet  * 		indicates that the tunnel is based on IPv6 protocol instead of
832c456dec4SQuentin Monnet  * 		IPv4.
833c456dec4SQuentin Monnet  *
834c456dec4SQuentin Monnet  * 		The **struct bpf_tunnel_key** is an object that generalizes the
835c456dec4SQuentin Monnet  * 		principal parameters used by various tunneling protocols into a
836c456dec4SQuentin Monnet  * 		single struct. This way, it can be used to easily make a
837c456dec4SQuentin Monnet  * 		decision based on the contents of the encapsulation header,
838c456dec4SQuentin Monnet  * 		"summarized" in this struct. In particular, it holds the IP
839c456dec4SQuentin Monnet  * 		address of the remote end (IPv4 or IPv6, depending on the case)
840c456dec4SQuentin Monnet  * 		in *key*\ **->remote_ipv4** or *key*\ **->remote_ipv6**. Also,
841c456dec4SQuentin Monnet  * 		this struct exposes the *key*\ **->tunnel_id**, which is
842c456dec4SQuentin Monnet  * 		generally mapped to a VNI (Virtual Network Identifier), making
843c456dec4SQuentin Monnet  * 		it programmable together with the **bpf_skb_set_tunnel_key**\
844c456dec4SQuentin Monnet  * 		() helper.
845c456dec4SQuentin Monnet  *
846c456dec4SQuentin Monnet  * 		Let's imagine that the following code is part of a program
847c456dec4SQuentin Monnet  * 		attached to the TC ingress interface, on one end of a GRE
848c456dec4SQuentin Monnet  * 		tunnel, and is supposed to filter out all messages coming from
849c456dec4SQuentin Monnet  * 		remote ends with IPv4 address other than 10.0.0.1:
850c456dec4SQuentin Monnet  *
851c456dec4SQuentin Monnet  * 		::
852c456dec4SQuentin Monnet  *
853c456dec4SQuentin Monnet  * 			int ret;
854c456dec4SQuentin Monnet  * 			struct bpf_tunnel_key key = {};
855c456dec4SQuentin Monnet  *
856c456dec4SQuentin Monnet  * 			ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
857c456dec4SQuentin Monnet  * 			if (ret < 0)
858c456dec4SQuentin Monnet  * 				return TC_ACT_SHOT;	// drop packet
859c456dec4SQuentin Monnet  *
860c456dec4SQuentin Monnet  * 			if (key.remote_ipv4 != 0x0a000001)
861c456dec4SQuentin Monnet  * 				return TC_ACT_SHOT;	// drop packet
862c456dec4SQuentin Monnet  *
863c456dec4SQuentin Monnet  * 			return TC_ACT_OK;		// accept packet
864c456dec4SQuentin Monnet  *
865c456dec4SQuentin Monnet  * 		This interface can also be used with all encapsulation devices
866c456dec4SQuentin Monnet  * 		that can operate in "collect metadata" mode: instead of having
867c456dec4SQuentin Monnet  * 		one network device per specific configuration, the "collect
868c456dec4SQuentin Monnet  * 		metadata" mode only requires a single device where the
869c456dec4SQuentin Monnet  * 		configuration can be extracted from this helper.
870c456dec4SQuentin Monnet  *
871c456dec4SQuentin Monnet  * 		This can be used together with various tunnels such as VXLan,
872c456dec4SQuentin Monnet  * 		Geneve, GRE or IP in IP (IPIP).
873c456dec4SQuentin Monnet  * 	Return
874c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
875c456dec4SQuentin Monnet  *
876c456dec4SQuentin Monnet  * int bpf_skb_set_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
877c456dec4SQuentin Monnet  * 	Description
878c456dec4SQuentin Monnet  * 		Populate tunnel metadata for packet associated to *skb.* The
879c456dec4SQuentin Monnet  * 		tunnel metadata is set to the contents of *key*, of *size*. The
880c456dec4SQuentin Monnet  * 		*flags* can be set to a combination of the following values:
881c456dec4SQuentin Monnet  *
882c456dec4SQuentin Monnet  * 		**BPF_F_TUNINFO_IPV6**
883c456dec4SQuentin Monnet  * 			Indicate that the tunnel is based on IPv6 protocol
884c456dec4SQuentin Monnet  * 			instead of IPv4.
885c456dec4SQuentin Monnet  * 		**BPF_F_ZERO_CSUM_TX**
886c456dec4SQuentin Monnet  * 			For IPv4 packets, add a flag to tunnel metadata
887c456dec4SQuentin Monnet  * 			indicating that checksum computation should be skipped
888c456dec4SQuentin Monnet  * 			and checksum set to zeroes.
889c456dec4SQuentin Monnet  * 		**BPF_F_DONT_FRAGMENT**
890c456dec4SQuentin Monnet  * 			Add a flag to tunnel metadata indicating that the
891c456dec4SQuentin Monnet  * 			packet should not be fragmented.
892c456dec4SQuentin Monnet  * 		**BPF_F_SEQ_NUMBER**
893c456dec4SQuentin Monnet  * 			Add a flag to tunnel metadata indicating that a
894c456dec4SQuentin Monnet  * 			sequence number should be added to tunnel header before
895c456dec4SQuentin Monnet  * 			sending the packet. This flag was added for GRE
896c456dec4SQuentin Monnet  * 			encapsulation, but might be used with other protocols
897c456dec4SQuentin Monnet  * 			as well in the future.
898c456dec4SQuentin Monnet  *
899c456dec4SQuentin Monnet  * 		Here is a typical usage on the transmit path:
900c456dec4SQuentin Monnet  *
901c456dec4SQuentin Monnet  * 		::
902c456dec4SQuentin Monnet  *
903c456dec4SQuentin Monnet  * 			struct bpf_tunnel_key key;
904c456dec4SQuentin Monnet  * 			     populate key ...
905c456dec4SQuentin Monnet  * 			bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0);
906c456dec4SQuentin Monnet  * 			bpf_clone_redirect(skb, vxlan_dev_ifindex, 0);
907c456dec4SQuentin Monnet  *
908c456dec4SQuentin Monnet  * 		See also the description of the **bpf_skb_get_tunnel_key**\ ()
909c456dec4SQuentin Monnet  * 		helper for additional information.
910c456dec4SQuentin Monnet  * 	Return
911c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
912c456dec4SQuentin Monnet  *
913c6b5fb86SQuentin Monnet  * u64 bpf_perf_event_read(struct bpf_map *map, u64 flags)
914c6b5fb86SQuentin Monnet  * 	Description
915c6b5fb86SQuentin Monnet  * 		Read the value of a perf event counter. This helper relies on a
916c6b5fb86SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of
917c6b5fb86SQuentin Monnet  * 		the perf event counter is selected when *map* is updated with
918c6b5fb86SQuentin Monnet  * 		perf event file descriptors. The *map* is an array whose size
919c6b5fb86SQuentin Monnet  * 		is the number of available CPUs, and each cell contains a value
920c6b5fb86SQuentin Monnet  * 		relative to one CPU. The value to retrieve is indicated by
921c6b5fb86SQuentin Monnet  * 		*flags*, that contains the index of the CPU to look up, masked
922c6b5fb86SQuentin Monnet  * 		with **BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
923c6b5fb86SQuentin Monnet  * 		**BPF_F_CURRENT_CPU** to indicate that the value for the
924c6b5fb86SQuentin Monnet  * 		current CPU should be retrieved.
925c6b5fb86SQuentin Monnet  *
926c6b5fb86SQuentin Monnet  * 		Note that before Linux 4.13, only hardware perf event can be
927c6b5fb86SQuentin Monnet  * 		retrieved.
928c6b5fb86SQuentin Monnet  *
929c6b5fb86SQuentin Monnet  * 		Also, be aware that the newer helper
930c6b5fb86SQuentin Monnet  * 		**bpf_perf_event_read_value**\ () is recommended over
9313bd5a09bSQuentin Monnet  * 		**bpf_perf_event_read**\ () in general. The latter has some ABI
932c6b5fb86SQuentin Monnet  * 		quirks where error and counter value are used as a return code
933c6b5fb86SQuentin Monnet  * 		(which is wrong to do since ranges may overlap). This issue is
9343bd5a09bSQuentin Monnet  * 		fixed with **bpf_perf_event_read_value**\ (), which at the same
9353bd5a09bSQuentin Monnet  * 		time provides more features over the **bpf_perf_event_read**\
9363bd5a09bSQuentin Monnet  * 		() interface. Please refer to the description of
937c6b5fb86SQuentin Monnet  * 		**bpf_perf_event_read_value**\ () for details.
938c6b5fb86SQuentin Monnet  * 	Return
939c6b5fb86SQuentin Monnet  * 		The value of the perf event counter read from the map, or a
940c6b5fb86SQuentin Monnet  * 		negative error code in case of failure.
941c6b5fb86SQuentin Monnet  *
942c456dec4SQuentin Monnet  * int bpf_redirect(u32 ifindex, u64 flags)
943c456dec4SQuentin Monnet  * 	Description
944c456dec4SQuentin Monnet  * 		Redirect the packet to another net device of index *ifindex*.
945c456dec4SQuentin Monnet  * 		This helper is somewhat similar to **bpf_clone_redirect**\
946c456dec4SQuentin Monnet  * 		(), except that the packet is not cloned, which provides
947c456dec4SQuentin Monnet  * 		increased performance.
948c456dec4SQuentin Monnet  *
949c456dec4SQuentin Monnet  * 		Except for XDP, both ingress and egress interfaces can be used
950c456dec4SQuentin Monnet  * 		for redirection. The **BPF_F_INGRESS** value in *flags* is used
951c456dec4SQuentin Monnet  * 		to make the distinction (ingress path is selected if the flag
952c456dec4SQuentin Monnet  * 		is present, egress path otherwise). Currently, XDP only
953c456dec4SQuentin Monnet  * 		supports redirection to the egress interface, and accepts no
954c456dec4SQuentin Monnet  * 		flag at all.
955c456dec4SQuentin Monnet  *
956c456dec4SQuentin Monnet  * 		The same effect can be attained with the more generic
957c456dec4SQuentin Monnet  * 		**bpf_redirect_map**\ (), which requires specific maps to be
958c456dec4SQuentin Monnet  * 		used but offers better performance.
959c456dec4SQuentin Monnet  * 	Return
960c456dec4SQuentin Monnet  * 		For XDP, the helper returns **XDP_REDIRECT** on success or
961c456dec4SQuentin Monnet  * 		**XDP_ABORTED** on error. For other program types, the values
962c456dec4SQuentin Monnet  * 		are **TC_ACT_REDIRECT** on success or **TC_ACT_SHOT** on
963c456dec4SQuentin Monnet  * 		error.
964c456dec4SQuentin Monnet  *
9651fdd08beSQuentin Monnet  * u32 bpf_get_route_realm(struct sk_buff *skb)
9661fdd08beSQuentin Monnet  * 	Description
9671fdd08beSQuentin Monnet  * 		Retrieve the realm or the route, that is to say the
9681fdd08beSQuentin Monnet  * 		**tclassid** field of the destination for the *skb*. The
9691fdd08beSQuentin Monnet  * 		indentifier retrieved is a user-provided tag, similar to the
9701fdd08beSQuentin Monnet  * 		one used with the net_cls cgroup (see description for
9711fdd08beSQuentin Monnet  * 		**bpf_get_cgroup_classid**\ () helper), but here this tag is
9721fdd08beSQuentin Monnet  * 		held by a route (a destination entry), not by a task.
9731fdd08beSQuentin Monnet  *
9741fdd08beSQuentin Monnet  * 		Retrieving this identifier works with the clsact TC egress hook
9751fdd08beSQuentin Monnet  * 		(see also **tc-bpf(8)**), or alternatively on conventional
9761fdd08beSQuentin Monnet  * 		classful egress qdiscs, but not on TC ingress path. In case of
9771fdd08beSQuentin Monnet  * 		clsact TC egress hook, this has the advantage that, internally,
9781fdd08beSQuentin Monnet  * 		the destination entry has not been dropped yet in the transmit
9791fdd08beSQuentin Monnet  * 		path. Therefore, the destination entry does not need to be
9801fdd08beSQuentin Monnet  * 		artificially held via **netif_keep_dst**\ () for a classful
9811fdd08beSQuentin Monnet  * 		qdisc until the *skb* is freed.
9821fdd08beSQuentin Monnet  *
9831fdd08beSQuentin Monnet  * 		This helper is available only if the kernel was compiled with
9841fdd08beSQuentin Monnet  * 		**CONFIG_IP_ROUTE_CLASSID** configuration option.
9851fdd08beSQuentin Monnet  * 	Return
9861fdd08beSQuentin Monnet  * 		The realm of the route for the packet associated to *skb*, or 0
9871fdd08beSQuentin Monnet  * 		if none was found.
9881fdd08beSQuentin Monnet  *
989c456dec4SQuentin Monnet  * int bpf_perf_event_output(struct pt_reg *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
990c456dec4SQuentin Monnet  * 	Description
991c456dec4SQuentin Monnet  * 		Write raw *data* blob into a special BPF perf event held by
992c456dec4SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
993c456dec4SQuentin Monnet  * 		event must have the following attributes: **PERF_SAMPLE_RAW**
994c456dec4SQuentin Monnet  * 		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
995c456dec4SQuentin Monnet  * 		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
996c456dec4SQuentin Monnet  *
997c456dec4SQuentin Monnet  * 		The *flags* are used to indicate the index in *map* for which
998c456dec4SQuentin Monnet  * 		the value must be put, masked with **BPF_F_INDEX_MASK**.
999c456dec4SQuentin Monnet  * 		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
1000c456dec4SQuentin Monnet  * 		to indicate that the index of the current CPU core should be
1001c456dec4SQuentin Monnet  * 		used.
1002c456dec4SQuentin Monnet  *
1003c456dec4SQuentin Monnet  * 		The value to write, of *size*, is passed through eBPF stack and
1004c456dec4SQuentin Monnet  * 		pointed by *data*.
1005c456dec4SQuentin Monnet  *
1006c456dec4SQuentin Monnet  * 		The context of the program *ctx* needs also be passed to the
1007c456dec4SQuentin Monnet  * 		helper.
1008c456dec4SQuentin Monnet  *
1009c456dec4SQuentin Monnet  * 		On user space, a program willing to read the values needs to
1010c456dec4SQuentin Monnet  * 		call **perf_event_open**\ () on the perf event (either for
1011c456dec4SQuentin Monnet  * 		one or for all CPUs) and to store the file descriptor into the
1012c456dec4SQuentin Monnet  * 		*map*. This must be done before the eBPF program can send data
1013c456dec4SQuentin Monnet  * 		into it. An example is available in file
1014c456dec4SQuentin Monnet  * 		*samples/bpf/trace_output_user.c* in the Linux kernel source
1015c456dec4SQuentin Monnet  * 		tree (the eBPF program counterpart is in
1016c456dec4SQuentin Monnet  * 		*samples/bpf/trace_output_kern.c*).
1017c456dec4SQuentin Monnet  *
1018c456dec4SQuentin Monnet  * 		**bpf_perf_event_output**\ () achieves better performance
1019c456dec4SQuentin Monnet  * 		than **bpf_trace_printk**\ () for sharing data with user
1020c456dec4SQuentin Monnet  * 		space, and is much better suitable for streaming data from eBPF
1021c456dec4SQuentin Monnet  * 		programs.
1022c456dec4SQuentin Monnet  *
1023c456dec4SQuentin Monnet  * 		Note that this helper is not restricted to tracing use cases
1024c456dec4SQuentin Monnet  * 		and can be used with programs attached to TC or XDP as well,
1025c456dec4SQuentin Monnet  * 		where it allows for passing data to user space listeners. Data
1026c456dec4SQuentin Monnet  * 		can be:
1027c456dec4SQuentin Monnet  *
1028c456dec4SQuentin Monnet  * 		* Only custom structs,
1029c456dec4SQuentin Monnet  * 		* Only the packet payload, or
1030c456dec4SQuentin Monnet  * 		* A combination of both.
1031c456dec4SQuentin Monnet  * 	Return
1032c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1033c456dec4SQuentin Monnet  *
10341fdd08beSQuentin Monnet  * int bpf_skb_load_bytes(const struct sk_buff *skb, u32 offset, void *to, u32 len)
10351fdd08beSQuentin Monnet  * 	Description
10361fdd08beSQuentin Monnet  * 		This helper was provided as an easy way to load data from a
10371fdd08beSQuentin Monnet  * 		packet. It can be used to load *len* bytes from *offset* from
10381fdd08beSQuentin Monnet  * 		the packet associated to *skb*, into the buffer pointed by
10391fdd08beSQuentin Monnet  * 		*to*.
10401fdd08beSQuentin Monnet  *
10411fdd08beSQuentin Monnet  * 		Since Linux 4.7, usage of this helper has mostly been replaced
10421fdd08beSQuentin Monnet  * 		by "direct packet access", enabling packet data to be
10431fdd08beSQuentin Monnet  * 		manipulated with *skb*\ **->data** and *skb*\ **->data_end**
10441fdd08beSQuentin Monnet  * 		pointing respectively to the first byte of packet data and to
10451fdd08beSQuentin Monnet  * 		the byte after the last byte of packet data. However, it
10461fdd08beSQuentin Monnet  * 		remains useful if one wishes to read large quantities of data
10471fdd08beSQuentin Monnet  * 		at once from a packet into the eBPF stack.
10481fdd08beSQuentin Monnet  * 	Return
10491fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
10501fdd08beSQuentin Monnet  *
1051c456dec4SQuentin Monnet  * int bpf_get_stackid(struct pt_reg *ctx, struct bpf_map *map, u64 flags)
1052c456dec4SQuentin Monnet  * 	Description
1053c456dec4SQuentin Monnet  * 		Walk a user or a kernel stack and return its id. To achieve
1054c456dec4SQuentin Monnet  * 		this, the helper needs *ctx*, which is a pointer to the context
1055c456dec4SQuentin Monnet  * 		on which the tracing program is executed, and a pointer to a
1056c456dec4SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_STACK_TRACE**.
1057c456dec4SQuentin Monnet  *
1058c456dec4SQuentin Monnet  * 		The last argument, *flags*, holds the number of stack frames to
1059c456dec4SQuentin Monnet  * 		skip (from 0 to 255), masked with
1060c456dec4SQuentin Monnet  * 		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
1061c456dec4SQuentin Monnet  * 		a combination of the following flags:
1062c456dec4SQuentin Monnet  *
1063c456dec4SQuentin Monnet  * 		**BPF_F_USER_STACK**
1064c456dec4SQuentin Monnet  * 			Collect a user space stack instead of a kernel stack.
1065c456dec4SQuentin Monnet  * 		**BPF_F_FAST_STACK_CMP**
1066c456dec4SQuentin Monnet  * 			Compare stacks by hash only.
1067c456dec4SQuentin Monnet  * 		**BPF_F_REUSE_STACKID**
1068c456dec4SQuentin Monnet  * 			If two different stacks hash into the same *stackid*,
1069c456dec4SQuentin Monnet  * 			discard the old one.
1070c456dec4SQuentin Monnet  *
1071c456dec4SQuentin Monnet  * 		The stack id retrieved is a 32 bit long integer handle which
1072c456dec4SQuentin Monnet  * 		can be further combined with other data (including other stack
1073c456dec4SQuentin Monnet  * 		ids) and used as a key into maps. This can be useful for
1074c456dec4SQuentin Monnet  * 		generating a variety of graphs (such as flame graphs or off-cpu
1075c456dec4SQuentin Monnet  * 		graphs).
1076c456dec4SQuentin Monnet  *
1077c456dec4SQuentin Monnet  * 		For walking a stack, this helper is an improvement over
1078c456dec4SQuentin Monnet  * 		**bpf_probe_read**\ (), which can be used with unrolled loops
1079c456dec4SQuentin Monnet  * 		but is not efficient and consumes a lot of eBPF instructions.
1080c456dec4SQuentin Monnet  * 		Instead, **bpf_get_stackid**\ () can collect up to
1081c456dec4SQuentin Monnet  * 		**PERF_MAX_STACK_DEPTH** both kernel and user frames. Note that
1082c456dec4SQuentin Monnet  * 		this limit can be controlled with the **sysctl** program, and
1083c456dec4SQuentin Monnet  * 		that it should be manually increased in order to profile long
1084c456dec4SQuentin Monnet  * 		user stacks (such as stacks for Java programs). To do so, use:
1085c456dec4SQuentin Monnet  *
1086c456dec4SQuentin Monnet  * 		::
1087c456dec4SQuentin Monnet  *
1088c456dec4SQuentin Monnet  * 			# sysctl kernel.perf_event_max_stack=<new value>
1089c456dec4SQuentin Monnet  * 	Return
1090c456dec4SQuentin Monnet  * 		The positive or null stack id on success, or a negative error
1091c456dec4SQuentin Monnet  * 		in case of failure.
1092c456dec4SQuentin Monnet  *
10931fdd08beSQuentin Monnet  * s64 bpf_csum_diff(__be32 *from, u32 from_size, __be32 *to, u32 to_size, __wsum seed)
10941fdd08beSQuentin Monnet  * 	Description
10951fdd08beSQuentin Monnet  * 		Compute a checksum difference, from the raw buffer pointed by
10961fdd08beSQuentin Monnet  * 		*from*, of length *from_size* (that must be a multiple of 4),
10971fdd08beSQuentin Monnet  * 		towards the raw buffer pointed by *to*, of size *to_size*
10981fdd08beSQuentin Monnet  * 		(same remark). An optional *seed* can be added to the value
10991fdd08beSQuentin Monnet  * 		(this can be cascaded, the seed may come from a previous call
11001fdd08beSQuentin Monnet  * 		to the helper).
11011fdd08beSQuentin Monnet  *
11021fdd08beSQuentin Monnet  * 		This is flexible enough to be used in several ways:
11031fdd08beSQuentin Monnet  *
11041fdd08beSQuentin Monnet  * 		* With *from_size* == 0, *to_size* > 0 and *seed* set to
11051fdd08beSQuentin Monnet  * 		  checksum, it can be used when pushing new data.
11061fdd08beSQuentin Monnet  * 		* With *from_size* > 0, *to_size* == 0 and *seed* set to
11071fdd08beSQuentin Monnet  * 		  checksum, it can be used when removing data from a packet.
11081fdd08beSQuentin Monnet  * 		* With *from_size* > 0, *to_size* > 0 and *seed* set to 0, it
11091fdd08beSQuentin Monnet  * 		  can be used to compute a diff. Note that *from_size* and
11101fdd08beSQuentin Monnet  * 		  *to_size* do not need to be equal.
11111fdd08beSQuentin Monnet  *
11121fdd08beSQuentin Monnet  * 		This helper can be used in combination with
11131fdd08beSQuentin Monnet  * 		**bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\ (), to
11141fdd08beSQuentin Monnet  * 		which one can feed in the difference computed with
11151fdd08beSQuentin Monnet  * 		**bpf_csum_diff**\ ().
11161fdd08beSQuentin Monnet  * 	Return
11171fdd08beSQuentin Monnet  * 		The checksum result, or a negative error code in case of
11181fdd08beSQuentin Monnet  * 		failure.
11191fdd08beSQuentin Monnet  *
11201fdd08beSQuentin Monnet  * int bpf_skb_get_tunnel_opt(struct sk_buff *skb, u8 *opt, u32 size)
11211fdd08beSQuentin Monnet  * 	Description
11221fdd08beSQuentin Monnet  * 		Retrieve tunnel options metadata for the packet associated to
11231fdd08beSQuentin Monnet  * 		*skb*, and store the raw tunnel option data to the buffer *opt*
11241fdd08beSQuentin Monnet  * 		of *size*.
11251fdd08beSQuentin Monnet  *
11261fdd08beSQuentin Monnet  * 		This helper can be used with encapsulation devices that can
11271fdd08beSQuentin Monnet  * 		operate in "collect metadata" mode (please refer to the related
11281fdd08beSQuentin Monnet  * 		note in the description of **bpf_skb_get_tunnel_key**\ () for
11291fdd08beSQuentin Monnet  * 		more details). A particular example where this can be used is
11301fdd08beSQuentin Monnet  * 		in combination with the Geneve encapsulation protocol, where it
11311fdd08beSQuentin Monnet  * 		allows for pushing (with **bpf_skb_get_tunnel_opt**\ () helper)
11321fdd08beSQuentin Monnet  * 		and retrieving arbitrary TLVs (Type-Length-Value headers) from
11331fdd08beSQuentin Monnet  * 		the eBPF program. This allows for full customization of these
11341fdd08beSQuentin Monnet  * 		headers.
11351fdd08beSQuentin Monnet  * 	Return
11361fdd08beSQuentin Monnet  * 		The size of the option data retrieved.
11371fdd08beSQuentin Monnet  *
11381fdd08beSQuentin Monnet  * int bpf_skb_set_tunnel_opt(struct sk_buff *skb, u8 *opt, u32 size)
11391fdd08beSQuentin Monnet  * 	Description
11401fdd08beSQuentin Monnet  * 		Set tunnel options metadata for the packet associated to *skb*
11411fdd08beSQuentin Monnet  * 		to the option data contained in the raw buffer *opt* of *size*.
11421fdd08beSQuentin Monnet  *
11431fdd08beSQuentin Monnet  * 		See also the description of the **bpf_skb_get_tunnel_opt**\ ()
11441fdd08beSQuentin Monnet  * 		helper for additional information.
11451fdd08beSQuentin Monnet  * 	Return
11461fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
11471fdd08beSQuentin Monnet  *
11481fdd08beSQuentin Monnet  * int bpf_skb_change_proto(struct sk_buff *skb, __be16 proto, u64 flags)
11491fdd08beSQuentin Monnet  * 	Description
11501fdd08beSQuentin Monnet  * 		Change the protocol of the *skb* to *proto*. Currently
11511fdd08beSQuentin Monnet  * 		supported are transition from IPv4 to IPv6, and from IPv6 to
11521fdd08beSQuentin Monnet  * 		IPv4. The helper takes care of the groundwork for the
11531fdd08beSQuentin Monnet  * 		transition, including resizing the socket buffer. The eBPF
11541fdd08beSQuentin Monnet  * 		program is expected to fill the new headers, if any, via
11551fdd08beSQuentin Monnet  * 		**skb_store_bytes**\ () and to recompute the checksums with
11561fdd08beSQuentin Monnet  * 		**bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\
11571fdd08beSQuentin Monnet  * 		(). The main case for this helper is to perform NAT64
11581fdd08beSQuentin Monnet  * 		operations out of an eBPF program.
11591fdd08beSQuentin Monnet  *
11601fdd08beSQuentin Monnet  * 		Internally, the GSO type is marked as dodgy so that headers are
11611fdd08beSQuentin Monnet  * 		checked and segments are recalculated by the GSO/GRO engine.
11621fdd08beSQuentin Monnet  * 		The size for GSO target is adapted as well.
11631fdd08beSQuentin Monnet  *
11641fdd08beSQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
11651fdd08beSQuentin Monnet  * 		be left at zero.
11661fdd08beSQuentin Monnet  *
11671fdd08beSQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
11681fdd08beSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
11691fdd08beSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
11701fdd08beSQuentin Monnet  * 		performed again, if the helper is used in combination with
11711fdd08beSQuentin Monnet  * 		direct packet access.
11721fdd08beSQuentin Monnet  * 	Return
11731fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
11741fdd08beSQuentin Monnet  *
11751fdd08beSQuentin Monnet  * int bpf_skb_change_type(struct sk_buff *skb, u32 type)
11761fdd08beSQuentin Monnet  * 	Description
11771fdd08beSQuentin Monnet  * 		Change the packet type for the packet associated to *skb*. This
11781fdd08beSQuentin Monnet  * 		comes down to setting *skb*\ **->pkt_type** to *type*, except
11791fdd08beSQuentin Monnet  * 		the eBPF program does not have a write access to *skb*\
11801fdd08beSQuentin Monnet  * 		**->pkt_type** beside this helper. Using a helper here allows
11811fdd08beSQuentin Monnet  * 		for graceful handling of errors.
11821fdd08beSQuentin Monnet  *
11831fdd08beSQuentin Monnet  * 		The major use case is to change incoming *skb*s to
11841fdd08beSQuentin Monnet  * 		**PACKET_HOST** in a programmatic way instead of having to
11851fdd08beSQuentin Monnet  * 		recirculate via **redirect**\ (..., **BPF_F_INGRESS**), for
11861fdd08beSQuentin Monnet  * 		example.
11871fdd08beSQuentin Monnet  *
11881fdd08beSQuentin Monnet  * 		Note that *type* only allows certain values. At this time, they
11891fdd08beSQuentin Monnet  * 		are:
11901fdd08beSQuentin Monnet  *
11911fdd08beSQuentin Monnet  * 		**PACKET_HOST**
11921fdd08beSQuentin Monnet  * 			Packet is for us.
11931fdd08beSQuentin Monnet  * 		**PACKET_BROADCAST**
11941fdd08beSQuentin Monnet  * 			Send packet to all.
11951fdd08beSQuentin Monnet  * 		**PACKET_MULTICAST**
11961fdd08beSQuentin Monnet  * 			Send packet to group.
11971fdd08beSQuentin Monnet  * 		**PACKET_OTHERHOST**
11981fdd08beSQuentin Monnet  * 			Send packet to someone else.
11991fdd08beSQuentin Monnet  * 	Return
12001fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
12011fdd08beSQuentin Monnet  *
1202c6b5fb86SQuentin Monnet  * int bpf_skb_under_cgroup(struct sk_buff *skb, struct bpf_map *map, u32 index)
1203c6b5fb86SQuentin Monnet  * 	Description
1204c6b5fb86SQuentin Monnet  * 		Check whether *skb* is a descendant of the cgroup2 held by
1205c6b5fb86SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
1206c6b5fb86SQuentin Monnet  * 	Return
1207c6b5fb86SQuentin Monnet  * 		The return value depends on the result of the test, and can be:
1208c6b5fb86SQuentin Monnet  *
1209c6b5fb86SQuentin Monnet  * 		* 0, if the *skb* failed the cgroup2 descendant test.
1210c6b5fb86SQuentin Monnet  * 		* 1, if the *skb* succeeded the cgroup2 descendant test.
1211c6b5fb86SQuentin Monnet  * 		* A negative error code, if an error occurred.
1212c6b5fb86SQuentin Monnet  *
1213fa15601aSQuentin Monnet  * u32 bpf_get_hash_recalc(struct sk_buff *skb)
1214fa15601aSQuentin Monnet  * 	Description
1215fa15601aSQuentin Monnet  * 		Retrieve the hash of the packet, *skb*\ **->hash**. If it is
1216fa15601aSQuentin Monnet  * 		not set, in particular if the hash was cleared due to mangling,
1217fa15601aSQuentin Monnet  * 		recompute this hash. Later accesses to the hash can be done
1218fa15601aSQuentin Monnet  * 		directly with *skb*\ **->hash**.
1219fa15601aSQuentin Monnet  *
1220fa15601aSQuentin Monnet  * 		Calling **bpf_set_hash_invalid**\ (), changing a packet
1221fa15601aSQuentin Monnet  * 		prototype with **bpf_skb_change_proto**\ (), or calling
1222fa15601aSQuentin Monnet  * 		**bpf_skb_store_bytes**\ () with the
1223fa15601aSQuentin Monnet  * 		**BPF_F_INVALIDATE_HASH** are actions susceptible to clear
1224fa15601aSQuentin Monnet  * 		the hash and to trigger a new computation for the next call to
1225fa15601aSQuentin Monnet  * 		**bpf_get_hash_recalc**\ ().
1226fa15601aSQuentin Monnet  * 	Return
1227fa15601aSQuentin Monnet  * 		The 32-bit hash.
1228fa15601aSQuentin Monnet  *
1229c456dec4SQuentin Monnet  * u64 bpf_get_current_task(void)
1230c456dec4SQuentin Monnet  * 	Return
1231c456dec4SQuentin Monnet  * 		A pointer to the current task struct.
1232fa15601aSQuentin Monnet  *
1233c6b5fb86SQuentin Monnet  * int bpf_probe_write_user(void *dst, const void *src, u32 len)
1234c6b5fb86SQuentin Monnet  * 	Description
1235c6b5fb86SQuentin Monnet  * 		Attempt in a safe way to write *len* bytes from the buffer
1236c6b5fb86SQuentin Monnet  * 		*src* to *dst* in memory. It only works for threads that are in
1237c6b5fb86SQuentin Monnet  * 		user context, and *dst* must be a valid user space address.
1238c6b5fb86SQuentin Monnet  *
1239c6b5fb86SQuentin Monnet  * 		This helper should not be used to implement any kind of
1240c6b5fb86SQuentin Monnet  * 		security mechanism because of TOC-TOU attacks, but rather to
1241c6b5fb86SQuentin Monnet  * 		debug, divert, and manipulate execution of semi-cooperative
1242c6b5fb86SQuentin Monnet  * 		processes.
1243c6b5fb86SQuentin Monnet  *
1244c6b5fb86SQuentin Monnet  * 		Keep in mind that this feature is meant for experiments, and it
1245c6b5fb86SQuentin Monnet  * 		has a risk of crashing the system and running programs.
1246c6b5fb86SQuentin Monnet  * 		Therefore, when an eBPF program using this helper is attached,
1247c6b5fb86SQuentin Monnet  * 		a warning including PID and process name is printed to kernel
1248c6b5fb86SQuentin Monnet  * 		logs.
1249c6b5fb86SQuentin Monnet  * 	Return
1250c6b5fb86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1251c6b5fb86SQuentin Monnet  *
1252c6b5fb86SQuentin Monnet  * int bpf_current_task_under_cgroup(struct bpf_map *map, u32 index)
1253c6b5fb86SQuentin Monnet  * 	Description
1254c6b5fb86SQuentin Monnet  * 		Check whether the probe is being run is the context of a given
1255c6b5fb86SQuentin Monnet  * 		subset of the cgroup2 hierarchy. The cgroup2 to test is held by
1256c6b5fb86SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
1257c6b5fb86SQuentin Monnet  * 	Return
1258c6b5fb86SQuentin Monnet  * 		The return value depends on the result of the test, and can be:
1259c6b5fb86SQuentin Monnet  *
1260c6b5fb86SQuentin Monnet  * 		* 0, if the *skb* task belongs to the cgroup2.
1261c6b5fb86SQuentin Monnet  * 		* 1, if the *skb* task does not belong to the cgroup2.
1262c6b5fb86SQuentin Monnet  * 		* A negative error code, if an error occurred.
1263c6b5fb86SQuentin Monnet  *
1264fa15601aSQuentin Monnet  * int bpf_skb_change_tail(struct sk_buff *skb, u32 len, u64 flags)
1265fa15601aSQuentin Monnet  * 	Description
1266fa15601aSQuentin Monnet  * 		Resize (trim or grow) the packet associated to *skb* to the
1267fa15601aSQuentin Monnet  * 		new *len*. The *flags* are reserved for future usage, and must
1268fa15601aSQuentin Monnet  * 		be left at zero.
1269fa15601aSQuentin Monnet  *
1270fa15601aSQuentin Monnet  * 		The basic idea is that the helper performs the needed work to
1271fa15601aSQuentin Monnet  * 		change the size of the packet, then the eBPF program rewrites
1272fa15601aSQuentin Monnet  * 		the rest via helpers like **bpf_skb_store_bytes**\ (),
1273fa15601aSQuentin Monnet  * 		**bpf_l3_csum_replace**\ (), **bpf_l3_csum_replace**\ ()
1274fa15601aSQuentin Monnet  * 		and others. This helper is a slow path utility intended for
1275fa15601aSQuentin Monnet  * 		replies with control messages. And because it is targeted for
1276fa15601aSQuentin Monnet  * 		slow path, the helper itself can afford to be slow: it
1277fa15601aSQuentin Monnet  * 		implicitly linearizes, unclones and drops offloads from the
1278fa15601aSQuentin Monnet  * 		*skb*.
1279fa15601aSQuentin Monnet  *
1280fa15601aSQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
1281fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1282fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1283fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
1284fa15601aSQuentin Monnet  * 		direct packet access.
1285fa15601aSQuentin Monnet  * 	Return
1286fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1287fa15601aSQuentin Monnet  *
1288fa15601aSQuentin Monnet  * int bpf_skb_pull_data(struct sk_buff *skb, u32 len)
1289fa15601aSQuentin Monnet  * 	Description
1290fa15601aSQuentin Monnet  * 		Pull in non-linear data in case the *skb* is non-linear and not
1291fa15601aSQuentin Monnet  * 		all of *len* are part of the linear section. Make *len* bytes
1292fa15601aSQuentin Monnet  * 		from *skb* readable and writable. If a zero value is passed for
1293fa15601aSQuentin Monnet  * 		*len*, then the whole length of the *skb* is pulled.
1294fa15601aSQuentin Monnet  *
1295fa15601aSQuentin Monnet  * 		This helper is only needed for reading and writing with direct
1296fa15601aSQuentin Monnet  * 		packet access.
1297fa15601aSQuentin Monnet  *
1298fa15601aSQuentin Monnet  * 		For direct packet access, testing that offsets to access
1299fa15601aSQuentin Monnet  * 		are within packet boundaries (test on *skb*\ **->data_end**) is
1300fa15601aSQuentin Monnet  * 		susceptible to fail if offsets are invalid, or if the requested
1301fa15601aSQuentin Monnet  * 		data is in non-linear parts of the *skb*. On failure the
1302fa15601aSQuentin Monnet  * 		program can just bail out, or in the case of a non-linear
1303fa15601aSQuentin Monnet  * 		buffer, use a helper to make the data available. The
1304fa15601aSQuentin Monnet  * 		**bpf_skb_load_bytes**\ () helper is a first solution to access
1305fa15601aSQuentin Monnet  * 		the data. Another one consists in using **bpf_skb_pull_data**
1306fa15601aSQuentin Monnet  * 		to pull in once the non-linear parts, then retesting and
1307fa15601aSQuentin Monnet  * 		eventually access the data.
1308fa15601aSQuentin Monnet  *
1309fa15601aSQuentin Monnet  * 		At the same time, this also makes sure the *skb* is uncloned,
1310fa15601aSQuentin Monnet  * 		which is a necessary condition for direct write. As this needs
1311fa15601aSQuentin Monnet  * 		to be an invariant for the write part only, the verifier
1312fa15601aSQuentin Monnet  * 		detects writes and adds a prologue that is calling
1313fa15601aSQuentin Monnet  * 		**bpf_skb_pull_data()** to effectively unclone the *skb* from
1314fa15601aSQuentin Monnet  * 		the very beginning in case it is indeed cloned.
1315fa15601aSQuentin Monnet  *
1316fa15601aSQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
1317fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1318fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1319fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
1320fa15601aSQuentin Monnet  * 		direct packet access.
1321fa15601aSQuentin Monnet  * 	Return
1322fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1323fa15601aSQuentin Monnet  *
1324fa15601aSQuentin Monnet  * s64 bpf_csum_update(struct sk_buff *skb, __wsum csum)
1325fa15601aSQuentin Monnet  * 	Description
1326fa15601aSQuentin Monnet  * 		Add the checksum *csum* into *skb*\ **->csum** in case the
1327fa15601aSQuentin Monnet  * 		driver has supplied a checksum for the entire packet into that
1328fa15601aSQuentin Monnet  * 		field. Return an error otherwise. This helper is intended to be
1329fa15601aSQuentin Monnet  * 		used in combination with **bpf_csum_diff**\ (), in particular
1330fa15601aSQuentin Monnet  * 		when the checksum needs to be updated after data has been
1331fa15601aSQuentin Monnet  * 		written into the packet through direct packet access.
1332fa15601aSQuentin Monnet  * 	Return
1333fa15601aSQuentin Monnet  * 		The checksum on success, or a negative error code in case of
1334fa15601aSQuentin Monnet  * 		failure.
1335fa15601aSQuentin Monnet  *
1336fa15601aSQuentin Monnet  * void bpf_set_hash_invalid(struct sk_buff *skb)
1337fa15601aSQuentin Monnet  * 	Description
1338fa15601aSQuentin Monnet  * 		Invalidate the current *skb*\ **->hash**. It can be used after
1339fa15601aSQuentin Monnet  * 		mangling on headers through direct packet access, in order to
1340fa15601aSQuentin Monnet  * 		indicate that the hash is outdated and to trigger a
1341fa15601aSQuentin Monnet  * 		recalculation the next time the kernel tries to access this
1342fa15601aSQuentin Monnet  * 		hash or when the **bpf_get_hash_recalc**\ () helper is called.
1343fa15601aSQuentin Monnet  *
1344fa15601aSQuentin Monnet  * int bpf_get_numa_node_id(void)
1345fa15601aSQuentin Monnet  * 	Description
1346fa15601aSQuentin Monnet  * 		Return the id of the current NUMA node. The primary use case
1347fa15601aSQuentin Monnet  * 		for this helper is the selection of sockets for the local NUMA
1348fa15601aSQuentin Monnet  * 		node, when the program is attached to sockets using the
1349fa15601aSQuentin Monnet  * 		**SO_ATTACH_REUSEPORT_EBPF** option (see also **socket(7)**),
1350fa15601aSQuentin Monnet  * 		but the helper is also available to other eBPF program types,
1351fa15601aSQuentin Monnet  * 		similarly to **bpf_get_smp_processor_id**\ ().
1352fa15601aSQuentin Monnet  * 	Return
1353fa15601aSQuentin Monnet  * 		The id of current NUMA node.
1354fa15601aSQuentin Monnet  *
1355c6b5fb86SQuentin Monnet  * int bpf_skb_change_head(struct sk_buff *skb, u32 len, u64 flags)
1356c6b5fb86SQuentin Monnet  * 	Description
1357c6b5fb86SQuentin Monnet  * 		Grows headroom of packet associated to *skb* and adjusts the
1358c6b5fb86SQuentin Monnet  * 		offset of the MAC header accordingly, adding *len* bytes of
1359c6b5fb86SQuentin Monnet  * 		space. It automatically extends and reallocates memory as
1360c6b5fb86SQuentin Monnet  * 		required.
1361c6b5fb86SQuentin Monnet  *
1362c6b5fb86SQuentin Monnet  * 		This helper can be used on a layer 3 *skb* to push a MAC header
1363c6b5fb86SQuentin Monnet  * 		for redirection into a layer 2 device.
1364c6b5fb86SQuentin Monnet  *
1365c6b5fb86SQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
1366c6b5fb86SQuentin Monnet  * 		be left at zero.
1367c6b5fb86SQuentin Monnet  *
1368c6b5fb86SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
1369c6b5fb86SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1370c6b5fb86SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1371c6b5fb86SQuentin Monnet  * 		performed again, if the helper is used in combination with
1372c6b5fb86SQuentin Monnet  * 		direct packet access.
1373c6b5fb86SQuentin Monnet  * 	Return
1374c6b5fb86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1375c6b5fb86SQuentin Monnet  *
1376c6b5fb86SQuentin Monnet  * int bpf_xdp_adjust_head(struct xdp_buff *xdp_md, int delta)
1377c6b5fb86SQuentin Monnet  * 	Description
1378c6b5fb86SQuentin Monnet  * 		Adjust (move) *xdp_md*\ **->data** by *delta* bytes. Note that
1379c6b5fb86SQuentin Monnet  * 		it is possible to use a negative value for *delta*. This helper
1380c6b5fb86SQuentin Monnet  * 		can be used to prepare the packet for pushing or popping
1381c6b5fb86SQuentin Monnet  * 		headers.
1382c6b5fb86SQuentin Monnet  *
1383c6b5fb86SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
1384c6b5fb86SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1385c6b5fb86SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1386c6b5fb86SQuentin Monnet  * 		performed again, if the helper is used in combination with
1387c6b5fb86SQuentin Monnet  * 		direct packet access.
1388c6b5fb86SQuentin Monnet  * 	Return
1389c6b5fb86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1390c6b5fb86SQuentin Monnet  *
1391c6b5fb86SQuentin Monnet  * int bpf_probe_read_str(void *dst, int size, const void *unsafe_ptr)
1392c6b5fb86SQuentin Monnet  * 	Description
1393c6b5fb86SQuentin Monnet  * 		Copy a NUL terminated string from an unsafe address
1394c6b5fb86SQuentin Monnet  * 		*unsafe_ptr* to *dst*. The *size* should include the
1395c6b5fb86SQuentin Monnet  * 		terminating NUL byte. In case the string length is smaller than
1396c6b5fb86SQuentin Monnet  * 		*size*, the target is not padded with further NUL bytes. If the
1397c6b5fb86SQuentin Monnet  * 		string length is larger than *size*, just *size*-1 bytes are
1398c6b5fb86SQuentin Monnet  * 		copied and the last byte is set to NUL.
1399c6b5fb86SQuentin Monnet  *
1400c6b5fb86SQuentin Monnet  * 		On success, the length of the copied string is returned. This
1401c6b5fb86SQuentin Monnet  * 		makes this helper useful in tracing programs for reading
1402c6b5fb86SQuentin Monnet  * 		strings, and more importantly to get its length at runtime. See
1403c6b5fb86SQuentin Monnet  * 		the following snippet:
1404c6b5fb86SQuentin Monnet  *
1405c6b5fb86SQuentin Monnet  * 		::
1406c6b5fb86SQuentin Monnet  *
1407c6b5fb86SQuentin Monnet  * 			SEC("kprobe/sys_open")
1408c6b5fb86SQuentin Monnet  * 			void bpf_sys_open(struct pt_regs *ctx)
1409c6b5fb86SQuentin Monnet  * 			{
1410c6b5fb86SQuentin Monnet  * 			        char buf[PATHLEN]; // PATHLEN is defined to 256
1411c6b5fb86SQuentin Monnet  * 			        int res = bpf_probe_read_str(buf, sizeof(buf),
1412c6b5fb86SQuentin Monnet  * 				                             ctx->di);
1413c6b5fb86SQuentin Monnet  *
1414c6b5fb86SQuentin Monnet  * 				// Consume buf, for example push it to
1415c6b5fb86SQuentin Monnet  * 				// userspace via bpf_perf_event_output(); we
1416c6b5fb86SQuentin Monnet  * 				// can use res (the string length) as event
1417c6b5fb86SQuentin Monnet  * 				// size, after checking its boundaries.
1418c6b5fb86SQuentin Monnet  * 			}
1419c6b5fb86SQuentin Monnet  *
1420c6b5fb86SQuentin Monnet  * 		In comparison, using **bpf_probe_read()** helper here instead
1421c6b5fb86SQuentin Monnet  * 		to read the string would require to estimate the length at
1422c6b5fb86SQuentin Monnet  * 		compile time, and would often result in copying more memory
1423c6b5fb86SQuentin Monnet  * 		than necessary.
1424c6b5fb86SQuentin Monnet  *
1425c6b5fb86SQuentin Monnet  * 		Another useful use case is when parsing individual process
1426c6b5fb86SQuentin Monnet  * 		arguments or individual environment variables navigating
1427c6b5fb86SQuentin Monnet  * 		*current*\ **->mm->arg_start** and *current*\
1428c6b5fb86SQuentin Monnet  * 		**->mm->env_start**: using this helper and the return value,
1429c6b5fb86SQuentin Monnet  * 		one can quickly iterate at the right offset of the memory area.
1430c6b5fb86SQuentin Monnet  * 	Return
1431c6b5fb86SQuentin Monnet  * 		On success, the strictly positive length of the string,
1432c6b5fb86SQuentin Monnet  * 		including the trailing NUL character. On error, a negative
1433c6b5fb86SQuentin Monnet  * 		value.
1434c6b5fb86SQuentin Monnet  *
1435c6b5fb86SQuentin Monnet  * u64 bpf_get_socket_cookie(struct sk_buff *skb)
1436c6b5fb86SQuentin Monnet  * 	Description
1437c6b5fb86SQuentin Monnet  * 		If the **struct sk_buff** pointed by *skb* has a known socket,
1438c6b5fb86SQuentin Monnet  * 		retrieve the cookie (generated by the kernel) of this socket.
1439c6b5fb86SQuentin Monnet  * 		If no cookie has been set yet, generate a new cookie. Once
1440c6b5fb86SQuentin Monnet  * 		generated, the socket cookie remains stable for the life of the
1441c6b5fb86SQuentin Monnet  * 		socket. This helper can be useful for monitoring per socket
1442c6b5fb86SQuentin Monnet  * 		networking traffic statistics as it provides a unique socket
1443c6b5fb86SQuentin Monnet  * 		identifier per namespace.
1444c6b5fb86SQuentin Monnet  * 	Return
1445c6b5fb86SQuentin Monnet  * 		A 8-byte long non-decreasing number on success, or 0 if the
1446c6b5fb86SQuentin Monnet  * 		socket field is missing inside *skb*.
1447c6b5fb86SQuentin Monnet  *
1448d692f113SAndrey Ignatov  * u64 bpf_get_socket_cookie(struct bpf_sock_addr *ctx)
1449d692f113SAndrey Ignatov  * 	Description
1450d692f113SAndrey Ignatov  * 		Equivalent to bpf_get_socket_cookie() helper that accepts
145162369db2SQuentin Monnet  * 		*skb*, but gets socket from **struct bpf_sock_addr** context.
1452d692f113SAndrey Ignatov  * 	Return
1453d692f113SAndrey Ignatov  * 		A 8-byte long non-decreasing number.
1454d692f113SAndrey Ignatov  *
1455d692f113SAndrey Ignatov  * u64 bpf_get_socket_cookie(struct bpf_sock_ops *ctx)
1456d692f113SAndrey Ignatov  * 	Description
1457d692f113SAndrey Ignatov  * 		Equivalent to bpf_get_socket_cookie() helper that accepts
145862369db2SQuentin Monnet  * 		*skb*, but gets socket from **struct bpf_sock_ops** context.
1459d692f113SAndrey Ignatov  * 	Return
1460d692f113SAndrey Ignatov  * 		A 8-byte long non-decreasing number.
1461d692f113SAndrey Ignatov  *
1462c6b5fb86SQuentin Monnet  * u32 bpf_get_socket_uid(struct sk_buff *skb)
1463c6b5fb86SQuentin Monnet  * 	Return
1464c6b5fb86SQuentin Monnet  * 		The owner UID of the socket associated to *skb*. If the socket
1465c6b5fb86SQuentin Monnet  * 		is **NULL**, or if it is not a full socket (i.e. if it is a
1466c6b5fb86SQuentin Monnet  * 		time-wait or a request socket instead), **overflowuid** value
1467c6b5fb86SQuentin Monnet  * 		is returned (note that **overflowuid** might also be the actual
1468c6b5fb86SQuentin Monnet  * 		UID value for the socket).
1469c6b5fb86SQuentin Monnet  *
1470fa15601aSQuentin Monnet  * u32 bpf_set_hash(struct sk_buff *skb, u32 hash)
1471fa15601aSQuentin Monnet  * 	Description
1472fa15601aSQuentin Monnet  * 		Set the full hash for *skb* (set the field *skb*\ **->hash**)
1473fa15601aSQuentin Monnet  * 		to value *hash*.
1474fa15601aSQuentin Monnet  * 	Return
1475fa15601aSQuentin Monnet  * 		0
1476fa15601aSQuentin Monnet  *
1477a3ef8e9aSAndrey Ignatov  * int bpf_setsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, char *optval, int optlen)
14787aa79a86SQuentin Monnet  * 	Description
14797aa79a86SQuentin Monnet  * 		Emulate a call to **setsockopt()** on the socket associated to
14807aa79a86SQuentin Monnet  * 		*bpf_socket*, which must be a full socket. The *level* at
14817aa79a86SQuentin Monnet  * 		which the option resides and the name *optname* of the option
14827aa79a86SQuentin Monnet  * 		must be specified, see **setsockopt(2)** for more information.
14837aa79a86SQuentin Monnet  * 		The option value of length *optlen* is pointed by *optval*.
14847aa79a86SQuentin Monnet  *
14857aa79a86SQuentin Monnet  * 		This helper actually implements a subset of **setsockopt()**.
14867aa79a86SQuentin Monnet  * 		It supports the following *level*\ s:
14877aa79a86SQuentin Monnet  *
14887aa79a86SQuentin Monnet  * 		* **SOL_SOCKET**, which supports the following *optname*\ s:
14897aa79a86SQuentin Monnet  * 		  **SO_RCVBUF**, **SO_SNDBUF**, **SO_MAX_PACING_RATE**,
14907aa79a86SQuentin Monnet  * 		  **SO_PRIORITY**, **SO_RCVLOWAT**, **SO_MARK**.
14917aa79a86SQuentin Monnet  * 		* **IPPROTO_TCP**, which supports the following *optname*\ s:
14927aa79a86SQuentin Monnet  * 		  **TCP_CONGESTION**, **TCP_BPF_IW**,
14937aa79a86SQuentin Monnet  * 		  **TCP_BPF_SNDCWND_CLAMP**.
14947aa79a86SQuentin Monnet  * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
14957aa79a86SQuentin Monnet  * 		* **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
14967aa79a86SQuentin Monnet  * 	Return
14977aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
14987aa79a86SQuentin Monnet  *
1499b55cbc8dSNicolas Dichtel  * int bpf_skb_adjust_room(struct sk_buff *skb, s32 len_diff, u32 mode, u64 flags)
1500fa15601aSQuentin Monnet  * 	Description
1501fa15601aSQuentin Monnet  * 		Grow or shrink the room for data in the packet associated to
1502fa15601aSQuentin Monnet  * 		*skb* by *len_diff*, and according to the selected *mode*.
1503fa15601aSQuentin Monnet  *
150414aa3192SWillem de Bruijn  *		There are two supported modes at this time:
150514aa3192SWillem de Bruijn  *
150614aa3192SWillem de Bruijn  *		* **BPF_ADJ_ROOM_MAC**: Adjust room at the mac layer
150714aa3192SWillem de Bruijn  *		  (room space is added or removed below the layer 2 header).
1508fa15601aSQuentin Monnet  *
1509fa15601aSQuentin Monnet  * 		* **BPF_ADJ_ROOM_NET**: Adjust room at the network layer
1510fa15601aSQuentin Monnet  * 		  (room space is added or removed below the layer 3 header).
1511fa15601aSQuentin Monnet  *
1512868d5235SWillem de Bruijn  *		The following flags are supported at this time:
15132278f6ccSWillem de Bruijn  *
15142278f6ccSWillem de Bruijn  *		* **BPF_F_ADJ_ROOM_FIXED_GSO**: Do not adjust gso_size.
15152278f6ccSWillem de Bruijn  *		  Adjusting mss in this way is not allowed for datagrams.
1516fa15601aSQuentin Monnet  *
1517868d5235SWillem de Bruijn  *		* **BPF_F_ADJ_ROOM_ENCAP_L3_IPV4 **:
1518868d5235SWillem de Bruijn  *		* **BPF_F_ADJ_ROOM_ENCAP_L3_IPV6 **:
1519868d5235SWillem de Bruijn  *		  Any new space is reserved to hold a tunnel header.
1520868d5235SWillem de Bruijn  *		  Configure skb offsets and other fields accordingly.
1521868d5235SWillem de Bruijn  *
1522868d5235SWillem de Bruijn  *		* **BPF_F_ADJ_ROOM_ENCAP_L4_GRE **:
1523868d5235SWillem de Bruijn  *		* **BPF_F_ADJ_ROOM_ENCAP_L4_UDP **:
1524868d5235SWillem de Bruijn  *		  Use with ENCAP_L3 flags to further specify the tunnel type.
1525868d5235SWillem de Bruijn  *
1526fa15601aSQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
1527fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1528fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1529fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
1530fa15601aSQuentin Monnet  * 		direct packet access.
1531fa15601aSQuentin Monnet  * 	Return
1532fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1533fa15601aSQuentin Monnet  *
1534ab127040SQuentin Monnet  * int bpf_redirect_map(struct bpf_map *map, u32 key, u64 flags)
1535ab127040SQuentin Monnet  * 	Description
1536ab127040SQuentin Monnet  * 		Redirect the packet to the endpoint referenced by *map* at
1537ab127040SQuentin Monnet  * 		index *key*. Depending on its type, this *map* can contain
1538ab127040SQuentin Monnet  * 		references to net devices (for forwarding packets through other
1539ab127040SQuentin Monnet  * 		ports), or to CPUs (for redirecting XDP frames to another CPU;
1540ab127040SQuentin Monnet  * 		but this is only implemented for native XDP (with driver
1541ab127040SQuentin Monnet  * 		support) as of this writing).
1542ab127040SQuentin Monnet  *
1543ab127040SQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
1544ab127040SQuentin Monnet  * 		be left at zero.
1545ab127040SQuentin Monnet  *
1546ab127040SQuentin Monnet  * 		When used to redirect packets to net devices, this helper
1547ab127040SQuentin Monnet  * 		provides a high performance increase over **bpf_redirect**\ ().
1548ab127040SQuentin Monnet  * 		This is due to various implementation details of the underlying
1549ab127040SQuentin Monnet  * 		mechanisms, one of which is the fact that **bpf_redirect_map**\
1550ab127040SQuentin Monnet  * 		() tries to send packet as a "bulk" to the device.
1551ab127040SQuentin Monnet  * 	Return
1552ab127040SQuentin Monnet  * 		**XDP_REDIRECT** on success, or **XDP_ABORTED** on error.
1553ab127040SQuentin Monnet  *
1554ab127040SQuentin Monnet  * int bpf_sk_redirect_map(struct bpf_map *map, u32 key, u64 flags)
1555ab127040SQuentin Monnet  * 	Description
1556ab127040SQuentin Monnet  * 		Redirect the packet to the socket referenced by *map* (of type
1557ab127040SQuentin Monnet  * 		**BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
1558ab127040SQuentin Monnet  * 		egress interfaces can be used for redirection. The
1559ab127040SQuentin Monnet  * 		**BPF_F_INGRESS** value in *flags* is used to make the
1560ab127040SQuentin Monnet  * 		distinction (ingress path is selected if the flag is present,
1561ab127040SQuentin Monnet  * 		egress path otherwise). This is the only flag supported for now.
1562ab127040SQuentin Monnet  * 	Return
1563ab127040SQuentin Monnet  * 		**SK_PASS** on success, or **SK_DROP** on error.
1564ab127040SQuentin Monnet  *
1565a3ef8e9aSAndrey Ignatov  * int bpf_sock_map_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
1566ab127040SQuentin Monnet  * 	Description
1567ab127040SQuentin Monnet  * 		Add an entry to, or update a *map* referencing sockets. The
1568ab127040SQuentin Monnet  * 		*skops* is used as a new value for the entry associated to
1569ab127040SQuentin Monnet  * 		*key*. *flags* is one of:
1570ab127040SQuentin Monnet  *
1571ab127040SQuentin Monnet  * 		**BPF_NOEXIST**
1572ab127040SQuentin Monnet  * 			The entry for *key* must not exist in the map.
1573ab127040SQuentin Monnet  * 		**BPF_EXIST**
1574ab127040SQuentin Monnet  * 			The entry for *key* must already exist in the map.
1575ab127040SQuentin Monnet  * 		**BPF_ANY**
1576ab127040SQuentin Monnet  * 			No condition on the existence of the entry for *key*.
1577ab127040SQuentin Monnet  *
1578ab127040SQuentin Monnet  * 		If the *map* has eBPF programs (parser and verdict), those will
1579ab127040SQuentin Monnet  * 		be inherited by the socket being added. If the socket is
1580ab127040SQuentin Monnet  * 		already attached to eBPF programs, this results in an error.
1581ab127040SQuentin Monnet  * 	Return
1582ab127040SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1583ab127040SQuentin Monnet  *
1584fa15601aSQuentin Monnet  * int bpf_xdp_adjust_meta(struct xdp_buff *xdp_md, int delta)
1585fa15601aSQuentin Monnet  * 	Description
1586fa15601aSQuentin Monnet  * 		Adjust the address pointed by *xdp_md*\ **->data_meta** by
1587fa15601aSQuentin Monnet  * 		*delta* (which can be positive or negative). Note that this
1588fa15601aSQuentin Monnet  * 		operation modifies the address stored in *xdp_md*\ **->data**,
1589fa15601aSQuentin Monnet  * 		so the latter must be loaded only after the helper has been
1590fa15601aSQuentin Monnet  * 		called.
1591fa15601aSQuentin Monnet  *
1592fa15601aSQuentin Monnet  * 		The use of *xdp_md*\ **->data_meta** is optional and programs
1593fa15601aSQuentin Monnet  * 		are not required to use it. The rationale is that when the
1594fa15601aSQuentin Monnet  * 		packet is processed with XDP (e.g. as DoS filter), it is
1595fa15601aSQuentin Monnet  * 		possible to push further meta data along with it before passing
1596fa15601aSQuentin Monnet  * 		to the stack, and to give the guarantee that an ingress eBPF
1597fa15601aSQuentin Monnet  * 		program attached as a TC classifier on the same device can pick
1598fa15601aSQuentin Monnet  * 		this up for further post-processing. Since TC works with socket
1599fa15601aSQuentin Monnet  * 		buffers, it remains possible to set from XDP the **mark** or
1600fa15601aSQuentin Monnet  * 		**priority** pointers, or other pointers for the socket buffer.
1601fa15601aSQuentin Monnet  * 		Having this scratch space generic and programmable allows for
1602fa15601aSQuentin Monnet  * 		more flexibility as the user is free to store whatever meta
1603fa15601aSQuentin Monnet  * 		data they need.
1604fa15601aSQuentin Monnet  *
1605fa15601aSQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
1606fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1607fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1608fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
1609fa15601aSQuentin Monnet  * 		direct packet access.
1610fa15601aSQuentin Monnet  * 	Return
1611fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
16127aa79a86SQuentin Monnet  *
16137aa79a86SQuentin Monnet  * int bpf_perf_event_read_value(struct bpf_map *map, u64 flags, struct bpf_perf_event_value *buf, u32 buf_size)
16147aa79a86SQuentin Monnet  * 	Description
16157aa79a86SQuentin Monnet  * 		Read the value of a perf event counter, and store it into *buf*
16167aa79a86SQuentin Monnet  * 		of size *buf_size*. This helper relies on a *map* of type
16177aa79a86SQuentin Monnet  * 		**BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of the perf event
16187aa79a86SQuentin Monnet  * 		counter is selected when *map* is updated with perf event file
16197aa79a86SQuentin Monnet  * 		descriptors. The *map* is an array whose size is the number of
16207aa79a86SQuentin Monnet  * 		available CPUs, and each cell contains a value relative to one
16217aa79a86SQuentin Monnet  * 		CPU. The value to retrieve is indicated by *flags*, that
16227aa79a86SQuentin Monnet  * 		contains the index of the CPU to look up, masked with
16237aa79a86SQuentin Monnet  * 		**BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
16247aa79a86SQuentin Monnet  * 		**BPF_F_CURRENT_CPU** to indicate that the value for the
16257aa79a86SQuentin Monnet  * 		current CPU should be retrieved.
16267aa79a86SQuentin Monnet  *
16277aa79a86SQuentin Monnet  * 		This helper behaves in a way close to
16287aa79a86SQuentin Monnet  * 		**bpf_perf_event_read**\ () helper, save that instead of
16297aa79a86SQuentin Monnet  * 		just returning the value observed, it fills the *buf*
16307aa79a86SQuentin Monnet  * 		structure. This allows for additional data to be retrieved: in
16317aa79a86SQuentin Monnet  * 		particular, the enabled and running times (in *buf*\
16327aa79a86SQuentin Monnet  * 		**->enabled** and *buf*\ **->running**, respectively) are
16337aa79a86SQuentin Monnet  * 		copied. In general, **bpf_perf_event_read_value**\ () is
16347aa79a86SQuentin Monnet  * 		recommended over **bpf_perf_event_read**\ (), which has some
16357aa79a86SQuentin Monnet  * 		ABI issues and provides fewer functionalities.
16367aa79a86SQuentin Monnet  *
16377aa79a86SQuentin Monnet  * 		These values are interesting, because hardware PMU (Performance
16387aa79a86SQuentin Monnet  * 		Monitoring Unit) counters are limited resources. When there are
16397aa79a86SQuentin Monnet  * 		more PMU based perf events opened than available counters,
16407aa79a86SQuentin Monnet  * 		kernel will multiplex these events so each event gets certain
16417aa79a86SQuentin Monnet  * 		percentage (but not all) of the PMU time. In case that
16427aa79a86SQuentin Monnet  * 		multiplexing happens, the number of samples or counter value
16437aa79a86SQuentin Monnet  * 		will not reflect the case compared to when no multiplexing
16447aa79a86SQuentin Monnet  * 		occurs. This makes comparison between different runs difficult.
16457aa79a86SQuentin Monnet  * 		Typically, the counter value should be normalized before
16467aa79a86SQuentin Monnet  * 		comparing to other experiments. The usual normalization is done
16477aa79a86SQuentin Monnet  * 		as follows.
16487aa79a86SQuentin Monnet  *
16497aa79a86SQuentin Monnet  * 		::
16507aa79a86SQuentin Monnet  *
16517aa79a86SQuentin Monnet  * 			normalized_counter = counter * t_enabled / t_running
16527aa79a86SQuentin Monnet  *
16537aa79a86SQuentin Monnet  * 		Where t_enabled is the time enabled for event and t_running is
16547aa79a86SQuentin Monnet  * 		the time running for event since last normalization. The
16557aa79a86SQuentin Monnet  * 		enabled and running times are accumulated since the perf event
16567aa79a86SQuentin Monnet  * 		open. To achieve scaling factor between two invocations of an
16577aa79a86SQuentin Monnet  * 		eBPF program, users can can use CPU id as the key (which is
16587aa79a86SQuentin Monnet  * 		typical for perf array usage model) to remember the previous
16597aa79a86SQuentin Monnet  * 		value and do the calculation inside the eBPF program.
16607aa79a86SQuentin Monnet  * 	Return
16617aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
16627aa79a86SQuentin Monnet  *
1663a3ef8e9aSAndrey Ignatov  * int bpf_perf_prog_read_value(struct bpf_perf_event_data *ctx, struct bpf_perf_event_value *buf, u32 buf_size)
16647aa79a86SQuentin Monnet  * 	Description
16657aa79a86SQuentin Monnet  * 		For en eBPF program attached to a perf event, retrieve the
16667aa79a86SQuentin Monnet  * 		value of the event counter associated to *ctx* and store it in
16677aa79a86SQuentin Monnet  * 		the structure pointed by *buf* and of size *buf_size*. Enabled
16687aa79a86SQuentin Monnet  * 		and running times are also stored in the structure (see
16697aa79a86SQuentin Monnet  * 		description of helper **bpf_perf_event_read_value**\ () for
16707aa79a86SQuentin Monnet  * 		more details).
16717aa79a86SQuentin Monnet  * 	Return
16727aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
16737aa79a86SQuentin Monnet  *
1674a3ef8e9aSAndrey Ignatov  * int bpf_getsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, char *optval, int optlen)
16757aa79a86SQuentin Monnet  * 	Description
16767aa79a86SQuentin Monnet  * 		Emulate a call to **getsockopt()** on the socket associated to
16777aa79a86SQuentin Monnet  * 		*bpf_socket*, which must be a full socket. The *level* at
16787aa79a86SQuentin Monnet  * 		which the option resides and the name *optname* of the option
16797aa79a86SQuentin Monnet  * 		must be specified, see **getsockopt(2)** for more information.
16807aa79a86SQuentin Monnet  * 		The retrieved value is stored in the structure pointed by
16817aa79a86SQuentin Monnet  * 		*opval* and of length *optlen*.
16827aa79a86SQuentin Monnet  *
16837aa79a86SQuentin Monnet  * 		This helper actually implements a subset of **getsockopt()**.
16847aa79a86SQuentin Monnet  * 		It supports the following *level*\ s:
16857aa79a86SQuentin Monnet  *
16867aa79a86SQuentin Monnet  * 		* **IPPROTO_TCP**, which supports *optname*
16877aa79a86SQuentin Monnet  * 		  **TCP_CONGESTION**.
16887aa79a86SQuentin Monnet  * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
16897aa79a86SQuentin Monnet  * 		* **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
16907aa79a86SQuentin Monnet  * 	Return
16917aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
16927aa79a86SQuentin Monnet  *
16937aa79a86SQuentin Monnet  * int bpf_override_return(struct pt_reg *regs, u64 rc)
16947aa79a86SQuentin Monnet  * 	Description
16957aa79a86SQuentin Monnet  * 		Used for error injection, this helper uses kprobes to override
16967aa79a86SQuentin Monnet  * 		the return value of the probed function, and to set it to *rc*.
16977aa79a86SQuentin Monnet  * 		The first argument is the context *regs* on which the kprobe
16987aa79a86SQuentin Monnet  * 		works.
16997aa79a86SQuentin Monnet  *
17007aa79a86SQuentin Monnet  * 		This helper works by setting setting the PC (program counter)
17017aa79a86SQuentin Monnet  * 		to an override function which is run in place of the original
17027aa79a86SQuentin Monnet  * 		probed function. This means the probed function is not run at
17037aa79a86SQuentin Monnet  * 		all. The replacement function just returns with the required
17047aa79a86SQuentin Monnet  * 		value.
17057aa79a86SQuentin Monnet  *
17067aa79a86SQuentin Monnet  * 		This helper has security implications, and thus is subject to
17077aa79a86SQuentin Monnet  * 		restrictions. It is only available if the kernel was compiled
17087aa79a86SQuentin Monnet  * 		with the **CONFIG_BPF_KPROBE_OVERRIDE** configuration
17097aa79a86SQuentin Monnet  * 		option, and in this case it only works on functions tagged with
17107aa79a86SQuentin Monnet  * 		**ALLOW_ERROR_INJECTION** in the kernel code.
17117aa79a86SQuentin Monnet  *
17127aa79a86SQuentin Monnet  * 		Also, the helper is only available for the architectures having
17137aa79a86SQuentin Monnet  * 		the CONFIG_FUNCTION_ERROR_INJECTION option. As of this writing,
17147aa79a86SQuentin Monnet  * 		x86 architecture is the only one to support this feature.
17157aa79a86SQuentin Monnet  * 	Return
17167aa79a86SQuentin Monnet  * 		0
17177aa79a86SQuentin Monnet  *
1718a3ef8e9aSAndrey Ignatov  * int bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *bpf_sock, int argval)
17197aa79a86SQuentin Monnet  * 	Description
17207aa79a86SQuentin Monnet  * 		Attempt to set the value of the **bpf_sock_ops_cb_flags** field
17217aa79a86SQuentin Monnet  * 		for the full TCP socket associated to *bpf_sock_ops* to
17227aa79a86SQuentin Monnet  * 		*argval*.
17237aa79a86SQuentin Monnet  *
17247aa79a86SQuentin Monnet  * 		The primary use of this field is to determine if there should
17257aa79a86SQuentin Monnet  * 		be calls to eBPF programs of type
17267aa79a86SQuentin Monnet  * 		**BPF_PROG_TYPE_SOCK_OPS** at various points in the TCP
17277aa79a86SQuentin Monnet  * 		code. A program of the same type can change its value, per
17287aa79a86SQuentin Monnet  * 		connection and as necessary, when the connection is
17297aa79a86SQuentin Monnet  * 		established. This field is directly accessible for reading, but
17307aa79a86SQuentin Monnet  * 		this helper must be used for updates in order to return an
17317aa79a86SQuentin Monnet  * 		error if an eBPF program tries to set a callback that is not
17327aa79a86SQuentin Monnet  * 		supported in the current kernel.
17337aa79a86SQuentin Monnet  *
17347aa79a86SQuentin Monnet  * 		The supported callback values that *argval* can combine are:
17357aa79a86SQuentin Monnet  *
17367aa79a86SQuentin Monnet  * 		* **BPF_SOCK_OPS_RTO_CB_FLAG** (retransmission time out)
17377aa79a86SQuentin Monnet  * 		* **BPF_SOCK_OPS_RETRANS_CB_FLAG** (retransmission)
17387aa79a86SQuentin Monnet  * 		* **BPF_SOCK_OPS_STATE_CB_FLAG** (TCP state change)
17397aa79a86SQuentin Monnet  *
17407aa79a86SQuentin Monnet  * 		Here are some examples of where one could call such eBPF
17417aa79a86SQuentin Monnet  * 		program:
17427aa79a86SQuentin Monnet  *
17437aa79a86SQuentin Monnet  * 		* When RTO fires.
17447aa79a86SQuentin Monnet  * 		* When a packet is retransmitted.
17457aa79a86SQuentin Monnet  * 		* When the connection terminates.
17467aa79a86SQuentin Monnet  * 		* When a packet is sent.
17477aa79a86SQuentin Monnet  * 		* When a packet is received.
17487aa79a86SQuentin Monnet  * 	Return
17497aa79a86SQuentin Monnet  * 		Code **-EINVAL** if the socket is not a full TCP socket;
17507aa79a86SQuentin Monnet  * 		otherwise, a positive number containing the bits that could not
17517aa79a86SQuentin Monnet  * 		be set is returned (which comes down to 0 if all bits were set
17527aa79a86SQuentin Monnet  * 		as required).
17537aa79a86SQuentin Monnet  *
1754ab127040SQuentin Monnet  * int bpf_msg_redirect_map(struct sk_msg_buff *msg, struct bpf_map *map, u32 key, u64 flags)
1755ab127040SQuentin Monnet  * 	Description
1756ab127040SQuentin Monnet  * 		This helper is used in programs implementing policies at the
1757ab127040SQuentin Monnet  * 		socket level. If the message *msg* is allowed to pass (i.e. if
1758ab127040SQuentin Monnet  * 		the verdict eBPF program returns **SK_PASS**), redirect it to
1759ab127040SQuentin Monnet  * 		the socket referenced by *map* (of type
1760ab127040SQuentin Monnet  * 		**BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
1761ab127040SQuentin Monnet  * 		egress interfaces can be used for redirection. The
1762ab127040SQuentin Monnet  * 		**BPF_F_INGRESS** value in *flags* is used to make the
1763ab127040SQuentin Monnet  * 		distinction (ingress path is selected if the flag is present,
1764ab127040SQuentin Monnet  * 		egress path otherwise). This is the only flag supported for now.
1765ab127040SQuentin Monnet  * 	Return
1766ab127040SQuentin Monnet  * 		**SK_PASS** on success, or **SK_DROP** on error.
1767ab127040SQuentin Monnet  *
1768ab127040SQuentin Monnet  * int bpf_msg_apply_bytes(struct sk_msg_buff *msg, u32 bytes)
1769ab127040SQuentin Monnet  * 	Description
1770ab127040SQuentin Monnet  * 		For socket policies, apply the verdict of the eBPF program to
1771ab127040SQuentin Monnet  * 		the next *bytes* (number of bytes) of message *msg*.
1772ab127040SQuentin Monnet  *
1773ab127040SQuentin Monnet  * 		For example, this helper can be used in the following cases:
1774ab127040SQuentin Monnet  *
1775ab127040SQuentin Monnet  * 		* A single **sendmsg**\ () or **sendfile**\ () system call
1776ab127040SQuentin Monnet  * 		  contains multiple logical messages that the eBPF program is
1777ab127040SQuentin Monnet  * 		  supposed to read and for which it should apply a verdict.
1778ab127040SQuentin Monnet  * 		* An eBPF program only cares to read the first *bytes* of a
1779ab127040SQuentin Monnet  * 		  *msg*. If the message has a large payload, then setting up
1780ab127040SQuentin Monnet  * 		  and calling the eBPF program repeatedly for all bytes, even
1781ab127040SQuentin Monnet  * 		  though the verdict is already known, would create unnecessary
1782ab127040SQuentin Monnet  * 		  overhead.
1783ab127040SQuentin Monnet  *
1784ab127040SQuentin Monnet  * 		When called from within an eBPF program, the helper sets a
1785ab127040SQuentin Monnet  * 		counter internal to the BPF infrastructure, that is used to
1786ab127040SQuentin Monnet  * 		apply the last verdict to the next *bytes*. If *bytes* is
1787ab127040SQuentin Monnet  * 		smaller than the current data being processed from a
1788ab127040SQuentin Monnet  * 		**sendmsg**\ () or **sendfile**\ () system call, the first
1789ab127040SQuentin Monnet  * 		*bytes* will be sent and the eBPF program will be re-run with
1790ab127040SQuentin Monnet  * 		the pointer for start of data pointing to byte number *bytes*
1791ab127040SQuentin Monnet  * 		**+ 1**. If *bytes* is larger than the current data being
1792ab127040SQuentin Monnet  * 		processed, then the eBPF verdict will be applied to multiple
1793ab127040SQuentin Monnet  * 		**sendmsg**\ () or **sendfile**\ () calls until *bytes* are
1794ab127040SQuentin Monnet  * 		consumed.
1795ab127040SQuentin Monnet  *
1796ab127040SQuentin Monnet  * 		Note that if a socket closes with the internal counter holding
1797ab127040SQuentin Monnet  * 		a non-zero value, this is not a problem because data is not
1798ab127040SQuentin Monnet  * 		being buffered for *bytes* and is sent as it is received.
1799ab127040SQuentin Monnet  * 	Return
1800ab127040SQuentin Monnet  * 		0
1801ab127040SQuentin Monnet  *
1802ab127040SQuentin Monnet  * int bpf_msg_cork_bytes(struct sk_msg_buff *msg, u32 bytes)
1803ab127040SQuentin Monnet  * 	Description
1804ab127040SQuentin Monnet  * 		For socket policies, prevent the execution of the verdict eBPF
1805ab127040SQuentin Monnet  * 		program for message *msg* until *bytes* (byte number) have been
1806ab127040SQuentin Monnet  * 		accumulated.
1807ab127040SQuentin Monnet  *
1808ab127040SQuentin Monnet  * 		This can be used when one needs a specific number of bytes
1809ab127040SQuentin Monnet  * 		before a verdict can be assigned, even if the data spans
1810ab127040SQuentin Monnet  * 		multiple **sendmsg**\ () or **sendfile**\ () calls. The extreme
1811ab127040SQuentin Monnet  * 		case would be a user calling **sendmsg**\ () repeatedly with
1812ab127040SQuentin Monnet  * 		1-byte long message segments. Obviously, this is bad for
1813ab127040SQuentin Monnet  * 		performance, but it is still valid. If the eBPF program needs
1814ab127040SQuentin Monnet  * 		*bytes* bytes to validate a header, this helper can be used to
1815ab127040SQuentin Monnet  * 		prevent the eBPF program to be called again until *bytes* have
1816ab127040SQuentin Monnet  * 		been accumulated.
1817ab127040SQuentin Monnet  * 	Return
1818ab127040SQuentin Monnet  * 		0
1819ab127040SQuentin Monnet  *
1820ab127040SQuentin Monnet  * int bpf_msg_pull_data(struct sk_msg_buff *msg, u32 start, u32 end, u64 flags)
1821ab127040SQuentin Monnet  * 	Description
1822ab127040SQuentin Monnet  * 		For socket policies, pull in non-linear data from user space
1823ab127040SQuentin Monnet  * 		for *msg* and set pointers *msg*\ **->data** and *msg*\
1824ab127040SQuentin Monnet  * 		**->data_end** to *start* and *end* bytes offsets into *msg*,
1825ab127040SQuentin Monnet  * 		respectively.
1826ab127040SQuentin Monnet  *
1827ab127040SQuentin Monnet  * 		If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
1828ab127040SQuentin Monnet  * 		*msg* it can only parse data that the (**data**, **data_end**)
1829ab127040SQuentin Monnet  * 		pointers have already consumed. For **sendmsg**\ () hooks this
1830ab127040SQuentin Monnet  * 		is likely the first scatterlist element. But for calls relying
1831ab127040SQuentin Monnet  * 		on the **sendpage** handler (e.g. **sendfile**\ ()) this will
1832ab127040SQuentin Monnet  * 		be the range (**0**, **0**) because the data is shared with
1833ab127040SQuentin Monnet  * 		user space and by default the objective is to avoid allowing
1834ab127040SQuentin Monnet  * 		user space to modify data while (or after) eBPF verdict is
1835ab127040SQuentin Monnet  * 		being decided. This helper can be used to pull in data and to
1836ab127040SQuentin Monnet  * 		set the start and end pointer to given values. Data will be
1837ab127040SQuentin Monnet  * 		copied if necessary (i.e. if data was not linear and if start
1838ab127040SQuentin Monnet  * 		and end pointers do not point to the same chunk).
1839ab127040SQuentin Monnet  *
1840ab127040SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
1841ab127040SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1842ab127040SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1843ab127040SQuentin Monnet  * 		performed again, if the helper is used in combination with
1844ab127040SQuentin Monnet  * 		direct packet access.
1845ab127040SQuentin Monnet  *
1846ab127040SQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
1847ab127040SQuentin Monnet  * 		be left at zero.
1848ab127040SQuentin Monnet  * 	Return
1849ab127040SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1850ab127040SQuentin Monnet  *
1851a3ef8e9aSAndrey Ignatov  * int bpf_bind(struct bpf_sock_addr *ctx, struct sockaddr *addr, int addr_len)
18527aa79a86SQuentin Monnet  * 	Description
18537aa79a86SQuentin Monnet  * 		Bind the socket associated to *ctx* to the address pointed by
18547aa79a86SQuentin Monnet  * 		*addr*, of length *addr_len*. This allows for making outgoing
18557aa79a86SQuentin Monnet  * 		connection from the desired IP address, which can be useful for
18567aa79a86SQuentin Monnet  * 		example when all processes inside a cgroup should use one
18577aa79a86SQuentin Monnet  * 		single IP address on a host that has multiple IP configured.
18587aa79a86SQuentin Monnet  *
18597aa79a86SQuentin Monnet  * 		This helper works for IPv4 and IPv6, TCP and UDP sockets. The
18607aa79a86SQuentin Monnet  * 		domain (*addr*\ **->sa_family**) must be **AF_INET** (or
18617aa79a86SQuentin Monnet  * 		**AF_INET6**). Looking for a free port to bind to can be
18627aa79a86SQuentin Monnet  * 		expensive, therefore binding to port is not permitted by the
18637aa79a86SQuentin Monnet  * 		helper: *addr*\ **->sin_port** (or **sin6_port**, respectively)
18647aa79a86SQuentin Monnet  * 		must be set to zero.
18657aa79a86SQuentin Monnet  * 	Return
18667aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
18672d020dd7SQuentin Monnet  *
18682d020dd7SQuentin Monnet  * int bpf_xdp_adjust_tail(struct xdp_buff *xdp_md, int delta)
18692d020dd7SQuentin Monnet  * 	Description
18702d020dd7SQuentin Monnet  * 		Adjust (move) *xdp_md*\ **->data_end** by *delta* bytes. It is
18712d020dd7SQuentin Monnet  * 		only possible to shrink the packet as of this writing,
18722d020dd7SQuentin Monnet  * 		therefore *delta* must be a negative integer.
18732d020dd7SQuentin Monnet  *
18742d020dd7SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
18752d020dd7SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
18762d020dd7SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
18772d020dd7SQuentin Monnet  * 		performed again, if the helper is used in combination with
18782d020dd7SQuentin Monnet  * 		direct packet access.
18792d020dd7SQuentin Monnet  * 	Return
18802d020dd7SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
18812d020dd7SQuentin Monnet  *
18822d020dd7SQuentin Monnet  * int bpf_skb_get_xfrm_state(struct sk_buff *skb, u32 index, struct bpf_xfrm_state *xfrm_state, u32 size, u64 flags)
18832d020dd7SQuentin Monnet  * 	Description
18842d020dd7SQuentin Monnet  * 		Retrieve the XFRM state (IP transform framework, see also
18852d020dd7SQuentin Monnet  * 		**ip-xfrm(8)**) at *index* in XFRM "security path" for *skb*.
18862d020dd7SQuentin Monnet  *
18872d020dd7SQuentin Monnet  * 		The retrieved value is stored in the **struct bpf_xfrm_state**
18882d020dd7SQuentin Monnet  * 		pointed by *xfrm_state* and of length *size*.
18892d020dd7SQuentin Monnet  *
18902d020dd7SQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
18912d020dd7SQuentin Monnet  * 		be left at zero.
18922d020dd7SQuentin Monnet  *
18932d020dd7SQuentin Monnet  * 		This helper is available only if the kernel was compiled with
18942d020dd7SQuentin Monnet  * 		**CONFIG_XFRM** configuration option.
18952d020dd7SQuentin Monnet  * 	Return
18962d020dd7SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1897c195651eSYonghong Song  *
1898c195651eSYonghong Song  * int bpf_get_stack(struct pt_regs *regs, void *buf, u32 size, u64 flags)
1899c195651eSYonghong Song  * 	Description
1900c195651eSYonghong Song  * 		Return a user or a kernel stack in bpf program provided buffer.
1901c195651eSYonghong Song  * 		To achieve this, the helper needs *ctx*, which is a pointer
1902c195651eSYonghong Song  * 		to the context on which the tracing program is executed.
1903c195651eSYonghong Song  * 		To store the stacktrace, the bpf program provides *buf* with
1904c195651eSYonghong Song  * 		a nonnegative *size*.
1905c195651eSYonghong Song  *
1906c195651eSYonghong Song  * 		The last argument, *flags*, holds the number of stack frames to
1907c195651eSYonghong Song  * 		skip (from 0 to 255), masked with
1908c195651eSYonghong Song  * 		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
1909c195651eSYonghong Song  * 		the following flags:
1910c195651eSYonghong Song  *
1911c195651eSYonghong Song  * 		**BPF_F_USER_STACK**
1912c195651eSYonghong Song  * 			Collect a user space stack instead of a kernel stack.
1913c195651eSYonghong Song  * 		**BPF_F_USER_BUILD_ID**
1914c195651eSYonghong Song  * 			Collect buildid+offset instead of ips for user stack,
1915c195651eSYonghong Song  * 			only valid if **BPF_F_USER_STACK** is also specified.
1916c195651eSYonghong Song  *
1917c195651eSYonghong Song  * 		**bpf_get_stack**\ () can collect up to
1918c195651eSYonghong Song  * 		**PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
1919c195651eSYonghong Song  * 		to sufficient large buffer size. Note that
1920c195651eSYonghong Song  * 		this limit can be controlled with the **sysctl** program, and
1921c195651eSYonghong Song  * 		that it should be manually increased in order to profile long
1922c195651eSYonghong Song  * 		user stacks (such as stacks for Java programs). To do so, use:
1923c195651eSYonghong Song  *
1924c195651eSYonghong Song  * 		::
1925c195651eSYonghong Song  *
1926c195651eSYonghong Song  * 			# sysctl kernel.perf_event_max_stack=<new value>
1927c195651eSYonghong Song  * 	Return
19287a279e93SQuentin Monnet  * 		A non-negative value equal to or less than *size* on success,
19297a279e93SQuentin Monnet  * 		or a negative error in case of failure.
19304e1ec56cSDaniel Borkmann  *
19312bae79d2SQuentin Monnet  * int bpf_skb_load_bytes_relative(const struct sk_buff *skb, u32 offset, void *to, u32 len, u32 start_header)
19324e1ec56cSDaniel Borkmann  * 	Description
19334e1ec56cSDaniel Borkmann  * 		This helper is similar to **bpf_skb_load_bytes**\ () in that
19344e1ec56cSDaniel Borkmann  * 		it provides an easy way to load *len* bytes from *offset*
19354e1ec56cSDaniel Borkmann  * 		from the packet associated to *skb*, into the buffer pointed
19364e1ec56cSDaniel Borkmann  * 		by *to*. The difference to **bpf_skb_load_bytes**\ () is that
19374e1ec56cSDaniel Borkmann  * 		a fifth argument *start_header* exists in order to select a
19384e1ec56cSDaniel Borkmann  * 		base offset to start from. *start_header* can be one of:
19394e1ec56cSDaniel Borkmann  *
19404e1ec56cSDaniel Borkmann  * 		**BPF_HDR_START_MAC**
19414e1ec56cSDaniel Borkmann  * 			Base offset to load data from is *skb*'s mac header.
19424e1ec56cSDaniel Borkmann  * 		**BPF_HDR_START_NET**
19434e1ec56cSDaniel Borkmann  * 			Base offset to load data from is *skb*'s network header.
19444e1ec56cSDaniel Borkmann  *
19454e1ec56cSDaniel Borkmann  * 		In general, "direct packet access" is the preferred method to
19464e1ec56cSDaniel Borkmann  * 		access packet data, however, this helper is in particular useful
19474e1ec56cSDaniel Borkmann  * 		in socket filters where *skb*\ **->data** does not always point
19484e1ec56cSDaniel Borkmann  * 		to the start of the mac header and where "direct packet access"
19494e1ec56cSDaniel Borkmann  * 		is not available.
19504e1ec56cSDaniel Borkmann  * 	Return
19514e1ec56cSDaniel Borkmann  * 		0 on success, or a negative error in case of failure.
19524e1ec56cSDaniel Borkmann  *
195387f5fc7eSDavid Ahern  * int bpf_fib_lookup(void *ctx, struct bpf_fib_lookup *params, int plen, u32 flags)
195487f5fc7eSDavid Ahern  *	Description
195587f5fc7eSDavid Ahern  *		Do FIB lookup in kernel tables using parameters in *params*.
195687f5fc7eSDavid Ahern  *		If lookup is successful and result shows packet is to be
195787f5fc7eSDavid Ahern  *		forwarded, the neighbor tables are searched for the nexthop.
195887f5fc7eSDavid Ahern  *		If successful (ie., FIB lookup shows forwarding and nexthop
1959fa898d76SDavid Ahern  *		is resolved), the nexthop address is returned in ipv4_dst
1960fa898d76SDavid Ahern  *		or ipv6_dst based on family, smac is set to mac address of
1961fa898d76SDavid Ahern  *		egress device, dmac is set to nexthop mac address, rt_metric
19624c79579bSDavid Ahern  *		is set to metric from route (IPv4/IPv6 only), and ifindex
19634c79579bSDavid Ahern  *		is set to the device index of the nexthop from the FIB lookup.
196487f5fc7eSDavid Ahern  *
196587f5fc7eSDavid Ahern  *		*plen* argument is the size of the passed in struct.
19667a279e93SQuentin Monnet  *		*flags* argument can be a combination of one or more of the
19677a279e93SQuentin Monnet  *		following values:
196887f5fc7eSDavid Ahern  *
19697a279e93SQuentin Monnet  *		**BPF_FIB_LOOKUP_DIRECT**
19707a279e93SQuentin Monnet  *			Do a direct table lookup vs full lookup using FIB
19717a279e93SQuentin Monnet  *			rules.
19727a279e93SQuentin Monnet  *		**BPF_FIB_LOOKUP_OUTPUT**
19737a279e93SQuentin Monnet  *			Perform lookup from an egress perspective (default is
19747a279e93SQuentin Monnet  *			ingress).
197587f5fc7eSDavid Ahern  *
197687f5fc7eSDavid Ahern  *		*ctx* is either **struct xdp_md** for XDP programs or
197787f5fc7eSDavid Ahern  *		**struct sk_buff** tc cls_act programs.
197887f5fc7eSDavid Ahern  *	Return
19794c79579bSDavid Ahern  *		* < 0 if any input argument is invalid
19804c79579bSDavid Ahern  *		*   0 on success (packet is forwarded, nexthop neighbor exists)
19814c79579bSDavid Ahern  *		* > 0 one of **BPF_FIB_LKUP_RET_** codes explaining why the
19822bae79d2SQuentin Monnet  *		  packet is not forwarded or needs assist from full stack
198381110384SJohn Fastabend  *
198481110384SJohn Fastabend  * int bpf_sock_hash_update(struct bpf_sock_ops_kern *skops, struct bpf_map *map, void *key, u64 flags)
198581110384SJohn Fastabend  *	Description
198681110384SJohn Fastabend  *		Add an entry to, or update a sockhash *map* referencing sockets.
198781110384SJohn Fastabend  *		The *skops* is used as a new value for the entry associated to
198881110384SJohn Fastabend  *		*key*. *flags* is one of:
198981110384SJohn Fastabend  *
199081110384SJohn Fastabend  *		**BPF_NOEXIST**
199181110384SJohn Fastabend  *			The entry for *key* must not exist in the map.
199281110384SJohn Fastabend  *		**BPF_EXIST**
199381110384SJohn Fastabend  *			The entry for *key* must already exist in the map.
199481110384SJohn Fastabend  *		**BPF_ANY**
199581110384SJohn Fastabend  *			No condition on the existence of the entry for *key*.
199681110384SJohn Fastabend  *
199781110384SJohn Fastabend  *		If the *map* has eBPF programs (parser and verdict), those will
199881110384SJohn Fastabend  *		be inherited by the socket being added. If the socket is
199981110384SJohn Fastabend  *		already attached to eBPF programs, this results in an error.
200081110384SJohn Fastabend  *	Return
200181110384SJohn Fastabend  *		0 on success, or a negative error in case of failure.
200281110384SJohn Fastabend  *
200381110384SJohn Fastabend  * int bpf_msg_redirect_hash(struct sk_msg_buff *msg, struct bpf_map *map, void *key, u64 flags)
200481110384SJohn Fastabend  *	Description
200581110384SJohn Fastabend  *		This helper is used in programs implementing policies at the
200681110384SJohn Fastabend  *		socket level. If the message *msg* is allowed to pass (i.e. if
200781110384SJohn Fastabend  *		the verdict eBPF program returns **SK_PASS**), redirect it to
200881110384SJohn Fastabend  *		the socket referenced by *map* (of type
200981110384SJohn Fastabend  *		**BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
201081110384SJohn Fastabend  *		egress interfaces can be used for redirection. The
201181110384SJohn Fastabend  *		**BPF_F_INGRESS** value in *flags* is used to make the
201281110384SJohn Fastabend  *		distinction (ingress path is selected if the flag is present,
201381110384SJohn Fastabend  *		egress path otherwise). This is the only flag supported for now.
201481110384SJohn Fastabend  *	Return
201581110384SJohn Fastabend  *		**SK_PASS** on success, or **SK_DROP** on error.
201681110384SJohn Fastabend  *
201781110384SJohn Fastabend  * int bpf_sk_redirect_hash(struct sk_buff *skb, struct bpf_map *map, void *key, u64 flags)
201881110384SJohn Fastabend  *	Description
201981110384SJohn Fastabend  *		This helper is used in programs implementing policies at the
202081110384SJohn Fastabend  *		skb socket level. If the sk_buff *skb* is allowed to pass (i.e.
202181110384SJohn Fastabend  *		if the verdeict eBPF program returns **SK_PASS**), redirect it
202281110384SJohn Fastabend  *		to the socket referenced by *map* (of type
202381110384SJohn Fastabend  *		**BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
202481110384SJohn Fastabend  *		egress interfaces can be used for redirection. The
202581110384SJohn Fastabend  *		**BPF_F_INGRESS** value in *flags* is used to make the
202681110384SJohn Fastabend  *		distinction (ingress path is selected if the flag is present,
202781110384SJohn Fastabend  *		egress otherwise). This is the only flag supported for now.
202881110384SJohn Fastabend  *	Return
202981110384SJohn Fastabend  *		**SK_PASS** on success, or **SK_DROP** on error.
2030fe94cc29SMathieu Xhonneux  *
2031fe94cc29SMathieu Xhonneux  * int bpf_lwt_push_encap(struct sk_buff *skb, u32 type, void *hdr, u32 len)
2032fe94cc29SMathieu Xhonneux  *	Description
2033fe94cc29SMathieu Xhonneux  *		Encapsulate the packet associated to *skb* within a Layer 3
2034fe94cc29SMathieu Xhonneux  *		protocol header. This header is provided in the buffer at
2035fe94cc29SMathieu Xhonneux  *		address *hdr*, with *len* its size in bytes. *type* indicates
2036fe94cc29SMathieu Xhonneux  *		the protocol of the header and can be one of:
2037fe94cc29SMathieu Xhonneux  *
2038fe94cc29SMathieu Xhonneux  *		**BPF_LWT_ENCAP_SEG6**
2039fe94cc29SMathieu Xhonneux  *			IPv6 encapsulation with Segment Routing Header
2040fe94cc29SMathieu Xhonneux  *			(**struct ipv6_sr_hdr**). *hdr* only contains the SRH,
2041fe94cc29SMathieu Xhonneux  *			the IPv6 header is computed by the kernel.
2042fe94cc29SMathieu Xhonneux  *		**BPF_LWT_ENCAP_SEG6_INLINE**
2043fe94cc29SMathieu Xhonneux  *			Only works if *skb* contains an IPv6 packet. Insert a
2044fe94cc29SMathieu Xhonneux  *			Segment Routing Header (**struct ipv6_sr_hdr**) inside
2045fe94cc29SMathieu Xhonneux  *			the IPv6 header.
20463e0bd37cSPeter Oskolkov  *		**BPF_LWT_ENCAP_IP**
20473e0bd37cSPeter Oskolkov  *			IP encapsulation (GRE/GUE/IPIP/etc). The outer header
20483e0bd37cSPeter Oskolkov  *			must be IPv4 or IPv6, followed by zero or more
20493e0bd37cSPeter Oskolkov  *			additional headers, up to LWT_BPF_MAX_HEADROOM total
20503e0bd37cSPeter Oskolkov  *			bytes in all prepended headers. Please note that
20513e0bd37cSPeter Oskolkov  *			if skb_is_gso(skb) is true, no more than two headers
20523e0bd37cSPeter Oskolkov  *			can be prepended, and the inner header, if present,
20533e0bd37cSPeter Oskolkov  *			should be either GRE or UDP/GUE.
20543e0bd37cSPeter Oskolkov  *
20553e0bd37cSPeter Oskolkov  *		BPF_LWT_ENCAP_SEG6*** types can be called by bpf programs of
20563e0bd37cSPeter Oskolkov  *		type BPF_PROG_TYPE_LWT_IN; BPF_LWT_ENCAP_IP type can be called
20573e0bd37cSPeter Oskolkov  *		by bpf programs of types BPF_PROG_TYPE_LWT_IN and
20583e0bd37cSPeter Oskolkov  *		BPF_PROG_TYPE_LWT_XMIT.
2059fe94cc29SMathieu Xhonneux  *
2060fe94cc29SMathieu Xhonneux  * 		A call to this helper is susceptible to change the underlaying
2061fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
2062fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
2063fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
2064fe94cc29SMathieu Xhonneux  * 		direct packet access.
2065fe94cc29SMathieu Xhonneux  *	Return
2066fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
2067fe94cc29SMathieu Xhonneux  *
2068fe94cc29SMathieu Xhonneux  * int bpf_lwt_seg6_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len)
2069fe94cc29SMathieu Xhonneux  *	Description
2070fe94cc29SMathieu Xhonneux  *		Store *len* bytes from address *from* into the packet
2071fe94cc29SMathieu Xhonneux  *		associated to *skb*, at *offset*. Only the flags, tag and TLVs
2072fe94cc29SMathieu Xhonneux  *		inside the outermost IPv6 Segment Routing Header can be
2073fe94cc29SMathieu Xhonneux  *		modified through this helper.
2074fe94cc29SMathieu Xhonneux  *
2075fe94cc29SMathieu Xhonneux  * 		A call to this helper is susceptible to change the underlaying
2076fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
2077fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
2078fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
2079fe94cc29SMathieu Xhonneux  * 		direct packet access.
2080fe94cc29SMathieu Xhonneux  *	Return
2081fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
2082fe94cc29SMathieu Xhonneux  *
2083fe94cc29SMathieu Xhonneux  * int bpf_lwt_seg6_adjust_srh(struct sk_buff *skb, u32 offset, s32 delta)
2084fe94cc29SMathieu Xhonneux  *	Description
2085fe94cc29SMathieu Xhonneux  *		Adjust the size allocated to TLVs in the outermost IPv6
2086fe94cc29SMathieu Xhonneux  *		Segment Routing Header contained in the packet associated to
2087fe94cc29SMathieu Xhonneux  *		*skb*, at position *offset* by *delta* bytes. Only offsets
2088fe94cc29SMathieu Xhonneux  *		after the segments are accepted. *delta* can be as well
2089fe94cc29SMathieu Xhonneux  *		positive (growing) as negative (shrinking).
2090fe94cc29SMathieu Xhonneux  *
2091fe94cc29SMathieu Xhonneux  * 		A call to this helper is susceptible to change the underlaying
2092fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
2093fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
2094fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
2095fe94cc29SMathieu Xhonneux  * 		direct packet access.
2096fe94cc29SMathieu Xhonneux  *	Return
2097fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
2098fe94cc29SMathieu Xhonneux  *
2099fe94cc29SMathieu Xhonneux  * int bpf_lwt_seg6_action(struct sk_buff *skb, u32 action, void *param, u32 param_len)
2100fe94cc29SMathieu Xhonneux  *	Description
2101fe94cc29SMathieu Xhonneux  *		Apply an IPv6 Segment Routing action of type *action* to the
2102fe94cc29SMathieu Xhonneux  *		packet associated to *skb*. Each action takes a parameter
2103fe94cc29SMathieu Xhonneux  *		contained at address *param*, and of length *param_len* bytes.
2104fe94cc29SMathieu Xhonneux  *		*action* can be one of:
2105fe94cc29SMathieu Xhonneux  *
2106fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_X**
2107fe94cc29SMathieu Xhonneux  *			End.X action: Endpoint with Layer-3 cross-connect.
2108fe94cc29SMathieu Xhonneux  *			Type of *param*: **struct in6_addr**.
2109fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_T**
2110fe94cc29SMathieu Xhonneux  *			End.T action: Endpoint with specific IPv6 table lookup.
2111fe94cc29SMathieu Xhonneux  *			Type of *param*: **int**.
2112fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_B6**
2113fe94cc29SMathieu Xhonneux  *			End.B6 action: Endpoint bound to an SRv6 policy.
2114fe94cc29SMathieu Xhonneux  *			Type of param: **struct ipv6_sr_hdr**.
2115fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_B6_ENCAP**
2116fe94cc29SMathieu Xhonneux  *			End.B6.Encap action: Endpoint bound to an SRv6
2117fe94cc29SMathieu Xhonneux  *			encapsulation policy.
2118fe94cc29SMathieu Xhonneux  *			Type of param: **struct ipv6_sr_hdr**.
2119fe94cc29SMathieu Xhonneux  *
2120fe94cc29SMathieu Xhonneux  * 		A call to this helper is susceptible to change the underlaying
2121fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
2122fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
2123fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
2124fe94cc29SMathieu Xhonneux  * 		direct packet access.
2125fe94cc29SMathieu Xhonneux  *	Return
2126fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
2127f4364dcfSSean Young  *
212862369db2SQuentin Monnet  * int bpf_rc_repeat(void *ctx)
212962369db2SQuentin Monnet  *	Description
213062369db2SQuentin Monnet  *		This helper is used in programs implementing IR decoding, to
213162369db2SQuentin Monnet  *		report a successfully decoded repeat key message. This delays
213262369db2SQuentin Monnet  *		the generation of a key up event for previously generated
213362369db2SQuentin Monnet  *		key down event.
213462369db2SQuentin Monnet  *
213562369db2SQuentin Monnet  *		Some IR protocols like NEC have a special IR message for
213662369db2SQuentin Monnet  *		repeating last button, for when a button is held down.
213762369db2SQuentin Monnet  *
213862369db2SQuentin Monnet  *		The *ctx* should point to the lirc sample as passed into
213962369db2SQuentin Monnet  *		the program.
214062369db2SQuentin Monnet  *
214162369db2SQuentin Monnet  *		This helper is only available is the kernel was compiled with
214262369db2SQuentin Monnet  *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
214362369db2SQuentin Monnet  *		"**y**".
214462369db2SQuentin Monnet  *	Return
214562369db2SQuentin Monnet  *		0
214662369db2SQuentin Monnet  *
2147f4364dcfSSean Young  * int bpf_rc_keydown(void *ctx, u32 protocol, u64 scancode, u32 toggle)
2148f4364dcfSSean Young  *	Description
2149f4364dcfSSean Young  *		This helper is used in programs implementing IR decoding, to
2150f4364dcfSSean Young  *		report a successfully decoded key press with *scancode*,
2151f4364dcfSSean Young  *		*toggle* value in the given *protocol*. The scancode will be
2152f4364dcfSSean Young  *		translated to a keycode using the rc keymap, and reported as
2153f4364dcfSSean Young  *		an input key down event. After a period a key up event is
2154f4364dcfSSean Young  *		generated. This period can be extended by calling either
215590b1023fSQuentin Monnet  *		**bpf_rc_keydown**\ () again with the same values, or calling
215690b1023fSQuentin Monnet  *		**bpf_rc_repeat**\ ().
2157f4364dcfSSean Young  *
2158f4364dcfSSean Young  *		Some protocols include a toggle bit, in case the button	was
2159f4364dcfSSean Young  *		released and pressed again between consecutive scancodes.
2160f4364dcfSSean Young  *
2161f4364dcfSSean Young  *		The *ctx* should point to the lirc sample as passed into
2162f4364dcfSSean Young  *		the program.
2163f4364dcfSSean Young  *
2164f4364dcfSSean Young  *		The *protocol* is the decoded protocol number (see
2165f4364dcfSSean Young  *		**enum rc_proto** for some predefined values).
2166f4364dcfSSean Young  *
2167f4364dcfSSean Young  *		This helper is only available is the kernel was compiled with
2168f4364dcfSSean Young  *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
2169f4364dcfSSean Young  *		"**y**".
2170f4364dcfSSean Young  *	Return
2171f4364dcfSSean Young  *		0
2172f4364dcfSSean Young  *
217362369db2SQuentin Monnet  * u64 bpf_skb_cgroup_id(struct sk_buff *skb)
2174cb20b08eSDaniel Borkmann  * 	Description
2175cb20b08eSDaniel Borkmann  * 		Return the cgroup v2 id of the socket associated with the *skb*.
2176cb20b08eSDaniel Borkmann  * 		This is roughly similar to the **bpf_get_cgroup_classid**\ ()
2177cb20b08eSDaniel Borkmann  * 		helper for cgroup v1 by providing a tag resp. identifier that
2178cb20b08eSDaniel Borkmann  * 		can be matched on or used for map lookups e.g. to implement
2179cb20b08eSDaniel Borkmann  * 		policy. The cgroup v2 id of a given path in the hierarchy is
2180cb20b08eSDaniel Borkmann  * 		exposed in user space through the f_handle API in order to get
2181cb20b08eSDaniel Borkmann  * 		to the same 64-bit id.
2182cb20b08eSDaniel Borkmann  *
2183cb20b08eSDaniel Borkmann  * 		This helper can be used on TC egress path, but not on ingress,
2184cb20b08eSDaniel Borkmann  * 		and is available only if the kernel was compiled with the
2185cb20b08eSDaniel Borkmann  * 		**CONFIG_SOCK_CGROUP_DATA** configuration option.
2186cb20b08eSDaniel Borkmann  * 	Return
2187cb20b08eSDaniel Borkmann  * 		The id is returned or 0 in case the id could not be retrieved.
2188bf6fa2c8SYonghong Song  *
2189bf6fa2c8SYonghong Song  * u64 bpf_get_current_cgroup_id(void)
2190bf6fa2c8SYonghong Song  * 	Return
2191bf6fa2c8SYonghong Song  * 		A 64-bit integer containing the current cgroup id based
2192bf6fa2c8SYonghong Song  * 		on the cgroup within which the current task is running.
2193cd339431SRoman Gushchin  *
219462369db2SQuentin Monnet  * void *bpf_get_local_storage(void *map, u64 flags)
2195cd339431SRoman Gushchin  *	Description
2196cd339431SRoman Gushchin  *		Get the pointer to the local storage area.
2197cd339431SRoman Gushchin  *		The type and the size of the local storage is defined
2198cd339431SRoman Gushchin  *		by the *map* argument.
2199cd339431SRoman Gushchin  *		The *flags* meaning is specific for each map type,
2200cd339431SRoman Gushchin  *		and has to be 0 for cgroup local storage.
2201cd339431SRoman Gushchin  *
220290b1023fSQuentin Monnet  *		Depending on the BPF program type, a local storage area
220390b1023fSQuentin Monnet  *		can be shared between multiple instances of the BPF program,
2204cd339431SRoman Gushchin  *		running simultaneously.
2205cd339431SRoman Gushchin  *
2206cd339431SRoman Gushchin  *		A user should care about the synchronization by himself.
220790b1023fSQuentin Monnet  *		For example, by using the **BPF_STX_XADD** instruction to alter
2208cd339431SRoman Gushchin  *		the shared data.
2209cd339431SRoman Gushchin  *	Return
221090b1023fSQuentin Monnet  *		A pointer to the local storage area.
22112dbb9b9eSMartin KaFai Lau  *
22122dbb9b9eSMartin KaFai Lau  * int bpf_sk_select_reuseport(struct sk_reuseport_md *reuse, struct bpf_map *map, void *key, u64 flags)
22132dbb9b9eSMartin KaFai Lau  *	Description
221490b1023fSQuentin Monnet  *		Select a **SO_REUSEPORT** socket from a
221590b1023fSQuentin Monnet  *		**BPF_MAP_TYPE_REUSEPORT_ARRAY** *map*.
221690b1023fSQuentin Monnet  *		It checks the selected socket is matching the incoming
221790b1023fSQuentin Monnet  *		request in the socket buffer.
22182dbb9b9eSMartin KaFai Lau  *	Return
22192dbb9b9eSMartin KaFai Lau  *		0 on success, or a negative error in case of failure.
22206acc9b43SJoe Stringer  *
222162369db2SQuentin Monnet  * u64 bpf_skb_ancestor_cgroup_id(struct sk_buff *skb, int ancestor_level)
222262369db2SQuentin Monnet  *	Description
222362369db2SQuentin Monnet  *		Return id of cgroup v2 that is ancestor of cgroup associated
222462369db2SQuentin Monnet  *		with the *skb* at the *ancestor_level*.  The root cgroup is at
222562369db2SQuentin Monnet  *		*ancestor_level* zero and each step down the hierarchy
222662369db2SQuentin Monnet  *		increments the level. If *ancestor_level* == level of cgroup
222762369db2SQuentin Monnet  *		associated with *skb*, then return value will be same as that
222862369db2SQuentin Monnet  *		of **bpf_skb_cgroup_id**\ ().
222962369db2SQuentin Monnet  *
223062369db2SQuentin Monnet  *		The helper is useful to implement policies based on cgroups
223162369db2SQuentin Monnet  *		that are upper in hierarchy than immediate cgroup associated
223262369db2SQuentin Monnet  *		with *skb*.
223362369db2SQuentin Monnet  *
223462369db2SQuentin Monnet  *		The format of returned id and helper limitations are same as in
223562369db2SQuentin Monnet  *		**bpf_skb_cgroup_id**\ ().
223662369db2SQuentin Monnet  *	Return
223762369db2SQuentin Monnet  *		The id is returned or 0 in case the id could not be retrieved.
223862369db2SQuentin Monnet  *
2239f71c6143SJoe Stringer  * struct bpf_sock *bpf_sk_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
22406acc9b43SJoe Stringer  *	Description
22416acc9b43SJoe Stringer  *		Look for TCP socket matching *tuple*, optionally in a child
22426acc9b43SJoe Stringer  *		network namespace *netns*. The return value must be checked,
224390b1023fSQuentin Monnet  *		and if non-**NULL**, released via **bpf_sk_release**\ ().
22446acc9b43SJoe Stringer  *
22456acc9b43SJoe Stringer  *		The *ctx* should point to the context of the program, such as
22466acc9b43SJoe Stringer  *		the skb or socket (depending on the hook in use). This is used
22476acc9b43SJoe Stringer  *		to determine the base network namespace for the lookup.
22486acc9b43SJoe Stringer  *
22496acc9b43SJoe Stringer  *		*tuple_size* must be one of:
22506acc9b43SJoe Stringer  *
22516acc9b43SJoe Stringer  *		**sizeof**\ (*tuple*\ **->ipv4**)
22526acc9b43SJoe Stringer  *			Look for an IPv4 socket.
22536acc9b43SJoe Stringer  *		**sizeof**\ (*tuple*\ **->ipv6**)
22546acc9b43SJoe Stringer  *			Look for an IPv6 socket.
22556acc9b43SJoe Stringer  *
2256f71c6143SJoe Stringer  *		If the *netns* is a negative signed 32-bit integer, then the
2257f71c6143SJoe Stringer  *		socket lookup table in the netns associated with the *ctx* will
2258f71c6143SJoe Stringer  *		will be used. For the TC hooks, this is the netns of the device
2259f71c6143SJoe Stringer  *		in the skb. For socket hooks, this is the netns of the socket.
2260f71c6143SJoe Stringer  *		If *netns* is any other signed 32-bit value greater than or
2261f71c6143SJoe Stringer  *		equal to zero then it specifies the ID of the netns relative to
2262f71c6143SJoe Stringer  *		the netns associated with the *ctx*. *netns* values beyond the
2263f71c6143SJoe Stringer  *		range of 32-bit integers are reserved for future use.
22646acc9b43SJoe Stringer  *
22656acc9b43SJoe Stringer  *		All values for *flags* are reserved for future usage, and must
22666acc9b43SJoe Stringer  *		be left at zero.
22676acc9b43SJoe Stringer  *
22686acc9b43SJoe Stringer  *		This helper is available only if the kernel was compiled with
22696acc9b43SJoe Stringer  *		**CONFIG_NET** configuration option.
22706acc9b43SJoe Stringer  *	Return
22710bd72117SDaniel Borkmann  *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
22720bd72117SDaniel Borkmann  *		For sockets with reuseport option, the **struct bpf_sock**
22730bd72117SDaniel Borkmann  *		result is from **reuse->socks**\ [] using the hash of the tuple.
22746acc9b43SJoe Stringer  *
2275f71c6143SJoe Stringer  * struct bpf_sock *bpf_sk_lookup_udp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
22766acc9b43SJoe Stringer  *	Description
22776acc9b43SJoe Stringer  *		Look for UDP socket matching *tuple*, optionally in a child
22786acc9b43SJoe Stringer  *		network namespace *netns*. The return value must be checked,
227990b1023fSQuentin Monnet  *		and if non-**NULL**, released via **bpf_sk_release**\ ().
22806acc9b43SJoe Stringer  *
22816acc9b43SJoe Stringer  *		The *ctx* should point to the context of the program, such as
22826acc9b43SJoe Stringer  *		the skb or socket (depending on the hook in use). This is used
22836acc9b43SJoe Stringer  *		to determine the base network namespace for the lookup.
22846acc9b43SJoe Stringer  *
22856acc9b43SJoe Stringer  *		*tuple_size* must be one of:
22866acc9b43SJoe Stringer  *
22876acc9b43SJoe Stringer  *		**sizeof**\ (*tuple*\ **->ipv4**)
22886acc9b43SJoe Stringer  *			Look for an IPv4 socket.
22896acc9b43SJoe Stringer  *		**sizeof**\ (*tuple*\ **->ipv6**)
22906acc9b43SJoe Stringer  *			Look for an IPv6 socket.
22916acc9b43SJoe Stringer  *
2292f71c6143SJoe Stringer  *		If the *netns* is a negative signed 32-bit integer, then the
2293f71c6143SJoe Stringer  *		socket lookup table in the netns associated with the *ctx* will
2294f71c6143SJoe Stringer  *		will be used. For the TC hooks, this is the netns of the device
2295f71c6143SJoe Stringer  *		in the skb. For socket hooks, this is the netns of the socket.
2296f71c6143SJoe Stringer  *		If *netns* is any other signed 32-bit value greater than or
2297f71c6143SJoe Stringer  *		equal to zero then it specifies the ID of the netns relative to
2298f71c6143SJoe Stringer  *		the netns associated with the *ctx*. *netns* values beyond the
2299f71c6143SJoe Stringer  *		range of 32-bit integers are reserved for future use.
23006acc9b43SJoe Stringer  *
23016acc9b43SJoe Stringer  *		All values for *flags* are reserved for future usage, and must
23026acc9b43SJoe Stringer  *		be left at zero.
23036acc9b43SJoe Stringer  *
23046acc9b43SJoe Stringer  *		This helper is available only if the kernel was compiled with
23056acc9b43SJoe Stringer  *		**CONFIG_NET** configuration option.
23066acc9b43SJoe Stringer  *	Return
23070bd72117SDaniel Borkmann  *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
23080bd72117SDaniel Borkmann  *		For sockets with reuseport option, the **struct bpf_sock**
23090bd72117SDaniel Borkmann  *		result is from **reuse->socks**\ [] using the hash of the tuple.
23106acc9b43SJoe Stringer  *
231190b1023fSQuentin Monnet  * int bpf_sk_release(struct bpf_sock *sock)
23126acc9b43SJoe Stringer  *	Description
231390b1023fSQuentin Monnet  *		Release the reference held by *sock*. *sock* must be a
231490b1023fSQuentin Monnet  *		non-**NULL** pointer that was returned from
231590b1023fSQuentin Monnet  *		**bpf_sk_lookup_xxx**\ ().
231690b1023fSQuentin Monnet  *	Return
231790b1023fSQuentin Monnet  *		0 on success, or a negative error in case of failure.
231890b1023fSQuentin Monnet  *
231962369db2SQuentin Monnet  * int bpf_map_push_elem(struct bpf_map *map, const void *value, u64 flags)
232062369db2SQuentin Monnet  * 	Description
232162369db2SQuentin Monnet  * 		Push an element *value* in *map*. *flags* is one of:
232262369db2SQuentin Monnet  *
232362369db2SQuentin Monnet  * 		**BPF_EXIST**
232462369db2SQuentin Monnet  * 			If the queue/stack is full, the oldest element is
232562369db2SQuentin Monnet  * 			removed to make room for this.
232662369db2SQuentin Monnet  * 	Return
232762369db2SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
232862369db2SQuentin Monnet  *
232990b1023fSQuentin Monnet  * int bpf_map_pop_elem(struct bpf_map *map, void *value)
233090b1023fSQuentin Monnet  * 	Description
233190b1023fSQuentin Monnet  * 		Pop an element from *map*.
233290b1023fSQuentin Monnet  * 	Return
233390b1023fSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
233490b1023fSQuentin Monnet  *
233590b1023fSQuentin Monnet  * int bpf_map_peek_elem(struct bpf_map *map, void *value)
233690b1023fSQuentin Monnet  * 	Description
233790b1023fSQuentin Monnet  * 		Get an element from *map* without removing it.
23386acc9b43SJoe Stringer  * 	Return
23396acc9b43SJoe Stringer  * 		0 on success, or a negative error in case of failure.
23406fff607eSJohn Fastabend  *
23416fff607eSJohn Fastabend  * int bpf_msg_push_data(struct sk_buff *skb, u32 start, u32 len, u64 flags)
23426fff607eSJohn Fastabend  *	Description
234390b1023fSQuentin Monnet  *		For socket policies, insert *len* bytes into *msg* at offset
23446fff607eSJohn Fastabend  *		*start*.
23456fff607eSJohn Fastabend  *
23466fff607eSJohn Fastabend  *		If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
234790b1023fSQuentin Monnet  *		*msg* it may want to insert metadata or options into the *msg*.
23486fff607eSJohn Fastabend  *		This can later be read and used by any of the lower layer BPF
23496fff607eSJohn Fastabend  *		hooks.
23506fff607eSJohn Fastabend  *
23516fff607eSJohn Fastabend  *		This helper may fail if under memory pressure (a malloc
23526fff607eSJohn Fastabend  *		fails) in these cases BPF programs will get an appropriate
23536fff607eSJohn Fastabend  *		error and BPF programs will need to handle them.
23546fff607eSJohn Fastabend  *	Return
23556fff607eSJohn Fastabend  *		0 on success, or a negative error in case of failure.
23567246d8edSJohn Fastabend  *
23577246d8edSJohn Fastabend  * int bpf_msg_pop_data(struct sk_msg_buff *msg, u32 start, u32 pop, u64 flags)
23587246d8edSJohn Fastabend  *	Description
23597246d8edSJohn Fastabend  *		Will remove *pop* bytes from a *msg* starting at byte *start*.
23607246d8edSJohn Fastabend  *		This may result in **ENOMEM** errors under certain situations if
23617246d8edSJohn Fastabend  *		an allocation and copy are required due to a full ring buffer.
23627246d8edSJohn Fastabend  *		However, the helper will try to avoid doing the allocation
23637246d8edSJohn Fastabend  *		if possible. Other errors can occur if input parameters are
236490b1023fSQuentin Monnet  *		invalid either due to *start* byte not being valid part of *msg*
23657246d8edSJohn Fastabend  *		payload and/or *pop* value being to large.
23667246d8edSJohn Fastabend  *	Return
236790b1023fSQuentin Monnet  *		0 on success, or a negative error in case of failure.
236801d3240aSSean Young  *
236901d3240aSSean Young  * int bpf_rc_pointer_rel(void *ctx, s32 rel_x, s32 rel_y)
237001d3240aSSean Young  *	Description
237101d3240aSSean Young  *		This helper is used in programs implementing IR decoding, to
237201d3240aSSean Young  *		report a successfully decoded pointer movement.
237301d3240aSSean Young  *
237401d3240aSSean Young  *		The *ctx* should point to the lirc sample as passed into
237501d3240aSSean Young  *		the program.
237601d3240aSSean Young  *
237701d3240aSSean Young  *		This helper is only available is the kernel was compiled with
237801d3240aSSean Young  *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
237901d3240aSSean Young  *		"**y**".
238001d3240aSSean Young  *	Return
238101d3240aSSean Young  *		0
238246f8bc92SMartin KaFai Lau  *
23830eb09785SQuentin Monnet  * int bpf_spin_lock(struct bpf_spin_lock *lock)
23840eb09785SQuentin Monnet  *	Description
23850eb09785SQuentin Monnet  *		Acquire a spinlock represented by the pointer *lock*, which is
23860eb09785SQuentin Monnet  *		stored as part of a value of a map. Taking the lock allows to
23870eb09785SQuentin Monnet  *		safely update the rest of the fields in that value. The
23880eb09785SQuentin Monnet  *		spinlock can (and must) later be released with a call to
23890eb09785SQuentin Monnet  *		**bpf_spin_unlock**\ (\ *lock*\ ).
23900eb09785SQuentin Monnet  *
23910eb09785SQuentin Monnet  *		Spinlocks in BPF programs come with a number of restrictions
23920eb09785SQuentin Monnet  *		and constraints:
23930eb09785SQuentin Monnet  *
23940eb09785SQuentin Monnet  *		* **bpf_spin_lock** objects are only allowed inside maps of
23950eb09785SQuentin Monnet  *		  types **BPF_MAP_TYPE_HASH** and **BPF_MAP_TYPE_ARRAY** (this
23960eb09785SQuentin Monnet  *		  list could be extended in the future).
23970eb09785SQuentin Monnet  *		* BTF description of the map is mandatory.
23980eb09785SQuentin Monnet  *		* The BPF program can take ONE lock at a time, since taking two
23990eb09785SQuentin Monnet  *		  or more could cause dead locks.
24000eb09785SQuentin Monnet  *		* Only one **struct bpf_spin_lock** is allowed per map element.
24010eb09785SQuentin Monnet  *		* When the lock is taken, calls (either BPF to BPF or helpers)
24020eb09785SQuentin Monnet  *		  are not allowed.
24030eb09785SQuentin Monnet  *		* The **BPF_LD_ABS** and **BPF_LD_IND** instructions are not
24040eb09785SQuentin Monnet  *		  allowed inside a spinlock-ed region.
24050eb09785SQuentin Monnet  *		* The BPF program MUST call **bpf_spin_unlock**\ () to release
24060eb09785SQuentin Monnet  *		  the lock, on all execution paths, before it returns.
24070eb09785SQuentin Monnet  *		* The BPF program can access **struct bpf_spin_lock** only via
24080eb09785SQuentin Monnet  *		  the **bpf_spin_lock**\ () and **bpf_spin_unlock**\ ()
24090eb09785SQuentin Monnet  *		  helpers. Loading or storing data into the **struct
24100eb09785SQuentin Monnet  *		  bpf_spin_lock** *lock*\ **;** field of a map is not allowed.
24110eb09785SQuentin Monnet  *		* To use the **bpf_spin_lock**\ () helper, the BTF description
24120eb09785SQuentin Monnet  *		  of the map value must be a struct and have **struct
24130eb09785SQuentin Monnet  *		  bpf_spin_lock** *anyname*\ **;** field at the top level.
24140eb09785SQuentin Monnet  *		  Nested lock inside another struct is not allowed.
24150eb09785SQuentin Monnet  *		* The **struct bpf_spin_lock** *lock* field in a map value must
24160eb09785SQuentin Monnet  *		  be aligned on a multiple of 4 bytes in that value.
24170eb09785SQuentin Monnet  *		* Syscall with command **BPF_MAP_LOOKUP_ELEM** does not copy
24180eb09785SQuentin Monnet  *		  the **bpf_spin_lock** field to user space.
24190eb09785SQuentin Monnet  *		* Syscall with command **BPF_MAP_UPDATE_ELEM**, or update from
24200eb09785SQuentin Monnet  *		  a BPF program, do not update the **bpf_spin_lock** field.
24210eb09785SQuentin Monnet  *		* **bpf_spin_lock** cannot be on the stack or inside a
24220eb09785SQuentin Monnet  *		  networking packet (it can only be inside of a map values).
24230eb09785SQuentin Monnet  *		* **bpf_spin_lock** is available to root only.
24240eb09785SQuentin Monnet  *		* Tracing programs and socket filter programs cannot use
24250eb09785SQuentin Monnet  *		  **bpf_spin_lock**\ () due to insufficient preemption checks
24260eb09785SQuentin Monnet  *		  (but this may change in the future).
24270eb09785SQuentin Monnet  *		* **bpf_spin_lock** is not allowed in inner maps of map-in-map.
24280eb09785SQuentin Monnet  *	Return
24290eb09785SQuentin Monnet  *		0
24300eb09785SQuentin Monnet  *
24310eb09785SQuentin Monnet  * int bpf_spin_unlock(struct bpf_spin_lock *lock)
24320eb09785SQuentin Monnet  *	Description
24330eb09785SQuentin Monnet  *		Release the *lock* previously locked by a call to
24340eb09785SQuentin Monnet  *		**bpf_spin_lock**\ (\ *lock*\ ).
24350eb09785SQuentin Monnet  *	Return
24360eb09785SQuentin Monnet  *		0
24370eb09785SQuentin Monnet  *
243846f8bc92SMartin KaFai Lau  * struct bpf_sock *bpf_sk_fullsock(struct bpf_sock *sk)
243946f8bc92SMartin KaFai Lau  *	Description
244046f8bc92SMartin KaFai Lau  *		This helper gets a **struct bpf_sock** pointer such
244162369db2SQuentin Monnet  *		that all the fields in this **bpf_sock** can be accessed.
244246f8bc92SMartin KaFai Lau  *	Return
244362369db2SQuentin Monnet  *		A **struct bpf_sock** pointer on success, or **NULL** in
244446f8bc92SMartin KaFai Lau  *		case of failure.
2445655a51e5SMartin KaFai Lau  *
2446655a51e5SMartin KaFai Lau  * struct bpf_tcp_sock *bpf_tcp_sock(struct bpf_sock *sk)
2447655a51e5SMartin KaFai Lau  *	Description
2448655a51e5SMartin KaFai Lau  *		This helper gets a **struct bpf_tcp_sock** pointer from a
2449655a51e5SMartin KaFai Lau  *		**struct bpf_sock** pointer.
2450655a51e5SMartin KaFai Lau  *	Return
245162369db2SQuentin Monnet  *		A **struct bpf_tcp_sock** pointer on success, or **NULL** in
2452655a51e5SMartin KaFai Lau  *		case of failure.
2453f7c917baSbrakmo  *
2454f7c917baSbrakmo  * int bpf_skb_ecn_set_ce(struct sk_buf *skb)
2455f7c917baSbrakmo  *	Description
245662369db2SQuentin Monnet  *		Set ECN (Explicit Congestion Notification) field of IP header
245762369db2SQuentin Monnet  *		to **CE** (Congestion Encountered) if current value is **ECT**
245862369db2SQuentin Monnet  *		(ECN Capable Transport). Otherwise, do nothing. Works with IPv6
245962369db2SQuentin Monnet  *		and IPv4.
2460f7c917baSbrakmo  *	Return
246162369db2SQuentin Monnet  *		1 if the **CE** flag is set (either by the current helper call
246262369db2SQuentin Monnet  *		or because it was already present), 0 if it is not set.
2463dbafd7ddSMartin KaFai Lau  *
2464dbafd7ddSMartin KaFai Lau  * struct bpf_sock *bpf_get_listener_sock(struct bpf_sock *sk)
2465dbafd7ddSMartin KaFai Lau  *	Description
246662369db2SQuentin Monnet  *		Return a **struct bpf_sock** pointer in **TCP_LISTEN** state.
246762369db2SQuentin Monnet  *		**bpf_sk_release**\ () is unnecessary and not allowed.
2468dbafd7ddSMartin KaFai Lau  *	Return
246962369db2SQuentin Monnet  *		A **struct bpf_sock** pointer on success, or **NULL** in
2470dbafd7ddSMartin KaFai Lau  *		case of failure.
2471edbf8c01SLorenz Bauer  *
2472edbf8c01SLorenz Bauer  * struct bpf_sock *bpf_skc_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
2473edbf8c01SLorenz Bauer  *	Description
2474edbf8c01SLorenz Bauer  *		Look for TCP socket matching *tuple*, optionally in a child
2475edbf8c01SLorenz Bauer  *		network namespace *netns*. The return value must be checked,
2476edbf8c01SLorenz Bauer  *		and if non-**NULL**, released via **bpf_sk_release**\ ().
2477edbf8c01SLorenz Bauer  *
2478edbf8c01SLorenz Bauer  *		This function is identical to bpf_sk_lookup_tcp, except that it
2479edbf8c01SLorenz Bauer  *		also returns timewait or request sockets. Use bpf_sk_fullsock
2480edbf8c01SLorenz Bauer  *		or bpf_tcp_socket to access the full structure.
2481edbf8c01SLorenz Bauer  *
2482edbf8c01SLorenz Bauer  *		This helper is available only if the kernel was compiled with
2483edbf8c01SLorenz Bauer  *		**CONFIG_NET** configuration option.
2484edbf8c01SLorenz Bauer  *	Return
2485edbf8c01SLorenz Bauer  *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
2486edbf8c01SLorenz Bauer  *		For sockets with reuseport option, the **struct bpf_sock**
2487edbf8c01SLorenz Bauer  *		result is from **reuse->socks**\ [] using the hash of the tuple.
248839904084SLorenz Bauer  *
248939904084SLorenz Bauer  * int bpf_tcp_check_syncookie(struct bpf_sock *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
249039904084SLorenz Bauer  * 	Description
249139904084SLorenz Bauer  * 		Check whether iph and th contain a valid SYN cookie ACK for
249239904084SLorenz Bauer  * 		the listening socket in sk.
249339904084SLorenz Bauer  *
249439904084SLorenz Bauer  * 		iph points to the start of the IPv4 or IPv6 header, while
249539904084SLorenz Bauer  * 		iph_len contains sizeof(struct iphdr) or sizeof(struct ip6hdr).
249639904084SLorenz Bauer  *
249739904084SLorenz Bauer  * 		th points to the start of the TCP header, while th_len contains
249839904084SLorenz Bauer  * 		sizeof(struct tcphdr).
249939904084SLorenz Bauer  *
250039904084SLorenz Bauer  * 	Return
250139904084SLorenz Bauer  * 		0 if iph and th are a valid SYN cookie ACK, or a negative error
250239904084SLorenz Bauer  * 		otherwise.
25037a4b28c6SDaniel Borkmann  */
2504ebb676daSThomas Graf #define __BPF_FUNC_MAPPER(FN)		\
2505ebb676daSThomas Graf 	FN(unspec),			\
2506ebb676daSThomas Graf 	FN(map_lookup_elem),		\
2507ebb676daSThomas Graf 	FN(map_update_elem),		\
2508ebb676daSThomas Graf 	FN(map_delete_elem),		\
2509ebb676daSThomas Graf 	FN(probe_read),			\
2510ebb676daSThomas Graf 	FN(ktime_get_ns),		\
2511ebb676daSThomas Graf 	FN(trace_printk),		\
2512ebb676daSThomas Graf 	FN(get_prandom_u32),		\
2513ebb676daSThomas Graf 	FN(get_smp_processor_id),	\
2514ebb676daSThomas Graf 	FN(skb_store_bytes),		\
2515ebb676daSThomas Graf 	FN(l3_csum_replace),		\
2516ebb676daSThomas Graf 	FN(l4_csum_replace),		\
2517ebb676daSThomas Graf 	FN(tail_call),			\
2518ebb676daSThomas Graf 	FN(clone_redirect),		\
2519ebb676daSThomas Graf 	FN(get_current_pid_tgid),	\
2520ebb676daSThomas Graf 	FN(get_current_uid_gid),	\
2521ebb676daSThomas Graf 	FN(get_current_comm),		\
2522ebb676daSThomas Graf 	FN(get_cgroup_classid),		\
2523ebb676daSThomas Graf 	FN(skb_vlan_push),		\
2524ebb676daSThomas Graf 	FN(skb_vlan_pop),		\
2525ebb676daSThomas Graf 	FN(skb_get_tunnel_key),		\
2526ebb676daSThomas Graf 	FN(skb_set_tunnel_key),		\
2527ebb676daSThomas Graf 	FN(perf_event_read),		\
2528ebb676daSThomas Graf 	FN(redirect),			\
2529ebb676daSThomas Graf 	FN(get_route_realm),		\
2530ebb676daSThomas Graf 	FN(perf_event_output),		\
2531ebb676daSThomas Graf 	FN(skb_load_bytes),		\
2532ebb676daSThomas Graf 	FN(get_stackid),		\
2533ebb676daSThomas Graf 	FN(csum_diff),			\
2534ebb676daSThomas Graf 	FN(skb_get_tunnel_opt),		\
2535ebb676daSThomas Graf 	FN(skb_set_tunnel_opt),		\
2536ebb676daSThomas Graf 	FN(skb_change_proto),		\
2537ebb676daSThomas Graf 	FN(skb_change_type),		\
2538ebb676daSThomas Graf 	FN(skb_under_cgroup),		\
2539ebb676daSThomas Graf 	FN(get_hash_recalc),		\
2540ebb676daSThomas Graf 	FN(get_current_task),		\
2541ebb676daSThomas Graf 	FN(probe_write_user),		\
2542ebb676daSThomas Graf 	FN(current_task_under_cgroup),	\
2543ebb676daSThomas Graf 	FN(skb_change_tail),		\
2544ebb676daSThomas Graf 	FN(skb_pull_data),		\
2545ebb676daSThomas Graf 	FN(csum_update),		\
2546ebb676daSThomas Graf 	FN(set_hash_invalid),		\
25473a0af8fdSThomas Graf 	FN(get_numa_node_id),		\
254817bedab2SMartin KaFai Lau 	FN(skb_change_head),		\
2549a5e8c070SGianluca Borello 	FN(xdp_adjust_head),		\
255091b8270fSChenbo Feng 	FN(probe_read_str),		\
25516acc5c29SChenbo Feng 	FN(get_socket_cookie),		\
2552ded092cdSDaniel Borkmann 	FN(get_socket_uid),		\
25538c4b4c7eSLawrence Brakmo 	FN(set_hash),			\
25542be7e212SDaniel Borkmann 	FN(setsockopt),			\
255597f91a7cSJohn Fastabend 	FN(skb_adjust_room),		\
2556174a79ffSJohn Fastabend 	FN(redirect_map),		\
2557174a79ffSJohn Fastabend 	FN(sk_redirect_map),		\
2558174a79ffSJohn Fastabend 	FN(sock_map_update),		\
2559908432caSYonghong Song 	FN(xdp_adjust_meta),		\
25604bebdc7aSYonghong Song 	FN(perf_event_read_value),	\
2561cd86d1fdSLawrence Brakmo 	FN(perf_prog_read_value),	\
25629802d865SJosef Bacik 	FN(getsockopt),			\
2563b13d8807SLawrence Brakmo 	FN(override_return),		\
25644f738adbSJohn Fastabend 	FN(sock_ops_cb_flags_set),	\
25652a100317SJohn Fastabend 	FN(msg_redirect_map),		\
256691843d54SJohn Fastabend 	FN(msg_apply_bytes),		\
2567015632bbSJohn Fastabend 	FN(msg_cork_bytes),		\
2568d74bad4eSAndrey Ignatov 	FN(msg_pull_data),		\
2569b32cc5b9SNikita V. Shirokov 	FN(bind),			\
257012bed760SEyal Birger 	FN(xdp_adjust_tail),		\
2571c195651eSYonghong Song 	FN(skb_get_xfrm_state),		\
25724e1ec56cSDaniel Borkmann 	FN(get_stack),			\
257387f5fc7eSDavid Ahern 	FN(skb_load_bytes_relative),	\
257481110384SJohn Fastabend 	FN(fib_lookup),			\
257581110384SJohn Fastabend 	FN(sock_hash_update),		\
257681110384SJohn Fastabend 	FN(msg_redirect_hash),		\
2577fe94cc29SMathieu Xhonneux 	FN(sk_redirect_hash),		\
2578fe94cc29SMathieu Xhonneux 	FN(lwt_push_encap),		\
2579fe94cc29SMathieu Xhonneux 	FN(lwt_seg6_store_bytes),	\
2580fe94cc29SMathieu Xhonneux 	FN(lwt_seg6_adjust_srh),	\
2581f4364dcfSSean Young 	FN(lwt_seg6_action),		\
2582f4364dcfSSean Young 	FN(rc_repeat),			\
2583cb20b08eSDaniel Borkmann 	FN(rc_keydown),			\
2584bf6fa2c8SYonghong Song 	FN(skb_cgroup_id),		\
2585cd339431SRoman Gushchin 	FN(get_current_cgroup_id),	\
25862dbb9b9eSMartin KaFai Lau 	FN(get_local_storage),		\
258777236281SAndrey Ignatov 	FN(sk_select_reuseport),	\
25886acc9b43SJoe Stringer 	FN(skb_ancestor_cgroup_id),	\
25896acc9b43SJoe Stringer 	FN(sk_lookup_tcp),		\
25906acc9b43SJoe Stringer 	FN(sk_lookup_udp),		\
2591f1a2e44aSMauricio Vasquez B 	FN(sk_release),			\
2592f1a2e44aSMauricio Vasquez B 	FN(map_push_elem),		\
2593f1a2e44aSMauricio Vasquez B 	FN(map_pop_elem),		\
25946fff607eSJohn Fastabend 	FN(map_peek_elem),		\
25957246d8edSJohn Fastabend 	FN(msg_push_data),		\
259601d3240aSSean Young 	FN(msg_pop_data),		\
2597d83525caSAlexei Starovoitov 	FN(rc_pointer_rel),		\
2598d83525caSAlexei Starovoitov 	FN(spin_lock),			\
259946f8bc92SMartin KaFai Lau 	FN(spin_unlock),		\
2600655a51e5SMartin KaFai Lau 	FN(sk_fullsock),		\
2601f7c917baSbrakmo 	FN(tcp_sock),			\
2602dbafd7ddSMartin KaFai Lau 	FN(skb_ecn_set_ce),		\
2603edbf8c01SLorenz Bauer 	FN(get_listener_sock),		\
260439904084SLorenz Bauer 	FN(skc_lookup_tcp),		\
260539904084SLorenz Bauer 	FN(tcp_check_syncookie),
26067a4b28c6SDaniel Borkmann 
2607ebb676daSThomas Graf /* integer value in 'imm' field of BPF_CALL instruction selects which helper
2608ebb676daSThomas Graf  * function eBPF program intends to call
26092d0e30c3SDaniel Borkmann  */
2610ebb676daSThomas Graf #define __BPF_ENUM_FN(x) BPF_FUNC_ ## x
2611ebb676daSThomas Graf enum bpf_func_id {
2612ebb676daSThomas Graf 	__BPF_FUNC_MAPPER(__BPF_ENUM_FN)
261309756af4SAlexei Starovoitov 	__BPF_FUNC_MAX_ID,
261409756af4SAlexei Starovoitov };
2615ebb676daSThomas Graf #undef __BPF_ENUM_FN
261609756af4SAlexei Starovoitov 
2617781c53bcSDaniel Borkmann /* All flags used by eBPF helper functions, placed here. */
2618781c53bcSDaniel Borkmann 
2619781c53bcSDaniel Borkmann /* BPF_FUNC_skb_store_bytes flags. */
2620781c53bcSDaniel Borkmann #define BPF_F_RECOMPUTE_CSUM		(1ULL << 0)
26218afd54c8SDaniel Borkmann #define BPF_F_INVALIDATE_HASH		(1ULL << 1)
2622781c53bcSDaniel Borkmann 
2623781c53bcSDaniel Borkmann /* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
2624781c53bcSDaniel Borkmann  * First 4 bits are for passing the header field size.
2625781c53bcSDaniel Borkmann  */
2626781c53bcSDaniel Borkmann #define BPF_F_HDR_FIELD_MASK		0xfULL
2627781c53bcSDaniel Borkmann 
2628781c53bcSDaniel Borkmann /* BPF_FUNC_l4_csum_replace flags. */
2629781c53bcSDaniel Borkmann #define BPF_F_PSEUDO_HDR		(1ULL << 4)
26302f72959aSDaniel Borkmann #define BPF_F_MARK_MANGLED_0		(1ULL << 5)
2631d1b662adSDaniel Borkmann #define BPF_F_MARK_ENFORCE		(1ULL << 6)
2632781c53bcSDaniel Borkmann 
2633781c53bcSDaniel Borkmann /* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */
2634781c53bcSDaniel Borkmann #define BPF_F_INGRESS			(1ULL << 0)
2635781c53bcSDaniel Borkmann 
2636c6c33454SDaniel Borkmann /* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */
2637c6c33454SDaniel Borkmann #define BPF_F_TUNINFO_IPV6		(1ULL << 0)
2638c6c33454SDaniel Borkmann 
2639c195651eSYonghong Song /* flags for both BPF_FUNC_get_stackid and BPF_FUNC_get_stack. */
2640d5a3b1f6SAlexei Starovoitov #define BPF_F_SKIP_FIELD_MASK		0xffULL
2641d5a3b1f6SAlexei Starovoitov #define BPF_F_USER_STACK		(1ULL << 8)
2642c195651eSYonghong Song /* flags used by BPF_FUNC_get_stackid only. */
2643d5a3b1f6SAlexei Starovoitov #define BPF_F_FAST_STACK_CMP		(1ULL << 9)
2644d5a3b1f6SAlexei Starovoitov #define BPF_F_REUSE_STACKID		(1ULL << 10)
2645c195651eSYonghong Song /* flags used by BPF_FUNC_get_stack only. */
2646c195651eSYonghong Song #define BPF_F_USER_BUILD_ID		(1ULL << 11)
2647d5a3b1f6SAlexei Starovoitov 
26482da897e5SDaniel Borkmann /* BPF_FUNC_skb_set_tunnel_key flags. */
26492da897e5SDaniel Borkmann #define BPF_F_ZERO_CSUM_TX		(1ULL << 1)
265022080870SDaniel Borkmann #define BPF_F_DONT_FRAGMENT		(1ULL << 2)
265177a5196aSWilliam Tu #define BPF_F_SEQ_NUMBER		(1ULL << 3)
26522da897e5SDaniel Borkmann 
2653908432caSYonghong Song /* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
2654908432caSYonghong Song  * BPF_FUNC_perf_event_read_value flags.
2655908432caSYonghong Song  */
26561e33759cSDaniel Borkmann #define BPF_F_INDEX_MASK		0xffffffffULL
26571e33759cSDaniel Borkmann #define BPF_F_CURRENT_CPU		BPF_F_INDEX_MASK
2658555c8a86SDaniel Borkmann /* BPF_FUNC_perf_event_output for sk_buff input context. */
2659555c8a86SDaniel Borkmann #define BPF_F_CTXLEN_MASK		(0xfffffULL << 32)
26601e33759cSDaniel Borkmann 
2661f71c6143SJoe Stringer /* Current network namespace */
2662f71c6143SJoe Stringer #define BPF_F_CURRENT_NETNS		(-1L)
2663f71c6143SJoe Stringer 
26642278f6ccSWillem de Bruijn /* BPF_FUNC_skb_adjust_room flags. */
26652278f6ccSWillem de Bruijn #define BPF_F_ADJ_ROOM_FIXED_GSO	(1ULL << 0)
26662278f6ccSWillem de Bruijn 
2667868d5235SWillem de Bruijn #define BPF_F_ADJ_ROOM_ENCAP_L3_IPV4	(1ULL << 1)
2668868d5235SWillem de Bruijn #define BPF_F_ADJ_ROOM_ENCAP_L3_IPV6	(1ULL << 2)
2669868d5235SWillem de Bruijn #define BPF_F_ADJ_ROOM_ENCAP_L4_GRE	(1ULL << 3)
2670868d5235SWillem de Bruijn #define BPF_F_ADJ_ROOM_ENCAP_L4_UDP	(1ULL << 4)
2671868d5235SWillem de Bruijn 
26722be7e212SDaniel Borkmann /* Mode for BPF_FUNC_skb_adjust_room helper. */
26732be7e212SDaniel Borkmann enum bpf_adj_room_mode {
26742be7e212SDaniel Borkmann 	BPF_ADJ_ROOM_NET,
267514aa3192SWillem de Bruijn 	BPF_ADJ_ROOM_MAC,
26762be7e212SDaniel Borkmann };
26772be7e212SDaniel Borkmann 
26784e1ec56cSDaniel Borkmann /* Mode for BPF_FUNC_skb_load_bytes_relative helper. */
26794e1ec56cSDaniel Borkmann enum bpf_hdr_start_off {
26804e1ec56cSDaniel Borkmann 	BPF_HDR_START_MAC,
26814e1ec56cSDaniel Borkmann 	BPF_HDR_START_NET,
26824e1ec56cSDaniel Borkmann };
26834e1ec56cSDaniel Borkmann 
2684fe94cc29SMathieu Xhonneux /* Encapsulation type for BPF_FUNC_lwt_push_encap helper. */
2685fe94cc29SMathieu Xhonneux enum bpf_lwt_encap_mode {
2686fe94cc29SMathieu Xhonneux 	BPF_LWT_ENCAP_SEG6,
26873e0bd37cSPeter Oskolkov 	BPF_LWT_ENCAP_SEG6_INLINE,
26883e0bd37cSPeter Oskolkov 	BPF_LWT_ENCAP_IP,
2689fe94cc29SMathieu Xhonneux };
2690fe94cc29SMathieu Xhonneux 
2691b7df9adaSDaniel Borkmann #define __bpf_md_ptr(type, name)	\
2692b7df9adaSDaniel Borkmann union {					\
2693b7df9adaSDaniel Borkmann 	type name;			\
2694b7df9adaSDaniel Borkmann 	__u64 :64;			\
2695b7df9adaSDaniel Borkmann } __attribute__((aligned(8)))
2696b7df9adaSDaniel Borkmann 
26979bac3d6dSAlexei Starovoitov /* user accessible mirror of in-kernel sk_buff.
26989bac3d6dSAlexei Starovoitov  * new fields can only be added to the end of this structure
26999bac3d6dSAlexei Starovoitov  */
27009bac3d6dSAlexei Starovoitov struct __sk_buff {
27019bac3d6dSAlexei Starovoitov 	__u32 len;
27029bac3d6dSAlexei Starovoitov 	__u32 pkt_type;
27039bac3d6dSAlexei Starovoitov 	__u32 mark;
27049bac3d6dSAlexei Starovoitov 	__u32 queue_mapping;
2705c2497395SAlexei Starovoitov 	__u32 protocol;
2706c2497395SAlexei Starovoitov 	__u32 vlan_present;
2707c2497395SAlexei Starovoitov 	__u32 vlan_tci;
270827cd5452SMichal Sekletar 	__u32 vlan_proto;
2709bcad5718SDaniel Borkmann 	__u32 priority;
271037e82c2fSAlexei Starovoitov 	__u32 ingress_ifindex;
271137e82c2fSAlexei Starovoitov 	__u32 ifindex;
2712d691f9e8SAlexei Starovoitov 	__u32 tc_index;
2713d691f9e8SAlexei Starovoitov 	__u32 cb[5];
2714ba7591d8SDaniel Borkmann 	__u32 hash;
2715045efa82SDaniel Borkmann 	__u32 tc_classid;
2716969bf05eSAlexei Starovoitov 	__u32 data;
2717969bf05eSAlexei Starovoitov 	__u32 data_end;
2718b1d9fc41SDaniel Borkmann 	__u32 napi_id;
27198a31db56SJohn Fastabend 
2720de8f3a83SDaniel Borkmann 	/* Accessed by BPF_PROG_TYPE_sk_skb types from here to ... */
27218a31db56SJohn Fastabend 	__u32 family;
27228a31db56SJohn Fastabend 	__u32 remote_ip4;	/* Stored in network byte order */
27238a31db56SJohn Fastabend 	__u32 local_ip4;	/* Stored in network byte order */
27248a31db56SJohn Fastabend 	__u32 remote_ip6[4];	/* Stored in network byte order */
27258a31db56SJohn Fastabend 	__u32 local_ip6[4];	/* Stored in network byte order */
27268a31db56SJohn Fastabend 	__u32 remote_port;	/* Stored in network byte order */
27278a31db56SJohn Fastabend 	__u32 local_port;	/* stored in host byte order */
2728de8f3a83SDaniel Borkmann 	/* ... here. */
2729de8f3a83SDaniel Borkmann 
2730de8f3a83SDaniel Borkmann 	__u32 data_meta;
2731b7df9adaSDaniel Borkmann 	__bpf_md_ptr(struct bpf_flow_keys *, flow_keys);
2732f11216b2SVlad Dumitrescu 	__u64 tstamp;
2733e3da08d0SPetar Penkov 	__u32 wire_len;
2734d9ff286aSEric Dumazet 	__u32 gso_segs;
273546f8bc92SMartin KaFai Lau 	__bpf_md_ptr(struct bpf_sock *, sk);
27369bac3d6dSAlexei Starovoitov };
27379bac3d6dSAlexei Starovoitov 
2738d3aa45ceSAlexei Starovoitov struct bpf_tunnel_key {
2739d3aa45ceSAlexei Starovoitov 	__u32 tunnel_id;
2740c6c33454SDaniel Borkmann 	union {
2741d3aa45ceSAlexei Starovoitov 		__u32 remote_ipv4;
2742c6c33454SDaniel Borkmann 		__u32 remote_ipv6[4];
2743c6c33454SDaniel Borkmann 	};
2744c6c33454SDaniel Borkmann 	__u8 tunnel_tos;
2745c6c33454SDaniel Borkmann 	__u8 tunnel_ttl;
27461fbc2e0cSDaniel Borkmann 	__u16 tunnel_ext;	/* Padding, future use. */
27474018ab18SDaniel Borkmann 	__u32 tunnel_label;
2748d3aa45ceSAlexei Starovoitov };
2749d3aa45ceSAlexei Starovoitov 
275012bed760SEyal Birger /* user accessible mirror of in-kernel xfrm_state.
275112bed760SEyal Birger  * new fields can only be added to the end of this structure
275212bed760SEyal Birger  */
275312bed760SEyal Birger struct bpf_xfrm_state {
275412bed760SEyal Birger 	__u32 reqid;
275512bed760SEyal Birger 	__u32 spi;	/* Stored in network byte order */
275612bed760SEyal Birger 	__u16 family;
27571fbc2e0cSDaniel Borkmann 	__u16 ext;	/* Padding, future use. */
275812bed760SEyal Birger 	union {
275912bed760SEyal Birger 		__u32 remote_ipv4;	/* Stored in network byte order */
276012bed760SEyal Birger 		__u32 remote_ipv6[4];	/* Stored in network byte order */
276112bed760SEyal Birger 	};
276212bed760SEyal Birger };
276312bed760SEyal Birger 
27643a0af8fdSThomas Graf /* Generic BPF return codes which all BPF program types may support.
27653a0af8fdSThomas Graf  * The values are binary compatible with their TC_ACT_* counter-part to
27663a0af8fdSThomas Graf  * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT
27673a0af8fdSThomas Graf  * programs.
27683a0af8fdSThomas Graf  *
27693a0af8fdSThomas Graf  * XDP is handled seprately, see XDP_*.
27703a0af8fdSThomas Graf  */
27713a0af8fdSThomas Graf enum bpf_ret_code {
27723a0af8fdSThomas Graf 	BPF_OK = 0,
27733a0af8fdSThomas Graf 	/* 1 reserved */
27743a0af8fdSThomas Graf 	BPF_DROP = 2,
27753a0af8fdSThomas Graf 	/* 3-6 reserved */
27763a0af8fdSThomas Graf 	BPF_REDIRECT = 7,
27773e0bd37cSPeter Oskolkov 	/* >127 are reserved for prog type specific return codes.
27783e0bd37cSPeter Oskolkov 	 *
27793e0bd37cSPeter Oskolkov 	 * BPF_LWT_REROUTE: used by BPF_PROG_TYPE_LWT_IN and
27803e0bd37cSPeter Oskolkov 	 *    BPF_PROG_TYPE_LWT_XMIT to indicate that skb had been
27813e0bd37cSPeter Oskolkov 	 *    changed and should be routed based on its new L3 header.
27823e0bd37cSPeter Oskolkov 	 *    (This is an L3 redirect, as opposed to L2 redirect
27833e0bd37cSPeter Oskolkov 	 *    represented by BPF_REDIRECT above).
27843e0bd37cSPeter Oskolkov 	 */
27853e0bd37cSPeter Oskolkov 	BPF_LWT_REROUTE = 128,
27863a0af8fdSThomas Graf };
27873a0af8fdSThomas Graf 
278861023658SDavid Ahern struct bpf_sock {
278961023658SDavid Ahern 	__u32 bound_dev_if;
2790aa4c1037SDavid Ahern 	__u32 family;
2791aa4c1037SDavid Ahern 	__u32 type;
2792aa4c1037SDavid Ahern 	__u32 protocol;
2793482dca93SDavid Ahern 	__u32 mark;
2794482dca93SDavid Ahern 	__u32 priority;
2795aa65d696SMartin KaFai Lau 	/* IP address also allows 1 and 2 bytes access */
2796aa65d696SMartin KaFai Lau 	__u32 src_ip4;
2797aa65d696SMartin KaFai Lau 	__u32 src_ip6[4];
2798aa65d696SMartin KaFai Lau 	__u32 src_port;		/* host byte order */
2799aa65d696SMartin KaFai Lau 	__u32 dst_port;		/* network byte order */
2800aa65d696SMartin KaFai Lau 	__u32 dst_ip4;
2801aa65d696SMartin KaFai Lau 	__u32 dst_ip6[4];
2802aa65d696SMartin KaFai Lau 	__u32 state;
280361023658SDavid Ahern };
280461023658SDavid Ahern 
2805655a51e5SMartin KaFai Lau struct bpf_tcp_sock {
2806655a51e5SMartin KaFai Lau 	__u32 snd_cwnd;		/* Sending congestion window		*/
2807655a51e5SMartin KaFai Lau 	__u32 srtt_us;		/* smoothed round trip time << 3 in usecs */
2808655a51e5SMartin KaFai Lau 	__u32 rtt_min;
2809655a51e5SMartin KaFai Lau 	__u32 snd_ssthresh;	/* Slow start size threshold		*/
2810655a51e5SMartin KaFai Lau 	__u32 rcv_nxt;		/* What we want to receive next		*/
2811655a51e5SMartin KaFai Lau 	__u32 snd_nxt;		/* Next sequence we send		*/
2812655a51e5SMartin KaFai Lau 	__u32 snd_una;		/* First byte we want an ack for	*/
2813655a51e5SMartin KaFai Lau 	__u32 mss_cache;	/* Cached effective mss, not including SACKS */
2814655a51e5SMartin KaFai Lau 	__u32 ecn_flags;	/* ECN status bits.			*/
2815655a51e5SMartin KaFai Lau 	__u32 rate_delivered;	/* saved rate sample: packets delivered */
2816655a51e5SMartin KaFai Lau 	__u32 rate_interval_us;	/* saved rate sample: time elapsed */
2817655a51e5SMartin KaFai Lau 	__u32 packets_out;	/* Packets which are "in flight"	*/
2818655a51e5SMartin KaFai Lau 	__u32 retrans_out;	/* Retransmitted packets out		*/
2819655a51e5SMartin KaFai Lau 	__u32 total_retrans;	/* Total retransmits for entire connection */
2820655a51e5SMartin KaFai Lau 	__u32 segs_in;		/* RFC4898 tcpEStatsPerfSegsIn
2821655a51e5SMartin KaFai Lau 				 * total number of segments in.
2822655a51e5SMartin KaFai Lau 				 */
2823655a51e5SMartin KaFai Lau 	__u32 data_segs_in;	/* RFC4898 tcpEStatsPerfDataSegsIn
2824655a51e5SMartin KaFai Lau 				 * total number of data segments in.
2825655a51e5SMartin KaFai Lau 				 */
2826655a51e5SMartin KaFai Lau 	__u32 segs_out;		/* RFC4898 tcpEStatsPerfSegsOut
2827655a51e5SMartin KaFai Lau 				 * The total number of segments sent.
2828655a51e5SMartin KaFai Lau 				 */
2829655a51e5SMartin KaFai Lau 	__u32 data_segs_out;	/* RFC4898 tcpEStatsPerfDataSegsOut
2830655a51e5SMartin KaFai Lau 				 * total number of data segments sent.
2831655a51e5SMartin KaFai Lau 				 */
2832655a51e5SMartin KaFai Lau 	__u32 lost_out;		/* Lost packets			*/
2833655a51e5SMartin KaFai Lau 	__u32 sacked_out;	/* SACK'd packets			*/
2834655a51e5SMartin KaFai Lau 	__u64 bytes_received;	/* RFC4898 tcpEStatsAppHCThruOctetsReceived
2835655a51e5SMartin KaFai Lau 				 * sum(delta(rcv_nxt)), or how many bytes
2836655a51e5SMartin KaFai Lau 				 * were acked.
2837655a51e5SMartin KaFai Lau 				 */
2838655a51e5SMartin KaFai Lau 	__u64 bytes_acked;	/* RFC4898 tcpEStatsAppHCThruOctetsAcked
2839655a51e5SMartin KaFai Lau 				 * sum(delta(snd_una)), or how many bytes
2840655a51e5SMartin KaFai Lau 				 * were acked.
2841655a51e5SMartin KaFai Lau 				 */
2842655a51e5SMartin KaFai Lau };
2843655a51e5SMartin KaFai Lau 
28446acc9b43SJoe Stringer struct bpf_sock_tuple {
28456acc9b43SJoe Stringer 	union {
28466acc9b43SJoe Stringer 		struct {
28476acc9b43SJoe Stringer 			__be32 saddr;
28486acc9b43SJoe Stringer 			__be32 daddr;
28496acc9b43SJoe Stringer 			__be16 sport;
28506acc9b43SJoe Stringer 			__be16 dport;
28516acc9b43SJoe Stringer 		} ipv4;
28526acc9b43SJoe Stringer 		struct {
28536acc9b43SJoe Stringer 			__be32 saddr[4];
28546acc9b43SJoe Stringer 			__be32 daddr[4];
28556acc9b43SJoe Stringer 			__be16 sport;
28566acc9b43SJoe Stringer 			__be16 dport;
28576acc9b43SJoe Stringer 		} ipv6;
28586acc9b43SJoe Stringer 	};
28596acc9b43SJoe Stringer };
28606acc9b43SJoe Stringer 
286117bedab2SMartin KaFai Lau #define XDP_PACKET_HEADROOM 256
286217bedab2SMartin KaFai Lau 
28636a773a15SBrenden Blanco /* User return codes for XDP prog type.
28646a773a15SBrenden Blanco  * A valid XDP program must return one of these defined values. All other
28659beb8bedSDaniel Borkmann  * return codes are reserved for future use. Unknown return codes will
28669beb8bedSDaniel Borkmann  * result in packet drops and a warning via bpf_warn_invalid_xdp_action().
28676a773a15SBrenden Blanco  */
28686a773a15SBrenden Blanco enum xdp_action {
28696a773a15SBrenden Blanco 	XDP_ABORTED = 0,
28706a773a15SBrenden Blanco 	XDP_DROP,
28716a773a15SBrenden Blanco 	XDP_PASS,
28726ce96ca3SBrenden Blanco 	XDP_TX,
2873814abfabSJohn Fastabend 	XDP_REDIRECT,
28746a773a15SBrenden Blanco };
28756a773a15SBrenden Blanco 
28766a773a15SBrenden Blanco /* user accessible metadata for XDP packet hook
28776a773a15SBrenden Blanco  * new fields must be added to the end of this structure
28786a773a15SBrenden Blanco  */
28796a773a15SBrenden Blanco struct xdp_md {
28806a773a15SBrenden Blanco 	__u32 data;
28816a773a15SBrenden Blanco 	__u32 data_end;
2882de8f3a83SDaniel Borkmann 	__u32 data_meta;
2883daaf24c6SJesper Dangaard Brouer 	/* Below access go through struct xdp_rxq_info */
288402dd3291SJesper Dangaard Brouer 	__u32 ingress_ifindex; /* rxq->dev->ifindex */
288502dd3291SJesper Dangaard Brouer 	__u32 rx_queue_index;  /* rxq->queue_index  */
28866a773a15SBrenden Blanco };
28876a773a15SBrenden Blanco 
2888174a79ffSJohn Fastabend enum sk_action {
2889bfa64075SJohn Fastabend 	SK_DROP = 0,
2890bfa64075SJohn Fastabend 	SK_PASS,
2891174a79ffSJohn Fastabend };
2892174a79ffSJohn Fastabend 
28934f738adbSJohn Fastabend /* user accessible metadata for SK_MSG packet hook, new fields must
28944f738adbSJohn Fastabend  * be added to the end of this structure
28954f738adbSJohn Fastabend  */
28964f738adbSJohn Fastabend struct sk_msg_md {
2897b7df9adaSDaniel Borkmann 	__bpf_md_ptr(void *, data);
2898b7df9adaSDaniel Borkmann 	__bpf_md_ptr(void *, data_end);
2899303def35SJohn Fastabend 
2900303def35SJohn Fastabend 	__u32 family;
2901303def35SJohn Fastabend 	__u32 remote_ip4;	/* Stored in network byte order */
2902303def35SJohn Fastabend 	__u32 local_ip4;	/* Stored in network byte order */
2903303def35SJohn Fastabend 	__u32 remote_ip6[4];	/* Stored in network byte order */
2904303def35SJohn Fastabend 	__u32 local_ip6[4];	/* Stored in network byte order */
2905303def35SJohn Fastabend 	__u32 remote_port;	/* Stored in network byte order */
2906303def35SJohn Fastabend 	__u32 local_port;	/* stored in host byte order */
29073bdbd022SJohn Fastabend 	__u32 size;		/* Total size of sk_msg */
29084f738adbSJohn Fastabend };
29094f738adbSJohn Fastabend 
29102dbb9b9eSMartin KaFai Lau struct sk_reuseport_md {
29112dbb9b9eSMartin KaFai Lau 	/*
29122dbb9b9eSMartin KaFai Lau 	 * Start of directly accessible data. It begins from
29132dbb9b9eSMartin KaFai Lau 	 * the tcp/udp header.
29142dbb9b9eSMartin KaFai Lau 	 */
2915b7df9adaSDaniel Borkmann 	__bpf_md_ptr(void *, data);
2916b7df9adaSDaniel Borkmann 	/* End of directly accessible data */
2917b7df9adaSDaniel Borkmann 	__bpf_md_ptr(void *, data_end);
29182dbb9b9eSMartin KaFai Lau 	/*
29192dbb9b9eSMartin KaFai Lau 	 * Total length of packet (starting from the tcp/udp header).
29202dbb9b9eSMartin KaFai Lau 	 * Note that the directly accessible bytes (data_end - data)
29212dbb9b9eSMartin KaFai Lau 	 * could be less than this "len".  Those bytes could be
29222dbb9b9eSMartin KaFai Lau 	 * indirectly read by a helper "bpf_skb_load_bytes()".
29232dbb9b9eSMartin KaFai Lau 	 */
29242dbb9b9eSMartin KaFai Lau 	__u32 len;
29252dbb9b9eSMartin KaFai Lau 	/*
29262dbb9b9eSMartin KaFai Lau 	 * Eth protocol in the mac header (network byte order). e.g.
29272dbb9b9eSMartin KaFai Lau 	 * ETH_P_IP(0x0800) and ETH_P_IPV6(0x86DD)
29282dbb9b9eSMartin KaFai Lau 	 */
29292dbb9b9eSMartin KaFai Lau 	__u32 eth_protocol;
29302dbb9b9eSMartin KaFai Lau 	__u32 ip_protocol;	/* IP protocol. e.g. IPPROTO_TCP, IPPROTO_UDP */
29312dbb9b9eSMartin KaFai Lau 	__u32 bind_inany;	/* Is sock bound to an INANY address? */
29322dbb9b9eSMartin KaFai Lau 	__u32 hash;		/* A hash of the packet 4 tuples */
29332dbb9b9eSMartin KaFai Lau };
29342dbb9b9eSMartin KaFai Lau 
29351e270976SMartin KaFai Lau #define BPF_TAG_SIZE	8
29361e270976SMartin KaFai Lau 
29371e270976SMartin KaFai Lau struct bpf_prog_info {
29381e270976SMartin KaFai Lau 	__u32 type;
29391e270976SMartin KaFai Lau 	__u32 id;
29401e270976SMartin KaFai Lau 	__u8  tag[BPF_TAG_SIZE];
29411e270976SMartin KaFai Lau 	__u32 jited_prog_len;
29421e270976SMartin KaFai Lau 	__u32 xlated_prog_len;
29431e270976SMartin KaFai Lau 	__aligned_u64 jited_prog_insns;
29441e270976SMartin KaFai Lau 	__aligned_u64 xlated_prog_insns;
2945cb4d2b3fSMartin KaFai Lau 	__u64 load_time;	/* ns since boottime */
2946cb4d2b3fSMartin KaFai Lau 	__u32 created_by_uid;
2947cb4d2b3fSMartin KaFai Lau 	__u32 nr_map_ids;
2948cb4d2b3fSMartin KaFai Lau 	__aligned_u64 map_ids;
2949067cae47SMartin KaFai Lau 	char name[BPF_OBJ_NAME_LEN];
2950675fc275SJakub Kicinski 	__u32 ifindex;
2951b85fab0eSJiri Olsa 	__u32 gpl_compatible:1;
2952675fc275SJakub Kicinski 	__u64 netns_dev;
2953675fc275SJakub Kicinski 	__u64 netns_ino;
2954dbecd738SSandipan Das 	__u32 nr_jited_ksyms;
2955815581c1SSandipan Das 	__u32 nr_jited_func_lens;
2956dbecd738SSandipan Das 	__aligned_u64 jited_ksyms;
2957815581c1SSandipan Das 	__aligned_u64 jited_func_lens;
2958838e9690SYonghong Song 	__u32 btf_id;
2959838e9690SYonghong Song 	__u32 func_info_rec_size;
2960838e9690SYonghong Song 	__aligned_u64 func_info;
296111d8b82dSYonghong Song 	__u32 nr_func_info;
296211d8b82dSYonghong Song 	__u32 nr_line_info;
2963c454a46bSMartin KaFai Lau 	__aligned_u64 line_info;
2964c454a46bSMartin KaFai Lau 	__aligned_u64 jited_line_info;
296511d8b82dSYonghong Song 	__u32 nr_jited_line_info;
2966c454a46bSMartin KaFai Lau 	__u32 line_info_rec_size;
2967c454a46bSMartin KaFai Lau 	__u32 jited_line_info_rec_size;
2968c872bdb3SSong Liu 	__u32 nr_prog_tags;
2969c872bdb3SSong Liu 	__aligned_u64 prog_tags;
29705f8f8b93SAlexei Starovoitov 	__u64 run_time_ns;
29715f8f8b93SAlexei Starovoitov 	__u64 run_cnt;
29721e270976SMartin KaFai Lau } __attribute__((aligned(8)));
29731e270976SMartin KaFai Lau 
29741e270976SMartin KaFai Lau struct bpf_map_info {
29751e270976SMartin KaFai Lau 	__u32 type;
29761e270976SMartin KaFai Lau 	__u32 id;
29771e270976SMartin KaFai Lau 	__u32 key_size;
29781e270976SMartin KaFai Lau 	__u32 value_size;
29791e270976SMartin KaFai Lau 	__u32 max_entries;
29801e270976SMartin KaFai Lau 	__u32 map_flags;
2981067cae47SMartin KaFai Lau 	char  name[BPF_OBJ_NAME_LEN];
298252775b33SJakub Kicinski 	__u32 ifindex;
298336f9814aSDaniel Borkmann 	__u32 :32;
298452775b33SJakub Kicinski 	__u64 netns_dev;
298552775b33SJakub Kicinski 	__u64 netns_ino;
298678958fcaSMartin KaFai Lau 	__u32 btf_id;
29879b2cf328SMartin KaFai Lau 	__u32 btf_key_type_id;
29889b2cf328SMartin KaFai Lau 	__u32 btf_value_type_id;
29891e270976SMartin KaFai Lau } __attribute__((aligned(8)));
29901e270976SMartin KaFai Lau 
299162dab84cSMartin KaFai Lau struct bpf_btf_info {
299262dab84cSMartin KaFai Lau 	__aligned_u64 btf;
299362dab84cSMartin KaFai Lau 	__u32 btf_size;
299462dab84cSMartin KaFai Lau 	__u32 id;
299562dab84cSMartin KaFai Lau } __attribute__((aligned(8)));
299662dab84cSMartin KaFai Lau 
29974fbac77dSAndrey Ignatov /* User bpf_sock_addr struct to access socket fields and sockaddr struct passed
29984fbac77dSAndrey Ignatov  * by user and intended to be used by socket (e.g. to bind to, depends on
29994fbac77dSAndrey Ignatov  * attach attach type).
30004fbac77dSAndrey Ignatov  */
30014fbac77dSAndrey Ignatov struct bpf_sock_addr {
30024fbac77dSAndrey Ignatov 	__u32 user_family;	/* Allows 4-byte read, but no write. */
30034fbac77dSAndrey Ignatov 	__u32 user_ip4;		/* Allows 1,2,4-byte read and 4-byte write.
30044fbac77dSAndrey Ignatov 				 * Stored in network byte order.
30054fbac77dSAndrey Ignatov 				 */
30064fbac77dSAndrey Ignatov 	__u32 user_ip6[4];	/* Allows 1,2,4-byte read an 4-byte write.
30074fbac77dSAndrey Ignatov 				 * Stored in network byte order.
30084fbac77dSAndrey Ignatov 				 */
30094fbac77dSAndrey Ignatov 	__u32 user_port;	/* Allows 4-byte read and write.
30104fbac77dSAndrey Ignatov 				 * Stored in network byte order
30114fbac77dSAndrey Ignatov 				 */
30124fbac77dSAndrey Ignatov 	__u32 family;		/* Allows 4-byte read, but no write */
30134fbac77dSAndrey Ignatov 	__u32 type;		/* Allows 4-byte read, but no write */
30144fbac77dSAndrey Ignatov 	__u32 protocol;		/* Allows 4-byte read, but no write */
30151cedee13SAndrey Ignatov 	__u32 msg_src_ip4;	/* Allows 1,2,4-byte read an 4-byte write.
30161cedee13SAndrey Ignatov 				 * Stored in network byte order.
30171cedee13SAndrey Ignatov 				 */
30181cedee13SAndrey Ignatov 	__u32 msg_src_ip6[4];	/* Allows 1,2,4-byte read an 4-byte write.
30191cedee13SAndrey Ignatov 				 * Stored in network byte order.
30201cedee13SAndrey Ignatov 				 */
30214fbac77dSAndrey Ignatov };
30224fbac77dSAndrey Ignatov 
302340304b2aSLawrence Brakmo /* User bpf_sock_ops struct to access socket values and specify request ops
302440304b2aSLawrence Brakmo  * and their replies.
302540304b2aSLawrence Brakmo  * Some of this fields are in network (bigendian) byte order and may need
302640304b2aSLawrence Brakmo  * to be converted before use (bpf_ntohl() defined in samples/bpf/bpf_endian.h).
302740304b2aSLawrence Brakmo  * New fields can only be added at the end of this structure
302840304b2aSLawrence Brakmo  */
302940304b2aSLawrence Brakmo struct bpf_sock_ops {
303040304b2aSLawrence Brakmo 	__u32 op;
303140304b2aSLawrence Brakmo 	union {
3032de525be2SLawrence Brakmo 		__u32 args[4];		/* Optionally passed to bpf program */
3033de525be2SLawrence Brakmo 		__u32 reply;		/* Returned by bpf program	    */
3034de525be2SLawrence Brakmo 		__u32 replylong[4];	/* Optionally returned by bpf prog  */
303540304b2aSLawrence Brakmo 	};
303640304b2aSLawrence Brakmo 	__u32 family;
303740304b2aSLawrence Brakmo 	__u32 remote_ip4;	/* Stored in network byte order */
303840304b2aSLawrence Brakmo 	__u32 local_ip4;	/* Stored in network byte order */
303940304b2aSLawrence Brakmo 	__u32 remote_ip6[4];	/* Stored in network byte order */
304040304b2aSLawrence Brakmo 	__u32 local_ip6[4];	/* Stored in network byte order */
304140304b2aSLawrence Brakmo 	__u32 remote_port;	/* Stored in network byte order */
304240304b2aSLawrence Brakmo 	__u32 local_port;	/* stored in host byte order */
3043f19397a5SLawrence Brakmo 	__u32 is_fullsock;	/* Some TCP fields are only valid if
3044f19397a5SLawrence Brakmo 				 * there is a full socket. If not, the
3045f19397a5SLawrence Brakmo 				 * fields read as zero.
3046f19397a5SLawrence Brakmo 				 */
3047f19397a5SLawrence Brakmo 	__u32 snd_cwnd;
3048f19397a5SLawrence Brakmo 	__u32 srtt_us;		/* Averaged RTT << 3 in usecs */
3049b13d8807SLawrence Brakmo 	__u32 bpf_sock_ops_cb_flags; /* flags defined in uapi/linux/tcp.h */
305044f0e430SLawrence Brakmo 	__u32 state;
305144f0e430SLawrence Brakmo 	__u32 rtt_min;
305244f0e430SLawrence Brakmo 	__u32 snd_ssthresh;
305344f0e430SLawrence Brakmo 	__u32 rcv_nxt;
305444f0e430SLawrence Brakmo 	__u32 snd_nxt;
305544f0e430SLawrence Brakmo 	__u32 snd_una;
305644f0e430SLawrence Brakmo 	__u32 mss_cache;
305744f0e430SLawrence Brakmo 	__u32 ecn_flags;
305844f0e430SLawrence Brakmo 	__u32 rate_delivered;
305944f0e430SLawrence Brakmo 	__u32 rate_interval_us;
306044f0e430SLawrence Brakmo 	__u32 packets_out;
306144f0e430SLawrence Brakmo 	__u32 retrans_out;
306244f0e430SLawrence Brakmo 	__u32 total_retrans;
306344f0e430SLawrence Brakmo 	__u32 segs_in;
306444f0e430SLawrence Brakmo 	__u32 data_segs_in;
306544f0e430SLawrence Brakmo 	__u32 segs_out;
306644f0e430SLawrence Brakmo 	__u32 data_segs_out;
306744f0e430SLawrence Brakmo 	__u32 lost_out;
306844f0e430SLawrence Brakmo 	__u32 sacked_out;
306944f0e430SLawrence Brakmo 	__u32 sk_txhash;
307044f0e430SLawrence Brakmo 	__u64 bytes_received;
307144f0e430SLawrence Brakmo 	__u64 bytes_acked;
307240304b2aSLawrence Brakmo };
307340304b2aSLawrence Brakmo 
3074b13d8807SLawrence Brakmo /* Definitions for bpf_sock_ops_cb_flags */
3075f89013f6SLawrence Brakmo #define BPF_SOCK_OPS_RTO_CB_FLAG	(1<<0)
3076a31ad29eSLawrence Brakmo #define BPF_SOCK_OPS_RETRANS_CB_FLAG	(1<<1)
3077d4487491SLawrence Brakmo #define BPF_SOCK_OPS_STATE_CB_FLAG	(1<<2)
3078d4487491SLawrence Brakmo #define BPF_SOCK_OPS_ALL_CB_FLAGS       0x7		/* Mask of all currently
3079b13d8807SLawrence Brakmo 							 * supported cb flags
3080b13d8807SLawrence Brakmo 							 */
3081b13d8807SLawrence Brakmo 
308240304b2aSLawrence Brakmo /* List of known BPF sock_ops operators.
308340304b2aSLawrence Brakmo  * New entries can only be added at the end
308440304b2aSLawrence Brakmo  */
308540304b2aSLawrence Brakmo enum {
308640304b2aSLawrence Brakmo 	BPF_SOCK_OPS_VOID,
30878550f328SLawrence Brakmo 	BPF_SOCK_OPS_TIMEOUT_INIT,	/* Should return SYN-RTO value to use or
30888550f328SLawrence Brakmo 					 * -1 if default value should be used
30898550f328SLawrence Brakmo 					 */
309013d3b1ebSLawrence Brakmo 	BPF_SOCK_OPS_RWND_INIT,		/* Should return initial advertized
309113d3b1ebSLawrence Brakmo 					 * window (in packets) or -1 if default
309213d3b1ebSLawrence Brakmo 					 * value should be used
309313d3b1ebSLawrence Brakmo 					 */
30949872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_TCP_CONNECT_CB,	/* Calls BPF program right before an
30959872a4bdSLawrence Brakmo 					 * active connection is initialized
30969872a4bdSLawrence Brakmo 					 */
30979872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB,	/* Calls BPF program when an
30989872a4bdSLawrence Brakmo 						 * active connection is
30999872a4bdSLawrence Brakmo 						 * established
31009872a4bdSLawrence Brakmo 						 */
31019872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB,	/* Calls BPF program when a
31029872a4bdSLawrence Brakmo 						 * passive connection is
31039872a4bdSLawrence Brakmo 						 * established
31049872a4bdSLawrence Brakmo 						 */
310591b5b21cSLawrence Brakmo 	BPF_SOCK_OPS_NEEDS_ECN,		/* If connection's congestion control
310691b5b21cSLawrence Brakmo 					 * needs ECN
310791b5b21cSLawrence Brakmo 					 */
3108e6546ef6SLawrence Brakmo 	BPF_SOCK_OPS_BASE_RTT,		/* Get base RTT. The correct value is
3109e6546ef6SLawrence Brakmo 					 * based on the path and may be
3110e6546ef6SLawrence Brakmo 					 * dependent on the congestion control
3111e6546ef6SLawrence Brakmo 					 * algorithm. In general it indicates
3112e6546ef6SLawrence Brakmo 					 * a congestion threshold. RTTs above
3113e6546ef6SLawrence Brakmo 					 * this indicate congestion
3114e6546ef6SLawrence Brakmo 					 */
3115f89013f6SLawrence Brakmo 	BPF_SOCK_OPS_RTO_CB,		/* Called when an RTO has triggered.
3116f89013f6SLawrence Brakmo 					 * Arg1: value of icsk_retransmits
3117f89013f6SLawrence Brakmo 					 * Arg2: value of icsk_rto
3118f89013f6SLawrence Brakmo 					 * Arg3: whether RTO has expired
3119f89013f6SLawrence Brakmo 					 */
3120a31ad29eSLawrence Brakmo 	BPF_SOCK_OPS_RETRANS_CB,	/* Called when skb is retransmitted.
3121a31ad29eSLawrence Brakmo 					 * Arg1: sequence number of 1st byte
3122a31ad29eSLawrence Brakmo 					 * Arg2: # segments
3123a31ad29eSLawrence Brakmo 					 * Arg3: return value of
3124a31ad29eSLawrence Brakmo 					 *       tcp_transmit_skb (0 => success)
3125a31ad29eSLawrence Brakmo 					 */
3126d4487491SLawrence Brakmo 	BPF_SOCK_OPS_STATE_CB,		/* Called when TCP changes state.
3127d4487491SLawrence Brakmo 					 * Arg1: old_state
3128d4487491SLawrence Brakmo 					 * Arg2: new_state
3129d4487491SLawrence Brakmo 					 */
3130f333ee0cSAndrey Ignatov 	BPF_SOCK_OPS_TCP_LISTEN_CB,	/* Called on listen(2), right after
3131f333ee0cSAndrey Ignatov 					 * socket transition to LISTEN state.
3132f333ee0cSAndrey Ignatov 					 */
3133d4487491SLawrence Brakmo };
3134d4487491SLawrence Brakmo 
3135d4487491SLawrence Brakmo /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
3136d4487491SLawrence Brakmo  * changes between the TCP and BPF versions. Ideally this should never happen.
3137d4487491SLawrence Brakmo  * If it does, we need to add code to convert them before calling
3138d4487491SLawrence Brakmo  * the BPF sock_ops function.
3139d4487491SLawrence Brakmo  */
3140d4487491SLawrence Brakmo enum {
3141d4487491SLawrence Brakmo 	BPF_TCP_ESTABLISHED = 1,
3142d4487491SLawrence Brakmo 	BPF_TCP_SYN_SENT,
3143d4487491SLawrence Brakmo 	BPF_TCP_SYN_RECV,
3144d4487491SLawrence Brakmo 	BPF_TCP_FIN_WAIT1,
3145d4487491SLawrence Brakmo 	BPF_TCP_FIN_WAIT2,
3146d4487491SLawrence Brakmo 	BPF_TCP_TIME_WAIT,
3147d4487491SLawrence Brakmo 	BPF_TCP_CLOSE,
3148d4487491SLawrence Brakmo 	BPF_TCP_CLOSE_WAIT,
3149d4487491SLawrence Brakmo 	BPF_TCP_LAST_ACK,
3150d4487491SLawrence Brakmo 	BPF_TCP_LISTEN,
3151d4487491SLawrence Brakmo 	BPF_TCP_CLOSING,	/* Now a valid state */
3152d4487491SLawrence Brakmo 	BPF_TCP_NEW_SYN_RECV,
3153d4487491SLawrence Brakmo 
3154d4487491SLawrence Brakmo 	BPF_TCP_MAX_STATES	/* Leave at the end! */
315540304b2aSLawrence Brakmo };
315640304b2aSLawrence Brakmo 
3157fc747810SLawrence Brakmo #define TCP_BPF_IW		1001	/* Set TCP initial congestion window */
315813bf9641SLawrence Brakmo #define TCP_BPF_SNDCWND_CLAMP	1002	/* Set sndcwnd_clamp */
3159fc747810SLawrence Brakmo 
3160908432caSYonghong Song struct bpf_perf_event_value {
3161908432caSYonghong Song 	__u64 counter;
3162908432caSYonghong Song 	__u64 enabled;
3163908432caSYonghong Song 	__u64 running;
3164908432caSYonghong Song };
3165908432caSYonghong Song 
3166ebc614f6SRoman Gushchin #define BPF_DEVCG_ACC_MKNOD	(1ULL << 0)
3167ebc614f6SRoman Gushchin #define BPF_DEVCG_ACC_READ	(1ULL << 1)
3168ebc614f6SRoman Gushchin #define BPF_DEVCG_ACC_WRITE	(1ULL << 2)
3169ebc614f6SRoman Gushchin 
3170ebc614f6SRoman Gushchin #define BPF_DEVCG_DEV_BLOCK	(1ULL << 0)
3171ebc614f6SRoman Gushchin #define BPF_DEVCG_DEV_CHAR	(1ULL << 1)
3172ebc614f6SRoman Gushchin 
3173ebc614f6SRoman Gushchin struct bpf_cgroup_dev_ctx {
317406ef0ccbSYonghong Song 	/* access_type encoded as (BPF_DEVCG_ACC_* << 16) | BPF_DEVCG_DEV_* */
317506ef0ccbSYonghong Song 	__u32 access_type;
3176ebc614f6SRoman Gushchin 	__u32 major;
3177ebc614f6SRoman Gushchin 	__u32 minor;
3178ebc614f6SRoman Gushchin };
3179ebc614f6SRoman Gushchin 
3180c4f6699dSAlexei Starovoitov struct bpf_raw_tracepoint_args {
3181c4f6699dSAlexei Starovoitov 	__u64 args[0];
3182c4f6699dSAlexei Starovoitov };
3183c4f6699dSAlexei Starovoitov 
318487f5fc7eSDavid Ahern /* DIRECT:  Skip the FIB rules and go to FIB table associated with device
318587f5fc7eSDavid Ahern  * OUTPUT:  Do lookup from egress perspective; default is ingress
318687f5fc7eSDavid Ahern  */
318787f5fc7eSDavid Ahern #define BPF_FIB_LOOKUP_DIRECT  BIT(0)
318887f5fc7eSDavid Ahern #define BPF_FIB_LOOKUP_OUTPUT  BIT(1)
318987f5fc7eSDavid Ahern 
31904c79579bSDavid Ahern enum {
31914c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_SUCCESS,      /* lookup successful */
31924c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_BLACKHOLE,    /* dest is blackholed; can be dropped */
31934c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_UNREACHABLE,  /* dest is unreachable; can be dropped */
31944c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_PROHIBIT,     /* dest not allowed; can be dropped */
31954c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_NOT_FWDED,    /* packet is not forwarded */
31964c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_FWD_DISABLED, /* fwding is not enabled on ingress */
31974c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_UNSUPP_LWT,   /* fwd requires encapsulation */
31984c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_NO_NEIGH,     /* no neighbor entry for nh */
31994c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_FRAG_NEEDED,  /* fragmentation required to fwd */
32004c79579bSDavid Ahern };
32014c79579bSDavid Ahern 
320287f5fc7eSDavid Ahern struct bpf_fib_lookup {
3203fa898d76SDavid Ahern 	/* input:  network family for lookup (AF_INET, AF_INET6)
3204fa898d76SDavid Ahern 	 * output: network family of egress nexthop
3205fa898d76SDavid Ahern 	 */
3206fa898d76SDavid Ahern 	__u8	family;
320787f5fc7eSDavid Ahern 
320887f5fc7eSDavid Ahern 	/* set if lookup is to consider L4 data - e.g., FIB rules */
320987f5fc7eSDavid Ahern 	__u8	l4_protocol;
321087f5fc7eSDavid Ahern 	__be16	sport;
321187f5fc7eSDavid Ahern 	__be16	dport;
321287f5fc7eSDavid Ahern 
321387f5fc7eSDavid Ahern 	/* total length of packet from network header - used for MTU check */
321487f5fc7eSDavid Ahern 	__u16	tot_len;
32154c79579bSDavid Ahern 
32164c79579bSDavid Ahern 	/* input: L3 device index for lookup
32174c79579bSDavid Ahern 	 * output: device index from FIB lookup
32184c79579bSDavid Ahern 	 */
32194c79579bSDavid Ahern 	__u32	ifindex;
322087f5fc7eSDavid Ahern 
322187f5fc7eSDavid Ahern 	union {
322287f5fc7eSDavid Ahern 		/* inputs to lookup */
322387f5fc7eSDavid Ahern 		__u8	tos;		/* AF_INET  */
3224bd3a08aaSDavid Ahern 		__be32	flowinfo;	/* AF_INET6, flow_label + priority */
322587f5fc7eSDavid Ahern 
3226fa898d76SDavid Ahern 		/* output: metric of fib result (IPv4/IPv6 only) */
322787f5fc7eSDavid Ahern 		__u32	rt_metric;
322887f5fc7eSDavid Ahern 	};
322987f5fc7eSDavid Ahern 
323087f5fc7eSDavid Ahern 	union {
323187f5fc7eSDavid Ahern 		__be32		ipv4_src;
323287f5fc7eSDavid Ahern 		__u32		ipv6_src[4];  /* in6_addr; network order */
323387f5fc7eSDavid Ahern 	};
323487f5fc7eSDavid Ahern 
3235fa898d76SDavid Ahern 	/* input to bpf_fib_lookup, ipv{4,6}_dst is destination address in
3236fa898d76SDavid Ahern 	 * network header. output: bpf_fib_lookup sets to gateway address
3237fa898d76SDavid Ahern 	 * if FIB lookup returns gateway route
323887f5fc7eSDavid Ahern 	 */
323987f5fc7eSDavid Ahern 	union {
324087f5fc7eSDavid Ahern 		__be32		ipv4_dst;
324187f5fc7eSDavid Ahern 		__u32		ipv6_dst[4];  /* in6_addr; network order */
324287f5fc7eSDavid Ahern 	};
324387f5fc7eSDavid Ahern 
324487f5fc7eSDavid Ahern 	/* output */
324587f5fc7eSDavid Ahern 	__be16	h_vlan_proto;
324687f5fc7eSDavid Ahern 	__be16	h_vlan_TCI;
324787f5fc7eSDavid Ahern 	__u8	smac[6];     /* ETH_ALEN */
324887f5fc7eSDavid Ahern 	__u8	dmac[6];     /* ETH_ALEN */
324987f5fc7eSDavid Ahern };
325087f5fc7eSDavid Ahern 
325141bdc4b4SYonghong Song enum bpf_task_fd_type {
325241bdc4b4SYonghong Song 	BPF_FD_TYPE_RAW_TRACEPOINT,	/* tp name */
325341bdc4b4SYonghong Song 	BPF_FD_TYPE_TRACEPOINT,		/* tp name */
325441bdc4b4SYonghong Song 	BPF_FD_TYPE_KPROBE,		/* (symbol + offset) or addr */
325541bdc4b4SYonghong Song 	BPF_FD_TYPE_KRETPROBE,		/* (symbol + offset) or addr */
325641bdc4b4SYonghong Song 	BPF_FD_TYPE_UPROBE,		/* filename + offset */
325741bdc4b4SYonghong Song 	BPF_FD_TYPE_URETPROBE,		/* filename + offset */
325841bdc4b4SYonghong Song };
325941bdc4b4SYonghong Song 
3260d58e468bSPetar Penkov struct bpf_flow_keys {
3261d58e468bSPetar Penkov 	__u16	nhoff;
3262d58e468bSPetar Penkov 	__u16	thoff;
3263d58e468bSPetar Penkov 	__u16	addr_proto;			/* ETH_P_* of valid addrs */
3264d58e468bSPetar Penkov 	__u8	is_frag;
3265d58e468bSPetar Penkov 	__u8	is_first_frag;
3266d58e468bSPetar Penkov 	__u8	is_encap;
3267d58e468bSPetar Penkov 	__u8	ip_proto;
3268d58e468bSPetar Penkov 	__be16	n_proto;
3269d58e468bSPetar Penkov 	__be16	sport;
3270d58e468bSPetar Penkov 	__be16	dport;
3271d58e468bSPetar Penkov 	union {
3272d58e468bSPetar Penkov 		struct {
3273d58e468bSPetar Penkov 			__be32	ipv4_src;
3274d58e468bSPetar Penkov 			__be32	ipv4_dst;
3275d58e468bSPetar Penkov 		};
3276d58e468bSPetar Penkov 		struct {
3277d58e468bSPetar Penkov 			__u32	ipv6_src[4];	/* in6_addr; network order */
3278d58e468bSPetar Penkov 			__u32	ipv6_dst[4];	/* in6_addr; network order */
3279d58e468bSPetar Penkov 		};
3280d58e468bSPetar Penkov 	};
3281d58e468bSPetar Penkov };
3282d58e468bSPetar Penkov 
3283838e9690SYonghong Song struct bpf_func_info {
3284d30d42e0SMartin KaFai Lau 	__u32	insn_off;
3285838e9690SYonghong Song 	__u32	type_id;
3286838e9690SYonghong Song };
3287838e9690SYonghong Song 
3288c454a46bSMartin KaFai Lau #define BPF_LINE_INFO_LINE_NUM(line_col)	((line_col) >> 10)
3289c454a46bSMartin KaFai Lau #define BPF_LINE_INFO_LINE_COL(line_col)	((line_col) & 0x3ff)
3290c454a46bSMartin KaFai Lau 
3291c454a46bSMartin KaFai Lau struct bpf_line_info {
3292c454a46bSMartin KaFai Lau 	__u32	insn_off;
3293c454a46bSMartin KaFai Lau 	__u32	file_name_off;
3294c454a46bSMartin KaFai Lau 	__u32	line_off;
3295c454a46bSMartin KaFai Lau 	__u32	line_col;
3296c454a46bSMartin KaFai Lau };
3297c454a46bSMartin KaFai Lau 
3298d83525caSAlexei Starovoitov struct bpf_spin_lock {
3299d83525caSAlexei Starovoitov 	__u32	val;
3300d83525caSAlexei Starovoitov };
3301daedfb22SAlexei Starovoitov #endif /* _UAPI__LINUX_BPF_H__ */
3302