xref: /linux/include/uapi/linux/bpf.h (revision f333ee0cdb27ba201e6cc0c99c76b1364aa29b86)
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 */
17daedfb22SAlexei Starovoitov #define BPF_ALU64	0x07	/* alu mode in double word width */
18daedfb22SAlexei Starovoitov 
19daedfb22SAlexei Starovoitov /* ld/ldx fields */
20cb5f7334SJesper Dangaard Brouer #define BPF_DW		0x18	/* double word (64-bit) */
21daedfb22SAlexei Starovoitov #define BPF_XADD	0xc0	/* exclusive add */
22daedfb22SAlexei Starovoitov 
23daedfb22SAlexei Starovoitov /* alu/jmp fields */
24daedfb22SAlexei Starovoitov #define BPF_MOV		0xb0	/* mov reg to reg */
25daedfb22SAlexei Starovoitov #define BPF_ARSH	0xc0	/* sign extending arithmetic shift right */
26daedfb22SAlexei Starovoitov 
27daedfb22SAlexei Starovoitov /* change endianness of a register */
28daedfb22SAlexei Starovoitov #define BPF_END		0xd0	/* flags for endianness conversion: */
29daedfb22SAlexei Starovoitov #define BPF_TO_LE	0x00	/* convert to little-endian */
30daedfb22SAlexei Starovoitov #define BPF_TO_BE	0x08	/* convert to big-endian */
31daedfb22SAlexei Starovoitov #define BPF_FROM_LE	BPF_TO_LE
32daedfb22SAlexei Starovoitov #define BPF_FROM_BE	BPF_TO_BE
33daedfb22SAlexei Starovoitov 
3492b31a9aSDaniel Borkmann /* jmp encodings */
35daedfb22SAlexei Starovoitov #define BPF_JNE		0x50	/* jump != */
3692b31a9aSDaniel Borkmann #define BPF_JLT		0xa0	/* LT is unsigned, '<' */
3792b31a9aSDaniel Borkmann #define BPF_JLE		0xb0	/* LE is unsigned, '<=' */
38daedfb22SAlexei Starovoitov #define BPF_JSGT	0x60	/* SGT is signed '>', GT in x86 */
39daedfb22SAlexei Starovoitov #define BPF_JSGE	0x70	/* SGE is signed '>=', GE in x86 */
4092b31a9aSDaniel Borkmann #define BPF_JSLT	0xc0	/* SLT is signed, '<' */
4192b31a9aSDaniel Borkmann #define BPF_JSLE	0xd0	/* SLE is signed, '<=' */
42daedfb22SAlexei Starovoitov #define BPF_CALL	0x80	/* function call */
43daedfb22SAlexei Starovoitov #define BPF_EXIT	0x90	/* function return */
44daedfb22SAlexei Starovoitov 
45daedfb22SAlexei Starovoitov /* Register numbers */
46daedfb22SAlexei Starovoitov enum {
47daedfb22SAlexei Starovoitov 	BPF_REG_0 = 0,
48daedfb22SAlexei Starovoitov 	BPF_REG_1,
49daedfb22SAlexei Starovoitov 	BPF_REG_2,
50daedfb22SAlexei Starovoitov 	BPF_REG_3,
51daedfb22SAlexei Starovoitov 	BPF_REG_4,
52daedfb22SAlexei Starovoitov 	BPF_REG_5,
53daedfb22SAlexei Starovoitov 	BPF_REG_6,
54daedfb22SAlexei Starovoitov 	BPF_REG_7,
55daedfb22SAlexei Starovoitov 	BPF_REG_8,
56daedfb22SAlexei Starovoitov 	BPF_REG_9,
57daedfb22SAlexei Starovoitov 	BPF_REG_10,
58daedfb22SAlexei Starovoitov 	__MAX_BPF_REG,
59daedfb22SAlexei Starovoitov };
60daedfb22SAlexei Starovoitov 
61daedfb22SAlexei Starovoitov /* BPF has 10 general purpose 64-bit registers and stack frame. */
62daedfb22SAlexei Starovoitov #define MAX_BPF_REG	__MAX_BPF_REG
63daedfb22SAlexei Starovoitov 
64daedfb22SAlexei Starovoitov struct bpf_insn {
65daedfb22SAlexei Starovoitov 	__u8	code;		/* opcode */
66daedfb22SAlexei Starovoitov 	__u8	dst_reg:4;	/* dest register */
67daedfb22SAlexei Starovoitov 	__u8	src_reg:4;	/* source register */
68daedfb22SAlexei Starovoitov 	__s16	off;		/* signed offset */
69daedfb22SAlexei Starovoitov 	__s32	imm;		/* signed immediate constant */
70daedfb22SAlexei Starovoitov };
71daedfb22SAlexei Starovoitov 
72b95a5c4dSDaniel Mack /* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */
73b95a5c4dSDaniel Mack struct bpf_lpm_trie_key {
74b95a5c4dSDaniel Mack 	__u32	prefixlen;	/* up to 32 for AF_INET, 128 for AF_INET6 */
75b95a5c4dSDaniel Mack 	__u8	data[0];	/* Arbitrary size */
76b95a5c4dSDaniel Mack };
77b95a5c4dSDaniel Mack 
78b2197755SDaniel Borkmann /* BPF syscall commands, see bpf(2) man-page for details. */
7999c55f7dSAlexei Starovoitov enum bpf_cmd {
8099c55f7dSAlexei Starovoitov 	BPF_MAP_CREATE,
81db20fd2bSAlexei Starovoitov 	BPF_MAP_LOOKUP_ELEM,
82db20fd2bSAlexei Starovoitov 	BPF_MAP_UPDATE_ELEM,
83db20fd2bSAlexei Starovoitov 	BPF_MAP_DELETE_ELEM,
84db20fd2bSAlexei Starovoitov 	BPF_MAP_GET_NEXT_KEY,
8509756af4SAlexei Starovoitov 	BPF_PROG_LOAD,
86b2197755SDaniel Borkmann 	BPF_OBJ_PIN,
87b2197755SDaniel Borkmann 	BPF_OBJ_GET,
88f4324551SDaniel Mack 	BPF_PROG_ATTACH,
89f4324551SDaniel Mack 	BPF_PROG_DETACH,
901cf1cae9SAlexei Starovoitov 	BPF_PROG_TEST_RUN,
9134ad5580SMartin KaFai Lau 	BPF_PROG_GET_NEXT_ID,
9234ad5580SMartin KaFai Lau 	BPF_MAP_GET_NEXT_ID,
93b16d9aa4SMartin KaFai Lau 	BPF_PROG_GET_FD_BY_ID,
94bd5f5f4eSMartin KaFai Lau 	BPF_MAP_GET_FD_BY_ID,
951e270976SMartin KaFai Lau 	BPF_OBJ_GET_INFO_BY_FD,
96468e2f64SAlexei Starovoitov 	BPF_PROG_QUERY,
97c4f6699dSAlexei Starovoitov 	BPF_RAW_TRACEPOINT_OPEN,
98f56a653cSMartin KaFai Lau 	BPF_BTF_LOAD,
9978958fcaSMartin KaFai Lau 	BPF_BTF_GET_FD_BY_ID,
10041bdc4b4SYonghong Song 	BPF_TASK_FD_QUERY,
10199c55f7dSAlexei Starovoitov };
10299c55f7dSAlexei Starovoitov 
10399c55f7dSAlexei Starovoitov enum bpf_map_type {
10499c55f7dSAlexei Starovoitov 	BPF_MAP_TYPE_UNSPEC,
1050f8e4bd8SAlexei Starovoitov 	BPF_MAP_TYPE_HASH,
10628fbcfa0SAlexei Starovoitov 	BPF_MAP_TYPE_ARRAY,
10704fd61abSAlexei Starovoitov 	BPF_MAP_TYPE_PROG_ARRAY,
108ea317b26SKaixu Xia 	BPF_MAP_TYPE_PERF_EVENT_ARRAY,
109824bd0ceSAlexei Starovoitov 	BPF_MAP_TYPE_PERCPU_HASH,
110a10423b8SAlexei Starovoitov 	BPF_MAP_TYPE_PERCPU_ARRAY,
111d5a3b1f6SAlexei Starovoitov 	BPF_MAP_TYPE_STACK_TRACE,
1124ed8ec52SMartin KaFai Lau 	BPF_MAP_TYPE_CGROUP_ARRAY,
11329ba732aSMartin KaFai Lau 	BPF_MAP_TYPE_LRU_HASH,
1148f844938SMartin KaFai Lau 	BPF_MAP_TYPE_LRU_PERCPU_HASH,
115b95a5c4dSDaniel Mack 	BPF_MAP_TYPE_LPM_TRIE,
11656f668dfSMartin KaFai Lau 	BPF_MAP_TYPE_ARRAY_OF_MAPS,
117bcc6b1b7SMartin KaFai Lau 	BPF_MAP_TYPE_HASH_OF_MAPS,
118546ac1ffSJohn Fastabend 	BPF_MAP_TYPE_DEVMAP,
119174a79ffSJohn Fastabend 	BPF_MAP_TYPE_SOCKMAP,
1206710e112SJesper Dangaard Brouer 	BPF_MAP_TYPE_CPUMAP,
121fbfc504aSBjörn Töpel 	BPF_MAP_TYPE_XSKMAP,
12281110384SJohn Fastabend 	BPF_MAP_TYPE_SOCKHASH,
12399c55f7dSAlexei Starovoitov };
12499c55f7dSAlexei Starovoitov 
12509756af4SAlexei Starovoitov enum bpf_prog_type {
12609756af4SAlexei Starovoitov 	BPF_PROG_TYPE_UNSPEC,
127ddd872bcSAlexei Starovoitov 	BPF_PROG_TYPE_SOCKET_FILTER,
1282541517cSAlexei Starovoitov 	BPF_PROG_TYPE_KPROBE,
12996be4325SDaniel Borkmann 	BPF_PROG_TYPE_SCHED_CLS,
13094caee8cSDaniel Borkmann 	BPF_PROG_TYPE_SCHED_ACT,
13198b5c2c6SAlexei Starovoitov 	BPF_PROG_TYPE_TRACEPOINT,
1326a773a15SBrenden Blanco 	BPF_PROG_TYPE_XDP,
1330515e599SAlexei Starovoitov 	BPF_PROG_TYPE_PERF_EVENT,
1340e33661dSDaniel Mack 	BPF_PROG_TYPE_CGROUP_SKB,
13561023658SDavid Ahern 	BPF_PROG_TYPE_CGROUP_SOCK,
1363a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_IN,
1373a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_OUT,
1383a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_XMIT,
13940304b2aSLawrence Brakmo 	BPF_PROG_TYPE_SOCK_OPS,
140b005fd18SJohn Fastabend 	BPF_PROG_TYPE_SK_SKB,
141ebc614f6SRoman Gushchin 	BPF_PROG_TYPE_CGROUP_DEVICE,
1424f738adbSJohn Fastabend 	BPF_PROG_TYPE_SK_MSG,
143c4f6699dSAlexei Starovoitov 	BPF_PROG_TYPE_RAW_TRACEPOINT,
1444fbac77dSAndrey Ignatov 	BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
145004d4b27SMathieu Xhonneux 	BPF_PROG_TYPE_LWT_SEG6LOCAL,
146f4364dcfSSean Young 	BPF_PROG_TYPE_LIRC_MODE2,
14709756af4SAlexei Starovoitov };
14809756af4SAlexei Starovoitov 
1490e33661dSDaniel Mack enum bpf_attach_type {
1500e33661dSDaniel Mack 	BPF_CGROUP_INET_INGRESS,
1510e33661dSDaniel Mack 	BPF_CGROUP_INET_EGRESS,
15261023658SDavid Ahern 	BPF_CGROUP_INET_SOCK_CREATE,
15340304b2aSLawrence Brakmo 	BPF_CGROUP_SOCK_OPS,
154464bc0fdSJohn Fastabend 	BPF_SK_SKB_STREAM_PARSER,
155464bc0fdSJohn Fastabend 	BPF_SK_SKB_STREAM_VERDICT,
156ebc614f6SRoman Gushchin 	BPF_CGROUP_DEVICE,
1574f738adbSJohn Fastabend 	BPF_SK_MSG_VERDICT,
1584fbac77dSAndrey Ignatov 	BPF_CGROUP_INET4_BIND,
1594fbac77dSAndrey Ignatov 	BPF_CGROUP_INET6_BIND,
160d74bad4eSAndrey Ignatov 	BPF_CGROUP_INET4_CONNECT,
161d74bad4eSAndrey Ignatov 	BPF_CGROUP_INET6_CONNECT,
162aac3fc32SAndrey Ignatov 	BPF_CGROUP_INET4_POST_BIND,
163aac3fc32SAndrey Ignatov 	BPF_CGROUP_INET6_POST_BIND,
1641cedee13SAndrey Ignatov 	BPF_CGROUP_UDP4_SENDMSG,
1651cedee13SAndrey Ignatov 	BPF_CGROUP_UDP6_SENDMSG,
166f4364dcfSSean Young 	BPF_LIRC_MODE2,
1670e33661dSDaniel Mack 	__MAX_BPF_ATTACH_TYPE
1680e33661dSDaniel Mack };
1690e33661dSDaniel Mack 
1700e33661dSDaniel Mack #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
1710e33661dSDaniel Mack 
172324bda9eSAlexei Starovoitov /* cgroup-bpf attach flags used in BPF_PROG_ATTACH command
173324bda9eSAlexei Starovoitov  *
174324bda9eSAlexei Starovoitov  * NONE(default): No further bpf programs allowed in the subtree.
175324bda9eSAlexei Starovoitov  *
176324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_OVERRIDE: If a sub-cgroup installs some bpf program,
177324bda9eSAlexei Starovoitov  * the program in this cgroup yields to sub-cgroup program.
178324bda9eSAlexei Starovoitov  *
179324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_MULTI: If a sub-cgroup installs some bpf program,
180324bda9eSAlexei Starovoitov  * that cgroup program gets run in addition to the program in this cgroup.
181324bda9eSAlexei Starovoitov  *
182324bda9eSAlexei Starovoitov  * Only one program is allowed to be attached to a cgroup with
183324bda9eSAlexei Starovoitov  * NONE or BPF_F_ALLOW_OVERRIDE flag.
184324bda9eSAlexei Starovoitov  * Attaching another program on top of NONE or BPF_F_ALLOW_OVERRIDE will
185324bda9eSAlexei Starovoitov  * release old program and attach the new one. Attach flags has to match.
186324bda9eSAlexei Starovoitov  *
187324bda9eSAlexei Starovoitov  * Multiple programs are allowed to be attached to a cgroup with
188324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_MULTI flag. They are executed in FIFO order
189324bda9eSAlexei Starovoitov  * (those that were attached first, run first)
190324bda9eSAlexei Starovoitov  * The programs of sub-cgroup are executed first, then programs of
191324bda9eSAlexei Starovoitov  * this cgroup and then programs of parent cgroup.
192324bda9eSAlexei Starovoitov  * When children program makes decision (like picking TCP CA or sock bind)
193324bda9eSAlexei Starovoitov  * parent program has a chance to override it.
194324bda9eSAlexei Starovoitov  *
195324bda9eSAlexei Starovoitov  * A cgroup with MULTI or OVERRIDE flag allows any attach flags in sub-cgroups.
196324bda9eSAlexei Starovoitov  * A cgroup with NONE doesn't allow any programs in sub-cgroups.
197324bda9eSAlexei Starovoitov  * Ex1:
198324bda9eSAlexei Starovoitov  * cgrp1 (MULTI progs A, B) ->
199324bda9eSAlexei Starovoitov  *    cgrp2 (OVERRIDE prog C) ->
200324bda9eSAlexei Starovoitov  *      cgrp3 (MULTI prog D) ->
201324bda9eSAlexei Starovoitov  *        cgrp4 (OVERRIDE prog E) ->
202324bda9eSAlexei Starovoitov  *          cgrp5 (NONE prog F)
203324bda9eSAlexei Starovoitov  * the event in cgrp5 triggers execution of F,D,A,B in that order.
204324bda9eSAlexei Starovoitov  * if prog F is detached, the execution is E,D,A,B
205324bda9eSAlexei Starovoitov  * if prog F and D are detached, the execution is E,A,B
206324bda9eSAlexei Starovoitov  * if prog F, E and D are detached, the execution is C,A,B
207324bda9eSAlexei Starovoitov  *
208324bda9eSAlexei Starovoitov  * All eligible programs are executed regardless of return code from
209324bda9eSAlexei Starovoitov  * earlier programs.
2107f677633SAlexei Starovoitov  */
2117f677633SAlexei Starovoitov #define BPF_F_ALLOW_OVERRIDE	(1U << 0)
212324bda9eSAlexei Starovoitov #define BPF_F_ALLOW_MULTI	(1U << 1)
2137f677633SAlexei Starovoitov 
214e07b98d9SDavid S. Miller /* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the
215e07b98d9SDavid S. Miller  * verifier will perform strict alignment checking as if the kernel
216e07b98d9SDavid S. Miller  * has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set,
217e07b98d9SDavid S. Miller  * and NET_IP_ALIGN defined to 2.
218e07b98d9SDavid S. Miller  */
219e07b98d9SDavid S. Miller #define BPF_F_STRICT_ALIGNMENT	(1U << 0)
220e07b98d9SDavid S. Miller 
221cc8b0b92SAlexei Starovoitov /* when bpf_ldimm64->src_reg == BPF_PSEUDO_MAP_FD, bpf_ldimm64->imm == fd */
222f1a66f85SDaniel Borkmann #define BPF_PSEUDO_MAP_FD	1
223f1a66f85SDaniel Borkmann 
224cc8b0b92SAlexei Starovoitov /* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative
225cc8b0b92SAlexei Starovoitov  * offset to another bpf function
226cc8b0b92SAlexei Starovoitov  */
227cc8b0b92SAlexei Starovoitov #define BPF_PSEUDO_CALL		1
228cc8b0b92SAlexei Starovoitov 
2293274f520SAlexei Starovoitov /* flags for BPF_MAP_UPDATE_ELEM command */
2303274f520SAlexei Starovoitov #define BPF_ANY		0 /* create new element or update existing */
2313274f520SAlexei Starovoitov #define BPF_NOEXIST	1 /* create new element if it didn't exist */
2323274f520SAlexei Starovoitov #define BPF_EXIST	2 /* update existing element */
2333274f520SAlexei Starovoitov 
23496eabe7aSMartin KaFai Lau /* flags for BPF_MAP_CREATE command */
2356c905981SAlexei Starovoitov #define BPF_F_NO_PREALLOC	(1U << 0)
23629ba732aSMartin KaFai Lau /* Instead of having one common LRU list in the
2378f844938SMartin KaFai Lau  * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list
23829ba732aSMartin KaFai Lau  * which can scale and perform better.
23929ba732aSMartin KaFai Lau  * Note, the LRU nodes (including free nodes) cannot be moved
24029ba732aSMartin KaFai Lau  * across different LRU lists.
24129ba732aSMartin KaFai Lau  */
24229ba732aSMartin KaFai Lau #define BPF_F_NO_COMMON_LRU	(1U << 1)
24396eabe7aSMartin KaFai Lau /* Specify numa node during map creation */
24496eabe7aSMartin KaFai Lau #define BPF_F_NUMA_NODE		(1U << 2)
2456c905981SAlexei Starovoitov 
246468e2f64SAlexei Starovoitov /* flags for BPF_PROG_QUERY */
247468e2f64SAlexei Starovoitov #define BPF_F_QUERY_EFFECTIVE	(1U << 0)
248468e2f64SAlexei Starovoitov 
249cb4d2b3fSMartin KaFai Lau #define BPF_OBJ_NAME_LEN 16U
250cb4d2b3fSMartin KaFai Lau 
2516e71b04aSChenbo Feng /* Flags for accessing BPF object */
2526e71b04aSChenbo Feng #define BPF_F_RDONLY		(1U << 3)
2536e71b04aSChenbo Feng #define BPF_F_WRONLY		(1U << 4)
2546e71b04aSChenbo Feng 
255615755a7SSong Liu /* Flag for stack_map, store build_id+offset instead of pointer */
256615755a7SSong Liu #define BPF_F_STACK_BUILD_ID	(1U << 5)
257615755a7SSong Liu 
258615755a7SSong Liu enum bpf_stack_build_id_status {
259615755a7SSong Liu 	/* user space need an empty entry to identify end of a trace */
260615755a7SSong Liu 	BPF_STACK_BUILD_ID_EMPTY = 0,
261615755a7SSong Liu 	/* with valid build_id and offset */
262615755a7SSong Liu 	BPF_STACK_BUILD_ID_VALID = 1,
263615755a7SSong Liu 	/* couldn't get build_id, fallback to ip */
264615755a7SSong Liu 	BPF_STACK_BUILD_ID_IP = 2,
265615755a7SSong Liu };
266615755a7SSong Liu 
267615755a7SSong Liu #define BPF_BUILD_ID_SIZE 20
268615755a7SSong Liu struct bpf_stack_build_id {
269615755a7SSong Liu 	__s32		status;
270615755a7SSong Liu 	unsigned char	build_id[BPF_BUILD_ID_SIZE];
271615755a7SSong Liu 	union {
272615755a7SSong Liu 		__u64	offset;
273615755a7SSong Liu 		__u64	ip;
274615755a7SSong Liu 	};
275615755a7SSong Liu };
276615755a7SSong Liu 
27799c55f7dSAlexei Starovoitov union bpf_attr {
27899c55f7dSAlexei Starovoitov 	struct { /* anonymous struct used by BPF_MAP_CREATE command */
27999c55f7dSAlexei Starovoitov 		__u32	map_type;	/* one of enum bpf_map_type */
28099c55f7dSAlexei Starovoitov 		__u32	key_size;	/* size of key in bytes */
28199c55f7dSAlexei Starovoitov 		__u32	value_size;	/* size of value in bytes */
28299c55f7dSAlexei Starovoitov 		__u32	max_entries;	/* max number of entries in a map */
28396eabe7aSMartin KaFai Lau 		__u32	map_flags;	/* BPF_MAP_CREATE related
28496eabe7aSMartin KaFai Lau 					 * flags defined above.
28596eabe7aSMartin KaFai Lau 					 */
28656f668dfSMartin KaFai Lau 		__u32	inner_map_fd;	/* fd pointing to the inner map */
28796eabe7aSMartin KaFai Lau 		__u32	numa_node;	/* numa node (effective only if
28896eabe7aSMartin KaFai Lau 					 * BPF_F_NUMA_NODE is set).
28996eabe7aSMartin KaFai Lau 					 */
290067cae47SMartin KaFai Lau 		char	map_name[BPF_OBJ_NAME_LEN];
291a3884572SJakub Kicinski 		__u32	map_ifindex;	/* ifindex of netdev to create on */
292a26ca7c9SMartin KaFai Lau 		__u32	btf_fd;		/* fd pointing to a BTF type data */
2939b2cf328SMartin KaFai Lau 		__u32	btf_key_type_id;	/* BTF type_id of the key */
2949b2cf328SMartin KaFai Lau 		__u32	btf_value_type_id;	/* BTF type_id of the value */
29599c55f7dSAlexei Starovoitov 	};
296db20fd2bSAlexei Starovoitov 
297db20fd2bSAlexei Starovoitov 	struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
298db20fd2bSAlexei Starovoitov 		__u32		map_fd;
299db20fd2bSAlexei Starovoitov 		__aligned_u64	key;
300db20fd2bSAlexei Starovoitov 		union {
301db20fd2bSAlexei Starovoitov 			__aligned_u64 value;
302db20fd2bSAlexei Starovoitov 			__aligned_u64 next_key;
303db20fd2bSAlexei Starovoitov 		};
3043274f520SAlexei Starovoitov 		__u64		flags;
305db20fd2bSAlexei Starovoitov 	};
30609756af4SAlexei Starovoitov 
30709756af4SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_LOAD command */
30809756af4SAlexei Starovoitov 		__u32		prog_type;	/* one of enum bpf_prog_type */
30909756af4SAlexei Starovoitov 		__u32		insn_cnt;
31009756af4SAlexei Starovoitov 		__aligned_u64	insns;
31109756af4SAlexei Starovoitov 		__aligned_u64	license;
312cbd35700SAlexei Starovoitov 		__u32		log_level;	/* verbosity level of verifier */
313cbd35700SAlexei Starovoitov 		__u32		log_size;	/* size of user buffer */
314cbd35700SAlexei Starovoitov 		__aligned_u64	log_buf;	/* user supplied buffer */
3152541517cSAlexei Starovoitov 		__u32		kern_version;	/* checked when prog_type=kprobe */
316e07b98d9SDavid S. Miller 		__u32		prog_flags;
317067cae47SMartin KaFai Lau 		char		prog_name[BPF_OBJ_NAME_LEN];
3181f6f4cb7SJakub Kicinski 		__u32		prog_ifindex;	/* ifindex of netdev to prep for */
3195e43f899SAndrey Ignatov 		/* For some prog types expected attach type must be known at
3205e43f899SAndrey Ignatov 		 * load time to verify attach type specific parts of prog
3215e43f899SAndrey Ignatov 		 * (context accesses, allowed helpers, etc).
3225e43f899SAndrey Ignatov 		 */
3235e43f899SAndrey Ignatov 		__u32		expected_attach_type;
32409756af4SAlexei Starovoitov 	};
325b2197755SDaniel Borkmann 
326b2197755SDaniel Borkmann 	struct { /* anonymous struct used by BPF_OBJ_* commands */
327b2197755SDaniel Borkmann 		__aligned_u64	pathname;
328b2197755SDaniel Borkmann 		__u32		bpf_fd;
3296e71b04aSChenbo Feng 		__u32		file_flags;
330b2197755SDaniel Borkmann 	};
331f4324551SDaniel Mack 
332f4324551SDaniel Mack 	struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
333f4324551SDaniel Mack 		__u32		target_fd;	/* container object to attach to */
334f4324551SDaniel Mack 		__u32		attach_bpf_fd;	/* eBPF program to attach */
335f4324551SDaniel Mack 		__u32		attach_type;
3367f677633SAlexei Starovoitov 		__u32		attach_flags;
337f4324551SDaniel Mack 	};
3381cf1cae9SAlexei Starovoitov 
3391cf1cae9SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
3401cf1cae9SAlexei Starovoitov 		__u32		prog_fd;
3411cf1cae9SAlexei Starovoitov 		__u32		retval;
3421cf1cae9SAlexei Starovoitov 		__u32		data_size_in;
3431cf1cae9SAlexei Starovoitov 		__u32		data_size_out;
3441cf1cae9SAlexei Starovoitov 		__aligned_u64	data_in;
3451cf1cae9SAlexei Starovoitov 		__aligned_u64	data_out;
3461cf1cae9SAlexei Starovoitov 		__u32		repeat;
3471cf1cae9SAlexei Starovoitov 		__u32		duration;
3481cf1cae9SAlexei Starovoitov 	} test;
34934ad5580SMartin KaFai Lau 
350b16d9aa4SMartin KaFai Lau 	struct { /* anonymous struct used by BPF_*_GET_*_ID */
351b16d9aa4SMartin KaFai Lau 		union {
35234ad5580SMartin KaFai Lau 			__u32		start_id;
353b16d9aa4SMartin KaFai Lau 			__u32		prog_id;
354bd5f5f4eSMartin KaFai Lau 			__u32		map_id;
35578958fcaSMartin KaFai Lau 			__u32		btf_id;
356b16d9aa4SMartin KaFai Lau 		};
35734ad5580SMartin KaFai Lau 		__u32		next_id;
3586e71b04aSChenbo Feng 		__u32		open_flags;
35934ad5580SMartin KaFai Lau 	};
3601e270976SMartin KaFai Lau 
3611e270976SMartin KaFai Lau 	struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
3621e270976SMartin KaFai Lau 		__u32		bpf_fd;
3631e270976SMartin KaFai Lau 		__u32		info_len;
3641e270976SMartin KaFai Lau 		__aligned_u64	info;
3651e270976SMartin KaFai Lau 	} info;
366468e2f64SAlexei Starovoitov 
367468e2f64SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_QUERY command */
368468e2f64SAlexei Starovoitov 		__u32		target_fd;	/* container object to query */
369468e2f64SAlexei Starovoitov 		__u32		attach_type;
370468e2f64SAlexei Starovoitov 		__u32		query_flags;
371468e2f64SAlexei Starovoitov 		__u32		attach_flags;
372468e2f64SAlexei Starovoitov 		__aligned_u64	prog_ids;
373468e2f64SAlexei Starovoitov 		__u32		prog_cnt;
374468e2f64SAlexei Starovoitov 	} query;
375c4f6699dSAlexei Starovoitov 
376c4f6699dSAlexei Starovoitov 	struct {
377c4f6699dSAlexei Starovoitov 		__u64 name;
378c4f6699dSAlexei Starovoitov 		__u32 prog_fd;
379c4f6699dSAlexei Starovoitov 	} raw_tracepoint;
380f56a653cSMartin KaFai Lau 
381f56a653cSMartin KaFai Lau 	struct { /* anonymous struct for BPF_BTF_LOAD */
382f56a653cSMartin KaFai Lau 		__aligned_u64	btf;
383f56a653cSMartin KaFai Lau 		__aligned_u64	btf_log_buf;
384f56a653cSMartin KaFai Lau 		__u32		btf_size;
385f56a653cSMartin KaFai Lau 		__u32		btf_log_size;
386f56a653cSMartin KaFai Lau 		__u32		btf_log_level;
387f56a653cSMartin KaFai Lau 	};
38841bdc4b4SYonghong Song 
38941bdc4b4SYonghong Song 	struct {
39041bdc4b4SYonghong Song 		__u32		pid;		/* input: pid */
39141bdc4b4SYonghong Song 		__u32		fd;		/* input: fd */
39241bdc4b4SYonghong Song 		__u32		flags;		/* input: flags */
39341bdc4b4SYonghong Song 		__u32		buf_len;	/* input/output: buf len */
39441bdc4b4SYonghong Song 		__aligned_u64	buf;		/* input/output:
39541bdc4b4SYonghong Song 						 *   tp_name for tracepoint
39641bdc4b4SYonghong Song 						 *   symbol for kprobe
39741bdc4b4SYonghong Song 						 *   filename for uprobe
39841bdc4b4SYonghong Song 						 */
39941bdc4b4SYonghong Song 		__u32		prog_id;	/* output: prod_id */
40041bdc4b4SYonghong Song 		__u32		fd_type;	/* output: BPF_FD_TYPE_* */
40141bdc4b4SYonghong Song 		__u64		probe_offset;	/* output: probe_offset */
40241bdc4b4SYonghong Song 		__u64		probe_addr;	/* output: probe_addr */
40341bdc4b4SYonghong Song 	} task_fd_query;
40499c55f7dSAlexei Starovoitov } __attribute__((aligned(8)));
40599c55f7dSAlexei Starovoitov 
40656a092c8SQuentin Monnet /* The description below is an attempt at providing documentation to eBPF
40756a092c8SQuentin Monnet  * developers about the multiple available eBPF helper functions. It can be
40856a092c8SQuentin Monnet  * parsed and used to produce a manual page. The workflow is the following,
40956a092c8SQuentin Monnet  * and requires the rst2man utility:
410ebb676daSThomas Graf  *
41156a092c8SQuentin Monnet  *     $ ./scripts/bpf_helpers_doc.py \
41256a092c8SQuentin Monnet  *             --filename include/uapi/linux/bpf.h > /tmp/bpf-helpers.rst
41356a092c8SQuentin Monnet  *     $ rst2man /tmp/bpf-helpers.rst > /tmp/bpf-helpers.7
41456a092c8SQuentin Monnet  *     $ man /tmp/bpf-helpers.7
415ebb676daSThomas Graf  *
41656a092c8SQuentin Monnet  * Note that in order to produce this external documentation, some RST
41756a092c8SQuentin Monnet  * formatting is used in the descriptions to get "bold" and "italics" in
41856a092c8SQuentin Monnet  * manual pages. Also note that the few trailing white spaces are
41956a092c8SQuentin Monnet  * intentional, removing them would break paragraphs for rst2man.
420ebb676daSThomas Graf  *
42156a092c8SQuentin Monnet  * Start of BPF helper function descriptions:
422ad4a5223SQuentin Monnet  *
423ad4a5223SQuentin Monnet  * void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)
424ad4a5223SQuentin Monnet  * 	Description
425ad4a5223SQuentin Monnet  * 		Perform a lookup in *map* for an entry associated to *key*.
426ad4a5223SQuentin Monnet  * 	Return
427ad4a5223SQuentin Monnet  * 		Map value associated to *key*, or **NULL** if no entry was
428ad4a5223SQuentin Monnet  * 		found.
429ad4a5223SQuentin Monnet  *
430ad4a5223SQuentin Monnet  * int bpf_map_update_elem(struct bpf_map *map, const void *key, const void *value, u64 flags)
431ad4a5223SQuentin Monnet  * 	Description
432ad4a5223SQuentin Monnet  * 		Add or update the value of the entry associated to *key* in
433ad4a5223SQuentin Monnet  * 		*map* with *value*. *flags* is one of:
434ad4a5223SQuentin Monnet  *
435ad4a5223SQuentin Monnet  * 		**BPF_NOEXIST**
436ad4a5223SQuentin Monnet  * 			The entry for *key* must not exist in the map.
437ad4a5223SQuentin Monnet  * 		**BPF_EXIST**
438ad4a5223SQuentin Monnet  * 			The entry for *key* must already exist in the map.
439ad4a5223SQuentin Monnet  * 		**BPF_ANY**
440ad4a5223SQuentin Monnet  * 			No condition on the existence of the entry for *key*.
441ad4a5223SQuentin Monnet  *
442ad4a5223SQuentin Monnet  * 		Flag value **BPF_NOEXIST** cannot be used for maps of types
443ad4a5223SQuentin Monnet  * 		**BPF_MAP_TYPE_ARRAY** or **BPF_MAP_TYPE_PERCPU_ARRAY**  (all
444ad4a5223SQuentin Monnet  * 		elements always exist), the helper would return an error.
445ad4a5223SQuentin Monnet  * 	Return
446ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
447ad4a5223SQuentin Monnet  *
448ad4a5223SQuentin Monnet  * int bpf_map_delete_elem(struct bpf_map *map, const void *key)
449ad4a5223SQuentin Monnet  * 	Description
450ad4a5223SQuentin Monnet  * 		Delete entry with *key* from *map*.
451ad4a5223SQuentin Monnet  * 	Return
452ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
453ad4a5223SQuentin Monnet  *
454ad4a5223SQuentin Monnet  * int bpf_probe_read(void *dst, u32 size, const void *src)
455ad4a5223SQuentin Monnet  * 	Description
456ad4a5223SQuentin Monnet  * 		For tracing programs, safely attempt to read *size* bytes from
457ad4a5223SQuentin Monnet  * 		address *src* and store the data in *dst*.
458ad4a5223SQuentin Monnet  * 	Return
459ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
460ad4a5223SQuentin Monnet  *
461ad4a5223SQuentin Monnet  * u64 bpf_ktime_get_ns(void)
462ad4a5223SQuentin Monnet  * 	Description
463ad4a5223SQuentin Monnet  * 		Return the time elapsed since system boot, in nanoseconds.
464ad4a5223SQuentin Monnet  * 	Return
465ad4a5223SQuentin Monnet  * 		Current *ktime*.
466ad4a5223SQuentin Monnet  *
467ad4a5223SQuentin Monnet  * int bpf_trace_printk(const char *fmt, u32 fmt_size, ...)
468ad4a5223SQuentin Monnet  * 	Description
469ad4a5223SQuentin Monnet  * 		This helper is a "printk()-like" facility for debugging. It
470ad4a5223SQuentin Monnet  * 		prints a message defined by format *fmt* (of size *fmt_size*)
471ad4a5223SQuentin Monnet  * 		to file *\/sys/kernel/debug/tracing/trace* from DebugFS, if
472ad4a5223SQuentin Monnet  * 		available. It can take up to three additional **u64**
473ad4a5223SQuentin Monnet  * 		arguments (as an eBPF helpers, the total number of arguments is
474ad4a5223SQuentin Monnet  * 		limited to five).
475ad4a5223SQuentin Monnet  *
476ad4a5223SQuentin Monnet  * 		Each time the helper is called, it appends a line to the trace.
477ad4a5223SQuentin Monnet  * 		The format of the trace is customizable, and the exact output
478ad4a5223SQuentin Monnet  * 		one will get depends on the options set in
479ad4a5223SQuentin Monnet  * 		*\/sys/kernel/debug/tracing/trace_options* (see also the
480ad4a5223SQuentin Monnet  * 		*README* file under the same directory). However, it usually
481ad4a5223SQuentin Monnet  * 		defaults to something like:
482ad4a5223SQuentin Monnet  *
483ad4a5223SQuentin Monnet  * 		::
484ad4a5223SQuentin Monnet  *
485ad4a5223SQuentin Monnet  * 			telnet-470   [001] .N.. 419421.045894: 0x00000001: <formatted msg>
486ad4a5223SQuentin Monnet  *
487ad4a5223SQuentin Monnet  * 		In the above:
488ad4a5223SQuentin Monnet  *
489ad4a5223SQuentin Monnet  * 			* ``telnet`` is the name of the current task.
490ad4a5223SQuentin Monnet  * 			* ``470`` is the PID of the current task.
491ad4a5223SQuentin Monnet  * 			* ``001`` is the CPU number on which the task is
492ad4a5223SQuentin Monnet  * 			  running.
493ad4a5223SQuentin Monnet  * 			* In ``.N..``, each character refers to a set of
494ad4a5223SQuentin Monnet  * 			  options (whether irqs are enabled, scheduling
495ad4a5223SQuentin Monnet  * 			  options, whether hard/softirqs are running, level of
496ad4a5223SQuentin Monnet  * 			  preempt_disabled respectively). **N** means that
497ad4a5223SQuentin Monnet  * 			  **TIF_NEED_RESCHED** and **PREEMPT_NEED_RESCHED**
498ad4a5223SQuentin Monnet  * 			  are set.
499ad4a5223SQuentin Monnet  * 			* ``419421.045894`` is a timestamp.
500ad4a5223SQuentin Monnet  * 			* ``0x00000001`` is a fake value used by BPF for the
501ad4a5223SQuentin Monnet  * 			  instruction pointer register.
502ad4a5223SQuentin Monnet  * 			* ``<formatted msg>`` is the message formatted with
503ad4a5223SQuentin Monnet  * 			  *fmt*.
504ad4a5223SQuentin Monnet  *
505ad4a5223SQuentin Monnet  * 		The conversion specifiers supported by *fmt* are similar, but
506ad4a5223SQuentin Monnet  * 		more limited than for printk(). They are **%d**, **%i**,
507ad4a5223SQuentin Monnet  * 		**%u**, **%x**, **%ld**, **%li**, **%lu**, **%lx**, **%lld**,
508ad4a5223SQuentin Monnet  * 		**%lli**, **%llu**, **%llx**, **%p**, **%s**. No modifier (size
509ad4a5223SQuentin Monnet  * 		of field, padding with zeroes, etc.) is available, and the
510ad4a5223SQuentin Monnet  * 		helper will return **-EINVAL** (but print nothing) if it
511ad4a5223SQuentin Monnet  * 		encounters an unknown specifier.
512ad4a5223SQuentin Monnet  *
513ad4a5223SQuentin Monnet  * 		Also, note that **bpf_trace_printk**\ () is slow, and should
514ad4a5223SQuentin Monnet  * 		only be used for debugging purposes. For this reason, a notice
515ad4a5223SQuentin Monnet  * 		bloc (spanning several lines) is printed to kernel logs and
516ad4a5223SQuentin Monnet  * 		states that the helper should not be used "for production use"
517ad4a5223SQuentin Monnet  * 		the first time this helper is used (or more precisely, when
518ad4a5223SQuentin Monnet  * 		**trace_printk**\ () buffers are allocated). For passing values
519ad4a5223SQuentin Monnet  * 		to user space, perf events should be preferred.
520ad4a5223SQuentin Monnet  * 	Return
521ad4a5223SQuentin Monnet  * 		The number of bytes written to the buffer, or a negative error
522ad4a5223SQuentin Monnet  * 		in case of failure.
523ad4a5223SQuentin Monnet  *
5241fdd08beSQuentin Monnet  * u32 bpf_get_prandom_u32(void)
5251fdd08beSQuentin Monnet  * 	Description
5261fdd08beSQuentin Monnet  * 		Get a pseudo-random number.
5271fdd08beSQuentin Monnet  *
5281fdd08beSQuentin Monnet  * 		From a security point of view, this helper uses its own
5291fdd08beSQuentin Monnet  * 		pseudo-random internal state, and cannot be used to infer the
5301fdd08beSQuentin Monnet  * 		seed of other random functions in the kernel. However, it is
5311fdd08beSQuentin Monnet  * 		essential to note that the generator used by the helper is not
5321fdd08beSQuentin Monnet  * 		cryptographically secure.
5331fdd08beSQuentin Monnet  * 	Return
5341fdd08beSQuentin Monnet  * 		A random 32-bit unsigned value.
5351fdd08beSQuentin Monnet  *
5361fdd08beSQuentin Monnet  * u32 bpf_get_smp_processor_id(void)
5371fdd08beSQuentin Monnet  * 	Description
5381fdd08beSQuentin Monnet  * 		Get the SMP (symmetric multiprocessing) processor id. Note that
5391fdd08beSQuentin Monnet  * 		all programs run with preemption disabled, which means that the
5401fdd08beSQuentin Monnet  * 		SMP processor id is stable during all the execution of the
5411fdd08beSQuentin Monnet  * 		program.
5421fdd08beSQuentin Monnet  * 	Return
5431fdd08beSQuentin Monnet  * 		The SMP id of the processor running the program.
5441fdd08beSQuentin Monnet  *
545ad4a5223SQuentin Monnet  * int bpf_skb_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len, u64 flags)
546ad4a5223SQuentin Monnet  * 	Description
547ad4a5223SQuentin Monnet  * 		Store *len* bytes from address *from* into the packet
548ad4a5223SQuentin Monnet  * 		associated to *skb*, at *offset*. *flags* are a combination of
549ad4a5223SQuentin Monnet  * 		**BPF_F_RECOMPUTE_CSUM** (automatically recompute the
550ad4a5223SQuentin Monnet  * 		checksum for the packet after storing the bytes) and
551ad4a5223SQuentin Monnet  * 		**BPF_F_INVALIDATE_HASH** (set *skb*\ **->hash**, *skb*\
552ad4a5223SQuentin Monnet  * 		**->swhash** and *skb*\ **->l4hash** to 0).
553ad4a5223SQuentin Monnet  *
554ad4a5223SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
555ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
556ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
557ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
558ad4a5223SQuentin Monnet  * 		direct packet access.
559ad4a5223SQuentin Monnet  * 	Return
560ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
561ad4a5223SQuentin Monnet  *
562ad4a5223SQuentin Monnet  * int bpf_l3_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 size)
563ad4a5223SQuentin Monnet  * 	Description
564ad4a5223SQuentin Monnet  * 		Recompute the layer 3 (e.g. IP) checksum for the packet
565ad4a5223SQuentin Monnet  * 		associated to *skb*. Computation is incremental, so the helper
566ad4a5223SQuentin Monnet  * 		must know the former value of the header field that was
567ad4a5223SQuentin Monnet  * 		modified (*from*), the new value of this field (*to*), and the
568ad4a5223SQuentin Monnet  * 		number of bytes (2 or 4) for this field, stored in *size*.
569ad4a5223SQuentin Monnet  * 		Alternatively, it is possible to store the difference between
570ad4a5223SQuentin Monnet  * 		the previous and the new values of the header field in *to*, by
571ad4a5223SQuentin Monnet  * 		setting *from* and *size* to 0. For both methods, *offset*
572ad4a5223SQuentin Monnet  * 		indicates the location of the IP checksum within the packet.
573ad4a5223SQuentin Monnet  *
574ad4a5223SQuentin Monnet  * 		This helper works in combination with **bpf_csum_diff**\ (),
575ad4a5223SQuentin Monnet  * 		which does not update the checksum in-place, but offers more
576ad4a5223SQuentin Monnet  * 		flexibility and can handle sizes larger than 2 or 4 for the
577ad4a5223SQuentin Monnet  * 		checksum to update.
578ad4a5223SQuentin Monnet  *
579ad4a5223SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
580ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
581ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
582ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
583ad4a5223SQuentin Monnet  * 		direct packet access.
584ad4a5223SQuentin Monnet  * 	Return
585ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
586ad4a5223SQuentin Monnet  *
587ad4a5223SQuentin Monnet  * int bpf_l4_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 flags)
588ad4a5223SQuentin Monnet  * 	Description
589ad4a5223SQuentin Monnet  * 		Recompute the layer 4 (e.g. TCP, UDP or ICMP) checksum for the
590ad4a5223SQuentin Monnet  * 		packet associated to *skb*. Computation is incremental, so the
591ad4a5223SQuentin Monnet  * 		helper must know the former value of the header field that was
592ad4a5223SQuentin Monnet  * 		modified (*from*), the new value of this field (*to*), and the
593ad4a5223SQuentin Monnet  * 		number of bytes (2 or 4) for this field, stored on the lowest
594ad4a5223SQuentin Monnet  * 		four bits of *flags*. Alternatively, it is possible to store
595ad4a5223SQuentin Monnet  * 		the difference between the previous and the new values of the
596ad4a5223SQuentin Monnet  * 		header field in *to*, by setting *from* and the four lowest
597ad4a5223SQuentin Monnet  * 		bits of *flags* to 0. For both methods, *offset* indicates the
598ad4a5223SQuentin Monnet  * 		location of the IP checksum within the packet. In addition to
599ad4a5223SQuentin Monnet  * 		the size of the field, *flags* can be added (bitwise OR) actual
600ad4a5223SQuentin Monnet  * 		flags. With **BPF_F_MARK_MANGLED_0**, a null checksum is left
601ad4a5223SQuentin Monnet  * 		untouched (unless **BPF_F_MARK_ENFORCE** is added as well), and
602ad4a5223SQuentin Monnet  * 		for updates resulting in a null checksum the value is set to
603ad4a5223SQuentin Monnet  * 		**CSUM_MANGLED_0** instead. Flag **BPF_F_PSEUDO_HDR** indicates
604ad4a5223SQuentin Monnet  * 		the checksum is to be computed against a pseudo-header.
605ad4a5223SQuentin Monnet  *
606ad4a5223SQuentin Monnet  * 		This helper works in combination with **bpf_csum_diff**\ (),
607ad4a5223SQuentin Monnet  * 		which does not update the checksum in-place, but offers more
608ad4a5223SQuentin Monnet  * 		flexibility and can handle sizes larger than 2 or 4 for the
609ad4a5223SQuentin Monnet  * 		checksum to update.
610ad4a5223SQuentin Monnet  *
611ad4a5223SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
612ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
613ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
614ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
615ad4a5223SQuentin Monnet  * 		direct packet access.
616ad4a5223SQuentin Monnet  * 	Return
617ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
618ad4a5223SQuentin Monnet  *
619ad4a5223SQuentin Monnet  * int bpf_tail_call(void *ctx, struct bpf_map *prog_array_map, u32 index)
620ad4a5223SQuentin Monnet  * 	Description
621ad4a5223SQuentin Monnet  * 		This special helper is used to trigger a "tail call", or in
622ad4a5223SQuentin Monnet  * 		other words, to jump into another eBPF program. The same stack
623ad4a5223SQuentin Monnet  * 		frame is used (but values on stack and in registers for the
624ad4a5223SQuentin Monnet  * 		caller are not accessible to the callee). This mechanism allows
625ad4a5223SQuentin Monnet  * 		for program chaining, either for raising the maximum number of
626ad4a5223SQuentin Monnet  * 		available eBPF instructions, or to execute given programs in
627ad4a5223SQuentin Monnet  * 		conditional blocks. For security reasons, there is an upper
628ad4a5223SQuentin Monnet  * 		limit to the number of successive tail calls that can be
629ad4a5223SQuentin Monnet  * 		performed.
630ad4a5223SQuentin Monnet  *
631ad4a5223SQuentin Monnet  * 		Upon call of this helper, the program attempts to jump into a
632ad4a5223SQuentin Monnet  * 		program referenced at index *index* in *prog_array_map*, a
633ad4a5223SQuentin Monnet  * 		special map of type **BPF_MAP_TYPE_PROG_ARRAY**, and passes
634ad4a5223SQuentin Monnet  * 		*ctx*, a pointer to the context.
635ad4a5223SQuentin Monnet  *
636ad4a5223SQuentin Monnet  * 		If the call succeeds, the kernel immediately runs the first
637ad4a5223SQuentin Monnet  * 		instruction of the new program. This is not a function call,
638ad4a5223SQuentin Monnet  * 		and it never returns to the previous program. If the call
639ad4a5223SQuentin Monnet  * 		fails, then the helper has no effect, and the caller continues
640ad4a5223SQuentin Monnet  * 		to run its subsequent instructions. A call can fail if the
641ad4a5223SQuentin Monnet  * 		destination program for the jump does not exist (i.e. *index*
642ad4a5223SQuentin Monnet  * 		is superior to the number of entries in *prog_array_map*), or
643ad4a5223SQuentin Monnet  * 		if the maximum number of tail calls has been reached for this
644ad4a5223SQuentin Monnet  * 		chain of programs. This limit is defined in the kernel by the
645ad4a5223SQuentin Monnet  * 		macro **MAX_TAIL_CALL_CNT** (not accessible to user space),
646ad4a5223SQuentin Monnet  * 		which is currently set to 32.
647ad4a5223SQuentin Monnet  * 	Return
648ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
649ad4a5223SQuentin Monnet  *
650ad4a5223SQuentin Monnet  * int bpf_clone_redirect(struct sk_buff *skb, u32 ifindex, u64 flags)
651ad4a5223SQuentin Monnet  * 	Description
652ad4a5223SQuentin Monnet  * 		Clone and redirect the packet associated to *skb* to another
653ad4a5223SQuentin Monnet  * 		net device of index *ifindex*. Both ingress and egress
654ad4a5223SQuentin Monnet  * 		interfaces can be used for redirection. The **BPF_F_INGRESS**
655ad4a5223SQuentin Monnet  * 		value in *flags* is used to make the distinction (ingress path
656ad4a5223SQuentin Monnet  * 		is selected if the flag is present, egress path otherwise).
657ad4a5223SQuentin Monnet  * 		This is the only flag supported for now.
658ad4a5223SQuentin Monnet  *
659ad4a5223SQuentin Monnet  * 		In comparison with **bpf_redirect**\ () helper,
660ad4a5223SQuentin Monnet  * 		**bpf_clone_redirect**\ () has the associated cost of
661ad4a5223SQuentin Monnet  * 		duplicating the packet buffer, but this can be executed out of
662ad4a5223SQuentin Monnet  * 		the eBPF program. Conversely, **bpf_redirect**\ () is more
663ad4a5223SQuentin Monnet  * 		efficient, but it is handled through an action code where the
664ad4a5223SQuentin Monnet  * 		redirection happens only after the eBPF program has returned.
665ad4a5223SQuentin Monnet  *
666ad4a5223SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
667ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
668ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
669ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
670ad4a5223SQuentin Monnet  * 		direct packet access.
671ad4a5223SQuentin Monnet  * 	Return
672ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
673c456dec4SQuentin Monnet  *
674c456dec4SQuentin Monnet  * u64 bpf_get_current_pid_tgid(void)
675c456dec4SQuentin Monnet  * 	Return
676c456dec4SQuentin Monnet  * 		A 64-bit integer containing the current tgid and pid, and
677c456dec4SQuentin Monnet  * 		created as such:
678c456dec4SQuentin Monnet  * 		*current_task*\ **->tgid << 32 \|**
679c456dec4SQuentin Monnet  * 		*current_task*\ **->pid**.
680c456dec4SQuentin Monnet  *
681c456dec4SQuentin Monnet  * u64 bpf_get_current_uid_gid(void)
682c456dec4SQuentin Monnet  * 	Return
683c456dec4SQuentin Monnet  * 		A 64-bit integer containing the current GID and UID, and
684c456dec4SQuentin Monnet  * 		created as such: *current_gid* **<< 32 \|** *current_uid*.
685c456dec4SQuentin Monnet  *
686c456dec4SQuentin Monnet  * int bpf_get_current_comm(char *buf, u32 size_of_buf)
687c456dec4SQuentin Monnet  * 	Description
688c456dec4SQuentin Monnet  * 		Copy the **comm** attribute of the current task into *buf* of
689c456dec4SQuentin Monnet  * 		*size_of_buf*. The **comm** attribute contains the name of
690c456dec4SQuentin Monnet  * 		the executable (excluding the path) for the current task. The
691c456dec4SQuentin Monnet  * 		*size_of_buf* must be strictly positive. On success, the
692c456dec4SQuentin Monnet  * 		helper makes sure that the *buf* is NUL-terminated. On failure,
693c456dec4SQuentin Monnet  * 		it is filled with zeroes.
694c456dec4SQuentin Monnet  * 	Return
695c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
696c456dec4SQuentin Monnet  *
6971fdd08beSQuentin Monnet  * u32 bpf_get_cgroup_classid(struct sk_buff *skb)
6981fdd08beSQuentin Monnet  * 	Description
6991fdd08beSQuentin Monnet  * 		Retrieve the classid for the current task, i.e. for the net_cls
7001fdd08beSQuentin Monnet  * 		cgroup to which *skb* belongs.
7011fdd08beSQuentin Monnet  *
7021fdd08beSQuentin Monnet  * 		This helper can be used on TC egress path, but not on ingress.
7031fdd08beSQuentin Monnet  *
7041fdd08beSQuentin Monnet  * 		The net_cls cgroup provides an interface to tag network packets
7051fdd08beSQuentin Monnet  * 		based on a user-provided identifier for all traffic coming from
7061fdd08beSQuentin Monnet  * 		the tasks belonging to the related cgroup. See also the related
7071fdd08beSQuentin Monnet  * 		kernel documentation, available from the Linux sources in file
7081fdd08beSQuentin Monnet  * 		*Documentation/cgroup-v1/net_cls.txt*.
7091fdd08beSQuentin Monnet  *
7101fdd08beSQuentin Monnet  * 		The Linux kernel has two versions for cgroups: there are
7111fdd08beSQuentin Monnet  * 		cgroups v1 and cgroups v2. Both are available to users, who can
7121fdd08beSQuentin Monnet  * 		use a mixture of them, but note that the net_cls cgroup is for
7131fdd08beSQuentin Monnet  * 		cgroup v1 only. This makes it incompatible with BPF programs
7141fdd08beSQuentin Monnet  * 		run on cgroups, which is a cgroup-v2-only feature (a socket can
7151fdd08beSQuentin Monnet  * 		only hold data for one version of cgroups at a time).
7161fdd08beSQuentin Monnet  *
7171fdd08beSQuentin Monnet  * 		This helper is only available is the kernel was compiled with
7181fdd08beSQuentin Monnet  * 		the **CONFIG_CGROUP_NET_CLASSID** configuration option set to
7191fdd08beSQuentin Monnet  * 		"**y**" or to "**m**".
7201fdd08beSQuentin Monnet  * 	Return
7211fdd08beSQuentin Monnet  * 		The classid, or 0 for the default unconfigured classid.
7221fdd08beSQuentin Monnet  *
723c456dec4SQuentin Monnet  * int bpf_skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)
724c456dec4SQuentin Monnet  * 	Description
725c456dec4SQuentin Monnet  * 		Push a *vlan_tci* (VLAN tag control information) of protocol
726c456dec4SQuentin Monnet  * 		*vlan_proto* to the packet associated to *skb*, then update
727c456dec4SQuentin Monnet  * 		the checksum. Note that if *vlan_proto* is different from
728c456dec4SQuentin Monnet  * 		**ETH_P_8021Q** and **ETH_P_8021AD**, it is considered to
729c456dec4SQuentin Monnet  * 		be **ETH_P_8021Q**.
730c456dec4SQuentin Monnet  *
731c456dec4SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
732c456dec4SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
733c456dec4SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
734c456dec4SQuentin Monnet  * 		performed again, if the helper is used in combination with
735c456dec4SQuentin Monnet  * 		direct packet access.
736c456dec4SQuentin Monnet  * 	Return
737c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
738c456dec4SQuentin Monnet  *
739c456dec4SQuentin Monnet  * int bpf_skb_vlan_pop(struct sk_buff *skb)
740c456dec4SQuentin Monnet  * 	Description
741c456dec4SQuentin Monnet  * 		Pop a VLAN header from the packet associated to *skb*.
742c456dec4SQuentin Monnet  *
743c456dec4SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
744c456dec4SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
745c456dec4SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
746c456dec4SQuentin Monnet  * 		performed again, if the helper is used in combination with
747c456dec4SQuentin Monnet  * 		direct packet access.
748c456dec4SQuentin Monnet  * 	Return
749c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
750c456dec4SQuentin Monnet  *
751c456dec4SQuentin Monnet  * int bpf_skb_get_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
752c456dec4SQuentin Monnet  * 	Description
753c456dec4SQuentin Monnet  * 		Get tunnel metadata. This helper takes a pointer *key* to an
754c456dec4SQuentin Monnet  * 		empty **struct bpf_tunnel_key** of **size**, that will be
755c456dec4SQuentin Monnet  * 		filled with tunnel metadata for the packet associated to *skb*.
756c456dec4SQuentin Monnet  * 		The *flags* can be set to **BPF_F_TUNINFO_IPV6**, which
757c456dec4SQuentin Monnet  * 		indicates that the tunnel is based on IPv6 protocol instead of
758c456dec4SQuentin Monnet  * 		IPv4.
759c456dec4SQuentin Monnet  *
760c456dec4SQuentin Monnet  * 		The **struct bpf_tunnel_key** is an object that generalizes the
761c456dec4SQuentin Monnet  * 		principal parameters used by various tunneling protocols into a
762c456dec4SQuentin Monnet  * 		single struct. This way, it can be used to easily make a
763c456dec4SQuentin Monnet  * 		decision based on the contents of the encapsulation header,
764c456dec4SQuentin Monnet  * 		"summarized" in this struct. In particular, it holds the IP
765c456dec4SQuentin Monnet  * 		address of the remote end (IPv4 or IPv6, depending on the case)
766c456dec4SQuentin Monnet  * 		in *key*\ **->remote_ipv4** or *key*\ **->remote_ipv6**. Also,
767c456dec4SQuentin Monnet  * 		this struct exposes the *key*\ **->tunnel_id**, which is
768c456dec4SQuentin Monnet  * 		generally mapped to a VNI (Virtual Network Identifier), making
769c456dec4SQuentin Monnet  * 		it programmable together with the **bpf_skb_set_tunnel_key**\
770c456dec4SQuentin Monnet  * 		() helper.
771c456dec4SQuentin Monnet  *
772c456dec4SQuentin Monnet  * 		Let's imagine that the following code is part of a program
773c456dec4SQuentin Monnet  * 		attached to the TC ingress interface, on one end of a GRE
774c456dec4SQuentin Monnet  * 		tunnel, and is supposed to filter out all messages coming from
775c456dec4SQuentin Monnet  * 		remote ends with IPv4 address other than 10.0.0.1:
776c456dec4SQuentin Monnet  *
777c456dec4SQuentin Monnet  * 		::
778c456dec4SQuentin Monnet  *
779c456dec4SQuentin Monnet  * 			int ret;
780c456dec4SQuentin Monnet  * 			struct bpf_tunnel_key key = {};
781c456dec4SQuentin Monnet  *
782c456dec4SQuentin Monnet  * 			ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
783c456dec4SQuentin Monnet  * 			if (ret < 0)
784c456dec4SQuentin Monnet  * 				return TC_ACT_SHOT;	// drop packet
785c456dec4SQuentin Monnet  *
786c456dec4SQuentin Monnet  * 			if (key.remote_ipv4 != 0x0a000001)
787c456dec4SQuentin Monnet  * 				return TC_ACT_SHOT;	// drop packet
788c456dec4SQuentin Monnet  *
789c456dec4SQuentin Monnet  * 			return TC_ACT_OK;		// accept packet
790c456dec4SQuentin Monnet  *
791c456dec4SQuentin Monnet  * 		This interface can also be used with all encapsulation devices
792c456dec4SQuentin Monnet  * 		that can operate in "collect metadata" mode: instead of having
793c456dec4SQuentin Monnet  * 		one network device per specific configuration, the "collect
794c456dec4SQuentin Monnet  * 		metadata" mode only requires a single device where the
795c456dec4SQuentin Monnet  * 		configuration can be extracted from this helper.
796c456dec4SQuentin Monnet  *
797c456dec4SQuentin Monnet  * 		This can be used together with various tunnels such as VXLan,
798c456dec4SQuentin Monnet  * 		Geneve, GRE or IP in IP (IPIP).
799c456dec4SQuentin Monnet  * 	Return
800c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
801c456dec4SQuentin Monnet  *
802c456dec4SQuentin Monnet  * int bpf_skb_set_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
803c456dec4SQuentin Monnet  * 	Description
804c456dec4SQuentin Monnet  * 		Populate tunnel metadata for packet associated to *skb.* The
805c456dec4SQuentin Monnet  * 		tunnel metadata is set to the contents of *key*, of *size*. The
806c456dec4SQuentin Monnet  * 		*flags* can be set to a combination of the following values:
807c456dec4SQuentin Monnet  *
808c456dec4SQuentin Monnet  * 		**BPF_F_TUNINFO_IPV6**
809c456dec4SQuentin Monnet  * 			Indicate that the tunnel is based on IPv6 protocol
810c456dec4SQuentin Monnet  * 			instead of IPv4.
811c456dec4SQuentin Monnet  * 		**BPF_F_ZERO_CSUM_TX**
812c456dec4SQuentin Monnet  * 			For IPv4 packets, add a flag to tunnel metadata
813c456dec4SQuentin Monnet  * 			indicating that checksum computation should be skipped
814c456dec4SQuentin Monnet  * 			and checksum set to zeroes.
815c456dec4SQuentin Monnet  * 		**BPF_F_DONT_FRAGMENT**
816c456dec4SQuentin Monnet  * 			Add a flag to tunnel metadata indicating that the
817c456dec4SQuentin Monnet  * 			packet should not be fragmented.
818c456dec4SQuentin Monnet  * 		**BPF_F_SEQ_NUMBER**
819c456dec4SQuentin Monnet  * 			Add a flag to tunnel metadata indicating that a
820c456dec4SQuentin Monnet  * 			sequence number should be added to tunnel header before
821c456dec4SQuentin Monnet  * 			sending the packet. This flag was added for GRE
822c456dec4SQuentin Monnet  * 			encapsulation, but might be used with other protocols
823c456dec4SQuentin Monnet  * 			as well in the future.
824c456dec4SQuentin Monnet  *
825c456dec4SQuentin Monnet  * 		Here is a typical usage on the transmit path:
826c456dec4SQuentin Monnet  *
827c456dec4SQuentin Monnet  * 		::
828c456dec4SQuentin Monnet  *
829c456dec4SQuentin Monnet  * 			struct bpf_tunnel_key key;
830c456dec4SQuentin Monnet  * 			     populate key ...
831c456dec4SQuentin Monnet  * 			bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0);
832c456dec4SQuentin Monnet  * 			bpf_clone_redirect(skb, vxlan_dev_ifindex, 0);
833c456dec4SQuentin Monnet  *
834c456dec4SQuentin Monnet  * 		See also the description of the **bpf_skb_get_tunnel_key**\ ()
835c456dec4SQuentin Monnet  * 		helper for additional information.
836c456dec4SQuentin Monnet  * 	Return
837c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
838c456dec4SQuentin Monnet  *
839c6b5fb86SQuentin Monnet  * u64 bpf_perf_event_read(struct bpf_map *map, u64 flags)
840c6b5fb86SQuentin Monnet  * 	Description
841c6b5fb86SQuentin Monnet  * 		Read the value of a perf event counter. This helper relies on a
842c6b5fb86SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of
843c6b5fb86SQuentin Monnet  * 		the perf event counter is selected when *map* is updated with
844c6b5fb86SQuentin Monnet  * 		perf event file descriptors. The *map* is an array whose size
845c6b5fb86SQuentin Monnet  * 		is the number of available CPUs, and each cell contains a value
846c6b5fb86SQuentin Monnet  * 		relative to one CPU. The value to retrieve is indicated by
847c6b5fb86SQuentin Monnet  * 		*flags*, that contains the index of the CPU to look up, masked
848c6b5fb86SQuentin Monnet  * 		with **BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
849c6b5fb86SQuentin Monnet  * 		**BPF_F_CURRENT_CPU** to indicate that the value for the
850c6b5fb86SQuentin Monnet  * 		current CPU should be retrieved.
851c6b5fb86SQuentin Monnet  *
852c6b5fb86SQuentin Monnet  * 		Note that before Linux 4.13, only hardware perf event can be
853c6b5fb86SQuentin Monnet  * 		retrieved.
854c6b5fb86SQuentin Monnet  *
855c6b5fb86SQuentin Monnet  * 		Also, be aware that the newer helper
856c6b5fb86SQuentin Monnet  * 		**bpf_perf_event_read_value**\ () is recommended over
8573bd5a09bSQuentin Monnet  * 		**bpf_perf_event_read**\ () in general. The latter has some ABI
858c6b5fb86SQuentin Monnet  * 		quirks where error and counter value are used as a return code
859c6b5fb86SQuentin Monnet  * 		(which is wrong to do since ranges may overlap). This issue is
8603bd5a09bSQuentin Monnet  * 		fixed with **bpf_perf_event_read_value**\ (), which at the same
8613bd5a09bSQuentin Monnet  * 		time provides more features over the **bpf_perf_event_read**\
8623bd5a09bSQuentin Monnet  * 		() interface. Please refer to the description of
863c6b5fb86SQuentin Monnet  * 		**bpf_perf_event_read_value**\ () for details.
864c6b5fb86SQuentin Monnet  * 	Return
865c6b5fb86SQuentin Monnet  * 		The value of the perf event counter read from the map, or a
866c6b5fb86SQuentin Monnet  * 		negative error code in case of failure.
867c6b5fb86SQuentin Monnet  *
868c456dec4SQuentin Monnet  * int bpf_redirect(u32 ifindex, u64 flags)
869c456dec4SQuentin Monnet  * 	Description
870c456dec4SQuentin Monnet  * 		Redirect the packet to another net device of index *ifindex*.
871c456dec4SQuentin Monnet  * 		This helper is somewhat similar to **bpf_clone_redirect**\
872c456dec4SQuentin Monnet  * 		(), except that the packet is not cloned, which provides
873c456dec4SQuentin Monnet  * 		increased performance.
874c456dec4SQuentin Monnet  *
875c456dec4SQuentin Monnet  * 		Except for XDP, both ingress and egress interfaces can be used
876c456dec4SQuentin Monnet  * 		for redirection. The **BPF_F_INGRESS** value in *flags* is used
877c456dec4SQuentin Monnet  * 		to make the distinction (ingress path is selected if the flag
878c456dec4SQuentin Monnet  * 		is present, egress path otherwise). Currently, XDP only
879c456dec4SQuentin Monnet  * 		supports redirection to the egress interface, and accepts no
880c456dec4SQuentin Monnet  * 		flag at all.
881c456dec4SQuentin Monnet  *
882c456dec4SQuentin Monnet  * 		The same effect can be attained with the more generic
883c456dec4SQuentin Monnet  * 		**bpf_redirect_map**\ (), which requires specific maps to be
884c456dec4SQuentin Monnet  * 		used but offers better performance.
885c456dec4SQuentin Monnet  * 	Return
886c456dec4SQuentin Monnet  * 		For XDP, the helper returns **XDP_REDIRECT** on success or
887c456dec4SQuentin Monnet  * 		**XDP_ABORTED** on error. For other program types, the values
888c456dec4SQuentin Monnet  * 		are **TC_ACT_REDIRECT** on success or **TC_ACT_SHOT** on
889c456dec4SQuentin Monnet  * 		error.
890c456dec4SQuentin Monnet  *
8911fdd08beSQuentin Monnet  * u32 bpf_get_route_realm(struct sk_buff *skb)
8921fdd08beSQuentin Monnet  * 	Description
8931fdd08beSQuentin Monnet  * 		Retrieve the realm or the route, that is to say the
8941fdd08beSQuentin Monnet  * 		**tclassid** field of the destination for the *skb*. The
8951fdd08beSQuentin Monnet  * 		indentifier retrieved is a user-provided tag, similar to the
8961fdd08beSQuentin Monnet  * 		one used with the net_cls cgroup (see description for
8971fdd08beSQuentin Monnet  * 		**bpf_get_cgroup_classid**\ () helper), but here this tag is
8981fdd08beSQuentin Monnet  * 		held by a route (a destination entry), not by a task.
8991fdd08beSQuentin Monnet  *
9001fdd08beSQuentin Monnet  * 		Retrieving this identifier works with the clsact TC egress hook
9011fdd08beSQuentin Monnet  * 		(see also **tc-bpf(8)**), or alternatively on conventional
9021fdd08beSQuentin Monnet  * 		classful egress qdiscs, but not on TC ingress path. In case of
9031fdd08beSQuentin Monnet  * 		clsact TC egress hook, this has the advantage that, internally,
9041fdd08beSQuentin Monnet  * 		the destination entry has not been dropped yet in the transmit
9051fdd08beSQuentin Monnet  * 		path. Therefore, the destination entry does not need to be
9061fdd08beSQuentin Monnet  * 		artificially held via **netif_keep_dst**\ () for a classful
9071fdd08beSQuentin Monnet  * 		qdisc until the *skb* is freed.
9081fdd08beSQuentin Monnet  *
9091fdd08beSQuentin Monnet  * 		This helper is available only if the kernel was compiled with
9101fdd08beSQuentin Monnet  * 		**CONFIG_IP_ROUTE_CLASSID** configuration option.
9111fdd08beSQuentin Monnet  * 	Return
9121fdd08beSQuentin Monnet  * 		The realm of the route for the packet associated to *skb*, or 0
9131fdd08beSQuentin Monnet  * 		if none was found.
9141fdd08beSQuentin Monnet  *
915c456dec4SQuentin Monnet  * int bpf_perf_event_output(struct pt_reg *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
916c456dec4SQuentin Monnet  * 	Description
917c456dec4SQuentin Monnet  * 		Write raw *data* blob into a special BPF perf event held by
918c456dec4SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
919c456dec4SQuentin Monnet  * 		event must have the following attributes: **PERF_SAMPLE_RAW**
920c456dec4SQuentin Monnet  * 		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
921c456dec4SQuentin Monnet  * 		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
922c456dec4SQuentin Monnet  *
923c456dec4SQuentin Monnet  * 		The *flags* are used to indicate the index in *map* for which
924c456dec4SQuentin Monnet  * 		the value must be put, masked with **BPF_F_INDEX_MASK**.
925c456dec4SQuentin Monnet  * 		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
926c456dec4SQuentin Monnet  * 		to indicate that the index of the current CPU core should be
927c456dec4SQuentin Monnet  * 		used.
928c456dec4SQuentin Monnet  *
929c456dec4SQuentin Monnet  * 		The value to write, of *size*, is passed through eBPF stack and
930c456dec4SQuentin Monnet  * 		pointed by *data*.
931c456dec4SQuentin Monnet  *
932c456dec4SQuentin Monnet  * 		The context of the program *ctx* needs also be passed to the
933c456dec4SQuentin Monnet  * 		helper.
934c456dec4SQuentin Monnet  *
935c456dec4SQuentin Monnet  * 		On user space, a program willing to read the values needs to
936c456dec4SQuentin Monnet  * 		call **perf_event_open**\ () on the perf event (either for
937c456dec4SQuentin Monnet  * 		one or for all CPUs) and to store the file descriptor into the
938c456dec4SQuentin Monnet  * 		*map*. This must be done before the eBPF program can send data
939c456dec4SQuentin Monnet  * 		into it. An example is available in file
940c456dec4SQuentin Monnet  * 		*samples/bpf/trace_output_user.c* in the Linux kernel source
941c456dec4SQuentin Monnet  * 		tree (the eBPF program counterpart is in
942c456dec4SQuentin Monnet  * 		*samples/bpf/trace_output_kern.c*).
943c456dec4SQuentin Monnet  *
944c456dec4SQuentin Monnet  * 		**bpf_perf_event_output**\ () achieves better performance
945c456dec4SQuentin Monnet  * 		than **bpf_trace_printk**\ () for sharing data with user
946c456dec4SQuentin Monnet  * 		space, and is much better suitable for streaming data from eBPF
947c456dec4SQuentin Monnet  * 		programs.
948c456dec4SQuentin Monnet  *
949c456dec4SQuentin Monnet  * 		Note that this helper is not restricted to tracing use cases
950c456dec4SQuentin Monnet  * 		and can be used with programs attached to TC or XDP as well,
951c456dec4SQuentin Monnet  * 		where it allows for passing data to user space listeners. Data
952c456dec4SQuentin Monnet  * 		can be:
953c456dec4SQuentin Monnet  *
954c456dec4SQuentin Monnet  * 		* Only custom structs,
955c456dec4SQuentin Monnet  * 		* Only the packet payload, or
956c456dec4SQuentin Monnet  * 		* A combination of both.
957c456dec4SQuentin Monnet  * 	Return
958c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
959c456dec4SQuentin Monnet  *
9601fdd08beSQuentin Monnet  * int bpf_skb_load_bytes(const struct sk_buff *skb, u32 offset, void *to, u32 len)
9611fdd08beSQuentin Monnet  * 	Description
9621fdd08beSQuentin Monnet  * 		This helper was provided as an easy way to load data from a
9631fdd08beSQuentin Monnet  * 		packet. It can be used to load *len* bytes from *offset* from
9641fdd08beSQuentin Monnet  * 		the packet associated to *skb*, into the buffer pointed by
9651fdd08beSQuentin Monnet  * 		*to*.
9661fdd08beSQuentin Monnet  *
9671fdd08beSQuentin Monnet  * 		Since Linux 4.7, usage of this helper has mostly been replaced
9681fdd08beSQuentin Monnet  * 		by "direct packet access", enabling packet data to be
9691fdd08beSQuentin Monnet  * 		manipulated with *skb*\ **->data** and *skb*\ **->data_end**
9701fdd08beSQuentin Monnet  * 		pointing respectively to the first byte of packet data and to
9711fdd08beSQuentin Monnet  * 		the byte after the last byte of packet data. However, it
9721fdd08beSQuentin Monnet  * 		remains useful if one wishes to read large quantities of data
9731fdd08beSQuentin Monnet  * 		at once from a packet into the eBPF stack.
9741fdd08beSQuentin Monnet  * 	Return
9751fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
9761fdd08beSQuentin Monnet  *
977c456dec4SQuentin Monnet  * int bpf_get_stackid(struct pt_reg *ctx, struct bpf_map *map, u64 flags)
978c456dec4SQuentin Monnet  * 	Description
979c456dec4SQuentin Monnet  * 		Walk a user or a kernel stack and return its id. To achieve
980c456dec4SQuentin Monnet  * 		this, the helper needs *ctx*, which is a pointer to the context
981c456dec4SQuentin Monnet  * 		on which the tracing program is executed, and a pointer to a
982c456dec4SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_STACK_TRACE**.
983c456dec4SQuentin Monnet  *
984c456dec4SQuentin Monnet  * 		The last argument, *flags*, holds the number of stack frames to
985c456dec4SQuentin Monnet  * 		skip (from 0 to 255), masked with
986c456dec4SQuentin Monnet  * 		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
987c456dec4SQuentin Monnet  * 		a combination of the following flags:
988c456dec4SQuentin Monnet  *
989c456dec4SQuentin Monnet  * 		**BPF_F_USER_STACK**
990c456dec4SQuentin Monnet  * 			Collect a user space stack instead of a kernel stack.
991c456dec4SQuentin Monnet  * 		**BPF_F_FAST_STACK_CMP**
992c456dec4SQuentin Monnet  * 			Compare stacks by hash only.
993c456dec4SQuentin Monnet  * 		**BPF_F_REUSE_STACKID**
994c456dec4SQuentin Monnet  * 			If two different stacks hash into the same *stackid*,
995c456dec4SQuentin Monnet  * 			discard the old one.
996c456dec4SQuentin Monnet  *
997c456dec4SQuentin Monnet  * 		The stack id retrieved is a 32 bit long integer handle which
998c456dec4SQuentin Monnet  * 		can be further combined with other data (including other stack
999c456dec4SQuentin Monnet  * 		ids) and used as a key into maps. This can be useful for
1000c456dec4SQuentin Monnet  * 		generating a variety of graphs (such as flame graphs or off-cpu
1001c456dec4SQuentin Monnet  * 		graphs).
1002c456dec4SQuentin Monnet  *
1003c456dec4SQuentin Monnet  * 		For walking a stack, this helper is an improvement over
1004c456dec4SQuentin Monnet  * 		**bpf_probe_read**\ (), which can be used with unrolled loops
1005c456dec4SQuentin Monnet  * 		but is not efficient and consumes a lot of eBPF instructions.
1006c456dec4SQuentin Monnet  * 		Instead, **bpf_get_stackid**\ () can collect up to
1007c456dec4SQuentin Monnet  * 		**PERF_MAX_STACK_DEPTH** both kernel and user frames. Note that
1008c456dec4SQuentin Monnet  * 		this limit can be controlled with the **sysctl** program, and
1009c456dec4SQuentin Monnet  * 		that it should be manually increased in order to profile long
1010c456dec4SQuentin Monnet  * 		user stacks (such as stacks for Java programs). To do so, use:
1011c456dec4SQuentin Monnet  *
1012c456dec4SQuentin Monnet  * 		::
1013c456dec4SQuentin Monnet  *
1014c456dec4SQuentin Monnet  * 			# sysctl kernel.perf_event_max_stack=<new value>
1015c456dec4SQuentin Monnet  * 	Return
1016c456dec4SQuentin Monnet  * 		The positive or null stack id on success, or a negative error
1017c456dec4SQuentin Monnet  * 		in case of failure.
1018c456dec4SQuentin Monnet  *
10191fdd08beSQuentin Monnet  * s64 bpf_csum_diff(__be32 *from, u32 from_size, __be32 *to, u32 to_size, __wsum seed)
10201fdd08beSQuentin Monnet  * 	Description
10211fdd08beSQuentin Monnet  * 		Compute a checksum difference, from the raw buffer pointed by
10221fdd08beSQuentin Monnet  * 		*from*, of length *from_size* (that must be a multiple of 4),
10231fdd08beSQuentin Monnet  * 		towards the raw buffer pointed by *to*, of size *to_size*
10241fdd08beSQuentin Monnet  * 		(same remark). An optional *seed* can be added to the value
10251fdd08beSQuentin Monnet  * 		(this can be cascaded, the seed may come from a previous call
10261fdd08beSQuentin Monnet  * 		to the helper).
10271fdd08beSQuentin Monnet  *
10281fdd08beSQuentin Monnet  * 		This is flexible enough to be used in several ways:
10291fdd08beSQuentin Monnet  *
10301fdd08beSQuentin Monnet  * 		* With *from_size* == 0, *to_size* > 0 and *seed* set to
10311fdd08beSQuentin Monnet  * 		  checksum, it can be used when pushing new data.
10321fdd08beSQuentin Monnet  * 		* With *from_size* > 0, *to_size* == 0 and *seed* set to
10331fdd08beSQuentin Monnet  * 		  checksum, it can be used when removing data from a packet.
10341fdd08beSQuentin Monnet  * 		* With *from_size* > 0, *to_size* > 0 and *seed* set to 0, it
10351fdd08beSQuentin Monnet  * 		  can be used to compute a diff. Note that *from_size* and
10361fdd08beSQuentin Monnet  * 		  *to_size* do not need to be equal.
10371fdd08beSQuentin Monnet  *
10381fdd08beSQuentin Monnet  * 		This helper can be used in combination with
10391fdd08beSQuentin Monnet  * 		**bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\ (), to
10401fdd08beSQuentin Monnet  * 		which one can feed in the difference computed with
10411fdd08beSQuentin Monnet  * 		**bpf_csum_diff**\ ().
10421fdd08beSQuentin Monnet  * 	Return
10431fdd08beSQuentin Monnet  * 		The checksum result, or a negative error code in case of
10441fdd08beSQuentin Monnet  * 		failure.
10451fdd08beSQuentin Monnet  *
10461fdd08beSQuentin Monnet  * int bpf_skb_get_tunnel_opt(struct sk_buff *skb, u8 *opt, u32 size)
10471fdd08beSQuentin Monnet  * 	Description
10481fdd08beSQuentin Monnet  * 		Retrieve tunnel options metadata for the packet associated to
10491fdd08beSQuentin Monnet  * 		*skb*, and store the raw tunnel option data to the buffer *opt*
10501fdd08beSQuentin Monnet  * 		of *size*.
10511fdd08beSQuentin Monnet  *
10521fdd08beSQuentin Monnet  * 		This helper can be used with encapsulation devices that can
10531fdd08beSQuentin Monnet  * 		operate in "collect metadata" mode (please refer to the related
10541fdd08beSQuentin Monnet  * 		note in the description of **bpf_skb_get_tunnel_key**\ () for
10551fdd08beSQuentin Monnet  * 		more details). A particular example where this can be used is
10561fdd08beSQuentin Monnet  * 		in combination with the Geneve encapsulation protocol, where it
10571fdd08beSQuentin Monnet  * 		allows for pushing (with **bpf_skb_get_tunnel_opt**\ () helper)
10581fdd08beSQuentin Monnet  * 		and retrieving arbitrary TLVs (Type-Length-Value headers) from
10591fdd08beSQuentin Monnet  * 		the eBPF program. This allows for full customization of these
10601fdd08beSQuentin Monnet  * 		headers.
10611fdd08beSQuentin Monnet  * 	Return
10621fdd08beSQuentin Monnet  * 		The size of the option data retrieved.
10631fdd08beSQuentin Monnet  *
10641fdd08beSQuentin Monnet  * int bpf_skb_set_tunnel_opt(struct sk_buff *skb, u8 *opt, u32 size)
10651fdd08beSQuentin Monnet  * 	Description
10661fdd08beSQuentin Monnet  * 		Set tunnel options metadata for the packet associated to *skb*
10671fdd08beSQuentin Monnet  * 		to the option data contained in the raw buffer *opt* of *size*.
10681fdd08beSQuentin Monnet  *
10691fdd08beSQuentin Monnet  * 		See also the description of the **bpf_skb_get_tunnel_opt**\ ()
10701fdd08beSQuentin Monnet  * 		helper for additional information.
10711fdd08beSQuentin Monnet  * 	Return
10721fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
10731fdd08beSQuentin Monnet  *
10741fdd08beSQuentin Monnet  * int bpf_skb_change_proto(struct sk_buff *skb, __be16 proto, u64 flags)
10751fdd08beSQuentin Monnet  * 	Description
10761fdd08beSQuentin Monnet  * 		Change the protocol of the *skb* to *proto*. Currently
10771fdd08beSQuentin Monnet  * 		supported are transition from IPv4 to IPv6, and from IPv6 to
10781fdd08beSQuentin Monnet  * 		IPv4. The helper takes care of the groundwork for the
10791fdd08beSQuentin Monnet  * 		transition, including resizing the socket buffer. The eBPF
10801fdd08beSQuentin Monnet  * 		program is expected to fill the new headers, if any, via
10811fdd08beSQuentin Monnet  * 		**skb_store_bytes**\ () and to recompute the checksums with
10821fdd08beSQuentin Monnet  * 		**bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\
10831fdd08beSQuentin Monnet  * 		(). The main case for this helper is to perform NAT64
10841fdd08beSQuentin Monnet  * 		operations out of an eBPF program.
10851fdd08beSQuentin Monnet  *
10861fdd08beSQuentin Monnet  * 		Internally, the GSO type is marked as dodgy so that headers are
10871fdd08beSQuentin Monnet  * 		checked and segments are recalculated by the GSO/GRO engine.
10881fdd08beSQuentin Monnet  * 		The size for GSO target is adapted as well.
10891fdd08beSQuentin Monnet  *
10901fdd08beSQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
10911fdd08beSQuentin Monnet  * 		be left at zero.
10921fdd08beSQuentin Monnet  *
10931fdd08beSQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
10941fdd08beSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
10951fdd08beSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
10961fdd08beSQuentin Monnet  * 		performed again, if the helper is used in combination with
10971fdd08beSQuentin Monnet  * 		direct packet access.
10981fdd08beSQuentin Monnet  * 	Return
10991fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
11001fdd08beSQuentin Monnet  *
11011fdd08beSQuentin Monnet  * int bpf_skb_change_type(struct sk_buff *skb, u32 type)
11021fdd08beSQuentin Monnet  * 	Description
11031fdd08beSQuentin Monnet  * 		Change the packet type for the packet associated to *skb*. This
11041fdd08beSQuentin Monnet  * 		comes down to setting *skb*\ **->pkt_type** to *type*, except
11051fdd08beSQuentin Monnet  * 		the eBPF program does not have a write access to *skb*\
11061fdd08beSQuentin Monnet  * 		**->pkt_type** beside this helper. Using a helper here allows
11071fdd08beSQuentin Monnet  * 		for graceful handling of errors.
11081fdd08beSQuentin Monnet  *
11091fdd08beSQuentin Monnet  * 		The major use case is to change incoming *skb*s to
11101fdd08beSQuentin Monnet  * 		**PACKET_HOST** in a programmatic way instead of having to
11111fdd08beSQuentin Monnet  * 		recirculate via **redirect**\ (..., **BPF_F_INGRESS**), for
11121fdd08beSQuentin Monnet  * 		example.
11131fdd08beSQuentin Monnet  *
11141fdd08beSQuentin Monnet  * 		Note that *type* only allows certain values. At this time, they
11151fdd08beSQuentin Monnet  * 		are:
11161fdd08beSQuentin Monnet  *
11171fdd08beSQuentin Monnet  * 		**PACKET_HOST**
11181fdd08beSQuentin Monnet  * 			Packet is for us.
11191fdd08beSQuentin Monnet  * 		**PACKET_BROADCAST**
11201fdd08beSQuentin Monnet  * 			Send packet to all.
11211fdd08beSQuentin Monnet  * 		**PACKET_MULTICAST**
11221fdd08beSQuentin Monnet  * 			Send packet to group.
11231fdd08beSQuentin Monnet  * 		**PACKET_OTHERHOST**
11241fdd08beSQuentin Monnet  * 			Send packet to someone else.
11251fdd08beSQuentin Monnet  * 	Return
11261fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
11271fdd08beSQuentin Monnet  *
1128c6b5fb86SQuentin Monnet  * int bpf_skb_under_cgroup(struct sk_buff *skb, struct bpf_map *map, u32 index)
1129c6b5fb86SQuentin Monnet  * 	Description
1130c6b5fb86SQuentin Monnet  * 		Check whether *skb* is a descendant of the cgroup2 held by
1131c6b5fb86SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
1132c6b5fb86SQuentin Monnet  * 	Return
1133c6b5fb86SQuentin Monnet  * 		The return value depends on the result of the test, and can be:
1134c6b5fb86SQuentin Monnet  *
1135c6b5fb86SQuentin Monnet  * 		* 0, if the *skb* failed the cgroup2 descendant test.
1136c6b5fb86SQuentin Monnet  * 		* 1, if the *skb* succeeded the cgroup2 descendant test.
1137c6b5fb86SQuentin Monnet  * 		* A negative error code, if an error occurred.
1138c6b5fb86SQuentin Monnet  *
1139fa15601aSQuentin Monnet  * u32 bpf_get_hash_recalc(struct sk_buff *skb)
1140fa15601aSQuentin Monnet  * 	Description
1141fa15601aSQuentin Monnet  * 		Retrieve the hash of the packet, *skb*\ **->hash**. If it is
1142fa15601aSQuentin Monnet  * 		not set, in particular if the hash was cleared due to mangling,
1143fa15601aSQuentin Monnet  * 		recompute this hash. Later accesses to the hash can be done
1144fa15601aSQuentin Monnet  * 		directly with *skb*\ **->hash**.
1145fa15601aSQuentin Monnet  *
1146fa15601aSQuentin Monnet  * 		Calling **bpf_set_hash_invalid**\ (), changing a packet
1147fa15601aSQuentin Monnet  * 		prototype with **bpf_skb_change_proto**\ (), or calling
1148fa15601aSQuentin Monnet  * 		**bpf_skb_store_bytes**\ () with the
1149fa15601aSQuentin Monnet  * 		**BPF_F_INVALIDATE_HASH** are actions susceptible to clear
1150fa15601aSQuentin Monnet  * 		the hash and to trigger a new computation for the next call to
1151fa15601aSQuentin Monnet  * 		**bpf_get_hash_recalc**\ ().
1152fa15601aSQuentin Monnet  * 	Return
1153fa15601aSQuentin Monnet  * 		The 32-bit hash.
1154fa15601aSQuentin Monnet  *
1155c456dec4SQuentin Monnet  * u64 bpf_get_current_task(void)
1156c456dec4SQuentin Monnet  * 	Return
1157c456dec4SQuentin Monnet  * 		A pointer to the current task struct.
1158fa15601aSQuentin Monnet  *
1159c6b5fb86SQuentin Monnet  * int bpf_probe_write_user(void *dst, const void *src, u32 len)
1160c6b5fb86SQuentin Monnet  * 	Description
1161c6b5fb86SQuentin Monnet  * 		Attempt in a safe way to write *len* bytes from the buffer
1162c6b5fb86SQuentin Monnet  * 		*src* to *dst* in memory. It only works for threads that are in
1163c6b5fb86SQuentin Monnet  * 		user context, and *dst* must be a valid user space address.
1164c6b5fb86SQuentin Monnet  *
1165c6b5fb86SQuentin Monnet  * 		This helper should not be used to implement any kind of
1166c6b5fb86SQuentin Monnet  * 		security mechanism because of TOC-TOU attacks, but rather to
1167c6b5fb86SQuentin Monnet  * 		debug, divert, and manipulate execution of semi-cooperative
1168c6b5fb86SQuentin Monnet  * 		processes.
1169c6b5fb86SQuentin Monnet  *
1170c6b5fb86SQuentin Monnet  * 		Keep in mind that this feature is meant for experiments, and it
1171c6b5fb86SQuentin Monnet  * 		has a risk of crashing the system and running programs.
1172c6b5fb86SQuentin Monnet  * 		Therefore, when an eBPF program using this helper is attached,
1173c6b5fb86SQuentin Monnet  * 		a warning including PID and process name is printed to kernel
1174c6b5fb86SQuentin Monnet  * 		logs.
1175c6b5fb86SQuentin Monnet  * 	Return
1176c6b5fb86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1177c6b5fb86SQuentin Monnet  *
1178c6b5fb86SQuentin Monnet  * int bpf_current_task_under_cgroup(struct bpf_map *map, u32 index)
1179c6b5fb86SQuentin Monnet  * 	Description
1180c6b5fb86SQuentin Monnet  * 		Check whether the probe is being run is the context of a given
1181c6b5fb86SQuentin Monnet  * 		subset of the cgroup2 hierarchy. The cgroup2 to test is held by
1182c6b5fb86SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
1183c6b5fb86SQuentin Monnet  * 	Return
1184c6b5fb86SQuentin Monnet  * 		The return value depends on the result of the test, and can be:
1185c6b5fb86SQuentin Monnet  *
1186c6b5fb86SQuentin Monnet  * 		* 0, if the *skb* task belongs to the cgroup2.
1187c6b5fb86SQuentin Monnet  * 		* 1, if the *skb* task does not belong to the cgroup2.
1188c6b5fb86SQuentin Monnet  * 		* A negative error code, if an error occurred.
1189c6b5fb86SQuentin Monnet  *
1190fa15601aSQuentin Monnet  * int bpf_skb_change_tail(struct sk_buff *skb, u32 len, u64 flags)
1191fa15601aSQuentin Monnet  * 	Description
1192fa15601aSQuentin Monnet  * 		Resize (trim or grow) the packet associated to *skb* to the
1193fa15601aSQuentin Monnet  * 		new *len*. The *flags* are reserved for future usage, and must
1194fa15601aSQuentin Monnet  * 		be left at zero.
1195fa15601aSQuentin Monnet  *
1196fa15601aSQuentin Monnet  * 		The basic idea is that the helper performs the needed work to
1197fa15601aSQuentin Monnet  * 		change the size of the packet, then the eBPF program rewrites
1198fa15601aSQuentin Monnet  * 		the rest via helpers like **bpf_skb_store_bytes**\ (),
1199fa15601aSQuentin Monnet  * 		**bpf_l3_csum_replace**\ (), **bpf_l3_csum_replace**\ ()
1200fa15601aSQuentin Monnet  * 		and others. This helper is a slow path utility intended for
1201fa15601aSQuentin Monnet  * 		replies with control messages. And because it is targeted for
1202fa15601aSQuentin Monnet  * 		slow path, the helper itself can afford to be slow: it
1203fa15601aSQuentin Monnet  * 		implicitly linearizes, unclones and drops offloads from the
1204fa15601aSQuentin Monnet  * 		*skb*.
1205fa15601aSQuentin Monnet  *
1206fa15601aSQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
1207fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1208fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1209fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
1210fa15601aSQuentin Monnet  * 		direct packet access.
1211fa15601aSQuentin Monnet  * 	Return
1212fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1213fa15601aSQuentin Monnet  *
1214fa15601aSQuentin Monnet  * int bpf_skb_pull_data(struct sk_buff *skb, u32 len)
1215fa15601aSQuentin Monnet  * 	Description
1216fa15601aSQuentin Monnet  * 		Pull in non-linear data in case the *skb* is non-linear and not
1217fa15601aSQuentin Monnet  * 		all of *len* are part of the linear section. Make *len* bytes
1218fa15601aSQuentin Monnet  * 		from *skb* readable and writable. If a zero value is passed for
1219fa15601aSQuentin Monnet  * 		*len*, then the whole length of the *skb* is pulled.
1220fa15601aSQuentin Monnet  *
1221fa15601aSQuentin Monnet  * 		This helper is only needed for reading and writing with direct
1222fa15601aSQuentin Monnet  * 		packet access.
1223fa15601aSQuentin Monnet  *
1224fa15601aSQuentin Monnet  * 		For direct packet access, testing that offsets to access
1225fa15601aSQuentin Monnet  * 		are within packet boundaries (test on *skb*\ **->data_end**) is
1226fa15601aSQuentin Monnet  * 		susceptible to fail if offsets are invalid, or if the requested
1227fa15601aSQuentin Monnet  * 		data is in non-linear parts of the *skb*. On failure the
1228fa15601aSQuentin Monnet  * 		program can just bail out, or in the case of a non-linear
1229fa15601aSQuentin Monnet  * 		buffer, use a helper to make the data available. The
1230fa15601aSQuentin Monnet  * 		**bpf_skb_load_bytes**\ () helper is a first solution to access
1231fa15601aSQuentin Monnet  * 		the data. Another one consists in using **bpf_skb_pull_data**
1232fa15601aSQuentin Monnet  * 		to pull in once the non-linear parts, then retesting and
1233fa15601aSQuentin Monnet  * 		eventually access the data.
1234fa15601aSQuentin Monnet  *
1235fa15601aSQuentin Monnet  * 		At the same time, this also makes sure the *skb* is uncloned,
1236fa15601aSQuentin Monnet  * 		which is a necessary condition for direct write. As this needs
1237fa15601aSQuentin Monnet  * 		to be an invariant for the write part only, the verifier
1238fa15601aSQuentin Monnet  * 		detects writes and adds a prologue that is calling
1239fa15601aSQuentin Monnet  * 		**bpf_skb_pull_data()** to effectively unclone the *skb* from
1240fa15601aSQuentin Monnet  * 		the very beginning in case it is indeed cloned.
1241fa15601aSQuentin Monnet  *
1242fa15601aSQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
1243fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1244fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1245fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
1246fa15601aSQuentin Monnet  * 		direct packet access.
1247fa15601aSQuentin Monnet  * 	Return
1248fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1249fa15601aSQuentin Monnet  *
1250fa15601aSQuentin Monnet  * s64 bpf_csum_update(struct sk_buff *skb, __wsum csum)
1251fa15601aSQuentin Monnet  * 	Description
1252fa15601aSQuentin Monnet  * 		Add the checksum *csum* into *skb*\ **->csum** in case the
1253fa15601aSQuentin Monnet  * 		driver has supplied a checksum for the entire packet into that
1254fa15601aSQuentin Monnet  * 		field. Return an error otherwise. This helper is intended to be
1255fa15601aSQuentin Monnet  * 		used in combination with **bpf_csum_diff**\ (), in particular
1256fa15601aSQuentin Monnet  * 		when the checksum needs to be updated after data has been
1257fa15601aSQuentin Monnet  * 		written into the packet through direct packet access.
1258fa15601aSQuentin Monnet  * 	Return
1259fa15601aSQuentin Monnet  * 		The checksum on success, or a negative error code in case of
1260fa15601aSQuentin Monnet  * 		failure.
1261fa15601aSQuentin Monnet  *
1262fa15601aSQuentin Monnet  * void bpf_set_hash_invalid(struct sk_buff *skb)
1263fa15601aSQuentin Monnet  * 	Description
1264fa15601aSQuentin Monnet  * 		Invalidate the current *skb*\ **->hash**. It can be used after
1265fa15601aSQuentin Monnet  * 		mangling on headers through direct packet access, in order to
1266fa15601aSQuentin Monnet  * 		indicate that the hash is outdated and to trigger a
1267fa15601aSQuentin Monnet  * 		recalculation the next time the kernel tries to access this
1268fa15601aSQuentin Monnet  * 		hash or when the **bpf_get_hash_recalc**\ () helper is called.
1269fa15601aSQuentin Monnet  *
1270fa15601aSQuentin Monnet  * int bpf_get_numa_node_id(void)
1271fa15601aSQuentin Monnet  * 	Description
1272fa15601aSQuentin Monnet  * 		Return the id of the current NUMA node. The primary use case
1273fa15601aSQuentin Monnet  * 		for this helper is the selection of sockets for the local NUMA
1274fa15601aSQuentin Monnet  * 		node, when the program is attached to sockets using the
1275fa15601aSQuentin Monnet  * 		**SO_ATTACH_REUSEPORT_EBPF** option (see also **socket(7)**),
1276fa15601aSQuentin Monnet  * 		but the helper is also available to other eBPF program types,
1277fa15601aSQuentin Monnet  * 		similarly to **bpf_get_smp_processor_id**\ ().
1278fa15601aSQuentin Monnet  * 	Return
1279fa15601aSQuentin Monnet  * 		The id of current NUMA node.
1280fa15601aSQuentin Monnet  *
1281c6b5fb86SQuentin Monnet  * int bpf_skb_change_head(struct sk_buff *skb, u32 len, u64 flags)
1282c6b5fb86SQuentin Monnet  * 	Description
1283c6b5fb86SQuentin Monnet  * 		Grows headroom of packet associated to *skb* and adjusts the
1284c6b5fb86SQuentin Monnet  * 		offset of the MAC header accordingly, adding *len* bytes of
1285c6b5fb86SQuentin Monnet  * 		space. It automatically extends and reallocates memory as
1286c6b5fb86SQuentin Monnet  * 		required.
1287c6b5fb86SQuentin Monnet  *
1288c6b5fb86SQuentin Monnet  * 		This helper can be used on a layer 3 *skb* to push a MAC header
1289c6b5fb86SQuentin Monnet  * 		for redirection into a layer 2 device.
1290c6b5fb86SQuentin Monnet  *
1291c6b5fb86SQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
1292c6b5fb86SQuentin Monnet  * 		be left at zero.
1293c6b5fb86SQuentin Monnet  *
1294c6b5fb86SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
1295c6b5fb86SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1296c6b5fb86SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1297c6b5fb86SQuentin Monnet  * 		performed again, if the helper is used in combination with
1298c6b5fb86SQuentin Monnet  * 		direct packet access.
1299c6b5fb86SQuentin Monnet  * 	Return
1300c6b5fb86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1301c6b5fb86SQuentin Monnet  *
1302c6b5fb86SQuentin Monnet  * int bpf_xdp_adjust_head(struct xdp_buff *xdp_md, int delta)
1303c6b5fb86SQuentin Monnet  * 	Description
1304c6b5fb86SQuentin Monnet  * 		Adjust (move) *xdp_md*\ **->data** by *delta* bytes. Note that
1305c6b5fb86SQuentin Monnet  * 		it is possible to use a negative value for *delta*. This helper
1306c6b5fb86SQuentin Monnet  * 		can be used to prepare the packet for pushing or popping
1307c6b5fb86SQuentin Monnet  * 		headers.
1308c6b5fb86SQuentin Monnet  *
1309c6b5fb86SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
1310c6b5fb86SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1311c6b5fb86SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1312c6b5fb86SQuentin Monnet  * 		performed again, if the helper is used in combination with
1313c6b5fb86SQuentin Monnet  * 		direct packet access.
1314c6b5fb86SQuentin Monnet  * 	Return
1315c6b5fb86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1316c6b5fb86SQuentin Monnet  *
1317c6b5fb86SQuentin Monnet  * int bpf_probe_read_str(void *dst, int size, const void *unsafe_ptr)
1318c6b5fb86SQuentin Monnet  * 	Description
1319c6b5fb86SQuentin Monnet  * 		Copy a NUL terminated string from an unsafe address
1320c6b5fb86SQuentin Monnet  * 		*unsafe_ptr* to *dst*. The *size* should include the
1321c6b5fb86SQuentin Monnet  * 		terminating NUL byte. In case the string length is smaller than
1322c6b5fb86SQuentin Monnet  * 		*size*, the target is not padded with further NUL bytes. If the
1323c6b5fb86SQuentin Monnet  * 		string length is larger than *size*, just *size*-1 bytes are
1324c6b5fb86SQuentin Monnet  * 		copied and the last byte is set to NUL.
1325c6b5fb86SQuentin Monnet  *
1326c6b5fb86SQuentin Monnet  * 		On success, the length of the copied string is returned. This
1327c6b5fb86SQuentin Monnet  * 		makes this helper useful in tracing programs for reading
1328c6b5fb86SQuentin Monnet  * 		strings, and more importantly to get its length at runtime. See
1329c6b5fb86SQuentin Monnet  * 		the following snippet:
1330c6b5fb86SQuentin Monnet  *
1331c6b5fb86SQuentin Monnet  * 		::
1332c6b5fb86SQuentin Monnet  *
1333c6b5fb86SQuentin Monnet  * 			SEC("kprobe/sys_open")
1334c6b5fb86SQuentin Monnet  * 			void bpf_sys_open(struct pt_regs *ctx)
1335c6b5fb86SQuentin Monnet  * 			{
1336c6b5fb86SQuentin Monnet  * 			        char buf[PATHLEN]; // PATHLEN is defined to 256
1337c6b5fb86SQuentin Monnet  * 			        int res = bpf_probe_read_str(buf, sizeof(buf),
1338c6b5fb86SQuentin Monnet  * 				                             ctx->di);
1339c6b5fb86SQuentin Monnet  *
1340c6b5fb86SQuentin Monnet  * 				// Consume buf, for example push it to
1341c6b5fb86SQuentin Monnet  * 				// userspace via bpf_perf_event_output(); we
1342c6b5fb86SQuentin Monnet  * 				// can use res (the string length) as event
1343c6b5fb86SQuentin Monnet  * 				// size, after checking its boundaries.
1344c6b5fb86SQuentin Monnet  * 			}
1345c6b5fb86SQuentin Monnet  *
1346c6b5fb86SQuentin Monnet  * 		In comparison, using **bpf_probe_read()** helper here instead
1347c6b5fb86SQuentin Monnet  * 		to read the string would require to estimate the length at
1348c6b5fb86SQuentin Monnet  * 		compile time, and would often result in copying more memory
1349c6b5fb86SQuentin Monnet  * 		than necessary.
1350c6b5fb86SQuentin Monnet  *
1351c6b5fb86SQuentin Monnet  * 		Another useful use case is when parsing individual process
1352c6b5fb86SQuentin Monnet  * 		arguments or individual environment variables navigating
1353c6b5fb86SQuentin Monnet  * 		*current*\ **->mm->arg_start** and *current*\
1354c6b5fb86SQuentin Monnet  * 		**->mm->env_start**: using this helper and the return value,
1355c6b5fb86SQuentin Monnet  * 		one can quickly iterate at the right offset of the memory area.
1356c6b5fb86SQuentin Monnet  * 	Return
1357c6b5fb86SQuentin Monnet  * 		On success, the strictly positive length of the string,
1358c6b5fb86SQuentin Monnet  * 		including the trailing NUL character. On error, a negative
1359c6b5fb86SQuentin Monnet  * 		value.
1360c6b5fb86SQuentin Monnet  *
1361c6b5fb86SQuentin Monnet  * u64 bpf_get_socket_cookie(struct sk_buff *skb)
1362c6b5fb86SQuentin Monnet  * 	Description
1363c6b5fb86SQuentin Monnet  * 		If the **struct sk_buff** pointed by *skb* has a known socket,
1364c6b5fb86SQuentin Monnet  * 		retrieve the cookie (generated by the kernel) of this socket.
1365c6b5fb86SQuentin Monnet  * 		If no cookie has been set yet, generate a new cookie. Once
1366c6b5fb86SQuentin Monnet  * 		generated, the socket cookie remains stable for the life of the
1367c6b5fb86SQuentin Monnet  * 		socket. This helper can be useful for monitoring per socket
1368c6b5fb86SQuentin Monnet  * 		networking traffic statistics as it provides a unique socket
1369c6b5fb86SQuentin Monnet  * 		identifier per namespace.
1370c6b5fb86SQuentin Monnet  * 	Return
1371c6b5fb86SQuentin Monnet  * 		A 8-byte long non-decreasing number on success, or 0 if the
1372c6b5fb86SQuentin Monnet  * 		socket field is missing inside *skb*.
1373c6b5fb86SQuentin Monnet  *
1374c6b5fb86SQuentin Monnet  * u32 bpf_get_socket_uid(struct sk_buff *skb)
1375c6b5fb86SQuentin Monnet  * 	Return
1376c6b5fb86SQuentin Monnet  * 		The owner UID of the socket associated to *skb*. If the socket
1377c6b5fb86SQuentin Monnet  * 		is **NULL**, or if it is not a full socket (i.e. if it is a
1378c6b5fb86SQuentin Monnet  * 		time-wait or a request socket instead), **overflowuid** value
1379c6b5fb86SQuentin Monnet  * 		is returned (note that **overflowuid** might also be the actual
1380c6b5fb86SQuentin Monnet  * 		UID value for the socket).
1381c6b5fb86SQuentin Monnet  *
1382fa15601aSQuentin Monnet  * u32 bpf_set_hash(struct sk_buff *skb, u32 hash)
1383fa15601aSQuentin Monnet  * 	Description
1384fa15601aSQuentin Monnet  * 		Set the full hash for *skb* (set the field *skb*\ **->hash**)
1385fa15601aSQuentin Monnet  * 		to value *hash*.
1386fa15601aSQuentin Monnet  * 	Return
1387fa15601aSQuentin Monnet  * 		0
1388fa15601aSQuentin Monnet  *
1389a3ef8e9aSAndrey Ignatov  * int bpf_setsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, char *optval, int optlen)
13907aa79a86SQuentin Monnet  * 	Description
13917aa79a86SQuentin Monnet  * 		Emulate a call to **setsockopt()** on the socket associated to
13927aa79a86SQuentin Monnet  * 		*bpf_socket*, which must be a full socket. The *level* at
13937aa79a86SQuentin Monnet  * 		which the option resides and the name *optname* of the option
13947aa79a86SQuentin Monnet  * 		must be specified, see **setsockopt(2)** for more information.
13957aa79a86SQuentin Monnet  * 		The option value of length *optlen* is pointed by *optval*.
13967aa79a86SQuentin Monnet  *
13977aa79a86SQuentin Monnet  * 		This helper actually implements a subset of **setsockopt()**.
13987aa79a86SQuentin Monnet  * 		It supports the following *level*\ s:
13997aa79a86SQuentin Monnet  *
14007aa79a86SQuentin Monnet  * 		* **SOL_SOCKET**, which supports the following *optname*\ s:
14017aa79a86SQuentin Monnet  * 		  **SO_RCVBUF**, **SO_SNDBUF**, **SO_MAX_PACING_RATE**,
14027aa79a86SQuentin Monnet  * 		  **SO_PRIORITY**, **SO_RCVLOWAT**, **SO_MARK**.
14037aa79a86SQuentin Monnet  * 		* **IPPROTO_TCP**, which supports the following *optname*\ s:
14047aa79a86SQuentin Monnet  * 		  **TCP_CONGESTION**, **TCP_BPF_IW**,
14057aa79a86SQuentin Monnet  * 		  **TCP_BPF_SNDCWND_CLAMP**.
14067aa79a86SQuentin Monnet  * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
14077aa79a86SQuentin Monnet  * 		* **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
14087aa79a86SQuentin Monnet  * 	Return
14097aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
14107aa79a86SQuentin Monnet  *
1411fa15601aSQuentin Monnet  * int bpf_skb_adjust_room(struct sk_buff *skb, u32 len_diff, u32 mode, u64 flags)
1412fa15601aSQuentin Monnet  * 	Description
1413fa15601aSQuentin Monnet  * 		Grow or shrink the room for data in the packet associated to
1414fa15601aSQuentin Monnet  * 		*skb* by *len_diff*, and according to the selected *mode*.
1415fa15601aSQuentin Monnet  *
1416fa15601aSQuentin Monnet  * 		There is a single supported mode at this time:
1417fa15601aSQuentin Monnet  *
1418fa15601aSQuentin Monnet  * 		* **BPF_ADJ_ROOM_NET**: Adjust room at the network layer
1419fa15601aSQuentin Monnet  * 		  (room space is added or removed below the layer 3 header).
1420fa15601aSQuentin Monnet  *
1421fa15601aSQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
1422fa15601aSQuentin Monnet  * 		be left at zero.
1423fa15601aSQuentin Monnet  *
1424fa15601aSQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
1425fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1426fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1427fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
1428fa15601aSQuentin Monnet  * 		direct packet access.
1429fa15601aSQuentin Monnet  * 	Return
1430fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1431fa15601aSQuentin Monnet  *
1432ab127040SQuentin Monnet  * int bpf_redirect_map(struct bpf_map *map, u32 key, u64 flags)
1433ab127040SQuentin Monnet  * 	Description
1434ab127040SQuentin Monnet  * 		Redirect the packet to the endpoint referenced by *map* at
1435ab127040SQuentin Monnet  * 		index *key*. Depending on its type, this *map* can contain
1436ab127040SQuentin Monnet  * 		references to net devices (for forwarding packets through other
1437ab127040SQuentin Monnet  * 		ports), or to CPUs (for redirecting XDP frames to another CPU;
1438ab127040SQuentin Monnet  * 		but this is only implemented for native XDP (with driver
1439ab127040SQuentin Monnet  * 		support) as of this writing).
1440ab127040SQuentin Monnet  *
1441ab127040SQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
1442ab127040SQuentin Monnet  * 		be left at zero.
1443ab127040SQuentin Monnet  *
1444ab127040SQuentin Monnet  * 		When used to redirect packets to net devices, this helper
1445ab127040SQuentin Monnet  * 		provides a high performance increase over **bpf_redirect**\ ().
1446ab127040SQuentin Monnet  * 		This is due to various implementation details of the underlying
1447ab127040SQuentin Monnet  * 		mechanisms, one of which is the fact that **bpf_redirect_map**\
1448ab127040SQuentin Monnet  * 		() tries to send packet as a "bulk" to the device.
1449ab127040SQuentin Monnet  * 	Return
1450ab127040SQuentin Monnet  * 		**XDP_REDIRECT** on success, or **XDP_ABORTED** on error.
1451ab127040SQuentin Monnet  *
1452ab127040SQuentin Monnet  * int bpf_sk_redirect_map(struct bpf_map *map, u32 key, u64 flags)
1453ab127040SQuentin Monnet  * 	Description
1454ab127040SQuentin Monnet  * 		Redirect the packet to the socket referenced by *map* (of type
1455ab127040SQuentin Monnet  * 		**BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
1456ab127040SQuentin Monnet  * 		egress interfaces can be used for redirection. The
1457ab127040SQuentin Monnet  * 		**BPF_F_INGRESS** value in *flags* is used to make the
1458ab127040SQuentin Monnet  * 		distinction (ingress path is selected if the flag is present,
1459ab127040SQuentin Monnet  * 		egress path otherwise). This is the only flag supported for now.
1460ab127040SQuentin Monnet  * 	Return
1461ab127040SQuentin Monnet  * 		**SK_PASS** on success, or **SK_DROP** on error.
1462ab127040SQuentin Monnet  *
1463a3ef8e9aSAndrey Ignatov  * int bpf_sock_map_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
1464ab127040SQuentin Monnet  * 	Description
1465ab127040SQuentin Monnet  * 		Add an entry to, or update a *map* referencing sockets. The
1466ab127040SQuentin Monnet  * 		*skops* is used as a new value for the entry associated to
1467ab127040SQuentin Monnet  * 		*key*. *flags* is one of:
1468ab127040SQuentin Monnet  *
1469ab127040SQuentin Monnet  * 		**BPF_NOEXIST**
1470ab127040SQuentin Monnet  * 			The entry for *key* must not exist in the map.
1471ab127040SQuentin Monnet  * 		**BPF_EXIST**
1472ab127040SQuentin Monnet  * 			The entry for *key* must already exist in the map.
1473ab127040SQuentin Monnet  * 		**BPF_ANY**
1474ab127040SQuentin Monnet  * 			No condition on the existence of the entry for *key*.
1475ab127040SQuentin Monnet  *
1476ab127040SQuentin Monnet  * 		If the *map* has eBPF programs (parser and verdict), those will
1477ab127040SQuentin Monnet  * 		be inherited by the socket being added. If the socket is
1478ab127040SQuentin Monnet  * 		already attached to eBPF programs, this results in an error.
1479ab127040SQuentin Monnet  * 	Return
1480ab127040SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1481ab127040SQuentin Monnet  *
1482fa15601aSQuentin Monnet  * int bpf_xdp_adjust_meta(struct xdp_buff *xdp_md, int delta)
1483fa15601aSQuentin Monnet  * 	Description
1484fa15601aSQuentin Monnet  * 		Adjust the address pointed by *xdp_md*\ **->data_meta** by
1485fa15601aSQuentin Monnet  * 		*delta* (which can be positive or negative). Note that this
1486fa15601aSQuentin Monnet  * 		operation modifies the address stored in *xdp_md*\ **->data**,
1487fa15601aSQuentin Monnet  * 		so the latter must be loaded only after the helper has been
1488fa15601aSQuentin Monnet  * 		called.
1489fa15601aSQuentin Monnet  *
1490fa15601aSQuentin Monnet  * 		The use of *xdp_md*\ **->data_meta** is optional and programs
1491fa15601aSQuentin Monnet  * 		are not required to use it. The rationale is that when the
1492fa15601aSQuentin Monnet  * 		packet is processed with XDP (e.g. as DoS filter), it is
1493fa15601aSQuentin Monnet  * 		possible to push further meta data along with it before passing
1494fa15601aSQuentin Monnet  * 		to the stack, and to give the guarantee that an ingress eBPF
1495fa15601aSQuentin Monnet  * 		program attached as a TC classifier on the same device can pick
1496fa15601aSQuentin Monnet  * 		this up for further post-processing. Since TC works with socket
1497fa15601aSQuentin Monnet  * 		buffers, it remains possible to set from XDP the **mark** or
1498fa15601aSQuentin Monnet  * 		**priority** pointers, or other pointers for the socket buffer.
1499fa15601aSQuentin Monnet  * 		Having this scratch space generic and programmable allows for
1500fa15601aSQuentin Monnet  * 		more flexibility as the user is free to store whatever meta
1501fa15601aSQuentin Monnet  * 		data they need.
1502fa15601aSQuentin Monnet  *
1503fa15601aSQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
1504fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1505fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1506fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
1507fa15601aSQuentin Monnet  * 		direct packet access.
1508fa15601aSQuentin Monnet  * 	Return
1509fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
15107aa79a86SQuentin Monnet  *
15117aa79a86SQuentin Monnet  * int bpf_perf_event_read_value(struct bpf_map *map, u64 flags, struct bpf_perf_event_value *buf, u32 buf_size)
15127aa79a86SQuentin Monnet  * 	Description
15137aa79a86SQuentin Monnet  * 		Read the value of a perf event counter, and store it into *buf*
15147aa79a86SQuentin Monnet  * 		of size *buf_size*. This helper relies on a *map* of type
15157aa79a86SQuentin Monnet  * 		**BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of the perf event
15167aa79a86SQuentin Monnet  * 		counter is selected when *map* is updated with perf event file
15177aa79a86SQuentin Monnet  * 		descriptors. The *map* is an array whose size is the number of
15187aa79a86SQuentin Monnet  * 		available CPUs, and each cell contains a value relative to one
15197aa79a86SQuentin Monnet  * 		CPU. The value to retrieve is indicated by *flags*, that
15207aa79a86SQuentin Monnet  * 		contains the index of the CPU to look up, masked with
15217aa79a86SQuentin Monnet  * 		**BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
15227aa79a86SQuentin Monnet  * 		**BPF_F_CURRENT_CPU** to indicate that the value for the
15237aa79a86SQuentin Monnet  * 		current CPU should be retrieved.
15247aa79a86SQuentin Monnet  *
15257aa79a86SQuentin Monnet  * 		This helper behaves in a way close to
15267aa79a86SQuentin Monnet  * 		**bpf_perf_event_read**\ () helper, save that instead of
15277aa79a86SQuentin Monnet  * 		just returning the value observed, it fills the *buf*
15287aa79a86SQuentin Monnet  * 		structure. This allows for additional data to be retrieved: in
15297aa79a86SQuentin Monnet  * 		particular, the enabled and running times (in *buf*\
15307aa79a86SQuentin Monnet  * 		**->enabled** and *buf*\ **->running**, respectively) are
15317aa79a86SQuentin Monnet  * 		copied. In general, **bpf_perf_event_read_value**\ () is
15327aa79a86SQuentin Monnet  * 		recommended over **bpf_perf_event_read**\ (), which has some
15337aa79a86SQuentin Monnet  * 		ABI issues and provides fewer functionalities.
15347aa79a86SQuentin Monnet  *
15357aa79a86SQuentin Monnet  * 		These values are interesting, because hardware PMU (Performance
15367aa79a86SQuentin Monnet  * 		Monitoring Unit) counters are limited resources. When there are
15377aa79a86SQuentin Monnet  * 		more PMU based perf events opened than available counters,
15387aa79a86SQuentin Monnet  * 		kernel will multiplex these events so each event gets certain
15397aa79a86SQuentin Monnet  * 		percentage (but not all) of the PMU time. In case that
15407aa79a86SQuentin Monnet  * 		multiplexing happens, the number of samples or counter value
15417aa79a86SQuentin Monnet  * 		will not reflect the case compared to when no multiplexing
15427aa79a86SQuentin Monnet  * 		occurs. This makes comparison between different runs difficult.
15437aa79a86SQuentin Monnet  * 		Typically, the counter value should be normalized before
15447aa79a86SQuentin Monnet  * 		comparing to other experiments. The usual normalization is done
15457aa79a86SQuentin Monnet  * 		as follows.
15467aa79a86SQuentin Monnet  *
15477aa79a86SQuentin Monnet  * 		::
15487aa79a86SQuentin Monnet  *
15497aa79a86SQuentin Monnet  * 			normalized_counter = counter * t_enabled / t_running
15507aa79a86SQuentin Monnet  *
15517aa79a86SQuentin Monnet  * 		Where t_enabled is the time enabled for event and t_running is
15527aa79a86SQuentin Monnet  * 		the time running for event since last normalization. The
15537aa79a86SQuentin Monnet  * 		enabled and running times are accumulated since the perf event
15547aa79a86SQuentin Monnet  * 		open. To achieve scaling factor between two invocations of an
15557aa79a86SQuentin Monnet  * 		eBPF program, users can can use CPU id as the key (which is
15567aa79a86SQuentin Monnet  * 		typical for perf array usage model) to remember the previous
15577aa79a86SQuentin Monnet  * 		value and do the calculation inside the eBPF program.
15587aa79a86SQuentin Monnet  * 	Return
15597aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
15607aa79a86SQuentin Monnet  *
1561a3ef8e9aSAndrey Ignatov  * int bpf_perf_prog_read_value(struct bpf_perf_event_data *ctx, struct bpf_perf_event_value *buf, u32 buf_size)
15627aa79a86SQuentin Monnet  * 	Description
15637aa79a86SQuentin Monnet  * 		For en eBPF program attached to a perf event, retrieve the
15647aa79a86SQuentin Monnet  * 		value of the event counter associated to *ctx* and store it in
15657aa79a86SQuentin Monnet  * 		the structure pointed by *buf* and of size *buf_size*. Enabled
15667aa79a86SQuentin Monnet  * 		and running times are also stored in the structure (see
15677aa79a86SQuentin Monnet  * 		description of helper **bpf_perf_event_read_value**\ () for
15687aa79a86SQuentin Monnet  * 		more details).
15697aa79a86SQuentin Monnet  * 	Return
15707aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
15717aa79a86SQuentin Monnet  *
1572a3ef8e9aSAndrey Ignatov  * int bpf_getsockopt(struct bpf_sock_ops *bpf_socket, int level, int optname, char *optval, int optlen)
15737aa79a86SQuentin Monnet  * 	Description
15747aa79a86SQuentin Monnet  * 		Emulate a call to **getsockopt()** on the socket associated to
15757aa79a86SQuentin Monnet  * 		*bpf_socket*, which must be a full socket. The *level* at
15767aa79a86SQuentin Monnet  * 		which the option resides and the name *optname* of the option
15777aa79a86SQuentin Monnet  * 		must be specified, see **getsockopt(2)** for more information.
15787aa79a86SQuentin Monnet  * 		The retrieved value is stored in the structure pointed by
15797aa79a86SQuentin Monnet  * 		*opval* and of length *optlen*.
15807aa79a86SQuentin Monnet  *
15817aa79a86SQuentin Monnet  * 		This helper actually implements a subset of **getsockopt()**.
15827aa79a86SQuentin Monnet  * 		It supports the following *level*\ s:
15837aa79a86SQuentin Monnet  *
15847aa79a86SQuentin Monnet  * 		* **IPPROTO_TCP**, which supports *optname*
15857aa79a86SQuentin Monnet  * 		  **TCP_CONGESTION**.
15867aa79a86SQuentin Monnet  * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
15877aa79a86SQuentin Monnet  * 		* **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
15887aa79a86SQuentin Monnet  * 	Return
15897aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
15907aa79a86SQuentin Monnet  *
15917aa79a86SQuentin Monnet  * int bpf_override_return(struct pt_reg *regs, u64 rc)
15927aa79a86SQuentin Monnet  * 	Description
15937aa79a86SQuentin Monnet  * 		Used for error injection, this helper uses kprobes to override
15947aa79a86SQuentin Monnet  * 		the return value of the probed function, and to set it to *rc*.
15957aa79a86SQuentin Monnet  * 		The first argument is the context *regs* on which the kprobe
15967aa79a86SQuentin Monnet  * 		works.
15977aa79a86SQuentin Monnet  *
15987aa79a86SQuentin Monnet  * 		This helper works by setting setting the PC (program counter)
15997aa79a86SQuentin Monnet  * 		to an override function which is run in place of the original
16007aa79a86SQuentin Monnet  * 		probed function. This means the probed function is not run at
16017aa79a86SQuentin Monnet  * 		all. The replacement function just returns with the required
16027aa79a86SQuentin Monnet  * 		value.
16037aa79a86SQuentin Monnet  *
16047aa79a86SQuentin Monnet  * 		This helper has security implications, and thus is subject to
16057aa79a86SQuentin Monnet  * 		restrictions. It is only available if the kernel was compiled
16067aa79a86SQuentin Monnet  * 		with the **CONFIG_BPF_KPROBE_OVERRIDE** configuration
16077aa79a86SQuentin Monnet  * 		option, and in this case it only works on functions tagged with
16087aa79a86SQuentin Monnet  * 		**ALLOW_ERROR_INJECTION** in the kernel code.
16097aa79a86SQuentin Monnet  *
16107aa79a86SQuentin Monnet  * 		Also, the helper is only available for the architectures having
16117aa79a86SQuentin Monnet  * 		the CONFIG_FUNCTION_ERROR_INJECTION option. As of this writing,
16127aa79a86SQuentin Monnet  * 		x86 architecture is the only one to support this feature.
16137aa79a86SQuentin Monnet  * 	Return
16147aa79a86SQuentin Monnet  * 		0
16157aa79a86SQuentin Monnet  *
1616a3ef8e9aSAndrey Ignatov  * int bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *bpf_sock, int argval)
16177aa79a86SQuentin Monnet  * 	Description
16187aa79a86SQuentin Monnet  * 		Attempt to set the value of the **bpf_sock_ops_cb_flags** field
16197aa79a86SQuentin Monnet  * 		for the full TCP socket associated to *bpf_sock_ops* to
16207aa79a86SQuentin Monnet  * 		*argval*.
16217aa79a86SQuentin Monnet  *
16227aa79a86SQuentin Monnet  * 		The primary use of this field is to determine if there should
16237aa79a86SQuentin Monnet  * 		be calls to eBPF programs of type
16247aa79a86SQuentin Monnet  * 		**BPF_PROG_TYPE_SOCK_OPS** at various points in the TCP
16257aa79a86SQuentin Monnet  * 		code. A program of the same type can change its value, per
16267aa79a86SQuentin Monnet  * 		connection and as necessary, when the connection is
16277aa79a86SQuentin Monnet  * 		established. This field is directly accessible for reading, but
16287aa79a86SQuentin Monnet  * 		this helper must be used for updates in order to return an
16297aa79a86SQuentin Monnet  * 		error if an eBPF program tries to set a callback that is not
16307aa79a86SQuentin Monnet  * 		supported in the current kernel.
16317aa79a86SQuentin Monnet  *
16327aa79a86SQuentin Monnet  * 		The supported callback values that *argval* can combine are:
16337aa79a86SQuentin Monnet  *
16347aa79a86SQuentin Monnet  * 		* **BPF_SOCK_OPS_RTO_CB_FLAG** (retransmission time out)
16357aa79a86SQuentin Monnet  * 		* **BPF_SOCK_OPS_RETRANS_CB_FLAG** (retransmission)
16367aa79a86SQuentin Monnet  * 		* **BPF_SOCK_OPS_STATE_CB_FLAG** (TCP state change)
16377aa79a86SQuentin Monnet  *
16387aa79a86SQuentin Monnet  * 		Here are some examples of where one could call such eBPF
16397aa79a86SQuentin Monnet  * 		program:
16407aa79a86SQuentin Monnet  *
16417aa79a86SQuentin Monnet  * 		* When RTO fires.
16427aa79a86SQuentin Monnet  * 		* When a packet is retransmitted.
16437aa79a86SQuentin Monnet  * 		* When the connection terminates.
16447aa79a86SQuentin Monnet  * 		* When a packet is sent.
16457aa79a86SQuentin Monnet  * 		* When a packet is received.
16467aa79a86SQuentin Monnet  * 	Return
16477aa79a86SQuentin Monnet  * 		Code **-EINVAL** if the socket is not a full TCP socket;
16487aa79a86SQuentin Monnet  * 		otherwise, a positive number containing the bits that could not
16497aa79a86SQuentin Monnet  * 		be set is returned (which comes down to 0 if all bits were set
16507aa79a86SQuentin Monnet  * 		as required).
16517aa79a86SQuentin Monnet  *
1652ab127040SQuentin Monnet  * int bpf_msg_redirect_map(struct sk_msg_buff *msg, struct bpf_map *map, u32 key, u64 flags)
1653ab127040SQuentin Monnet  * 	Description
1654ab127040SQuentin Monnet  * 		This helper is used in programs implementing policies at the
1655ab127040SQuentin Monnet  * 		socket level. If the message *msg* is allowed to pass (i.e. if
1656ab127040SQuentin Monnet  * 		the verdict eBPF program returns **SK_PASS**), redirect it to
1657ab127040SQuentin Monnet  * 		the socket referenced by *map* (of type
1658ab127040SQuentin Monnet  * 		**BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
1659ab127040SQuentin Monnet  * 		egress interfaces can be used for redirection. The
1660ab127040SQuentin Monnet  * 		**BPF_F_INGRESS** value in *flags* is used to make the
1661ab127040SQuentin Monnet  * 		distinction (ingress path is selected if the flag is present,
1662ab127040SQuentin Monnet  * 		egress path otherwise). This is the only flag supported for now.
1663ab127040SQuentin Monnet  * 	Return
1664ab127040SQuentin Monnet  * 		**SK_PASS** on success, or **SK_DROP** on error.
1665ab127040SQuentin Monnet  *
1666ab127040SQuentin Monnet  * int bpf_msg_apply_bytes(struct sk_msg_buff *msg, u32 bytes)
1667ab127040SQuentin Monnet  * 	Description
1668ab127040SQuentin Monnet  * 		For socket policies, apply the verdict of the eBPF program to
1669ab127040SQuentin Monnet  * 		the next *bytes* (number of bytes) of message *msg*.
1670ab127040SQuentin Monnet  *
1671ab127040SQuentin Monnet  * 		For example, this helper can be used in the following cases:
1672ab127040SQuentin Monnet  *
1673ab127040SQuentin Monnet  * 		* A single **sendmsg**\ () or **sendfile**\ () system call
1674ab127040SQuentin Monnet  * 		  contains multiple logical messages that the eBPF program is
1675ab127040SQuentin Monnet  * 		  supposed to read and for which it should apply a verdict.
1676ab127040SQuentin Monnet  * 		* An eBPF program only cares to read the first *bytes* of a
1677ab127040SQuentin Monnet  * 		  *msg*. If the message has a large payload, then setting up
1678ab127040SQuentin Monnet  * 		  and calling the eBPF program repeatedly for all bytes, even
1679ab127040SQuentin Monnet  * 		  though the verdict is already known, would create unnecessary
1680ab127040SQuentin Monnet  * 		  overhead.
1681ab127040SQuentin Monnet  *
1682ab127040SQuentin Monnet  * 		When called from within an eBPF program, the helper sets a
1683ab127040SQuentin Monnet  * 		counter internal to the BPF infrastructure, that is used to
1684ab127040SQuentin Monnet  * 		apply the last verdict to the next *bytes*. If *bytes* is
1685ab127040SQuentin Monnet  * 		smaller than the current data being processed from a
1686ab127040SQuentin Monnet  * 		**sendmsg**\ () or **sendfile**\ () system call, the first
1687ab127040SQuentin Monnet  * 		*bytes* will be sent and the eBPF program will be re-run with
1688ab127040SQuentin Monnet  * 		the pointer for start of data pointing to byte number *bytes*
1689ab127040SQuentin Monnet  * 		**+ 1**. If *bytes* is larger than the current data being
1690ab127040SQuentin Monnet  * 		processed, then the eBPF verdict will be applied to multiple
1691ab127040SQuentin Monnet  * 		**sendmsg**\ () or **sendfile**\ () calls until *bytes* are
1692ab127040SQuentin Monnet  * 		consumed.
1693ab127040SQuentin Monnet  *
1694ab127040SQuentin Monnet  * 		Note that if a socket closes with the internal counter holding
1695ab127040SQuentin Monnet  * 		a non-zero value, this is not a problem because data is not
1696ab127040SQuentin Monnet  * 		being buffered for *bytes* and is sent as it is received.
1697ab127040SQuentin Monnet  * 	Return
1698ab127040SQuentin Monnet  * 		0
1699ab127040SQuentin Monnet  *
1700ab127040SQuentin Monnet  * int bpf_msg_cork_bytes(struct sk_msg_buff *msg, u32 bytes)
1701ab127040SQuentin Monnet  * 	Description
1702ab127040SQuentin Monnet  * 		For socket policies, prevent the execution of the verdict eBPF
1703ab127040SQuentin Monnet  * 		program for message *msg* until *bytes* (byte number) have been
1704ab127040SQuentin Monnet  * 		accumulated.
1705ab127040SQuentin Monnet  *
1706ab127040SQuentin Monnet  * 		This can be used when one needs a specific number of bytes
1707ab127040SQuentin Monnet  * 		before a verdict can be assigned, even if the data spans
1708ab127040SQuentin Monnet  * 		multiple **sendmsg**\ () or **sendfile**\ () calls. The extreme
1709ab127040SQuentin Monnet  * 		case would be a user calling **sendmsg**\ () repeatedly with
1710ab127040SQuentin Monnet  * 		1-byte long message segments. Obviously, this is bad for
1711ab127040SQuentin Monnet  * 		performance, but it is still valid. If the eBPF program needs
1712ab127040SQuentin Monnet  * 		*bytes* bytes to validate a header, this helper can be used to
1713ab127040SQuentin Monnet  * 		prevent the eBPF program to be called again until *bytes* have
1714ab127040SQuentin Monnet  * 		been accumulated.
1715ab127040SQuentin Monnet  * 	Return
1716ab127040SQuentin Monnet  * 		0
1717ab127040SQuentin Monnet  *
1718ab127040SQuentin Monnet  * int bpf_msg_pull_data(struct sk_msg_buff *msg, u32 start, u32 end, u64 flags)
1719ab127040SQuentin Monnet  * 	Description
1720ab127040SQuentin Monnet  * 		For socket policies, pull in non-linear data from user space
1721ab127040SQuentin Monnet  * 		for *msg* and set pointers *msg*\ **->data** and *msg*\
1722ab127040SQuentin Monnet  * 		**->data_end** to *start* and *end* bytes offsets into *msg*,
1723ab127040SQuentin Monnet  * 		respectively.
1724ab127040SQuentin Monnet  *
1725ab127040SQuentin Monnet  * 		If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
1726ab127040SQuentin Monnet  * 		*msg* it can only parse data that the (**data**, **data_end**)
1727ab127040SQuentin Monnet  * 		pointers have already consumed. For **sendmsg**\ () hooks this
1728ab127040SQuentin Monnet  * 		is likely the first scatterlist element. But for calls relying
1729ab127040SQuentin Monnet  * 		on the **sendpage** handler (e.g. **sendfile**\ ()) this will
1730ab127040SQuentin Monnet  * 		be the range (**0**, **0**) because the data is shared with
1731ab127040SQuentin Monnet  * 		user space and by default the objective is to avoid allowing
1732ab127040SQuentin Monnet  * 		user space to modify data while (or after) eBPF verdict is
1733ab127040SQuentin Monnet  * 		being decided. This helper can be used to pull in data and to
1734ab127040SQuentin Monnet  * 		set the start and end pointer to given values. Data will be
1735ab127040SQuentin Monnet  * 		copied if necessary (i.e. if data was not linear and if start
1736ab127040SQuentin Monnet  * 		and end pointers do not point to the same chunk).
1737ab127040SQuentin Monnet  *
1738ab127040SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
1739ab127040SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1740ab127040SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1741ab127040SQuentin Monnet  * 		performed again, if the helper is used in combination with
1742ab127040SQuentin Monnet  * 		direct packet access.
1743ab127040SQuentin Monnet  *
1744ab127040SQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
1745ab127040SQuentin Monnet  * 		be left at zero.
1746ab127040SQuentin Monnet  * 	Return
1747ab127040SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1748ab127040SQuentin Monnet  *
1749a3ef8e9aSAndrey Ignatov  * int bpf_bind(struct bpf_sock_addr *ctx, struct sockaddr *addr, int addr_len)
17507aa79a86SQuentin Monnet  * 	Description
17517aa79a86SQuentin Monnet  * 		Bind the socket associated to *ctx* to the address pointed by
17527aa79a86SQuentin Monnet  * 		*addr*, of length *addr_len*. This allows for making outgoing
17537aa79a86SQuentin Monnet  * 		connection from the desired IP address, which can be useful for
17547aa79a86SQuentin Monnet  * 		example when all processes inside a cgroup should use one
17557aa79a86SQuentin Monnet  * 		single IP address on a host that has multiple IP configured.
17567aa79a86SQuentin Monnet  *
17577aa79a86SQuentin Monnet  * 		This helper works for IPv4 and IPv6, TCP and UDP sockets. The
17587aa79a86SQuentin Monnet  * 		domain (*addr*\ **->sa_family**) must be **AF_INET** (or
17597aa79a86SQuentin Monnet  * 		**AF_INET6**). Looking for a free port to bind to can be
17607aa79a86SQuentin Monnet  * 		expensive, therefore binding to port is not permitted by the
17617aa79a86SQuentin Monnet  * 		helper: *addr*\ **->sin_port** (or **sin6_port**, respectively)
17627aa79a86SQuentin Monnet  * 		must be set to zero.
17637aa79a86SQuentin Monnet  * 	Return
17647aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
17652d020dd7SQuentin Monnet  *
17662d020dd7SQuentin Monnet  * int bpf_xdp_adjust_tail(struct xdp_buff *xdp_md, int delta)
17672d020dd7SQuentin Monnet  * 	Description
17682d020dd7SQuentin Monnet  * 		Adjust (move) *xdp_md*\ **->data_end** by *delta* bytes. It is
17692d020dd7SQuentin Monnet  * 		only possible to shrink the packet as of this writing,
17702d020dd7SQuentin Monnet  * 		therefore *delta* must be a negative integer.
17712d020dd7SQuentin Monnet  *
17722d020dd7SQuentin Monnet  * 		A call to this helper is susceptible to change the underlaying
17732d020dd7SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
17742d020dd7SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
17752d020dd7SQuentin Monnet  * 		performed again, if the helper is used in combination with
17762d020dd7SQuentin Monnet  * 		direct packet access.
17772d020dd7SQuentin Monnet  * 	Return
17782d020dd7SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
17792d020dd7SQuentin Monnet  *
17802d020dd7SQuentin Monnet  * int bpf_skb_get_xfrm_state(struct sk_buff *skb, u32 index, struct bpf_xfrm_state *xfrm_state, u32 size, u64 flags)
17812d020dd7SQuentin Monnet  * 	Description
17822d020dd7SQuentin Monnet  * 		Retrieve the XFRM state (IP transform framework, see also
17832d020dd7SQuentin Monnet  * 		**ip-xfrm(8)**) at *index* in XFRM "security path" for *skb*.
17842d020dd7SQuentin Monnet  *
17852d020dd7SQuentin Monnet  * 		The retrieved value is stored in the **struct bpf_xfrm_state**
17862d020dd7SQuentin Monnet  * 		pointed by *xfrm_state* and of length *size*.
17872d020dd7SQuentin Monnet  *
17882d020dd7SQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
17892d020dd7SQuentin Monnet  * 		be left at zero.
17902d020dd7SQuentin Monnet  *
17912d020dd7SQuentin Monnet  * 		This helper is available only if the kernel was compiled with
17922d020dd7SQuentin Monnet  * 		**CONFIG_XFRM** configuration option.
17932d020dd7SQuentin Monnet  * 	Return
17942d020dd7SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1795c195651eSYonghong Song  *
1796c195651eSYonghong Song  * int bpf_get_stack(struct pt_regs *regs, void *buf, u32 size, u64 flags)
1797c195651eSYonghong Song  * 	Description
1798c195651eSYonghong Song  * 		Return a user or a kernel stack in bpf program provided buffer.
1799c195651eSYonghong Song  * 		To achieve this, the helper needs *ctx*, which is a pointer
1800c195651eSYonghong Song  * 		to the context on which the tracing program is executed.
1801c195651eSYonghong Song  * 		To store the stacktrace, the bpf program provides *buf* with
1802c195651eSYonghong Song  * 		a nonnegative *size*.
1803c195651eSYonghong Song  *
1804c195651eSYonghong Song  * 		The last argument, *flags*, holds the number of stack frames to
1805c195651eSYonghong Song  * 		skip (from 0 to 255), masked with
1806c195651eSYonghong Song  * 		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
1807c195651eSYonghong Song  * 		the following flags:
1808c195651eSYonghong Song  *
1809c195651eSYonghong Song  * 		**BPF_F_USER_STACK**
1810c195651eSYonghong Song  * 			Collect a user space stack instead of a kernel stack.
1811c195651eSYonghong Song  * 		**BPF_F_USER_BUILD_ID**
1812c195651eSYonghong Song  * 			Collect buildid+offset instead of ips for user stack,
1813c195651eSYonghong Song  * 			only valid if **BPF_F_USER_STACK** is also specified.
1814c195651eSYonghong Song  *
1815c195651eSYonghong Song  * 		**bpf_get_stack**\ () can collect up to
1816c195651eSYonghong Song  * 		**PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
1817c195651eSYonghong Song  * 		to sufficient large buffer size. Note that
1818c195651eSYonghong Song  * 		this limit can be controlled with the **sysctl** program, and
1819c195651eSYonghong Song  * 		that it should be manually increased in order to profile long
1820c195651eSYonghong Song  * 		user stacks (such as stacks for Java programs). To do so, use:
1821c195651eSYonghong Song  *
1822c195651eSYonghong Song  * 		::
1823c195651eSYonghong Song  *
1824c195651eSYonghong Song  * 			# sysctl kernel.perf_event_max_stack=<new value>
1825c195651eSYonghong Song  * 	Return
18267a279e93SQuentin Monnet  * 		A non-negative value equal to or less than *size* on success,
18277a279e93SQuentin Monnet  * 		or a negative error in case of failure.
18284e1ec56cSDaniel Borkmann  *
18292bae79d2SQuentin Monnet  * int bpf_skb_load_bytes_relative(const struct sk_buff *skb, u32 offset, void *to, u32 len, u32 start_header)
18304e1ec56cSDaniel Borkmann  * 	Description
18314e1ec56cSDaniel Borkmann  * 		This helper is similar to **bpf_skb_load_bytes**\ () in that
18324e1ec56cSDaniel Borkmann  * 		it provides an easy way to load *len* bytes from *offset*
18334e1ec56cSDaniel Borkmann  * 		from the packet associated to *skb*, into the buffer pointed
18344e1ec56cSDaniel Borkmann  * 		by *to*. The difference to **bpf_skb_load_bytes**\ () is that
18354e1ec56cSDaniel Borkmann  * 		a fifth argument *start_header* exists in order to select a
18364e1ec56cSDaniel Borkmann  * 		base offset to start from. *start_header* can be one of:
18374e1ec56cSDaniel Borkmann  *
18384e1ec56cSDaniel Borkmann  * 		**BPF_HDR_START_MAC**
18394e1ec56cSDaniel Borkmann  * 			Base offset to load data from is *skb*'s mac header.
18404e1ec56cSDaniel Borkmann  * 		**BPF_HDR_START_NET**
18414e1ec56cSDaniel Borkmann  * 			Base offset to load data from is *skb*'s network header.
18424e1ec56cSDaniel Borkmann  *
18434e1ec56cSDaniel Borkmann  * 		In general, "direct packet access" is the preferred method to
18444e1ec56cSDaniel Borkmann  * 		access packet data, however, this helper is in particular useful
18454e1ec56cSDaniel Borkmann  * 		in socket filters where *skb*\ **->data** does not always point
18464e1ec56cSDaniel Borkmann  * 		to the start of the mac header and where "direct packet access"
18474e1ec56cSDaniel Borkmann  * 		is not available.
18484e1ec56cSDaniel Borkmann  * 	Return
18494e1ec56cSDaniel Borkmann  * 		0 on success, or a negative error in case of failure.
18504e1ec56cSDaniel Borkmann  *
185187f5fc7eSDavid Ahern  * int bpf_fib_lookup(void *ctx, struct bpf_fib_lookup *params, int plen, u32 flags)
185287f5fc7eSDavid Ahern  *	Description
185387f5fc7eSDavid Ahern  *		Do FIB lookup in kernel tables using parameters in *params*.
185487f5fc7eSDavid Ahern  *		If lookup is successful and result shows packet is to be
185587f5fc7eSDavid Ahern  *		forwarded, the neighbor tables are searched for the nexthop.
185687f5fc7eSDavid Ahern  *		If successful (ie., FIB lookup shows forwarding and nexthop
1857fa898d76SDavid Ahern  *		is resolved), the nexthop address is returned in ipv4_dst
1858fa898d76SDavid Ahern  *		or ipv6_dst based on family, smac is set to mac address of
1859fa898d76SDavid Ahern  *		egress device, dmac is set to nexthop mac address, rt_metric
18604c79579bSDavid Ahern  *		is set to metric from route (IPv4/IPv6 only), and ifindex
18614c79579bSDavid Ahern  *		is set to the device index of the nexthop from the FIB lookup.
186287f5fc7eSDavid Ahern  *
186387f5fc7eSDavid Ahern  *             *plen* argument is the size of the passed in struct.
18647a279e93SQuentin Monnet  *             *flags* argument can be a combination of one or more of the
18657a279e93SQuentin Monnet  *             following values:
186687f5fc7eSDavid Ahern  *
18677a279e93SQuentin Monnet  *		**BPF_FIB_LOOKUP_DIRECT**
18687a279e93SQuentin Monnet  *			Do a direct table lookup vs full lookup using FIB
18697a279e93SQuentin Monnet  *			rules.
18707a279e93SQuentin Monnet  *		**BPF_FIB_LOOKUP_OUTPUT**
18717a279e93SQuentin Monnet  *			Perform lookup from an egress perspective (default is
18727a279e93SQuentin Monnet  *			ingress).
187387f5fc7eSDavid Ahern  *
187487f5fc7eSDavid Ahern  *             *ctx* is either **struct xdp_md** for XDP programs or
187587f5fc7eSDavid Ahern  *             **struct sk_buff** tc cls_act programs.
187687f5fc7eSDavid Ahern  *     Return
18774c79579bSDavid Ahern  *		* < 0 if any input argument is invalid
18784c79579bSDavid Ahern  *		*   0 on success (packet is forwarded, nexthop neighbor exists)
18794c79579bSDavid Ahern  *		* > 0 one of **BPF_FIB_LKUP_RET_** codes explaining why the
18802bae79d2SQuentin Monnet  *		  packet is not forwarded or needs assist from full stack
188181110384SJohn Fastabend  *
188281110384SJohn Fastabend  * int bpf_sock_hash_update(struct bpf_sock_ops_kern *skops, struct bpf_map *map, void *key, u64 flags)
188381110384SJohn Fastabend  *	Description
188481110384SJohn Fastabend  *		Add an entry to, or update a sockhash *map* referencing sockets.
188581110384SJohn Fastabend  *		The *skops* is used as a new value for the entry associated to
188681110384SJohn Fastabend  *		*key*. *flags* is one of:
188781110384SJohn Fastabend  *
188881110384SJohn Fastabend  *		**BPF_NOEXIST**
188981110384SJohn Fastabend  *			The entry for *key* must not exist in the map.
189081110384SJohn Fastabend  *		**BPF_EXIST**
189181110384SJohn Fastabend  *			The entry for *key* must already exist in the map.
189281110384SJohn Fastabend  *		**BPF_ANY**
189381110384SJohn Fastabend  *			No condition on the existence of the entry for *key*.
189481110384SJohn Fastabend  *
189581110384SJohn Fastabend  *		If the *map* has eBPF programs (parser and verdict), those will
189681110384SJohn Fastabend  *		be inherited by the socket being added. If the socket is
189781110384SJohn Fastabend  *		already attached to eBPF programs, this results in an error.
189881110384SJohn Fastabend  *	Return
189981110384SJohn Fastabend  *		0 on success, or a negative error in case of failure.
190081110384SJohn Fastabend  *
190181110384SJohn Fastabend  * int bpf_msg_redirect_hash(struct sk_msg_buff *msg, struct bpf_map *map, void *key, u64 flags)
190281110384SJohn Fastabend  *	Description
190381110384SJohn Fastabend  *		This helper is used in programs implementing policies at the
190481110384SJohn Fastabend  *		socket level. If the message *msg* is allowed to pass (i.e. if
190581110384SJohn Fastabend  *		the verdict eBPF program returns **SK_PASS**), redirect it to
190681110384SJohn Fastabend  *		the socket referenced by *map* (of type
190781110384SJohn Fastabend  *		**BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
190881110384SJohn Fastabend  *		egress interfaces can be used for redirection. The
190981110384SJohn Fastabend  *		**BPF_F_INGRESS** value in *flags* is used to make the
191081110384SJohn Fastabend  *		distinction (ingress path is selected if the flag is present,
191181110384SJohn Fastabend  *		egress path otherwise). This is the only flag supported for now.
191281110384SJohn Fastabend  *	Return
191381110384SJohn Fastabend  *		**SK_PASS** on success, or **SK_DROP** on error.
191481110384SJohn Fastabend  *
191581110384SJohn Fastabend  * int bpf_sk_redirect_hash(struct sk_buff *skb, struct bpf_map *map, void *key, u64 flags)
191681110384SJohn Fastabend  *	Description
191781110384SJohn Fastabend  *		This helper is used in programs implementing policies at the
191881110384SJohn Fastabend  *		skb socket level. If the sk_buff *skb* is allowed to pass (i.e.
191981110384SJohn Fastabend  *		if the verdeict eBPF program returns **SK_PASS**), redirect it
192081110384SJohn Fastabend  *		to the socket referenced by *map* (of type
192181110384SJohn Fastabend  *		**BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
192281110384SJohn Fastabend  *		egress interfaces can be used for redirection. The
192381110384SJohn Fastabend  *		**BPF_F_INGRESS** value in *flags* is used to make the
192481110384SJohn Fastabend  *		distinction (ingress path is selected if the flag is present,
192581110384SJohn Fastabend  *		egress otherwise). This is the only flag supported for now.
192681110384SJohn Fastabend  *	Return
192781110384SJohn Fastabend  *		**SK_PASS** on success, or **SK_DROP** on error.
1928fe94cc29SMathieu Xhonneux  *
1929fe94cc29SMathieu Xhonneux  * int bpf_lwt_push_encap(struct sk_buff *skb, u32 type, void *hdr, u32 len)
1930fe94cc29SMathieu Xhonneux  *	Description
1931fe94cc29SMathieu Xhonneux  *		Encapsulate the packet associated to *skb* within a Layer 3
1932fe94cc29SMathieu Xhonneux  *		protocol header. This header is provided in the buffer at
1933fe94cc29SMathieu Xhonneux  *		address *hdr*, with *len* its size in bytes. *type* indicates
1934fe94cc29SMathieu Xhonneux  *		the protocol of the header and can be one of:
1935fe94cc29SMathieu Xhonneux  *
1936fe94cc29SMathieu Xhonneux  *		**BPF_LWT_ENCAP_SEG6**
1937fe94cc29SMathieu Xhonneux  *			IPv6 encapsulation with Segment Routing Header
1938fe94cc29SMathieu Xhonneux  *			(**struct ipv6_sr_hdr**). *hdr* only contains the SRH,
1939fe94cc29SMathieu Xhonneux  *			the IPv6 header is computed by the kernel.
1940fe94cc29SMathieu Xhonneux  *		**BPF_LWT_ENCAP_SEG6_INLINE**
1941fe94cc29SMathieu Xhonneux  *			Only works if *skb* contains an IPv6 packet. Insert a
1942fe94cc29SMathieu Xhonneux  *			Segment Routing Header (**struct ipv6_sr_hdr**) inside
1943fe94cc29SMathieu Xhonneux  *			the IPv6 header.
1944fe94cc29SMathieu Xhonneux  *
1945fe94cc29SMathieu Xhonneux  * 		A call to this helper is susceptible to change the underlaying
1946fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
1947fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
1948fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
1949fe94cc29SMathieu Xhonneux  * 		direct packet access.
1950fe94cc29SMathieu Xhonneux  *	Return
1951fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
1952fe94cc29SMathieu Xhonneux  *
1953fe94cc29SMathieu Xhonneux  * int bpf_lwt_seg6_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len)
1954fe94cc29SMathieu Xhonneux  *	Description
1955fe94cc29SMathieu Xhonneux  *		Store *len* bytes from address *from* into the packet
1956fe94cc29SMathieu Xhonneux  *		associated to *skb*, at *offset*. Only the flags, tag and TLVs
1957fe94cc29SMathieu Xhonneux  *		inside the outermost IPv6 Segment Routing Header can be
1958fe94cc29SMathieu Xhonneux  *		modified through this helper.
1959fe94cc29SMathieu Xhonneux  *
1960fe94cc29SMathieu Xhonneux  * 		A call to this helper is susceptible to change the underlaying
1961fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
1962fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
1963fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
1964fe94cc29SMathieu Xhonneux  * 		direct packet access.
1965fe94cc29SMathieu Xhonneux  *	Return
1966fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
1967fe94cc29SMathieu Xhonneux  *
1968fe94cc29SMathieu Xhonneux  * int bpf_lwt_seg6_adjust_srh(struct sk_buff *skb, u32 offset, s32 delta)
1969fe94cc29SMathieu Xhonneux  *	Description
1970fe94cc29SMathieu Xhonneux  *		Adjust the size allocated to TLVs in the outermost IPv6
1971fe94cc29SMathieu Xhonneux  *		Segment Routing Header contained in the packet associated to
1972fe94cc29SMathieu Xhonneux  *		*skb*, at position *offset* by *delta* bytes. Only offsets
1973fe94cc29SMathieu Xhonneux  *		after the segments are accepted. *delta* can be as well
1974fe94cc29SMathieu Xhonneux  *		positive (growing) as negative (shrinking).
1975fe94cc29SMathieu Xhonneux  *
1976fe94cc29SMathieu Xhonneux  * 		A call to this helper is susceptible to change the underlaying
1977fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
1978fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
1979fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
1980fe94cc29SMathieu Xhonneux  * 		direct packet access.
1981fe94cc29SMathieu Xhonneux  *	Return
1982fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
1983fe94cc29SMathieu Xhonneux  *
1984fe94cc29SMathieu Xhonneux  * int bpf_lwt_seg6_action(struct sk_buff *skb, u32 action, void *param, u32 param_len)
1985fe94cc29SMathieu Xhonneux  *	Description
1986fe94cc29SMathieu Xhonneux  *		Apply an IPv6 Segment Routing action of type *action* to the
1987fe94cc29SMathieu Xhonneux  *		packet associated to *skb*. Each action takes a parameter
1988fe94cc29SMathieu Xhonneux  *		contained at address *param*, and of length *param_len* bytes.
1989fe94cc29SMathieu Xhonneux  *		*action* can be one of:
1990fe94cc29SMathieu Xhonneux  *
1991fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_X**
1992fe94cc29SMathieu Xhonneux  *			End.X action: Endpoint with Layer-3 cross-connect.
1993fe94cc29SMathieu Xhonneux  *			Type of *param*: **struct in6_addr**.
1994fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_T**
1995fe94cc29SMathieu Xhonneux  *			End.T action: Endpoint with specific IPv6 table lookup.
1996fe94cc29SMathieu Xhonneux  *			Type of *param*: **int**.
1997fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_B6**
1998fe94cc29SMathieu Xhonneux  *			End.B6 action: Endpoint bound to an SRv6 policy.
1999fe94cc29SMathieu Xhonneux  *			Type of param: **struct ipv6_sr_hdr**.
2000fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_B6_ENCAP**
2001fe94cc29SMathieu Xhonneux  *			End.B6.Encap action: Endpoint bound to an SRv6
2002fe94cc29SMathieu Xhonneux  *			encapsulation policy.
2003fe94cc29SMathieu Xhonneux  *			Type of param: **struct ipv6_sr_hdr**.
2004fe94cc29SMathieu Xhonneux  *
2005fe94cc29SMathieu Xhonneux  * 		A call to this helper is susceptible to change the underlaying
2006fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
2007fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
2008fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
2009fe94cc29SMathieu Xhonneux  * 		direct packet access.
2010fe94cc29SMathieu Xhonneux  *	Return
2011fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
2012f4364dcfSSean Young  *
2013f4364dcfSSean Young  * int bpf_rc_keydown(void *ctx, u32 protocol, u64 scancode, u32 toggle)
2014f4364dcfSSean Young  *	Description
2015f4364dcfSSean Young  *		This helper is used in programs implementing IR decoding, to
2016f4364dcfSSean Young  *		report a successfully decoded key press with *scancode*,
2017f4364dcfSSean Young  *		*toggle* value in the given *protocol*. The scancode will be
2018f4364dcfSSean Young  *		translated to a keycode using the rc keymap, and reported as
2019f4364dcfSSean Young  *		an input key down event. After a period a key up event is
2020f4364dcfSSean Young  *		generated. This period can be extended by calling either
2021f4364dcfSSean Young  *		**bpf_rc_keydown** () again with the same values, or calling
2022f4364dcfSSean Young  *		**bpf_rc_repeat** ().
2023f4364dcfSSean Young  *
2024f4364dcfSSean Young  *		Some protocols include a toggle bit, in case the button	was
2025f4364dcfSSean Young  *		released and pressed again between consecutive scancodes.
2026f4364dcfSSean Young  *
2027f4364dcfSSean Young  *		The *ctx* should point to the lirc sample as passed into
2028f4364dcfSSean Young  *		the program.
2029f4364dcfSSean Young  *
2030f4364dcfSSean Young  *		The *protocol* is the decoded protocol number (see
2031f4364dcfSSean Young  *		**enum rc_proto** for some predefined values).
2032f4364dcfSSean Young  *
2033f4364dcfSSean Young  *		This helper is only available is the kernel was compiled with
2034f4364dcfSSean Young  *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
2035f4364dcfSSean Young  *		"**y**".
2036f4364dcfSSean Young  *	Return
2037f4364dcfSSean Young  *		0
2038f4364dcfSSean Young  *
2039f4364dcfSSean Young  * int bpf_rc_repeat(void *ctx)
2040f4364dcfSSean Young  *	Description
2041f4364dcfSSean Young  *		This helper is used in programs implementing IR decoding, to
2042f4364dcfSSean Young  *		report a successfully decoded repeat key message. This delays
2043f4364dcfSSean Young  *		the generation of a key up event for previously generated
2044f4364dcfSSean Young  *		key down event.
2045f4364dcfSSean Young  *
2046f4364dcfSSean Young  *		Some IR protocols like NEC have a special IR message for
2047f4364dcfSSean Young  *		repeating last button, for when a button is held down.
2048f4364dcfSSean Young  *
2049f4364dcfSSean Young  *		The *ctx* should point to the lirc sample as passed into
2050f4364dcfSSean Young  *		the program.
2051f4364dcfSSean Young  *
2052f4364dcfSSean Young  *		This helper is only available is the kernel was compiled with
2053f4364dcfSSean Young  *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
2054f4364dcfSSean Young  *		"**y**".
2055f4364dcfSSean Young  *	Return
2056f4364dcfSSean Young  *		0
2057cb20b08eSDaniel Borkmann  *
2058cb20b08eSDaniel Borkmann  * uint64_t bpf_skb_cgroup_id(struct sk_buff *skb)
2059cb20b08eSDaniel Borkmann  * 	Description
2060cb20b08eSDaniel Borkmann  * 		Return the cgroup v2 id of the socket associated with the *skb*.
2061cb20b08eSDaniel Borkmann  * 		This is roughly similar to the **bpf_get_cgroup_classid**\ ()
2062cb20b08eSDaniel Borkmann  * 		helper for cgroup v1 by providing a tag resp. identifier that
2063cb20b08eSDaniel Borkmann  * 		can be matched on or used for map lookups e.g. to implement
2064cb20b08eSDaniel Borkmann  * 		policy. The cgroup v2 id of a given path in the hierarchy is
2065cb20b08eSDaniel Borkmann  * 		exposed in user space through the f_handle API in order to get
2066cb20b08eSDaniel Borkmann  * 		to the same 64-bit id.
2067cb20b08eSDaniel Borkmann  *
2068cb20b08eSDaniel Borkmann  * 		This helper can be used on TC egress path, but not on ingress,
2069cb20b08eSDaniel Borkmann  * 		and is available only if the kernel was compiled with the
2070cb20b08eSDaniel Borkmann  * 		**CONFIG_SOCK_CGROUP_DATA** configuration option.
2071cb20b08eSDaniel Borkmann  * 	Return
2072cb20b08eSDaniel Borkmann  * 		The id is returned or 0 in case the id could not be retrieved.
2073bf6fa2c8SYonghong Song  *
2074bf6fa2c8SYonghong Song  * u64 bpf_get_current_cgroup_id(void)
2075bf6fa2c8SYonghong Song  * 	Return
2076bf6fa2c8SYonghong Song  * 		A 64-bit integer containing the current cgroup id based
2077bf6fa2c8SYonghong Song  * 		on the cgroup within which the current task is running.
20787a4b28c6SDaniel Borkmann  */
2079ebb676daSThomas Graf #define __BPF_FUNC_MAPPER(FN)		\
2080ebb676daSThomas Graf 	FN(unspec),			\
2081ebb676daSThomas Graf 	FN(map_lookup_elem),		\
2082ebb676daSThomas Graf 	FN(map_update_elem),		\
2083ebb676daSThomas Graf 	FN(map_delete_elem),		\
2084ebb676daSThomas Graf 	FN(probe_read),			\
2085ebb676daSThomas Graf 	FN(ktime_get_ns),		\
2086ebb676daSThomas Graf 	FN(trace_printk),		\
2087ebb676daSThomas Graf 	FN(get_prandom_u32),		\
2088ebb676daSThomas Graf 	FN(get_smp_processor_id),	\
2089ebb676daSThomas Graf 	FN(skb_store_bytes),		\
2090ebb676daSThomas Graf 	FN(l3_csum_replace),		\
2091ebb676daSThomas Graf 	FN(l4_csum_replace),		\
2092ebb676daSThomas Graf 	FN(tail_call),			\
2093ebb676daSThomas Graf 	FN(clone_redirect),		\
2094ebb676daSThomas Graf 	FN(get_current_pid_tgid),	\
2095ebb676daSThomas Graf 	FN(get_current_uid_gid),	\
2096ebb676daSThomas Graf 	FN(get_current_comm),		\
2097ebb676daSThomas Graf 	FN(get_cgroup_classid),		\
2098ebb676daSThomas Graf 	FN(skb_vlan_push),		\
2099ebb676daSThomas Graf 	FN(skb_vlan_pop),		\
2100ebb676daSThomas Graf 	FN(skb_get_tunnel_key),		\
2101ebb676daSThomas Graf 	FN(skb_set_tunnel_key),		\
2102ebb676daSThomas Graf 	FN(perf_event_read),		\
2103ebb676daSThomas Graf 	FN(redirect),			\
2104ebb676daSThomas Graf 	FN(get_route_realm),		\
2105ebb676daSThomas Graf 	FN(perf_event_output),		\
2106ebb676daSThomas Graf 	FN(skb_load_bytes),		\
2107ebb676daSThomas Graf 	FN(get_stackid),		\
2108ebb676daSThomas Graf 	FN(csum_diff),			\
2109ebb676daSThomas Graf 	FN(skb_get_tunnel_opt),		\
2110ebb676daSThomas Graf 	FN(skb_set_tunnel_opt),		\
2111ebb676daSThomas Graf 	FN(skb_change_proto),		\
2112ebb676daSThomas Graf 	FN(skb_change_type),		\
2113ebb676daSThomas Graf 	FN(skb_under_cgroup),		\
2114ebb676daSThomas Graf 	FN(get_hash_recalc),		\
2115ebb676daSThomas Graf 	FN(get_current_task),		\
2116ebb676daSThomas Graf 	FN(probe_write_user),		\
2117ebb676daSThomas Graf 	FN(current_task_under_cgroup),	\
2118ebb676daSThomas Graf 	FN(skb_change_tail),		\
2119ebb676daSThomas Graf 	FN(skb_pull_data),		\
2120ebb676daSThomas Graf 	FN(csum_update),		\
2121ebb676daSThomas Graf 	FN(set_hash_invalid),		\
21223a0af8fdSThomas Graf 	FN(get_numa_node_id),		\
212317bedab2SMartin KaFai Lau 	FN(skb_change_head),		\
2124a5e8c070SGianluca Borello 	FN(xdp_adjust_head),		\
212591b8270fSChenbo Feng 	FN(probe_read_str),		\
21266acc5c29SChenbo Feng 	FN(get_socket_cookie),		\
2127ded092cdSDaniel Borkmann 	FN(get_socket_uid),		\
21288c4b4c7eSLawrence Brakmo 	FN(set_hash),			\
21292be7e212SDaniel Borkmann 	FN(setsockopt),			\
213097f91a7cSJohn Fastabend 	FN(skb_adjust_room),		\
2131174a79ffSJohn Fastabend 	FN(redirect_map),		\
2132174a79ffSJohn Fastabend 	FN(sk_redirect_map),		\
2133174a79ffSJohn Fastabend 	FN(sock_map_update),		\
2134908432caSYonghong Song 	FN(xdp_adjust_meta),		\
21354bebdc7aSYonghong Song 	FN(perf_event_read_value),	\
2136cd86d1fdSLawrence Brakmo 	FN(perf_prog_read_value),	\
21379802d865SJosef Bacik 	FN(getsockopt),			\
2138b13d8807SLawrence Brakmo 	FN(override_return),		\
21394f738adbSJohn Fastabend 	FN(sock_ops_cb_flags_set),	\
21402a100317SJohn Fastabend 	FN(msg_redirect_map),		\
214191843d54SJohn Fastabend 	FN(msg_apply_bytes),		\
2142015632bbSJohn Fastabend 	FN(msg_cork_bytes),		\
2143d74bad4eSAndrey Ignatov 	FN(msg_pull_data),		\
2144b32cc5b9SNikita V. Shirokov 	FN(bind),			\
214512bed760SEyal Birger 	FN(xdp_adjust_tail),		\
2146c195651eSYonghong Song 	FN(skb_get_xfrm_state),		\
21474e1ec56cSDaniel Borkmann 	FN(get_stack),			\
214887f5fc7eSDavid Ahern 	FN(skb_load_bytes_relative),	\
214981110384SJohn Fastabend 	FN(fib_lookup),			\
215081110384SJohn Fastabend 	FN(sock_hash_update),		\
215181110384SJohn Fastabend 	FN(msg_redirect_hash),		\
2152fe94cc29SMathieu Xhonneux 	FN(sk_redirect_hash),		\
2153fe94cc29SMathieu Xhonneux 	FN(lwt_push_encap),		\
2154fe94cc29SMathieu Xhonneux 	FN(lwt_seg6_store_bytes),	\
2155fe94cc29SMathieu Xhonneux 	FN(lwt_seg6_adjust_srh),	\
2156f4364dcfSSean Young 	FN(lwt_seg6_action),		\
2157f4364dcfSSean Young 	FN(rc_repeat),			\
2158cb20b08eSDaniel Borkmann 	FN(rc_keydown),			\
2159bf6fa2c8SYonghong Song 	FN(skb_cgroup_id),		\
2160bf6fa2c8SYonghong Song 	FN(get_current_cgroup_id),
21617a4b28c6SDaniel Borkmann 
2162ebb676daSThomas Graf /* integer value in 'imm' field of BPF_CALL instruction selects which helper
2163ebb676daSThomas Graf  * function eBPF program intends to call
21642d0e30c3SDaniel Borkmann  */
2165ebb676daSThomas Graf #define __BPF_ENUM_FN(x) BPF_FUNC_ ## x
2166ebb676daSThomas Graf enum bpf_func_id {
2167ebb676daSThomas Graf 	__BPF_FUNC_MAPPER(__BPF_ENUM_FN)
216809756af4SAlexei Starovoitov 	__BPF_FUNC_MAX_ID,
216909756af4SAlexei Starovoitov };
2170ebb676daSThomas Graf #undef __BPF_ENUM_FN
217109756af4SAlexei Starovoitov 
2172781c53bcSDaniel Borkmann /* All flags used by eBPF helper functions, placed here. */
2173781c53bcSDaniel Borkmann 
2174781c53bcSDaniel Borkmann /* BPF_FUNC_skb_store_bytes flags. */
2175781c53bcSDaniel Borkmann #define BPF_F_RECOMPUTE_CSUM		(1ULL << 0)
21768afd54c8SDaniel Borkmann #define BPF_F_INVALIDATE_HASH		(1ULL << 1)
2177781c53bcSDaniel Borkmann 
2178781c53bcSDaniel Borkmann /* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
2179781c53bcSDaniel Borkmann  * First 4 bits are for passing the header field size.
2180781c53bcSDaniel Borkmann  */
2181781c53bcSDaniel Borkmann #define BPF_F_HDR_FIELD_MASK		0xfULL
2182781c53bcSDaniel Borkmann 
2183781c53bcSDaniel Borkmann /* BPF_FUNC_l4_csum_replace flags. */
2184781c53bcSDaniel Borkmann #define BPF_F_PSEUDO_HDR		(1ULL << 4)
21852f72959aSDaniel Borkmann #define BPF_F_MARK_MANGLED_0		(1ULL << 5)
2186d1b662adSDaniel Borkmann #define BPF_F_MARK_ENFORCE		(1ULL << 6)
2187781c53bcSDaniel Borkmann 
2188781c53bcSDaniel Borkmann /* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */
2189781c53bcSDaniel Borkmann #define BPF_F_INGRESS			(1ULL << 0)
2190781c53bcSDaniel Borkmann 
2191c6c33454SDaniel Borkmann /* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */
2192c6c33454SDaniel Borkmann #define BPF_F_TUNINFO_IPV6		(1ULL << 0)
2193c6c33454SDaniel Borkmann 
2194c195651eSYonghong Song /* flags for both BPF_FUNC_get_stackid and BPF_FUNC_get_stack. */
2195d5a3b1f6SAlexei Starovoitov #define BPF_F_SKIP_FIELD_MASK		0xffULL
2196d5a3b1f6SAlexei Starovoitov #define BPF_F_USER_STACK		(1ULL << 8)
2197c195651eSYonghong Song /* flags used by BPF_FUNC_get_stackid only. */
2198d5a3b1f6SAlexei Starovoitov #define BPF_F_FAST_STACK_CMP		(1ULL << 9)
2199d5a3b1f6SAlexei Starovoitov #define BPF_F_REUSE_STACKID		(1ULL << 10)
2200c195651eSYonghong Song /* flags used by BPF_FUNC_get_stack only. */
2201c195651eSYonghong Song #define BPF_F_USER_BUILD_ID		(1ULL << 11)
2202d5a3b1f6SAlexei Starovoitov 
22032da897e5SDaniel Borkmann /* BPF_FUNC_skb_set_tunnel_key flags. */
22042da897e5SDaniel Borkmann #define BPF_F_ZERO_CSUM_TX		(1ULL << 1)
220522080870SDaniel Borkmann #define BPF_F_DONT_FRAGMENT		(1ULL << 2)
220677a5196aSWilliam Tu #define BPF_F_SEQ_NUMBER		(1ULL << 3)
22072da897e5SDaniel Borkmann 
2208908432caSYonghong Song /* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
2209908432caSYonghong Song  * BPF_FUNC_perf_event_read_value flags.
2210908432caSYonghong Song  */
22111e33759cSDaniel Borkmann #define BPF_F_INDEX_MASK		0xffffffffULL
22121e33759cSDaniel Borkmann #define BPF_F_CURRENT_CPU		BPF_F_INDEX_MASK
2213555c8a86SDaniel Borkmann /* BPF_FUNC_perf_event_output for sk_buff input context. */
2214555c8a86SDaniel Borkmann #define BPF_F_CTXLEN_MASK		(0xfffffULL << 32)
22151e33759cSDaniel Borkmann 
22162be7e212SDaniel Borkmann /* Mode for BPF_FUNC_skb_adjust_room helper. */
22172be7e212SDaniel Borkmann enum bpf_adj_room_mode {
22182be7e212SDaniel Borkmann 	BPF_ADJ_ROOM_NET,
22192be7e212SDaniel Borkmann };
22202be7e212SDaniel Borkmann 
22214e1ec56cSDaniel Borkmann /* Mode for BPF_FUNC_skb_load_bytes_relative helper. */
22224e1ec56cSDaniel Borkmann enum bpf_hdr_start_off {
22234e1ec56cSDaniel Borkmann 	BPF_HDR_START_MAC,
22244e1ec56cSDaniel Borkmann 	BPF_HDR_START_NET,
22254e1ec56cSDaniel Borkmann };
22264e1ec56cSDaniel Borkmann 
2227fe94cc29SMathieu Xhonneux /* Encapsulation type for BPF_FUNC_lwt_push_encap helper. */
2228fe94cc29SMathieu Xhonneux enum bpf_lwt_encap_mode {
2229fe94cc29SMathieu Xhonneux 	BPF_LWT_ENCAP_SEG6,
2230fe94cc29SMathieu Xhonneux 	BPF_LWT_ENCAP_SEG6_INLINE
2231fe94cc29SMathieu Xhonneux };
2232fe94cc29SMathieu Xhonneux 
22339bac3d6dSAlexei Starovoitov /* user accessible mirror of in-kernel sk_buff.
22349bac3d6dSAlexei Starovoitov  * new fields can only be added to the end of this structure
22359bac3d6dSAlexei Starovoitov  */
22369bac3d6dSAlexei Starovoitov struct __sk_buff {
22379bac3d6dSAlexei Starovoitov 	__u32 len;
22389bac3d6dSAlexei Starovoitov 	__u32 pkt_type;
22399bac3d6dSAlexei Starovoitov 	__u32 mark;
22409bac3d6dSAlexei Starovoitov 	__u32 queue_mapping;
2241c2497395SAlexei Starovoitov 	__u32 protocol;
2242c2497395SAlexei Starovoitov 	__u32 vlan_present;
2243c2497395SAlexei Starovoitov 	__u32 vlan_tci;
224427cd5452SMichal Sekletar 	__u32 vlan_proto;
2245bcad5718SDaniel Borkmann 	__u32 priority;
224637e82c2fSAlexei Starovoitov 	__u32 ingress_ifindex;
224737e82c2fSAlexei Starovoitov 	__u32 ifindex;
2248d691f9e8SAlexei Starovoitov 	__u32 tc_index;
2249d691f9e8SAlexei Starovoitov 	__u32 cb[5];
2250ba7591d8SDaniel Borkmann 	__u32 hash;
2251045efa82SDaniel Borkmann 	__u32 tc_classid;
2252969bf05eSAlexei Starovoitov 	__u32 data;
2253969bf05eSAlexei Starovoitov 	__u32 data_end;
2254b1d9fc41SDaniel Borkmann 	__u32 napi_id;
22558a31db56SJohn Fastabend 
2256de8f3a83SDaniel Borkmann 	/* Accessed by BPF_PROG_TYPE_sk_skb types from here to ... */
22578a31db56SJohn Fastabend 	__u32 family;
22588a31db56SJohn Fastabend 	__u32 remote_ip4;	/* Stored in network byte order */
22598a31db56SJohn Fastabend 	__u32 local_ip4;	/* Stored in network byte order */
22608a31db56SJohn Fastabend 	__u32 remote_ip6[4];	/* Stored in network byte order */
22618a31db56SJohn Fastabend 	__u32 local_ip6[4];	/* Stored in network byte order */
22628a31db56SJohn Fastabend 	__u32 remote_port;	/* Stored in network byte order */
22638a31db56SJohn Fastabend 	__u32 local_port;	/* stored in host byte order */
2264de8f3a83SDaniel Borkmann 	/* ... here. */
2265de8f3a83SDaniel Borkmann 
2266de8f3a83SDaniel Borkmann 	__u32 data_meta;
22679bac3d6dSAlexei Starovoitov };
22689bac3d6dSAlexei Starovoitov 
2269d3aa45ceSAlexei Starovoitov struct bpf_tunnel_key {
2270d3aa45ceSAlexei Starovoitov 	__u32 tunnel_id;
2271c6c33454SDaniel Borkmann 	union {
2272d3aa45ceSAlexei Starovoitov 		__u32 remote_ipv4;
2273c6c33454SDaniel Borkmann 		__u32 remote_ipv6[4];
2274c6c33454SDaniel Borkmann 	};
2275c6c33454SDaniel Borkmann 	__u8 tunnel_tos;
2276c6c33454SDaniel Borkmann 	__u8 tunnel_ttl;
22771fbc2e0cSDaniel Borkmann 	__u16 tunnel_ext;	/* Padding, future use. */
22784018ab18SDaniel Borkmann 	__u32 tunnel_label;
2279d3aa45ceSAlexei Starovoitov };
2280d3aa45ceSAlexei Starovoitov 
228112bed760SEyal Birger /* user accessible mirror of in-kernel xfrm_state.
228212bed760SEyal Birger  * new fields can only be added to the end of this structure
228312bed760SEyal Birger  */
228412bed760SEyal Birger struct bpf_xfrm_state {
228512bed760SEyal Birger 	__u32 reqid;
228612bed760SEyal Birger 	__u32 spi;	/* Stored in network byte order */
228712bed760SEyal Birger 	__u16 family;
22881fbc2e0cSDaniel Borkmann 	__u16 ext;	/* Padding, future use. */
228912bed760SEyal Birger 	union {
229012bed760SEyal Birger 		__u32 remote_ipv4;	/* Stored in network byte order */
229112bed760SEyal Birger 		__u32 remote_ipv6[4];	/* Stored in network byte order */
229212bed760SEyal Birger 	};
229312bed760SEyal Birger };
229412bed760SEyal Birger 
22953a0af8fdSThomas Graf /* Generic BPF return codes which all BPF program types may support.
22963a0af8fdSThomas Graf  * The values are binary compatible with their TC_ACT_* counter-part to
22973a0af8fdSThomas Graf  * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT
22983a0af8fdSThomas Graf  * programs.
22993a0af8fdSThomas Graf  *
23003a0af8fdSThomas Graf  * XDP is handled seprately, see XDP_*.
23013a0af8fdSThomas Graf  */
23023a0af8fdSThomas Graf enum bpf_ret_code {
23033a0af8fdSThomas Graf 	BPF_OK = 0,
23043a0af8fdSThomas Graf 	/* 1 reserved */
23053a0af8fdSThomas Graf 	BPF_DROP = 2,
23063a0af8fdSThomas Graf 	/* 3-6 reserved */
23073a0af8fdSThomas Graf 	BPF_REDIRECT = 7,
23083a0af8fdSThomas Graf 	/* >127 are reserved for prog type specific return codes */
23093a0af8fdSThomas Graf };
23103a0af8fdSThomas Graf 
231161023658SDavid Ahern struct bpf_sock {
231261023658SDavid Ahern 	__u32 bound_dev_if;
2313aa4c1037SDavid Ahern 	__u32 family;
2314aa4c1037SDavid Ahern 	__u32 type;
2315aa4c1037SDavid Ahern 	__u32 protocol;
2316482dca93SDavid Ahern 	__u32 mark;
2317482dca93SDavid Ahern 	__u32 priority;
2318aac3fc32SAndrey Ignatov 	__u32 src_ip4;		/* Allows 1,2,4-byte read.
2319aac3fc32SAndrey Ignatov 				 * Stored in network byte order.
2320aac3fc32SAndrey Ignatov 				 */
2321aac3fc32SAndrey Ignatov 	__u32 src_ip6[4];	/* Allows 1,2,4-byte read.
2322aac3fc32SAndrey Ignatov 				 * Stored in network byte order.
2323aac3fc32SAndrey Ignatov 				 */
2324aac3fc32SAndrey Ignatov 	__u32 src_port;		/* Allows 4-byte read.
2325aac3fc32SAndrey Ignatov 				 * Stored in host byte order
2326aac3fc32SAndrey Ignatov 				 */
232761023658SDavid Ahern };
232861023658SDavid Ahern 
232917bedab2SMartin KaFai Lau #define XDP_PACKET_HEADROOM 256
233017bedab2SMartin KaFai Lau 
23316a773a15SBrenden Blanco /* User return codes for XDP prog type.
23326a773a15SBrenden Blanco  * A valid XDP program must return one of these defined values. All other
23339beb8bedSDaniel Borkmann  * return codes are reserved for future use. Unknown return codes will
23349beb8bedSDaniel Borkmann  * result in packet drops and a warning via bpf_warn_invalid_xdp_action().
23356a773a15SBrenden Blanco  */
23366a773a15SBrenden Blanco enum xdp_action {
23376a773a15SBrenden Blanco 	XDP_ABORTED = 0,
23386a773a15SBrenden Blanco 	XDP_DROP,
23396a773a15SBrenden Blanco 	XDP_PASS,
23406ce96ca3SBrenden Blanco 	XDP_TX,
2341814abfabSJohn Fastabend 	XDP_REDIRECT,
23426a773a15SBrenden Blanco };
23436a773a15SBrenden Blanco 
23446a773a15SBrenden Blanco /* user accessible metadata for XDP packet hook
23456a773a15SBrenden Blanco  * new fields must be added to the end of this structure
23466a773a15SBrenden Blanco  */
23476a773a15SBrenden Blanco struct xdp_md {
23486a773a15SBrenden Blanco 	__u32 data;
23496a773a15SBrenden Blanco 	__u32 data_end;
2350de8f3a83SDaniel Borkmann 	__u32 data_meta;
2351daaf24c6SJesper Dangaard Brouer 	/* Below access go through struct xdp_rxq_info */
235202dd3291SJesper Dangaard Brouer 	__u32 ingress_ifindex; /* rxq->dev->ifindex */
235302dd3291SJesper Dangaard Brouer 	__u32 rx_queue_index;  /* rxq->queue_index  */
23546a773a15SBrenden Blanco };
23556a773a15SBrenden Blanco 
2356174a79ffSJohn Fastabend enum sk_action {
2357bfa64075SJohn Fastabend 	SK_DROP = 0,
2358bfa64075SJohn Fastabend 	SK_PASS,
2359174a79ffSJohn Fastabend };
2360174a79ffSJohn Fastabend 
23614f738adbSJohn Fastabend /* user accessible metadata for SK_MSG packet hook, new fields must
23624f738adbSJohn Fastabend  * be added to the end of this structure
23634f738adbSJohn Fastabend  */
23644f738adbSJohn Fastabend struct sk_msg_md {
23654f738adbSJohn Fastabend 	void *data;
23664f738adbSJohn Fastabend 	void *data_end;
2367303def35SJohn Fastabend 
2368303def35SJohn Fastabend 	__u32 family;
2369303def35SJohn Fastabend 	__u32 remote_ip4;	/* Stored in network byte order */
2370303def35SJohn Fastabend 	__u32 local_ip4;	/* Stored in network byte order */
2371303def35SJohn Fastabend 	__u32 remote_ip6[4];	/* Stored in network byte order */
2372303def35SJohn Fastabend 	__u32 local_ip6[4];	/* Stored in network byte order */
2373303def35SJohn Fastabend 	__u32 remote_port;	/* Stored in network byte order */
2374303def35SJohn Fastabend 	__u32 local_port;	/* stored in host byte order */
23754f738adbSJohn Fastabend };
23764f738adbSJohn Fastabend 
23771e270976SMartin KaFai Lau #define BPF_TAG_SIZE	8
23781e270976SMartin KaFai Lau 
23791e270976SMartin KaFai Lau struct bpf_prog_info {
23801e270976SMartin KaFai Lau 	__u32 type;
23811e270976SMartin KaFai Lau 	__u32 id;
23821e270976SMartin KaFai Lau 	__u8  tag[BPF_TAG_SIZE];
23831e270976SMartin KaFai Lau 	__u32 jited_prog_len;
23841e270976SMartin KaFai Lau 	__u32 xlated_prog_len;
23851e270976SMartin KaFai Lau 	__aligned_u64 jited_prog_insns;
23861e270976SMartin KaFai Lau 	__aligned_u64 xlated_prog_insns;
2387cb4d2b3fSMartin KaFai Lau 	__u64 load_time;	/* ns since boottime */
2388cb4d2b3fSMartin KaFai Lau 	__u32 created_by_uid;
2389cb4d2b3fSMartin KaFai Lau 	__u32 nr_map_ids;
2390cb4d2b3fSMartin KaFai Lau 	__aligned_u64 map_ids;
2391067cae47SMartin KaFai Lau 	char name[BPF_OBJ_NAME_LEN];
2392675fc275SJakub Kicinski 	__u32 ifindex;
2393b85fab0eSJiri Olsa 	__u32 gpl_compatible:1;
2394675fc275SJakub Kicinski 	__u64 netns_dev;
2395675fc275SJakub Kicinski 	__u64 netns_ino;
2396dbecd738SSandipan Das 	__u32 nr_jited_ksyms;
2397815581c1SSandipan Das 	__u32 nr_jited_func_lens;
2398dbecd738SSandipan Das 	__aligned_u64 jited_ksyms;
2399815581c1SSandipan Das 	__aligned_u64 jited_func_lens;
24001e270976SMartin KaFai Lau } __attribute__((aligned(8)));
24011e270976SMartin KaFai Lau 
24021e270976SMartin KaFai Lau struct bpf_map_info {
24031e270976SMartin KaFai Lau 	__u32 type;
24041e270976SMartin KaFai Lau 	__u32 id;
24051e270976SMartin KaFai Lau 	__u32 key_size;
24061e270976SMartin KaFai Lau 	__u32 value_size;
24071e270976SMartin KaFai Lau 	__u32 max_entries;
24081e270976SMartin KaFai Lau 	__u32 map_flags;
2409067cae47SMartin KaFai Lau 	char  name[BPF_OBJ_NAME_LEN];
241052775b33SJakub Kicinski 	__u32 ifindex;
241136f9814aSDaniel Borkmann 	__u32 :32;
241252775b33SJakub Kicinski 	__u64 netns_dev;
241352775b33SJakub Kicinski 	__u64 netns_ino;
241478958fcaSMartin KaFai Lau 	__u32 btf_id;
24159b2cf328SMartin KaFai Lau 	__u32 btf_key_type_id;
24169b2cf328SMartin KaFai Lau 	__u32 btf_value_type_id;
24171e270976SMartin KaFai Lau } __attribute__((aligned(8)));
24181e270976SMartin KaFai Lau 
241962dab84cSMartin KaFai Lau struct bpf_btf_info {
242062dab84cSMartin KaFai Lau 	__aligned_u64 btf;
242162dab84cSMartin KaFai Lau 	__u32 btf_size;
242262dab84cSMartin KaFai Lau 	__u32 id;
242362dab84cSMartin KaFai Lau } __attribute__((aligned(8)));
242462dab84cSMartin KaFai Lau 
24254fbac77dSAndrey Ignatov /* User bpf_sock_addr struct to access socket fields and sockaddr struct passed
24264fbac77dSAndrey Ignatov  * by user and intended to be used by socket (e.g. to bind to, depends on
24274fbac77dSAndrey Ignatov  * attach attach type).
24284fbac77dSAndrey Ignatov  */
24294fbac77dSAndrey Ignatov struct bpf_sock_addr {
24304fbac77dSAndrey Ignatov 	__u32 user_family;	/* Allows 4-byte read, but no write. */
24314fbac77dSAndrey Ignatov 	__u32 user_ip4;		/* Allows 1,2,4-byte read and 4-byte write.
24324fbac77dSAndrey Ignatov 				 * Stored in network byte order.
24334fbac77dSAndrey Ignatov 				 */
24344fbac77dSAndrey Ignatov 	__u32 user_ip6[4];	/* Allows 1,2,4-byte read an 4-byte write.
24354fbac77dSAndrey Ignatov 				 * Stored in network byte order.
24364fbac77dSAndrey Ignatov 				 */
24374fbac77dSAndrey Ignatov 	__u32 user_port;	/* Allows 4-byte read and write.
24384fbac77dSAndrey Ignatov 				 * Stored in network byte order
24394fbac77dSAndrey Ignatov 				 */
24404fbac77dSAndrey Ignatov 	__u32 family;		/* Allows 4-byte read, but no write */
24414fbac77dSAndrey Ignatov 	__u32 type;		/* Allows 4-byte read, but no write */
24424fbac77dSAndrey Ignatov 	__u32 protocol;		/* Allows 4-byte read, but no write */
24431cedee13SAndrey Ignatov 	__u32 msg_src_ip4;	/* Allows 1,2,4-byte read an 4-byte write.
24441cedee13SAndrey Ignatov 				 * Stored in network byte order.
24451cedee13SAndrey Ignatov 				 */
24461cedee13SAndrey Ignatov 	__u32 msg_src_ip6[4];	/* Allows 1,2,4-byte read an 4-byte write.
24471cedee13SAndrey Ignatov 				 * Stored in network byte order.
24481cedee13SAndrey Ignatov 				 */
24494fbac77dSAndrey Ignatov };
24504fbac77dSAndrey Ignatov 
245140304b2aSLawrence Brakmo /* User bpf_sock_ops struct to access socket values and specify request ops
245240304b2aSLawrence Brakmo  * and their replies.
245340304b2aSLawrence Brakmo  * Some of this fields are in network (bigendian) byte order and may need
245440304b2aSLawrence Brakmo  * to be converted before use (bpf_ntohl() defined in samples/bpf/bpf_endian.h).
245540304b2aSLawrence Brakmo  * New fields can only be added at the end of this structure
245640304b2aSLawrence Brakmo  */
245740304b2aSLawrence Brakmo struct bpf_sock_ops {
245840304b2aSLawrence Brakmo 	__u32 op;
245940304b2aSLawrence Brakmo 	union {
2460de525be2SLawrence Brakmo 		__u32 args[4];		/* Optionally passed to bpf program */
2461de525be2SLawrence Brakmo 		__u32 reply;		/* Returned by bpf program	    */
2462de525be2SLawrence Brakmo 		__u32 replylong[4];	/* Optionally returned by bpf prog  */
246340304b2aSLawrence Brakmo 	};
246440304b2aSLawrence Brakmo 	__u32 family;
246540304b2aSLawrence Brakmo 	__u32 remote_ip4;	/* Stored in network byte order */
246640304b2aSLawrence Brakmo 	__u32 local_ip4;	/* Stored in network byte order */
246740304b2aSLawrence Brakmo 	__u32 remote_ip6[4];	/* Stored in network byte order */
246840304b2aSLawrence Brakmo 	__u32 local_ip6[4];	/* Stored in network byte order */
246940304b2aSLawrence Brakmo 	__u32 remote_port;	/* Stored in network byte order */
247040304b2aSLawrence Brakmo 	__u32 local_port;	/* stored in host byte order */
2471f19397a5SLawrence Brakmo 	__u32 is_fullsock;	/* Some TCP fields are only valid if
2472f19397a5SLawrence Brakmo 				 * there is a full socket. If not, the
2473f19397a5SLawrence Brakmo 				 * fields read as zero.
2474f19397a5SLawrence Brakmo 				 */
2475f19397a5SLawrence Brakmo 	__u32 snd_cwnd;
2476f19397a5SLawrence Brakmo 	__u32 srtt_us;		/* Averaged RTT << 3 in usecs */
2477b13d8807SLawrence Brakmo 	__u32 bpf_sock_ops_cb_flags; /* flags defined in uapi/linux/tcp.h */
247844f0e430SLawrence Brakmo 	__u32 state;
247944f0e430SLawrence Brakmo 	__u32 rtt_min;
248044f0e430SLawrence Brakmo 	__u32 snd_ssthresh;
248144f0e430SLawrence Brakmo 	__u32 rcv_nxt;
248244f0e430SLawrence Brakmo 	__u32 snd_nxt;
248344f0e430SLawrence Brakmo 	__u32 snd_una;
248444f0e430SLawrence Brakmo 	__u32 mss_cache;
248544f0e430SLawrence Brakmo 	__u32 ecn_flags;
248644f0e430SLawrence Brakmo 	__u32 rate_delivered;
248744f0e430SLawrence Brakmo 	__u32 rate_interval_us;
248844f0e430SLawrence Brakmo 	__u32 packets_out;
248944f0e430SLawrence Brakmo 	__u32 retrans_out;
249044f0e430SLawrence Brakmo 	__u32 total_retrans;
249144f0e430SLawrence Brakmo 	__u32 segs_in;
249244f0e430SLawrence Brakmo 	__u32 data_segs_in;
249344f0e430SLawrence Brakmo 	__u32 segs_out;
249444f0e430SLawrence Brakmo 	__u32 data_segs_out;
249544f0e430SLawrence Brakmo 	__u32 lost_out;
249644f0e430SLawrence Brakmo 	__u32 sacked_out;
249744f0e430SLawrence Brakmo 	__u32 sk_txhash;
249844f0e430SLawrence Brakmo 	__u64 bytes_received;
249944f0e430SLawrence Brakmo 	__u64 bytes_acked;
250040304b2aSLawrence Brakmo };
250140304b2aSLawrence Brakmo 
2502b13d8807SLawrence Brakmo /* Definitions for bpf_sock_ops_cb_flags */
2503f89013f6SLawrence Brakmo #define BPF_SOCK_OPS_RTO_CB_FLAG	(1<<0)
2504a31ad29eSLawrence Brakmo #define BPF_SOCK_OPS_RETRANS_CB_FLAG	(1<<1)
2505d4487491SLawrence Brakmo #define BPF_SOCK_OPS_STATE_CB_FLAG	(1<<2)
2506d4487491SLawrence Brakmo #define BPF_SOCK_OPS_ALL_CB_FLAGS       0x7		/* Mask of all currently
2507b13d8807SLawrence Brakmo 							 * supported cb flags
2508b13d8807SLawrence Brakmo 							 */
2509b13d8807SLawrence Brakmo 
251040304b2aSLawrence Brakmo /* List of known BPF sock_ops operators.
251140304b2aSLawrence Brakmo  * New entries can only be added at the end
251240304b2aSLawrence Brakmo  */
251340304b2aSLawrence Brakmo enum {
251440304b2aSLawrence Brakmo 	BPF_SOCK_OPS_VOID,
25158550f328SLawrence Brakmo 	BPF_SOCK_OPS_TIMEOUT_INIT,	/* Should return SYN-RTO value to use or
25168550f328SLawrence Brakmo 					 * -1 if default value should be used
25178550f328SLawrence Brakmo 					 */
251813d3b1ebSLawrence Brakmo 	BPF_SOCK_OPS_RWND_INIT,		/* Should return initial advertized
251913d3b1ebSLawrence Brakmo 					 * window (in packets) or -1 if default
252013d3b1ebSLawrence Brakmo 					 * value should be used
252113d3b1ebSLawrence Brakmo 					 */
25229872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_TCP_CONNECT_CB,	/* Calls BPF program right before an
25239872a4bdSLawrence Brakmo 					 * active connection is initialized
25249872a4bdSLawrence Brakmo 					 */
25259872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB,	/* Calls BPF program when an
25269872a4bdSLawrence Brakmo 						 * active connection is
25279872a4bdSLawrence Brakmo 						 * established
25289872a4bdSLawrence Brakmo 						 */
25299872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB,	/* Calls BPF program when a
25309872a4bdSLawrence Brakmo 						 * passive connection is
25319872a4bdSLawrence Brakmo 						 * established
25329872a4bdSLawrence Brakmo 						 */
253391b5b21cSLawrence Brakmo 	BPF_SOCK_OPS_NEEDS_ECN,		/* If connection's congestion control
253491b5b21cSLawrence Brakmo 					 * needs ECN
253591b5b21cSLawrence Brakmo 					 */
2536e6546ef6SLawrence Brakmo 	BPF_SOCK_OPS_BASE_RTT,		/* Get base RTT. The correct value is
2537e6546ef6SLawrence Brakmo 					 * based on the path and may be
2538e6546ef6SLawrence Brakmo 					 * dependent on the congestion control
2539e6546ef6SLawrence Brakmo 					 * algorithm. In general it indicates
2540e6546ef6SLawrence Brakmo 					 * a congestion threshold. RTTs above
2541e6546ef6SLawrence Brakmo 					 * this indicate congestion
2542e6546ef6SLawrence Brakmo 					 */
2543f89013f6SLawrence Brakmo 	BPF_SOCK_OPS_RTO_CB,		/* Called when an RTO has triggered.
2544f89013f6SLawrence Brakmo 					 * Arg1: value of icsk_retransmits
2545f89013f6SLawrence Brakmo 					 * Arg2: value of icsk_rto
2546f89013f6SLawrence Brakmo 					 * Arg3: whether RTO has expired
2547f89013f6SLawrence Brakmo 					 */
2548a31ad29eSLawrence Brakmo 	BPF_SOCK_OPS_RETRANS_CB,	/* Called when skb is retransmitted.
2549a31ad29eSLawrence Brakmo 					 * Arg1: sequence number of 1st byte
2550a31ad29eSLawrence Brakmo 					 * Arg2: # segments
2551a31ad29eSLawrence Brakmo 					 * Arg3: return value of
2552a31ad29eSLawrence Brakmo 					 *       tcp_transmit_skb (0 => success)
2553a31ad29eSLawrence Brakmo 					 */
2554d4487491SLawrence Brakmo 	BPF_SOCK_OPS_STATE_CB,		/* Called when TCP changes state.
2555d4487491SLawrence Brakmo 					 * Arg1: old_state
2556d4487491SLawrence Brakmo 					 * Arg2: new_state
2557d4487491SLawrence Brakmo 					 */
2558*f333ee0cSAndrey Ignatov 	BPF_SOCK_OPS_TCP_LISTEN_CB,	/* Called on listen(2), right after
2559*f333ee0cSAndrey Ignatov 					 * socket transition to LISTEN state.
2560*f333ee0cSAndrey Ignatov 					 */
2561d4487491SLawrence Brakmo };
2562d4487491SLawrence Brakmo 
2563d4487491SLawrence Brakmo /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
2564d4487491SLawrence Brakmo  * changes between the TCP and BPF versions. Ideally this should never happen.
2565d4487491SLawrence Brakmo  * If it does, we need to add code to convert them before calling
2566d4487491SLawrence Brakmo  * the BPF sock_ops function.
2567d4487491SLawrence Brakmo  */
2568d4487491SLawrence Brakmo enum {
2569d4487491SLawrence Brakmo 	BPF_TCP_ESTABLISHED = 1,
2570d4487491SLawrence Brakmo 	BPF_TCP_SYN_SENT,
2571d4487491SLawrence Brakmo 	BPF_TCP_SYN_RECV,
2572d4487491SLawrence Brakmo 	BPF_TCP_FIN_WAIT1,
2573d4487491SLawrence Brakmo 	BPF_TCP_FIN_WAIT2,
2574d4487491SLawrence Brakmo 	BPF_TCP_TIME_WAIT,
2575d4487491SLawrence Brakmo 	BPF_TCP_CLOSE,
2576d4487491SLawrence Brakmo 	BPF_TCP_CLOSE_WAIT,
2577d4487491SLawrence Brakmo 	BPF_TCP_LAST_ACK,
2578d4487491SLawrence Brakmo 	BPF_TCP_LISTEN,
2579d4487491SLawrence Brakmo 	BPF_TCP_CLOSING,	/* Now a valid state */
2580d4487491SLawrence Brakmo 	BPF_TCP_NEW_SYN_RECV,
2581d4487491SLawrence Brakmo 
2582d4487491SLawrence Brakmo 	BPF_TCP_MAX_STATES	/* Leave at the end! */
258340304b2aSLawrence Brakmo };
258440304b2aSLawrence Brakmo 
2585fc747810SLawrence Brakmo #define TCP_BPF_IW		1001	/* Set TCP initial congestion window */
258613bf9641SLawrence Brakmo #define TCP_BPF_SNDCWND_CLAMP	1002	/* Set sndcwnd_clamp */
2587fc747810SLawrence Brakmo 
2588908432caSYonghong Song struct bpf_perf_event_value {
2589908432caSYonghong Song 	__u64 counter;
2590908432caSYonghong Song 	__u64 enabled;
2591908432caSYonghong Song 	__u64 running;
2592908432caSYonghong Song };
2593908432caSYonghong Song 
2594ebc614f6SRoman Gushchin #define BPF_DEVCG_ACC_MKNOD	(1ULL << 0)
2595ebc614f6SRoman Gushchin #define BPF_DEVCG_ACC_READ	(1ULL << 1)
2596ebc614f6SRoman Gushchin #define BPF_DEVCG_ACC_WRITE	(1ULL << 2)
2597ebc614f6SRoman Gushchin 
2598ebc614f6SRoman Gushchin #define BPF_DEVCG_DEV_BLOCK	(1ULL << 0)
2599ebc614f6SRoman Gushchin #define BPF_DEVCG_DEV_CHAR	(1ULL << 1)
2600ebc614f6SRoman Gushchin 
2601ebc614f6SRoman Gushchin struct bpf_cgroup_dev_ctx {
260206ef0ccbSYonghong Song 	/* access_type encoded as (BPF_DEVCG_ACC_* << 16) | BPF_DEVCG_DEV_* */
260306ef0ccbSYonghong Song 	__u32 access_type;
2604ebc614f6SRoman Gushchin 	__u32 major;
2605ebc614f6SRoman Gushchin 	__u32 minor;
2606ebc614f6SRoman Gushchin };
2607ebc614f6SRoman Gushchin 
2608c4f6699dSAlexei Starovoitov struct bpf_raw_tracepoint_args {
2609c4f6699dSAlexei Starovoitov 	__u64 args[0];
2610c4f6699dSAlexei Starovoitov };
2611c4f6699dSAlexei Starovoitov 
261287f5fc7eSDavid Ahern /* DIRECT:  Skip the FIB rules and go to FIB table associated with device
261387f5fc7eSDavid Ahern  * OUTPUT:  Do lookup from egress perspective; default is ingress
261487f5fc7eSDavid Ahern  */
261587f5fc7eSDavid Ahern #define BPF_FIB_LOOKUP_DIRECT  BIT(0)
261687f5fc7eSDavid Ahern #define BPF_FIB_LOOKUP_OUTPUT  BIT(1)
261787f5fc7eSDavid Ahern 
26184c79579bSDavid Ahern enum {
26194c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_SUCCESS,      /* lookup successful */
26204c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_BLACKHOLE,    /* dest is blackholed; can be dropped */
26214c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_UNREACHABLE,  /* dest is unreachable; can be dropped */
26224c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_PROHIBIT,     /* dest not allowed; can be dropped */
26234c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_NOT_FWDED,    /* packet is not forwarded */
26244c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_FWD_DISABLED, /* fwding is not enabled on ingress */
26254c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_UNSUPP_LWT,   /* fwd requires encapsulation */
26264c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_NO_NEIGH,     /* no neighbor entry for nh */
26274c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_FRAG_NEEDED,  /* fragmentation required to fwd */
26284c79579bSDavid Ahern };
26294c79579bSDavid Ahern 
263087f5fc7eSDavid Ahern struct bpf_fib_lookup {
2631fa898d76SDavid Ahern 	/* input:  network family for lookup (AF_INET, AF_INET6)
2632fa898d76SDavid Ahern 	 * output: network family of egress nexthop
2633fa898d76SDavid Ahern 	 */
2634fa898d76SDavid Ahern 	__u8	family;
263587f5fc7eSDavid Ahern 
263687f5fc7eSDavid Ahern 	/* set if lookup is to consider L4 data - e.g., FIB rules */
263787f5fc7eSDavid Ahern 	__u8	l4_protocol;
263887f5fc7eSDavid Ahern 	__be16	sport;
263987f5fc7eSDavid Ahern 	__be16	dport;
264087f5fc7eSDavid Ahern 
264187f5fc7eSDavid Ahern 	/* total length of packet from network header - used for MTU check */
264287f5fc7eSDavid Ahern 	__u16	tot_len;
26434c79579bSDavid Ahern 
26444c79579bSDavid Ahern 	/* input: L3 device index for lookup
26454c79579bSDavid Ahern 	 * output: device index from FIB lookup
26464c79579bSDavid Ahern 	 */
26474c79579bSDavid Ahern 	__u32	ifindex;
264887f5fc7eSDavid Ahern 
264987f5fc7eSDavid Ahern 	union {
265087f5fc7eSDavid Ahern 		/* inputs to lookup */
265187f5fc7eSDavid Ahern 		__u8	tos;		/* AF_INET  */
2652bd3a08aaSDavid Ahern 		__be32	flowinfo;	/* AF_INET6, flow_label + priority */
265387f5fc7eSDavid Ahern 
2654fa898d76SDavid Ahern 		/* output: metric of fib result (IPv4/IPv6 only) */
265587f5fc7eSDavid Ahern 		__u32	rt_metric;
265687f5fc7eSDavid Ahern 	};
265787f5fc7eSDavid Ahern 
265887f5fc7eSDavid Ahern 	union {
265987f5fc7eSDavid Ahern 		__be32		ipv4_src;
266087f5fc7eSDavid Ahern 		__u32		ipv6_src[4];  /* in6_addr; network order */
266187f5fc7eSDavid Ahern 	};
266287f5fc7eSDavid Ahern 
2663fa898d76SDavid Ahern 	/* input to bpf_fib_lookup, ipv{4,6}_dst is destination address in
2664fa898d76SDavid Ahern 	 * network header. output: bpf_fib_lookup sets to gateway address
2665fa898d76SDavid Ahern 	 * if FIB lookup returns gateway route
266687f5fc7eSDavid Ahern 	 */
266787f5fc7eSDavid Ahern 	union {
266887f5fc7eSDavid Ahern 		__be32		ipv4_dst;
266987f5fc7eSDavid Ahern 		__u32		ipv6_dst[4];  /* in6_addr; network order */
267087f5fc7eSDavid Ahern 	};
267187f5fc7eSDavid Ahern 
267287f5fc7eSDavid Ahern 	/* output */
267387f5fc7eSDavid Ahern 	__be16	h_vlan_proto;
267487f5fc7eSDavid Ahern 	__be16	h_vlan_TCI;
267587f5fc7eSDavid Ahern 	__u8	smac[6];     /* ETH_ALEN */
267687f5fc7eSDavid Ahern 	__u8	dmac[6];     /* ETH_ALEN */
267787f5fc7eSDavid Ahern };
267887f5fc7eSDavid Ahern 
267941bdc4b4SYonghong Song enum bpf_task_fd_type {
268041bdc4b4SYonghong Song 	BPF_FD_TYPE_RAW_TRACEPOINT,	/* tp name */
268141bdc4b4SYonghong Song 	BPF_FD_TYPE_TRACEPOINT,		/* tp name */
268241bdc4b4SYonghong Song 	BPF_FD_TYPE_KPROBE,		/* (symbol + offset) or addr */
268341bdc4b4SYonghong Song 	BPF_FD_TYPE_KRETPROBE,		/* (symbol + offset) or addr */
268441bdc4b4SYonghong Song 	BPF_FD_TYPE_UPROBE,		/* filename + offset */
268541bdc4b4SYonghong Song 	BPF_FD_TYPE_URETPROBE,		/* filename + offset */
268641bdc4b4SYonghong Song };
268741bdc4b4SYonghong Song 
2688daedfb22SAlexei Starovoitov #endif /* _UAPI__LINUX_BPF_H__ */
2689