xref: /linux/include/uapi/linux/bpf.h (revision 1b715e1b0ec531fae72cd6698fe1c98affa436f8)
1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2daedfb22SAlexei Starovoitov /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
3daedfb22SAlexei Starovoitov  *
4daedfb22SAlexei Starovoitov  * This program is free software; you can redistribute it and/or
5daedfb22SAlexei Starovoitov  * modify it under the terms of version 2 of the GNU General Public
6daedfb22SAlexei Starovoitov  * License as published by the Free Software Foundation.
7daedfb22SAlexei Starovoitov  */
8daedfb22SAlexei Starovoitov #ifndef _UAPI__LINUX_BPF_H__
9daedfb22SAlexei Starovoitov #define _UAPI__LINUX_BPF_H__
10daedfb22SAlexei Starovoitov 
11daedfb22SAlexei Starovoitov #include <linux/types.h>
12c15952dcSAlexei Starovoitov #include <linux/bpf_common.h>
13daedfb22SAlexei Starovoitov 
14daedfb22SAlexei Starovoitov /* Extended instruction set based on top of classic BPF */
15daedfb22SAlexei Starovoitov 
16daedfb22SAlexei Starovoitov /* instruction classes */
17d405c740SJiong Wang #define BPF_JMP32	0x06	/* jmp mode in word width */
18daedfb22SAlexei Starovoitov #define BPF_ALU64	0x07	/* alu mode in double word width */
19daedfb22SAlexei Starovoitov 
20daedfb22SAlexei Starovoitov /* ld/ldx fields */
21cb5f7334SJesper Dangaard Brouer #define BPF_DW		0x18	/* double word (64-bit) */
2291c960b0SBrendan Jackman #define BPF_ATOMIC	0xc0	/* atomic memory ops - op type in immediate */
2391c960b0SBrendan Jackman #define BPF_XADD	0xc0	/* exclusive add - legacy name */
24daedfb22SAlexei Starovoitov 
25daedfb22SAlexei Starovoitov /* alu/jmp fields */
26daedfb22SAlexei Starovoitov #define BPF_MOV		0xb0	/* mov reg to reg */
27daedfb22SAlexei Starovoitov #define BPF_ARSH	0xc0	/* sign extending arithmetic shift right */
28daedfb22SAlexei Starovoitov 
29daedfb22SAlexei Starovoitov /* change endianness of a register */
30daedfb22SAlexei Starovoitov #define BPF_END		0xd0	/* flags for endianness conversion: */
31daedfb22SAlexei Starovoitov #define BPF_TO_LE	0x00	/* convert to little-endian */
32daedfb22SAlexei Starovoitov #define BPF_TO_BE	0x08	/* convert to big-endian */
33daedfb22SAlexei Starovoitov #define BPF_FROM_LE	BPF_TO_LE
34daedfb22SAlexei Starovoitov #define BPF_FROM_BE	BPF_TO_BE
35daedfb22SAlexei Starovoitov 
3692b31a9aSDaniel Borkmann /* jmp encodings */
37daedfb22SAlexei Starovoitov #define BPF_JNE		0x50	/* jump != */
3892b31a9aSDaniel Borkmann #define BPF_JLT		0xa0	/* LT is unsigned, '<' */
3992b31a9aSDaniel Borkmann #define BPF_JLE		0xb0	/* LE is unsigned, '<=' */
40daedfb22SAlexei Starovoitov #define BPF_JSGT	0x60	/* SGT is signed '>', GT in x86 */
41daedfb22SAlexei Starovoitov #define BPF_JSGE	0x70	/* SGE is signed '>=', GE in x86 */
4292b31a9aSDaniel Borkmann #define BPF_JSLT	0xc0	/* SLT is signed, '<' */
4392b31a9aSDaniel Borkmann #define BPF_JSLE	0xd0	/* SLE is signed, '<=' */
44daedfb22SAlexei Starovoitov #define BPF_CALL	0x80	/* function call */
45daedfb22SAlexei Starovoitov #define BPF_EXIT	0x90	/* function return */
46daedfb22SAlexei Starovoitov 
475ca419f2SBrendan Jackman /* atomic op type fields (stored in immediate) */
485ffa2550SBrendan Jackman #define BPF_FETCH	0x01	/* not an opcode on its own, used to build others */
495ffa2550SBrendan Jackman #define BPF_XCHG	(0xe0 | BPF_FETCH)	/* atomic exchange */
505ffa2550SBrendan Jackman #define BPF_CMPXCHG	(0xf0 | BPF_FETCH)	/* atomic compare-and-write */
515ca419f2SBrendan Jackman 
52daedfb22SAlexei Starovoitov /* Register numbers */
53daedfb22SAlexei Starovoitov enum {
54daedfb22SAlexei Starovoitov 	BPF_REG_0 = 0,
55daedfb22SAlexei Starovoitov 	BPF_REG_1,
56daedfb22SAlexei Starovoitov 	BPF_REG_2,
57daedfb22SAlexei Starovoitov 	BPF_REG_3,
58daedfb22SAlexei Starovoitov 	BPF_REG_4,
59daedfb22SAlexei Starovoitov 	BPF_REG_5,
60daedfb22SAlexei Starovoitov 	BPF_REG_6,
61daedfb22SAlexei Starovoitov 	BPF_REG_7,
62daedfb22SAlexei Starovoitov 	BPF_REG_8,
63daedfb22SAlexei Starovoitov 	BPF_REG_9,
64daedfb22SAlexei Starovoitov 	BPF_REG_10,
65daedfb22SAlexei Starovoitov 	__MAX_BPF_REG,
66daedfb22SAlexei Starovoitov };
67daedfb22SAlexei Starovoitov 
68daedfb22SAlexei Starovoitov /* BPF has 10 general purpose 64-bit registers and stack frame. */
69daedfb22SAlexei Starovoitov #define MAX_BPF_REG	__MAX_BPF_REG
70daedfb22SAlexei Starovoitov 
71daedfb22SAlexei Starovoitov struct bpf_insn {
72daedfb22SAlexei Starovoitov 	__u8	code;		/* opcode */
73daedfb22SAlexei Starovoitov 	__u8	dst_reg:4;	/* dest register */
74daedfb22SAlexei Starovoitov 	__u8	src_reg:4;	/* source register */
75daedfb22SAlexei Starovoitov 	__s16	off;		/* signed offset */
76daedfb22SAlexei Starovoitov 	__s32	imm;		/* signed immediate constant */
77daedfb22SAlexei Starovoitov };
78daedfb22SAlexei Starovoitov 
79b95a5c4dSDaniel Mack /* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */
80b95a5c4dSDaniel Mack struct bpf_lpm_trie_key {
81b95a5c4dSDaniel Mack 	__u32	prefixlen;	/* up to 32 for AF_INET, 128 for AF_INET6 */
823024d95aSDaniel Borkmann 	__u8	data[0];	/* Arbitrary size */
83b95a5c4dSDaniel Mack };
84b95a5c4dSDaniel Mack 
85de9cbbaaSRoman Gushchin struct bpf_cgroup_storage_key {
86de9cbbaaSRoman Gushchin 	__u64	cgroup_inode_id;	/* cgroup inode id */
876fc88c35SDave Marchevsky 	__u32	attach_type;		/* program attach type (enum bpf_attach_type) */
88de9cbbaaSRoman Gushchin };
89de9cbbaaSRoman Gushchin 
90d4ccaf58SHao Luo enum bpf_cgroup_iter_order {
91d4ffb6f3SHao Luo 	BPF_CGROUP_ITER_ORDER_UNSPEC = 0,
92d4ffb6f3SHao Luo 	BPF_CGROUP_ITER_SELF_ONLY,		/* process only a single object. */
93d4ffb6f3SHao Luo 	BPF_CGROUP_ITER_DESCENDANTS_PRE,	/* walk descendants in pre-order. */
94d4ffb6f3SHao Luo 	BPF_CGROUP_ITER_DESCENDANTS_POST,	/* walk descendants in post-order. */
95d4ffb6f3SHao Luo 	BPF_CGROUP_ITER_ANCESTORS_UP,		/* walk ancestors upward. */
96d4ccaf58SHao Luo };
97d4ccaf58SHao Luo 
985e7b3020SYonghong Song union bpf_iter_link_info {
995e7b3020SYonghong Song 	struct {
1005e7b3020SYonghong Song 		__u32	map_fd;
1015e7b3020SYonghong Song 	} map;
102d4ccaf58SHao Luo 	struct {
103d4ccaf58SHao Luo 		enum bpf_cgroup_iter_order order;
104d4ccaf58SHao Luo 
105d4ccaf58SHao Luo 		/* At most one of cgroup_fd and cgroup_id can be non-zero. If
106d4ccaf58SHao Luo 		 * both are zero, the walk starts from the default cgroup v2
107d4ccaf58SHao Luo 		 * root. For walking v1 hierarchy, one should always explicitly
108d4ccaf58SHao Luo 		 * specify cgroup_fd.
109d4ccaf58SHao Luo 		 */
110d4ccaf58SHao Luo 		__u32	cgroup_fd;
111d4ccaf58SHao Luo 		__u64	cgroup_id;
112d4ccaf58SHao Luo 	} cgroup;
113f0d74c4dSKui-Feng Lee 	/* Parameters of task iterators. */
114f0d74c4dSKui-Feng Lee 	struct {
115f0d74c4dSKui-Feng Lee 		__u32	tid;
116f0d74c4dSKui-Feng Lee 		__u32	pid;
117f0d74c4dSKui-Feng Lee 		__u32	pid_fd;
118f0d74c4dSKui-Feng Lee 	} task;
1195e7b3020SYonghong Song };
1205e7b3020SYonghong Song 
1217799e4d9SJoe Stringer /* BPF syscall commands, see bpf(2) man-page for more details. */
1227799e4d9SJoe Stringer /**
1237799e4d9SJoe Stringer  * DOC: eBPF Syscall Preamble
1247799e4d9SJoe Stringer  *
1257799e4d9SJoe Stringer  * The operation to be performed by the **bpf**\ () system call is determined
1267799e4d9SJoe Stringer  * by the *cmd* argument. Each operation takes an accompanying argument,
1277799e4d9SJoe Stringer  * provided via *attr*, which is a pointer to a union of type *bpf_attr* (see
1287799e4d9SJoe Stringer  * below). The size argument is the size of the union pointed to by *attr*.
1297799e4d9SJoe Stringer  */
1307799e4d9SJoe Stringer /**
1317799e4d9SJoe Stringer  * DOC: eBPF Syscall Commands
1327799e4d9SJoe Stringer  *
1337799e4d9SJoe Stringer  * BPF_MAP_CREATE
1347799e4d9SJoe Stringer  *	Description
1357799e4d9SJoe Stringer  *		Create a map and return a file descriptor that refers to the
1367799e4d9SJoe Stringer  *		map. The close-on-exec file descriptor flag (see **fcntl**\ (2))
1377799e4d9SJoe Stringer  *		is automatically enabled for the new file descriptor.
1387799e4d9SJoe Stringer  *
1397799e4d9SJoe Stringer  *		Applying **close**\ (2) to the file descriptor returned by
1407799e4d9SJoe Stringer  *		**BPF_MAP_CREATE** will delete the map (but see NOTES).
1417799e4d9SJoe Stringer  *
1427799e4d9SJoe Stringer  *	Return
1437799e4d9SJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
1447799e4d9SJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
1457799e4d9SJoe Stringer  *
1467799e4d9SJoe Stringer  * BPF_MAP_LOOKUP_ELEM
1477799e4d9SJoe Stringer  *	Description
1487799e4d9SJoe Stringer  *		Look up an element with a given *key* in the map referred to
1497799e4d9SJoe Stringer  *		by the file descriptor *map_fd*.
1507799e4d9SJoe Stringer  *
1516690523bSJoe Stringer  *		The *flags* argument may be specified as one of the
1526690523bSJoe Stringer  *		following:
1536690523bSJoe Stringer  *
1546690523bSJoe Stringer  *		**BPF_F_LOCK**
1556690523bSJoe Stringer  *			Look up the value of a spin-locked map without
1566690523bSJoe Stringer  *			returning the lock. This must be specified if the
1576690523bSJoe Stringer  *			elements contain a spinlock.
1586690523bSJoe Stringer  *
1597799e4d9SJoe Stringer  *	Return
1607799e4d9SJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
1617799e4d9SJoe Stringer  *		is set appropriately.
1627799e4d9SJoe Stringer  *
1637799e4d9SJoe Stringer  * BPF_MAP_UPDATE_ELEM
1647799e4d9SJoe Stringer  *	Description
1657799e4d9SJoe Stringer  *		Create or update an element (key/value pair) in a specified map.
1667799e4d9SJoe Stringer  *
1677799e4d9SJoe Stringer  *		The *flags* argument should be specified as one of the
1687799e4d9SJoe Stringer  *		following:
1697799e4d9SJoe Stringer  *
1707799e4d9SJoe Stringer  *		**BPF_ANY**
1717799e4d9SJoe Stringer  *			Create a new element or update an existing element.
1727799e4d9SJoe Stringer  *		**BPF_NOEXIST**
1737799e4d9SJoe Stringer  *			Create a new element only if it did not exist.
1747799e4d9SJoe Stringer  *		**BPF_EXIST**
1757799e4d9SJoe Stringer  *			Update an existing element.
1766690523bSJoe Stringer  *		**BPF_F_LOCK**
1776690523bSJoe Stringer  *			Update a spin_lock-ed map element.
1787799e4d9SJoe Stringer  *
1797799e4d9SJoe Stringer  *	Return
1807799e4d9SJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
1817799e4d9SJoe Stringer  *		is set appropriately.
1827799e4d9SJoe Stringer  *
1837799e4d9SJoe Stringer  *		May set *errno* to **EINVAL**, **EPERM**, **ENOMEM**,
1847799e4d9SJoe Stringer  *		**E2BIG**, **EEXIST**, or **ENOENT**.
1857799e4d9SJoe Stringer  *
1867799e4d9SJoe Stringer  *		**E2BIG**
1877799e4d9SJoe Stringer  *			The number of elements in the map reached the
1887799e4d9SJoe Stringer  *			*max_entries* limit specified at map creation time.
1897799e4d9SJoe Stringer  *		**EEXIST**
1907799e4d9SJoe Stringer  *			If *flags* specifies **BPF_NOEXIST** and the element
1917799e4d9SJoe Stringer  *			with *key* already exists in the map.
1927799e4d9SJoe Stringer  *		**ENOENT**
1937799e4d9SJoe Stringer  *			If *flags* specifies **BPF_EXIST** and the element with
1947799e4d9SJoe Stringer  *			*key* does not exist in the map.
1957799e4d9SJoe Stringer  *
1967799e4d9SJoe Stringer  * BPF_MAP_DELETE_ELEM
1977799e4d9SJoe Stringer  *	Description
1987799e4d9SJoe Stringer  *		Look up and delete an element by key in a specified map.
1997799e4d9SJoe Stringer  *
2007799e4d9SJoe Stringer  *	Return
2017799e4d9SJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
2027799e4d9SJoe Stringer  *		is set appropriately.
2037799e4d9SJoe Stringer  *
2047799e4d9SJoe Stringer  * BPF_MAP_GET_NEXT_KEY
2057799e4d9SJoe Stringer  *	Description
2067799e4d9SJoe Stringer  *		Look up an element by key in a specified map and return the key
2077799e4d9SJoe Stringer  *		of the next element. Can be used to iterate over all elements
2087799e4d9SJoe Stringer  *		in the map.
2097799e4d9SJoe Stringer  *
2107799e4d9SJoe Stringer  *	Return
2117799e4d9SJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
2127799e4d9SJoe Stringer  *		is set appropriately.
2137799e4d9SJoe Stringer  *
2147799e4d9SJoe Stringer  *		The following cases can be used to iterate over all elements of
2157799e4d9SJoe Stringer  *		the map:
2167799e4d9SJoe Stringer  *
2177799e4d9SJoe Stringer  *		* If *key* is not found, the operation returns zero and sets
2187799e4d9SJoe Stringer  *		  the *next_key* pointer to the key of the first element.
2197799e4d9SJoe Stringer  *		* If *key* is found, the operation returns zero and sets the
2207799e4d9SJoe Stringer  *		  *next_key* pointer to the key of the next element.
2217799e4d9SJoe Stringer  *		* If *key* is the last element, returns -1 and *errno* is set
2227799e4d9SJoe Stringer  *		  to **ENOENT**.
2237799e4d9SJoe Stringer  *
2247799e4d9SJoe Stringer  *		May set *errno* to **ENOMEM**, **EFAULT**, **EPERM**, or
2257799e4d9SJoe Stringer  *		**EINVAL** on error.
2267799e4d9SJoe Stringer  *
2277799e4d9SJoe Stringer  * BPF_PROG_LOAD
2287799e4d9SJoe Stringer  *	Description
2297799e4d9SJoe Stringer  *		Verify and load an eBPF program, returning a new file
2307799e4d9SJoe Stringer  *		descriptor associated with the program.
2317799e4d9SJoe Stringer  *
2327799e4d9SJoe Stringer  *		Applying **close**\ (2) to the file descriptor returned by
2337799e4d9SJoe Stringer  *		**BPF_PROG_LOAD** will unload the eBPF program (but see NOTES).
2347799e4d9SJoe Stringer  *
2357799e4d9SJoe Stringer  *		The close-on-exec file descriptor flag (see **fcntl**\ (2)) is
2367799e4d9SJoe Stringer  *		automatically enabled for the new file descriptor.
2377799e4d9SJoe Stringer  *
2387799e4d9SJoe Stringer  *	Return
2397799e4d9SJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
2407799e4d9SJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
2417799e4d9SJoe Stringer  *
242f67c9cbfSJoe Stringer  * BPF_OBJ_PIN
243f67c9cbfSJoe Stringer  *	Description
244f67c9cbfSJoe Stringer  *		Pin an eBPF program or map referred by the specified *bpf_fd*
245f67c9cbfSJoe Stringer  *		to the provided *pathname* on the filesystem.
246f67c9cbfSJoe Stringer  *
2478aacb3c8SJoe Stringer  *		The *pathname* argument must not contain a dot (".").
2488aacb3c8SJoe Stringer  *
2498aacb3c8SJoe Stringer  *		On success, *pathname* retains a reference to the eBPF object,
2508aacb3c8SJoe Stringer  *		preventing deallocation of the object when the original
2518aacb3c8SJoe Stringer  *		*bpf_fd* is closed. This allow the eBPF object to live beyond
2528aacb3c8SJoe Stringer  *		**close**\ (\ *bpf_fd*\ ), and hence the lifetime of the parent
2538aacb3c8SJoe Stringer  *		process.
2548aacb3c8SJoe Stringer  *
2558aacb3c8SJoe Stringer  *		Applying **unlink**\ (2) or similar calls to the *pathname*
2568aacb3c8SJoe Stringer  *		unpins the object from the filesystem, removing the reference.
2578aacb3c8SJoe Stringer  *		If no other file descriptors or filesystem nodes refer to the
2588aacb3c8SJoe Stringer  *		same object, it will be deallocated (see NOTES).
2598aacb3c8SJoe Stringer  *
2608aacb3c8SJoe Stringer  *		The filesystem type for the parent directory of *pathname* must
2618aacb3c8SJoe Stringer  *		be **BPF_FS_MAGIC**.
2628aacb3c8SJoe Stringer  *
263f67c9cbfSJoe Stringer  *	Return
264f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
265f67c9cbfSJoe Stringer  *		is set appropriately.
266f67c9cbfSJoe Stringer  *
267f67c9cbfSJoe Stringer  * BPF_OBJ_GET
268f67c9cbfSJoe Stringer  *	Description
269f67c9cbfSJoe Stringer  *		Open a file descriptor for the eBPF object pinned to the
270f67c9cbfSJoe Stringer  *		specified *pathname*.
271f67c9cbfSJoe Stringer  *
272f67c9cbfSJoe Stringer  *	Return
273f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
274f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
275f67c9cbfSJoe Stringer  *
276f67c9cbfSJoe Stringer  * BPF_PROG_ATTACH
277f67c9cbfSJoe Stringer  *	Description
278f67c9cbfSJoe Stringer  *		Attach an eBPF program to a *target_fd* at the specified
279f67c9cbfSJoe Stringer  *		*attach_type* hook.
280f67c9cbfSJoe Stringer  *
28132e76b18SJoe Stringer  *		The *attach_type* specifies the eBPF attachment point to
28232e76b18SJoe Stringer  *		attach the program to, and must be one of *bpf_attach_type*
28332e76b18SJoe Stringer  *		(see below).
28432e76b18SJoe Stringer  *
28532e76b18SJoe Stringer  *		The *attach_bpf_fd* must be a valid file descriptor for a
28632e76b18SJoe Stringer  *		loaded eBPF program of a cgroup, flow dissector, LIRC, sockmap
28732e76b18SJoe Stringer  *		or sock_ops type corresponding to the specified *attach_type*.
28832e76b18SJoe Stringer  *
28932e76b18SJoe Stringer  *		The *target_fd* must be a valid file descriptor for a kernel
29032e76b18SJoe Stringer  *		object which depends on the attach type of *attach_bpf_fd*:
29132e76b18SJoe Stringer  *
29232e76b18SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_DEVICE**,
29332e76b18SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SKB**,
29432e76b18SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SOCK**,
29532e76b18SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,
29632e76b18SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SOCKOPT**,
29732e76b18SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SYSCTL**,
29832e76b18SJoe Stringer  *		**BPF_PROG_TYPE_SOCK_OPS**
29932e76b18SJoe Stringer  *
30032e76b18SJoe Stringer  *			Control Group v2 hierarchy with the eBPF controller
30132e76b18SJoe Stringer  *			enabled. Requires the kernel to be compiled with
30232e76b18SJoe Stringer  *			**CONFIG_CGROUP_BPF**.
30332e76b18SJoe Stringer  *
30432e76b18SJoe Stringer  *		**BPF_PROG_TYPE_FLOW_DISSECTOR**
30532e76b18SJoe Stringer  *
30632e76b18SJoe Stringer  *			Network namespace (eg /proc/self/ns/net).
30732e76b18SJoe Stringer  *
30832e76b18SJoe Stringer  *		**BPF_PROG_TYPE_LIRC_MODE2**
30932e76b18SJoe Stringer  *
31032e76b18SJoe Stringer  *			LIRC device path (eg /dev/lircN). Requires the kernel
31132e76b18SJoe Stringer  *			to be compiled with **CONFIG_BPF_LIRC_MODE2**.
31232e76b18SJoe Stringer  *
31332e76b18SJoe Stringer  *		**BPF_PROG_TYPE_SK_SKB**,
31432e76b18SJoe Stringer  *		**BPF_PROG_TYPE_SK_MSG**
31532e76b18SJoe Stringer  *
31632e76b18SJoe Stringer  *			eBPF map of socket type (eg **BPF_MAP_TYPE_SOCKHASH**).
31732e76b18SJoe Stringer  *
318f67c9cbfSJoe Stringer  *	Return
319f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
320f67c9cbfSJoe Stringer  *		is set appropriately.
321f67c9cbfSJoe Stringer  *
322f67c9cbfSJoe Stringer  * BPF_PROG_DETACH
323f67c9cbfSJoe Stringer  *	Description
324f67c9cbfSJoe Stringer  *		Detach the eBPF program associated with the *target_fd* at the
325f67c9cbfSJoe Stringer  *		hook specified by *attach_type*. The program must have been
326f67c9cbfSJoe Stringer  *		previously attached using **BPF_PROG_ATTACH**.
327f67c9cbfSJoe Stringer  *
328f67c9cbfSJoe Stringer  *	Return
329f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
330f67c9cbfSJoe Stringer  *		is set appropriately.
331f67c9cbfSJoe Stringer  *
332f67c9cbfSJoe Stringer  * BPF_PROG_TEST_RUN
333f67c9cbfSJoe Stringer  *	Description
3342a3fdca4SJoe Stringer  *		Run the eBPF program associated with the *prog_fd* a *repeat*
3352a3fdca4SJoe Stringer  *		number of times against a provided program context *ctx_in* and
3362a3fdca4SJoe Stringer  *		data *data_in*, and return the modified program context
3372a3fdca4SJoe Stringer  *		*ctx_out*, *data_out* (for example, packet data), result of the
3382a3fdca4SJoe Stringer  *		execution *retval*, and *duration* of the test run.
339f67c9cbfSJoe Stringer  *
340f3c45326SJoe Stringer  *		The sizes of the buffers provided as input and output
341f3c45326SJoe Stringer  *		parameters *ctx_in*, *ctx_out*, *data_in*, and *data_out* must
342f3c45326SJoe Stringer  *		be provided in the corresponding variables *ctx_size_in*,
343f3c45326SJoe Stringer  *		*ctx_size_out*, *data_size_in*, and/or *data_size_out*. If any
344f3c45326SJoe Stringer  *		of these parameters are not provided (ie set to NULL), the
345f3c45326SJoe Stringer  *		corresponding size field must be zero.
346f3c45326SJoe Stringer  *
347f3c45326SJoe Stringer  *		Some program types have particular requirements:
348f3c45326SJoe Stringer  *
349f3c45326SJoe Stringer  *		**BPF_PROG_TYPE_SK_LOOKUP**
350f3c45326SJoe Stringer  *			*data_in* and *data_out* must be NULL.
351f3c45326SJoe Stringer  *
352f3c45326SJoe Stringer  *		**BPF_PROG_TYPE_RAW_TRACEPOINT**,
353f3c45326SJoe Stringer  *		**BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE**
354f3c45326SJoe Stringer  *
355f3c45326SJoe Stringer  *			*ctx_out*, *data_in* and *data_out* must be NULL.
356f3c45326SJoe Stringer  *			*repeat* must be zero.
357f3c45326SJoe Stringer  *
358e40fbbf0SUsama Arif  *		BPF_PROG_RUN is an alias for BPF_PROG_TEST_RUN.
359e40fbbf0SUsama Arif  *
360f67c9cbfSJoe Stringer  *	Return
361f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
362f67c9cbfSJoe Stringer  *		is set appropriately.
363f67c9cbfSJoe Stringer  *
3642a3fdca4SJoe Stringer  *		**ENOSPC**
3652a3fdca4SJoe Stringer  *			Either *data_size_out* or *ctx_size_out* is too small.
3662a3fdca4SJoe Stringer  *		**ENOTSUPP**
3672a3fdca4SJoe Stringer  *			This command is not supported by the program type of
3682a3fdca4SJoe Stringer  *			the program referred to by *prog_fd*.
3692a3fdca4SJoe Stringer  *
370f67c9cbfSJoe Stringer  * BPF_PROG_GET_NEXT_ID
371f67c9cbfSJoe Stringer  *	Description
372f67c9cbfSJoe Stringer  *		Fetch the next eBPF program currently loaded into the kernel.
373f67c9cbfSJoe Stringer  *
374f67c9cbfSJoe Stringer  *		Looks for the eBPF program with an id greater than *start_id*
375f67c9cbfSJoe Stringer  *		and updates *next_id* on success. If no other eBPF programs
376f67c9cbfSJoe Stringer  *		remain with ids higher than *start_id*, returns -1 and sets
377f67c9cbfSJoe Stringer  *		*errno* to **ENOENT**.
378f67c9cbfSJoe Stringer  *
379f67c9cbfSJoe Stringer  *	Return
380f67c9cbfSJoe Stringer  *		Returns zero on success. On error, or when no id remains, -1
381f67c9cbfSJoe Stringer  *		is returned and *errno* is set appropriately.
382f67c9cbfSJoe Stringer  *
383f67c9cbfSJoe Stringer  * BPF_MAP_GET_NEXT_ID
384f67c9cbfSJoe Stringer  *	Description
385f67c9cbfSJoe Stringer  *		Fetch the next eBPF map currently loaded into the kernel.
386f67c9cbfSJoe Stringer  *
387f67c9cbfSJoe Stringer  *		Looks for the eBPF map with an id greater than *start_id*
388f67c9cbfSJoe Stringer  *		and updates *next_id* on success. If no other eBPF maps
389f67c9cbfSJoe Stringer  *		remain with ids higher than *start_id*, returns -1 and sets
390f67c9cbfSJoe Stringer  *		*errno* to **ENOENT**.
391f67c9cbfSJoe Stringer  *
392f67c9cbfSJoe Stringer  *	Return
393f67c9cbfSJoe Stringer  *		Returns zero on success. On error, or when no id remains, -1
394f67c9cbfSJoe Stringer  *		is returned and *errno* is set appropriately.
395f67c9cbfSJoe Stringer  *
396f67c9cbfSJoe Stringer  * BPF_PROG_GET_FD_BY_ID
397f67c9cbfSJoe Stringer  *	Description
398f67c9cbfSJoe Stringer  *		Open a file descriptor for the eBPF program corresponding to
399f67c9cbfSJoe Stringer  *		*prog_id*.
400f67c9cbfSJoe Stringer  *
401f67c9cbfSJoe Stringer  *	Return
402f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
403f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
404f67c9cbfSJoe Stringer  *
405f67c9cbfSJoe Stringer  * BPF_MAP_GET_FD_BY_ID
406f67c9cbfSJoe Stringer  *	Description
407f67c9cbfSJoe Stringer  *		Open a file descriptor for the eBPF map corresponding to
408f67c9cbfSJoe Stringer  *		*map_id*.
409f67c9cbfSJoe Stringer  *
410f67c9cbfSJoe Stringer  *	Return
411f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
412f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
413f67c9cbfSJoe Stringer  *
414f67c9cbfSJoe Stringer  * BPF_OBJ_GET_INFO_BY_FD
415f67c9cbfSJoe Stringer  *	Description
416f67c9cbfSJoe Stringer  *		Obtain information about the eBPF object corresponding to
417f67c9cbfSJoe Stringer  *		*bpf_fd*.
418f67c9cbfSJoe Stringer  *
419f67c9cbfSJoe Stringer  *		Populates up to *info_len* bytes of *info*, which will be in
420f67c9cbfSJoe Stringer  *		one of the following formats depending on the eBPF object type
421f67c9cbfSJoe Stringer  *		of *bpf_fd*:
422f67c9cbfSJoe Stringer  *
423f67c9cbfSJoe Stringer  *		* **struct bpf_prog_info**
424f67c9cbfSJoe Stringer  *		* **struct bpf_map_info**
425f67c9cbfSJoe Stringer  *		* **struct bpf_btf_info**
426f67c9cbfSJoe Stringer  *		* **struct bpf_link_info**
427f67c9cbfSJoe Stringer  *
428f67c9cbfSJoe Stringer  *	Return
429f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
430f67c9cbfSJoe Stringer  *		is set appropriately.
431f67c9cbfSJoe Stringer  *
432f67c9cbfSJoe Stringer  * BPF_PROG_QUERY
433f67c9cbfSJoe Stringer  *	Description
434f67c9cbfSJoe Stringer  *		Obtain information about eBPF programs associated with the
435f67c9cbfSJoe Stringer  *		specified *attach_type* hook.
436f67c9cbfSJoe Stringer  *
4375d999994SJoe Stringer  *		The *target_fd* must be a valid file descriptor for a kernel
4385d999994SJoe Stringer  *		object which depends on the attach type of *attach_bpf_fd*:
4395d999994SJoe Stringer  *
4405d999994SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_DEVICE**,
4415d999994SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SKB**,
4425d999994SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SOCK**,
4435d999994SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,
4445d999994SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SOCKOPT**,
4455d999994SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SYSCTL**,
4465d999994SJoe Stringer  *		**BPF_PROG_TYPE_SOCK_OPS**
4475d999994SJoe Stringer  *
4485d999994SJoe Stringer  *			Control Group v2 hierarchy with the eBPF controller
4495d999994SJoe Stringer  *			enabled. Requires the kernel to be compiled with
4505d999994SJoe Stringer  *			**CONFIG_CGROUP_BPF**.
4515d999994SJoe Stringer  *
4525d999994SJoe Stringer  *		**BPF_PROG_TYPE_FLOW_DISSECTOR**
4535d999994SJoe Stringer  *
4545d999994SJoe Stringer  *			Network namespace (eg /proc/self/ns/net).
4555d999994SJoe Stringer  *
4565d999994SJoe Stringer  *		**BPF_PROG_TYPE_LIRC_MODE2**
4575d999994SJoe Stringer  *
4585d999994SJoe Stringer  *			LIRC device path (eg /dev/lircN). Requires the kernel
4595d999994SJoe Stringer  *			to be compiled with **CONFIG_BPF_LIRC_MODE2**.
4605d999994SJoe Stringer  *
4615d999994SJoe Stringer  *		**BPF_PROG_QUERY** always fetches the number of programs
4625d999994SJoe Stringer  *		attached and the *attach_flags* which were used to attach those
4635d999994SJoe Stringer  *		programs. Additionally, if *prog_ids* is nonzero and the number
4645d999994SJoe Stringer  *		of attached programs is less than *prog_cnt*, populates
4655d999994SJoe Stringer  *		*prog_ids* with the eBPF program ids of the programs attached
4665d999994SJoe Stringer  *		at *target_fd*.
4675d999994SJoe Stringer  *
4685d999994SJoe Stringer  *		The following flags may alter the result:
4695d999994SJoe Stringer  *
4705d999994SJoe Stringer  *		**BPF_F_QUERY_EFFECTIVE**
4715d999994SJoe Stringer  *			Only return information regarding programs which are
4725d999994SJoe Stringer  *			currently effective at the specified *target_fd*.
4735d999994SJoe Stringer  *
474f67c9cbfSJoe Stringer  *	Return
475f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
476f67c9cbfSJoe Stringer  *		is set appropriately.
477f67c9cbfSJoe Stringer  *
478f67c9cbfSJoe Stringer  * BPF_RAW_TRACEPOINT_OPEN
479f67c9cbfSJoe Stringer  *	Description
480f67c9cbfSJoe Stringer  *		Attach an eBPF program to a tracepoint *name* to access kernel
481f67c9cbfSJoe Stringer  *		internal arguments of the tracepoint in their raw form.
482f67c9cbfSJoe Stringer  *
483f67c9cbfSJoe Stringer  *		The *prog_fd* must be a valid file descriptor associated with
484f67c9cbfSJoe Stringer  *		a loaded eBPF program of type **BPF_PROG_TYPE_RAW_TRACEPOINT**.
485f67c9cbfSJoe Stringer  *
486f67c9cbfSJoe Stringer  *		No ABI guarantees are made about the content of tracepoint
487f67c9cbfSJoe Stringer  *		arguments exposed to the corresponding eBPF program.
488f67c9cbfSJoe Stringer  *
489f67c9cbfSJoe Stringer  *		Applying **close**\ (2) to the file descriptor returned by
490f67c9cbfSJoe Stringer  *		**BPF_RAW_TRACEPOINT_OPEN** will delete the map (but see NOTES).
491f67c9cbfSJoe Stringer  *
492f67c9cbfSJoe Stringer  *	Return
493f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
494f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
495f67c9cbfSJoe Stringer  *
496f67c9cbfSJoe Stringer  * BPF_BTF_LOAD
497f67c9cbfSJoe Stringer  *	Description
498f67c9cbfSJoe Stringer  *		Verify and load BPF Type Format (BTF) metadata into the kernel,
499f67c9cbfSJoe Stringer  *		returning a new file descriptor associated with the metadata.
500f67c9cbfSJoe Stringer  *		BTF is described in more detail at
501f67c9cbfSJoe Stringer  *		https://www.kernel.org/doc/html/latest/bpf/btf.html.
502f67c9cbfSJoe Stringer  *
503f67c9cbfSJoe Stringer  *		The *btf* parameter must point to valid memory providing
504f67c9cbfSJoe Stringer  *		*btf_size* bytes of BTF binary metadata.
505f67c9cbfSJoe Stringer  *
506f67c9cbfSJoe Stringer  *		The returned file descriptor can be passed to other **bpf**\ ()
507f67c9cbfSJoe Stringer  *		subcommands such as **BPF_PROG_LOAD** or **BPF_MAP_CREATE** to
508f67c9cbfSJoe Stringer  *		associate the BTF with those objects.
509f67c9cbfSJoe Stringer  *
510f67c9cbfSJoe Stringer  *		Similar to **BPF_PROG_LOAD**, **BPF_BTF_LOAD** has optional
511f67c9cbfSJoe Stringer  *		parameters to specify a *btf_log_buf*, *btf_log_size* and
512f67c9cbfSJoe Stringer  *		*btf_log_level* which allow the kernel to return freeform log
513f67c9cbfSJoe Stringer  *		output regarding the BTF verification process.
514f67c9cbfSJoe Stringer  *
515f67c9cbfSJoe Stringer  *	Return
516f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
517f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
518f67c9cbfSJoe Stringer  *
519f67c9cbfSJoe Stringer  * BPF_BTF_GET_FD_BY_ID
520f67c9cbfSJoe Stringer  *	Description
521f67c9cbfSJoe Stringer  *		Open a file descriptor for the BPF Type Format (BTF)
522f67c9cbfSJoe Stringer  *		corresponding to *btf_id*.
523f67c9cbfSJoe Stringer  *
524f67c9cbfSJoe Stringer  *	Return
525f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
526f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
527f67c9cbfSJoe Stringer  *
528f67c9cbfSJoe Stringer  * BPF_TASK_FD_QUERY
529f67c9cbfSJoe Stringer  *	Description
530f67c9cbfSJoe Stringer  *		Obtain information about eBPF programs associated with the
531f67c9cbfSJoe Stringer  *		target process identified by *pid* and *fd*.
532f67c9cbfSJoe Stringer  *
533f67c9cbfSJoe Stringer  *		If the *pid* and *fd* are associated with a tracepoint, kprobe
534f67c9cbfSJoe Stringer  *		or uprobe perf event, then the *prog_id* and *fd_type* will
535f67c9cbfSJoe Stringer  *		be populated with the eBPF program id and file descriptor type
536f67c9cbfSJoe Stringer  *		of type **bpf_task_fd_type**. If associated with a kprobe or
537f67c9cbfSJoe Stringer  *		uprobe, the  *probe_offset* and *probe_addr* will also be
538f67c9cbfSJoe Stringer  *		populated. Optionally, if *buf* is provided, then up to
539f67c9cbfSJoe Stringer  *		*buf_len* bytes of *buf* will be populated with the name of
540f67c9cbfSJoe Stringer  *		the tracepoint, kprobe or uprobe.
541f67c9cbfSJoe Stringer  *
542f67c9cbfSJoe Stringer  *		The resulting *prog_id* may be introspected in deeper detail
543f67c9cbfSJoe Stringer  *		using **BPF_PROG_GET_FD_BY_ID** and **BPF_OBJ_GET_INFO_BY_FD**.
544f67c9cbfSJoe Stringer  *
545f67c9cbfSJoe Stringer  *	Return
546f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
547f67c9cbfSJoe Stringer  *		is set appropriately.
548f67c9cbfSJoe Stringer  *
549f67c9cbfSJoe Stringer  * BPF_MAP_LOOKUP_AND_DELETE_ELEM
550f67c9cbfSJoe Stringer  *	Description
551f67c9cbfSJoe Stringer  *		Look up an element with the given *key* in the map referred to
552f67c9cbfSJoe Stringer  *		by the file descriptor *fd*, and if found, delete the element.
553f67c9cbfSJoe Stringer  *
5543e87f192SDenis Salopek  *		For **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map
5553e87f192SDenis Salopek  *		types, the *flags* argument needs to be set to 0, but for other
5563e87f192SDenis Salopek  *		map types, it may be specified as:
5573e87f192SDenis Salopek  *
5583e87f192SDenis Salopek  *		**BPF_F_LOCK**
5593e87f192SDenis Salopek  *			Look up and delete the value of a spin-locked map
5603e87f192SDenis Salopek  *			without returning the lock. This must be specified if
5613e87f192SDenis Salopek  *			the elements contain a spinlock.
5623e87f192SDenis Salopek  *
563f67c9cbfSJoe Stringer  *		The **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map types
564f67c9cbfSJoe Stringer  *		implement this command as a "pop" operation, deleting the top
565f67c9cbfSJoe Stringer  *		element rather than one corresponding to *key*.
566f67c9cbfSJoe Stringer  *		The *key* and *key_len* parameters should be zeroed when
567f67c9cbfSJoe Stringer  *		issuing this operation for these map types.
568f67c9cbfSJoe Stringer  *
569f67c9cbfSJoe Stringer  *		This command is only valid for the following map types:
570f67c9cbfSJoe Stringer  *		* **BPF_MAP_TYPE_QUEUE**
571f67c9cbfSJoe Stringer  *		* **BPF_MAP_TYPE_STACK**
5723e87f192SDenis Salopek  *		* **BPF_MAP_TYPE_HASH**
5733e87f192SDenis Salopek  *		* **BPF_MAP_TYPE_PERCPU_HASH**
5743e87f192SDenis Salopek  *		* **BPF_MAP_TYPE_LRU_HASH**
5753e87f192SDenis Salopek  *		* **BPF_MAP_TYPE_LRU_PERCPU_HASH**
576f67c9cbfSJoe Stringer  *
577f67c9cbfSJoe Stringer  *	Return
578f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
579f67c9cbfSJoe Stringer  *		is set appropriately.
580f67c9cbfSJoe Stringer  *
581f67c9cbfSJoe Stringer  * BPF_MAP_FREEZE
582f67c9cbfSJoe Stringer  *	Description
583f67c9cbfSJoe Stringer  *		Freeze the permissions of the specified map.
584f67c9cbfSJoe Stringer  *
585f67c9cbfSJoe Stringer  *		Write permissions may be frozen by passing zero *flags*.
586f67c9cbfSJoe Stringer  *		Upon success, no future syscall invocations may alter the
587f67c9cbfSJoe Stringer  *		map state of *map_fd*. Write operations from eBPF programs
588f67c9cbfSJoe Stringer  *		are still possible for a frozen map.
589f67c9cbfSJoe Stringer  *
590f67c9cbfSJoe Stringer  *		Not supported for maps of type **BPF_MAP_TYPE_STRUCT_OPS**.
591f67c9cbfSJoe Stringer  *
592f67c9cbfSJoe Stringer  *	Return
593f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
594f67c9cbfSJoe Stringer  *		is set appropriately.
595f67c9cbfSJoe Stringer  *
596f67c9cbfSJoe Stringer  * BPF_BTF_GET_NEXT_ID
597f67c9cbfSJoe Stringer  *	Description
598f67c9cbfSJoe Stringer  *		Fetch the next BPF Type Format (BTF) object currently loaded
599f67c9cbfSJoe Stringer  *		into the kernel.
600f67c9cbfSJoe Stringer  *
601f67c9cbfSJoe Stringer  *		Looks for the BTF object with an id greater than *start_id*
602f67c9cbfSJoe Stringer  *		and updates *next_id* on success. If no other BTF objects
603f67c9cbfSJoe Stringer  *		remain with ids higher than *start_id*, returns -1 and sets
604f67c9cbfSJoe Stringer  *		*errno* to **ENOENT**.
605f67c9cbfSJoe Stringer  *
606f67c9cbfSJoe Stringer  *	Return
607f67c9cbfSJoe Stringer  *		Returns zero on success. On error, or when no id remains, -1
608f67c9cbfSJoe Stringer  *		is returned and *errno* is set appropriately.
609f67c9cbfSJoe Stringer  *
610f67c9cbfSJoe Stringer  * BPF_MAP_LOOKUP_BATCH
611f67c9cbfSJoe Stringer  *	Description
612f67c9cbfSJoe Stringer  *		Iterate and fetch multiple elements in a map.
613f67c9cbfSJoe Stringer  *
6140cb80454SJoe Stringer  *		Two opaque values are used to manage batch operations,
6150cb80454SJoe Stringer  *		*in_batch* and *out_batch*. Initially, *in_batch* must be set
6160cb80454SJoe Stringer  *		to NULL to begin the batched operation. After each subsequent
6170cb80454SJoe Stringer  *		**BPF_MAP_LOOKUP_BATCH**, the caller should pass the resultant
6180cb80454SJoe Stringer  *		*out_batch* as the *in_batch* for the next operation to
6190cb80454SJoe Stringer  *		continue iteration from the current point.
6200cb80454SJoe Stringer  *
6210cb80454SJoe Stringer  *		The *keys* and *values* are output parameters which must point
6220cb80454SJoe Stringer  *		to memory large enough to hold *count* items based on the key
6230cb80454SJoe Stringer  *		and value size of the map *map_fd*. The *keys* buffer must be
6240cb80454SJoe Stringer  *		of *key_size* * *count*. The *values* buffer must be of
6250cb80454SJoe Stringer  *		*value_size* * *count*.
6260cb80454SJoe Stringer  *
6270cb80454SJoe Stringer  *		The *elem_flags* argument may be specified as one of the
6280cb80454SJoe Stringer  *		following:
6290cb80454SJoe Stringer  *
6300cb80454SJoe Stringer  *		**BPF_F_LOCK**
6310cb80454SJoe Stringer  *			Look up the value of a spin-locked map without
6320cb80454SJoe Stringer  *			returning the lock. This must be specified if the
6330cb80454SJoe Stringer  *			elements contain a spinlock.
6340cb80454SJoe Stringer  *
6350cb80454SJoe Stringer  *		On success, *count* elements from the map are copied into the
6360cb80454SJoe Stringer  *		user buffer, with the keys copied into *keys* and the values
6370cb80454SJoe Stringer  *		copied into the corresponding indices in *values*.
6380cb80454SJoe Stringer  *
6390cb80454SJoe Stringer  *		If an error is returned and *errno* is not **EFAULT**, *count*
6400cb80454SJoe Stringer  *		is set to the number of successfully processed elements.
6410cb80454SJoe Stringer  *
642f67c9cbfSJoe Stringer  *	Return
643f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
644f67c9cbfSJoe Stringer  *		is set appropriately.
645f67c9cbfSJoe Stringer  *
6460cb80454SJoe Stringer  *		May set *errno* to **ENOSPC** to indicate that *keys* or
6470cb80454SJoe Stringer  *		*values* is too small to dump an entire bucket during
6480cb80454SJoe Stringer  *		iteration of a hash-based map type.
6490cb80454SJoe Stringer  *
650f67c9cbfSJoe Stringer  * BPF_MAP_LOOKUP_AND_DELETE_BATCH
651f67c9cbfSJoe Stringer  *	Description
6520cb80454SJoe Stringer  *		Iterate and delete all elements in a map.
6530cb80454SJoe Stringer  *
6540cb80454SJoe Stringer  *		This operation has the same behavior as
6550cb80454SJoe Stringer  *		**BPF_MAP_LOOKUP_BATCH** with two exceptions:
6560cb80454SJoe Stringer  *
6570cb80454SJoe Stringer  *		* Every element that is successfully returned is also deleted
6580cb80454SJoe Stringer  *		  from the map. This is at least *count* elements. Note that
6590cb80454SJoe Stringer  *		  *count* is both an input and an output parameter.
6600cb80454SJoe Stringer  *		* Upon returning with *errno* set to **EFAULT**, up to
6610cb80454SJoe Stringer  *		  *count* elements may be deleted without returning the keys
6620cb80454SJoe Stringer  *		  and values of the deleted elements.
663f67c9cbfSJoe Stringer  *
664f67c9cbfSJoe Stringer  *	Return
665f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
666f67c9cbfSJoe Stringer  *		is set appropriately.
667f67c9cbfSJoe Stringer  *
668f67c9cbfSJoe Stringer  * BPF_MAP_UPDATE_BATCH
669f67c9cbfSJoe Stringer  *	Description
6700cb80454SJoe Stringer  *		Update multiple elements in a map by *key*.
6710cb80454SJoe Stringer  *
6720cb80454SJoe Stringer  *		The *keys* and *values* are input parameters which must point
6730cb80454SJoe Stringer  *		to memory large enough to hold *count* items based on the key
6740cb80454SJoe Stringer  *		and value size of the map *map_fd*. The *keys* buffer must be
6750cb80454SJoe Stringer  *		of *key_size* * *count*. The *values* buffer must be of
6760cb80454SJoe Stringer  *		*value_size* * *count*.
6770cb80454SJoe Stringer  *
6780cb80454SJoe Stringer  *		Each element specified in *keys* is sequentially updated to the
6790cb80454SJoe Stringer  *		value in the corresponding index in *values*. The *in_batch*
6800cb80454SJoe Stringer  *		and *out_batch* parameters are ignored and should be zeroed.
6810cb80454SJoe Stringer  *
6820cb80454SJoe Stringer  *		The *elem_flags* argument should be specified as one of the
6830cb80454SJoe Stringer  *		following:
6840cb80454SJoe Stringer  *
6850cb80454SJoe Stringer  *		**BPF_ANY**
6860cb80454SJoe Stringer  *			Create new elements or update a existing elements.
6870cb80454SJoe Stringer  *		**BPF_NOEXIST**
6880cb80454SJoe Stringer  *			Create new elements only if they do not exist.
6890cb80454SJoe Stringer  *		**BPF_EXIST**
6900cb80454SJoe Stringer  *			Update existing elements.
6910cb80454SJoe Stringer  *		**BPF_F_LOCK**
6920cb80454SJoe Stringer  *			Update spin_lock-ed map elements. This must be
6930cb80454SJoe Stringer  *			specified if the map value contains a spinlock.
6940cb80454SJoe Stringer  *
6950cb80454SJoe Stringer  *		On success, *count* elements from the map are updated.
6960cb80454SJoe Stringer  *
6970cb80454SJoe Stringer  *		If an error is returned and *errno* is not **EFAULT**, *count*
6980cb80454SJoe Stringer  *		is set to the number of successfully processed elements.
699f67c9cbfSJoe Stringer  *
700f67c9cbfSJoe Stringer  *	Return
701f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
702f67c9cbfSJoe Stringer  *		is set appropriately.
703f67c9cbfSJoe Stringer  *
7040cb80454SJoe Stringer  *		May set *errno* to **EINVAL**, **EPERM**, **ENOMEM**, or
7050cb80454SJoe Stringer  *		**E2BIG**. **E2BIG** indicates that the number of elements in
7060cb80454SJoe Stringer  *		the map reached the *max_entries* limit specified at map
7070cb80454SJoe Stringer  *		creation time.
7080cb80454SJoe Stringer  *
7090cb80454SJoe Stringer  *		May set *errno* to one of the following error codes under
7100cb80454SJoe Stringer  *		specific circumstances:
7110cb80454SJoe Stringer  *
7120cb80454SJoe Stringer  *		**EEXIST**
7130cb80454SJoe Stringer  *			If *flags* specifies **BPF_NOEXIST** and the element
7140cb80454SJoe Stringer  *			with *key* already exists in the map.
7150cb80454SJoe Stringer  *		**ENOENT**
7160cb80454SJoe Stringer  *			If *flags* specifies **BPF_EXIST** and the element with
7170cb80454SJoe Stringer  *			*key* does not exist in the map.
7180cb80454SJoe Stringer  *
719f67c9cbfSJoe Stringer  * BPF_MAP_DELETE_BATCH
720f67c9cbfSJoe Stringer  *	Description
7210cb80454SJoe Stringer  *		Delete multiple elements in a map by *key*.
7220cb80454SJoe Stringer  *
7230cb80454SJoe Stringer  *		The *keys* parameter is an input parameter which must point
7240cb80454SJoe Stringer  *		to memory large enough to hold *count* items based on the key
7250cb80454SJoe Stringer  *		size of the map *map_fd*, that is, *key_size* * *count*.
7260cb80454SJoe Stringer  *
7270cb80454SJoe Stringer  *		Each element specified in *keys* is sequentially deleted. The
7280cb80454SJoe Stringer  *		*in_batch*, *out_batch*, and *values* parameters are ignored
7290cb80454SJoe Stringer  *		and should be zeroed.
7300cb80454SJoe Stringer  *
7310cb80454SJoe Stringer  *		The *elem_flags* argument may be specified as one of the
7320cb80454SJoe Stringer  *		following:
7330cb80454SJoe Stringer  *
7340cb80454SJoe Stringer  *		**BPF_F_LOCK**
7350cb80454SJoe Stringer  *			Look up the value of a spin-locked map without
7360cb80454SJoe Stringer  *			returning the lock. This must be specified if the
7370cb80454SJoe Stringer  *			elements contain a spinlock.
7380cb80454SJoe Stringer  *
7390cb80454SJoe Stringer  *		On success, *count* elements from the map are updated.
7400cb80454SJoe Stringer  *
7410cb80454SJoe Stringer  *		If an error is returned and *errno* is not **EFAULT**, *count*
7420cb80454SJoe Stringer  *		is set to the number of successfully processed elements. If
7430cb80454SJoe Stringer  *		*errno* is **EFAULT**, up to *count* elements may be been
7440cb80454SJoe Stringer  *		deleted.
745f67c9cbfSJoe Stringer  *
746f67c9cbfSJoe Stringer  *	Return
747f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
748f67c9cbfSJoe Stringer  *		is set appropriately.
749f67c9cbfSJoe Stringer  *
750f67c9cbfSJoe Stringer  * BPF_LINK_CREATE
751f67c9cbfSJoe Stringer  *	Description
752f67c9cbfSJoe Stringer  *		Attach an eBPF program to a *target_fd* at the specified
753f67c9cbfSJoe Stringer  *		*attach_type* hook and return a file descriptor handle for
754f67c9cbfSJoe Stringer  *		managing the link.
755f67c9cbfSJoe Stringer  *
756f67c9cbfSJoe Stringer  *	Return
757f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
758f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
759f67c9cbfSJoe Stringer  *
760f67c9cbfSJoe Stringer  * BPF_LINK_UPDATE
761f67c9cbfSJoe Stringer  *	Description
762f67c9cbfSJoe Stringer  *		Update the eBPF program in the specified *link_fd* to
763f67c9cbfSJoe Stringer  *		*new_prog_fd*.
764f67c9cbfSJoe Stringer  *
765f67c9cbfSJoe Stringer  *	Return
766f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
767f67c9cbfSJoe Stringer  *		is set appropriately.
768f67c9cbfSJoe Stringer  *
769f67c9cbfSJoe Stringer  * BPF_LINK_GET_FD_BY_ID
770f67c9cbfSJoe Stringer  *	Description
771f67c9cbfSJoe Stringer  *		Open a file descriptor for the eBPF Link corresponding to
772f67c9cbfSJoe Stringer  *		*link_id*.
773f67c9cbfSJoe Stringer  *
774f67c9cbfSJoe Stringer  *	Return
775f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
776f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
777f67c9cbfSJoe Stringer  *
778f67c9cbfSJoe Stringer  * BPF_LINK_GET_NEXT_ID
779f67c9cbfSJoe Stringer  *	Description
780f67c9cbfSJoe Stringer  *		Fetch the next eBPF link currently loaded into the kernel.
781f67c9cbfSJoe Stringer  *
782f67c9cbfSJoe Stringer  *		Looks for the eBPF link with an id greater than *start_id*
783f67c9cbfSJoe Stringer  *		and updates *next_id* on success. If no other eBPF links
784f67c9cbfSJoe Stringer  *		remain with ids higher than *start_id*, returns -1 and sets
785f67c9cbfSJoe Stringer  *		*errno* to **ENOENT**.
786f67c9cbfSJoe Stringer  *
787f67c9cbfSJoe Stringer  *	Return
788f67c9cbfSJoe Stringer  *		Returns zero on success. On error, or when no id remains, -1
789f67c9cbfSJoe Stringer  *		is returned and *errno* is set appropriately.
790f67c9cbfSJoe Stringer  *
791f67c9cbfSJoe Stringer  * BPF_ENABLE_STATS
792f67c9cbfSJoe Stringer  *	Description
793f67c9cbfSJoe Stringer  *		Enable eBPF runtime statistics gathering.
794f67c9cbfSJoe Stringer  *
795f67c9cbfSJoe Stringer  *		Runtime statistics gathering for the eBPF runtime is disabled
796f67c9cbfSJoe Stringer  *		by default to minimize the corresponding performance overhead.
797f67c9cbfSJoe Stringer  *		This command enables statistics globally.
798f67c9cbfSJoe Stringer  *
799f67c9cbfSJoe Stringer  *		Multiple programs may independently enable statistics.
800f67c9cbfSJoe Stringer  *		After gathering the desired statistics, eBPF runtime statistics
801f67c9cbfSJoe Stringer  *		may be disabled again by calling **close**\ (2) for the file
802f67c9cbfSJoe Stringer  *		descriptor returned by this function. Statistics will only be
803f67c9cbfSJoe Stringer  *		disabled system-wide when all outstanding file descriptors
804f67c9cbfSJoe Stringer  *		returned by prior calls for this subcommand are closed.
805f67c9cbfSJoe Stringer  *
806f67c9cbfSJoe Stringer  *	Return
807f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
808f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
809f67c9cbfSJoe Stringer  *
810f67c9cbfSJoe Stringer  * BPF_ITER_CREATE
811f67c9cbfSJoe Stringer  *	Description
812f67c9cbfSJoe Stringer  *		Create an iterator on top of the specified *link_fd* (as
813f67c9cbfSJoe Stringer  *		previously created using **BPF_LINK_CREATE**) and return a
814f67c9cbfSJoe Stringer  *		file descriptor that can be used to trigger the iteration.
815f67c9cbfSJoe Stringer  *
816f67c9cbfSJoe Stringer  *		If the resulting file descriptor is pinned to the filesystem
817f67c9cbfSJoe Stringer  *		using  **BPF_OBJ_PIN**, then subsequent **read**\ (2) syscalls
818f67c9cbfSJoe Stringer  *		for that path will trigger the iterator to read kernel state
819f67c9cbfSJoe Stringer  *		using the eBPF program attached to *link_fd*.
820f67c9cbfSJoe Stringer  *
821f67c9cbfSJoe Stringer  *	Return
822f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
823f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
824f67c9cbfSJoe Stringer  *
825f67c9cbfSJoe Stringer  * BPF_LINK_DETACH
826f67c9cbfSJoe Stringer  *	Description
827f67c9cbfSJoe Stringer  *		Forcefully detach the specified *link_fd* from its
828f67c9cbfSJoe Stringer  *		corresponding attachment point.
829f67c9cbfSJoe Stringer  *
830f67c9cbfSJoe Stringer  *	Return
831f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
832f67c9cbfSJoe Stringer  *		is set appropriately.
833f67c9cbfSJoe Stringer  *
834f67c9cbfSJoe Stringer  * BPF_PROG_BIND_MAP
835f67c9cbfSJoe Stringer  *	Description
836f67c9cbfSJoe Stringer  *		Bind a map to the lifetime of an eBPF program.
837f67c9cbfSJoe Stringer  *
838f67c9cbfSJoe Stringer  *		The map identified by *map_fd* is bound to the program
839f67c9cbfSJoe Stringer  *		identified by *prog_fd* and only released when *prog_fd* is
840f67c9cbfSJoe Stringer  *		released. This may be used in cases where metadata should be
841f67c9cbfSJoe Stringer  *		associated with a program which otherwise does not contain any
842f67c9cbfSJoe Stringer  *		references to the map (for example, embedded in the eBPF
843f67c9cbfSJoe Stringer  *		program instructions).
844f67c9cbfSJoe Stringer  *
845f67c9cbfSJoe Stringer  *	Return
846f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
847f67c9cbfSJoe Stringer  *		is set appropriately.
848f67c9cbfSJoe Stringer  *
8497799e4d9SJoe Stringer  * NOTES
8507799e4d9SJoe Stringer  *	eBPF objects (maps and programs) can be shared between processes.
8518aacb3c8SJoe Stringer  *
8528aacb3c8SJoe Stringer  *	* After **fork**\ (2), the child inherits file descriptors
8538aacb3c8SJoe Stringer  *	  referring to the same eBPF objects.
8548aacb3c8SJoe Stringer  *	* File descriptors referring to eBPF objects can be transferred over
8558aacb3c8SJoe Stringer  *	  **unix**\ (7) domain sockets.
8568aacb3c8SJoe Stringer  *	* File descriptors referring to eBPF objects can be duplicated in the
8578aacb3c8SJoe Stringer  *	  usual way, using **dup**\ (2) and similar calls.
8588aacb3c8SJoe Stringer  *	* File descriptors referring to eBPF objects can be pinned to the
8598aacb3c8SJoe Stringer  *	  filesystem using the **BPF_OBJ_PIN** command of **bpf**\ (2).
8608aacb3c8SJoe Stringer  *
8618aacb3c8SJoe Stringer  *	An eBPF object is deallocated only after all file descriptors referring
8628aacb3c8SJoe Stringer  *	to the object have been closed and no references remain pinned to the
8638aacb3c8SJoe Stringer  *	filesystem or attached (for example, bound to a program or device).
8647799e4d9SJoe Stringer  */
86599c55f7dSAlexei Starovoitov enum bpf_cmd {
86699c55f7dSAlexei Starovoitov 	BPF_MAP_CREATE,
867db20fd2bSAlexei Starovoitov 	BPF_MAP_LOOKUP_ELEM,
868db20fd2bSAlexei Starovoitov 	BPF_MAP_UPDATE_ELEM,
869db20fd2bSAlexei Starovoitov 	BPF_MAP_DELETE_ELEM,
870db20fd2bSAlexei Starovoitov 	BPF_MAP_GET_NEXT_KEY,
87109756af4SAlexei Starovoitov 	BPF_PROG_LOAD,
872b2197755SDaniel Borkmann 	BPF_OBJ_PIN,
873b2197755SDaniel Borkmann 	BPF_OBJ_GET,
874f4324551SDaniel Mack 	BPF_PROG_ATTACH,
875f4324551SDaniel Mack 	BPF_PROG_DETACH,
8761cf1cae9SAlexei Starovoitov 	BPF_PROG_TEST_RUN,
8775d67f349SAlexei Starovoitov 	BPF_PROG_RUN = BPF_PROG_TEST_RUN,
87834ad5580SMartin KaFai Lau 	BPF_PROG_GET_NEXT_ID,
87934ad5580SMartin KaFai Lau 	BPF_MAP_GET_NEXT_ID,
880b16d9aa4SMartin KaFai Lau 	BPF_PROG_GET_FD_BY_ID,
881bd5f5f4eSMartin KaFai Lau 	BPF_MAP_GET_FD_BY_ID,
8821e270976SMartin KaFai Lau 	BPF_OBJ_GET_INFO_BY_FD,
883468e2f64SAlexei Starovoitov 	BPF_PROG_QUERY,
884c4f6699dSAlexei Starovoitov 	BPF_RAW_TRACEPOINT_OPEN,
885f56a653cSMartin KaFai Lau 	BPF_BTF_LOAD,
88678958fcaSMartin KaFai Lau 	BPF_BTF_GET_FD_BY_ID,
88741bdc4b4SYonghong Song 	BPF_TASK_FD_QUERY,
888bd513cd0SMauricio Vasquez B 	BPF_MAP_LOOKUP_AND_DELETE_ELEM,
88987df15deSDaniel Borkmann 	BPF_MAP_FREEZE,
8901b9ed84eSQuentin Monnet 	BPF_BTF_GET_NEXT_ID,
891cb4d03abSBrian Vazquez 	BPF_MAP_LOOKUP_BATCH,
89205799638SYonghong Song 	BPF_MAP_LOOKUP_AND_DELETE_BATCH,
893aa2e93b8SBrian Vazquez 	BPF_MAP_UPDATE_BATCH,
894aa2e93b8SBrian Vazquez 	BPF_MAP_DELETE_BATCH,
895af6eea57SAndrii Nakryiko 	BPF_LINK_CREATE,
8960c991ebcSAndrii Nakryiko 	BPF_LINK_UPDATE,
8972d602c8cSAndrii Nakryiko 	BPF_LINK_GET_FD_BY_ID,
8982d602c8cSAndrii Nakryiko 	BPF_LINK_GET_NEXT_ID,
899d46edd67SSong Liu 	BPF_ENABLE_STATS,
900ac51d99bSYonghong Song 	BPF_ITER_CREATE,
90173b11c2aSAndrii Nakryiko 	BPF_LINK_DETACH,
902ef15314aSYiFei Zhu 	BPF_PROG_BIND_MAP,
90399c55f7dSAlexei Starovoitov };
90499c55f7dSAlexei Starovoitov 
90599c55f7dSAlexei Starovoitov enum bpf_map_type {
90699c55f7dSAlexei Starovoitov 	BPF_MAP_TYPE_UNSPEC,
9070f8e4bd8SAlexei Starovoitov 	BPF_MAP_TYPE_HASH,
90828fbcfa0SAlexei Starovoitov 	BPF_MAP_TYPE_ARRAY,
90904fd61abSAlexei Starovoitov 	BPF_MAP_TYPE_PROG_ARRAY,
910ea317b26SKaixu Xia 	BPF_MAP_TYPE_PERF_EVENT_ARRAY,
911824bd0ceSAlexei Starovoitov 	BPF_MAP_TYPE_PERCPU_HASH,
912a10423b8SAlexei Starovoitov 	BPF_MAP_TYPE_PERCPU_ARRAY,
913d5a3b1f6SAlexei Starovoitov 	BPF_MAP_TYPE_STACK_TRACE,
9144ed8ec52SMartin KaFai Lau 	BPF_MAP_TYPE_CGROUP_ARRAY,
91529ba732aSMartin KaFai Lau 	BPF_MAP_TYPE_LRU_HASH,
9168f844938SMartin KaFai Lau 	BPF_MAP_TYPE_LRU_PERCPU_HASH,
917b95a5c4dSDaniel Mack 	BPF_MAP_TYPE_LPM_TRIE,
91856f668dfSMartin KaFai Lau 	BPF_MAP_TYPE_ARRAY_OF_MAPS,
919bcc6b1b7SMartin KaFai Lau 	BPF_MAP_TYPE_HASH_OF_MAPS,
920546ac1ffSJohn Fastabend 	BPF_MAP_TYPE_DEVMAP,
921174a79ffSJohn Fastabend 	BPF_MAP_TYPE_SOCKMAP,
9226710e112SJesper Dangaard Brouer 	BPF_MAP_TYPE_CPUMAP,
923fbfc504aSBjörn Töpel 	BPF_MAP_TYPE_XSKMAP,
92481110384SJohn Fastabend 	BPF_MAP_TYPE_SOCKHASH,
925c4bcfb38SYonghong Song 	BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED,
926c4bcfb38SYonghong Song 	/* BPF_MAP_TYPE_CGROUP_STORAGE is available to bpf programs attaching
927c4bcfb38SYonghong Song 	 * to a cgroup. The newer BPF_MAP_TYPE_CGRP_STORAGE is available to
928c4bcfb38SYonghong Song 	 * both cgroup-attached and other progs and supports all functionality
929c4bcfb38SYonghong Song 	 * provided by BPF_MAP_TYPE_CGROUP_STORAGE. So mark
930c4bcfb38SYonghong Song 	 * BPF_MAP_TYPE_CGROUP_STORAGE deprecated.
931c4bcfb38SYonghong Song 	 */
932c4bcfb38SYonghong Song 	BPF_MAP_TYPE_CGROUP_STORAGE = BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED,
9335dc4c4b7SMartin KaFai Lau 	BPF_MAP_TYPE_REUSEPORT_SOCKARRAY,
934b741f163SRoman Gushchin 	BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE,
935f1a2e44aSMauricio Vasquez B 	BPF_MAP_TYPE_QUEUE,
936f1a2e44aSMauricio Vasquez B 	BPF_MAP_TYPE_STACK,
9376ac99e8fSMartin KaFai Lau 	BPF_MAP_TYPE_SK_STORAGE,
9386f9d451aSToke Høiland-Jørgensen 	BPF_MAP_TYPE_DEVMAP_HASH,
93985d33df3SMartin KaFai Lau 	BPF_MAP_TYPE_STRUCT_OPS,
940457f4436SAndrii Nakryiko 	BPF_MAP_TYPE_RINGBUF,
9418ea63684SKP Singh 	BPF_MAP_TYPE_INODE_STORAGE,
9424cf1bc1fSKP Singh 	BPF_MAP_TYPE_TASK_STORAGE,
9439330986cSJoanne Koong 	BPF_MAP_TYPE_BLOOM_FILTER,
944583c1f42SDavid Vernet 	BPF_MAP_TYPE_USER_RINGBUF,
945c4bcfb38SYonghong Song 	BPF_MAP_TYPE_CGRP_STORAGE,
94699c55f7dSAlexei Starovoitov };
94799c55f7dSAlexei Starovoitov 
9486c4fc209SDaniel Borkmann /* Note that tracing related programs such as
9496c4fc209SDaniel Borkmann  * BPF_PROG_TYPE_{KPROBE,TRACEPOINT,PERF_EVENT,RAW_TRACEPOINT}
9506c4fc209SDaniel Borkmann  * are not subject to a stable API since kernel internal data
9516c4fc209SDaniel Borkmann  * structures can change from release to release and may
9526c4fc209SDaniel Borkmann  * therefore break existing tracing BPF programs. Tracing BPF
9536c4fc209SDaniel Borkmann  * programs correspond to /a/ specific kernel which is to be
9546c4fc209SDaniel Borkmann  * analyzed, and not /a/ specific kernel /and/ all future ones.
9556c4fc209SDaniel Borkmann  */
95609756af4SAlexei Starovoitov enum bpf_prog_type {
95709756af4SAlexei Starovoitov 	BPF_PROG_TYPE_UNSPEC,
958ddd872bcSAlexei Starovoitov 	BPF_PROG_TYPE_SOCKET_FILTER,
9592541517cSAlexei Starovoitov 	BPF_PROG_TYPE_KPROBE,
96096be4325SDaniel Borkmann 	BPF_PROG_TYPE_SCHED_CLS,
96194caee8cSDaniel Borkmann 	BPF_PROG_TYPE_SCHED_ACT,
96298b5c2c6SAlexei Starovoitov 	BPF_PROG_TYPE_TRACEPOINT,
9636a773a15SBrenden Blanco 	BPF_PROG_TYPE_XDP,
9640515e599SAlexei Starovoitov 	BPF_PROG_TYPE_PERF_EVENT,
9650e33661dSDaniel Mack 	BPF_PROG_TYPE_CGROUP_SKB,
96661023658SDavid Ahern 	BPF_PROG_TYPE_CGROUP_SOCK,
9673a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_IN,
9683a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_OUT,
9693a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_XMIT,
97040304b2aSLawrence Brakmo 	BPF_PROG_TYPE_SOCK_OPS,
971b005fd18SJohn Fastabend 	BPF_PROG_TYPE_SK_SKB,
972ebc614f6SRoman Gushchin 	BPF_PROG_TYPE_CGROUP_DEVICE,
9734f738adbSJohn Fastabend 	BPF_PROG_TYPE_SK_MSG,
974c4f6699dSAlexei Starovoitov 	BPF_PROG_TYPE_RAW_TRACEPOINT,
9754fbac77dSAndrey Ignatov 	BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
976004d4b27SMathieu Xhonneux 	BPF_PROG_TYPE_LWT_SEG6LOCAL,
977f4364dcfSSean Young 	BPF_PROG_TYPE_LIRC_MODE2,
9782dbb9b9eSMartin KaFai Lau 	BPF_PROG_TYPE_SK_REUSEPORT,
979d58e468bSPetar Penkov 	BPF_PROG_TYPE_FLOW_DISSECTOR,
9807b146cebSAndrey Ignatov 	BPF_PROG_TYPE_CGROUP_SYSCTL,
9819df1c28bSMatt Mullins 	BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
9820d01da6aSStanislav Fomichev 	BPF_PROG_TYPE_CGROUP_SOCKOPT,
983f1b9509cSAlexei Starovoitov 	BPF_PROG_TYPE_TRACING,
98427ae7997SMartin KaFai Lau 	BPF_PROG_TYPE_STRUCT_OPS,
985be8704ffSAlexei Starovoitov 	BPF_PROG_TYPE_EXT,
986fc611f47SKP Singh 	BPF_PROG_TYPE_LSM,
987e9ddbb77SJakub Sitnicki 	BPF_PROG_TYPE_SK_LOOKUP,
98879a7f8bdSAlexei Starovoitov 	BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */
98984601d6eSFlorian Westphal 	BPF_PROG_TYPE_NETFILTER,
99009756af4SAlexei Starovoitov };
99109756af4SAlexei Starovoitov 
9920e33661dSDaniel Mack enum bpf_attach_type {
9930e33661dSDaniel Mack 	BPF_CGROUP_INET_INGRESS,
9940e33661dSDaniel Mack 	BPF_CGROUP_INET_EGRESS,
99561023658SDavid Ahern 	BPF_CGROUP_INET_SOCK_CREATE,
99640304b2aSLawrence Brakmo 	BPF_CGROUP_SOCK_OPS,
997464bc0fdSJohn Fastabend 	BPF_SK_SKB_STREAM_PARSER,
998464bc0fdSJohn Fastabend 	BPF_SK_SKB_STREAM_VERDICT,
999ebc614f6SRoman Gushchin 	BPF_CGROUP_DEVICE,
10004f738adbSJohn Fastabend 	BPF_SK_MSG_VERDICT,
10014fbac77dSAndrey Ignatov 	BPF_CGROUP_INET4_BIND,
10024fbac77dSAndrey Ignatov 	BPF_CGROUP_INET6_BIND,
1003d74bad4eSAndrey Ignatov 	BPF_CGROUP_INET4_CONNECT,
1004d74bad4eSAndrey Ignatov 	BPF_CGROUP_INET6_CONNECT,
1005aac3fc32SAndrey Ignatov 	BPF_CGROUP_INET4_POST_BIND,
1006aac3fc32SAndrey Ignatov 	BPF_CGROUP_INET6_POST_BIND,
10071cedee13SAndrey Ignatov 	BPF_CGROUP_UDP4_SENDMSG,
10081cedee13SAndrey Ignatov 	BPF_CGROUP_UDP6_SENDMSG,
1009f4364dcfSSean Young 	BPF_LIRC_MODE2,
1010d58e468bSPetar Penkov 	BPF_FLOW_DISSECTOR,
10117b146cebSAndrey Ignatov 	BPF_CGROUP_SYSCTL,
1012983695faSDaniel Borkmann 	BPF_CGROUP_UDP4_RECVMSG,
1013983695faSDaniel Borkmann 	BPF_CGROUP_UDP6_RECVMSG,
10140d01da6aSStanislav Fomichev 	BPF_CGROUP_GETSOCKOPT,
10150d01da6aSStanislav Fomichev 	BPF_CGROUP_SETSOCKOPT,
1016f1b9509cSAlexei Starovoitov 	BPF_TRACE_RAW_TP,
1017fec56f58SAlexei Starovoitov 	BPF_TRACE_FENTRY,
1018fec56f58SAlexei Starovoitov 	BPF_TRACE_FEXIT,
1019ae240823SKP Singh 	BPF_MODIFY_RETURN,
1020fc611f47SKP Singh 	BPF_LSM_MAC,
102115d83c4dSYonghong Song 	BPF_TRACE_ITER,
10221b66d253SDaniel Borkmann 	BPF_CGROUP_INET4_GETPEERNAME,
10231b66d253SDaniel Borkmann 	BPF_CGROUP_INET6_GETPEERNAME,
10241b66d253SDaniel Borkmann 	BPF_CGROUP_INET4_GETSOCKNAME,
10251b66d253SDaniel Borkmann 	BPF_CGROUP_INET6_GETSOCKNAME,
1026fbee97feSDavid Ahern 	BPF_XDP_DEVMAP,
1027f5836749SStanislav Fomichev 	BPF_CGROUP_INET_SOCK_RELEASE,
102892164774SLorenzo Bianconi 	BPF_XDP_CPUMAP,
1029e9ddbb77SJakub Sitnicki 	BPF_SK_LOOKUP,
1030aa8d3a71SAndrii Nakryiko 	BPF_XDP,
1031a7ba4558SCong Wang 	BPF_SK_SKB_VERDICT,
1032d5e4ddaeSKuniyuki Iwashima 	BPF_SK_REUSEPORT_SELECT,
1033d5e4ddaeSKuniyuki Iwashima 	BPF_SK_REUSEPORT_SELECT_OR_MIGRATE,
1034b89fbfbbSAndrii Nakryiko 	BPF_PERF_EVENT,
10350dcac272SJiri Olsa 	BPF_TRACE_KPROBE_MULTI,
103669fd337aSStanislav Fomichev 	BPF_LSM_CGROUP,
103768b04864SKui-Feng Lee 	BPF_STRUCT_OPS,
1038132328e8SFlorian Westphal 	BPF_NETFILTER,
10390e33661dSDaniel Mack 	__MAX_BPF_ATTACH_TYPE
10400e33661dSDaniel Mack };
10410e33661dSDaniel Mack 
10420e33661dSDaniel Mack #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
10430e33661dSDaniel Mack 
1044f2e10bffSAndrii Nakryiko enum bpf_link_type {
1045f2e10bffSAndrii Nakryiko 	BPF_LINK_TYPE_UNSPEC = 0,
1046f2e10bffSAndrii Nakryiko 	BPF_LINK_TYPE_RAW_TRACEPOINT = 1,
1047f2e10bffSAndrii Nakryiko 	BPF_LINK_TYPE_TRACING = 2,
1048f2e10bffSAndrii Nakryiko 	BPF_LINK_TYPE_CGROUP = 3,
1049de4e05caSYonghong Song 	BPF_LINK_TYPE_ITER = 4,
10507f045a49SJakub Sitnicki 	BPF_LINK_TYPE_NETNS = 5,
1051aa8d3a71SAndrii Nakryiko 	BPF_LINK_TYPE_XDP = 6,
1052b89fbfbbSAndrii Nakryiko 	BPF_LINK_TYPE_PERF_EVENT = 7,
10530dcac272SJiri Olsa 	BPF_LINK_TYPE_KPROBE_MULTI = 8,
1054f7e0beafSKui-Feng Lee 	BPF_LINK_TYPE_STRUCT_OPS = 9,
105584601d6eSFlorian Westphal 	BPF_LINK_TYPE_NETFILTER = 10,
1056f2e10bffSAndrii Nakryiko 
1057f2e10bffSAndrii Nakryiko 	MAX_BPF_LINK_TYPE,
1058f2e10bffSAndrii Nakryiko };
1059f2e10bffSAndrii Nakryiko 
1060*1b715e1bSYafang Shao enum bpf_perf_event_type {
1061*1b715e1bSYafang Shao 	BPF_PERF_EVENT_UNSPEC = 0,
1062*1b715e1bSYafang Shao 	BPF_PERF_EVENT_UPROBE = 1,
1063*1b715e1bSYafang Shao 	BPF_PERF_EVENT_URETPROBE = 2,
1064*1b715e1bSYafang Shao 	BPF_PERF_EVENT_KPROBE = 3,
1065*1b715e1bSYafang Shao 	BPF_PERF_EVENT_KRETPROBE = 4,
1066*1b715e1bSYafang Shao 	BPF_PERF_EVENT_TRACEPOINT = 5,
1067*1b715e1bSYafang Shao 	BPF_PERF_EVENT_EVENT = 6,
1068*1b715e1bSYafang Shao };
1069*1b715e1bSYafang Shao 
1070324bda9eSAlexei Starovoitov /* cgroup-bpf attach flags used in BPF_PROG_ATTACH command
1071324bda9eSAlexei Starovoitov  *
1072324bda9eSAlexei Starovoitov  * NONE(default): No further bpf programs allowed in the subtree.
1073324bda9eSAlexei Starovoitov  *
1074324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_OVERRIDE: If a sub-cgroup installs some bpf program,
1075324bda9eSAlexei Starovoitov  * the program in this cgroup yields to sub-cgroup program.
1076324bda9eSAlexei Starovoitov  *
1077324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_MULTI: If a sub-cgroup installs some bpf program,
1078324bda9eSAlexei Starovoitov  * that cgroup program gets run in addition to the program in this cgroup.
1079324bda9eSAlexei Starovoitov  *
1080324bda9eSAlexei Starovoitov  * Only one program is allowed to be attached to a cgroup with
1081324bda9eSAlexei Starovoitov  * NONE or BPF_F_ALLOW_OVERRIDE flag.
1082324bda9eSAlexei Starovoitov  * Attaching another program on top of NONE or BPF_F_ALLOW_OVERRIDE will
1083324bda9eSAlexei Starovoitov  * release old program and attach the new one. Attach flags has to match.
1084324bda9eSAlexei Starovoitov  *
1085324bda9eSAlexei Starovoitov  * Multiple programs are allowed to be attached to a cgroup with
1086324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_MULTI flag. They are executed in FIFO order
1087324bda9eSAlexei Starovoitov  * (those that were attached first, run first)
1088324bda9eSAlexei Starovoitov  * The programs of sub-cgroup are executed first, then programs of
1089324bda9eSAlexei Starovoitov  * this cgroup and then programs of parent cgroup.
1090324bda9eSAlexei Starovoitov  * When children program makes decision (like picking TCP CA or sock bind)
1091324bda9eSAlexei Starovoitov  * parent program has a chance to override it.
1092324bda9eSAlexei Starovoitov  *
10937dd68b32SAndrey Ignatov  * With BPF_F_ALLOW_MULTI a new program is added to the end of the list of
10947dd68b32SAndrey Ignatov  * programs for a cgroup. Though it's possible to replace an old program at
10957dd68b32SAndrey Ignatov  * any position by also specifying BPF_F_REPLACE flag and position itself in
10967dd68b32SAndrey Ignatov  * replace_bpf_fd attribute. Old program at this position will be released.
10977dd68b32SAndrey Ignatov  *
1098324bda9eSAlexei Starovoitov  * A cgroup with MULTI or OVERRIDE flag allows any attach flags in sub-cgroups.
1099324bda9eSAlexei Starovoitov  * A cgroup with NONE doesn't allow any programs in sub-cgroups.
1100324bda9eSAlexei Starovoitov  * Ex1:
1101324bda9eSAlexei Starovoitov  * cgrp1 (MULTI progs A, B) ->
1102324bda9eSAlexei Starovoitov  *    cgrp2 (OVERRIDE prog C) ->
1103324bda9eSAlexei Starovoitov  *      cgrp3 (MULTI prog D) ->
1104324bda9eSAlexei Starovoitov  *        cgrp4 (OVERRIDE prog E) ->
1105324bda9eSAlexei Starovoitov  *          cgrp5 (NONE prog F)
1106324bda9eSAlexei Starovoitov  * the event in cgrp5 triggers execution of F,D,A,B in that order.
1107324bda9eSAlexei Starovoitov  * if prog F is detached, the execution is E,D,A,B
1108324bda9eSAlexei Starovoitov  * if prog F and D are detached, the execution is E,A,B
1109324bda9eSAlexei Starovoitov  * if prog F, E and D are detached, the execution is C,A,B
1110324bda9eSAlexei Starovoitov  *
1111324bda9eSAlexei Starovoitov  * All eligible programs are executed regardless of return code from
1112324bda9eSAlexei Starovoitov  * earlier programs.
11137f677633SAlexei Starovoitov  */
11147f677633SAlexei Starovoitov #define BPF_F_ALLOW_OVERRIDE	(1U << 0)
1115324bda9eSAlexei Starovoitov #define BPF_F_ALLOW_MULTI	(1U << 1)
11167dd68b32SAndrey Ignatov #define BPF_F_REPLACE		(1U << 2)
11177f677633SAlexei Starovoitov 
1118e07b98d9SDavid S. Miller /* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the
1119e07b98d9SDavid S. Miller  * verifier will perform strict alignment checking as if the kernel
1120e07b98d9SDavid S. Miller  * has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set,
1121e07b98d9SDavid S. Miller  * and NET_IP_ALIGN defined to 2.
1122e07b98d9SDavid S. Miller  */
1123e07b98d9SDavid S. Miller #define BPF_F_STRICT_ALIGNMENT	(1U << 0)
1124e07b98d9SDavid S. Miller 
11255a70f4a6SMichael Weiß /* If BPF_F_ANY_ALIGNMENT is used in BPF_PROG_LOAD command, the
1126e9ee9efcSDavid Miller  * verifier will allow any alignment whatsoever.  On platforms
1127e9ee9efcSDavid Miller  * with strict alignment requirements for loads ands stores (such
1128e9ee9efcSDavid Miller  * as sparc and mips) the verifier validates that all loads and
1129e9ee9efcSDavid Miller  * stores provably follow this requirement.  This flag turns that
1130e9ee9efcSDavid Miller  * checking and enforcement off.
1131e9ee9efcSDavid Miller  *
1132e9ee9efcSDavid Miller  * It is mostly used for testing when we want to validate the
1133e9ee9efcSDavid Miller  * context and memory access aspects of the verifier, but because
1134e9ee9efcSDavid Miller  * of an unaligned access the alignment check would trigger before
1135e9ee9efcSDavid Miller  * the one we are interested in.
1136e9ee9efcSDavid Miller  */
1137e9ee9efcSDavid Miller #define BPF_F_ANY_ALIGNMENT	(1U << 1)
1138e9ee9efcSDavid Miller 
1139c240eff6SJiong Wang /* BPF_F_TEST_RND_HI32 is used in BPF_PROG_LOAD command for testing purpose.
1140c240eff6SJiong Wang  * Verifier does sub-register def/use analysis and identifies instructions whose
1141c240eff6SJiong Wang  * def only matters for low 32-bit, high 32-bit is never referenced later
1142c240eff6SJiong Wang  * through implicit zero extension. Therefore verifier notifies JIT back-ends
1143c240eff6SJiong Wang  * that it is safe to ignore clearing high 32-bit for these instructions. This
1144c240eff6SJiong Wang  * saves some back-ends a lot of code-gen. However such optimization is not
1145c240eff6SJiong Wang  * necessary on some arches, for example x86_64, arm64 etc, whose JIT back-ends
1146c240eff6SJiong Wang  * hence hasn't used verifier's analysis result. But, we really want to have a
1147c240eff6SJiong Wang  * way to be able to verify the correctness of the described optimization on
1148c240eff6SJiong Wang  * x86_64 on which testsuites are frequently exercised.
1149c240eff6SJiong Wang  *
1150c240eff6SJiong Wang  * So, this flag is introduced. Once it is set, verifier will randomize high
1151c240eff6SJiong Wang  * 32-bit for those instructions who has been identified as safe to ignore them.
1152c240eff6SJiong Wang  * Then, if verifier is not doing correct analysis, such randomization will
1153c240eff6SJiong Wang  * regress tests to expose bugs.
1154c240eff6SJiong Wang  */
1155c240eff6SJiong Wang #define BPF_F_TEST_RND_HI32	(1U << 2)
1156c240eff6SJiong Wang 
115710d274e8SAlexei Starovoitov /* The verifier internal test flag. Behavior is undefined */
115810d274e8SAlexei Starovoitov #define BPF_F_TEST_STATE_FREQ	(1U << 3)
115910d274e8SAlexei Starovoitov 
11601e6c62a8SAlexei Starovoitov /* If BPF_F_SLEEPABLE is used in BPF_PROG_LOAD command, the verifier will
11611e6c62a8SAlexei Starovoitov  * restrict map and helper usage for such programs. Sleepable BPF programs can
11621e6c62a8SAlexei Starovoitov  * only be attached to hooks where kernel execution context allows sleeping.
11631e6c62a8SAlexei Starovoitov  * Such programs are allowed to use helpers that may sleep like
11641e6c62a8SAlexei Starovoitov  * bpf_copy_from_user().
11651e6c62a8SAlexei Starovoitov  */
11661e6c62a8SAlexei Starovoitov #define BPF_F_SLEEPABLE		(1U << 4)
11671e6c62a8SAlexei Starovoitov 
1168c2f2cdbeSLorenzo Bianconi /* If BPF_F_XDP_HAS_FRAGS is used in BPF_PROG_LOAD command, the loaded program
1169c2f2cdbeSLorenzo Bianconi  * fully support xdp frags.
1170c2f2cdbeSLorenzo Bianconi  */
1171c2f2cdbeSLorenzo Bianconi #define BPF_F_XDP_HAS_FRAGS	(1U << 5)
1172c2f2cdbeSLorenzo Bianconi 
11732b3486bcSStanislav Fomichev /* If BPF_F_XDP_DEV_BOUND_ONLY is used in BPF_PROG_LOAD command, the loaded
11742b3486bcSStanislav Fomichev  * program becomes device-bound but can access XDP metadata.
11752b3486bcSStanislav Fomichev  */
11762b3486bcSStanislav Fomichev #define BPF_F_XDP_DEV_BOUND_ONLY	(1U << 6)
11772b3486bcSStanislav Fomichev 
11780dcac272SJiri Olsa /* link_create.kprobe_multi.flags used in LINK_CREATE command for
11790dcac272SJiri Olsa  * BPF_TRACE_KPROBE_MULTI attach type to create return probe.
11800dcac272SJiri Olsa  */
11810dcac272SJiri Olsa #define BPF_F_KPROBE_MULTI_RETURN	(1U << 0)
11820dcac272SJiri Olsa 
1183d8eca5bbSDaniel Borkmann /* When BPF ldimm64's insn[0].src_reg != 0 then this can have
11844976b718SHao Luo  * the following extensions:
1185d8eca5bbSDaniel Borkmann  *
1186387544bfSAlexei Starovoitov  * insn[0].src_reg:  BPF_PSEUDO_MAP_[FD|IDX]
1187387544bfSAlexei Starovoitov  * insn[0].imm:      map fd or fd_idx
11884976b718SHao Luo  * insn[1].imm:      0
11894976b718SHao Luo  * insn[0].off:      0
11904976b718SHao Luo  * insn[1].off:      0
11914976b718SHao Luo  * ldimm64 rewrite:  address of map
11924976b718SHao Luo  * verifier type:    CONST_PTR_TO_MAP
1193d8eca5bbSDaniel Borkmann  */
1194f1a66f85SDaniel Borkmann #define BPF_PSEUDO_MAP_FD	1
1195387544bfSAlexei Starovoitov #define BPF_PSEUDO_MAP_IDX	5
1196387544bfSAlexei Starovoitov 
1197387544bfSAlexei Starovoitov /* insn[0].src_reg:  BPF_PSEUDO_MAP_[IDX_]VALUE
1198387544bfSAlexei Starovoitov  * insn[0].imm:      map fd or fd_idx
11994976b718SHao Luo  * insn[1].imm:      offset into value
12004976b718SHao Luo  * insn[0].off:      0
12014976b718SHao Luo  * insn[1].off:      0
12024976b718SHao Luo  * ldimm64 rewrite:  address of map[0]+offset
12034976b718SHao Luo  * verifier type:    PTR_TO_MAP_VALUE
12044976b718SHao Luo  */
1205d8eca5bbSDaniel Borkmann #define BPF_PSEUDO_MAP_VALUE		2
1206387544bfSAlexei Starovoitov #define BPF_PSEUDO_MAP_IDX_VALUE	6
1207387544bfSAlexei Starovoitov 
12084976b718SHao Luo /* insn[0].src_reg:  BPF_PSEUDO_BTF_ID
12094976b718SHao Luo  * insn[0].imm:      kernel btd id of VAR
12104976b718SHao Luo  * insn[1].imm:      0
12114976b718SHao Luo  * insn[0].off:      0
12124976b718SHao Luo  * insn[1].off:      0
12134976b718SHao Luo  * ldimm64 rewrite:  address of the kernel variable
12144976b718SHao Luo  * verifier type:    PTR_TO_BTF_ID or PTR_TO_MEM, depending on whether the var
12154976b718SHao Luo  *                   is struct/union.
12164976b718SHao Luo  */
12174976b718SHao Luo #define BPF_PSEUDO_BTF_ID	3
121869c087baSYonghong Song /* insn[0].src_reg:  BPF_PSEUDO_FUNC
121969c087baSYonghong Song  * insn[0].imm:      insn offset to the func
122069c087baSYonghong Song  * insn[1].imm:      0
122169c087baSYonghong Song  * insn[0].off:      0
122269c087baSYonghong Song  * insn[1].off:      0
122369c087baSYonghong Song  * ldimm64 rewrite:  address of the function
122469c087baSYonghong Song  * verifier type:    PTR_TO_FUNC.
122569c087baSYonghong Song  */
122669c087baSYonghong Song #define BPF_PSEUDO_FUNC		4
1227f1a66f85SDaniel Borkmann 
1228cc8b0b92SAlexei Starovoitov /* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative
1229cc8b0b92SAlexei Starovoitov  * offset to another bpf function
1230cc8b0b92SAlexei Starovoitov  */
1231cc8b0b92SAlexei Starovoitov #define BPF_PSEUDO_CALL		1
1232e6ac2450SMartin KaFai Lau /* when bpf_call->src_reg == BPF_PSEUDO_KFUNC_CALL,
1233e6ac2450SMartin KaFai Lau  * bpf_call->imm == btf_id of a BTF_KIND_FUNC in the running kernel
1234e6ac2450SMartin KaFai Lau  */
1235e6ac2450SMartin KaFai Lau #define BPF_PSEUDO_KFUNC_CALL	2
1236cc8b0b92SAlexei Starovoitov 
12373274f520SAlexei Starovoitov /* flags for BPF_MAP_UPDATE_ELEM command */
12381aae4bddSAndrii Nakryiko enum {
12391aae4bddSAndrii Nakryiko 	BPF_ANY		= 0, /* create new element or update existing */
12401aae4bddSAndrii Nakryiko 	BPF_NOEXIST	= 1, /* create new element if it didn't exist */
12411aae4bddSAndrii Nakryiko 	BPF_EXIST	= 2, /* update existing element */
12421aae4bddSAndrii Nakryiko 	BPF_F_LOCK	= 4, /* spin_lock-ed map_lookup/map_update */
12431aae4bddSAndrii Nakryiko };
12443274f520SAlexei Starovoitov 
124596eabe7aSMartin KaFai Lau /* flags for BPF_MAP_CREATE command */
12461aae4bddSAndrii Nakryiko enum {
12471aae4bddSAndrii Nakryiko 	BPF_F_NO_PREALLOC	= (1U << 0),
124829ba732aSMartin KaFai Lau /* Instead of having one common LRU list in the
12498f844938SMartin KaFai Lau  * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list
125029ba732aSMartin KaFai Lau  * which can scale and perform better.
125129ba732aSMartin KaFai Lau  * Note, the LRU nodes (including free nodes) cannot be moved
125229ba732aSMartin KaFai Lau  * across different LRU lists.
125329ba732aSMartin KaFai Lau  */
12541aae4bddSAndrii Nakryiko 	BPF_F_NO_COMMON_LRU	= (1U << 1),
125596eabe7aSMartin KaFai Lau /* Specify numa node during map creation */
12561aae4bddSAndrii Nakryiko 	BPF_F_NUMA_NODE		= (1U << 2),
1257cb4d2b3fSMartin KaFai Lau 
1258591fe988SDaniel Borkmann /* Flags for accessing BPF object from syscall side. */
12591aae4bddSAndrii Nakryiko 	BPF_F_RDONLY		= (1U << 3),
12601aae4bddSAndrii Nakryiko 	BPF_F_WRONLY		= (1U << 4),
12616e71b04aSChenbo Feng 
1262615755a7SSong Liu /* Flag for stack_map, store build_id+offset instead of pointer */
12631aae4bddSAndrii Nakryiko 	BPF_F_STACK_BUILD_ID	= (1U << 5),
1264615755a7SSong Liu 
126596b3b6c9SLorenz Bauer /* Zero-initialize hash function seed. This should only be used for testing. */
12661aae4bddSAndrii Nakryiko 	BPF_F_ZERO_SEED		= (1U << 6),
126796b3b6c9SLorenz Bauer 
1268591fe988SDaniel Borkmann /* Flags for accessing BPF object from program side. */
12691aae4bddSAndrii Nakryiko 	BPF_F_RDONLY_PROG	= (1U << 7),
12701aae4bddSAndrii Nakryiko 	BPF_F_WRONLY_PROG	= (1U << 8),
1271591fe988SDaniel Borkmann 
12728f51dfc7SStanislav Fomichev /* Clone map from listener for newly accepted socket */
12731aae4bddSAndrii Nakryiko 	BPF_F_CLONE		= (1U << 9),
12748f51dfc7SStanislav Fomichev 
1275fc970227SAndrii Nakryiko /* Enable memory-mapping BPF map */
12761aae4bddSAndrii Nakryiko 	BPF_F_MMAPABLE		= (1U << 10),
1277792cacccSSong Liu 
1278792cacccSSong Liu /* Share perf_event among processes */
1279792cacccSSong Liu 	BPF_F_PRESERVE_ELEMS	= (1U << 11),
12804a8f87e6SDaniel Borkmann 
12814a8f87e6SDaniel Borkmann /* Create a map that is suitable to be an inner map with dynamic max entries */
12824a8f87e6SDaniel Borkmann 	BPF_F_INNER_MAP		= (1U << 12),
128368b04864SKui-Feng Lee 
128468b04864SKui-Feng Lee /* Create a map that will be registered/unregesitered by the backed bpf_link */
128568b04864SKui-Feng Lee 	BPF_F_LINK		= (1U << 13),
1286cb8edce2SAndrii Nakryiko 
1287cb8edce2SAndrii Nakryiko /* Get path from provided FD in BPF_OBJ_PIN/BPF_OBJ_GET commands */
1288cb8edce2SAndrii Nakryiko 	BPF_F_PATH_FD		= (1U << 14),
12891aae4bddSAndrii Nakryiko };
1290fc970227SAndrii Nakryiko 
1291f5bfcd95SAndrey Ignatov /* Flags for BPF_PROG_QUERY. */
1292f5bfcd95SAndrey Ignatov 
1293f5bfcd95SAndrey Ignatov /* Query effective (directly attached + inherited from ancestor cgroups)
1294f5bfcd95SAndrey Ignatov  * programs that will be executed for events within a cgroup.
12950e426a3aSPu Lehui  * attach_flags with this flag are always returned 0.
1296f5bfcd95SAndrey Ignatov  */
12972f183360SLorenz Bauer #define BPF_F_QUERY_EFFECTIVE	(1U << 0)
12982f183360SLorenz Bauer 
12991b4d60ecSSong Liu /* Flags for BPF_PROG_TEST_RUN */
13001b4d60ecSSong Liu 
13011b4d60ecSSong Liu /* If set, run the test on the cpu specified by bpf_attr.test.cpu */
13021b4d60ecSSong Liu #define BPF_F_TEST_RUN_ON_CPU	(1U << 0)
1303b530e9e1SToke Høiland-Jørgensen /* If set, XDP frames will be transmitted after processing */
1304b530e9e1SToke Høiland-Jørgensen #define BPF_F_TEST_XDP_LIVE_FRAMES	(1U << 1)
13051b4d60ecSSong Liu 
1306d46edd67SSong Liu /* type for BPF_ENABLE_STATS */
1307d46edd67SSong Liu enum bpf_stats_type {
1308d46edd67SSong Liu 	/* enabled run_time_ns and run_cnt */
1309d46edd67SSong Liu 	BPF_STATS_RUN_TIME = 0,
1310d46edd67SSong Liu };
1311d46edd67SSong Liu 
1312615755a7SSong Liu enum bpf_stack_build_id_status {
1313615755a7SSong Liu 	/* user space need an empty entry to identify end of a trace */
1314615755a7SSong Liu 	BPF_STACK_BUILD_ID_EMPTY = 0,
1315615755a7SSong Liu 	/* with valid build_id and offset */
1316615755a7SSong Liu 	BPF_STACK_BUILD_ID_VALID = 1,
1317615755a7SSong Liu 	/* couldn't get build_id, fallback to ip */
1318615755a7SSong Liu 	BPF_STACK_BUILD_ID_IP = 2,
1319615755a7SSong Liu };
1320615755a7SSong Liu 
1321615755a7SSong Liu #define BPF_BUILD_ID_SIZE 20
1322615755a7SSong Liu struct bpf_stack_build_id {
1323615755a7SSong Liu 	__s32		status;
1324615755a7SSong Liu 	unsigned char	build_id[BPF_BUILD_ID_SIZE];
1325615755a7SSong Liu 	union {
1326615755a7SSong Liu 		__u64	offset;
1327615755a7SSong Liu 		__u64	ip;
1328615755a7SSong Liu 	};
1329615755a7SSong Liu };
1330615755a7SSong Liu 
13311aae4bddSAndrii Nakryiko #define BPF_OBJ_NAME_LEN 16U
13321aae4bddSAndrii Nakryiko 
133399c55f7dSAlexei Starovoitov union bpf_attr {
133499c55f7dSAlexei Starovoitov 	struct { /* anonymous struct used by BPF_MAP_CREATE command */
133599c55f7dSAlexei Starovoitov 		__u32	map_type;	/* one of enum bpf_map_type */
133699c55f7dSAlexei Starovoitov 		__u32	key_size;	/* size of key in bytes */
133799c55f7dSAlexei Starovoitov 		__u32	value_size;	/* size of value in bytes */
133899c55f7dSAlexei Starovoitov 		__u32	max_entries;	/* max number of entries in a map */
133996eabe7aSMartin KaFai Lau 		__u32	map_flags;	/* BPF_MAP_CREATE related
134096eabe7aSMartin KaFai Lau 					 * flags defined above.
134196eabe7aSMartin KaFai Lau 					 */
134256f668dfSMartin KaFai Lau 		__u32	inner_map_fd;	/* fd pointing to the inner map */
134396eabe7aSMartin KaFai Lau 		__u32	numa_node;	/* numa node (effective only if
134496eabe7aSMartin KaFai Lau 					 * BPF_F_NUMA_NODE is set).
134596eabe7aSMartin KaFai Lau 					 */
1346067cae47SMartin KaFai Lau 		char	map_name[BPF_OBJ_NAME_LEN];
1347a3884572SJakub Kicinski 		__u32	map_ifindex;	/* ifindex of netdev to create on */
1348a26ca7c9SMartin KaFai Lau 		__u32	btf_fd;		/* fd pointing to a BTF type data */
13499b2cf328SMartin KaFai Lau 		__u32	btf_key_type_id;	/* BTF type_id of the key */
13509b2cf328SMartin KaFai Lau 		__u32	btf_value_type_id;	/* BTF type_id of the value */
135185d33df3SMartin KaFai Lau 		__u32	btf_vmlinux_value_type_id;/* BTF type_id of a kernel-
135285d33df3SMartin KaFai Lau 						   * struct stored as the
135385d33df3SMartin KaFai Lau 						   * map value
135485d33df3SMartin KaFai Lau 						   */
13559330986cSJoanne Koong 		/* Any per-map-type extra fields
13569330986cSJoanne Koong 		 *
13579330986cSJoanne Koong 		 * BPF_MAP_TYPE_BLOOM_FILTER - the lowest 4 bits indicate the
13589330986cSJoanne Koong 		 * number of hash functions (if 0, the bloom filter will default
13599330986cSJoanne Koong 		 * to using 5 hash functions).
13609330986cSJoanne Koong 		 */
13619330986cSJoanne Koong 		__u64	map_extra;
136299c55f7dSAlexei Starovoitov 	};
1363db20fd2bSAlexei Starovoitov 
1364db20fd2bSAlexei Starovoitov 	struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
1365db20fd2bSAlexei Starovoitov 		__u32		map_fd;
1366db20fd2bSAlexei Starovoitov 		__aligned_u64	key;
1367db20fd2bSAlexei Starovoitov 		union {
1368db20fd2bSAlexei Starovoitov 			__aligned_u64 value;
1369db20fd2bSAlexei Starovoitov 			__aligned_u64 next_key;
1370db20fd2bSAlexei Starovoitov 		};
13713274f520SAlexei Starovoitov 		__u64		flags;
1372db20fd2bSAlexei Starovoitov 	};
137309756af4SAlexei Starovoitov 
1374cb4d03abSBrian Vazquez 	struct { /* struct used by BPF_MAP_*_BATCH commands */
1375cb4d03abSBrian Vazquez 		__aligned_u64	in_batch;	/* start batch,
1376cb4d03abSBrian Vazquez 						 * NULL to start from beginning
1377cb4d03abSBrian Vazquez 						 */
1378cb4d03abSBrian Vazquez 		__aligned_u64	out_batch;	/* output: next start batch */
1379cb4d03abSBrian Vazquez 		__aligned_u64	keys;
1380cb4d03abSBrian Vazquez 		__aligned_u64	values;
1381cb4d03abSBrian Vazquez 		__u32		count;		/* input/output:
1382cb4d03abSBrian Vazquez 						 * input: # of key/value
1383cb4d03abSBrian Vazquez 						 * elements
1384cb4d03abSBrian Vazquez 						 * output: # of filled elements
1385cb4d03abSBrian Vazquez 						 */
1386cb4d03abSBrian Vazquez 		__u32		map_fd;
1387cb4d03abSBrian Vazquez 		__u64		elem_flags;
1388cb4d03abSBrian Vazquez 		__u64		flags;
1389cb4d03abSBrian Vazquez 	} batch;
1390cb4d03abSBrian Vazquez 
139109756af4SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_LOAD command */
139209756af4SAlexei Starovoitov 		__u32		prog_type;	/* one of enum bpf_prog_type */
139309756af4SAlexei Starovoitov 		__u32		insn_cnt;
139409756af4SAlexei Starovoitov 		__aligned_u64	insns;
139509756af4SAlexei Starovoitov 		__aligned_u64	license;
1396cbd35700SAlexei Starovoitov 		__u32		log_level;	/* verbosity level of verifier */
1397cbd35700SAlexei Starovoitov 		__u32		log_size;	/* size of user buffer */
1398cbd35700SAlexei Starovoitov 		__aligned_u64	log_buf;	/* user supplied buffer */
13996c4fc209SDaniel Borkmann 		__u32		kern_version;	/* not used */
1400e07b98d9SDavid S. Miller 		__u32		prog_flags;
1401067cae47SMartin KaFai Lau 		char		prog_name[BPF_OBJ_NAME_LEN];
14021f6f4cb7SJakub Kicinski 		__u32		prog_ifindex;	/* ifindex of netdev to prep for */
14035e43f899SAndrey Ignatov 		/* For some prog types expected attach type must be known at
14045e43f899SAndrey Ignatov 		 * load time to verify attach type specific parts of prog
14055e43f899SAndrey Ignatov 		 * (context accesses, allowed helpers, etc).
14065e43f899SAndrey Ignatov 		 */
14075e43f899SAndrey Ignatov 		__u32		expected_attach_type;
1408838e9690SYonghong Song 		__u32		prog_btf_fd;	/* fd pointing to BTF type data */
1409838e9690SYonghong Song 		__u32		func_info_rec_size;	/* userspace bpf_func_info size */
1410838e9690SYonghong Song 		__aligned_u64	func_info;	/* func info */
1411838e9690SYonghong Song 		__u32		func_info_cnt;	/* number of bpf_func_info records */
1412c454a46bSMartin KaFai Lau 		__u32		line_info_rec_size;	/* userspace bpf_line_info size */
1413c454a46bSMartin KaFai Lau 		__aligned_u64	line_info;	/* line info */
1414c454a46bSMartin KaFai Lau 		__u32		line_info_cnt;	/* number of bpf_line_info records */
1415ccfe29ebSAlexei Starovoitov 		__u32		attach_btf_id;	/* in-kernel BTF type id to attach to */
1416290248a5SAndrii Nakryiko 		union {
1417290248a5SAndrii Nakryiko 			/* valid prog_fd to attach to bpf prog */
1418290248a5SAndrii Nakryiko 			__u32		attach_prog_fd;
1419290248a5SAndrii Nakryiko 			/* or valid module BTF object fd or 0 to attach to vmlinux */
1420290248a5SAndrii Nakryiko 			__u32		attach_btf_obj_fd;
1421290248a5SAndrii Nakryiko 		};
1422fbd94c7aSAlexei Starovoitov 		__u32		core_relo_cnt;	/* number of bpf_core_relo */
1423387544bfSAlexei Starovoitov 		__aligned_u64	fd_array;	/* array of FDs */
1424fbd94c7aSAlexei Starovoitov 		__aligned_u64	core_relos;
1425fbd94c7aSAlexei Starovoitov 		__u32		core_relo_rec_size; /* sizeof(struct bpf_core_relo) */
142647a71c1fSAndrii Nakryiko 		/* output: actual total log contents size (including termintaing zero).
142747a71c1fSAndrii Nakryiko 		 * It could be both larger than original log_size (if log was
142847a71c1fSAndrii Nakryiko 		 * truncated), or smaller (if log buffer wasn't filled completely).
142947a71c1fSAndrii Nakryiko 		 */
143047a71c1fSAndrii Nakryiko 		__u32		log_true_size;
143109756af4SAlexei Starovoitov 	};
1432b2197755SDaniel Borkmann 
1433b2197755SDaniel Borkmann 	struct { /* anonymous struct used by BPF_OBJ_* commands */
1434b2197755SDaniel Borkmann 		__aligned_u64	pathname;
1435b2197755SDaniel Borkmann 		__u32		bpf_fd;
14366e71b04aSChenbo Feng 		__u32		file_flags;
1437cb8edce2SAndrii Nakryiko 		/* Same as dirfd in openat() syscall; see openat(2)
1438cb8edce2SAndrii Nakryiko 		 * manpage for details of path FD and pathname semantics;
1439cb8edce2SAndrii Nakryiko 		 * path_fd should accompanied by BPF_F_PATH_FD flag set in
1440cb8edce2SAndrii Nakryiko 		 * file_flags field, otherwise it should be set to zero;
1441cb8edce2SAndrii Nakryiko 		 * if BPF_F_PATH_FD flag is not set, AT_FDCWD is assumed.
1442cb8edce2SAndrii Nakryiko 		 */
1443cb8edce2SAndrii Nakryiko 		__s32		path_fd;
1444b2197755SDaniel Borkmann 	};
1445f4324551SDaniel Mack 
1446f4324551SDaniel Mack 	struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
1447f4324551SDaniel Mack 		__u32		target_fd;	/* container object to attach to */
1448f4324551SDaniel Mack 		__u32		attach_bpf_fd;	/* eBPF program to attach */
1449f4324551SDaniel Mack 		__u32		attach_type;
14507f677633SAlexei Starovoitov 		__u32		attach_flags;
14517dd68b32SAndrey Ignatov 		__u32		replace_bpf_fd;	/* previously attached eBPF
14527dd68b32SAndrey Ignatov 						 * program to replace if
14537dd68b32SAndrey Ignatov 						 * BPF_F_REPLACE is used
14547dd68b32SAndrey Ignatov 						 */
1455f4324551SDaniel Mack 	};
14561cf1cae9SAlexei Starovoitov 
14571cf1cae9SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
14581cf1cae9SAlexei Starovoitov 		__u32		prog_fd;
14591cf1cae9SAlexei Starovoitov 		__u32		retval;
1460b5a36b1eSLorenz Bauer 		__u32		data_size_in;	/* input: len of data_in */
1461b5a36b1eSLorenz Bauer 		__u32		data_size_out;	/* input/output: len of data_out
1462b5a36b1eSLorenz Bauer 						 *   returns ENOSPC if data_out
1463b5a36b1eSLorenz Bauer 						 *   is too small.
1464b5a36b1eSLorenz Bauer 						 */
14651cf1cae9SAlexei Starovoitov 		__aligned_u64	data_in;
14661cf1cae9SAlexei Starovoitov 		__aligned_u64	data_out;
14671cf1cae9SAlexei Starovoitov 		__u32		repeat;
14681cf1cae9SAlexei Starovoitov 		__u32		duration;
1469b0b9395dSStanislav Fomichev 		__u32		ctx_size_in;	/* input: len of ctx_in */
1470b0b9395dSStanislav Fomichev 		__u32		ctx_size_out;	/* input/output: len of ctx_out
1471b0b9395dSStanislav Fomichev 						 *   returns ENOSPC if ctx_out
1472b0b9395dSStanislav Fomichev 						 *   is too small.
1473b0b9395dSStanislav Fomichev 						 */
1474b0b9395dSStanislav Fomichev 		__aligned_u64	ctx_in;
1475b0b9395dSStanislav Fomichev 		__aligned_u64	ctx_out;
14761b4d60ecSSong Liu 		__u32		flags;
14771b4d60ecSSong Liu 		__u32		cpu;
1478b530e9e1SToke Høiland-Jørgensen 		__u32		batch_size;
14791cf1cae9SAlexei Starovoitov 	} test;
148034ad5580SMartin KaFai Lau 
1481b16d9aa4SMartin KaFai Lau 	struct { /* anonymous struct used by BPF_*_GET_*_ID */
1482b16d9aa4SMartin KaFai Lau 		union {
148334ad5580SMartin KaFai Lau 			__u32		start_id;
1484b16d9aa4SMartin KaFai Lau 			__u32		prog_id;
1485bd5f5f4eSMartin KaFai Lau 			__u32		map_id;
148678958fcaSMartin KaFai Lau 			__u32		btf_id;
1487a3b80e10SAndrii Nakryiko 			__u32		link_id;
1488b16d9aa4SMartin KaFai Lau 		};
148934ad5580SMartin KaFai Lau 		__u32		next_id;
14906e71b04aSChenbo Feng 		__u32		open_flags;
149134ad5580SMartin KaFai Lau 	};
14921e270976SMartin KaFai Lau 
14931e270976SMartin KaFai Lau 	struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
14941e270976SMartin KaFai Lau 		__u32		bpf_fd;
14951e270976SMartin KaFai Lau 		__u32		info_len;
14961e270976SMartin KaFai Lau 		__aligned_u64	info;
14971e270976SMartin KaFai Lau 	} info;
1498468e2f64SAlexei Starovoitov 
1499468e2f64SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_QUERY command */
1500468e2f64SAlexei Starovoitov 		__u32		target_fd;	/* container object to query */
1501468e2f64SAlexei Starovoitov 		__u32		attach_type;
1502468e2f64SAlexei Starovoitov 		__u32		query_flags;
1503468e2f64SAlexei Starovoitov 		__u32		attach_flags;
1504468e2f64SAlexei Starovoitov 		__aligned_u64	prog_ids;
1505468e2f64SAlexei Starovoitov 		__u32		prog_cnt;
15060e426a3aSPu Lehui 		/* output: per-program attach_flags.
15070e426a3aSPu Lehui 		 * not allowed to be set during effective query.
15080e426a3aSPu Lehui 		 */
15090e426a3aSPu Lehui 		__aligned_u64	prog_attach_flags;
1510468e2f64SAlexei Starovoitov 	} query;
1511c4f6699dSAlexei Starovoitov 
1512af6eea57SAndrii Nakryiko 	struct { /* anonymous struct used by BPF_RAW_TRACEPOINT_OPEN command */
1513c4f6699dSAlexei Starovoitov 		__u64 name;
1514c4f6699dSAlexei Starovoitov 		__u32 prog_fd;
1515c4f6699dSAlexei Starovoitov 	} raw_tracepoint;
1516f56a653cSMartin KaFai Lau 
1517f56a653cSMartin KaFai Lau 	struct { /* anonymous struct for BPF_BTF_LOAD */
1518f56a653cSMartin KaFai Lau 		__aligned_u64	btf;
1519f56a653cSMartin KaFai Lau 		__aligned_u64	btf_log_buf;
1520f56a653cSMartin KaFai Lau 		__u32		btf_size;
1521f56a653cSMartin KaFai Lau 		__u32		btf_log_size;
1522f56a653cSMartin KaFai Lau 		__u32		btf_log_level;
152347a71c1fSAndrii Nakryiko 		/* output: actual total log contents size (including termintaing zero).
152447a71c1fSAndrii Nakryiko 		 * It could be both larger than original log_size (if log was
152547a71c1fSAndrii Nakryiko 		 * truncated), or smaller (if log buffer wasn't filled completely).
152647a71c1fSAndrii Nakryiko 		 */
152747a71c1fSAndrii Nakryiko 		__u32		btf_log_true_size;
1528f56a653cSMartin KaFai Lau 	};
152941bdc4b4SYonghong Song 
153041bdc4b4SYonghong Song 	struct {
153141bdc4b4SYonghong Song 		__u32		pid;		/* input: pid */
153241bdc4b4SYonghong Song 		__u32		fd;		/* input: fd */
153341bdc4b4SYonghong Song 		__u32		flags;		/* input: flags */
153441bdc4b4SYonghong Song 		__u32		buf_len;	/* input/output: buf len */
153541bdc4b4SYonghong Song 		__aligned_u64	buf;		/* input/output:
153641bdc4b4SYonghong Song 						 *   tp_name for tracepoint
153741bdc4b4SYonghong Song 						 *   symbol for kprobe
153841bdc4b4SYonghong Song 						 *   filename for uprobe
153941bdc4b4SYonghong Song 						 */
154041bdc4b4SYonghong Song 		__u32		prog_id;	/* output: prod_id */
154141bdc4b4SYonghong Song 		__u32		fd_type;	/* output: BPF_FD_TYPE_* */
154241bdc4b4SYonghong Song 		__u64		probe_offset;	/* output: probe_offset */
154341bdc4b4SYonghong Song 		__u64		probe_addr;	/* output: probe_addr */
154441bdc4b4SYonghong Song 	} task_fd_query;
1545af6eea57SAndrii Nakryiko 
1546af6eea57SAndrii Nakryiko 	struct { /* struct used by BPF_LINK_CREATE command */
154768b04864SKui-Feng Lee 		union {
1548af6eea57SAndrii Nakryiko 			__u32		prog_fd;	/* eBPF program to attach */
154968b04864SKui-Feng Lee 			__u32		map_fd;		/* struct_ops to attach */
155068b04864SKui-Feng Lee 		};
1551aa8d3a71SAndrii Nakryiko 		union {
1552af6eea57SAndrii Nakryiko 			__u32		target_fd;	/* object to attach to */
1553aa8d3a71SAndrii Nakryiko 			__u32		target_ifindex; /* target ifindex */
1554aa8d3a71SAndrii Nakryiko 		};
1555af6eea57SAndrii Nakryiko 		__u32		attach_type;	/* attach type */
1556af6eea57SAndrii Nakryiko 		__u32		flags;		/* extra flags */
15574a1e7c0cSToke Høiland-Jørgensen 		union {
15584a1e7c0cSToke Høiland-Jørgensen 			__u32		target_btf_id;	/* btf_id of target to attach to */
15594a1e7c0cSToke Høiland-Jørgensen 			struct {
15605e7b3020SYonghong Song 				__aligned_u64	iter_info;	/* extra bpf_iter_link_info */
15615e7b3020SYonghong Song 				__u32		iter_info_len;	/* iter_info length */
15624a1e7c0cSToke Høiland-Jørgensen 			};
156382e6b1eeSAndrii Nakryiko 			struct {
156482e6b1eeSAndrii Nakryiko 				/* black box user-provided value passed through
156582e6b1eeSAndrii Nakryiko 				 * to BPF program at the execution time and
156682e6b1eeSAndrii Nakryiko 				 * accessible through bpf_get_attach_cookie() BPF helper
156782e6b1eeSAndrii Nakryiko 				 */
156882e6b1eeSAndrii Nakryiko 				__u64		bpf_cookie;
156982e6b1eeSAndrii Nakryiko 			} perf_event;
15700dcac272SJiri Olsa 			struct {
15710dcac272SJiri Olsa 				__u32		flags;
15720dcac272SJiri Olsa 				__u32		cnt;
15730dcac272SJiri Olsa 				__aligned_u64	syms;
15740dcac272SJiri Olsa 				__aligned_u64	addrs;
1575ca74823cSJiri Olsa 				__aligned_u64	cookies;
15760dcac272SJiri Olsa 			} kprobe_multi;
15772fcc8241SKui-Feng Lee 			struct {
15782fcc8241SKui-Feng Lee 				/* this is overlaid with the target_btf_id above. */
15792fcc8241SKui-Feng Lee 				__u32		target_btf_id;
15802fcc8241SKui-Feng Lee 				/* black box user-provided value passed through
15812fcc8241SKui-Feng Lee 				 * to BPF program at the execution time and
15822fcc8241SKui-Feng Lee 				 * accessible through bpf_get_attach_cookie() BPF helper
15832fcc8241SKui-Feng Lee 				 */
15842fcc8241SKui-Feng Lee 				__u64		cookie;
15852fcc8241SKui-Feng Lee 			} tracing;
158684601d6eSFlorian Westphal 			struct {
158784601d6eSFlorian Westphal 				__u32		pf;
158884601d6eSFlorian Westphal 				__u32		hooknum;
158984601d6eSFlorian Westphal 				__s32		priority;
159084601d6eSFlorian Westphal 				__u32		flags;
159184601d6eSFlorian Westphal 			} netfilter;
15924a1e7c0cSToke Høiland-Jørgensen 		};
1593af6eea57SAndrii Nakryiko 	} link_create;
15940c991ebcSAndrii Nakryiko 
15950c991ebcSAndrii Nakryiko 	struct { /* struct used by BPF_LINK_UPDATE command */
15960c991ebcSAndrii Nakryiko 		__u32		link_fd;	/* link fd */
1597aef56f2eSKui-Feng Lee 		union {
15980c991ebcSAndrii Nakryiko 			/* new program fd to update link with */
15990c991ebcSAndrii Nakryiko 			__u32		new_prog_fd;
1600aef56f2eSKui-Feng Lee 			/* new struct_ops map fd to update link with */
1601aef56f2eSKui-Feng Lee 			__u32           new_map_fd;
1602aef56f2eSKui-Feng Lee 		};
16030c991ebcSAndrii Nakryiko 		__u32		flags;		/* extra flags */
1604aef56f2eSKui-Feng Lee 		union {
16050c991ebcSAndrii Nakryiko 			/* expected link's program fd; is specified only if
1606aef56f2eSKui-Feng Lee 			 * BPF_F_REPLACE flag is set in flags.
1607aef56f2eSKui-Feng Lee 			 */
16080c991ebcSAndrii Nakryiko 			__u32		old_prog_fd;
1609aef56f2eSKui-Feng Lee 			/* expected link's map fd; is specified only
1610aef56f2eSKui-Feng Lee 			 * if BPF_F_REPLACE flag is set.
1611aef56f2eSKui-Feng Lee 			 */
1612aef56f2eSKui-Feng Lee 			__u32           old_map_fd;
1613aef56f2eSKui-Feng Lee 		};
16140c991ebcSAndrii Nakryiko 	} link_update;
16150c991ebcSAndrii Nakryiko 
161673b11c2aSAndrii Nakryiko 	struct {
161773b11c2aSAndrii Nakryiko 		__u32		link_fd;
161873b11c2aSAndrii Nakryiko 	} link_detach;
161973b11c2aSAndrii Nakryiko 
1620d46edd67SSong Liu 	struct { /* struct used by BPF_ENABLE_STATS command */
1621d46edd67SSong Liu 		__u32		type;
1622d46edd67SSong Liu 	} enable_stats;
1623d46edd67SSong Liu 
1624ac51d99bSYonghong Song 	struct { /* struct used by BPF_ITER_CREATE command */
1625ac51d99bSYonghong Song 		__u32		link_fd;
1626ac51d99bSYonghong Song 		__u32		flags;
1627ac51d99bSYonghong Song 	} iter_create;
1628ac51d99bSYonghong Song 
1629ef15314aSYiFei Zhu 	struct { /* struct used by BPF_PROG_BIND_MAP command */
1630ef15314aSYiFei Zhu 		__u32		prog_fd;
1631ef15314aSYiFei Zhu 		__u32		map_fd;
1632ef15314aSYiFei Zhu 		__u32		flags;		/* extra flags */
1633ef15314aSYiFei Zhu 	} prog_bind_map;
1634ef15314aSYiFei Zhu 
163599c55f7dSAlexei Starovoitov } __attribute__((aligned(8)));
163699c55f7dSAlexei Starovoitov 
163756a092c8SQuentin Monnet /* The description below is an attempt at providing documentation to eBPF
163856a092c8SQuentin Monnet  * developers about the multiple available eBPF helper functions. It can be
163956a092c8SQuentin Monnet  * parsed and used to produce a manual page. The workflow is the following,
164056a092c8SQuentin Monnet  * and requires the rst2man utility:
1641ebb676daSThomas Graf  *
1642923a932cSJoe Stringer  *     $ ./scripts/bpf_doc.py \
164356a092c8SQuentin Monnet  *             --filename include/uapi/linux/bpf.h > /tmp/bpf-helpers.rst
164456a092c8SQuentin Monnet  *     $ rst2man /tmp/bpf-helpers.rst > /tmp/bpf-helpers.7
164556a092c8SQuentin Monnet  *     $ man /tmp/bpf-helpers.7
1646ebb676daSThomas Graf  *
164756a092c8SQuentin Monnet  * Note that in order to produce this external documentation, some RST
164856a092c8SQuentin Monnet  * formatting is used in the descriptions to get "bold" and "italics" in
164956a092c8SQuentin Monnet  * manual pages. Also note that the few trailing white spaces are
165056a092c8SQuentin Monnet  * intentional, removing them would break paragraphs for rst2man.
1651ebb676daSThomas Graf  *
165256a092c8SQuentin Monnet  * Start of BPF helper function descriptions:
1653ad4a5223SQuentin Monnet  *
1654ad4a5223SQuentin Monnet  * void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)
1655ad4a5223SQuentin Monnet  * 	Description
1656ad4a5223SQuentin Monnet  * 		Perform a lookup in *map* for an entry associated to *key*.
1657ad4a5223SQuentin Monnet  * 	Return
1658ad4a5223SQuentin Monnet  * 		Map value associated to *key*, or **NULL** if no entry was
1659ad4a5223SQuentin Monnet  * 		found.
1660ad4a5223SQuentin Monnet  *
1661bdb7b79bSAndrii Nakryiko  * long bpf_map_update_elem(struct bpf_map *map, const void *key, const void *value, u64 flags)
1662ad4a5223SQuentin Monnet  * 	Description
1663ad4a5223SQuentin Monnet  * 		Add or update the value of the entry associated to *key* in
1664ad4a5223SQuentin Monnet  * 		*map* with *value*. *flags* is one of:
1665ad4a5223SQuentin Monnet  *
1666ad4a5223SQuentin Monnet  * 		**BPF_NOEXIST**
1667ad4a5223SQuentin Monnet  * 			The entry for *key* must not exist in the map.
1668ad4a5223SQuentin Monnet  * 		**BPF_EXIST**
1669ad4a5223SQuentin Monnet  * 			The entry for *key* must already exist in the map.
1670ad4a5223SQuentin Monnet  * 		**BPF_ANY**
1671ad4a5223SQuentin Monnet  * 			No condition on the existence of the entry for *key*.
1672ad4a5223SQuentin Monnet  *
1673ad4a5223SQuentin Monnet  * 		Flag value **BPF_NOEXIST** cannot be used for maps of types
1674ad4a5223SQuentin Monnet  * 		**BPF_MAP_TYPE_ARRAY** or **BPF_MAP_TYPE_PERCPU_ARRAY**  (all
1675ad4a5223SQuentin Monnet  * 		elements always exist), the helper would return an error.
1676ad4a5223SQuentin Monnet  * 	Return
1677ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1678ad4a5223SQuentin Monnet  *
1679bdb7b79bSAndrii Nakryiko  * long bpf_map_delete_elem(struct bpf_map *map, const void *key)
1680ad4a5223SQuentin Monnet  * 	Description
1681ad4a5223SQuentin Monnet  * 		Delete entry with *key* from *map*.
1682ad4a5223SQuentin Monnet  * 	Return
1683ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1684ad4a5223SQuentin Monnet  *
1685bdb7b79bSAndrii Nakryiko  * long bpf_probe_read(void *dst, u32 size, const void *unsafe_ptr)
1686ad4a5223SQuentin Monnet  * 	Description
1687ad4a5223SQuentin Monnet  * 		For tracing programs, safely attempt to read *size* bytes from
16886ae08ae3SDaniel Borkmann  * 		kernel space address *unsafe_ptr* and store the data in *dst*.
16896ae08ae3SDaniel Borkmann  *
1690ab8d7809SQuentin Monnet  * 		Generally, use **bpf_probe_read_user**\ () or
1691ab8d7809SQuentin Monnet  * 		**bpf_probe_read_kernel**\ () instead.
1692ad4a5223SQuentin Monnet  * 	Return
1693ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1694ad4a5223SQuentin Monnet  *
1695ad4a5223SQuentin Monnet  * u64 bpf_ktime_get_ns(void)
1696ad4a5223SQuentin Monnet  * 	Description
1697ad4a5223SQuentin Monnet  * 		Return the time elapsed since system boot, in nanoseconds.
169871d19214SMaciej Żenczykowski  * 		Does not include time the system was suspended.
1699ab8d7809SQuentin Monnet  * 		See: **clock_gettime**\ (**CLOCK_MONOTONIC**)
1700ad4a5223SQuentin Monnet  * 	Return
1701ad4a5223SQuentin Monnet  * 		Current *ktime*.
1702ad4a5223SQuentin Monnet  *
1703bdb7b79bSAndrii Nakryiko  * long bpf_trace_printk(const char *fmt, u32 fmt_size, ...)
1704ad4a5223SQuentin Monnet  * 	Description
1705ad4a5223SQuentin Monnet  * 		This helper is a "printk()-like" facility for debugging. It
1706ad4a5223SQuentin Monnet  * 		prints a message defined by format *fmt* (of size *fmt_size*)
170727d7fdf0SRoss Zwisler  * 		to file *\/sys/kernel/tracing/trace* from TraceFS, if
1708ad4a5223SQuentin Monnet  * 		available. It can take up to three additional **u64**
1709ad4a5223SQuentin Monnet  * 		arguments (as an eBPF helpers, the total number of arguments is
1710ad4a5223SQuentin Monnet  * 		limited to five).
1711ad4a5223SQuentin Monnet  *
1712ad4a5223SQuentin Monnet  * 		Each time the helper is called, it appends a line to the trace.
171327d7fdf0SRoss Zwisler  * 		Lines are discarded while *\/sys/kernel/tracing/trace* is
171427d7fdf0SRoss Zwisler  * 		open, use *\/sys/kernel/tracing/trace_pipe* to avoid this.
1715ad4a5223SQuentin Monnet  * 		The format of the trace is customizable, and the exact output
1716ad4a5223SQuentin Monnet  * 		one will get depends on the options set in
171727d7fdf0SRoss Zwisler  * 		*\/sys/kernel/tracing/trace_options* (see also the
1718ad4a5223SQuentin Monnet  * 		*README* file under the same directory). However, it usually
1719ad4a5223SQuentin Monnet  * 		defaults to something like:
1720ad4a5223SQuentin Monnet  *
1721ad4a5223SQuentin Monnet  * 		::
1722ad4a5223SQuentin Monnet  *
1723ad4a5223SQuentin Monnet  * 			telnet-470   [001] .N.. 419421.045894: 0x00000001: <formatted msg>
1724ad4a5223SQuentin Monnet  *
1725ad4a5223SQuentin Monnet  * 		In the above:
1726ad4a5223SQuentin Monnet  *
1727ad4a5223SQuentin Monnet  * 			* ``telnet`` is the name of the current task.
1728ad4a5223SQuentin Monnet  * 			* ``470`` is the PID of the current task.
1729ad4a5223SQuentin Monnet  * 			* ``001`` is the CPU number on which the task is
1730ad4a5223SQuentin Monnet  * 			  running.
1731ad4a5223SQuentin Monnet  * 			* In ``.N..``, each character refers to a set of
1732ad4a5223SQuentin Monnet  * 			  options (whether irqs are enabled, scheduling
1733ad4a5223SQuentin Monnet  * 			  options, whether hard/softirqs are running, level of
1734ad4a5223SQuentin Monnet  * 			  preempt_disabled respectively). **N** means that
1735ad4a5223SQuentin Monnet  * 			  **TIF_NEED_RESCHED** and **PREEMPT_NEED_RESCHED**
1736ad4a5223SQuentin Monnet  * 			  are set.
1737ad4a5223SQuentin Monnet  * 			* ``419421.045894`` is a timestamp.
1738ad4a5223SQuentin Monnet  * 			* ``0x00000001`` is a fake value used by BPF for the
1739ad4a5223SQuentin Monnet  * 			  instruction pointer register.
1740ad4a5223SQuentin Monnet  * 			* ``<formatted msg>`` is the message formatted with
1741ad4a5223SQuentin Monnet  * 			  *fmt*.
1742ad4a5223SQuentin Monnet  *
1743ad4a5223SQuentin Monnet  * 		The conversion specifiers supported by *fmt* are similar, but
1744ad4a5223SQuentin Monnet  * 		more limited than for printk(). They are **%d**, **%i**,
1745ad4a5223SQuentin Monnet  * 		**%u**, **%x**, **%ld**, **%li**, **%lu**, **%lx**, **%lld**,
1746ad4a5223SQuentin Monnet  * 		**%lli**, **%llu**, **%llx**, **%p**, **%s**. No modifier (size
1747ad4a5223SQuentin Monnet  * 		of field, padding with zeroes, etc.) is available, and the
1748ad4a5223SQuentin Monnet  * 		helper will return **-EINVAL** (but print nothing) if it
1749ad4a5223SQuentin Monnet  * 		encounters an unknown specifier.
1750ad4a5223SQuentin Monnet  *
1751ad4a5223SQuentin Monnet  * 		Also, note that **bpf_trace_printk**\ () is slow, and should
1752ad4a5223SQuentin Monnet  * 		only be used for debugging purposes. For this reason, a notice
1753b16fc097STobias Klauser  * 		block (spanning several lines) is printed to kernel logs and
1754ad4a5223SQuentin Monnet  * 		states that the helper should not be used "for production use"
1755ad4a5223SQuentin Monnet  * 		the first time this helper is used (or more precisely, when
1756ad4a5223SQuentin Monnet  * 		**trace_printk**\ () buffers are allocated). For passing values
1757ad4a5223SQuentin Monnet  * 		to user space, perf events should be preferred.
1758ad4a5223SQuentin Monnet  * 	Return
1759ad4a5223SQuentin Monnet  * 		The number of bytes written to the buffer, or a negative error
1760ad4a5223SQuentin Monnet  * 		in case of failure.
1761ad4a5223SQuentin Monnet  *
17621fdd08beSQuentin Monnet  * u32 bpf_get_prandom_u32(void)
17631fdd08beSQuentin Monnet  * 	Description
17641fdd08beSQuentin Monnet  * 		Get a pseudo-random number.
17651fdd08beSQuentin Monnet  *
17661fdd08beSQuentin Monnet  * 		From a security point of view, this helper uses its own
17671fdd08beSQuentin Monnet  * 		pseudo-random internal state, and cannot be used to infer the
17681fdd08beSQuentin Monnet  * 		seed of other random functions in the kernel. However, it is
17691fdd08beSQuentin Monnet  * 		essential to note that the generator used by the helper is not
17701fdd08beSQuentin Monnet  * 		cryptographically secure.
17711fdd08beSQuentin Monnet  * 	Return
17721fdd08beSQuentin Monnet  * 		A random 32-bit unsigned value.
17731fdd08beSQuentin Monnet  *
17741fdd08beSQuentin Monnet  * u32 bpf_get_smp_processor_id(void)
17751fdd08beSQuentin Monnet  * 	Description
17761fdd08beSQuentin Monnet  * 		Get the SMP (symmetric multiprocessing) processor id. Note that
177733656275SMatteo Croce  * 		all programs run with migration disabled, which means that the
17781fdd08beSQuentin Monnet  * 		SMP processor id is stable during all the execution of the
17791fdd08beSQuentin Monnet  * 		program.
17801fdd08beSQuentin Monnet  * 	Return
17811fdd08beSQuentin Monnet  * 		The SMP id of the processor running the program.
17821fdd08beSQuentin Monnet  *
1783bdb7b79bSAndrii Nakryiko  * long bpf_skb_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len, u64 flags)
1784ad4a5223SQuentin Monnet  * 	Description
1785ad4a5223SQuentin Monnet  * 		Store *len* bytes from address *from* into the packet
1786ad4a5223SQuentin Monnet  * 		associated to *skb*, at *offset*. *flags* are a combination of
1787ad4a5223SQuentin Monnet  * 		**BPF_F_RECOMPUTE_CSUM** (automatically recompute the
1788ad4a5223SQuentin Monnet  * 		checksum for the packet after storing the bytes) and
1789ad4a5223SQuentin Monnet  * 		**BPF_F_INVALIDATE_HASH** (set *skb*\ **->hash**, *skb*\
1790ad4a5223SQuentin Monnet  * 		**->swhash** and *skb*\ **->l4hash** to 0).
1791ad4a5223SQuentin Monnet  *
179232e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
1793ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1794ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1795ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
1796ad4a5223SQuentin Monnet  * 		direct packet access.
1797ad4a5223SQuentin Monnet  * 	Return
1798ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1799ad4a5223SQuentin Monnet  *
1800bdb7b79bSAndrii Nakryiko  * long bpf_l3_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 size)
1801ad4a5223SQuentin Monnet  * 	Description
1802ad4a5223SQuentin Monnet  * 		Recompute the layer 3 (e.g. IP) checksum for the packet
1803ad4a5223SQuentin Monnet  * 		associated to *skb*. Computation is incremental, so the helper
1804ad4a5223SQuentin Monnet  * 		must know the former value of the header field that was
1805ad4a5223SQuentin Monnet  * 		modified (*from*), the new value of this field (*to*), and the
1806ad4a5223SQuentin Monnet  * 		number of bytes (2 or 4) for this field, stored in *size*.
1807ad4a5223SQuentin Monnet  * 		Alternatively, it is possible to store the difference between
1808ad4a5223SQuentin Monnet  * 		the previous and the new values of the header field in *to*, by
1809ad4a5223SQuentin Monnet  * 		setting *from* and *size* to 0. For both methods, *offset*
1810ad4a5223SQuentin Monnet  * 		indicates the location of the IP checksum within the packet.
1811ad4a5223SQuentin Monnet  *
1812ad4a5223SQuentin Monnet  * 		This helper works in combination with **bpf_csum_diff**\ (),
1813ad4a5223SQuentin Monnet  * 		which does not update the checksum in-place, but offers more
1814ad4a5223SQuentin Monnet  * 		flexibility and can handle sizes larger than 2 or 4 for the
1815ad4a5223SQuentin Monnet  * 		checksum to update.
1816ad4a5223SQuentin Monnet  *
181732e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
1818ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1819ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1820ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
1821ad4a5223SQuentin Monnet  * 		direct packet access.
1822ad4a5223SQuentin Monnet  * 	Return
1823ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1824ad4a5223SQuentin Monnet  *
1825bdb7b79bSAndrii Nakryiko  * long bpf_l4_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 flags)
1826ad4a5223SQuentin Monnet  * 	Description
1827ad4a5223SQuentin Monnet  * 		Recompute the layer 4 (e.g. TCP, UDP or ICMP) checksum for the
1828ad4a5223SQuentin Monnet  * 		packet associated to *skb*. Computation is incremental, so the
1829ad4a5223SQuentin Monnet  * 		helper must know the former value of the header field that was
1830ad4a5223SQuentin Monnet  * 		modified (*from*), the new value of this field (*to*), and the
1831ad4a5223SQuentin Monnet  * 		number of bytes (2 or 4) for this field, stored on the lowest
1832ad4a5223SQuentin Monnet  * 		four bits of *flags*. Alternatively, it is possible to store
1833ad4a5223SQuentin Monnet  * 		the difference between the previous and the new values of the
1834ad4a5223SQuentin Monnet  * 		header field in *to*, by setting *from* and the four lowest
1835ad4a5223SQuentin Monnet  * 		bits of *flags* to 0. For both methods, *offset* indicates the
1836ad4a5223SQuentin Monnet  * 		location of the IP checksum within the packet. In addition to
1837ad4a5223SQuentin Monnet  * 		the size of the field, *flags* can be added (bitwise OR) actual
1838ad4a5223SQuentin Monnet  * 		flags. With **BPF_F_MARK_MANGLED_0**, a null checksum is left
1839ad4a5223SQuentin Monnet  * 		untouched (unless **BPF_F_MARK_ENFORCE** is added as well), and
1840ad4a5223SQuentin Monnet  * 		for updates resulting in a null checksum the value is set to
1841ad4a5223SQuentin Monnet  * 		**CSUM_MANGLED_0** instead. Flag **BPF_F_PSEUDO_HDR** indicates
1842ad4a5223SQuentin Monnet  * 		the checksum is to be computed against a pseudo-header.
1843ad4a5223SQuentin Monnet  *
1844ad4a5223SQuentin Monnet  * 		This helper works in combination with **bpf_csum_diff**\ (),
1845ad4a5223SQuentin Monnet  * 		which does not update the checksum in-place, but offers more
1846ad4a5223SQuentin Monnet  * 		flexibility and can handle sizes larger than 2 or 4 for the
1847ad4a5223SQuentin Monnet  * 		checksum to update.
1848ad4a5223SQuentin Monnet  *
184932e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
1850ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1851ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1852ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
1853ad4a5223SQuentin Monnet  * 		direct packet access.
1854ad4a5223SQuentin Monnet  * 	Return
1855ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1856ad4a5223SQuentin Monnet  *
1857bdb7b79bSAndrii Nakryiko  * long bpf_tail_call(void *ctx, struct bpf_map *prog_array_map, u32 index)
1858ad4a5223SQuentin Monnet  * 	Description
1859ad4a5223SQuentin Monnet  * 		This special helper is used to trigger a "tail call", or in
1860ad4a5223SQuentin Monnet  * 		other words, to jump into another eBPF program. The same stack
1861ad4a5223SQuentin Monnet  * 		frame is used (but values on stack and in registers for the
1862ad4a5223SQuentin Monnet  * 		caller are not accessible to the callee). This mechanism allows
1863ad4a5223SQuentin Monnet  * 		for program chaining, either for raising the maximum number of
1864ad4a5223SQuentin Monnet  * 		available eBPF instructions, or to execute given programs in
1865ad4a5223SQuentin Monnet  * 		conditional blocks. For security reasons, there is an upper
1866ad4a5223SQuentin Monnet  * 		limit to the number of successive tail calls that can be
1867ad4a5223SQuentin Monnet  * 		performed.
1868ad4a5223SQuentin Monnet  *
1869ad4a5223SQuentin Monnet  * 		Upon call of this helper, the program attempts to jump into a
1870ad4a5223SQuentin Monnet  * 		program referenced at index *index* in *prog_array_map*, a
1871ad4a5223SQuentin Monnet  * 		special map of type **BPF_MAP_TYPE_PROG_ARRAY**, and passes
1872ad4a5223SQuentin Monnet  * 		*ctx*, a pointer to the context.
1873ad4a5223SQuentin Monnet  *
1874ad4a5223SQuentin Monnet  * 		If the call succeeds, the kernel immediately runs the first
1875ad4a5223SQuentin Monnet  * 		instruction of the new program. This is not a function call,
1876ad4a5223SQuentin Monnet  * 		and it never returns to the previous program. If the call
1877ad4a5223SQuentin Monnet  * 		fails, then the helper has no effect, and the caller continues
1878ad4a5223SQuentin Monnet  * 		to run its subsequent instructions. A call can fail if the
1879ad4a5223SQuentin Monnet  * 		destination program for the jump does not exist (i.e. *index*
1880ad4a5223SQuentin Monnet  * 		is superior to the number of entries in *prog_array_map*), or
1881ad4a5223SQuentin Monnet  * 		if the maximum number of tail calls has been reached for this
1882ad4a5223SQuentin Monnet  * 		chain of programs. This limit is defined in the kernel by the
1883ad4a5223SQuentin Monnet  * 		macro **MAX_TAIL_CALL_CNT** (not accessible to user space),
1884ebf7f6f0STiezhu Yang  *		which is currently set to 33.
1885ad4a5223SQuentin Monnet  * 	Return
1886ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1887ad4a5223SQuentin Monnet  *
1888bdb7b79bSAndrii Nakryiko  * long bpf_clone_redirect(struct sk_buff *skb, u32 ifindex, u64 flags)
1889ad4a5223SQuentin Monnet  * 	Description
1890ad4a5223SQuentin Monnet  * 		Clone and redirect the packet associated to *skb* to another
1891ad4a5223SQuentin Monnet  * 		net device of index *ifindex*. Both ingress and egress
1892ad4a5223SQuentin Monnet  * 		interfaces can be used for redirection. The **BPF_F_INGRESS**
1893ad4a5223SQuentin Monnet  * 		value in *flags* is used to make the distinction (ingress path
1894ad4a5223SQuentin Monnet  * 		is selected if the flag is present, egress path otherwise).
1895ad4a5223SQuentin Monnet  * 		This is the only flag supported for now.
1896ad4a5223SQuentin Monnet  *
1897ad4a5223SQuentin Monnet  * 		In comparison with **bpf_redirect**\ () helper,
1898ad4a5223SQuentin Monnet  * 		**bpf_clone_redirect**\ () has the associated cost of
1899ad4a5223SQuentin Monnet  * 		duplicating the packet buffer, but this can be executed out of
1900ad4a5223SQuentin Monnet  * 		the eBPF program. Conversely, **bpf_redirect**\ () is more
1901ad4a5223SQuentin Monnet  * 		efficient, but it is handled through an action code where the
1902ad4a5223SQuentin Monnet  * 		redirection happens only after the eBPF program has returned.
1903ad4a5223SQuentin Monnet  *
190432e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
1905ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1906ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1907ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
1908ad4a5223SQuentin Monnet  * 		direct packet access.
1909ad4a5223SQuentin Monnet  * 	Return
1910ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1911c456dec4SQuentin Monnet  *
1912c456dec4SQuentin Monnet  * u64 bpf_get_current_pid_tgid(void)
1913e40fbbf0SUsama Arif  * 	Description
1914e40fbbf0SUsama Arif  * 		Get the current pid and tgid.
1915c456dec4SQuentin Monnet  * 	Return
1916c456dec4SQuentin Monnet  * 		A 64-bit integer containing the current tgid and pid, and
1917c456dec4SQuentin Monnet  * 		created as such:
1918c456dec4SQuentin Monnet  * 		*current_task*\ **->tgid << 32 \|**
1919c456dec4SQuentin Monnet  * 		*current_task*\ **->pid**.
1920c456dec4SQuentin Monnet  *
1921c456dec4SQuentin Monnet  * u64 bpf_get_current_uid_gid(void)
1922e40fbbf0SUsama Arif  * 	Description
1923e40fbbf0SUsama Arif  * 		Get the current uid and gid.
1924c456dec4SQuentin Monnet  * 	Return
1925c456dec4SQuentin Monnet  * 		A 64-bit integer containing the current GID and UID, and
1926c456dec4SQuentin Monnet  * 		created as such: *current_gid* **<< 32 \|** *current_uid*.
1927c456dec4SQuentin Monnet  *
1928bdb7b79bSAndrii Nakryiko  * long bpf_get_current_comm(void *buf, u32 size_of_buf)
1929c456dec4SQuentin Monnet  * 	Description
1930c456dec4SQuentin Monnet  * 		Copy the **comm** attribute of the current task into *buf* of
1931c456dec4SQuentin Monnet  * 		*size_of_buf*. The **comm** attribute contains the name of
1932c456dec4SQuentin Monnet  * 		the executable (excluding the path) for the current task. The
1933c456dec4SQuentin Monnet  * 		*size_of_buf* must be strictly positive. On success, the
1934c456dec4SQuentin Monnet  * 		helper makes sure that the *buf* is NUL-terminated. On failure,
1935c456dec4SQuentin Monnet  * 		it is filled with zeroes.
1936c456dec4SQuentin Monnet  * 	Return
1937c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1938c456dec4SQuentin Monnet  *
19391fdd08beSQuentin Monnet  * u32 bpf_get_cgroup_classid(struct sk_buff *skb)
19401fdd08beSQuentin Monnet  * 	Description
19411fdd08beSQuentin Monnet  * 		Retrieve the classid for the current task, i.e. for the net_cls
19421fdd08beSQuentin Monnet  * 		cgroup to which *skb* belongs.
19431fdd08beSQuentin Monnet  *
19441fdd08beSQuentin Monnet  * 		This helper can be used on TC egress path, but not on ingress.
19451fdd08beSQuentin Monnet  *
19461fdd08beSQuentin Monnet  * 		The net_cls cgroup provides an interface to tag network packets
19471fdd08beSQuentin Monnet  * 		based on a user-provided identifier for all traffic coming from
19481fdd08beSQuentin Monnet  * 		the tasks belonging to the related cgroup. See also the related
19491fdd08beSQuentin Monnet  * 		kernel documentation, available from the Linux sources in file
1950da82c92fSMauro Carvalho Chehab  * 		*Documentation/admin-guide/cgroup-v1/net_cls.rst*.
19511fdd08beSQuentin Monnet  *
19521fdd08beSQuentin Monnet  * 		The Linux kernel has two versions for cgroups: there are
19531fdd08beSQuentin Monnet  * 		cgroups v1 and cgroups v2. Both are available to users, who can
19541fdd08beSQuentin Monnet  * 		use a mixture of them, but note that the net_cls cgroup is for
19551fdd08beSQuentin Monnet  * 		cgroup v1 only. This makes it incompatible with BPF programs
19561fdd08beSQuentin Monnet  * 		run on cgroups, which is a cgroup-v2-only feature (a socket can
19571fdd08beSQuentin Monnet  * 		only hold data for one version of cgroups at a time).
19581fdd08beSQuentin Monnet  *
19591fdd08beSQuentin Monnet  * 		This helper is only available is the kernel was compiled with
19601fdd08beSQuentin Monnet  * 		the **CONFIG_CGROUP_NET_CLASSID** configuration option set to
19611fdd08beSQuentin Monnet  * 		"**y**" or to "**m**".
19621fdd08beSQuentin Monnet  * 	Return
19631fdd08beSQuentin Monnet  * 		The classid, or 0 for the default unconfigured classid.
19641fdd08beSQuentin Monnet  *
1965bdb7b79bSAndrii Nakryiko  * long bpf_skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)
1966c456dec4SQuentin Monnet  * 	Description
1967c456dec4SQuentin Monnet  * 		Push a *vlan_tci* (VLAN tag control information) of protocol
1968c456dec4SQuentin Monnet  * 		*vlan_proto* to the packet associated to *skb*, then update
1969c456dec4SQuentin Monnet  * 		the checksum. Note that if *vlan_proto* is different from
1970c456dec4SQuentin Monnet  * 		**ETH_P_8021Q** and **ETH_P_8021AD**, it is considered to
1971c456dec4SQuentin Monnet  * 		be **ETH_P_8021Q**.
1972c456dec4SQuentin Monnet  *
197332e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
1974c456dec4SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1975c456dec4SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1976c456dec4SQuentin Monnet  * 		performed again, if the helper is used in combination with
1977c456dec4SQuentin Monnet  * 		direct packet access.
1978c456dec4SQuentin Monnet  * 	Return
1979c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1980c456dec4SQuentin Monnet  *
1981bdb7b79bSAndrii Nakryiko  * long bpf_skb_vlan_pop(struct sk_buff *skb)
1982c456dec4SQuentin Monnet  * 	Description
1983c456dec4SQuentin Monnet  * 		Pop a VLAN header from the packet associated to *skb*.
1984c456dec4SQuentin Monnet  *
198532e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
1986c456dec4SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1987c456dec4SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1988c456dec4SQuentin Monnet  * 		performed again, if the helper is used in combination with
1989c456dec4SQuentin Monnet  * 		direct packet access.
1990c456dec4SQuentin Monnet  * 	Return
1991c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1992c456dec4SQuentin Monnet  *
1993bdb7b79bSAndrii Nakryiko  * long bpf_skb_get_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
1994c456dec4SQuentin Monnet  * 	Description
1995c456dec4SQuentin Monnet  * 		Get tunnel metadata. This helper takes a pointer *key* to an
1996c456dec4SQuentin Monnet  * 		empty **struct bpf_tunnel_key** of **size**, that will be
1997c456dec4SQuentin Monnet  * 		filled with tunnel metadata for the packet associated to *skb*.
1998c456dec4SQuentin Monnet  * 		The *flags* can be set to **BPF_F_TUNINFO_IPV6**, which
1999c456dec4SQuentin Monnet  * 		indicates that the tunnel is based on IPv6 protocol instead of
2000c456dec4SQuentin Monnet  * 		IPv4.
2001c456dec4SQuentin Monnet  *
2002c456dec4SQuentin Monnet  * 		The **struct bpf_tunnel_key** is an object that generalizes the
2003c456dec4SQuentin Monnet  * 		principal parameters used by various tunneling protocols into a
2004c456dec4SQuentin Monnet  * 		single struct. This way, it can be used to easily make a
2005c456dec4SQuentin Monnet  * 		decision based on the contents of the encapsulation header,
2006c456dec4SQuentin Monnet  * 		"summarized" in this struct. In particular, it holds the IP
2007c456dec4SQuentin Monnet  * 		address of the remote end (IPv4 or IPv6, depending on the case)
2008c456dec4SQuentin Monnet  * 		in *key*\ **->remote_ipv4** or *key*\ **->remote_ipv6**. Also,
2009c456dec4SQuentin Monnet  * 		this struct exposes the *key*\ **->tunnel_id**, which is
2010c456dec4SQuentin Monnet  * 		generally mapped to a VNI (Virtual Network Identifier), making
2011c456dec4SQuentin Monnet  * 		it programmable together with the **bpf_skb_set_tunnel_key**\
2012c456dec4SQuentin Monnet  * 		() helper.
2013c456dec4SQuentin Monnet  *
2014c456dec4SQuentin Monnet  * 		Let's imagine that the following code is part of a program
2015c456dec4SQuentin Monnet  * 		attached to the TC ingress interface, on one end of a GRE
2016c456dec4SQuentin Monnet  * 		tunnel, and is supposed to filter out all messages coming from
2017c456dec4SQuentin Monnet  * 		remote ends with IPv4 address other than 10.0.0.1:
2018c456dec4SQuentin Monnet  *
2019c456dec4SQuentin Monnet  * 		::
2020c456dec4SQuentin Monnet  *
2021c456dec4SQuentin Monnet  * 			int ret;
2022c456dec4SQuentin Monnet  * 			struct bpf_tunnel_key key = {};
2023c456dec4SQuentin Monnet  *
2024c456dec4SQuentin Monnet  * 			ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
2025c456dec4SQuentin Monnet  * 			if (ret < 0)
2026c456dec4SQuentin Monnet  * 				return TC_ACT_SHOT;	// drop packet
2027c456dec4SQuentin Monnet  *
2028c456dec4SQuentin Monnet  * 			if (key.remote_ipv4 != 0x0a000001)
2029c456dec4SQuentin Monnet  * 				return TC_ACT_SHOT;	// drop packet
2030c456dec4SQuentin Monnet  *
2031c456dec4SQuentin Monnet  * 			return TC_ACT_OK;		// accept packet
2032c456dec4SQuentin Monnet  *
2033c456dec4SQuentin Monnet  * 		This interface can also be used with all encapsulation devices
2034c456dec4SQuentin Monnet  * 		that can operate in "collect metadata" mode: instead of having
2035c456dec4SQuentin Monnet  * 		one network device per specific configuration, the "collect
2036c456dec4SQuentin Monnet  * 		metadata" mode only requires a single device where the
2037c456dec4SQuentin Monnet  * 		configuration can be extracted from this helper.
2038c456dec4SQuentin Monnet  *
2039c456dec4SQuentin Monnet  * 		This can be used together with various tunnels such as VXLan,
2040c456dec4SQuentin Monnet  * 		Geneve, GRE or IP in IP (IPIP).
2041c456dec4SQuentin Monnet  * 	Return
2042c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2043c456dec4SQuentin Monnet  *
2044bdb7b79bSAndrii Nakryiko  * long bpf_skb_set_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
2045c456dec4SQuentin Monnet  * 	Description
2046c456dec4SQuentin Monnet  * 		Populate tunnel metadata for packet associated to *skb.* The
2047c456dec4SQuentin Monnet  * 		tunnel metadata is set to the contents of *key*, of *size*. The
2048c456dec4SQuentin Monnet  * 		*flags* can be set to a combination of the following values:
2049c456dec4SQuentin Monnet  *
2050c456dec4SQuentin Monnet  * 		**BPF_F_TUNINFO_IPV6**
2051c456dec4SQuentin Monnet  * 			Indicate that the tunnel is based on IPv6 protocol
2052c456dec4SQuentin Monnet  * 			instead of IPv4.
2053c456dec4SQuentin Monnet  * 		**BPF_F_ZERO_CSUM_TX**
2054c456dec4SQuentin Monnet  * 			For IPv4 packets, add a flag to tunnel metadata
2055c456dec4SQuentin Monnet  * 			indicating that checksum computation should be skipped
2056c456dec4SQuentin Monnet  * 			and checksum set to zeroes.
2057c456dec4SQuentin Monnet  * 		**BPF_F_DONT_FRAGMENT**
2058c456dec4SQuentin Monnet  * 			Add a flag to tunnel metadata indicating that the
2059c456dec4SQuentin Monnet  * 			packet should not be fragmented.
2060c456dec4SQuentin Monnet  * 		**BPF_F_SEQ_NUMBER**
2061c456dec4SQuentin Monnet  * 			Add a flag to tunnel metadata indicating that a
2062c456dec4SQuentin Monnet  * 			sequence number should be added to tunnel header before
2063c456dec4SQuentin Monnet  * 			sending the packet. This flag was added for GRE
2064c456dec4SQuentin Monnet  * 			encapsulation, but might be used with other protocols
2065c456dec4SQuentin Monnet  * 			as well in the future.
2066e26aa600SChristian Ehrig  * 		**BPF_F_NO_TUNNEL_KEY**
2067e26aa600SChristian Ehrig  * 			Add a flag to tunnel metadata indicating that no tunnel
2068e26aa600SChristian Ehrig  * 			key should be set in the resulting tunnel header.
2069c456dec4SQuentin Monnet  *
2070c456dec4SQuentin Monnet  * 		Here is a typical usage on the transmit path:
2071c456dec4SQuentin Monnet  *
2072c456dec4SQuentin Monnet  * 		::
2073c456dec4SQuentin Monnet  *
2074c456dec4SQuentin Monnet  * 			struct bpf_tunnel_key key;
2075c456dec4SQuentin Monnet  * 			     populate key ...
2076c456dec4SQuentin Monnet  * 			bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0);
2077c456dec4SQuentin Monnet  * 			bpf_clone_redirect(skb, vxlan_dev_ifindex, 0);
2078c456dec4SQuentin Monnet  *
2079c456dec4SQuentin Monnet  * 		See also the description of the **bpf_skb_get_tunnel_key**\ ()
2080c456dec4SQuentin Monnet  * 		helper for additional information.
2081c456dec4SQuentin Monnet  * 	Return
2082c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2083c456dec4SQuentin Monnet  *
2084c6b5fb86SQuentin Monnet  * u64 bpf_perf_event_read(struct bpf_map *map, u64 flags)
2085c6b5fb86SQuentin Monnet  * 	Description
2086c6b5fb86SQuentin Monnet  * 		Read the value of a perf event counter. This helper relies on a
2087c6b5fb86SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of
2088c6b5fb86SQuentin Monnet  * 		the perf event counter is selected when *map* is updated with
2089c6b5fb86SQuentin Monnet  * 		perf event file descriptors. The *map* is an array whose size
2090c6b5fb86SQuentin Monnet  * 		is the number of available CPUs, and each cell contains a value
2091c6b5fb86SQuentin Monnet  * 		relative to one CPU. The value to retrieve is indicated by
2092c6b5fb86SQuentin Monnet  * 		*flags*, that contains the index of the CPU to look up, masked
2093c6b5fb86SQuentin Monnet  * 		with **BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
2094c6b5fb86SQuentin Monnet  * 		**BPF_F_CURRENT_CPU** to indicate that the value for the
2095c6b5fb86SQuentin Monnet  * 		current CPU should be retrieved.
2096c6b5fb86SQuentin Monnet  *
2097c6b5fb86SQuentin Monnet  * 		Note that before Linux 4.13, only hardware perf event can be
2098c6b5fb86SQuentin Monnet  * 		retrieved.
2099c6b5fb86SQuentin Monnet  *
2100c6b5fb86SQuentin Monnet  * 		Also, be aware that the newer helper
2101c6b5fb86SQuentin Monnet  * 		**bpf_perf_event_read_value**\ () is recommended over
21023bd5a09bSQuentin Monnet  * 		**bpf_perf_event_read**\ () in general. The latter has some ABI
2103c6b5fb86SQuentin Monnet  * 		quirks where error and counter value are used as a return code
2104c6b5fb86SQuentin Monnet  * 		(which is wrong to do since ranges may overlap). This issue is
21053bd5a09bSQuentin Monnet  * 		fixed with **bpf_perf_event_read_value**\ (), which at the same
21063bd5a09bSQuentin Monnet  * 		time provides more features over the **bpf_perf_event_read**\
21073bd5a09bSQuentin Monnet  * 		() interface. Please refer to the description of
2108c6b5fb86SQuentin Monnet  * 		**bpf_perf_event_read_value**\ () for details.
2109c6b5fb86SQuentin Monnet  * 	Return
2110c6b5fb86SQuentin Monnet  * 		The value of the perf event counter read from the map, or a
2111c6b5fb86SQuentin Monnet  * 		negative error code in case of failure.
2112c6b5fb86SQuentin Monnet  *
2113bdb7b79bSAndrii Nakryiko  * long bpf_redirect(u32 ifindex, u64 flags)
2114c456dec4SQuentin Monnet  * 	Description
2115c456dec4SQuentin Monnet  * 		Redirect the packet to another net device of index *ifindex*.
2116c456dec4SQuentin Monnet  * 		This helper is somewhat similar to **bpf_clone_redirect**\
2117c456dec4SQuentin Monnet  * 		(), except that the packet is not cloned, which provides
2118c456dec4SQuentin Monnet  * 		increased performance.
2119c456dec4SQuentin Monnet  *
2120c456dec4SQuentin Monnet  * 		Except for XDP, both ingress and egress interfaces can be used
2121c456dec4SQuentin Monnet  * 		for redirection. The **BPF_F_INGRESS** value in *flags* is used
2122c456dec4SQuentin Monnet  * 		to make the distinction (ingress path is selected if the flag
2123c456dec4SQuentin Monnet  * 		is present, egress path otherwise). Currently, XDP only
2124c456dec4SQuentin Monnet  * 		supports redirection to the egress interface, and accepts no
2125c456dec4SQuentin Monnet  * 		flag at all.
2126c456dec4SQuentin Monnet  *
2127f25975f4SToke Høiland-Jørgensen  * 		The same effect can also be attained with the more generic
2128f25975f4SToke Høiland-Jørgensen  * 		**bpf_redirect_map**\ (), which uses a BPF map to store the
2129f25975f4SToke Høiland-Jørgensen  * 		redirect target instead of providing it directly to the helper.
2130c456dec4SQuentin Monnet  * 	Return
2131c456dec4SQuentin Monnet  * 		For XDP, the helper returns **XDP_REDIRECT** on success or
2132c456dec4SQuentin Monnet  * 		**XDP_ABORTED** on error. For other program types, the values
2133c456dec4SQuentin Monnet  * 		are **TC_ACT_REDIRECT** on success or **TC_ACT_SHOT** on
2134c456dec4SQuentin Monnet  * 		error.
2135c456dec4SQuentin Monnet  *
21361fdd08beSQuentin Monnet  * u32 bpf_get_route_realm(struct sk_buff *skb)
21371fdd08beSQuentin Monnet  * 	Description
21381fdd08beSQuentin Monnet  * 		Retrieve the realm or the route, that is to say the
21391fdd08beSQuentin Monnet  * 		**tclassid** field of the destination for the *skb*. The
2140b16fc097STobias Klauser  * 		identifier retrieved is a user-provided tag, similar to the
21411fdd08beSQuentin Monnet  * 		one used with the net_cls cgroup (see description for
21421fdd08beSQuentin Monnet  * 		**bpf_get_cgroup_classid**\ () helper), but here this tag is
21431fdd08beSQuentin Monnet  * 		held by a route (a destination entry), not by a task.
21441fdd08beSQuentin Monnet  *
21451fdd08beSQuentin Monnet  * 		Retrieving this identifier works with the clsact TC egress hook
21461fdd08beSQuentin Monnet  * 		(see also **tc-bpf(8)**), or alternatively on conventional
21471fdd08beSQuentin Monnet  * 		classful egress qdiscs, but not on TC ingress path. In case of
21481fdd08beSQuentin Monnet  * 		clsact TC egress hook, this has the advantage that, internally,
21491fdd08beSQuentin Monnet  * 		the destination entry has not been dropped yet in the transmit
21501fdd08beSQuentin Monnet  * 		path. Therefore, the destination entry does not need to be
21511fdd08beSQuentin Monnet  * 		artificially held via **netif_keep_dst**\ () for a classful
21521fdd08beSQuentin Monnet  * 		qdisc until the *skb* is freed.
21531fdd08beSQuentin Monnet  *
21541fdd08beSQuentin Monnet  * 		This helper is available only if the kernel was compiled with
21551fdd08beSQuentin Monnet  * 		**CONFIG_IP_ROUTE_CLASSID** configuration option.
21561fdd08beSQuentin Monnet  * 	Return
21571fdd08beSQuentin Monnet  * 		The realm of the route for the packet associated to *skb*, or 0
21581fdd08beSQuentin Monnet  * 		if none was found.
21591fdd08beSQuentin Monnet  *
2160bdb7b79bSAndrii Nakryiko  * long bpf_perf_event_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
2161c456dec4SQuentin Monnet  * 	Description
2162c456dec4SQuentin Monnet  * 		Write raw *data* blob into a special BPF perf event held by
2163c456dec4SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
2164c456dec4SQuentin Monnet  * 		event must have the following attributes: **PERF_SAMPLE_RAW**
2165c456dec4SQuentin Monnet  * 		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
2166c456dec4SQuentin Monnet  * 		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
2167c456dec4SQuentin Monnet  *
2168c456dec4SQuentin Monnet  * 		The *flags* are used to indicate the index in *map* for which
2169c456dec4SQuentin Monnet  * 		the value must be put, masked with **BPF_F_INDEX_MASK**.
2170c456dec4SQuentin Monnet  * 		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
2171c456dec4SQuentin Monnet  * 		to indicate that the index of the current CPU core should be
2172c456dec4SQuentin Monnet  * 		used.
2173c456dec4SQuentin Monnet  *
2174c456dec4SQuentin Monnet  * 		The value to write, of *size*, is passed through eBPF stack and
2175c456dec4SQuentin Monnet  * 		pointed by *data*.
2176c456dec4SQuentin Monnet  *
2177c456dec4SQuentin Monnet  * 		The context of the program *ctx* needs also be passed to the
2178c456dec4SQuentin Monnet  * 		helper.
2179c456dec4SQuentin Monnet  *
2180c456dec4SQuentin Monnet  * 		On user space, a program willing to read the values needs to
2181c456dec4SQuentin Monnet  * 		call **perf_event_open**\ () on the perf event (either for
2182c456dec4SQuentin Monnet  * 		one or for all CPUs) and to store the file descriptor into the
2183c456dec4SQuentin Monnet  * 		*map*. This must be done before the eBPF program can send data
2184c456dec4SQuentin Monnet  * 		into it. An example is available in file
2185c456dec4SQuentin Monnet  * 		*samples/bpf/trace_output_user.c* in the Linux kernel source
2186c456dec4SQuentin Monnet  * 		tree (the eBPF program counterpart is in
2187c456dec4SQuentin Monnet  * 		*samples/bpf/trace_output_kern.c*).
2188c456dec4SQuentin Monnet  *
2189c456dec4SQuentin Monnet  * 		**bpf_perf_event_output**\ () achieves better performance
2190c456dec4SQuentin Monnet  * 		than **bpf_trace_printk**\ () for sharing data with user
2191c456dec4SQuentin Monnet  * 		space, and is much better suitable for streaming data from eBPF
2192c456dec4SQuentin Monnet  * 		programs.
2193c456dec4SQuentin Monnet  *
2194c456dec4SQuentin Monnet  * 		Note that this helper is not restricted to tracing use cases
2195c456dec4SQuentin Monnet  * 		and can be used with programs attached to TC or XDP as well,
2196c456dec4SQuentin Monnet  * 		where it allows for passing data to user space listeners. Data
2197c456dec4SQuentin Monnet  * 		can be:
2198c456dec4SQuentin Monnet  *
2199c456dec4SQuentin Monnet  * 		* Only custom structs,
2200c456dec4SQuentin Monnet  * 		* Only the packet payload, or
2201c456dec4SQuentin Monnet  * 		* A combination of both.
2202c456dec4SQuentin Monnet  * 	Return
2203c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2204c456dec4SQuentin Monnet  *
2205bdb7b79bSAndrii Nakryiko  * long bpf_skb_load_bytes(const void *skb, u32 offset, void *to, u32 len)
22061fdd08beSQuentin Monnet  * 	Description
22071fdd08beSQuentin Monnet  * 		This helper was provided as an easy way to load data from a
22081fdd08beSQuentin Monnet  * 		packet. It can be used to load *len* bytes from *offset* from
22091fdd08beSQuentin Monnet  * 		the packet associated to *skb*, into the buffer pointed by
22101fdd08beSQuentin Monnet  * 		*to*.
22111fdd08beSQuentin Monnet  *
22121fdd08beSQuentin Monnet  * 		Since Linux 4.7, usage of this helper has mostly been replaced
22131fdd08beSQuentin Monnet  * 		by "direct packet access", enabling packet data to be
22141fdd08beSQuentin Monnet  * 		manipulated with *skb*\ **->data** and *skb*\ **->data_end**
22151fdd08beSQuentin Monnet  * 		pointing respectively to the first byte of packet data and to
22161fdd08beSQuentin Monnet  * 		the byte after the last byte of packet data. However, it
22171fdd08beSQuentin Monnet  * 		remains useful if one wishes to read large quantities of data
22181fdd08beSQuentin Monnet  * 		at once from a packet into the eBPF stack.
22191fdd08beSQuentin Monnet  * 	Return
22201fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
22211fdd08beSQuentin Monnet  *
2222bdb7b79bSAndrii Nakryiko  * long bpf_get_stackid(void *ctx, struct bpf_map *map, u64 flags)
2223c456dec4SQuentin Monnet  * 	Description
2224c456dec4SQuentin Monnet  * 		Walk a user or a kernel stack and return its id. To achieve
2225c456dec4SQuentin Monnet  * 		this, the helper needs *ctx*, which is a pointer to the context
2226c456dec4SQuentin Monnet  * 		on which the tracing program is executed, and a pointer to a
2227c456dec4SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_STACK_TRACE**.
2228c456dec4SQuentin Monnet  *
2229c456dec4SQuentin Monnet  * 		The last argument, *flags*, holds the number of stack frames to
2230c456dec4SQuentin Monnet  * 		skip (from 0 to 255), masked with
2231c456dec4SQuentin Monnet  * 		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
2232c456dec4SQuentin Monnet  * 		a combination of the following flags:
2233c456dec4SQuentin Monnet  *
2234c456dec4SQuentin Monnet  * 		**BPF_F_USER_STACK**
2235c456dec4SQuentin Monnet  * 			Collect a user space stack instead of a kernel stack.
2236c456dec4SQuentin Monnet  * 		**BPF_F_FAST_STACK_CMP**
2237c456dec4SQuentin Monnet  * 			Compare stacks by hash only.
2238c456dec4SQuentin Monnet  * 		**BPF_F_REUSE_STACKID**
2239c456dec4SQuentin Monnet  * 			If two different stacks hash into the same *stackid*,
2240c456dec4SQuentin Monnet  * 			discard the old one.
2241c456dec4SQuentin Monnet  *
2242c456dec4SQuentin Monnet  * 		The stack id retrieved is a 32 bit long integer handle which
2243c456dec4SQuentin Monnet  * 		can be further combined with other data (including other stack
2244c456dec4SQuentin Monnet  * 		ids) and used as a key into maps. This can be useful for
2245c456dec4SQuentin Monnet  * 		generating a variety of graphs (such as flame graphs or off-cpu
2246c456dec4SQuentin Monnet  * 		graphs).
2247c456dec4SQuentin Monnet  *
2248c456dec4SQuentin Monnet  * 		For walking a stack, this helper is an improvement over
2249c456dec4SQuentin Monnet  * 		**bpf_probe_read**\ (), which can be used with unrolled loops
2250c456dec4SQuentin Monnet  * 		but is not efficient and consumes a lot of eBPF instructions.
2251c456dec4SQuentin Monnet  * 		Instead, **bpf_get_stackid**\ () can collect up to
2252c456dec4SQuentin Monnet  * 		**PERF_MAX_STACK_DEPTH** both kernel and user frames. Note that
2253c456dec4SQuentin Monnet  * 		this limit can be controlled with the **sysctl** program, and
2254c456dec4SQuentin Monnet  * 		that it should be manually increased in order to profile long
2255c456dec4SQuentin Monnet  * 		user stacks (such as stacks for Java programs). To do so, use:
2256c456dec4SQuentin Monnet  *
2257c456dec4SQuentin Monnet  * 		::
2258c456dec4SQuentin Monnet  *
2259c456dec4SQuentin Monnet  * 			# sysctl kernel.perf_event_max_stack=<new value>
2260c456dec4SQuentin Monnet  * 	Return
2261c456dec4SQuentin Monnet  * 		The positive or null stack id on success, or a negative error
2262c456dec4SQuentin Monnet  * 		in case of failure.
2263c456dec4SQuentin Monnet  *
22641fdd08beSQuentin Monnet  * s64 bpf_csum_diff(__be32 *from, u32 from_size, __be32 *to, u32 to_size, __wsum seed)
22651fdd08beSQuentin Monnet  * 	Description
22661fdd08beSQuentin Monnet  * 		Compute a checksum difference, from the raw buffer pointed by
22671fdd08beSQuentin Monnet  * 		*from*, of length *from_size* (that must be a multiple of 4),
22681fdd08beSQuentin Monnet  * 		towards the raw buffer pointed by *to*, of size *to_size*
22691fdd08beSQuentin Monnet  * 		(same remark). An optional *seed* can be added to the value
22701fdd08beSQuentin Monnet  * 		(this can be cascaded, the seed may come from a previous call
22711fdd08beSQuentin Monnet  * 		to the helper).
22721fdd08beSQuentin Monnet  *
22731fdd08beSQuentin Monnet  * 		This is flexible enough to be used in several ways:
22741fdd08beSQuentin Monnet  *
22751fdd08beSQuentin Monnet  * 		* With *from_size* == 0, *to_size* > 0 and *seed* set to
22761fdd08beSQuentin Monnet  * 		  checksum, it can be used when pushing new data.
22771fdd08beSQuentin Monnet  * 		* With *from_size* > 0, *to_size* == 0 and *seed* set to
22781fdd08beSQuentin Monnet  * 		  checksum, it can be used when removing data from a packet.
22791fdd08beSQuentin Monnet  * 		* With *from_size* > 0, *to_size* > 0 and *seed* set to 0, it
22801fdd08beSQuentin Monnet  * 		  can be used to compute a diff. Note that *from_size* and
22811fdd08beSQuentin Monnet  * 		  *to_size* do not need to be equal.
22821fdd08beSQuentin Monnet  *
22831fdd08beSQuentin Monnet  * 		This helper can be used in combination with
22841fdd08beSQuentin Monnet  * 		**bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\ (), to
22851fdd08beSQuentin Monnet  * 		which one can feed in the difference computed with
22861fdd08beSQuentin Monnet  * 		**bpf_csum_diff**\ ().
22871fdd08beSQuentin Monnet  * 	Return
22881fdd08beSQuentin Monnet  * 		The checksum result, or a negative error code in case of
22891fdd08beSQuentin Monnet  * 		failure.
22901fdd08beSQuentin Monnet  *
2291bdb7b79bSAndrii Nakryiko  * long bpf_skb_get_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)
22921fdd08beSQuentin Monnet  * 	Description
22931fdd08beSQuentin Monnet  * 		Retrieve tunnel options metadata for the packet associated to
22941fdd08beSQuentin Monnet  * 		*skb*, and store the raw tunnel option data to the buffer *opt*
22951fdd08beSQuentin Monnet  * 		of *size*.
22961fdd08beSQuentin Monnet  *
22971fdd08beSQuentin Monnet  * 		This helper can be used with encapsulation devices that can
22981fdd08beSQuentin Monnet  * 		operate in "collect metadata" mode (please refer to the related
22991fdd08beSQuentin Monnet  * 		note in the description of **bpf_skb_get_tunnel_key**\ () for
23001fdd08beSQuentin Monnet  * 		more details). A particular example where this can be used is
23011fdd08beSQuentin Monnet  * 		in combination with the Geneve encapsulation protocol, where it
23021fdd08beSQuentin Monnet  * 		allows for pushing (with **bpf_skb_get_tunnel_opt**\ () helper)
23031fdd08beSQuentin Monnet  * 		and retrieving arbitrary TLVs (Type-Length-Value headers) from
23041fdd08beSQuentin Monnet  * 		the eBPF program. This allows for full customization of these
23051fdd08beSQuentin Monnet  * 		headers.
23061fdd08beSQuentin Monnet  * 	Return
23071fdd08beSQuentin Monnet  * 		The size of the option data retrieved.
23081fdd08beSQuentin Monnet  *
2309bdb7b79bSAndrii Nakryiko  * long bpf_skb_set_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)
23101fdd08beSQuentin Monnet  * 	Description
23111fdd08beSQuentin Monnet  * 		Set tunnel options metadata for the packet associated to *skb*
23121fdd08beSQuentin Monnet  * 		to the option data contained in the raw buffer *opt* of *size*.
23131fdd08beSQuentin Monnet  *
23141fdd08beSQuentin Monnet  * 		See also the description of the **bpf_skb_get_tunnel_opt**\ ()
23151fdd08beSQuentin Monnet  * 		helper for additional information.
23161fdd08beSQuentin Monnet  * 	Return
23171fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
23181fdd08beSQuentin Monnet  *
2319bdb7b79bSAndrii Nakryiko  * long bpf_skb_change_proto(struct sk_buff *skb, __be16 proto, u64 flags)
23201fdd08beSQuentin Monnet  * 	Description
23211fdd08beSQuentin Monnet  * 		Change the protocol of the *skb* to *proto*. Currently
23221fdd08beSQuentin Monnet  * 		supported are transition from IPv4 to IPv6, and from IPv6 to
23231fdd08beSQuentin Monnet  * 		IPv4. The helper takes care of the groundwork for the
23241fdd08beSQuentin Monnet  * 		transition, including resizing the socket buffer. The eBPF
23251fdd08beSQuentin Monnet  * 		program is expected to fill the new headers, if any, via
23261fdd08beSQuentin Monnet  * 		**skb_store_bytes**\ () and to recompute the checksums with
23271fdd08beSQuentin Monnet  * 		**bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\
23281fdd08beSQuentin Monnet  * 		(). The main case for this helper is to perform NAT64
23291fdd08beSQuentin Monnet  * 		operations out of an eBPF program.
23301fdd08beSQuentin Monnet  *
23311fdd08beSQuentin Monnet  * 		Internally, the GSO type is marked as dodgy so that headers are
23321fdd08beSQuentin Monnet  * 		checked and segments are recalculated by the GSO/GRO engine.
23331fdd08beSQuentin Monnet  * 		The size for GSO target is adapted as well.
23341fdd08beSQuentin Monnet  *
23351fdd08beSQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
23361fdd08beSQuentin Monnet  * 		be left at zero.
23371fdd08beSQuentin Monnet  *
233832e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
23391fdd08beSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
23401fdd08beSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
23411fdd08beSQuentin Monnet  * 		performed again, if the helper is used in combination with
23421fdd08beSQuentin Monnet  * 		direct packet access.
23431fdd08beSQuentin Monnet  * 	Return
23441fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
23451fdd08beSQuentin Monnet  *
2346bdb7b79bSAndrii Nakryiko  * long bpf_skb_change_type(struct sk_buff *skb, u32 type)
23471fdd08beSQuentin Monnet  * 	Description
23481fdd08beSQuentin Monnet  * 		Change the packet type for the packet associated to *skb*. This
23491fdd08beSQuentin Monnet  * 		comes down to setting *skb*\ **->pkt_type** to *type*, except
23501fdd08beSQuentin Monnet  * 		the eBPF program does not have a write access to *skb*\
23511fdd08beSQuentin Monnet  * 		**->pkt_type** beside this helper. Using a helper here allows
23521fdd08beSQuentin Monnet  * 		for graceful handling of errors.
23531fdd08beSQuentin Monnet  *
23541fdd08beSQuentin Monnet  * 		The major use case is to change incoming *skb*s to
23551fdd08beSQuentin Monnet  * 		**PACKET_HOST** in a programmatic way instead of having to
23561fdd08beSQuentin Monnet  * 		recirculate via **redirect**\ (..., **BPF_F_INGRESS**), for
23571fdd08beSQuentin Monnet  * 		example.
23581fdd08beSQuentin Monnet  *
23591fdd08beSQuentin Monnet  * 		Note that *type* only allows certain values. At this time, they
23601fdd08beSQuentin Monnet  * 		are:
23611fdd08beSQuentin Monnet  *
23621fdd08beSQuentin Monnet  * 		**PACKET_HOST**
23631fdd08beSQuentin Monnet  * 			Packet is for us.
23641fdd08beSQuentin Monnet  * 		**PACKET_BROADCAST**
23651fdd08beSQuentin Monnet  * 			Send packet to all.
23661fdd08beSQuentin Monnet  * 		**PACKET_MULTICAST**
23671fdd08beSQuentin Monnet  * 			Send packet to group.
23681fdd08beSQuentin Monnet  * 		**PACKET_OTHERHOST**
23691fdd08beSQuentin Monnet  * 			Send packet to someone else.
23701fdd08beSQuentin Monnet  * 	Return
23711fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
23721fdd08beSQuentin Monnet  *
2373bdb7b79bSAndrii Nakryiko  * long bpf_skb_under_cgroup(struct sk_buff *skb, struct bpf_map *map, u32 index)
2374c6b5fb86SQuentin Monnet  * 	Description
2375c6b5fb86SQuentin Monnet  * 		Check whether *skb* is a descendant of the cgroup2 held by
2376c6b5fb86SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
2377c6b5fb86SQuentin Monnet  * 	Return
2378c6b5fb86SQuentin Monnet  * 		The return value depends on the result of the test, and can be:
2379c6b5fb86SQuentin Monnet  *
2380c6b5fb86SQuentin Monnet  * 		* 0, if the *skb* failed the cgroup2 descendant test.
2381c6b5fb86SQuentin Monnet  * 		* 1, if the *skb* succeeded the cgroup2 descendant test.
2382c6b5fb86SQuentin Monnet  * 		* A negative error code, if an error occurred.
2383c6b5fb86SQuentin Monnet  *
2384fa15601aSQuentin Monnet  * u32 bpf_get_hash_recalc(struct sk_buff *skb)
2385fa15601aSQuentin Monnet  * 	Description
2386fa15601aSQuentin Monnet  * 		Retrieve the hash of the packet, *skb*\ **->hash**. If it is
2387fa15601aSQuentin Monnet  * 		not set, in particular if the hash was cleared due to mangling,
2388fa15601aSQuentin Monnet  * 		recompute this hash. Later accesses to the hash can be done
2389fa15601aSQuentin Monnet  * 		directly with *skb*\ **->hash**.
2390fa15601aSQuentin Monnet  *
2391fa15601aSQuentin Monnet  * 		Calling **bpf_set_hash_invalid**\ (), changing a packet
2392fa15601aSQuentin Monnet  * 		prototype with **bpf_skb_change_proto**\ (), or calling
2393fa15601aSQuentin Monnet  * 		**bpf_skb_store_bytes**\ () with the
2394fa15601aSQuentin Monnet  * 		**BPF_F_INVALIDATE_HASH** are actions susceptible to clear
2395fa15601aSQuentin Monnet  * 		the hash and to trigger a new computation for the next call to
2396fa15601aSQuentin Monnet  * 		**bpf_get_hash_recalc**\ ().
2397fa15601aSQuentin Monnet  * 	Return
2398fa15601aSQuentin Monnet  * 		The 32-bit hash.
2399fa15601aSQuentin Monnet  *
2400c456dec4SQuentin Monnet  * u64 bpf_get_current_task(void)
2401e40fbbf0SUsama Arif  * 	Description
2402e40fbbf0SUsama Arif  * 		Get the current task.
2403c456dec4SQuentin Monnet  * 	Return
2404c456dec4SQuentin Monnet  * 		A pointer to the current task struct.
2405fa15601aSQuentin Monnet  *
2406bdb7b79bSAndrii Nakryiko  * long bpf_probe_write_user(void *dst, const void *src, u32 len)
2407c6b5fb86SQuentin Monnet  * 	Description
2408c6b5fb86SQuentin Monnet  * 		Attempt in a safe way to write *len* bytes from the buffer
2409c6b5fb86SQuentin Monnet  * 		*src* to *dst* in memory. It only works for threads that are in
2410c6b5fb86SQuentin Monnet  * 		user context, and *dst* must be a valid user space address.
2411c6b5fb86SQuentin Monnet  *
2412c6b5fb86SQuentin Monnet  * 		This helper should not be used to implement any kind of
2413c6b5fb86SQuentin Monnet  * 		security mechanism because of TOC-TOU attacks, but rather to
2414c6b5fb86SQuentin Monnet  * 		debug, divert, and manipulate execution of semi-cooperative
2415c6b5fb86SQuentin Monnet  * 		processes.
2416c6b5fb86SQuentin Monnet  *
2417c6b5fb86SQuentin Monnet  * 		Keep in mind that this feature is meant for experiments, and it
2418c6b5fb86SQuentin Monnet  * 		has a risk of crashing the system and running programs.
2419c6b5fb86SQuentin Monnet  * 		Therefore, when an eBPF program using this helper is attached,
2420c6b5fb86SQuentin Monnet  * 		a warning including PID and process name is printed to kernel
2421c6b5fb86SQuentin Monnet  * 		logs.
2422c6b5fb86SQuentin Monnet  * 	Return
2423c6b5fb86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2424c6b5fb86SQuentin Monnet  *
2425bdb7b79bSAndrii Nakryiko  * long bpf_current_task_under_cgroup(struct bpf_map *map, u32 index)
2426c6b5fb86SQuentin Monnet  * 	Description
2427c6b5fb86SQuentin Monnet  * 		Check whether the probe is being run is the context of a given
2428c6b5fb86SQuentin Monnet  * 		subset of the cgroup2 hierarchy. The cgroup2 to test is held by
2429c6b5fb86SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
2430c6b5fb86SQuentin Monnet  * 	Return
2431c6b5fb86SQuentin Monnet  * 		The return value depends on the result of the test, and can be:
2432c6b5fb86SQuentin Monnet  *
243358617014SHengqi Chen  *		* 1, if current task belongs to the cgroup2.
243458617014SHengqi Chen  *		* 0, if current task does not belong to the cgroup2.
2435c6b5fb86SQuentin Monnet  * 		* A negative error code, if an error occurred.
2436c6b5fb86SQuentin Monnet  *
2437bdb7b79bSAndrii Nakryiko  * long bpf_skb_change_tail(struct sk_buff *skb, u32 len, u64 flags)
2438fa15601aSQuentin Monnet  * 	Description
2439fa15601aSQuentin Monnet  * 		Resize (trim or grow) the packet associated to *skb* to the
2440fa15601aSQuentin Monnet  * 		new *len*. The *flags* are reserved for future usage, and must
2441fa15601aSQuentin Monnet  * 		be left at zero.
2442fa15601aSQuentin Monnet  *
2443fa15601aSQuentin Monnet  * 		The basic idea is that the helper performs the needed work to
2444fa15601aSQuentin Monnet  * 		change the size of the packet, then the eBPF program rewrites
2445fa15601aSQuentin Monnet  * 		the rest via helpers like **bpf_skb_store_bytes**\ (),
2446fa15601aSQuentin Monnet  * 		**bpf_l3_csum_replace**\ (), **bpf_l3_csum_replace**\ ()
2447fa15601aSQuentin Monnet  * 		and others. This helper is a slow path utility intended for
2448fa15601aSQuentin Monnet  * 		replies with control messages. And because it is targeted for
2449fa15601aSQuentin Monnet  * 		slow path, the helper itself can afford to be slow: it
2450fa15601aSQuentin Monnet  * 		implicitly linearizes, unclones and drops offloads from the
2451fa15601aSQuentin Monnet  * 		*skb*.
2452fa15601aSQuentin Monnet  *
245332e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
2454fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
2455fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
2456fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
2457fa15601aSQuentin Monnet  * 		direct packet access.
2458fa15601aSQuentin Monnet  * 	Return
2459fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2460fa15601aSQuentin Monnet  *
2461bdb7b79bSAndrii Nakryiko  * long bpf_skb_pull_data(struct sk_buff *skb, u32 len)
2462fa15601aSQuentin Monnet  * 	Description
2463fa15601aSQuentin Monnet  * 		Pull in non-linear data in case the *skb* is non-linear and not
2464fa15601aSQuentin Monnet  * 		all of *len* are part of the linear section. Make *len* bytes
2465fa15601aSQuentin Monnet  * 		from *skb* readable and writable. If a zero value is passed for
2466bdb2bc75SJoanne Koong  *		*len*, then all bytes in the linear part of *skb* will be made
2467bdb2bc75SJoanne Koong  *		readable and writable.
2468fa15601aSQuentin Monnet  *
2469fa15601aSQuentin Monnet  * 		This helper is only needed for reading and writing with direct
2470fa15601aSQuentin Monnet  * 		packet access.
2471fa15601aSQuentin Monnet  *
2472fa15601aSQuentin Monnet  * 		For direct packet access, testing that offsets to access
2473fa15601aSQuentin Monnet  * 		are within packet boundaries (test on *skb*\ **->data_end**) is
2474fa15601aSQuentin Monnet  * 		susceptible to fail if offsets are invalid, or if the requested
2475fa15601aSQuentin Monnet  * 		data is in non-linear parts of the *skb*. On failure the
2476fa15601aSQuentin Monnet  * 		program can just bail out, or in the case of a non-linear
2477fa15601aSQuentin Monnet  * 		buffer, use a helper to make the data available. The
2478fa15601aSQuentin Monnet  * 		**bpf_skb_load_bytes**\ () helper is a first solution to access
2479fa15601aSQuentin Monnet  * 		the data. Another one consists in using **bpf_skb_pull_data**
2480fa15601aSQuentin Monnet  * 		to pull in once the non-linear parts, then retesting and
2481fa15601aSQuentin Monnet  * 		eventually access the data.
2482fa15601aSQuentin Monnet  *
2483fa15601aSQuentin Monnet  * 		At the same time, this also makes sure the *skb* is uncloned,
2484fa15601aSQuentin Monnet  * 		which is a necessary condition for direct write. As this needs
2485fa15601aSQuentin Monnet  * 		to be an invariant for the write part only, the verifier
2486fa15601aSQuentin Monnet  * 		detects writes and adds a prologue that is calling
2487fa15601aSQuentin Monnet  * 		**bpf_skb_pull_data()** to effectively unclone the *skb* from
2488fa15601aSQuentin Monnet  * 		the very beginning in case it is indeed cloned.
2489fa15601aSQuentin Monnet  *
249032e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
2491fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
2492fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
2493fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
2494fa15601aSQuentin Monnet  * 		direct packet access.
2495fa15601aSQuentin Monnet  * 	Return
2496fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2497fa15601aSQuentin Monnet  *
2498fa15601aSQuentin Monnet  * s64 bpf_csum_update(struct sk_buff *skb, __wsum csum)
2499fa15601aSQuentin Monnet  * 	Description
2500fa15601aSQuentin Monnet  * 		Add the checksum *csum* into *skb*\ **->csum** in case the
2501fa15601aSQuentin Monnet  * 		driver has supplied a checksum for the entire packet into that
2502fa15601aSQuentin Monnet  * 		field. Return an error otherwise. This helper is intended to be
2503fa15601aSQuentin Monnet  * 		used in combination with **bpf_csum_diff**\ (), in particular
2504fa15601aSQuentin Monnet  * 		when the checksum needs to be updated after data has been
2505fa15601aSQuentin Monnet  * 		written into the packet through direct packet access.
2506fa15601aSQuentin Monnet  * 	Return
2507fa15601aSQuentin Monnet  * 		The checksum on success, or a negative error code in case of
2508fa15601aSQuentin Monnet  * 		failure.
2509fa15601aSQuentin Monnet  *
2510fa15601aSQuentin Monnet  * void bpf_set_hash_invalid(struct sk_buff *skb)
2511fa15601aSQuentin Monnet  * 	Description
2512fa15601aSQuentin Monnet  * 		Invalidate the current *skb*\ **->hash**. It can be used after
2513fa15601aSQuentin Monnet  * 		mangling on headers through direct packet access, in order to
2514fa15601aSQuentin Monnet  * 		indicate that the hash is outdated and to trigger a
2515fa15601aSQuentin Monnet  * 		recalculation the next time the kernel tries to access this
2516fa15601aSQuentin Monnet  * 		hash or when the **bpf_get_hash_recalc**\ () helper is called.
2517e40fbbf0SUsama Arif  * 	Return
2518e40fbbf0SUsama Arif  * 		void.
2519fa15601aSQuentin Monnet  *
2520bdb7b79bSAndrii Nakryiko  * long bpf_get_numa_node_id(void)
2521fa15601aSQuentin Monnet  * 	Description
2522fa15601aSQuentin Monnet  * 		Return the id of the current NUMA node. The primary use case
2523fa15601aSQuentin Monnet  * 		for this helper is the selection of sockets for the local NUMA
2524fa15601aSQuentin Monnet  * 		node, when the program is attached to sockets using the
2525fa15601aSQuentin Monnet  * 		**SO_ATTACH_REUSEPORT_EBPF** option (see also **socket(7)**),
2526fa15601aSQuentin Monnet  * 		but the helper is also available to other eBPF program types,
2527fa15601aSQuentin Monnet  * 		similarly to **bpf_get_smp_processor_id**\ ().
2528fa15601aSQuentin Monnet  * 	Return
2529fa15601aSQuentin Monnet  * 		The id of current NUMA node.
2530fa15601aSQuentin Monnet  *
2531bdb7b79bSAndrii Nakryiko  * long bpf_skb_change_head(struct sk_buff *skb, u32 len, u64 flags)
2532c6b5fb86SQuentin Monnet  * 	Description
2533c6b5fb86SQuentin Monnet  * 		Grows headroom of packet associated to *skb* and adjusts the
2534c6b5fb86SQuentin Monnet  * 		offset of the MAC header accordingly, adding *len* bytes of
2535c6b5fb86SQuentin Monnet  * 		space. It automatically extends and reallocates memory as
2536c6b5fb86SQuentin Monnet  * 		required.
2537c6b5fb86SQuentin Monnet  *
2538c6b5fb86SQuentin Monnet  * 		This helper can be used on a layer 3 *skb* to push a MAC header
2539c6b5fb86SQuentin Monnet  * 		for redirection into a layer 2 device.
2540c6b5fb86SQuentin Monnet  *
2541c6b5fb86SQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
2542c6b5fb86SQuentin Monnet  * 		be left at zero.
2543c6b5fb86SQuentin Monnet  *
254432e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
2545c6b5fb86SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
2546c6b5fb86SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
2547c6b5fb86SQuentin Monnet  * 		performed again, if the helper is used in combination with
2548c6b5fb86SQuentin Monnet  * 		direct packet access.
2549c6b5fb86SQuentin Monnet  * 	Return
2550c6b5fb86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2551c6b5fb86SQuentin Monnet  *
2552bdb7b79bSAndrii Nakryiko  * long bpf_xdp_adjust_head(struct xdp_buff *xdp_md, int delta)
2553c6b5fb86SQuentin Monnet  * 	Description
2554c6b5fb86SQuentin Monnet  * 		Adjust (move) *xdp_md*\ **->data** by *delta* bytes. Note that
2555c6b5fb86SQuentin Monnet  * 		it is possible to use a negative value for *delta*. This helper
2556c6b5fb86SQuentin Monnet  * 		can be used to prepare the packet for pushing or popping
2557c6b5fb86SQuentin Monnet  * 		headers.
2558c6b5fb86SQuentin Monnet  *
255932e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
2560c6b5fb86SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
2561c6b5fb86SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
2562c6b5fb86SQuentin Monnet  * 		performed again, if the helper is used in combination with
2563c6b5fb86SQuentin Monnet  * 		direct packet access.
2564c6b5fb86SQuentin Monnet  * 	Return
2565c6b5fb86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2566c6b5fb86SQuentin Monnet  *
2567bdb7b79bSAndrii Nakryiko  * long bpf_probe_read_str(void *dst, u32 size, const void *unsafe_ptr)
2568c6b5fb86SQuentin Monnet  * 	Description
25696ae08ae3SDaniel Borkmann  * 		Copy a NUL terminated string from an unsafe kernel address
2570ab8d7809SQuentin Monnet  * 		*unsafe_ptr* to *dst*. See **bpf_probe_read_kernel_str**\ () for
25716ae08ae3SDaniel Borkmann  * 		more details.
2572c6b5fb86SQuentin Monnet  *
2573ab8d7809SQuentin Monnet  * 		Generally, use **bpf_probe_read_user_str**\ () or
2574ab8d7809SQuentin Monnet  * 		**bpf_probe_read_kernel_str**\ () instead.
2575c6b5fb86SQuentin Monnet  * 	Return
2576c6b5fb86SQuentin Monnet  * 		On success, the strictly positive length of the string,
2577c6b5fb86SQuentin Monnet  * 		including the trailing NUL character. On error, a negative
2578c6b5fb86SQuentin Monnet  * 		value.
2579c6b5fb86SQuentin Monnet  *
2580c6b5fb86SQuentin Monnet  * u64 bpf_get_socket_cookie(struct sk_buff *skb)
2581c6b5fb86SQuentin Monnet  * 	Description
2582c6b5fb86SQuentin Monnet  * 		If the **struct sk_buff** pointed by *skb* has a known socket,
2583c6b5fb86SQuentin Monnet  * 		retrieve the cookie (generated by the kernel) of this socket.
2584c6b5fb86SQuentin Monnet  * 		If no cookie has been set yet, generate a new cookie. Once
2585c6b5fb86SQuentin Monnet  * 		generated, the socket cookie remains stable for the life of the
2586c6b5fb86SQuentin Monnet  * 		socket. This helper can be useful for monitoring per socket
2587cd48bddaSDaniel Borkmann  * 		networking traffic statistics as it provides a global socket
2588cd48bddaSDaniel Borkmann  * 		identifier that can be assumed unique.
2589c6b5fb86SQuentin Monnet  * 	Return
259007881ccbSFlorent Revest  * 		A 8-byte long unique number on success, or 0 if the socket
259107881ccbSFlorent Revest  * 		field is missing inside *skb*.
2592c6b5fb86SQuentin Monnet  *
2593d692f113SAndrey Ignatov  * u64 bpf_get_socket_cookie(struct bpf_sock_addr *ctx)
2594d692f113SAndrey Ignatov  * 	Description
2595d692f113SAndrey Ignatov  * 		Equivalent to bpf_get_socket_cookie() helper that accepts
259662369db2SQuentin Monnet  * 		*skb*, but gets socket from **struct bpf_sock_addr** context.
2597d692f113SAndrey Ignatov  * 	Return
259807881ccbSFlorent Revest  * 		A 8-byte long unique number.
2599d692f113SAndrey Ignatov  *
2600d692f113SAndrey Ignatov  * u64 bpf_get_socket_cookie(struct bpf_sock_ops *ctx)
2601d692f113SAndrey Ignatov  * 	Description
2602ab8d7809SQuentin Monnet  * 		Equivalent to **bpf_get_socket_cookie**\ () helper that accepts
260362369db2SQuentin Monnet  * 		*skb*, but gets socket from **struct bpf_sock_ops** context.
2604d692f113SAndrey Ignatov  * 	Return
260507881ccbSFlorent Revest  * 		A 8-byte long unique number.
2606d692f113SAndrey Ignatov  *
2607c5dbb89fSFlorent Revest  * u64 bpf_get_socket_cookie(struct sock *sk)
2608c5dbb89fSFlorent Revest  * 	Description
2609c5dbb89fSFlorent Revest  * 		Equivalent to **bpf_get_socket_cookie**\ () helper that accepts
2610c5dbb89fSFlorent Revest  * 		*sk*, but gets socket from a BTF **struct sock**. This helper
2611c5dbb89fSFlorent Revest  * 		also works for sleepable programs.
2612c5dbb89fSFlorent Revest  * 	Return
2613c5dbb89fSFlorent Revest  * 		A 8-byte long unique number or 0 if *sk* is NULL.
2614c5dbb89fSFlorent Revest  *
2615c6b5fb86SQuentin Monnet  * u32 bpf_get_socket_uid(struct sk_buff *skb)
2616e40fbbf0SUsama Arif  * 	Description
2617e40fbbf0SUsama Arif  * 		Get the owner UID of the socked associated to *skb*.
2618c6b5fb86SQuentin Monnet  * 	Return
2619c6b5fb86SQuentin Monnet  * 		The owner UID of the socket associated to *skb*. If the socket
2620c6b5fb86SQuentin Monnet  * 		is **NULL**, or if it is not a full socket (i.e. if it is a
2621c6b5fb86SQuentin Monnet  * 		time-wait or a request socket instead), **overflowuid** value
2622c6b5fb86SQuentin Monnet  * 		is returned (note that **overflowuid** might also be the actual
2623c6b5fb86SQuentin Monnet  * 		UID value for the socket).
2624c6b5fb86SQuentin Monnet  *
2625bdb7b79bSAndrii Nakryiko  * long bpf_set_hash(struct sk_buff *skb, u32 hash)
2626fa15601aSQuentin Monnet  * 	Description
2627fa15601aSQuentin Monnet  * 		Set the full hash for *skb* (set the field *skb*\ **->hash**)
2628fa15601aSQuentin Monnet  * 		to value *hash*.
2629fa15601aSQuentin Monnet  * 	Return
2630fa15601aSQuentin Monnet  * 		0
2631fa15601aSQuentin Monnet  *
2632bdb7b79bSAndrii Nakryiko  * long bpf_setsockopt(void *bpf_socket, int level, int optname, void *optval, int optlen)
26337aa79a86SQuentin Monnet  * 	Description
26347aa79a86SQuentin Monnet  * 		Emulate a call to **setsockopt()** on the socket associated to
26357aa79a86SQuentin Monnet  * 		*bpf_socket*, which must be a full socket. The *level* at
26367aa79a86SQuentin Monnet  * 		which the option resides and the name *optname* of the option
26377aa79a86SQuentin Monnet  * 		must be specified, see **setsockopt(2)** for more information.
26387aa79a86SQuentin Monnet  * 		The option value of length *optlen* is pointed by *optval*.
26397aa79a86SQuentin Monnet  *
2640beecf11bSStanislav Fomichev  * 		*bpf_socket* should be one of the following:
2641ab8d7809SQuentin Monnet  *
2642beecf11bSStanislav Fomichev  * 		* **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
2643beecf11bSStanislav Fomichev  * 		* **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**
2644beecf11bSStanislav Fomichev  * 		  and **BPF_CGROUP_INET6_CONNECT**.
2645beecf11bSStanislav Fomichev  *
26467aa79a86SQuentin Monnet  * 		This helper actually implements a subset of **setsockopt()**.
26477aa79a86SQuentin Monnet  * 		It supports the following *level*\ s:
26487aa79a86SQuentin Monnet  *
26497aa79a86SQuentin Monnet  * 		* **SOL_SOCKET**, which supports the following *optname*\ s:
26507aa79a86SQuentin Monnet  * 		  **SO_RCVBUF**, **SO_SNDBUF**, **SO_MAX_PACING_RATE**,
2651f9bcf968SDmitry Yakunin  * 		  **SO_PRIORITY**, **SO_RCVLOWAT**, **SO_MARK**,
265272b43bdeSJi Rongfeng  * 		  **SO_BINDTODEVICE**, **SO_KEEPALIVE**, **SO_REUSEADDR**,
265372b43bdeSJi Rongfeng  * 		  **SO_REUSEPORT**, **SO_BINDTOIFINDEX**, **SO_TXREHASH**.
26547aa79a86SQuentin Monnet  * 		* **IPPROTO_TCP**, which supports the following *optname*\ s:
26557aa79a86SQuentin Monnet  * 		  **TCP_CONGESTION**, **TCP_BPF_IW**,
2656f9bcf968SDmitry Yakunin  * 		  **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,
2657f9bcf968SDmitry Yakunin  * 		  **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,
265872b43bdeSJi Rongfeng  * 		  **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**,
265972b43bdeSJi Rongfeng  * 		  **TCP_NODELAY**, **TCP_MAXSEG**, **TCP_WINDOW_CLAMP**,
266072b43bdeSJi Rongfeng  * 		  **TCP_THIN_LINEAR_TIMEOUTS**, **TCP_BPF_DELACK_MAX**,
266172b43bdeSJi Rongfeng  * 		  **TCP_BPF_RTO_MIN**.
26627aa79a86SQuentin Monnet  * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
266372b43bdeSJi Rongfeng  * 		* **IPPROTO_IPV6**, which supports the following *optname*\ s:
266472b43bdeSJi Rongfeng  * 		  **IPV6_TCLASS**, **IPV6_AUTOFLOWLABEL**.
26657aa79a86SQuentin Monnet  * 	Return
26667aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
26677aa79a86SQuentin Monnet  *
2668bdb7b79bSAndrii Nakryiko  * long bpf_skb_adjust_room(struct sk_buff *skb, s32 len_diff, u32 mode, u64 flags)
2669fa15601aSQuentin Monnet  * 	Description
2670fa15601aSQuentin Monnet  * 		Grow or shrink the room for data in the packet associated to
2671fa15601aSQuentin Monnet  * 		*skb* by *len_diff*, and according to the selected *mode*.
2672fa15601aSQuentin Monnet  *
2673836e66c2SDaniel Borkmann  * 		By default, the helper will reset any offloaded checksum
2674836e66c2SDaniel Borkmann  * 		indicator of the skb to CHECKSUM_NONE. This can be avoided
2675836e66c2SDaniel Borkmann  * 		by the following flag:
2676836e66c2SDaniel Borkmann  *
2677836e66c2SDaniel Borkmann  * 		* **BPF_F_ADJ_ROOM_NO_CSUM_RESET**: Do not reset offloaded
2678836e66c2SDaniel Borkmann  * 		  checksum data of the skb to CHECKSUM_NONE.
2679836e66c2SDaniel Borkmann  *
268014aa3192SWillem de Bruijn  *		There are two supported modes at this time:
268114aa3192SWillem de Bruijn  *
268214aa3192SWillem de Bruijn  *		* **BPF_ADJ_ROOM_MAC**: Adjust room at the mac layer
26834961d077SQuentin Monnet  * 		  (room space is added or removed between the layer 2 and
26844961d077SQuentin Monnet  * 		  layer 3 headers).
2685fa15601aSQuentin Monnet  *
2686fa15601aSQuentin Monnet  * 		* **BPF_ADJ_ROOM_NET**: Adjust room at the network layer
26874961d077SQuentin Monnet  * 		  (room space is added or removed between the layer 3 and
26884961d077SQuentin Monnet  * 		  layer 4 headers).
2689fa15601aSQuentin Monnet  *
2690868d5235SWillem de Bruijn  *		The following flags are supported at this time:
26912278f6ccSWillem de Bruijn  *
26922278f6ccSWillem de Bruijn  *		* **BPF_F_ADJ_ROOM_FIXED_GSO**: Do not adjust gso_size.
26932278f6ccSWillem de Bruijn  *		  Adjusting mss in this way is not allowed for datagrams.
2694fa15601aSQuentin Monnet  *
269580867c5eSQuentin Monnet  *		* **BPF_F_ADJ_ROOM_ENCAP_L3_IPV4**,
269680867c5eSQuentin Monnet  *		  **BPF_F_ADJ_ROOM_ENCAP_L3_IPV6**:
2697868d5235SWillem de Bruijn  *		  Any new space is reserved to hold a tunnel header.
2698868d5235SWillem de Bruijn  *		  Configure skb offsets and other fields accordingly.
2699868d5235SWillem de Bruijn  *
270080867c5eSQuentin Monnet  *		* **BPF_F_ADJ_ROOM_ENCAP_L4_GRE**,
270180867c5eSQuentin Monnet  *		  **BPF_F_ADJ_ROOM_ENCAP_L4_UDP**:
2702868d5235SWillem de Bruijn  *		  Use with ENCAP_L3 flags to further specify the tunnel type.
2703868d5235SWillem de Bruijn  *
270480867c5eSQuentin Monnet  *		* **BPF_F_ADJ_ROOM_ENCAP_L2**\ (*len*):
270558dfc900SAlan Maguire  *		  Use with ENCAP_L3/L4 flags to further specify the tunnel
270680867c5eSQuentin Monnet  *		  type; *len* is the length of the inner MAC header.
270758dfc900SAlan Maguire  *
2708d01b59c9SXuesen Huang  *		* **BPF_F_ADJ_ROOM_ENCAP_L2_ETH**:
2709d01b59c9SXuesen Huang  *		  Use with BPF_F_ADJ_ROOM_ENCAP_L2 flag to further specify the
2710d01b59c9SXuesen Huang  *		  L2 type as Ethernet.
2711d01b59c9SXuesen Huang  *
2712d219df60SZiyang Xuan  *		* **BPF_F_ADJ_ROOM_DECAP_L3_IPV4**,
2713d219df60SZiyang Xuan  *		  **BPF_F_ADJ_ROOM_DECAP_L3_IPV6**:
2714d219df60SZiyang Xuan  *		  Indicate the new IP header version after decapsulating the outer
2715d219df60SZiyang Xuan  *		  IP header. Used when the inner and outer IP versions are different.
2716d219df60SZiyang Xuan  *
271732e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
2718fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
2719fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
2720fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
2721fa15601aSQuentin Monnet  * 		direct packet access.
2722fa15601aSQuentin Monnet  * 	Return
2723fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2724fa15601aSQuentin Monnet  *
272532637e33SToke Høiland-Jørgensen  * long bpf_redirect_map(struct bpf_map *map, u64 key, u64 flags)
2726ab127040SQuentin Monnet  * 	Description
2727ab127040SQuentin Monnet  * 		Redirect the packet to the endpoint referenced by *map* at
2728ab127040SQuentin Monnet  * 		index *key*. Depending on its type, this *map* can contain
2729ab127040SQuentin Monnet  * 		references to net devices (for forwarding packets through other
2730ab127040SQuentin Monnet  * 		ports), or to CPUs (for redirecting XDP frames to another CPU;
2731ab127040SQuentin Monnet  * 		but this is only implemented for native XDP (with driver
2732ab127040SQuentin Monnet  * 		support) as of this writing).
2733ab127040SQuentin Monnet  *
273443e74c02SToke Høiland-Jørgensen  * 		The lower two bits of *flags* are used as the return code if
273543e74c02SToke Høiland-Jørgensen  * 		the map lookup fails. This is so that the return value can be
2736ab8d7809SQuentin Monnet  * 		one of the XDP program return codes up to **XDP_TX**, as chosen
2737e624d4edSHangbin Liu  * 		by the caller. The higher bits of *flags* can be set to
2738e624d4edSHangbin Liu  * 		BPF_F_BROADCAST or BPF_F_EXCLUDE_INGRESS as defined below.
2739e624d4edSHangbin Liu  *
2740e624d4edSHangbin Liu  * 		With BPF_F_BROADCAST the packet will be broadcasted to all the
2741e624d4edSHangbin Liu  * 		interfaces in the map, with BPF_F_EXCLUDE_INGRESS the ingress
2742e624d4edSHangbin Liu  * 		interface will be excluded when do broadcasting.
2743ab127040SQuentin Monnet  *
2744ab8d7809SQuentin Monnet  * 		See also **bpf_redirect**\ (), which only supports redirecting
2745ab8d7809SQuentin Monnet  * 		to an ifindex, but doesn't require a map to do so.
2746ab127040SQuentin Monnet  * 	Return
2747f25975f4SToke Høiland-Jørgensen  * 		**XDP_REDIRECT** on success, or the value of the two lower bits
2748a33d3147SJakub Wilk  * 		of the *flags* argument on error.
2749ab127040SQuentin Monnet  *
2750bdb7b79bSAndrii Nakryiko  * long bpf_sk_redirect_map(struct sk_buff *skb, struct bpf_map *map, u32 key, u64 flags)
2751ab127040SQuentin Monnet  * 	Description
2752ab127040SQuentin Monnet  * 		Redirect the packet to the socket referenced by *map* (of type
2753ab127040SQuentin Monnet  * 		**BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
2754ab127040SQuentin Monnet  * 		egress interfaces can be used for redirection. The
2755ab127040SQuentin Monnet  * 		**BPF_F_INGRESS** value in *flags* is used to make the
2756ab127040SQuentin Monnet  * 		distinction (ingress path is selected if the flag is present,
2757ab127040SQuentin Monnet  * 		egress path otherwise). This is the only flag supported for now.
2758ab127040SQuentin Monnet  * 	Return
2759ab127040SQuentin Monnet  * 		**SK_PASS** on success, or **SK_DROP** on error.
2760ab127040SQuentin Monnet  *
2761bdb7b79bSAndrii Nakryiko  * long bpf_sock_map_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
2762ab127040SQuentin Monnet  * 	Description
2763ab127040SQuentin Monnet  * 		Add an entry to, or update a *map* referencing sockets. The
2764ab127040SQuentin Monnet  * 		*skops* is used as a new value for the entry associated to
2765ab127040SQuentin Monnet  * 		*key*. *flags* is one of:
2766ab127040SQuentin Monnet  *
2767ab127040SQuentin Monnet  * 		**BPF_NOEXIST**
2768ab127040SQuentin Monnet  * 			The entry for *key* must not exist in the map.
2769ab127040SQuentin Monnet  * 		**BPF_EXIST**
2770ab127040SQuentin Monnet  * 			The entry for *key* must already exist in the map.
2771ab127040SQuentin Monnet  * 		**BPF_ANY**
2772ab127040SQuentin Monnet  * 			No condition on the existence of the entry for *key*.
2773ab127040SQuentin Monnet  *
2774ab127040SQuentin Monnet  * 		If the *map* has eBPF programs (parser and verdict), those will
2775ab127040SQuentin Monnet  * 		be inherited by the socket being added. If the socket is
2776ab127040SQuentin Monnet  * 		already attached to eBPF programs, this results in an error.
2777ab127040SQuentin Monnet  * 	Return
2778ab127040SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2779ab127040SQuentin Monnet  *
2780bdb7b79bSAndrii Nakryiko  * long bpf_xdp_adjust_meta(struct xdp_buff *xdp_md, int delta)
2781fa15601aSQuentin Monnet  * 	Description
2782fa15601aSQuentin Monnet  * 		Adjust the address pointed by *xdp_md*\ **->data_meta** by
2783fa15601aSQuentin Monnet  * 		*delta* (which can be positive or negative). Note that this
2784fa15601aSQuentin Monnet  * 		operation modifies the address stored in *xdp_md*\ **->data**,
2785fa15601aSQuentin Monnet  * 		so the latter must be loaded only after the helper has been
2786fa15601aSQuentin Monnet  * 		called.
2787fa15601aSQuentin Monnet  *
2788fa15601aSQuentin Monnet  * 		The use of *xdp_md*\ **->data_meta** is optional and programs
2789fa15601aSQuentin Monnet  * 		are not required to use it. The rationale is that when the
2790fa15601aSQuentin Monnet  * 		packet is processed with XDP (e.g. as DoS filter), it is
2791fa15601aSQuentin Monnet  * 		possible to push further meta data along with it before passing
2792fa15601aSQuentin Monnet  * 		to the stack, and to give the guarantee that an ingress eBPF
2793fa15601aSQuentin Monnet  * 		program attached as a TC classifier on the same device can pick
2794fa15601aSQuentin Monnet  * 		this up for further post-processing. Since TC works with socket
2795fa15601aSQuentin Monnet  * 		buffers, it remains possible to set from XDP the **mark** or
2796fa15601aSQuentin Monnet  * 		**priority** pointers, or other pointers for the socket buffer.
2797fa15601aSQuentin Monnet  * 		Having this scratch space generic and programmable allows for
2798fa15601aSQuentin Monnet  * 		more flexibility as the user is free to store whatever meta
2799fa15601aSQuentin Monnet  * 		data they need.
2800fa15601aSQuentin Monnet  *
280132e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
2802fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
2803fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
2804fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
2805fa15601aSQuentin Monnet  * 		direct packet access.
2806fa15601aSQuentin Monnet  * 	Return
2807fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
28087aa79a86SQuentin Monnet  *
2809bdb7b79bSAndrii Nakryiko  * long bpf_perf_event_read_value(struct bpf_map *map, u64 flags, struct bpf_perf_event_value *buf, u32 buf_size)
28107aa79a86SQuentin Monnet  * 	Description
28117aa79a86SQuentin Monnet  * 		Read the value of a perf event counter, and store it into *buf*
28127aa79a86SQuentin Monnet  * 		of size *buf_size*. This helper relies on a *map* of type
28137aa79a86SQuentin Monnet  * 		**BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of the perf event
28147aa79a86SQuentin Monnet  * 		counter is selected when *map* is updated with perf event file
28157aa79a86SQuentin Monnet  * 		descriptors. The *map* is an array whose size is the number of
28167aa79a86SQuentin Monnet  * 		available CPUs, and each cell contains a value relative to one
28177aa79a86SQuentin Monnet  * 		CPU. The value to retrieve is indicated by *flags*, that
28187aa79a86SQuentin Monnet  * 		contains the index of the CPU to look up, masked with
28197aa79a86SQuentin Monnet  * 		**BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
28207aa79a86SQuentin Monnet  * 		**BPF_F_CURRENT_CPU** to indicate that the value for the
28217aa79a86SQuentin Monnet  * 		current CPU should be retrieved.
28227aa79a86SQuentin Monnet  *
28237aa79a86SQuentin Monnet  * 		This helper behaves in a way close to
28247aa79a86SQuentin Monnet  * 		**bpf_perf_event_read**\ () helper, save that instead of
28257aa79a86SQuentin Monnet  * 		just returning the value observed, it fills the *buf*
28267aa79a86SQuentin Monnet  * 		structure. This allows for additional data to be retrieved: in
28277aa79a86SQuentin Monnet  * 		particular, the enabled and running times (in *buf*\
28287aa79a86SQuentin Monnet  * 		**->enabled** and *buf*\ **->running**, respectively) are
28297aa79a86SQuentin Monnet  * 		copied. In general, **bpf_perf_event_read_value**\ () is
28307aa79a86SQuentin Monnet  * 		recommended over **bpf_perf_event_read**\ (), which has some
28317aa79a86SQuentin Monnet  * 		ABI issues and provides fewer functionalities.
28327aa79a86SQuentin Monnet  *
28337aa79a86SQuentin Monnet  * 		These values are interesting, because hardware PMU (Performance
28347aa79a86SQuentin Monnet  * 		Monitoring Unit) counters are limited resources. When there are
28357aa79a86SQuentin Monnet  * 		more PMU based perf events opened than available counters,
28367aa79a86SQuentin Monnet  * 		kernel will multiplex these events so each event gets certain
28377aa79a86SQuentin Monnet  * 		percentage (but not all) of the PMU time. In case that
28387aa79a86SQuentin Monnet  * 		multiplexing happens, the number of samples or counter value
28397aa79a86SQuentin Monnet  * 		will not reflect the case compared to when no multiplexing
28407aa79a86SQuentin Monnet  * 		occurs. This makes comparison between different runs difficult.
28417aa79a86SQuentin Monnet  * 		Typically, the counter value should be normalized before
28427aa79a86SQuentin Monnet  * 		comparing to other experiments. The usual normalization is done
28437aa79a86SQuentin Monnet  * 		as follows.
28447aa79a86SQuentin Monnet  *
28457aa79a86SQuentin Monnet  * 		::
28467aa79a86SQuentin Monnet  *
28477aa79a86SQuentin Monnet  * 			normalized_counter = counter * t_enabled / t_running
28487aa79a86SQuentin Monnet  *
28497aa79a86SQuentin Monnet  * 		Where t_enabled is the time enabled for event and t_running is
28507aa79a86SQuentin Monnet  * 		the time running for event since last normalization. The
28517aa79a86SQuentin Monnet  * 		enabled and running times are accumulated since the perf event
28527aa79a86SQuentin Monnet  * 		open. To achieve scaling factor between two invocations of an
2853ab8d7809SQuentin Monnet  * 		eBPF program, users can use CPU id as the key (which is
28547aa79a86SQuentin Monnet  * 		typical for perf array usage model) to remember the previous
28557aa79a86SQuentin Monnet  * 		value and do the calculation inside the eBPF program.
28567aa79a86SQuentin Monnet  * 	Return
28577aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
28587aa79a86SQuentin Monnet  *
2859bdb7b79bSAndrii Nakryiko  * long bpf_perf_prog_read_value(struct bpf_perf_event_data *ctx, struct bpf_perf_event_value *buf, u32 buf_size)
28607aa79a86SQuentin Monnet  * 	Description
286117c9b4e1SFlorian Lehner  * 		For an eBPF program attached to a perf event, retrieve the
28627aa79a86SQuentin Monnet  * 		value of the event counter associated to *ctx* and store it in
28637aa79a86SQuentin Monnet  * 		the structure pointed by *buf* and of size *buf_size*. Enabled
28647aa79a86SQuentin Monnet  * 		and running times are also stored in the structure (see
28657aa79a86SQuentin Monnet  * 		description of helper **bpf_perf_event_read_value**\ () for
28667aa79a86SQuentin Monnet  * 		more details).
28677aa79a86SQuentin Monnet  * 	Return
28687aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
28697aa79a86SQuentin Monnet  *
2870bdb7b79bSAndrii Nakryiko  * long bpf_getsockopt(void *bpf_socket, int level, int optname, void *optval, int optlen)
28717aa79a86SQuentin Monnet  * 	Description
28727aa79a86SQuentin Monnet  * 		Emulate a call to **getsockopt()** on the socket associated to
28737aa79a86SQuentin Monnet  * 		*bpf_socket*, which must be a full socket. The *level* at
28747aa79a86SQuentin Monnet  * 		which the option resides and the name *optname* of the option
28757aa79a86SQuentin Monnet  * 		must be specified, see **getsockopt(2)** for more information.
28767aa79a86SQuentin Monnet  * 		The retrieved value is stored in the structure pointed by
28777aa79a86SQuentin Monnet  * 		*opval* and of length *optlen*.
28787aa79a86SQuentin Monnet  *
2879beecf11bSStanislav Fomichev  * 		*bpf_socket* should be one of the following:
2880ab8d7809SQuentin Monnet  *
2881beecf11bSStanislav Fomichev  * 		* **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
2882beecf11bSStanislav Fomichev  * 		* **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**
2883beecf11bSStanislav Fomichev  * 		  and **BPF_CGROUP_INET6_CONNECT**.
2884beecf11bSStanislav Fomichev  *
28857aa79a86SQuentin Monnet  * 		This helper actually implements a subset of **getsockopt()**.
288672b43bdeSJi Rongfeng  * 		It supports the same set of *optname*\ s that is supported by
288772b43bdeSJi Rongfeng  * 		the **bpf_setsockopt**\ () helper.  The exceptions are
288872b43bdeSJi Rongfeng  * 		**TCP_BPF_*** is **bpf_setsockopt**\ () only and
288972b43bdeSJi Rongfeng  * 		**TCP_SAVED_SYN** is **bpf_getsockopt**\ () only.
28907aa79a86SQuentin Monnet  * 	Return
28917aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
28927aa79a86SQuentin Monnet  *
2893bdb7b79bSAndrii Nakryiko  * long bpf_override_return(struct pt_regs *regs, u64 rc)
28947aa79a86SQuentin Monnet  * 	Description
28957aa79a86SQuentin Monnet  * 		Used for error injection, this helper uses kprobes to override
28967aa79a86SQuentin Monnet  * 		the return value of the probed function, and to set it to *rc*.
28977aa79a86SQuentin Monnet  * 		The first argument is the context *regs* on which the kprobe
28987aa79a86SQuentin Monnet  * 		works.
28997aa79a86SQuentin Monnet  *
2900ab8d7809SQuentin Monnet  * 		This helper works by setting the PC (program counter)
29017aa79a86SQuentin Monnet  * 		to an override function which is run in place of the original
29027aa79a86SQuentin Monnet  * 		probed function. This means the probed function is not run at
29037aa79a86SQuentin Monnet  * 		all. The replacement function just returns with the required
29047aa79a86SQuentin Monnet  * 		value.
29057aa79a86SQuentin Monnet  *
29067aa79a86SQuentin Monnet  * 		This helper has security implications, and thus is subject to
29077aa79a86SQuentin Monnet  * 		restrictions. It is only available if the kernel was compiled
29087aa79a86SQuentin Monnet  * 		with the **CONFIG_BPF_KPROBE_OVERRIDE** configuration
29097aa79a86SQuentin Monnet  * 		option, and in this case it only works on functions tagged with
29107aa79a86SQuentin Monnet  * 		**ALLOW_ERROR_INJECTION** in the kernel code.
29117aa79a86SQuentin Monnet  *
29127aa79a86SQuentin Monnet  * 		Also, the helper is only available for the architectures having
29137aa79a86SQuentin Monnet  * 		the CONFIG_FUNCTION_ERROR_INJECTION option. As of this writing,
29147aa79a86SQuentin Monnet  * 		x86 architecture is the only one to support this feature.
29157aa79a86SQuentin Monnet  * 	Return
29167aa79a86SQuentin Monnet  * 		0
29177aa79a86SQuentin Monnet  *
2918bdb7b79bSAndrii Nakryiko  * long bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *bpf_sock, int argval)
29197aa79a86SQuentin Monnet  * 	Description
29207aa79a86SQuentin Monnet  * 		Attempt to set the value of the **bpf_sock_ops_cb_flags** field
29217aa79a86SQuentin Monnet  * 		for the full TCP socket associated to *bpf_sock_ops* to
29227aa79a86SQuentin Monnet  * 		*argval*.
29237aa79a86SQuentin Monnet  *
29247aa79a86SQuentin Monnet  * 		The primary use of this field is to determine if there should
29257aa79a86SQuentin Monnet  * 		be calls to eBPF programs of type
29267aa79a86SQuentin Monnet  * 		**BPF_PROG_TYPE_SOCK_OPS** at various points in the TCP
29277aa79a86SQuentin Monnet  * 		code. A program of the same type can change its value, per
29287aa79a86SQuentin Monnet  * 		connection and as necessary, when the connection is
29297aa79a86SQuentin Monnet  * 		established. This field is directly accessible for reading, but
29307aa79a86SQuentin Monnet  * 		this helper must be used for updates in order to return an
29317aa79a86SQuentin Monnet  * 		error if an eBPF program tries to set a callback that is not
29327aa79a86SQuentin Monnet  * 		supported in the current kernel.
29337aa79a86SQuentin Monnet  *
2934725721a6SViet Hoang Tran  * 		*argval* is a flag array which can combine these flags:
29357aa79a86SQuentin Monnet  *
29367aa79a86SQuentin Monnet  * 		* **BPF_SOCK_OPS_RTO_CB_FLAG** (retransmission time out)
29377aa79a86SQuentin Monnet  * 		* **BPF_SOCK_OPS_RETRANS_CB_FLAG** (retransmission)
29387aa79a86SQuentin Monnet  * 		* **BPF_SOCK_OPS_STATE_CB_FLAG** (TCP state change)
293923729ff2SStanislav Fomichev  * 		* **BPF_SOCK_OPS_RTT_CB_FLAG** (every RTT)
29407aa79a86SQuentin Monnet  *
2941725721a6SViet Hoang Tran  * 		Therefore, this function can be used to clear a callback flag by
2942725721a6SViet Hoang Tran  * 		setting the appropriate bit to zero. e.g. to disable the RTO
2943725721a6SViet Hoang Tran  * 		callback:
2944725721a6SViet Hoang Tran  *
2945725721a6SViet Hoang Tran  * 		**bpf_sock_ops_cb_flags_set(bpf_sock,**
2946725721a6SViet Hoang Tran  * 			**bpf_sock->bpf_sock_ops_cb_flags & ~BPF_SOCK_OPS_RTO_CB_FLAG)**
2947725721a6SViet Hoang Tran  *
29487aa79a86SQuentin Monnet  * 		Here are some examples of where one could call such eBPF
29497aa79a86SQuentin Monnet  * 		program:
29507aa79a86SQuentin Monnet  *
29517aa79a86SQuentin Monnet  * 		* When RTO fires.
29527aa79a86SQuentin Monnet  * 		* When a packet is retransmitted.
29537aa79a86SQuentin Monnet  * 		* When the connection terminates.
29547aa79a86SQuentin Monnet  * 		* When a packet is sent.
29557aa79a86SQuentin Monnet  * 		* When a packet is received.
29567aa79a86SQuentin Monnet  * 	Return
29577aa79a86SQuentin Monnet  * 		Code **-EINVAL** if the socket is not a full TCP socket;
29587aa79a86SQuentin Monnet  * 		otherwise, a positive number containing the bits that could not
29597aa79a86SQuentin Monnet  * 		be set is returned (which comes down to 0 if all bits were set
29607aa79a86SQuentin Monnet  * 		as required).
29617aa79a86SQuentin Monnet  *
2962bdb7b79bSAndrii Nakryiko  * long bpf_msg_redirect_map(struct sk_msg_buff *msg, struct bpf_map *map, u32 key, u64 flags)
2963ab127040SQuentin Monnet  * 	Description
2964ab127040SQuentin Monnet  * 		This helper is used in programs implementing policies at the
2965ab127040SQuentin Monnet  * 		socket level. If the message *msg* is allowed to pass (i.e. if
2966ab127040SQuentin Monnet  * 		the verdict eBPF program returns **SK_PASS**), redirect it to
2967ab127040SQuentin Monnet  * 		the socket referenced by *map* (of type
2968ab127040SQuentin Monnet  * 		**BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
2969ab127040SQuentin Monnet  * 		egress interfaces can be used for redirection. The
2970ab127040SQuentin Monnet  * 		**BPF_F_INGRESS** value in *flags* is used to make the
2971ab127040SQuentin Monnet  * 		distinction (ingress path is selected if the flag is present,
2972ab127040SQuentin Monnet  * 		egress path otherwise). This is the only flag supported for now.
2973ab127040SQuentin Monnet  * 	Return
2974ab127040SQuentin Monnet  * 		**SK_PASS** on success, or **SK_DROP** on error.
2975ab127040SQuentin Monnet  *
2976bdb7b79bSAndrii Nakryiko  * long bpf_msg_apply_bytes(struct sk_msg_buff *msg, u32 bytes)
2977ab127040SQuentin Monnet  * 	Description
2978ab127040SQuentin Monnet  * 		For socket policies, apply the verdict of the eBPF program to
2979ab127040SQuentin Monnet  * 		the next *bytes* (number of bytes) of message *msg*.
2980ab127040SQuentin Monnet  *
2981ab127040SQuentin Monnet  * 		For example, this helper can be used in the following cases:
2982ab127040SQuentin Monnet  *
2983ab127040SQuentin Monnet  * 		* A single **sendmsg**\ () or **sendfile**\ () system call
2984ab127040SQuentin Monnet  * 		  contains multiple logical messages that the eBPF program is
2985ab127040SQuentin Monnet  * 		  supposed to read and for which it should apply a verdict.
2986ab127040SQuentin Monnet  * 		* An eBPF program only cares to read the first *bytes* of a
2987ab127040SQuentin Monnet  * 		  *msg*. If the message has a large payload, then setting up
2988ab127040SQuentin Monnet  * 		  and calling the eBPF program repeatedly for all bytes, even
2989ab127040SQuentin Monnet  * 		  though the verdict is already known, would create unnecessary
2990ab127040SQuentin Monnet  * 		  overhead.
2991ab127040SQuentin Monnet  *
2992ab127040SQuentin Monnet  * 		When called from within an eBPF program, the helper sets a
2993ab127040SQuentin Monnet  * 		counter internal to the BPF infrastructure, that is used to
2994ab127040SQuentin Monnet  * 		apply the last verdict to the next *bytes*. If *bytes* is
2995ab127040SQuentin Monnet  * 		smaller than the current data being processed from a
2996ab127040SQuentin Monnet  * 		**sendmsg**\ () or **sendfile**\ () system call, the first
2997ab127040SQuentin Monnet  * 		*bytes* will be sent and the eBPF program will be re-run with
2998ab127040SQuentin Monnet  * 		the pointer for start of data pointing to byte number *bytes*
2999ab127040SQuentin Monnet  * 		**+ 1**. If *bytes* is larger than the current data being
3000ab127040SQuentin Monnet  * 		processed, then the eBPF verdict will be applied to multiple
3001ab127040SQuentin Monnet  * 		**sendmsg**\ () or **sendfile**\ () calls until *bytes* are
3002ab127040SQuentin Monnet  * 		consumed.
3003ab127040SQuentin Monnet  *
3004ab127040SQuentin Monnet  * 		Note that if a socket closes with the internal counter holding
3005ab127040SQuentin Monnet  * 		a non-zero value, this is not a problem because data is not
3006ab127040SQuentin Monnet  * 		being buffered for *bytes* and is sent as it is received.
3007ab127040SQuentin Monnet  * 	Return
3008ab127040SQuentin Monnet  * 		0
3009ab127040SQuentin Monnet  *
3010bdb7b79bSAndrii Nakryiko  * long bpf_msg_cork_bytes(struct sk_msg_buff *msg, u32 bytes)
3011ab127040SQuentin Monnet  * 	Description
3012ab127040SQuentin Monnet  * 		For socket policies, prevent the execution of the verdict eBPF
3013ab127040SQuentin Monnet  * 		program for message *msg* until *bytes* (byte number) have been
3014ab127040SQuentin Monnet  * 		accumulated.
3015ab127040SQuentin Monnet  *
3016ab127040SQuentin Monnet  * 		This can be used when one needs a specific number of bytes
3017ab127040SQuentin Monnet  * 		before a verdict can be assigned, even if the data spans
3018ab127040SQuentin Monnet  * 		multiple **sendmsg**\ () or **sendfile**\ () calls. The extreme
3019ab127040SQuentin Monnet  * 		case would be a user calling **sendmsg**\ () repeatedly with
3020ab127040SQuentin Monnet  * 		1-byte long message segments. Obviously, this is bad for
3021ab127040SQuentin Monnet  * 		performance, but it is still valid. If the eBPF program needs
3022ab127040SQuentin Monnet  * 		*bytes* bytes to validate a header, this helper can be used to
3023ab127040SQuentin Monnet  * 		prevent the eBPF program to be called again until *bytes* have
3024ab127040SQuentin Monnet  * 		been accumulated.
3025ab127040SQuentin Monnet  * 	Return
3026ab127040SQuentin Monnet  * 		0
3027ab127040SQuentin Monnet  *
3028bdb7b79bSAndrii Nakryiko  * long bpf_msg_pull_data(struct sk_msg_buff *msg, u32 start, u32 end, u64 flags)
3029ab127040SQuentin Monnet  * 	Description
3030ab127040SQuentin Monnet  * 		For socket policies, pull in non-linear data from user space
3031ab127040SQuentin Monnet  * 		for *msg* and set pointers *msg*\ **->data** and *msg*\
3032ab127040SQuentin Monnet  * 		**->data_end** to *start* and *end* bytes offsets into *msg*,
3033ab127040SQuentin Monnet  * 		respectively.
3034ab127040SQuentin Monnet  *
3035ab127040SQuentin Monnet  * 		If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
3036ab127040SQuentin Monnet  * 		*msg* it can only parse data that the (**data**, **data_end**)
3037ab127040SQuentin Monnet  * 		pointers have already consumed. For **sendmsg**\ () hooks this
3038ab127040SQuentin Monnet  * 		is likely the first scatterlist element. But for calls relying
3039ab127040SQuentin Monnet  * 		on the **sendpage** handler (e.g. **sendfile**\ ()) this will
3040ab127040SQuentin Monnet  * 		be the range (**0**, **0**) because the data is shared with
3041ab127040SQuentin Monnet  * 		user space and by default the objective is to avoid allowing
3042ab127040SQuentin Monnet  * 		user space to modify data while (or after) eBPF verdict is
3043ab127040SQuentin Monnet  * 		being decided. This helper can be used to pull in data and to
3044ab127040SQuentin Monnet  * 		set the start and end pointer to given values. Data will be
3045ab127040SQuentin Monnet  * 		copied if necessary (i.e. if data was not linear and if start
3046ab127040SQuentin Monnet  * 		and end pointers do not point to the same chunk).
3047ab127040SQuentin Monnet  *
304832e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
3049ab127040SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
3050ab127040SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
3051ab127040SQuentin Monnet  * 		performed again, if the helper is used in combination with
3052ab127040SQuentin Monnet  * 		direct packet access.
3053ab127040SQuentin Monnet  *
3054ab127040SQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
3055ab127040SQuentin Monnet  * 		be left at zero.
3056ab127040SQuentin Monnet  * 	Return
3057ab127040SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
3058ab127040SQuentin Monnet  *
3059bdb7b79bSAndrii Nakryiko  * long bpf_bind(struct bpf_sock_addr *ctx, struct sockaddr *addr, int addr_len)
30607aa79a86SQuentin Monnet  * 	Description
30617aa79a86SQuentin Monnet  * 		Bind the socket associated to *ctx* to the address pointed by
30627aa79a86SQuentin Monnet  * 		*addr*, of length *addr_len*. This allows for making outgoing
30637aa79a86SQuentin Monnet  * 		connection from the desired IP address, which can be useful for
30647aa79a86SQuentin Monnet  * 		example when all processes inside a cgroup should use one
30657aa79a86SQuentin Monnet  * 		single IP address on a host that has multiple IP configured.
30667aa79a86SQuentin Monnet  *
30677aa79a86SQuentin Monnet  * 		This helper works for IPv4 and IPv6, TCP and UDP sockets. The
30687aa79a86SQuentin Monnet  * 		domain (*addr*\ **->sa_family**) must be **AF_INET** (or
30698086fbafSStanislav Fomichev  * 		**AF_INET6**). It's advised to pass zero port (**sin_port**
30708086fbafSStanislav Fomichev  * 		or **sin6_port**) which triggers IP_BIND_ADDRESS_NO_PORT-like
30718086fbafSStanislav Fomichev  * 		behavior and lets the kernel efficiently pick up an unused
30728086fbafSStanislav Fomichev  * 		port as long as 4-tuple is unique. Passing non-zero port might
30738086fbafSStanislav Fomichev  * 		lead to degraded performance.
30747aa79a86SQuentin Monnet  * 	Return
30757aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
30762d020dd7SQuentin Monnet  *
3077bdb7b79bSAndrii Nakryiko  * long bpf_xdp_adjust_tail(struct xdp_buff *xdp_md, int delta)
30782d020dd7SQuentin Monnet  * 	Description
30792d020dd7SQuentin Monnet  * 		Adjust (move) *xdp_md*\ **->data_end** by *delta* bytes. It is
3080c8741e2bSJesper Dangaard Brouer  * 		possible to both shrink and grow the packet tail.
3081c8741e2bSJesper Dangaard Brouer  * 		Shrink done via *delta* being a negative integer.
30822d020dd7SQuentin Monnet  *
308332e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
30842d020dd7SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
30852d020dd7SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
30862d020dd7SQuentin Monnet  * 		performed again, if the helper is used in combination with
30872d020dd7SQuentin Monnet  * 		direct packet access.
30882d020dd7SQuentin Monnet  * 	Return
30892d020dd7SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
30902d020dd7SQuentin Monnet  *
3091bdb7b79bSAndrii Nakryiko  * long bpf_skb_get_xfrm_state(struct sk_buff *skb, u32 index, struct bpf_xfrm_state *xfrm_state, u32 size, u64 flags)
30922d020dd7SQuentin Monnet  * 	Description
30932d020dd7SQuentin Monnet  * 		Retrieve the XFRM state (IP transform framework, see also
30942d020dd7SQuentin Monnet  * 		**ip-xfrm(8)**) at *index* in XFRM "security path" for *skb*.
30952d020dd7SQuentin Monnet  *
30962d020dd7SQuentin Monnet  * 		The retrieved value is stored in the **struct bpf_xfrm_state**
30972d020dd7SQuentin Monnet  * 		pointed by *xfrm_state* and of length *size*.
30982d020dd7SQuentin Monnet  *
30992d020dd7SQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
31002d020dd7SQuentin Monnet  * 		be left at zero.
31012d020dd7SQuentin Monnet  *
31022d020dd7SQuentin Monnet  * 		This helper is available only if the kernel was compiled with
31032d020dd7SQuentin Monnet  * 		**CONFIG_XFRM** configuration option.
31042d020dd7SQuentin Monnet  * 	Return
31052d020dd7SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
3106c195651eSYonghong Song  *
3107bdb7b79bSAndrii Nakryiko  * long bpf_get_stack(void *ctx, void *buf, u32 size, u64 flags)
3108c195651eSYonghong Song  * 	Description
3109c195651eSYonghong Song  * 		Return a user or a kernel stack in bpf program provided buffer.
3110c195651eSYonghong Song  * 		To achieve this, the helper needs *ctx*, which is a pointer
3111c195651eSYonghong Song  * 		to the context on which the tracing program is executed.
3112c195651eSYonghong Song  * 		To store the stacktrace, the bpf program provides *buf* with
3113c195651eSYonghong Song  * 		a nonnegative *size*.
3114c195651eSYonghong Song  *
3115c195651eSYonghong Song  * 		The last argument, *flags*, holds the number of stack frames to
3116c195651eSYonghong Song  * 		skip (from 0 to 255), masked with
3117c195651eSYonghong Song  * 		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
3118c195651eSYonghong Song  * 		the following flags:
3119c195651eSYonghong Song  *
3120c195651eSYonghong Song  * 		**BPF_F_USER_STACK**
3121c195651eSYonghong Song  * 			Collect a user space stack instead of a kernel stack.
3122c195651eSYonghong Song  * 		**BPF_F_USER_BUILD_ID**
3123ca34ce29SDave Marchevsky  * 			Collect (build_id, file_offset) instead of ips for user
3124ca34ce29SDave Marchevsky  * 			stack, only valid if **BPF_F_USER_STACK** is also
3125ca34ce29SDave Marchevsky  * 			specified.
3126ca34ce29SDave Marchevsky  *
3127ca34ce29SDave Marchevsky  * 			*file_offset* is an offset relative to the beginning
3128ca34ce29SDave Marchevsky  * 			of the executable or shared object file backing the vma
3129ca34ce29SDave Marchevsky  * 			which the *ip* falls in. It is *not* an offset relative
3130ca34ce29SDave Marchevsky  * 			to that object's base address. Accordingly, it must be
3131ca34ce29SDave Marchevsky  * 			adjusted by adding (sh_addr - sh_offset), where
3132ca34ce29SDave Marchevsky  * 			sh_{addr,offset} correspond to the executable section
3133ca34ce29SDave Marchevsky  * 			containing *file_offset* in the object, for comparisons
3134ca34ce29SDave Marchevsky  * 			to symbols' st_value to be valid.
3135c195651eSYonghong Song  *
3136c195651eSYonghong Song  * 		**bpf_get_stack**\ () can collect up to
3137c195651eSYonghong Song  * 		**PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
3138c195651eSYonghong Song  * 		to sufficient large buffer size. Note that
3139c195651eSYonghong Song  * 		this limit can be controlled with the **sysctl** program, and
3140c195651eSYonghong Song  * 		that it should be manually increased in order to profile long
3141c195651eSYonghong Song  * 		user stacks (such as stacks for Java programs). To do so, use:
3142c195651eSYonghong Song  *
3143c195651eSYonghong Song  * 		::
3144c195651eSYonghong Song  *
3145c195651eSYonghong Song  * 			# sysctl kernel.perf_event_max_stack=<new value>
3146c195651eSYonghong Song  * 	Return
3147ee2a0988SNamhyung Kim  * 		The non-negative copied *buf* length equal to or less than
3148ee2a0988SNamhyung Kim  * 		*size* on success, or a negative error in case of failure.
31494e1ec56cSDaniel Borkmann  *
3150bdb7b79bSAndrii Nakryiko  * long bpf_skb_load_bytes_relative(const void *skb, u32 offset, void *to, u32 len, u32 start_header)
31514e1ec56cSDaniel Borkmann  * 	Description
31524e1ec56cSDaniel Borkmann  * 		This helper is similar to **bpf_skb_load_bytes**\ () in that
31534e1ec56cSDaniel Borkmann  * 		it provides an easy way to load *len* bytes from *offset*
31544e1ec56cSDaniel Borkmann  * 		from the packet associated to *skb*, into the buffer pointed
31554e1ec56cSDaniel Borkmann  * 		by *to*. The difference to **bpf_skb_load_bytes**\ () is that
31564e1ec56cSDaniel Borkmann  * 		a fifth argument *start_header* exists in order to select a
31574e1ec56cSDaniel Borkmann  * 		base offset to start from. *start_header* can be one of:
31584e1ec56cSDaniel Borkmann  *
31594e1ec56cSDaniel Borkmann  * 		**BPF_HDR_START_MAC**
31604e1ec56cSDaniel Borkmann  * 			Base offset to load data from is *skb*'s mac header.
31614e1ec56cSDaniel Borkmann  * 		**BPF_HDR_START_NET**
31624e1ec56cSDaniel Borkmann  * 			Base offset to load data from is *skb*'s network header.
31634e1ec56cSDaniel Borkmann  *
31644e1ec56cSDaniel Borkmann  * 		In general, "direct packet access" is the preferred method to
31654e1ec56cSDaniel Borkmann  * 		access packet data, however, this helper is in particular useful
31664e1ec56cSDaniel Borkmann  * 		in socket filters where *skb*\ **->data** does not always point
31674e1ec56cSDaniel Borkmann  * 		to the start of the mac header and where "direct packet access"
31684e1ec56cSDaniel Borkmann  * 		is not available.
31694e1ec56cSDaniel Borkmann  * 	Return
31704e1ec56cSDaniel Borkmann  * 		0 on success, or a negative error in case of failure.
31714e1ec56cSDaniel Borkmann  *
3172bdb7b79bSAndrii Nakryiko  * long bpf_fib_lookup(void *ctx, struct bpf_fib_lookup *params, int plen, u32 flags)
317387f5fc7eSDavid Ahern  *	Description
317487f5fc7eSDavid Ahern  *		Do FIB lookup in kernel tables using parameters in *params*.
317587f5fc7eSDavid Ahern  *		If lookup is successful and result shows packet is to be
317687f5fc7eSDavid Ahern  *		forwarded, the neighbor tables are searched for the nexthop.
317787f5fc7eSDavid Ahern  *		If successful (ie., FIB lookup shows forwarding and nexthop
3178fa898d76SDavid Ahern  *		is resolved), the nexthop address is returned in ipv4_dst
3179fa898d76SDavid Ahern  *		or ipv6_dst based on family, smac is set to mac address of
3180fa898d76SDavid Ahern  *		egress device, dmac is set to nexthop mac address, rt_metric
31814c79579bSDavid Ahern  *		is set to metric from route (IPv4/IPv6 only), and ifindex
31824c79579bSDavid Ahern  *		is set to the device index of the nexthop from the FIB lookup.
318387f5fc7eSDavid Ahern  *
318487f5fc7eSDavid Ahern  *		*plen* argument is the size of the passed in struct.
31857a279e93SQuentin Monnet  *		*flags* argument can be a combination of one or more of the
31867a279e93SQuentin Monnet  *		following values:
318787f5fc7eSDavid Ahern  *
31887a279e93SQuentin Monnet  *		**BPF_FIB_LOOKUP_DIRECT**
31897a279e93SQuentin Monnet  *			Do a direct table lookup vs full lookup using FIB
31907a279e93SQuentin Monnet  *			rules.
31918ad77e72SLouis DeLosSantos  *		**BPF_FIB_LOOKUP_TBID**
31928ad77e72SLouis DeLosSantos  *			Used with BPF_FIB_LOOKUP_DIRECT.
31938ad77e72SLouis DeLosSantos  *			Use the routing table ID present in *params*->tbid
31948ad77e72SLouis DeLosSantos  *			for the fib lookup.
31957a279e93SQuentin Monnet  *		**BPF_FIB_LOOKUP_OUTPUT**
31967a279e93SQuentin Monnet  *			Perform lookup from an egress perspective (default is
31977a279e93SQuentin Monnet  *			ingress).
319831de4105SMartin KaFai Lau  *		**BPF_FIB_LOOKUP_SKIP_NEIGH**
319931de4105SMartin KaFai Lau  *			Skip the neighbour table lookup. *params*->dmac
320031de4105SMartin KaFai Lau  *			and *params*->smac will not be set as output. A common
320131de4105SMartin KaFai Lau  *			use case is to call **bpf_redirect_neigh**\ () after
320231de4105SMartin KaFai Lau  *			doing **bpf_fib_lookup**\ ().
320387f5fc7eSDavid Ahern  *
320487f5fc7eSDavid Ahern  *		*ctx* is either **struct xdp_md** for XDP programs or
320587f5fc7eSDavid Ahern  *		**struct sk_buff** tc cls_act programs.
320687f5fc7eSDavid Ahern  *	Return
32074c79579bSDavid Ahern  *		* < 0 if any input argument is invalid
32084c79579bSDavid Ahern  *		*   0 on success (packet is forwarded, nexthop neighbor exists)
32094c79579bSDavid Ahern  *		* > 0 one of **BPF_FIB_LKUP_RET_** codes explaining why the
32102bae79d2SQuentin Monnet  *		  packet is not forwarded or needs assist from full stack
321181110384SJohn Fastabend  *
3212e1850ea9SJesper Dangaard Brouer  *		If lookup fails with BPF_FIB_LKUP_RET_FRAG_NEEDED, then the MTU
3213e1850ea9SJesper Dangaard Brouer  *		was exceeded and output params->mtu_result contains the MTU.
3214e1850ea9SJesper Dangaard Brouer  *
3215bdb7b79bSAndrii Nakryiko  * long bpf_sock_hash_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
321681110384SJohn Fastabend  *	Description
321781110384SJohn Fastabend  *		Add an entry to, or update a sockhash *map* referencing sockets.
321881110384SJohn Fastabend  *		The *skops* is used as a new value for the entry associated to
321981110384SJohn Fastabend  *		*key*. *flags* is one of:
322081110384SJohn Fastabend  *
322181110384SJohn Fastabend  *		**BPF_NOEXIST**
322281110384SJohn Fastabend  *			The entry for *key* must not exist in the map.
322381110384SJohn Fastabend  *		**BPF_EXIST**
322481110384SJohn Fastabend  *			The entry for *key* must already exist in the map.
322581110384SJohn Fastabend  *		**BPF_ANY**
322681110384SJohn Fastabend  *			No condition on the existence of the entry for *key*.
322781110384SJohn Fastabend  *
322881110384SJohn Fastabend  *		If the *map* has eBPF programs (parser and verdict), those will
322981110384SJohn Fastabend  *		be inherited by the socket being added. If the socket is
323081110384SJohn Fastabend  *		already attached to eBPF programs, this results in an error.
323181110384SJohn Fastabend  *	Return
323281110384SJohn Fastabend  *		0 on success, or a negative error in case of failure.
323381110384SJohn Fastabend  *
3234bdb7b79bSAndrii Nakryiko  * long bpf_msg_redirect_hash(struct sk_msg_buff *msg, struct bpf_map *map, void *key, u64 flags)
323581110384SJohn Fastabend  *	Description
323681110384SJohn Fastabend  *		This helper is used in programs implementing policies at the
323781110384SJohn Fastabend  *		socket level. If the message *msg* is allowed to pass (i.e. if
323881110384SJohn Fastabend  *		the verdict eBPF program returns **SK_PASS**), redirect it to
323981110384SJohn Fastabend  *		the socket referenced by *map* (of type
324081110384SJohn Fastabend  *		**BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
324181110384SJohn Fastabend  *		egress interfaces can be used for redirection. The
324281110384SJohn Fastabend  *		**BPF_F_INGRESS** value in *flags* is used to make the
324381110384SJohn Fastabend  *		distinction (ingress path is selected if the flag is present,
324481110384SJohn Fastabend  *		egress path otherwise). This is the only flag supported for now.
324581110384SJohn Fastabend  *	Return
324681110384SJohn Fastabend  *		**SK_PASS** on success, or **SK_DROP** on error.
324781110384SJohn Fastabend  *
3248bdb7b79bSAndrii Nakryiko  * long bpf_sk_redirect_hash(struct sk_buff *skb, struct bpf_map *map, void *key, u64 flags)
324981110384SJohn Fastabend  *	Description
325081110384SJohn Fastabend  *		This helper is used in programs implementing policies at the
325181110384SJohn Fastabend  *		skb socket level. If the sk_buff *skb* is allowed to pass (i.e.
325249f3d12bSJakub Wilk  *		if the verdict eBPF program returns **SK_PASS**), redirect it
325381110384SJohn Fastabend  *		to the socket referenced by *map* (of type
325481110384SJohn Fastabend  *		**BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
325581110384SJohn Fastabend  *		egress interfaces can be used for redirection. The
325681110384SJohn Fastabend  *		**BPF_F_INGRESS** value in *flags* is used to make the
325781110384SJohn Fastabend  *		distinction (ingress path is selected if the flag is present,
325881110384SJohn Fastabend  *		egress otherwise). This is the only flag supported for now.
325981110384SJohn Fastabend  *	Return
326081110384SJohn Fastabend  *		**SK_PASS** on success, or **SK_DROP** on error.
3261fe94cc29SMathieu Xhonneux  *
3262bdb7b79bSAndrii Nakryiko  * long bpf_lwt_push_encap(struct sk_buff *skb, u32 type, void *hdr, u32 len)
3263fe94cc29SMathieu Xhonneux  *	Description
3264fe94cc29SMathieu Xhonneux  *		Encapsulate the packet associated to *skb* within a Layer 3
3265fe94cc29SMathieu Xhonneux  *		protocol header. This header is provided in the buffer at
3266fe94cc29SMathieu Xhonneux  *		address *hdr*, with *len* its size in bytes. *type* indicates
3267fe94cc29SMathieu Xhonneux  *		the protocol of the header and can be one of:
3268fe94cc29SMathieu Xhonneux  *
3269fe94cc29SMathieu Xhonneux  *		**BPF_LWT_ENCAP_SEG6**
3270fe94cc29SMathieu Xhonneux  *			IPv6 encapsulation with Segment Routing Header
3271fe94cc29SMathieu Xhonneux  *			(**struct ipv6_sr_hdr**). *hdr* only contains the SRH,
3272fe94cc29SMathieu Xhonneux  *			the IPv6 header is computed by the kernel.
3273fe94cc29SMathieu Xhonneux  *		**BPF_LWT_ENCAP_SEG6_INLINE**
3274fe94cc29SMathieu Xhonneux  *			Only works if *skb* contains an IPv6 packet. Insert a
3275fe94cc29SMathieu Xhonneux  *			Segment Routing Header (**struct ipv6_sr_hdr**) inside
3276fe94cc29SMathieu Xhonneux  *			the IPv6 header.
32773e0bd37cSPeter Oskolkov  *		**BPF_LWT_ENCAP_IP**
32783e0bd37cSPeter Oskolkov  *			IP encapsulation (GRE/GUE/IPIP/etc). The outer header
32793e0bd37cSPeter Oskolkov  *			must be IPv4 or IPv6, followed by zero or more
328080867c5eSQuentin Monnet  *			additional headers, up to **LWT_BPF_MAX_HEADROOM**
328180867c5eSQuentin Monnet  *			total bytes in all prepended headers. Please note that
328280867c5eSQuentin Monnet  *			if **skb_is_gso**\ (*skb*) is true, no more than two
328380867c5eSQuentin Monnet  *			headers can be prepended, and the inner header, if
328480867c5eSQuentin Monnet  *			present, should be either GRE or UDP/GUE.
32853e0bd37cSPeter Oskolkov  *
328680867c5eSQuentin Monnet  *		**BPF_LWT_ENCAP_SEG6**\ \* types can be called by BPF programs
328780867c5eSQuentin Monnet  *		of type **BPF_PROG_TYPE_LWT_IN**; **BPF_LWT_ENCAP_IP** type can
328880867c5eSQuentin Monnet  *		be called by bpf programs of types **BPF_PROG_TYPE_LWT_IN** and
328980867c5eSQuentin Monnet  *		**BPF_PROG_TYPE_LWT_XMIT**.
3290fe94cc29SMathieu Xhonneux  *
329132e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
3292fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
3293fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
3294fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
3295fe94cc29SMathieu Xhonneux  * 		direct packet access.
3296fe94cc29SMathieu Xhonneux  *	Return
3297fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
3298fe94cc29SMathieu Xhonneux  *
3299bdb7b79bSAndrii Nakryiko  * long bpf_lwt_seg6_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len)
3300fe94cc29SMathieu Xhonneux  *	Description
3301fe94cc29SMathieu Xhonneux  *		Store *len* bytes from address *from* into the packet
3302fe94cc29SMathieu Xhonneux  *		associated to *skb*, at *offset*. Only the flags, tag and TLVs
3303fe94cc29SMathieu Xhonneux  *		inside the outermost IPv6 Segment Routing Header can be
3304fe94cc29SMathieu Xhonneux  *		modified through this helper.
3305fe94cc29SMathieu Xhonneux  *
330632e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
3307fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
3308fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
3309fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
3310fe94cc29SMathieu Xhonneux  * 		direct packet access.
3311fe94cc29SMathieu Xhonneux  *	Return
3312fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
3313fe94cc29SMathieu Xhonneux  *
3314bdb7b79bSAndrii Nakryiko  * long bpf_lwt_seg6_adjust_srh(struct sk_buff *skb, u32 offset, s32 delta)
3315fe94cc29SMathieu Xhonneux  *	Description
3316fe94cc29SMathieu Xhonneux  *		Adjust the size allocated to TLVs in the outermost IPv6
3317fe94cc29SMathieu Xhonneux  *		Segment Routing Header contained in the packet associated to
3318fe94cc29SMathieu Xhonneux  *		*skb*, at position *offset* by *delta* bytes. Only offsets
3319fe94cc29SMathieu Xhonneux  *		after the segments are accepted. *delta* can be as well
3320fe94cc29SMathieu Xhonneux  *		positive (growing) as negative (shrinking).
3321fe94cc29SMathieu Xhonneux  *
332232e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
3323fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
3324fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
3325fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
3326fe94cc29SMathieu Xhonneux  * 		direct packet access.
3327fe94cc29SMathieu Xhonneux  *	Return
3328fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
3329fe94cc29SMathieu Xhonneux  *
3330bdb7b79bSAndrii Nakryiko  * long bpf_lwt_seg6_action(struct sk_buff *skb, u32 action, void *param, u32 param_len)
3331fe94cc29SMathieu Xhonneux  *	Description
3332fe94cc29SMathieu Xhonneux  *		Apply an IPv6 Segment Routing action of type *action* to the
3333fe94cc29SMathieu Xhonneux  *		packet associated to *skb*. Each action takes a parameter
3334fe94cc29SMathieu Xhonneux  *		contained at address *param*, and of length *param_len* bytes.
3335fe94cc29SMathieu Xhonneux  *		*action* can be one of:
3336fe94cc29SMathieu Xhonneux  *
3337fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_X**
3338fe94cc29SMathieu Xhonneux  *			End.X action: Endpoint with Layer-3 cross-connect.
3339fe94cc29SMathieu Xhonneux  *			Type of *param*: **struct in6_addr**.
3340fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_T**
3341fe94cc29SMathieu Xhonneux  *			End.T action: Endpoint with specific IPv6 table lookup.
3342fe94cc29SMathieu Xhonneux  *			Type of *param*: **int**.
3343fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_B6**
3344fe94cc29SMathieu Xhonneux  *			End.B6 action: Endpoint bound to an SRv6 policy.
334580867c5eSQuentin Monnet  *			Type of *param*: **struct ipv6_sr_hdr**.
3346fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_B6_ENCAP**
3347fe94cc29SMathieu Xhonneux  *			End.B6.Encap action: Endpoint bound to an SRv6
3348fe94cc29SMathieu Xhonneux  *			encapsulation policy.
334980867c5eSQuentin Monnet  *			Type of *param*: **struct ipv6_sr_hdr**.
3350fe94cc29SMathieu Xhonneux  *
335132e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
3352fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
3353fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
3354fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
3355fe94cc29SMathieu Xhonneux  * 		direct packet access.
3356fe94cc29SMathieu Xhonneux  *	Return
3357fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
3358f4364dcfSSean Young  *
3359bdb7b79bSAndrii Nakryiko  * long bpf_rc_repeat(void *ctx)
336062369db2SQuentin Monnet  *	Description
336162369db2SQuentin Monnet  *		This helper is used in programs implementing IR decoding, to
336262369db2SQuentin Monnet  *		report a successfully decoded repeat key message. This delays
336362369db2SQuentin Monnet  *		the generation of a key up event for previously generated
336462369db2SQuentin Monnet  *		key down event.
336562369db2SQuentin Monnet  *
336662369db2SQuentin Monnet  *		Some IR protocols like NEC have a special IR message for
336762369db2SQuentin Monnet  *		repeating last button, for when a button is held down.
336862369db2SQuentin Monnet  *
336962369db2SQuentin Monnet  *		The *ctx* should point to the lirc sample as passed into
337062369db2SQuentin Monnet  *		the program.
337162369db2SQuentin Monnet  *
337262369db2SQuentin Monnet  *		This helper is only available is the kernel was compiled with
337362369db2SQuentin Monnet  *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
337462369db2SQuentin Monnet  *		"**y**".
337562369db2SQuentin Monnet  *	Return
337662369db2SQuentin Monnet  *		0
337762369db2SQuentin Monnet  *
3378bdb7b79bSAndrii Nakryiko  * long bpf_rc_keydown(void *ctx, u32 protocol, u64 scancode, u32 toggle)
3379f4364dcfSSean Young  *	Description
3380f4364dcfSSean Young  *		This helper is used in programs implementing IR decoding, to
3381f4364dcfSSean Young  *		report a successfully decoded key press with *scancode*,
3382f4364dcfSSean Young  *		*toggle* value in the given *protocol*. The scancode will be
3383f4364dcfSSean Young  *		translated to a keycode using the rc keymap, and reported as
3384f4364dcfSSean Young  *		an input key down event. After a period a key up event is
3385f4364dcfSSean Young  *		generated. This period can be extended by calling either
338690b1023fSQuentin Monnet  *		**bpf_rc_keydown**\ () again with the same values, or calling
338790b1023fSQuentin Monnet  *		**bpf_rc_repeat**\ ().
3388f4364dcfSSean Young  *
3389f4364dcfSSean Young  *		Some protocols include a toggle bit, in case the button was
3390f4364dcfSSean Young  *		released and pressed again between consecutive scancodes.
3391f4364dcfSSean Young  *
3392f4364dcfSSean Young  *		The *ctx* should point to the lirc sample as passed into
3393f4364dcfSSean Young  *		the program.
3394f4364dcfSSean Young  *
3395f4364dcfSSean Young  *		The *protocol* is the decoded protocol number (see
3396f4364dcfSSean Young  *		**enum rc_proto** for some predefined values).
3397f4364dcfSSean Young  *
3398f4364dcfSSean Young  *		This helper is only available is the kernel was compiled with
3399f4364dcfSSean Young  *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
3400f4364dcfSSean Young  *		"**y**".
3401f4364dcfSSean Young  *	Return
3402f4364dcfSSean Young  *		0
3403f4364dcfSSean Young  *
340462369db2SQuentin Monnet  * u64 bpf_skb_cgroup_id(struct sk_buff *skb)
3405cb20b08eSDaniel Borkmann  * 	Description
3406cb20b08eSDaniel Borkmann  * 		Return the cgroup v2 id of the socket associated with the *skb*.
3407cb20b08eSDaniel Borkmann  * 		This is roughly similar to the **bpf_get_cgroup_classid**\ ()
3408cb20b08eSDaniel Borkmann  * 		helper for cgroup v1 by providing a tag resp. identifier that
3409cb20b08eSDaniel Borkmann  * 		can be matched on or used for map lookups e.g. to implement
3410cb20b08eSDaniel Borkmann  * 		policy. The cgroup v2 id of a given path in the hierarchy is
3411cb20b08eSDaniel Borkmann  * 		exposed in user space through the f_handle API in order to get
3412cb20b08eSDaniel Borkmann  * 		to the same 64-bit id.
3413cb20b08eSDaniel Borkmann  *
3414cb20b08eSDaniel Borkmann  * 		This helper can be used on TC egress path, but not on ingress,
3415cb20b08eSDaniel Borkmann  * 		and is available only if the kernel was compiled with the
3416cb20b08eSDaniel Borkmann  * 		**CONFIG_SOCK_CGROUP_DATA** configuration option.
3417cb20b08eSDaniel Borkmann  * 	Return
3418cb20b08eSDaniel Borkmann  * 		The id is returned or 0 in case the id could not be retrieved.
3419bf6fa2c8SYonghong Song  *
3420bf6fa2c8SYonghong Song  * u64 bpf_get_current_cgroup_id(void)
3421e40fbbf0SUsama Arif  * 	Description
3422e40fbbf0SUsama Arif  * 		Get the current cgroup id based on the cgroup within which
3423e40fbbf0SUsama Arif  * 		the current task is running.
3424bf6fa2c8SYonghong Song  * 	Return
3425bf6fa2c8SYonghong Song  * 		A 64-bit integer containing the current cgroup id based
3426bf6fa2c8SYonghong Song  * 		on the cgroup within which the current task is running.
3427cd339431SRoman Gushchin  *
342862369db2SQuentin Monnet  * void *bpf_get_local_storage(void *map, u64 flags)
3429cd339431SRoman Gushchin  *	Description
3430cd339431SRoman Gushchin  *		Get the pointer to the local storage area.
3431cd339431SRoman Gushchin  *		The type and the size of the local storage is defined
3432cd339431SRoman Gushchin  *		by the *map* argument.
3433cd339431SRoman Gushchin  *		The *flags* meaning is specific for each map type,
3434cd339431SRoman Gushchin  *		and has to be 0 for cgroup local storage.
3435cd339431SRoman Gushchin  *
343690b1023fSQuentin Monnet  *		Depending on the BPF program type, a local storage area
343790b1023fSQuentin Monnet  *		can be shared between multiple instances of the BPF program,
3438cd339431SRoman Gushchin  *		running simultaneously.
3439cd339431SRoman Gushchin  *
3440cd339431SRoman Gushchin  *		A user should care about the synchronization by himself.
344191c960b0SBrendan Jackman  *		For example, by using the **BPF_ATOMIC** instructions to alter
3442cd339431SRoman Gushchin  *		the shared data.
3443cd339431SRoman Gushchin  *	Return
344490b1023fSQuentin Monnet  *		A pointer to the local storage area.
34452dbb9b9eSMartin KaFai Lau  *
3446bdb7b79bSAndrii Nakryiko  * long bpf_sk_select_reuseport(struct sk_reuseport_md *reuse, struct bpf_map *map, void *key, u64 flags)
34472dbb9b9eSMartin KaFai Lau  *	Description
344890b1023fSQuentin Monnet  *		Select a **SO_REUSEPORT** socket from a
3449f170acdaSKuniyuki Iwashima  *		**BPF_MAP_TYPE_REUSEPORT_SOCKARRAY** *map*.
345090b1023fSQuentin Monnet  *		It checks the selected socket is matching the incoming
345190b1023fSQuentin Monnet  *		request in the socket buffer.
34522dbb9b9eSMartin KaFai Lau  *	Return
34532dbb9b9eSMartin KaFai Lau  *		0 on success, or a negative error in case of failure.
34546acc9b43SJoe Stringer  *
345562369db2SQuentin Monnet  * u64 bpf_skb_ancestor_cgroup_id(struct sk_buff *skb, int ancestor_level)
345662369db2SQuentin Monnet  *	Description
345762369db2SQuentin Monnet  *		Return id of cgroup v2 that is ancestor of cgroup associated
345862369db2SQuentin Monnet  *		with the *skb* at the *ancestor_level*.  The root cgroup is at
345962369db2SQuentin Monnet  *		*ancestor_level* zero and each step down the hierarchy
346062369db2SQuentin Monnet  *		increments the level. If *ancestor_level* == level of cgroup
346162369db2SQuentin Monnet  *		associated with *skb*, then return value will be same as that
346262369db2SQuentin Monnet  *		of **bpf_skb_cgroup_id**\ ().
346362369db2SQuentin Monnet  *
346462369db2SQuentin Monnet  *		The helper is useful to implement policies based on cgroups
346562369db2SQuentin Monnet  *		that are upper in hierarchy than immediate cgroup associated
346662369db2SQuentin Monnet  *		with *skb*.
346762369db2SQuentin Monnet  *
346862369db2SQuentin Monnet  *		The format of returned id and helper limitations are same as in
346962369db2SQuentin Monnet  *		**bpf_skb_cgroup_id**\ ().
347062369db2SQuentin Monnet  *	Return
347162369db2SQuentin Monnet  *		The id is returned or 0 in case the id could not be retrieved.
347262369db2SQuentin Monnet  *
3473f71c6143SJoe Stringer  * struct bpf_sock *bpf_sk_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
34746acc9b43SJoe Stringer  *	Description
34756acc9b43SJoe Stringer  *		Look for TCP socket matching *tuple*, optionally in a child
34766acc9b43SJoe Stringer  *		network namespace *netns*. The return value must be checked,
347790b1023fSQuentin Monnet  *		and if non-**NULL**, released via **bpf_sk_release**\ ().
34786acc9b43SJoe Stringer  *
34796acc9b43SJoe Stringer  *		The *ctx* should point to the context of the program, such as
34806acc9b43SJoe Stringer  *		the skb or socket (depending on the hook in use). This is used
34816acc9b43SJoe Stringer  *		to determine the base network namespace for the lookup.
34826acc9b43SJoe Stringer  *
34836acc9b43SJoe Stringer  *		*tuple_size* must be one of:
34846acc9b43SJoe Stringer  *
34856acc9b43SJoe Stringer  *		**sizeof**\ (*tuple*\ **->ipv4**)
34866acc9b43SJoe Stringer  *			Look for an IPv4 socket.
34876acc9b43SJoe Stringer  *		**sizeof**\ (*tuple*\ **->ipv6**)
34886acc9b43SJoe Stringer  *			Look for an IPv6 socket.
34896acc9b43SJoe Stringer  *
3490f71c6143SJoe Stringer  *		If the *netns* is a negative signed 32-bit integer, then the
3491bfdfa517SRandy Dunlap  *		socket lookup table in the netns associated with the *ctx*
3492f71c6143SJoe Stringer  *		will be used. For the TC hooks, this is the netns of the device
3493f71c6143SJoe Stringer  *		in the skb. For socket hooks, this is the netns of the socket.
3494f71c6143SJoe Stringer  *		If *netns* is any other signed 32-bit value greater than or
3495f71c6143SJoe Stringer  *		equal to zero then it specifies the ID of the netns relative to
3496f71c6143SJoe Stringer  *		the netns associated with the *ctx*. *netns* values beyond the
3497f71c6143SJoe Stringer  *		range of 32-bit integers are reserved for future use.
34986acc9b43SJoe Stringer  *
34996acc9b43SJoe Stringer  *		All values for *flags* are reserved for future usage, and must
35006acc9b43SJoe Stringer  *		be left at zero.
35016acc9b43SJoe Stringer  *
35026acc9b43SJoe Stringer  *		This helper is available only if the kernel was compiled with
35036acc9b43SJoe Stringer  *		**CONFIG_NET** configuration option.
35046acc9b43SJoe Stringer  *	Return
35050bd72117SDaniel Borkmann  *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
35060bd72117SDaniel Borkmann  *		For sockets with reuseport option, the **struct bpf_sock**
350780867c5eSQuentin Monnet  *		result is from *reuse*\ **->socks**\ [] using the hash of the
350880867c5eSQuentin Monnet  *		tuple.
35096acc9b43SJoe Stringer  *
3510f71c6143SJoe Stringer  * struct bpf_sock *bpf_sk_lookup_udp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
35116acc9b43SJoe Stringer  *	Description
35126acc9b43SJoe Stringer  *		Look for UDP socket matching *tuple*, optionally in a child
35136acc9b43SJoe Stringer  *		network namespace *netns*. The return value must be checked,
351490b1023fSQuentin Monnet  *		and if non-**NULL**, released via **bpf_sk_release**\ ().
35156acc9b43SJoe Stringer  *
35166acc9b43SJoe Stringer  *		The *ctx* should point to the context of the program, such as
35176acc9b43SJoe Stringer  *		the skb or socket (depending on the hook in use). This is used
35186acc9b43SJoe Stringer  *		to determine the base network namespace for the lookup.
35196acc9b43SJoe Stringer  *
35206acc9b43SJoe Stringer  *		*tuple_size* must be one of:
35216acc9b43SJoe Stringer  *
35226acc9b43SJoe Stringer  *		**sizeof**\ (*tuple*\ **->ipv4**)
35236acc9b43SJoe Stringer  *			Look for an IPv4 socket.
35246acc9b43SJoe Stringer  *		**sizeof**\ (*tuple*\ **->ipv6**)
35256acc9b43SJoe Stringer  *			Look for an IPv6 socket.
35266acc9b43SJoe Stringer  *
3527f71c6143SJoe Stringer  *		If the *netns* is a negative signed 32-bit integer, then the
3528bfdfa517SRandy Dunlap  *		socket lookup table in the netns associated with the *ctx*
3529f71c6143SJoe Stringer  *		will be used. For the TC hooks, this is the netns of the device
3530f71c6143SJoe Stringer  *		in the skb. For socket hooks, this is the netns of the socket.
3531f71c6143SJoe Stringer  *		If *netns* is any other signed 32-bit value greater than or
3532f71c6143SJoe Stringer  *		equal to zero then it specifies the ID of the netns relative to
3533f71c6143SJoe Stringer  *		the netns associated with the *ctx*. *netns* values beyond the
3534f71c6143SJoe Stringer  *		range of 32-bit integers are reserved for future use.
35356acc9b43SJoe Stringer  *
35366acc9b43SJoe Stringer  *		All values for *flags* are reserved for future usage, and must
35376acc9b43SJoe Stringer  *		be left at zero.
35386acc9b43SJoe Stringer  *
35396acc9b43SJoe Stringer  *		This helper is available only if the kernel was compiled with
35406acc9b43SJoe Stringer  *		**CONFIG_NET** configuration option.
35416acc9b43SJoe Stringer  *	Return
35420bd72117SDaniel Borkmann  *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
35430bd72117SDaniel Borkmann  *		For sockets with reuseport option, the **struct bpf_sock**
354480867c5eSQuentin Monnet  *		result is from *reuse*\ **->socks**\ [] using the hash of the
354580867c5eSQuentin Monnet  *		tuple.
35466acc9b43SJoe Stringer  *
3547a5fa25adSMartin KaFai Lau  * long bpf_sk_release(void *sock)
35486acc9b43SJoe Stringer  *	Description
354990b1023fSQuentin Monnet  *		Release the reference held by *sock*. *sock* must be a
355090b1023fSQuentin Monnet  *		non-**NULL** pointer that was returned from
355190b1023fSQuentin Monnet  *		**bpf_sk_lookup_xxx**\ ().
355290b1023fSQuentin Monnet  *	Return
355390b1023fSQuentin Monnet  *		0 on success, or a negative error in case of failure.
355490b1023fSQuentin Monnet  *
3555bdb7b79bSAndrii Nakryiko  * long bpf_map_push_elem(struct bpf_map *map, const void *value, u64 flags)
355662369db2SQuentin Monnet  * 	Description
355762369db2SQuentin Monnet  * 		Push an element *value* in *map*. *flags* is one of:
355862369db2SQuentin Monnet  *
355962369db2SQuentin Monnet  * 		**BPF_EXIST**
356062369db2SQuentin Monnet  * 			If the queue/stack is full, the oldest element is
356162369db2SQuentin Monnet  * 			removed to make room for this.
356262369db2SQuentin Monnet  * 	Return
356362369db2SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
356462369db2SQuentin Monnet  *
3565bdb7b79bSAndrii Nakryiko  * long bpf_map_pop_elem(struct bpf_map *map, void *value)
356690b1023fSQuentin Monnet  * 	Description
356790b1023fSQuentin Monnet  * 		Pop an element from *map*.
356890b1023fSQuentin Monnet  * 	Return
356990b1023fSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
357090b1023fSQuentin Monnet  *
3571bdb7b79bSAndrii Nakryiko  * long bpf_map_peek_elem(struct bpf_map *map, void *value)
357290b1023fSQuentin Monnet  * 	Description
357390b1023fSQuentin Monnet  * 		Get an element from *map* without removing it.
35746acc9b43SJoe Stringer  * 	Return
35756acc9b43SJoe Stringer  * 		0 on success, or a negative error in case of failure.
35766fff607eSJohn Fastabend  *
3577bdb7b79bSAndrii Nakryiko  * long bpf_msg_push_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)
35786fff607eSJohn Fastabend  *	Description
357990b1023fSQuentin Monnet  *		For socket policies, insert *len* bytes into *msg* at offset
35806fff607eSJohn Fastabend  *		*start*.
35816fff607eSJohn Fastabend  *
35826fff607eSJohn Fastabend  *		If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
358390b1023fSQuentin Monnet  *		*msg* it may want to insert metadata or options into the *msg*.
35846fff607eSJohn Fastabend  *		This can later be read and used by any of the lower layer BPF
35856fff607eSJohn Fastabend  *		hooks.
35866fff607eSJohn Fastabend  *
35876fff607eSJohn Fastabend  *		This helper may fail if under memory pressure (a malloc
35886fff607eSJohn Fastabend  *		fails) in these cases BPF programs will get an appropriate
35896fff607eSJohn Fastabend  *		error and BPF programs will need to handle them.
35906fff607eSJohn Fastabend  *	Return
35916fff607eSJohn Fastabend  *		0 on success, or a negative error in case of failure.
35927246d8edSJohn Fastabend  *
3593bdb7b79bSAndrii Nakryiko  * long bpf_msg_pop_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)
35947246d8edSJohn Fastabend  *	Description
35955f0e5412SAndrii Nakryiko  *		Will remove *len* bytes from a *msg* starting at byte *start*.
35967246d8edSJohn Fastabend  *		This may result in **ENOMEM** errors under certain situations if
35977246d8edSJohn Fastabend  *		an allocation and copy are required due to a full ring buffer.
35987246d8edSJohn Fastabend  *		However, the helper will try to avoid doing the allocation
35997246d8edSJohn Fastabend  *		if possible. Other errors can occur if input parameters are
360090b1023fSQuentin Monnet  *		invalid either due to *start* byte not being valid part of *msg*
36017246d8edSJohn Fastabend  *		payload and/or *pop* value being to large.
36027246d8edSJohn Fastabend  *	Return
360390b1023fSQuentin Monnet  *		0 on success, or a negative error in case of failure.
360401d3240aSSean Young  *
3605bdb7b79bSAndrii Nakryiko  * long bpf_rc_pointer_rel(void *ctx, s32 rel_x, s32 rel_y)
360601d3240aSSean Young  *	Description
360701d3240aSSean Young  *		This helper is used in programs implementing IR decoding, to
360801d3240aSSean Young  *		report a successfully decoded pointer movement.
360901d3240aSSean Young  *
361001d3240aSSean Young  *		The *ctx* should point to the lirc sample as passed into
361101d3240aSSean Young  *		the program.
361201d3240aSSean Young  *
361301d3240aSSean Young  *		This helper is only available is the kernel was compiled with
361401d3240aSSean Young  *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
361501d3240aSSean Young  *		"**y**".
361601d3240aSSean Young  *	Return
361701d3240aSSean Young  *		0
361846f8bc92SMartin KaFai Lau  *
3619bdb7b79bSAndrii Nakryiko  * long bpf_spin_lock(struct bpf_spin_lock *lock)
36200eb09785SQuentin Monnet  *	Description
36210eb09785SQuentin Monnet  *		Acquire a spinlock represented by the pointer *lock*, which is
36220eb09785SQuentin Monnet  *		stored as part of a value of a map. Taking the lock allows to
36230eb09785SQuentin Monnet  *		safely update the rest of the fields in that value. The
36240eb09785SQuentin Monnet  *		spinlock can (and must) later be released with a call to
36250eb09785SQuentin Monnet  *		**bpf_spin_unlock**\ (\ *lock*\ ).
36260eb09785SQuentin Monnet  *
36270eb09785SQuentin Monnet  *		Spinlocks in BPF programs come with a number of restrictions
36280eb09785SQuentin Monnet  *		and constraints:
36290eb09785SQuentin Monnet  *
36300eb09785SQuentin Monnet  *		* **bpf_spin_lock** objects are only allowed inside maps of
36310eb09785SQuentin Monnet  *		  types **BPF_MAP_TYPE_HASH** and **BPF_MAP_TYPE_ARRAY** (this
36320eb09785SQuentin Monnet  *		  list could be extended in the future).
36330eb09785SQuentin Monnet  *		* BTF description of the map is mandatory.
36340eb09785SQuentin Monnet  *		* The BPF program can take ONE lock at a time, since taking two
36350eb09785SQuentin Monnet  *		  or more could cause dead locks.
36360eb09785SQuentin Monnet  *		* Only one **struct bpf_spin_lock** is allowed per map element.
36370eb09785SQuentin Monnet  *		* When the lock is taken, calls (either BPF to BPF or helpers)
36380eb09785SQuentin Monnet  *		  are not allowed.
36390eb09785SQuentin Monnet  *		* The **BPF_LD_ABS** and **BPF_LD_IND** instructions are not
36400eb09785SQuentin Monnet  *		  allowed inside a spinlock-ed region.
36410eb09785SQuentin Monnet  *		* The BPF program MUST call **bpf_spin_unlock**\ () to release
36420eb09785SQuentin Monnet  *		  the lock, on all execution paths, before it returns.
36430eb09785SQuentin Monnet  *		* The BPF program can access **struct bpf_spin_lock** only via
36440eb09785SQuentin Monnet  *		  the **bpf_spin_lock**\ () and **bpf_spin_unlock**\ ()
36450eb09785SQuentin Monnet  *		  helpers. Loading or storing data into the **struct
36460eb09785SQuentin Monnet  *		  bpf_spin_lock** *lock*\ **;** field of a map is not allowed.
36470eb09785SQuentin Monnet  *		* To use the **bpf_spin_lock**\ () helper, the BTF description
36480eb09785SQuentin Monnet  *		  of the map value must be a struct and have **struct
36490eb09785SQuentin Monnet  *		  bpf_spin_lock** *anyname*\ **;** field at the top level.
36500eb09785SQuentin Monnet  *		  Nested lock inside another struct is not allowed.
36510eb09785SQuentin Monnet  *		* The **struct bpf_spin_lock** *lock* field in a map value must
36520eb09785SQuentin Monnet  *		  be aligned on a multiple of 4 bytes in that value.
36530eb09785SQuentin Monnet  *		* Syscall with command **BPF_MAP_LOOKUP_ELEM** does not copy
36540eb09785SQuentin Monnet  *		  the **bpf_spin_lock** field to user space.
36550eb09785SQuentin Monnet  *		* Syscall with command **BPF_MAP_UPDATE_ELEM**, or update from
36560eb09785SQuentin Monnet  *		  a BPF program, do not update the **bpf_spin_lock** field.
36570eb09785SQuentin Monnet  *		* **bpf_spin_lock** cannot be on the stack or inside a
36580eb09785SQuentin Monnet  *		  networking packet (it can only be inside of a map values).
36590eb09785SQuentin Monnet  *		* **bpf_spin_lock** is available to root only.
36600eb09785SQuentin Monnet  *		* Tracing programs and socket filter programs cannot use
36610eb09785SQuentin Monnet  *		  **bpf_spin_lock**\ () due to insufficient preemption checks
36620eb09785SQuentin Monnet  *		  (but this may change in the future).
36630eb09785SQuentin Monnet  *		* **bpf_spin_lock** is not allowed in inner maps of map-in-map.
36640eb09785SQuentin Monnet  *	Return
36650eb09785SQuentin Monnet  *		0
36660eb09785SQuentin Monnet  *
3667bdb7b79bSAndrii Nakryiko  * long bpf_spin_unlock(struct bpf_spin_lock *lock)
36680eb09785SQuentin Monnet  *	Description
36690eb09785SQuentin Monnet  *		Release the *lock* previously locked by a call to
36700eb09785SQuentin Monnet  *		**bpf_spin_lock**\ (\ *lock*\ ).
36710eb09785SQuentin Monnet  *	Return
36720eb09785SQuentin Monnet  *		0
36730eb09785SQuentin Monnet  *
367446f8bc92SMartin KaFai Lau  * struct bpf_sock *bpf_sk_fullsock(struct bpf_sock *sk)
367546f8bc92SMartin KaFai Lau  *	Description
367646f8bc92SMartin KaFai Lau  *		This helper gets a **struct bpf_sock** pointer such
367762369db2SQuentin Monnet  *		that all the fields in this **bpf_sock** can be accessed.
367846f8bc92SMartin KaFai Lau  *	Return
367962369db2SQuentin Monnet  *		A **struct bpf_sock** pointer on success, or **NULL** in
368046f8bc92SMartin KaFai Lau  *		case of failure.
3681655a51e5SMartin KaFai Lau  *
3682655a51e5SMartin KaFai Lau  * struct bpf_tcp_sock *bpf_tcp_sock(struct bpf_sock *sk)
3683655a51e5SMartin KaFai Lau  *	Description
3684655a51e5SMartin KaFai Lau  *		This helper gets a **struct bpf_tcp_sock** pointer from a
3685655a51e5SMartin KaFai Lau  *		**struct bpf_sock** pointer.
3686655a51e5SMartin KaFai Lau  *	Return
368762369db2SQuentin Monnet  *		A **struct bpf_tcp_sock** pointer on success, or **NULL** in
3688655a51e5SMartin KaFai Lau  *		case of failure.
3689f7c917baSbrakmo  *
3690bdb7b79bSAndrii Nakryiko  * long bpf_skb_ecn_set_ce(struct sk_buff *skb)
3691f7c917baSbrakmo  *	Description
369262369db2SQuentin Monnet  *		Set ECN (Explicit Congestion Notification) field of IP header
369362369db2SQuentin Monnet  *		to **CE** (Congestion Encountered) if current value is **ECT**
369462369db2SQuentin Monnet  *		(ECN Capable Transport). Otherwise, do nothing. Works with IPv6
369562369db2SQuentin Monnet  *		and IPv4.
3696f7c917baSbrakmo  *	Return
369762369db2SQuentin Monnet  *		1 if the **CE** flag is set (either by the current helper call
369862369db2SQuentin Monnet  *		or because it was already present), 0 if it is not set.
3699dbafd7ddSMartin KaFai Lau  *
3700dbafd7ddSMartin KaFai Lau  * struct bpf_sock *bpf_get_listener_sock(struct bpf_sock *sk)
3701dbafd7ddSMartin KaFai Lau  *	Description
370262369db2SQuentin Monnet  *		Return a **struct bpf_sock** pointer in **TCP_LISTEN** state.
370362369db2SQuentin Monnet  *		**bpf_sk_release**\ () is unnecessary and not allowed.
3704dbafd7ddSMartin KaFai Lau  *	Return
370562369db2SQuentin Monnet  *		A **struct bpf_sock** pointer on success, or **NULL** in
3706dbafd7ddSMartin KaFai Lau  *		case of failure.
3707edbf8c01SLorenz Bauer  *
3708edbf8c01SLorenz Bauer  * struct bpf_sock *bpf_skc_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
3709edbf8c01SLorenz Bauer  *	Description
3710edbf8c01SLorenz Bauer  *		Look for TCP socket matching *tuple*, optionally in a child
3711edbf8c01SLorenz Bauer  *		network namespace *netns*. The return value must be checked,
3712edbf8c01SLorenz Bauer  *		and if non-**NULL**, released via **bpf_sk_release**\ ().
3713edbf8c01SLorenz Bauer  *
371480867c5eSQuentin Monnet  *		This function is identical to **bpf_sk_lookup_tcp**\ (), except
371580867c5eSQuentin Monnet  *		that it also returns timewait or request sockets. Use
371680867c5eSQuentin Monnet  *		**bpf_sk_fullsock**\ () or **bpf_tcp_sock**\ () to access the
371780867c5eSQuentin Monnet  *		full structure.
3718edbf8c01SLorenz Bauer  *
3719edbf8c01SLorenz Bauer  *		This helper is available only if the kernel was compiled with
3720edbf8c01SLorenz Bauer  *		**CONFIG_NET** configuration option.
3721edbf8c01SLorenz Bauer  *	Return
3722edbf8c01SLorenz Bauer  *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
3723edbf8c01SLorenz Bauer  *		For sockets with reuseport option, the **struct bpf_sock**
372480867c5eSQuentin Monnet  *		result is from *reuse*\ **->socks**\ [] using the hash of the
372580867c5eSQuentin Monnet  *		tuple.
372639904084SLorenz Bauer  *
3727c0df236eSMartin KaFai Lau  * long bpf_tcp_check_syncookie(void *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
372839904084SLorenz Bauer  * 	Description
372980867c5eSQuentin Monnet  * 		Check whether *iph* and *th* contain a valid SYN cookie ACK for
373080867c5eSQuentin Monnet  * 		the listening socket in *sk*.
373139904084SLorenz Bauer  *
373280867c5eSQuentin Monnet  * 		*iph* points to the start of the IPv4 or IPv6 header, while
373380867c5eSQuentin Monnet  * 		*iph_len* contains **sizeof**\ (**struct iphdr**) or
3734ac80287aSMaxim Mikityanskiy  * 		**sizeof**\ (**struct ipv6hdr**).
373539904084SLorenz Bauer  *
373680867c5eSQuentin Monnet  * 		*th* points to the start of the TCP header, while *th_len*
3737ac80287aSMaxim Mikityanskiy  *		contains the length of the TCP header (at least
3738ac80287aSMaxim Mikityanskiy  *		**sizeof**\ (**struct tcphdr**)).
373939904084SLorenz Bauer  * 	Return
374080867c5eSQuentin Monnet  * 		0 if *iph* and *th* are a valid SYN cookie ACK, or a negative
374180867c5eSQuentin Monnet  * 		error otherwise.
3742808649fbSAndrey Ignatov  *
3743bdb7b79bSAndrii Nakryiko  * long bpf_sysctl_get_name(struct bpf_sysctl *ctx, char *buf, size_t buf_len, u64 flags)
3744808649fbSAndrey Ignatov  *	Description
3745808649fbSAndrey Ignatov  *		Get name of sysctl in /proc/sys/ and copy it into provided by
3746808649fbSAndrey Ignatov  *		program buffer *buf* of size *buf_len*.
3747808649fbSAndrey Ignatov  *
3748808649fbSAndrey Ignatov  *		The buffer is always NUL terminated, unless it's zero-sized.
3749808649fbSAndrey Ignatov  *
3750808649fbSAndrey Ignatov  *		If *flags* is zero, full name (e.g. "net/ipv4/tcp_mem") is
3751808649fbSAndrey Ignatov  *		copied. Use **BPF_F_SYSCTL_BASE_NAME** flag to copy base name
3752808649fbSAndrey Ignatov  *		only (e.g. "tcp_mem").
3753808649fbSAndrey Ignatov  *	Return
3754808649fbSAndrey Ignatov  *		Number of character copied (not including the trailing NUL).
3755808649fbSAndrey Ignatov  *
3756808649fbSAndrey Ignatov  *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
3757808649fbSAndrey Ignatov  *		truncated name in this case).
37581d11b301SAndrey Ignatov  *
3759bdb7b79bSAndrii Nakryiko  * long bpf_sysctl_get_current_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)
37601d11b301SAndrey Ignatov  *	Description
37611d11b301SAndrey Ignatov  *		Get current value of sysctl as it is presented in /proc/sys
37621d11b301SAndrey Ignatov  *		(incl. newline, etc), and copy it as a string into provided
37631d11b301SAndrey Ignatov  *		by program buffer *buf* of size *buf_len*.
37641d11b301SAndrey Ignatov  *
37651d11b301SAndrey Ignatov  *		The whole value is copied, no matter what file position user
37661d11b301SAndrey Ignatov  *		space issued e.g. sys_read at.
37671d11b301SAndrey Ignatov  *
37681d11b301SAndrey Ignatov  *		The buffer is always NUL terminated, unless it's zero-sized.
37691d11b301SAndrey Ignatov  *	Return
37701d11b301SAndrey Ignatov  *		Number of character copied (not including the trailing NUL).
37711d11b301SAndrey Ignatov  *
37721d11b301SAndrey Ignatov  *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
37731d11b301SAndrey Ignatov  *		truncated name in this case).
37741d11b301SAndrey Ignatov  *
37751d11b301SAndrey Ignatov  *		**-EINVAL** if current value was unavailable, e.g. because
37761d11b301SAndrey Ignatov  *		sysctl is uninitialized and read returns -EIO for it.
37774e63acdfSAndrey Ignatov  *
3778bdb7b79bSAndrii Nakryiko  * long bpf_sysctl_get_new_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)
37794e63acdfSAndrey Ignatov  *	Description
37804e63acdfSAndrey Ignatov  *		Get new value being written by user space to sysctl (before
37814e63acdfSAndrey Ignatov  *		the actual write happens) and copy it as a string into
37824e63acdfSAndrey Ignatov  *		provided by program buffer *buf* of size *buf_len*.
37834e63acdfSAndrey Ignatov  *
37844e63acdfSAndrey Ignatov  *		User space may write new value at file position > 0.
37854e63acdfSAndrey Ignatov  *
37864e63acdfSAndrey Ignatov  *		The buffer is always NUL terminated, unless it's zero-sized.
37874e63acdfSAndrey Ignatov  *	Return
37884e63acdfSAndrey Ignatov  *		Number of character copied (not including the trailing NUL).
37894e63acdfSAndrey Ignatov  *
37904e63acdfSAndrey Ignatov  *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
37914e63acdfSAndrey Ignatov  *		truncated name in this case).
37924e63acdfSAndrey Ignatov  *
37934e63acdfSAndrey Ignatov  *		**-EINVAL** if sysctl is being read.
37944e63acdfSAndrey Ignatov  *
3795bdb7b79bSAndrii Nakryiko  * long bpf_sysctl_set_new_value(struct bpf_sysctl *ctx, const char *buf, size_t buf_len)
37964e63acdfSAndrey Ignatov  *	Description
37974e63acdfSAndrey Ignatov  *		Override new value being written by user space to sysctl with
37984e63acdfSAndrey Ignatov  *		value provided by program in buffer *buf* of size *buf_len*.
37994e63acdfSAndrey Ignatov  *
38004e63acdfSAndrey Ignatov  *		*buf* should contain a string in same form as provided by user
38014e63acdfSAndrey Ignatov  *		space on sysctl write.
38024e63acdfSAndrey Ignatov  *
38034e63acdfSAndrey Ignatov  *		User space may write new value at file position > 0. To override
38044e63acdfSAndrey Ignatov  *		the whole sysctl value file position should be set to zero.
38054e63acdfSAndrey Ignatov  *	Return
38064e63acdfSAndrey Ignatov  *		0 on success.
38074e63acdfSAndrey Ignatov  *
38084e63acdfSAndrey Ignatov  *		**-E2BIG** if the *buf_len* is too big.
38094e63acdfSAndrey Ignatov  *
38104e63acdfSAndrey Ignatov  *		**-EINVAL** if sysctl is being read.
3811d7a4cb9bSAndrey Ignatov  *
3812bdb7b79bSAndrii Nakryiko  * long bpf_strtol(const char *buf, size_t buf_len, u64 flags, long *res)
3813d7a4cb9bSAndrey Ignatov  *	Description
3814d7a4cb9bSAndrey Ignatov  *		Convert the initial part of the string from buffer *buf* of
3815d7a4cb9bSAndrey Ignatov  *		size *buf_len* to a long integer according to the given base
3816d7a4cb9bSAndrey Ignatov  *		and save the result in *res*.
3817d7a4cb9bSAndrey Ignatov  *
3818d7a4cb9bSAndrey Ignatov  *		The string may begin with an arbitrary amount of white space
381980867c5eSQuentin Monnet  *		(as determined by **isspace**\ (3)) followed by a single
382080867c5eSQuentin Monnet  *		optional '**-**' sign.
3821d7a4cb9bSAndrey Ignatov  *
3822d7a4cb9bSAndrey Ignatov  *		Five least significant bits of *flags* encode base, other bits
3823d7a4cb9bSAndrey Ignatov  *		are currently unused.
3824d7a4cb9bSAndrey Ignatov  *
3825d7a4cb9bSAndrey Ignatov  *		Base must be either 8, 10, 16 or 0 to detect it automatically
382680867c5eSQuentin Monnet  *		similar to user space **strtol**\ (3).
3827d7a4cb9bSAndrey Ignatov  *	Return
3828d7a4cb9bSAndrey Ignatov  *		Number of characters consumed on success. Must be positive but
382980867c5eSQuentin Monnet  *		no more than *buf_len*.
3830d7a4cb9bSAndrey Ignatov  *
3831d7a4cb9bSAndrey Ignatov  *		**-EINVAL** if no valid digits were found or unsupported base
3832d7a4cb9bSAndrey Ignatov  *		was provided.
3833d7a4cb9bSAndrey Ignatov  *
3834d7a4cb9bSAndrey Ignatov  *		**-ERANGE** if resulting value was out of range.
3835d7a4cb9bSAndrey Ignatov  *
3836bdb7b79bSAndrii Nakryiko  * long bpf_strtoul(const char *buf, size_t buf_len, u64 flags, unsigned long *res)
3837d7a4cb9bSAndrey Ignatov  *	Description
3838d7a4cb9bSAndrey Ignatov  *		Convert the initial part of the string from buffer *buf* of
3839d7a4cb9bSAndrey Ignatov  *		size *buf_len* to an unsigned long integer according to the
3840d7a4cb9bSAndrey Ignatov  *		given base and save the result in *res*.
3841d7a4cb9bSAndrey Ignatov  *
3842d7a4cb9bSAndrey Ignatov  *		The string may begin with an arbitrary amount of white space
384380867c5eSQuentin Monnet  *		(as determined by **isspace**\ (3)).
3844d7a4cb9bSAndrey Ignatov  *
3845d7a4cb9bSAndrey Ignatov  *		Five least significant bits of *flags* encode base, other bits
3846d7a4cb9bSAndrey Ignatov  *		are currently unused.
3847d7a4cb9bSAndrey Ignatov  *
3848d7a4cb9bSAndrey Ignatov  *		Base must be either 8, 10, 16 or 0 to detect it automatically
384980867c5eSQuentin Monnet  *		similar to user space **strtoul**\ (3).
3850d7a4cb9bSAndrey Ignatov  *	Return
3851d7a4cb9bSAndrey Ignatov  *		Number of characters consumed on success. Must be positive but
385280867c5eSQuentin Monnet  *		no more than *buf_len*.
3853d7a4cb9bSAndrey Ignatov  *
3854d7a4cb9bSAndrey Ignatov  *		**-EINVAL** if no valid digits were found or unsupported base
3855d7a4cb9bSAndrey Ignatov  *		was provided.
3856d7a4cb9bSAndrey Ignatov  *
3857d7a4cb9bSAndrey Ignatov  *		**-ERANGE** if resulting value was out of range.
38586ac99e8fSMartin KaFai Lau  *
385930897832SKP Singh  * void *bpf_sk_storage_get(struct bpf_map *map, void *sk, void *value, u64 flags)
38606ac99e8fSMartin KaFai Lau  *	Description
386180867c5eSQuentin Monnet  *		Get a bpf-local-storage from a *sk*.
38626ac99e8fSMartin KaFai Lau  *
38636ac99e8fSMartin KaFai Lau  *		Logically, it could be thought of getting the value from
38646ac99e8fSMartin KaFai Lau  *		a *map* with *sk* as the **key**.  From this
38656ac99e8fSMartin KaFai Lau  *		perspective,  the usage is not much different from
386680867c5eSQuentin Monnet  *		**bpf_map_lookup_elem**\ (*map*, **&**\ *sk*) except this
386780867c5eSQuentin Monnet  *		helper enforces the key must be a full socket and the map must
386880867c5eSQuentin Monnet  *		be a **BPF_MAP_TYPE_SK_STORAGE** also.
38696ac99e8fSMartin KaFai Lau  *
38706ac99e8fSMartin KaFai Lau  *		Underneath, the value is stored locally at *sk* instead of
387180867c5eSQuentin Monnet  *		the *map*.  The *map* is used as the bpf-local-storage
387280867c5eSQuentin Monnet  *		"type". The bpf-local-storage "type" (i.e. the *map*) is
387380867c5eSQuentin Monnet  *		searched against all bpf-local-storages residing at *sk*.
38746ac99e8fSMartin KaFai Lau  *
387530897832SKP Singh  *		*sk* is a kernel **struct sock** pointer for LSM program.
387630897832SKP Singh  *		*sk* is a **struct bpf_sock** pointer for other program types.
387730897832SKP Singh  *
387880867c5eSQuentin Monnet  *		An optional *flags* (**BPF_SK_STORAGE_GET_F_CREATE**) can be
38796ac99e8fSMartin KaFai Lau  *		used such that a new bpf-local-storage will be
38806ac99e8fSMartin KaFai Lau  *		created if one does not exist.  *value* can be used
388180867c5eSQuentin Monnet  *		together with **BPF_SK_STORAGE_GET_F_CREATE** to specify
38826ac99e8fSMartin KaFai Lau  *		the initial value of a bpf-local-storage.  If *value* is
388380867c5eSQuentin Monnet  *		**NULL**, the new bpf-local-storage will be zero initialized.
38846ac99e8fSMartin KaFai Lau  *	Return
38856ac99e8fSMartin KaFai Lau  *		A bpf-local-storage pointer is returned on success.
38866ac99e8fSMartin KaFai Lau  *
38876ac99e8fSMartin KaFai Lau  *		**NULL** if not found or there was an error in adding
38886ac99e8fSMartin KaFai Lau  *		a new bpf-local-storage.
38896ac99e8fSMartin KaFai Lau  *
389030897832SKP Singh  * long bpf_sk_storage_delete(struct bpf_map *map, void *sk)
38916ac99e8fSMartin KaFai Lau  *	Description
389280867c5eSQuentin Monnet  *		Delete a bpf-local-storage from a *sk*.
38936ac99e8fSMartin KaFai Lau  *	Return
38946ac99e8fSMartin KaFai Lau  *		0 on success.
38956ac99e8fSMartin KaFai Lau  *
38966ac99e8fSMartin KaFai Lau  *		**-ENOENT** if the bpf-local-storage cannot be found.
3897592a3498SMartin KaFai Lau  *		**-EINVAL** if sk is not a fullsock (e.g. a request_sock).
38988b401f9eSYonghong Song  *
3899bdb7b79bSAndrii Nakryiko  * long bpf_send_signal(u32 sig)
39008b401f9eSYonghong Song  *	Description
39018482941fSYonghong Song  *		Send signal *sig* to the process of the current task.
39028482941fSYonghong Song  *		The signal may be delivered to any of this process's threads.
39038b401f9eSYonghong Song  *	Return
39048b401f9eSYonghong Song  *		0 on success or successfully queued.
39058b401f9eSYonghong Song  *
39068b401f9eSYonghong Song  *		**-EBUSY** if work queue under nmi is full.
39078b401f9eSYonghong Song  *
39088b401f9eSYonghong Song  *		**-EINVAL** if *sig* is invalid.
39098b401f9eSYonghong Song  *
39108b401f9eSYonghong Song  *		**-EPERM** if no permission to send the *sig*.
39118b401f9eSYonghong Song  *
39128b401f9eSYonghong Song  *		**-EAGAIN** if bpf program can try again.
391370d66244SPetar Penkov  *
3914c0df236eSMartin KaFai Lau  * s64 bpf_tcp_gen_syncookie(void *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
391570d66244SPetar Penkov  *	Description
391670d66244SPetar Penkov  *		Try to issue a SYN cookie for the packet with corresponding
391770d66244SPetar Penkov  *		IP/TCP headers, *iph* and *th*, on the listening socket in *sk*.
391870d66244SPetar Penkov  *
391970d66244SPetar Penkov  *		*iph* points to the start of the IPv4 or IPv6 header, while
392070d66244SPetar Penkov  *		*iph_len* contains **sizeof**\ (**struct iphdr**) or
3921ac80287aSMaxim Mikityanskiy  *		**sizeof**\ (**struct ipv6hdr**).
392270d66244SPetar Penkov  *
392370d66244SPetar Penkov  *		*th* points to the start of the TCP header, while *th_len*
3924ac80287aSMaxim Mikityanskiy  *		contains the length of the TCP header with options (at least
3925ac80287aSMaxim Mikityanskiy  *		**sizeof**\ (**struct tcphdr**)).
392670d66244SPetar Penkov  *	Return
392770d66244SPetar Penkov  *		On success, lower 32 bits hold the generated SYN cookie in
392870d66244SPetar Penkov  *		followed by 16 bits which hold the MSS value for that cookie,
392970d66244SPetar Penkov  *		and the top 16 bits are unused.
393070d66244SPetar Penkov  *
393170d66244SPetar Penkov  *		On failure, the returned value is one of the following:
393270d66244SPetar Penkov  *
393370d66244SPetar Penkov  *		**-EINVAL** SYN cookie cannot be issued due to error
393470d66244SPetar Penkov  *
393570d66244SPetar Penkov  *		**-ENOENT** SYN cookie should not be issued (no SYN flood)
393670d66244SPetar Penkov  *
393770d66244SPetar Penkov  *		**-EOPNOTSUPP** kernel configuration does not enable SYN cookies
393870d66244SPetar Penkov  *
393970d66244SPetar Penkov  *		**-EPROTONOSUPPORT** IP packet version is not 4 or 6
3940a7658e1aSAlexei Starovoitov  *
3941bdb7b79bSAndrii Nakryiko  * long bpf_skb_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
3942a7658e1aSAlexei Starovoitov  * 	Description
3943a7658e1aSAlexei Starovoitov  * 		Write raw *data* blob into a special BPF perf event held by
3944a7658e1aSAlexei Starovoitov  * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
3945a7658e1aSAlexei Starovoitov  * 		event must have the following attributes: **PERF_SAMPLE_RAW**
3946a7658e1aSAlexei Starovoitov  * 		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
3947a7658e1aSAlexei Starovoitov  * 		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
3948a7658e1aSAlexei Starovoitov  *
3949a7658e1aSAlexei Starovoitov  * 		The *flags* are used to indicate the index in *map* for which
3950a7658e1aSAlexei Starovoitov  * 		the value must be put, masked with **BPF_F_INDEX_MASK**.
3951a7658e1aSAlexei Starovoitov  * 		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
3952a7658e1aSAlexei Starovoitov  * 		to indicate that the index of the current CPU core should be
3953a7658e1aSAlexei Starovoitov  * 		used.
3954a7658e1aSAlexei Starovoitov  *
3955a7658e1aSAlexei Starovoitov  * 		The value to write, of *size*, is passed through eBPF stack and
3956a7658e1aSAlexei Starovoitov  * 		pointed by *data*.
3957a7658e1aSAlexei Starovoitov  *
3958a7658e1aSAlexei Starovoitov  * 		*ctx* is a pointer to in-kernel struct sk_buff.
3959a7658e1aSAlexei Starovoitov  *
3960a7658e1aSAlexei Starovoitov  * 		This helper is similar to **bpf_perf_event_output**\ () but
3961a7658e1aSAlexei Starovoitov  * 		restricted to raw_tracepoint bpf programs.
3962a7658e1aSAlexei Starovoitov  * 	Return
3963a7658e1aSAlexei Starovoitov  * 		0 on success, or a negative error in case of failure.
39646ae08ae3SDaniel Borkmann  *
3965bdb7b79bSAndrii Nakryiko  * long bpf_probe_read_user(void *dst, u32 size, const void *unsafe_ptr)
39666ae08ae3SDaniel Borkmann  * 	Description
39676ae08ae3SDaniel Borkmann  * 		Safely attempt to read *size* bytes from user space address
39686ae08ae3SDaniel Borkmann  * 		*unsafe_ptr* and store the data in *dst*.
39696ae08ae3SDaniel Borkmann  * 	Return
39706ae08ae3SDaniel Borkmann  * 		0 on success, or a negative error in case of failure.
39716ae08ae3SDaniel Borkmann  *
3972bdb7b79bSAndrii Nakryiko  * long bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
39736ae08ae3SDaniel Borkmann  * 	Description
39746ae08ae3SDaniel Borkmann  * 		Safely attempt to read *size* bytes from kernel space address
39756ae08ae3SDaniel Borkmann  * 		*unsafe_ptr* and store the data in *dst*.
39766ae08ae3SDaniel Borkmann  * 	Return
39776ae08ae3SDaniel Borkmann  * 		0 on success, or a negative error in case of failure.
39786ae08ae3SDaniel Borkmann  *
3979bdb7b79bSAndrii Nakryiko  * long bpf_probe_read_user_str(void *dst, u32 size, const void *unsafe_ptr)
39806ae08ae3SDaniel Borkmann  * 	Description
39816ae08ae3SDaniel Borkmann  * 		Copy a NUL terminated string from an unsafe user address
39826ae08ae3SDaniel Borkmann  * 		*unsafe_ptr* to *dst*. The *size* should include the
39836ae08ae3SDaniel Borkmann  * 		terminating NUL byte. In case the string length is smaller than
39846ae08ae3SDaniel Borkmann  * 		*size*, the target is not padded with further NUL bytes. If the
39856ae08ae3SDaniel Borkmann  * 		string length is larger than *size*, just *size*-1 bytes are
39866ae08ae3SDaniel Borkmann  * 		copied and the last byte is set to NUL.
39876ae08ae3SDaniel Borkmann  *
3988c6458e72SBrendan Jackman  * 		On success, returns the number of bytes that were written,
3989c6458e72SBrendan Jackman  * 		including the terminal NUL. This makes this helper useful in
3990c6458e72SBrendan Jackman  * 		tracing programs for reading strings, and more importantly to
3991c6458e72SBrendan Jackman  * 		get its length at runtime. See the following snippet:
39926ae08ae3SDaniel Borkmann  *
39936ae08ae3SDaniel Borkmann  * 		::
39946ae08ae3SDaniel Borkmann  *
39956ae08ae3SDaniel Borkmann  * 			SEC("kprobe/sys_open")
39966ae08ae3SDaniel Borkmann  * 			void bpf_sys_open(struct pt_regs *ctx)
39976ae08ae3SDaniel Borkmann  * 			{
39986ae08ae3SDaniel Borkmann  * 			        char buf[PATHLEN]; // PATHLEN is defined to 256
39996ae08ae3SDaniel Borkmann  * 			        int res = bpf_probe_read_user_str(buf, sizeof(buf),
40006ae08ae3SDaniel Borkmann  * 				                                  ctx->di);
40016ae08ae3SDaniel Borkmann  *
40026ae08ae3SDaniel Borkmann  * 				// Consume buf, for example push it to
40036ae08ae3SDaniel Borkmann  * 				// userspace via bpf_perf_event_output(); we
40046ae08ae3SDaniel Borkmann  * 				// can use res (the string length) as event
40056ae08ae3SDaniel Borkmann  * 				// size, after checking its boundaries.
40066ae08ae3SDaniel Borkmann  * 			}
40076ae08ae3SDaniel Borkmann  *
4008ab8d7809SQuentin Monnet  * 		In comparison, using **bpf_probe_read_user**\ () helper here
40096ae08ae3SDaniel Borkmann  * 		instead to read the string would require to estimate the length
40106ae08ae3SDaniel Borkmann  * 		at compile time, and would often result in copying more memory
40116ae08ae3SDaniel Borkmann  * 		than necessary.
40126ae08ae3SDaniel Borkmann  *
40136ae08ae3SDaniel Borkmann  * 		Another useful use case is when parsing individual process
40146ae08ae3SDaniel Borkmann  * 		arguments or individual environment variables navigating
40156ae08ae3SDaniel Borkmann  * 		*current*\ **->mm->arg_start** and *current*\
40166ae08ae3SDaniel Borkmann  * 		**->mm->env_start**: using this helper and the return value,
40176ae08ae3SDaniel Borkmann  * 		one can quickly iterate at the right offset of the memory area.
40186ae08ae3SDaniel Borkmann  * 	Return
4019c6458e72SBrendan Jackman  * 		On success, the strictly positive length of the output string,
40206ae08ae3SDaniel Borkmann  * 		including the trailing NUL character. On error, a negative
40216ae08ae3SDaniel Borkmann  * 		value.
40226ae08ae3SDaniel Borkmann  *
4023bdb7b79bSAndrii Nakryiko  * long bpf_probe_read_kernel_str(void *dst, u32 size, const void *unsafe_ptr)
40246ae08ae3SDaniel Borkmann  * 	Description
40256ae08ae3SDaniel Borkmann  * 		Copy a NUL terminated string from an unsafe kernel address *unsafe_ptr*
4026ab8d7809SQuentin Monnet  * 		to *dst*. Same semantics as with **bpf_probe_read_user_str**\ () apply.
40276ae08ae3SDaniel Borkmann  * 	Return
40286ae08ae3SDaniel Borkmann  * 		On success, the strictly positive length of the string, including
40296ae08ae3SDaniel Borkmann  * 		the trailing NUL character. On error, a negative value.
4030206057feSMartin KaFai Lau  *
4031bdb7b79bSAndrii Nakryiko  * long bpf_tcp_send_ack(void *tp, u32 rcv_nxt)
4032206057feSMartin KaFai Lau  *	Description
4033ab8d7809SQuentin Monnet  *		Send out a tcp-ack. *tp* is the in-kernel struct **tcp_sock**.
4034206057feSMartin KaFai Lau  *		*rcv_nxt* is the ack_seq to be sent out.
4035206057feSMartin KaFai Lau  *	Return
4036206057feSMartin KaFai Lau  *		0 on success, or a negative error in case of failure.
4037206057feSMartin KaFai Lau  *
4038bdb7b79bSAndrii Nakryiko  * long bpf_send_signal_thread(u32 sig)
40398482941fSYonghong Song  *	Description
40408482941fSYonghong Song  *		Send signal *sig* to the thread corresponding to the current task.
40418482941fSYonghong Song  *	Return
40428482941fSYonghong Song  *		0 on success or successfully queued.
40438482941fSYonghong Song  *
40448482941fSYonghong Song  *		**-EBUSY** if work queue under nmi is full.
40458482941fSYonghong Song  *
40468482941fSYonghong Song  *		**-EINVAL** if *sig* is invalid.
40478482941fSYonghong Song  *
40488482941fSYonghong Song  *		**-EPERM** if no permission to send the *sig*.
40498482941fSYonghong Song  *
40508482941fSYonghong Song  *		**-EAGAIN** if bpf program can try again.
40515576b991SMartin KaFai Lau  *
40525576b991SMartin KaFai Lau  * u64 bpf_jiffies64(void)
40535576b991SMartin KaFai Lau  *	Description
40545576b991SMartin KaFai Lau  *		Obtain the 64bit jiffies
40555576b991SMartin KaFai Lau  *	Return
40565576b991SMartin KaFai Lau  *		The 64 bit jiffies
4057fff7b643SDaniel Xu  *
4058bdb7b79bSAndrii Nakryiko  * long bpf_read_branch_records(struct bpf_perf_event_data *ctx, void *buf, u32 size, u64 flags)
4059fff7b643SDaniel Xu  *	Description
4060fff7b643SDaniel Xu  *		For an eBPF program attached to a perf event, retrieve the
4061ab8d7809SQuentin Monnet  *		branch records (**struct perf_branch_entry**) associated to *ctx*
4062fff7b643SDaniel Xu  *		and store it in the buffer pointed by *buf* up to size
4063fff7b643SDaniel Xu  *		*size* bytes.
4064fff7b643SDaniel Xu  *	Return
4065fff7b643SDaniel Xu  *		On success, number of bytes written to *buf*. On error, a
4066fff7b643SDaniel Xu  *		negative value.
4067fff7b643SDaniel Xu  *
4068fff7b643SDaniel Xu  *		The *flags* can be set to **BPF_F_GET_BRANCH_RECORDS_SIZE** to
4069fff7b643SDaniel Xu  *		instead return the number of bytes required to store all the
4070fff7b643SDaniel Xu  *		branch entries. If this flag is set, *buf* may be NULL.
4071fff7b643SDaniel Xu  *
4072fff7b643SDaniel Xu  *		**-EINVAL** if arguments invalid or **size** not a multiple
4073ab8d7809SQuentin Monnet  *		of **sizeof**\ (**struct perf_branch_entry**\ ).
4074fff7b643SDaniel Xu  *
4075fff7b643SDaniel Xu  *		**-ENOENT** if architecture does not support branch records.
4076b4490c5cSCarlos Neira  *
4077bdb7b79bSAndrii Nakryiko  * long bpf_get_ns_current_pid_tgid(u64 dev, u64 ino, struct bpf_pidns_info *nsdata, u32 size)
4078b4490c5cSCarlos Neira  *	Description
4079b4490c5cSCarlos Neira  *		Returns 0 on success, values for *pid* and *tgid* as seen from the current
4080b4490c5cSCarlos Neira  *		*namespace* will be returned in *nsdata*.
4081ab8d7809SQuentin Monnet  *	Return
4082ab8d7809SQuentin Monnet  *		0 on success, or one of the following in case of failure:
4083b4490c5cSCarlos Neira  *
4084b4490c5cSCarlos Neira  *		**-EINVAL** if dev and inum supplied don't match dev_t and inode number
4085b4490c5cSCarlos Neira  *              with nsfs of current task, or if dev conversion to dev_t lost high bits.
4086b4490c5cSCarlos Neira  *
4087b4490c5cSCarlos Neira  *		**-ENOENT** if pidns does not exists for the current task.
4088b4490c5cSCarlos Neira  *
4089bdb7b79bSAndrii Nakryiko  * long bpf_xdp_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
4090d831ee84SEelco Chaudron  *	Description
4091d831ee84SEelco Chaudron  *		Write raw *data* blob into a special BPF perf event held by
4092d831ee84SEelco Chaudron  *		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
4093d831ee84SEelco Chaudron  *		event must have the following attributes: **PERF_SAMPLE_RAW**
4094d831ee84SEelco Chaudron  *		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
4095d831ee84SEelco Chaudron  *		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
4096d831ee84SEelco Chaudron  *
4097d831ee84SEelco Chaudron  *		The *flags* are used to indicate the index in *map* for which
4098d831ee84SEelco Chaudron  *		the value must be put, masked with **BPF_F_INDEX_MASK**.
4099d831ee84SEelco Chaudron  *		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
4100d831ee84SEelco Chaudron  *		to indicate that the index of the current CPU core should be
4101d831ee84SEelco Chaudron  *		used.
4102d831ee84SEelco Chaudron  *
4103d831ee84SEelco Chaudron  *		The value to write, of *size*, is passed through eBPF stack and
4104d831ee84SEelco Chaudron  *		pointed by *data*.
4105d831ee84SEelco Chaudron  *
4106d831ee84SEelco Chaudron  *		*ctx* is a pointer to in-kernel struct xdp_buff.
4107d831ee84SEelco Chaudron  *
4108d831ee84SEelco Chaudron  *		This helper is similar to **bpf_perf_eventoutput**\ () but
4109d831ee84SEelco Chaudron  *		restricted to raw_tracepoint bpf programs.
4110d831ee84SEelco Chaudron  *	Return
4111d831ee84SEelco Chaudron  *		0 on success, or a negative error in case of failure.
4112f318903cSDaniel Borkmann  *
4113f318903cSDaniel Borkmann  * u64 bpf_get_netns_cookie(void *ctx)
4114f318903cSDaniel Borkmann  * 	Description
4115f318903cSDaniel Borkmann  * 		Retrieve the cookie (generated by the kernel) of the network
4116f318903cSDaniel Borkmann  * 		namespace the input *ctx* is associated with. The network
4117f318903cSDaniel Borkmann  * 		namespace cookie remains stable for its lifetime and provides
4118f318903cSDaniel Borkmann  * 		a global identifier that can be assumed unique. If *ctx* is
4119f318903cSDaniel Borkmann  * 		NULL, then the helper returns the cookie for the initial
4120f318903cSDaniel Borkmann  * 		network namespace. The cookie itself is very similar to that
4121ab8d7809SQuentin Monnet  * 		of **bpf_get_socket_cookie**\ () helper, but for network
4122ab8d7809SQuentin Monnet  * 		namespaces instead of sockets.
4123f318903cSDaniel Borkmann  * 	Return
4124f318903cSDaniel Borkmann  * 		A 8-byte long opaque number.
41250f09abd1SDaniel Borkmann  *
41260f09abd1SDaniel Borkmann  * u64 bpf_get_current_ancestor_cgroup_id(int ancestor_level)
41270f09abd1SDaniel Borkmann  * 	Description
41280f09abd1SDaniel Borkmann  * 		Return id of cgroup v2 that is ancestor of the cgroup associated
41290f09abd1SDaniel Borkmann  * 		with the current task at the *ancestor_level*. The root cgroup
41300f09abd1SDaniel Borkmann  * 		is at *ancestor_level* zero and each step down the hierarchy
41310f09abd1SDaniel Borkmann  * 		increments the level. If *ancestor_level* == level of cgroup
41320f09abd1SDaniel Borkmann  * 		associated with the current task, then return value will be the
41330f09abd1SDaniel Borkmann  * 		same as that of **bpf_get_current_cgroup_id**\ ().
41340f09abd1SDaniel Borkmann  *
41350f09abd1SDaniel Borkmann  * 		The helper is useful to implement policies based on cgroups
41360f09abd1SDaniel Borkmann  * 		that are upper in hierarchy than immediate cgroup associated
41370f09abd1SDaniel Borkmann  * 		with the current task.
41380f09abd1SDaniel Borkmann  *
41390f09abd1SDaniel Borkmann  * 		The format of returned id and helper limitations are same as in
41400f09abd1SDaniel Borkmann  * 		**bpf_get_current_cgroup_id**\ ().
41410f09abd1SDaniel Borkmann  * 	Return
41420f09abd1SDaniel Borkmann  * 		The id is returned or 0 in case the id could not be retrieved.
4143cf7fbe66SJoe Stringer  *
414427e5203bSMartin KaFai Lau  * long bpf_sk_assign(struct sk_buff *skb, void *sk, u64 flags)
4145cf7fbe66SJoe Stringer  *	Description
4146e9ddbb77SJakub Sitnicki  *		Helper is overloaded depending on BPF program type. This
4147e9ddbb77SJakub Sitnicki  *		description applies to **BPF_PROG_TYPE_SCHED_CLS** and
4148e9ddbb77SJakub Sitnicki  *		**BPF_PROG_TYPE_SCHED_ACT** programs.
4149e9ddbb77SJakub Sitnicki  *
4150cf7fbe66SJoe Stringer  *		Assign the *sk* to the *skb*. When combined with appropriate
4151cf7fbe66SJoe Stringer  *		routing configuration to receive the packet towards the socket,
4152cf7fbe66SJoe Stringer  *		will cause *skb* to be delivered to the specified socket.
4153cf7fbe66SJoe Stringer  *		Subsequent redirection of *skb* via  **bpf_redirect**\ (),
4154cf7fbe66SJoe Stringer  *		**bpf_clone_redirect**\ () or other methods outside of BPF may
4155cf7fbe66SJoe Stringer  *		interfere with successful delivery to the socket.
4156cf7fbe66SJoe Stringer  *
4157cf7fbe66SJoe Stringer  *		This operation is only valid from TC ingress path.
4158cf7fbe66SJoe Stringer  *
4159cf7fbe66SJoe Stringer  *		The *flags* argument must be zero.
4160cf7fbe66SJoe Stringer  *	Return
4161ab8d7809SQuentin Monnet  *		0 on success, or a negative error in case of failure:
4162cf7fbe66SJoe Stringer  *
4163ab8d7809SQuentin Monnet  *		**-EINVAL** if specified *flags* are not supported.
4164ab8d7809SQuentin Monnet  *
4165ab8d7809SQuentin Monnet  *		**-ENOENT** if the socket is unavailable for assignment.
4166ab8d7809SQuentin Monnet  *
4167ab8d7809SQuentin Monnet  *		**-ENETUNREACH** if the socket is unreachable (wrong netns).
4168ab8d7809SQuentin Monnet  *
4169ab8d7809SQuentin Monnet  *		**-EOPNOTSUPP** if the operation is not supported, for example
4170ab8d7809SQuentin Monnet  *		a call from outside of TC ingress.
4171ab8d7809SQuentin Monnet  *
4172ab8d7809SQuentin Monnet  *		**-ESOCKTNOSUPPORT** if the socket type is not supported
4173ab8d7809SQuentin Monnet  *		(reuseport).
417471d19214SMaciej Żenczykowski  *
4175e9ddbb77SJakub Sitnicki  * long bpf_sk_assign(struct bpf_sk_lookup *ctx, struct bpf_sock *sk, u64 flags)
4176e9ddbb77SJakub Sitnicki  *	Description
4177e9ddbb77SJakub Sitnicki  *		Helper is overloaded depending on BPF program type. This
4178e9ddbb77SJakub Sitnicki  *		description applies to **BPF_PROG_TYPE_SK_LOOKUP** programs.
4179e9ddbb77SJakub Sitnicki  *
4180e9ddbb77SJakub Sitnicki  *		Select the *sk* as a result of a socket lookup.
4181e9ddbb77SJakub Sitnicki  *
4182e9ddbb77SJakub Sitnicki  *		For the operation to succeed passed socket must be compatible
4183e9ddbb77SJakub Sitnicki  *		with the packet description provided by the *ctx* object.
4184e9ddbb77SJakub Sitnicki  *
4185e9ddbb77SJakub Sitnicki  *		L4 protocol (**IPPROTO_TCP** or **IPPROTO_UDP**) must
4186e9ddbb77SJakub Sitnicki  *		be an exact match. While IP family (**AF_INET** or
4187e9ddbb77SJakub Sitnicki  *		**AF_INET6**) must be compatible, that is IPv6 sockets
4188e9ddbb77SJakub Sitnicki  *		that are not v6-only can be selected for IPv4 packets.
4189e9ddbb77SJakub Sitnicki  *
4190e9ddbb77SJakub Sitnicki  *		Only TCP listeners and UDP unconnected sockets can be
4191e9ddbb77SJakub Sitnicki  *		selected. *sk* can also be NULL to reset any previous
4192e9ddbb77SJakub Sitnicki  *		selection.
4193e9ddbb77SJakub Sitnicki  *
4194e9ddbb77SJakub Sitnicki  *		*flags* argument can combination of following values:
4195e9ddbb77SJakub Sitnicki  *
4196e9ddbb77SJakub Sitnicki  *		* **BPF_SK_LOOKUP_F_REPLACE** to override the previous
4197e9ddbb77SJakub Sitnicki  *		  socket selection, potentially done by a BPF program
4198e9ddbb77SJakub Sitnicki  *		  that ran before us.
4199e9ddbb77SJakub Sitnicki  *
4200e9ddbb77SJakub Sitnicki  *		* **BPF_SK_LOOKUP_F_NO_REUSEPORT** to skip
4201e9ddbb77SJakub Sitnicki  *		  load-balancing within reuseport group for the socket
4202e9ddbb77SJakub Sitnicki  *		  being selected.
4203e9ddbb77SJakub Sitnicki  *
4204e9ddbb77SJakub Sitnicki  *		On success *ctx->sk* will point to the selected socket.
4205e9ddbb77SJakub Sitnicki  *
4206e9ddbb77SJakub Sitnicki  *	Return
4207e9ddbb77SJakub Sitnicki  *		0 on success, or a negative errno in case of failure.
4208e9ddbb77SJakub Sitnicki  *
4209e9ddbb77SJakub Sitnicki  *		* **-EAFNOSUPPORT** if socket family (*sk->family*) is
4210e9ddbb77SJakub Sitnicki  *		  not compatible with packet family (*ctx->family*).
4211e9ddbb77SJakub Sitnicki  *
4212e9ddbb77SJakub Sitnicki  *		* **-EEXIST** if socket has been already selected,
4213e9ddbb77SJakub Sitnicki  *		  potentially by another program, and
4214e9ddbb77SJakub Sitnicki  *		  **BPF_SK_LOOKUP_F_REPLACE** flag was not specified.
4215e9ddbb77SJakub Sitnicki  *
4216e9ddbb77SJakub Sitnicki  *		* **-EINVAL** if unsupported flags were specified.
4217e9ddbb77SJakub Sitnicki  *
4218e9ddbb77SJakub Sitnicki  *		* **-EPROTOTYPE** if socket L4 protocol
4219e9ddbb77SJakub Sitnicki  *		  (*sk->protocol*) doesn't match packet protocol
4220e9ddbb77SJakub Sitnicki  *		  (*ctx->protocol*).
4221e9ddbb77SJakub Sitnicki  *
4222e9ddbb77SJakub Sitnicki  *		* **-ESOCKTNOSUPPORT** if socket is not in allowed
4223e9ddbb77SJakub Sitnicki  *		  state (TCP listening or UDP unconnected).
4224e9ddbb77SJakub Sitnicki  *
422571d19214SMaciej Żenczykowski  * u64 bpf_ktime_get_boot_ns(void)
422671d19214SMaciej Żenczykowski  * 	Description
422771d19214SMaciej Żenczykowski  * 		Return the time elapsed since system boot, in nanoseconds.
422871d19214SMaciej Żenczykowski  * 		Does include the time the system was suspended.
4229ab8d7809SQuentin Monnet  * 		See: **clock_gettime**\ (**CLOCK_BOOTTIME**)
423071d19214SMaciej Żenczykowski  * 	Return
423171d19214SMaciej Żenczykowski  * 		Current *ktime*.
4232492e639fSYonghong Song  *
4233bdb7b79bSAndrii Nakryiko  * long bpf_seq_printf(struct seq_file *m, const char *fmt, u32 fmt_size, const void *data, u32 data_len)
4234492e639fSYonghong Song  * 	Description
4235ab8d7809SQuentin Monnet  * 		**bpf_seq_printf**\ () uses seq_file **seq_printf**\ () to print
4236ab8d7809SQuentin Monnet  * 		out the format string.
4237492e639fSYonghong Song  * 		The *m* represents the seq_file. The *fmt* and *fmt_size* are for
4238492e639fSYonghong Song  * 		the format string itself. The *data* and *data_len* are format string
4239ab8d7809SQuentin Monnet  * 		arguments. The *data* are a **u64** array and corresponding format string
4240492e639fSYonghong Song  * 		values are stored in the array. For strings and pointers where pointees
4241492e639fSYonghong Song  * 		are accessed, only the pointer values are stored in the *data* array.
4242a42effb0SDave Marchevsky  * 		The *data_len* is the size of *data* in bytes - must be a multiple of 8.
4243492e639fSYonghong Song  *
4244492e639fSYonghong Song  *		Formats **%s**, **%p{i,I}{4,6}** requires to read kernel memory.
4245492e639fSYonghong Song  *		Reading kernel memory may fail due to either invalid address or
4246492e639fSYonghong Song  *		valid address but requiring a major memory fault. If reading kernel memory
4247492e639fSYonghong Song  *		fails, the string for **%s** will be an empty string, and the ip
4248492e639fSYonghong Song  *		address for **%p{i,I}{4,6}** will be 0. Not returning error to
4249ab8d7809SQuentin Monnet  *		bpf program is consistent with what **bpf_trace_printk**\ () does for now.
4250492e639fSYonghong Song  * 	Return
4251ab8d7809SQuentin Monnet  * 		0 on success, or a negative error in case of failure:
4252492e639fSYonghong Song  *
4253ab8d7809SQuentin Monnet  *		**-EBUSY** if per-CPU memory copy buffer is busy, can try again
4254492e639fSYonghong Song  *		by returning 1 from bpf program.
4255ab8d7809SQuentin Monnet  *
4256ab8d7809SQuentin Monnet  *		**-EINVAL** if arguments are invalid, or if *fmt* is invalid/unsupported.
4257ab8d7809SQuentin Monnet  *
4258ab8d7809SQuentin Monnet  *		**-E2BIG** if *fmt* contains too many format specifiers.
4259ab8d7809SQuentin Monnet  *
4260ab8d7809SQuentin Monnet  *		**-EOVERFLOW** if an overflow happened: The same object will be tried again.
4261492e639fSYonghong Song  *
4262bdb7b79bSAndrii Nakryiko  * long bpf_seq_write(struct seq_file *m, const void *data, u32 len)
4263492e639fSYonghong Song  * 	Description
4264ab8d7809SQuentin Monnet  * 		**bpf_seq_write**\ () uses seq_file **seq_write**\ () to write the data.
4265492e639fSYonghong Song  * 		The *m* represents the seq_file. The *data* and *len* represent the
4266492e639fSYonghong Song  * 		data to write in bytes.
4267492e639fSYonghong Song  * 	Return
4268ab8d7809SQuentin Monnet  * 		0 on success, or a negative error in case of failure:
4269492e639fSYonghong Song  *
4270ab8d7809SQuentin Monnet  *		**-EOVERFLOW** if an overflow happened: The same object will be tried again.
4271f307fa2cSAndrey Ignatov  *
4272a5fa25adSMartin KaFai Lau  * u64 bpf_sk_cgroup_id(void *sk)
4273f307fa2cSAndrey Ignatov  *	Description
4274f307fa2cSAndrey Ignatov  *		Return the cgroup v2 id of the socket *sk*.
4275f307fa2cSAndrey Ignatov  *
4276a5fa25adSMartin KaFai Lau  *		*sk* must be a non-**NULL** pointer to a socket, e.g. one
4277f307fa2cSAndrey Ignatov  *		returned from **bpf_sk_lookup_xxx**\ (),
4278f307fa2cSAndrey Ignatov  *		**bpf_sk_fullsock**\ (), etc. The format of returned id is
4279f307fa2cSAndrey Ignatov  *		same as in **bpf_skb_cgroup_id**\ ().
4280f307fa2cSAndrey Ignatov  *
4281f307fa2cSAndrey Ignatov  *		This helper is available only if the kernel was compiled with
4282f307fa2cSAndrey Ignatov  *		the **CONFIG_SOCK_CGROUP_DATA** configuration option.
4283f307fa2cSAndrey Ignatov  *	Return
4284f307fa2cSAndrey Ignatov  *		The id is returned or 0 in case the id could not be retrieved.
4285f307fa2cSAndrey Ignatov  *
4286a5fa25adSMartin KaFai Lau  * u64 bpf_sk_ancestor_cgroup_id(void *sk, int ancestor_level)
4287f307fa2cSAndrey Ignatov  *	Description
4288f307fa2cSAndrey Ignatov  *		Return id of cgroup v2 that is ancestor of cgroup associated
4289f307fa2cSAndrey Ignatov  *		with the *sk* at the *ancestor_level*.  The root cgroup is at
4290f307fa2cSAndrey Ignatov  *		*ancestor_level* zero and each step down the hierarchy
4291f307fa2cSAndrey Ignatov  *		increments the level. If *ancestor_level* == level of cgroup
4292f307fa2cSAndrey Ignatov  *		associated with *sk*, then return value will be same as that
4293f307fa2cSAndrey Ignatov  *		of **bpf_sk_cgroup_id**\ ().
4294f307fa2cSAndrey Ignatov  *
4295f307fa2cSAndrey Ignatov  *		The helper is useful to implement policies based on cgroups
4296f307fa2cSAndrey Ignatov  *		that are upper in hierarchy than immediate cgroup associated
4297f307fa2cSAndrey Ignatov  *		with *sk*.
4298f307fa2cSAndrey Ignatov  *
4299f307fa2cSAndrey Ignatov  *		The format of returned id and helper limitations are same as in
4300f307fa2cSAndrey Ignatov  *		**bpf_sk_cgroup_id**\ ().
4301f307fa2cSAndrey Ignatov  *	Return
4302f307fa2cSAndrey Ignatov  *		The id is returned or 0 in case the id could not be retrieved.
4303457f4436SAndrii Nakryiko  *
4304e1613b57SAndrii Nakryiko  * long bpf_ringbuf_output(void *ringbuf, void *data, u64 size, u64 flags)
4305457f4436SAndrii Nakryiko  * 	Description
4306457f4436SAndrii Nakryiko  * 		Copy *size* bytes from *data* into a ring buffer *ringbuf*.
4307bcc7f554SQuentin Monnet  * 		If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
4308bcc7f554SQuentin Monnet  * 		of new data availability is sent.
4309bcc7f554SQuentin Monnet  * 		If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
4310bcc7f554SQuentin Monnet  * 		of new data availability is sent unconditionally.
43115c507329SPedro Tammela  * 		If **0** is specified in *flags*, an adaptive notification
43125c507329SPedro Tammela  * 		of new data availability is sent.
43135c507329SPedro Tammela  *
43145c507329SPedro Tammela  * 		An adaptive notification is a notification sent whenever the user-space
43155c507329SPedro Tammela  * 		process has caught up and consumed all available payloads. In case the user-space
43165c507329SPedro Tammela  * 		process is still processing a previous payload, then no notification is needed
43175c507329SPedro Tammela  * 		as it will process the newly added payload automatically.
4318457f4436SAndrii Nakryiko  * 	Return
4319bcc7f554SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
4320457f4436SAndrii Nakryiko  *
4321457f4436SAndrii Nakryiko  * void *bpf_ringbuf_reserve(void *ringbuf, u64 size, u64 flags)
4322457f4436SAndrii Nakryiko  * 	Description
4323457f4436SAndrii Nakryiko  * 		Reserve *size* bytes of payload in a ring buffer *ringbuf*.
43245c507329SPedro Tammela  * 		*flags* must be 0.
4325457f4436SAndrii Nakryiko  * 	Return
4326457f4436SAndrii Nakryiko  * 		Valid pointer with *size* bytes of memory available; NULL,
4327457f4436SAndrii Nakryiko  * 		otherwise.
4328457f4436SAndrii Nakryiko  *
4329457f4436SAndrii Nakryiko  * void bpf_ringbuf_submit(void *data, u64 flags)
4330457f4436SAndrii Nakryiko  * 	Description
4331457f4436SAndrii Nakryiko  * 		Submit reserved ring buffer sample, pointed to by *data*.
4332bcc7f554SQuentin Monnet  * 		If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
4333bcc7f554SQuentin Monnet  * 		of new data availability is sent.
4334bcc7f554SQuentin Monnet  * 		If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
4335bcc7f554SQuentin Monnet  * 		of new data availability is sent unconditionally.
43365c507329SPedro Tammela  * 		If **0** is specified in *flags*, an adaptive notification
43375c507329SPedro Tammela  * 		of new data availability is sent.
43385c507329SPedro Tammela  *
43395c507329SPedro Tammela  * 		See 'bpf_ringbuf_output()' for the definition of adaptive notification.
4340457f4436SAndrii Nakryiko  * 	Return
4341457f4436SAndrii Nakryiko  * 		Nothing. Always succeeds.
4342457f4436SAndrii Nakryiko  *
4343457f4436SAndrii Nakryiko  * void bpf_ringbuf_discard(void *data, u64 flags)
4344457f4436SAndrii Nakryiko  * 	Description
4345457f4436SAndrii Nakryiko  * 		Discard reserved ring buffer sample, pointed to by *data*.
4346bcc7f554SQuentin Monnet  * 		If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
4347bcc7f554SQuentin Monnet  * 		of new data availability is sent.
4348bcc7f554SQuentin Monnet  * 		If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
4349bcc7f554SQuentin Monnet  * 		of new data availability is sent unconditionally.
43505c507329SPedro Tammela  * 		If **0** is specified in *flags*, an adaptive notification
43515c507329SPedro Tammela  * 		of new data availability is sent.
43525c507329SPedro Tammela  *
43535c507329SPedro Tammela  * 		See 'bpf_ringbuf_output()' for the definition of adaptive notification.
4354457f4436SAndrii Nakryiko  * 	Return
4355457f4436SAndrii Nakryiko  * 		Nothing. Always succeeds.
4356457f4436SAndrii Nakryiko  *
4357457f4436SAndrii Nakryiko  * u64 bpf_ringbuf_query(void *ringbuf, u64 flags)
4358457f4436SAndrii Nakryiko  *	Description
4359457f4436SAndrii Nakryiko  *		Query various characteristics of provided ring buffer. What
4360457f4436SAndrii Nakryiko  *		exactly is queries is determined by *flags*:
4361bcc7f554SQuentin Monnet  *
4362bcc7f554SQuentin Monnet  *		* **BPF_RB_AVAIL_DATA**: Amount of data not yet consumed.
4363bcc7f554SQuentin Monnet  *		* **BPF_RB_RING_SIZE**: The size of ring buffer.
4364bcc7f554SQuentin Monnet  *		* **BPF_RB_CONS_POS**: Consumer position (can wrap around).
4365bcc7f554SQuentin Monnet  *		* **BPF_RB_PROD_POS**: Producer(s) position (can wrap around).
4366bcc7f554SQuentin Monnet  *
4367bcc7f554SQuentin Monnet  *		Data returned is just a momentary snapshot of actual values
4368457f4436SAndrii Nakryiko  *		and could be inaccurate, so this facility should be used to
4369457f4436SAndrii Nakryiko  *		power heuristics and for reporting, not to make 100% correct
4370457f4436SAndrii Nakryiko  *		calculation.
4371457f4436SAndrii Nakryiko  *	Return
4372bcc7f554SQuentin Monnet  *		Requested value, or 0, if *flags* are not recognized.
43737cdec54fSDaniel Borkmann  *
4374bdb7b79bSAndrii Nakryiko  * long bpf_csum_level(struct sk_buff *skb, u64 level)
43757cdec54fSDaniel Borkmann  * 	Description
43767cdec54fSDaniel Borkmann  * 		Change the skbs checksum level by one layer up or down, or
43777cdec54fSDaniel Borkmann  * 		reset it entirely to none in order to have the stack perform
43787cdec54fSDaniel Borkmann  * 		checksum validation. The level is applicable to the following
43797cdec54fSDaniel Borkmann  * 		protocols: TCP, UDP, GRE, SCTP, FCOE. For example, a decap of
43807cdec54fSDaniel Borkmann  * 		| ETH | IP | UDP | GUE | IP | TCP | into | ETH | IP | TCP |
43817cdec54fSDaniel Borkmann  * 		through **bpf_skb_adjust_room**\ () helper with passing in
43827cdec54fSDaniel Borkmann  * 		**BPF_F_ADJ_ROOM_NO_CSUM_RESET** flag would require one	call
43837cdec54fSDaniel Borkmann  * 		to **bpf_csum_level**\ () with **BPF_CSUM_LEVEL_DEC** since
43847cdec54fSDaniel Borkmann  * 		the UDP header is removed. Similarly, an encap of the latter
43857cdec54fSDaniel Borkmann  * 		into the former could be accompanied by a helper call to
43867cdec54fSDaniel Borkmann  * 		**bpf_csum_level**\ () with **BPF_CSUM_LEVEL_INC** if the
43877cdec54fSDaniel Borkmann  * 		skb is still intended to be processed in higher layers of the
43887cdec54fSDaniel Borkmann  * 		stack instead of just egressing at tc.
43897cdec54fSDaniel Borkmann  *
43907cdec54fSDaniel Borkmann  * 		There are three supported level settings at this time:
43917cdec54fSDaniel Borkmann  *
43927cdec54fSDaniel Borkmann  * 		* **BPF_CSUM_LEVEL_INC**: Increases skb->csum_level for skbs
43937cdec54fSDaniel Borkmann  * 		  with CHECKSUM_UNNECESSARY.
43947cdec54fSDaniel Borkmann  * 		* **BPF_CSUM_LEVEL_DEC**: Decreases skb->csum_level for skbs
43957cdec54fSDaniel Borkmann  * 		  with CHECKSUM_UNNECESSARY.
43967cdec54fSDaniel Borkmann  * 		* **BPF_CSUM_LEVEL_RESET**: Resets skb->csum_level to 0 and
43977cdec54fSDaniel Borkmann  * 		  sets CHECKSUM_NONE to force checksum validation by the stack.
43987cdec54fSDaniel Borkmann  * 		* **BPF_CSUM_LEVEL_QUERY**: No-op, returns the current
43997cdec54fSDaniel Borkmann  * 		  skb->csum_level.
44007cdec54fSDaniel Borkmann  * 	Return
44017cdec54fSDaniel Borkmann  * 		0 on success, or a negative error in case of failure. In the
44027cdec54fSDaniel Borkmann  * 		case of **BPF_CSUM_LEVEL_QUERY**, the current skb->csum_level
44037cdec54fSDaniel Borkmann  * 		is returned or the error code -EACCES in case the skb is not
44047cdec54fSDaniel Borkmann  * 		subject to CHECKSUM_UNNECESSARY.
4405af7ec138SYonghong Song  *
4406af7ec138SYonghong Song  * struct tcp6_sock *bpf_skc_to_tcp6_sock(void *sk)
4407af7ec138SYonghong Song  *	Description
4408af7ec138SYonghong Song  *		Dynamically cast a *sk* pointer to a *tcp6_sock* pointer.
4409af7ec138SYonghong Song  *	Return
4410938c3efdSQuentin Monnet  *		*sk* if casting is valid, or **NULL** otherwise.
4411478cfbdfSYonghong Song  *
4412478cfbdfSYonghong Song  * struct tcp_sock *bpf_skc_to_tcp_sock(void *sk)
4413478cfbdfSYonghong Song  *	Description
4414478cfbdfSYonghong Song  *		Dynamically cast a *sk* pointer to a *tcp_sock* pointer.
4415478cfbdfSYonghong Song  *	Return
4416938c3efdSQuentin Monnet  *		*sk* if casting is valid, or **NULL** otherwise.
4417478cfbdfSYonghong Song  *
4418478cfbdfSYonghong Song  * struct tcp_timewait_sock *bpf_skc_to_tcp_timewait_sock(void *sk)
4419478cfbdfSYonghong Song  * 	Description
4420478cfbdfSYonghong Song  *		Dynamically cast a *sk* pointer to a *tcp_timewait_sock* pointer.
4421478cfbdfSYonghong Song  *	Return
4422938c3efdSQuentin Monnet  *		*sk* if casting is valid, or **NULL** otherwise.
4423478cfbdfSYonghong Song  *
4424478cfbdfSYonghong Song  * struct tcp_request_sock *bpf_skc_to_tcp_request_sock(void *sk)
4425478cfbdfSYonghong Song  * 	Description
4426478cfbdfSYonghong Song  *		Dynamically cast a *sk* pointer to a *tcp_request_sock* pointer.
4427478cfbdfSYonghong Song  *	Return
4428938c3efdSQuentin Monnet  *		*sk* if casting is valid, or **NULL** otherwise.
44290d4fad3eSYonghong Song  *
44300d4fad3eSYonghong Song  * struct udp6_sock *bpf_skc_to_udp6_sock(void *sk)
44310d4fad3eSYonghong Song  * 	Description
44320d4fad3eSYonghong Song  *		Dynamically cast a *sk* pointer to a *udp6_sock* pointer.
44330d4fad3eSYonghong Song  *	Return
4434938c3efdSQuentin Monnet  *		*sk* if casting is valid, or **NULL** otherwise.
4435fa28dcb8SSong Liu  *
4436fa28dcb8SSong Liu  * long bpf_get_task_stack(struct task_struct *task, void *buf, u32 size, u64 flags)
4437fa28dcb8SSong Liu  *	Description
4438fa28dcb8SSong Liu  *		Return a user or a kernel stack in bpf program provided buffer.
4439fa28dcb8SSong Liu  *		To achieve this, the helper needs *task*, which is a valid
4440938c3efdSQuentin Monnet  *		pointer to **struct task_struct**. To store the stacktrace, the
4441fa28dcb8SSong Liu  *		bpf program provides *buf* with a nonnegative *size*.
4442fa28dcb8SSong Liu  *
4443fa28dcb8SSong Liu  *		The last argument, *flags*, holds the number of stack frames to
4444fa28dcb8SSong Liu  *		skip (from 0 to 255), masked with
4445fa28dcb8SSong Liu  *		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
4446fa28dcb8SSong Liu  *		the following flags:
4447fa28dcb8SSong Liu  *
4448fa28dcb8SSong Liu  *		**BPF_F_USER_STACK**
4449fa28dcb8SSong Liu  *			Collect a user space stack instead of a kernel stack.
4450fa28dcb8SSong Liu  *		**BPF_F_USER_BUILD_ID**
4451fa28dcb8SSong Liu  *			Collect buildid+offset instead of ips for user stack,
4452fa28dcb8SSong Liu  *			only valid if **BPF_F_USER_STACK** is also specified.
4453fa28dcb8SSong Liu  *
4454fa28dcb8SSong Liu  *		**bpf_get_task_stack**\ () can collect up to
4455fa28dcb8SSong Liu  *		**PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
4456fa28dcb8SSong Liu  *		to sufficient large buffer size. Note that
4457fa28dcb8SSong Liu  *		this limit can be controlled with the **sysctl** program, and
4458fa28dcb8SSong Liu  *		that it should be manually increased in order to profile long
4459fa28dcb8SSong Liu  *		user stacks (such as stacks for Java programs). To do so, use:
4460fa28dcb8SSong Liu  *
4461fa28dcb8SSong Liu  *		::
4462fa28dcb8SSong Liu  *
4463fa28dcb8SSong Liu  *			# sysctl kernel.perf_event_max_stack=<new value>
4464fa28dcb8SSong Liu  *	Return
4465ee2a0988SNamhyung Kim  * 		The non-negative copied *buf* length equal to or less than
4466ee2a0988SNamhyung Kim  * 		*size* on success, or a negative error in case of failure.
4467fa28dcb8SSong Liu  *
44680813a841SMartin KaFai Lau  * long bpf_load_hdr_opt(struct bpf_sock_ops *skops, void *searchby_res, u32 len, u64 flags)
44690813a841SMartin KaFai Lau  *	Description
44700813a841SMartin KaFai Lau  *		Load header option.  Support reading a particular TCP header
4471938c3efdSQuentin Monnet  *		option for bpf program (**BPF_PROG_TYPE_SOCK_OPS**).
44720813a841SMartin KaFai Lau  *
44730813a841SMartin KaFai Lau  *		If *flags* is 0, it will search the option from the
4474938c3efdSQuentin Monnet  *		*skops*\ **->skb_data**.  The comment in **struct bpf_sock_ops**
44750813a841SMartin KaFai Lau  *		has details on what skb_data contains under different
4476938c3efdSQuentin Monnet  *		*skops*\ **->op**.
44770813a841SMartin KaFai Lau  *
44780813a841SMartin KaFai Lau  *		The first byte of the *searchby_res* specifies the
44790813a841SMartin KaFai Lau  *		kind that it wants to search.
44800813a841SMartin KaFai Lau  *
44810813a841SMartin KaFai Lau  *		If the searching kind is an experimental kind
44820813a841SMartin KaFai Lau  *		(i.e. 253 or 254 according to RFC6994).  It also
44830813a841SMartin KaFai Lau  *		needs to specify the "magic" which is either
44840813a841SMartin KaFai Lau  *		2 bytes or 4 bytes.  It then also needs to
44850813a841SMartin KaFai Lau  *		specify the size of the magic by using
44860813a841SMartin KaFai Lau  *		the 2nd byte which is "kind-length" of a TCP
44870813a841SMartin KaFai Lau  *		header option and the "kind-length" also
44880813a841SMartin KaFai Lau  *		includes the first 2 bytes "kind" and "kind-length"
44890813a841SMartin KaFai Lau  *		itself as a normal TCP header option also does.
44900813a841SMartin KaFai Lau  *
44910813a841SMartin KaFai Lau  *		For example, to search experimental kind 254 with
44920813a841SMartin KaFai Lau  *		2 byte magic 0xeB9F, the searchby_res should be
44930813a841SMartin KaFai Lau  *		[ 254, 4, 0xeB, 0x9F, 0, 0, .... 0 ].
44940813a841SMartin KaFai Lau  *
44950813a841SMartin KaFai Lau  *		To search for the standard window scale option (3),
4496938c3efdSQuentin Monnet  *		the *searchby_res* should be [ 3, 0, 0, .... 0 ].
44970813a841SMartin KaFai Lau  *		Note, kind-length must be 0 for regular option.
44980813a841SMartin KaFai Lau  *
44990813a841SMartin KaFai Lau  *		Searching for No-Op (0) and End-of-Option-List (1) are
45000813a841SMartin KaFai Lau  *		not supported.
45010813a841SMartin KaFai Lau  *
45020813a841SMartin KaFai Lau  *		*len* must be at least 2 bytes which is the minimal size
45030813a841SMartin KaFai Lau  *		of a header option.
45040813a841SMartin KaFai Lau  *
45050813a841SMartin KaFai Lau  *		Supported flags:
4506938c3efdSQuentin Monnet  *
45070813a841SMartin KaFai Lau  *		* **BPF_LOAD_HDR_OPT_TCP_SYN** to search from the
45080813a841SMartin KaFai Lau  *		  saved_syn packet or the just-received syn packet.
45090813a841SMartin KaFai Lau  *
45100813a841SMartin KaFai Lau  *	Return
45110813a841SMartin KaFai Lau  *		> 0 when found, the header option is copied to *searchby_res*.
4512938c3efdSQuentin Monnet  *		The return value is the total length copied. On failure, a
4513938c3efdSQuentin Monnet  *		negative error code is returned:
45140813a841SMartin KaFai Lau  *
4515938c3efdSQuentin Monnet  *		**-EINVAL** if a parameter is invalid.
45160813a841SMartin KaFai Lau  *
4517938c3efdSQuentin Monnet  *		**-ENOMSG** if the option is not found.
45180813a841SMartin KaFai Lau  *
4519938c3efdSQuentin Monnet  *		**-ENOENT** if no syn packet is available when
4520938c3efdSQuentin Monnet  *		**BPF_LOAD_HDR_OPT_TCP_SYN** is used.
45210813a841SMartin KaFai Lau  *
4522938c3efdSQuentin Monnet  *		**-ENOSPC** if there is not enough space.  Only *len* number of
45230813a841SMartin KaFai Lau  *		bytes are copied.
45240813a841SMartin KaFai Lau  *
4525938c3efdSQuentin Monnet  *		**-EFAULT** on failure to parse the header options in the
4526938c3efdSQuentin Monnet  *		packet.
45270813a841SMartin KaFai Lau  *
4528938c3efdSQuentin Monnet  *		**-EPERM** if the helper cannot be used under the current
4529938c3efdSQuentin Monnet  *		*skops*\ **->op**.
45300813a841SMartin KaFai Lau  *
45310813a841SMartin KaFai Lau  * long bpf_store_hdr_opt(struct bpf_sock_ops *skops, const void *from, u32 len, u64 flags)
45320813a841SMartin KaFai Lau  *	Description
45330813a841SMartin KaFai Lau  *		Store header option.  The data will be copied
45340813a841SMartin KaFai Lau  *		from buffer *from* with length *len* to the TCP header.
45350813a841SMartin KaFai Lau  *
45360813a841SMartin KaFai Lau  *		The buffer *from* should have the whole option that
45370813a841SMartin KaFai Lau  *		includes the kind, kind-length, and the actual
45380813a841SMartin KaFai Lau  *		option data.  The *len* must be at least kind-length
45390813a841SMartin KaFai Lau  *		long.  The kind-length does not have to be 4 byte
45400813a841SMartin KaFai Lau  *		aligned.  The kernel will take care of the padding
45410813a841SMartin KaFai Lau  *		and setting the 4 bytes aligned value to th->doff.
45420813a841SMartin KaFai Lau  *
45430813a841SMartin KaFai Lau  *		This helper will check for duplicated option
45440813a841SMartin KaFai Lau  *		by searching the same option in the outgoing skb.
45450813a841SMartin KaFai Lau  *
45460813a841SMartin KaFai Lau  *		This helper can only be called during
4547938c3efdSQuentin Monnet  *		**BPF_SOCK_OPS_WRITE_HDR_OPT_CB**.
45480813a841SMartin KaFai Lau  *
45490813a841SMartin KaFai Lau  *	Return
45500813a841SMartin KaFai Lau  *		0 on success, or negative error in case of failure:
45510813a841SMartin KaFai Lau  *
4552938c3efdSQuentin Monnet  *		**-EINVAL** If param is invalid.
45530813a841SMartin KaFai Lau  *
4554938c3efdSQuentin Monnet  *		**-ENOSPC** if there is not enough space in the header.
45550813a841SMartin KaFai Lau  *		Nothing has been written
45560813a841SMartin KaFai Lau  *
4557938c3efdSQuentin Monnet  *		**-EEXIST** if the option already exists.
45580813a841SMartin KaFai Lau  *
4559aa75622cSQuentin Monnet  *		**-EFAULT** on failure to parse the existing header options.
45600813a841SMartin KaFai Lau  *
4561938c3efdSQuentin Monnet  *		**-EPERM** if the helper cannot be used under the current
4562938c3efdSQuentin Monnet  *		*skops*\ **->op**.
45630813a841SMartin KaFai Lau  *
45640813a841SMartin KaFai Lau  * long bpf_reserve_hdr_opt(struct bpf_sock_ops *skops, u32 len, u64 flags)
45650813a841SMartin KaFai Lau  *	Description
45660813a841SMartin KaFai Lau  *		Reserve *len* bytes for the bpf header option.  The
4567938c3efdSQuentin Monnet  *		space will be used by **bpf_store_hdr_opt**\ () later in
4568938c3efdSQuentin Monnet  *		**BPF_SOCK_OPS_WRITE_HDR_OPT_CB**.
45690813a841SMartin KaFai Lau  *
4570938c3efdSQuentin Monnet  *		If **bpf_reserve_hdr_opt**\ () is called multiple times,
45710813a841SMartin KaFai Lau  *		the total number of bytes will be reserved.
45720813a841SMartin KaFai Lau  *
45730813a841SMartin KaFai Lau  *		This helper can only be called during
4574938c3efdSQuentin Monnet  *		**BPF_SOCK_OPS_HDR_OPT_LEN_CB**.
45750813a841SMartin KaFai Lau  *
45760813a841SMartin KaFai Lau  *	Return
45770813a841SMartin KaFai Lau  *		0 on success, or negative error in case of failure:
45780813a841SMartin KaFai Lau  *
4579938c3efdSQuentin Monnet  *		**-EINVAL** if a parameter is invalid.
45800813a841SMartin KaFai Lau  *
4581938c3efdSQuentin Monnet  *		**-ENOSPC** if there is not enough space in the header.
45820813a841SMartin KaFai Lau  *
4583938c3efdSQuentin Monnet  *		**-EPERM** if the helper cannot be used under the current
4584938c3efdSQuentin Monnet  *		*skops*\ **->op**.
45856e22ab9dSJiri Olsa  *
45868ea63684SKP Singh  * void *bpf_inode_storage_get(struct bpf_map *map, void *inode, void *value, u64 flags)
45878ea63684SKP Singh  *	Description
45888ea63684SKP Singh  *		Get a bpf_local_storage from an *inode*.
45898ea63684SKP Singh  *
45908ea63684SKP Singh  *		Logically, it could be thought of as getting the value from
45918ea63684SKP Singh  *		a *map* with *inode* as the **key**.  From this
45928ea63684SKP Singh  *		perspective,  the usage is not much different from
45938ea63684SKP Singh  *		**bpf_map_lookup_elem**\ (*map*, **&**\ *inode*) except this
45948ea63684SKP Singh  *		helper enforces the key must be an inode and the map must also
45958ea63684SKP Singh  *		be a **BPF_MAP_TYPE_INODE_STORAGE**.
45968ea63684SKP Singh  *
45978ea63684SKP Singh  *		Underneath, the value is stored locally at *inode* instead of
45988ea63684SKP Singh  *		the *map*.  The *map* is used as the bpf-local-storage
45998ea63684SKP Singh  *		"type". The bpf-local-storage "type" (i.e. the *map*) is
46008ea63684SKP Singh  *		searched against all bpf_local_storage residing at *inode*.
46018ea63684SKP Singh  *
46028ea63684SKP Singh  *		An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
46038ea63684SKP Singh  *		used such that a new bpf_local_storage will be
46048ea63684SKP Singh  *		created if one does not exist.  *value* can be used
46058ea63684SKP Singh  *		together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
46068ea63684SKP Singh  *		the initial value of a bpf_local_storage.  If *value* is
46078ea63684SKP Singh  *		**NULL**, the new bpf_local_storage will be zero initialized.
46088ea63684SKP Singh  *	Return
46098ea63684SKP Singh  *		A bpf_local_storage pointer is returned on success.
46108ea63684SKP Singh  *
46118ea63684SKP Singh  *		**NULL** if not found or there was an error in adding
46128ea63684SKP Singh  *		a new bpf_local_storage.
46138ea63684SKP Singh  *
46148ea63684SKP Singh  * int bpf_inode_storage_delete(struct bpf_map *map, void *inode)
46158ea63684SKP Singh  *	Description
46168ea63684SKP Singh  *		Delete a bpf_local_storage from an *inode*.
46178ea63684SKP Singh  *	Return
46188ea63684SKP Singh  *		0 on success.
46198ea63684SKP Singh  *
46208ea63684SKP Singh  *		**-ENOENT** if the bpf_local_storage cannot be found.
46216e22ab9dSJiri Olsa  *
46226e22ab9dSJiri Olsa  * long bpf_d_path(struct path *path, char *buf, u32 sz)
46236e22ab9dSJiri Olsa  *	Description
4624938c3efdSQuentin Monnet  *		Return full path for given **struct path** object, which
4625938c3efdSQuentin Monnet  *		needs to be the kernel BTF *path* object. The path is
4626938c3efdSQuentin Monnet  *		returned in the provided buffer *buf* of size *sz* and
46276e22ab9dSJiri Olsa  *		is zero terminated.
46286e22ab9dSJiri Olsa  *
46296e22ab9dSJiri Olsa  *	Return
46306e22ab9dSJiri Olsa  *		On success, the strictly positive length of the string,
46316e22ab9dSJiri Olsa  *		including the trailing NUL character. On error, a negative
46326e22ab9dSJiri Olsa  *		value.
463307be4c4aSAlexei Starovoitov  *
463407be4c4aSAlexei Starovoitov  * long bpf_copy_from_user(void *dst, u32 size, const void *user_ptr)
463507be4c4aSAlexei Starovoitov  * 	Description
463607be4c4aSAlexei Starovoitov  * 		Read *size* bytes from user space address *user_ptr* and store
4637938c3efdSQuentin Monnet  * 		the data in *dst*. This is a wrapper of **copy_from_user**\ ().
463807be4c4aSAlexei Starovoitov  * 	Return
463907be4c4aSAlexei Starovoitov  * 		0 on success, or a negative error in case of failure.
4640c4d0bfb4SAlan Maguire  *
4641c4d0bfb4SAlan Maguire  * long bpf_snprintf_btf(char *str, u32 str_size, struct btf_ptr *ptr, u32 btf_ptr_size, u64 flags)
4642c4d0bfb4SAlan Maguire  *	Description
4643c4d0bfb4SAlan Maguire  *		Use BTF to store a string representation of *ptr*->ptr in *str*,
4644c4d0bfb4SAlan Maguire  *		using *ptr*->type_id.  This value should specify the type
4645c4d0bfb4SAlan Maguire  *		that *ptr*->ptr points to. LLVM __builtin_btf_type_id(type, 1)
4646c4d0bfb4SAlan Maguire  *		can be used to look up vmlinux BTF type ids. Traversing the
4647c4d0bfb4SAlan Maguire  *		data structure using BTF, the type information and values are
4648c4d0bfb4SAlan Maguire  *		stored in the first *str_size* - 1 bytes of *str*.  Safe copy of
4649c4d0bfb4SAlan Maguire  *		the pointer data is carried out to avoid kernel crashes during
4650c4d0bfb4SAlan Maguire  *		operation.  Smaller types can use string space on the stack;
4651c4d0bfb4SAlan Maguire  *		larger programs can use map data to store the string
4652c4d0bfb4SAlan Maguire  *		representation.
4653c4d0bfb4SAlan Maguire  *
4654c4d0bfb4SAlan Maguire  *		The string can be subsequently shared with userspace via
4655c4d0bfb4SAlan Maguire  *		bpf_perf_event_output() or ring buffer interfaces.
4656c4d0bfb4SAlan Maguire  *		bpf_trace_printk() is to be avoided as it places too small
4657c4d0bfb4SAlan Maguire  *		a limit on string size to be useful.
4658c4d0bfb4SAlan Maguire  *
4659c4d0bfb4SAlan Maguire  *		*flags* is a combination of
4660c4d0bfb4SAlan Maguire  *
4661c4d0bfb4SAlan Maguire  *		**BTF_F_COMPACT**
4662c4d0bfb4SAlan Maguire  *			no formatting around type information
4663c4d0bfb4SAlan Maguire  *		**BTF_F_NONAME**
4664c4d0bfb4SAlan Maguire  *			no struct/union member names/types
4665c4d0bfb4SAlan Maguire  *		**BTF_F_PTR_RAW**
4666c4d0bfb4SAlan Maguire  *			show raw (unobfuscated) pointer values;
4667c4d0bfb4SAlan Maguire  *			equivalent to printk specifier %px.
4668c4d0bfb4SAlan Maguire  *		**BTF_F_ZERO**
4669c4d0bfb4SAlan Maguire  *			show zero-valued struct/union members; they
4670c4d0bfb4SAlan Maguire  *			are not displayed by default
4671c4d0bfb4SAlan Maguire  *
4672c4d0bfb4SAlan Maguire  *	Return
4673c4d0bfb4SAlan Maguire  *		The number of bytes that were written (or would have been
4674c4d0bfb4SAlan Maguire  *		written if output had to be truncated due to string size),
4675c4d0bfb4SAlan Maguire  *		or a negative error in cases of failure.
4676eb411377SAlan Maguire  *
4677eb411377SAlan Maguire  * long bpf_seq_printf_btf(struct seq_file *m, struct btf_ptr *ptr, u32 ptr_size, u64 flags)
4678eb411377SAlan Maguire  *	Description
4679eb411377SAlan Maguire  *		Use BTF to write to seq_write a string representation of
4680eb411377SAlan Maguire  *		*ptr*->ptr, using *ptr*->type_id as per bpf_snprintf_btf().
4681eb411377SAlan Maguire  *		*flags* are identical to those used for bpf_snprintf_btf.
4682eb411377SAlan Maguire  *	Return
4683eb411377SAlan Maguire  *		0 on success or a negative error in case of failure.
4684b426ce83SDaniel Borkmann  *
4685b426ce83SDaniel Borkmann  * u64 bpf_skb_cgroup_classid(struct sk_buff *skb)
4686b426ce83SDaniel Borkmann  * 	Description
4687b426ce83SDaniel Borkmann  * 		See **bpf_get_cgroup_classid**\ () for the main description.
4688b426ce83SDaniel Borkmann  * 		This helper differs from **bpf_get_cgroup_classid**\ () in that
4689b426ce83SDaniel Borkmann  * 		the cgroup v1 net_cls class is retrieved only from the *skb*'s
4690b426ce83SDaniel Borkmann  * 		associated socket instead of the current process.
4691b426ce83SDaniel Borkmann  * 	Return
4692b426ce83SDaniel Borkmann  * 		The id is returned or 0 in case the id could not be retrieved.
4693b4ab3141SDaniel Borkmann  *
4694ba452c9eSToke Høiland-Jørgensen  * long bpf_redirect_neigh(u32 ifindex, struct bpf_redir_neigh *params, int plen, u64 flags)
4695b4ab3141SDaniel Borkmann  * 	Description
4696b4ab3141SDaniel Borkmann  * 		Redirect the packet to another net device of index *ifindex*
4697b4ab3141SDaniel Borkmann  * 		and fill in L2 addresses from neighboring subsystem. This helper
4698b4ab3141SDaniel Borkmann  * 		is somewhat similar to **bpf_redirect**\ (), except that it
4699dd2ce6a5SDaniel Borkmann  * 		populates L2 addresses as well, meaning, internally, the helper
4700ba452c9eSToke Høiland-Jørgensen  * 		relies on the neighbor lookup for the L2 address of the nexthop.
4701ba452c9eSToke Høiland-Jørgensen  *
4702ba452c9eSToke Høiland-Jørgensen  * 		The helper will perform a FIB lookup based on the skb's
4703ba452c9eSToke Høiland-Jørgensen  * 		networking header to get the address of the next hop, unless
4704ba452c9eSToke Høiland-Jørgensen  * 		this is supplied by the caller in the *params* argument. The
4705ba452c9eSToke Høiland-Jørgensen  * 		*plen* argument indicates the len of *params* and should be set
4706ba452c9eSToke Høiland-Jørgensen  * 		to 0 if *params* is NULL.
4707dd2ce6a5SDaniel Borkmann  *
4708b4ab3141SDaniel Borkmann  * 		The *flags* argument is reserved and must be 0. The helper is
4709dd2ce6a5SDaniel Borkmann  * 		currently only supported for tc BPF program types, and enabled
4710dd2ce6a5SDaniel Borkmann  * 		for IPv4 and IPv6 protocols.
4711b4ab3141SDaniel Borkmann  * 	Return
4712b4ab3141SDaniel Borkmann  * 		The helper returns **TC_ACT_REDIRECT** on success or
4713b4ab3141SDaniel Borkmann  * 		**TC_ACT_SHOT** on error.
4714eaa6bcb7SHao Luo  *
4715eaa6bcb7SHao Luo  * void *bpf_per_cpu_ptr(const void *percpu_ptr, u32 cpu)
4716eaa6bcb7SHao Luo  *     Description
4717eaa6bcb7SHao Luo  *             Take a pointer to a percpu ksym, *percpu_ptr*, and return a
4718eaa6bcb7SHao Luo  *             pointer to the percpu kernel variable on *cpu*. A ksym is an
4719eaa6bcb7SHao Luo  *             extern variable decorated with '__ksym'. For ksym, there is a
4720eaa6bcb7SHao Luo  *             global var (either static or global) defined of the same name
4721eaa6bcb7SHao Luo  *             in the kernel. The ksym is percpu if the global var is percpu.
4722eaa6bcb7SHao Luo  *             The returned pointer points to the global percpu var on *cpu*.
4723eaa6bcb7SHao Luo  *
4724eaa6bcb7SHao Luo  *             bpf_per_cpu_ptr() has the same semantic as per_cpu_ptr() in the
4725eaa6bcb7SHao Luo  *             kernel, except that bpf_per_cpu_ptr() may return NULL. This
4726eaa6bcb7SHao Luo  *             happens if *cpu* is larger than nr_cpu_ids. The caller of
4727eaa6bcb7SHao Luo  *             bpf_per_cpu_ptr() must check the returned value.
4728eaa6bcb7SHao Luo  *     Return
4729eaa6bcb7SHao Luo  *             A pointer pointing to the kernel percpu variable on *cpu*, or
4730eaa6bcb7SHao Luo  *             NULL, if *cpu* is invalid.
473163d9b80dSHao Luo  *
473263d9b80dSHao Luo  * void *bpf_this_cpu_ptr(const void *percpu_ptr)
473363d9b80dSHao Luo  *	Description
473463d9b80dSHao Luo  *		Take a pointer to a percpu ksym, *percpu_ptr*, and return a
473563d9b80dSHao Luo  *		pointer to the percpu kernel variable on this cpu. See the
473663d9b80dSHao Luo  *		description of 'ksym' in **bpf_per_cpu_ptr**\ ().
473763d9b80dSHao Luo  *
473863d9b80dSHao Luo  *		bpf_this_cpu_ptr() has the same semantic as this_cpu_ptr() in
473963d9b80dSHao Luo  *		the kernel. Different from **bpf_per_cpu_ptr**\ (), it would
474063d9b80dSHao Luo  *		never return NULL.
474163d9b80dSHao Luo  *	Return
474263d9b80dSHao Luo  *		A pointer pointing to the kernel percpu variable on this cpu.
47439aa1206eSDaniel Borkmann  *
47449aa1206eSDaniel Borkmann  * long bpf_redirect_peer(u32 ifindex, u64 flags)
47459aa1206eSDaniel Borkmann  * 	Description
47469aa1206eSDaniel Borkmann  * 		Redirect the packet to another net device of index *ifindex*.
47479aa1206eSDaniel Borkmann  * 		This helper is somewhat similar to **bpf_redirect**\ (), except
47489aa1206eSDaniel Borkmann  * 		that the redirection happens to the *ifindex*' peer device and
47499aa1206eSDaniel Borkmann  * 		the netns switch takes place from ingress to ingress without
47509aa1206eSDaniel Borkmann  * 		going through the CPU's backlog queue.
47519aa1206eSDaniel Borkmann  *
47529aa1206eSDaniel Borkmann  * 		The *flags* argument is reserved and must be 0. The helper is
47539aa1206eSDaniel Borkmann  * 		currently only supported for tc BPF program types at the ingress
47549aa1206eSDaniel Borkmann  * 		hook and for veth device types. The peer device must reside in a
47559aa1206eSDaniel Borkmann  * 		different network namespace.
47569aa1206eSDaniel Borkmann  * 	Return
47579aa1206eSDaniel Borkmann  * 		The helper returns **TC_ACT_REDIRECT** on success or
47589aa1206eSDaniel Borkmann  * 		**TC_ACT_SHOT** on error.
47594cf1bc1fSKP Singh  *
47604cf1bc1fSKP Singh  * void *bpf_task_storage_get(struct bpf_map *map, struct task_struct *task, void *value, u64 flags)
47614cf1bc1fSKP Singh  *	Description
47624cf1bc1fSKP Singh  *		Get a bpf_local_storage from the *task*.
47634cf1bc1fSKP Singh  *
47644cf1bc1fSKP Singh  *		Logically, it could be thought of as getting the value from
47654cf1bc1fSKP Singh  *		a *map* with *task* as the **key**.  From this
47664cf1bc1fSKP Singh  *		perspective,  the usage is not much different from
47674cf1bc1fSKP Singh  *		**bpf_map_lookup_elem**\ (*map*, **&**\ *task*) except this
4768aa75622cSQuentin Monnet  *		helper enforces the key must be a task_struct and the map must also
47694cf1bc1fSKP Singh  *		be a **BPF_MAP_TYPE_TASK_STORAGE**.
47704cf1bc1fSKP Singh  *
47714cf1bc1fSKP Singh  *		Underneath, the value is stored locally at *task* instead of
47724cf1bc1fSKP Singh  *		the *map*.  The *map* is used as the bpf-local-storage
47734cf1bc1fSKP Singh  *		"type". The bpf-local-storage "type" (i.e. the *map*) is
47744cf1bc1fSKP Singh  *		searched against all bpf_local_storage residing at *task*.
47754cf1bc1fSKP Singh  *
47764cf1bc1fSKP Singh  *		An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
47774cf1bc1fSKP Singh  *		used such that a new bpf_local_storage will be
47784cf1bc1fSKP Singh  *		created if one does not exist.  *value* can be used
47794cf1bc1fSKP Singh  *		together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
47804cf1bc1fSKP Singh  *		the initial value of a bpf_local_storage.  If *value* is
47814cf1bc1fSKP Singh  *		**NULL**, the new bpf_local_storage will be zero initialized.
47824cf1bc1fSKP Singh  *	Return
47834cf1bc1fSKP Singh  *		A bpf_local_storage pointer is returned on success.
47844cf1bc1fSKP Singh  *
47854cf1bc1fSKP Singh  *		**NULL** if not found or there was an error in adding
47864cf1bc1fSKP Singh  *		a new bpf_local_storage.
47874cf1bc1fSKP Singh  *
47884cf1bc1fSKP Singh  * long bpf_task_storage_delete(struct bpf_map *map, struct task_struct *task)
47894cf1bc1fSKP Singh  *	Description
47904cf1bc1fSKP Singh  *		Delete a bpf_local_storage from a *task*.
47914cf1bc1fSKP Singh  *	Return
47924cf1bc1fSKP Singh  *		0 on success.
47934cf1bc1fSKP Singh  *
47944cf1bc1fSKP Singh  *		**-ENOENT** if the bpf_local_storage cannot be found.
47953ca1032aSKP Singh  *
47963ca1032aSKP Singh  * struct task_struct *bpf_get_current_task_btf(void)
47973ca1032aSKP Singh  *	Description
47983ca1032aSKP Singh  *		Return a BTF pointer to the "current" task.
47993ca1032aSKP Singh  *		This pointer can also be used in helpers that accept an
48003ca1032aSKP Singh  *		*ARG_PTR_TO_BTF_ID* of type *task_struct*.
48013ca1032aSKP Singh  *	Return
48023ca1032aSKP Singh  *		Pointer to the current task.
48033f6719c7SKP Singh  *
48043f6719c7SKP Singh  * long bpf_bprm_opts_set(struct linux_binprm *bprm, u64 flags)
48053f6719c7SKP Singh  *	Description
48063f6719c7SKP Singh  *		Set or clear certain options on *bprm*:
48073f6719c7SKP Singh  *
48083f6719c7SKP Singh  *		**BPF_F_BPRM_SECUREEXEC** Set the secureexec bit
48093f6719c7SKP Singh  *		which sets the **AT_SECURE** auxv for glibc. The bit
48103f6719c7SKP Singh  *		is cleared if the flag is not specified.
48113f6719c7SKP Singh  *	Return
48123f6719c7SKP Singh  *		**-EINVAL** if invalid *flags* are passed, zero otherwise.
4813d0551261SDmitrii Banshchikov  *
4814d0551261SDmitrii Banshchikov  * u64 bpf_ktime_get_coarse_ns(void)
4815d0551261SDmitrii Banshchikov  * 	Description
4816d0551261SDmitrii Banshchikov  * 		Return a coarse-grained version of the time elapsed since
4817d0551261SDmitrii Banshchikov  * 		system boot, in nanoseconds. Does not include time the system
4818d0551261SDmitrii Banshchikov  * 		was suspended.
4819d0551261SDmitrii Banshchikov  *
4820d0551261SDmitrii Banshchikov  * 		See: **clock_gettime**\ (**CLOCK_MONOTONIC_COARSE**)
4821d0551261SDmitrii Banshchikov  * 	Return
4822d0551261SDmitrii Banshchikov  * 		Current *ktime*.
482327672f0dSKP Singh  *
482427672f0dSKP Singh  * long bpf_ima_inode_hash(struct inode *inode, void *dst, u32 size)
482527672f0dSKP Singh  *	Description
4826aa75622cSQuentin Monnet  *		Returns the stored IMA hash of the *inode* (if it's available).
482727672f0dSKP Singh  *		If the hash is larger than *size*, then only *size*
482827672f0dSKP Singh  *		bytes will be copied to *dst*
482927672f0dSKP Singh  *	Return
483027672f0dSKP Singh  *		The **hash_algo** is returned on success,
483127672f0dSKP Singh  *		**-EOPNOTSUP** if IMA is disabled or **-EINVAL** if
483227672f0dSKP Singh  *		invalid arguments are passed.
48334f19cab7SFlorent Revest  *
48344f19cab7SFlorent Revest  * struct socket *bpf_sock_from_file(struct file *file)
48354f19cab7SFlorent Revest  *	Description
48364f19cab7SFlorent Revest  *		If the given file represents a socket, returns the associated
48374f19cab7SFlorent Revest  *		socket.
48384f19cab7SFlorent Revest  *	Return
48394f19cab7SFlorent Revest  *		A pointer to a struct socket on success or NULL if the file is
48404f19cab7SFlorent Revest  *		not a socket.
484134b2021cSJesper Dangaard Brouer  *
484234b2021cSJesper Dangaard Brouer  * long bpf_check_mtu(void *ctx, u32 ifindex, u32 *mtu_len, s32 len_diff, u64 flags)
484334b2021cSJesper Dangaard Brouer  *	Description
4844e5e35e75SJesper Dangaard Brouer  *		Check packet size against exceeding MTU of net device (based
484534b2021cSJesper Dangaard Brouer  *		on *ifindex*).  This helper will likely be used in combination
484634b2021cSJesper Dangaard Brouer  *		with helpers that adjust/change the packet size.
484734b2021cSJesper Dangaard Brouer  *
484834b2021cSJesper Dangaard Brouer  *		The argument *len_diff* can be used for querying with a planned
484934b2021cSJesper Dangaard Brouer  *		size change. This allows to check MTU prior to changing packet
4850aa75622cSQuentin Monnet  *		ctx. Providing a *len_diff* adjustment that is larger than the
485134b2021cSJesper Dangaard Brouer  *		actual packet size (resulting in negative packet size) will in
4852aa75622cSQuentin Monnet  *		principle not exceed the MTU, which is why it is not considered
4853aa75622cSQuentin Monnet  *		a failure.  Other BPF helpers are needed for performing the
4854aa75622cSQuentin Monnet  *		planned size change; therefore the responsibility for catching
4855aa75622cSQuentin Monnet  *		a negative packet size belongs in those helpers.
485634b2021cSJesper Dangaard Brouer  *
485734b2021cSJesper Dangaard Brouer  *		Specifying *ifindex* zero means the MTU check is performed
485834b2021cSJesper Dangaard Brouer  *		against the current net device.  This is practical if this isn't
485934b2021cSJesper Dangaard Brouer  *		used prior to redirect.
486034b2021cSJesper Dangaard Brouer  *
4861e5e35e75SJesper Dangaard Brouer  *		On input *mtu_len* must be a valid pointer, else verifier will
4862e5e35e75SJesper Dangaard Brouer  *		reject BPF program.  If the value *mtu_len* is initialized to
4863e5e35e75SJesper Dangaard Brouer  *		zero then the ctx packet size is use.  When value *mtu_len* is
4864e5e35e75SJesper Dangaard Brouer  *		provided as input this specify the L3 length that the MTU check
4865e5e35e75SJesper Dangaard Brouer  *		is done against. Remember XDP and TC length operate at L2, but
4866e5e35e75SJesper Dangaard Brouer  *		this value is L3 as this correlate to MTU and IP-header tot_len
4867e5e35e75SJesper Dangaard Brouer  *		values which are L3 (similar behavior as bpf_fib_lookup).
4868e5e35e75SJesper Dangaard Brouer  *
486934b2021cSJesper Dangaard Brouer  *		The Linux kernel route table can configure MTUs on a more
487034b2021cSJesper Dangaard Brouer  *		specific per route level, which is not provided by this helper.
487134b2021cSJesper Dangaard Brouer  *		For route level MTU checks use the **bpf_fib_lookup**\ ()
487234b2021cSJesper Dangaard Brouer  *		helper.
487334b2021cSJesper Dangaard Brouer  *
487434b2021cSJesper Dangaard Brouer  *		*ctx* is either **struct xdp_md** for XDP programs or
487534b2021cSJesper Dangaard Brouer  *		**struct sk_buff** for tc cls_act programs.
487634b2021cSJesper Dangaard Brouer  *
487734b2021cSJesper Dangaard Brouer  *		The *flags* argument can be a combination of one or more of the
487834b2021cSJesper Dangaard Brouer  *		following values:
487934b2021cSJesper Dangaard Brouer  *
488034b2021cSJesper Dangaard Brouer  *		**BPF_MTU_CHK_SEGS**
488134b2021cSJesper Dangaard Brouer  *			This flag will only works for *ctx* **struct sk_buff**.
488234b2021cSJesper Dangaard Brouer  *			If packet context contains extra packet segment buffers
488334b2021cSJesper Dangaard Brouer  *			(often knows as GSO skb), then MTU check is harder to
488434b2021cSJesper Dangaard Brouer  *			check at this point, because in transmit path it is
488534b2021cSJesper Dangaard Brouer  *			possible for the skb packet to get re-segmented
488634b2021cSJesper Dangaard Brouer  *			(depending on net device features).  This could still be
488734b2021cSJesper Dangaard Brouer  *			a MTU violation, so this flag enables performing MTU
488834b2021cSJesper Dangaard Brouer  *			check against segments, with a different violation
488934b2021cSJesper Dangaard Brouer  *			return code to tell it apart. Check cannot use len_diff.
489034b2021cSJesper Dangaard Brouer  *
489134b2021cSJesper Dangaard Brouer  *		On return *mtu_len* pointer contains the MTU value of the net
489234b2021cSJesper Dangaard Brouer  *		device.  Remember the net device configured MTU is the L3 size,
4893e5e35e75SJesper Dangaard Brouer  *		which is returned here and XDP and TC length operate at L2.
489434b2021cSJesper Dangaard Brouer  *		Helper take this into account for you, but remember when using
4895e5e35e75SJesper Dangaard Brouer  *		MTU value in your BPF-code.
489634b2021cSJesper Dangaard Brouer  *
489734b2021cSJesper Dangaard Brouer  *	Return
489834b2021cSJesper Dangaard Brouer  *		* 0 on success, and populate MTU value in *mtu_len* pointer.
489934b2021cSJesper Dangaard Brouer  *
490034b2021cSJesper Dangaard Brouer  *		* < 0 if any input argument is invalid (*mtu_len* not updated)
490134b2021cSJesper Dangaard Brouer  *
490234b2021cSJesper Dangaard Brouer  *		MTU violations return positive values, but also populate MTU
490334b2021cSJesper Dangaard Brouer  *		value in *mtu_len* pointer, as this can be needed for
490434b2021cSJesper Dangaard Brouer  *		implementing PMTU handing:
490534b2021cSJesper Dangaard Brouer  *
490634b2021cSJesper Dangaard Brouer  *		* **BPF_MTU_CHK_RET_FRAG_NEEDED**
490734b2021cSJesper Dangaard Brouer  *		* **BPF_MTU_CHK_RET_SEGS_TOOBIG**
490834b2021cSJesper Dangaard Brouer  *
490969c087baSYonghong Song  * long bpf_for_each_map_elem(struct bpf_map *map, void *callback_fn, void *callback_ctx, u64 flags)
491069c087baSYonghong Song  *	Description
491169c087baSYonghong Song  *		For each element in **map**, call **callback_fn** function with
491269c087baSYonghong Song  *		**map**, **callback_ctx** and other map-specific parameters.
491369c087baSYonghong Song  *		The **callback_fn** should be a static function and
491469c087baSYonghong Song  *		the **callback_ctx** should be a pointer to the stack.
491569c087baSYonghong Song  *		The **flags** is used to control certain aspects of the helper.
491669c087baSYonghong Song  *		Currently, the **flags** must be 0.
491769c087baSYonghong Song  *
491869c087baSYonghong Song  *		The following are a list of supported map types and their
491969c087baSYonghong Song  *		respective expected callback signatures:
492069c087baSYonghong Song  *
492169c087baSYonghong Song  *		BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_PERCPU_HASH,
492269c087baSYonghong Song  *		BPF_MAP_TYPE_LRU_HASH, BPF_MAP_TYPE_LRU_PERCPU_HASH,
492369c087baSYonghong Song  *		BPF_MAP_TYPE_ARRAY, BPF_MAP_TYPE_PERCPU_ARRAY
492469c087baSYonghong Song  *
492569c087baSYonghong Song  *		long (\*callback_fn)(struct bpf_map \*map, const void \*key, void \*value, void \*ctx);
492669c087baSYonghong Song  *
492769c087baSYonghong Song  *		For per_cpu maps, the map_value is the value on the cpu where the
492869c087baSYonghong Song  *		bpf_prog is running.
492969c087baSYonghong Song  *
493069c087baSYonghong Song  *		If **callback_fn** return 0, the helper will continue to the next
493169c087baSYonghong Song  *		element. If return value is 1, the helper will skip the rest of
493269c087baSYonghong Song  *		elements and return. Other return values are not used now.
493369c087baSYonghong Song  *
493469c087baSYonghong Song  *	Return
493569c087baSYonghong Song  *		The number of traversed map elements for success, **-EINVAL** for
493669c087baSYonghong Song  *		invalid **flags**.
49377b15523aSFlorent Revest  *
49387b15523aSFlorent Revest  * long bpf_snprintf(char *str, u32 str_size, const char *fmt, u64 *data, u32 data_len)
49397b15523aSFlorent Revest  *	Description
49407b15523aSFlorent Revest  *		Outputs a string into the **str** buffer of size **str_size**
49417b15523aSFlorent Revest  *		based on a format string stored in a read-only map pointed by
49427b15523aSFlorent Revest  *		**fmt**.
49437b15523aSFlorent Revest  *
49447b15523aSFlorent Revest  *		Each format specifier in **fmt** corresponds to one u64 element
49457b15523aSFlorent Revest  *		in the **data** array. For strings and pointers where pointees
49467b15523aSFlorent Revest  *		are accessed, only the pointer values are stored in the *data*
4947a42effb0SDave Marchevsky  *		array. The *data_len* is the size of *data* in bytes - must be
4948a42effb0SDave Marchevsky  *		a multiple of 8.
49497b15523aSFlorent Revest  *
49507b15523aSFlorent Revest  *		Formats **%s** and **%p{i,I}{4,6}** require to read kernel
49517b15523aSFlorent Revest  *		memory. Reading kernel memory may fail due to either invalid
49527b15523aSFlorent Revest  *		address or valid address but requiring a major memory fault. If
49537b15523aSFlorent Revest  *		reading kernel memory fails, the string for **%s** will be an
49547b15523aSFlorent Revest  *		empty string, and the ip address for **%p{i,I}{4,6}** will be 0.
49557b15523aSFlorent Revest  *		Not returning error to bpf program is consistent with what
49567b15523aSFlorent Revest  *		**bpf_trace_printk**\ () does for now.
49577b15523aSFlorent Revest  *
49587b15523aSFlorent Revest  *	Return
49597b15523aSFlorent Revest  *		The strictly positive length of the formatted string, including
49607b15523aSFlorent Revest  *		the trailing zero character. If the return value is greater than
49617b15523aSFlorent Revest  *		**str_size**, **str** contains a truncated string, guaranteed to
49627b15523aSFlorent Revest  *		be zero-terminated except when **str_size** is 0.
49637b15523aSFlorent Revest  *
49647b15523aSFlorent Revest  *		Or **-EBUSY** if the per-CPU memory copy buffer is busy.
496579a7f8bdSAlexei Starovoitov  *
496679a7f8bdSAlexei Starovoitov  * long bpf_sys_bpf(u32 cmd, void *attr, u32 attr_size)
496779a7f8bdSAlexei Starovoitov  * 	Description
496879a7f8bdSAlexei Starovoitov  * 		Execute bpf syscall with given arguments.
496979a7f8bdSAlexei Starovoitov  * 	Return
497079a7f8bdSAlexei Starovoitov  * 		A syscall result.
49713d78417bSAlexei Starovoitov  *
49723d78417bSAlexei Starovoitov  * long bpf_btf_find_by_name_kind(char *name, int name_sz, u32 kind, int flags)
49733d78417bSAlexei Starovoitov  * 	Description
49743d78417bSAlexei Starovoitov  * 		Find BTF type with given name and kind in vmlinux BTF or in module's BTFs.
49753d78417bSAlexei Starovoitov  * 	Return
49763d78417bSAlexei Starovoitov  * 		Returns btf_id and btf_obj_fd in lower and upper 32 bits.
49773abea089SAlexei Starovoitov  *
49783abea089SAlexei Starovoitov  * long bpf_sys_close(u32 fd)
49793abea089SAlexei Starovoitov  * 	Description
49803abea089SAlexei Starovoitov  * 		Execute close syscall for given FD.
49813abea089SAlexei Starovoitov  * 	Return
49823abea089SAlexei Starovoitov  * 		A syscall result.
4983b00628b1SAlexei Starovoitov  *
4984b00628b1SAlexei Starovoitov  * long bpf_timer_init(struct bpf_timer *timer, struct bpf_map *map, u64 flags)
4985b00628b1SAlexei Starovoitov  *	Description
4986b00628b1SAlexei Starovoitov  *		Initialize the timer.
4987b00628b1SAlexei Starovoitov  *		First 4 bits of *flags* specify clockid.
4988b00628b1SAlexei Starovoitov  *		Only CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_BOOTTIME are allowed.
4989b00628b1SAlexei Starovoitov  *		All other bits of *flags* are reserved.
4990b00628b1SAlexei Starovoitov  *		The verifier will reject the program if *timer* is not from
4991b00628b1SAlexei Starovoitov  *		the same *map*.
4992b00628b1SAlexei Starovoitov  *	Return
4993b00628b1SAlexei Starovoitov  *		0 on success.
4994b00628b1SAlexei Starovoitov  *		**-EBUSY** if *timer* is already initialized.
4995b00628b1SAlexei Starovoitov  *		**-EINVAL** if invalid *flags* are passed.
4996b00628b1SAlexei Starovoitov  *		**-EPERM** if *timer* is in a map that doesn't have any user references.
4997b00628b1SAlexei Starovoitov  *		The user space should either hold a file descriptor to a map with timers
4998b00628b1SAlexei Starovoitov  *		or pin such map in bpffs. When map is unpinned or file descriptor is
4999b00628b1SAlexei Starovoitov  *		closed all timers in the map will be cancelled and freed.
5000b00628b1SAlexei Starovoitov  *
5001b00628b1SAlexei Starovoitov  * long bpf_timer_set_callback(struct bpf_timer *timer, void *callback_fn)
5002b00628b1SAlexei Starovoitov  *	Description
5003b00628b1SAlexei Starovoitov  *		Configure the timer to call *callback_fn* static function.
5004b00628b1SAlexei Starovoitov  *	Return
5005b00628b1SAlexei Starovoitov  *		0 on success.
5006b00628b1SAlexei Starovoitov  *		**-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier.
5007b00628b1SAlexei Starovoitov  *		**-EPERM** if *timer* is in a map that doesn't have any user references.
5008b00628b1SAlexei Starovoitov  *		The user space should either hold a file descriptor to a map with timers
5009b00628b1SAlexei Starovoitov  *		or pin such map in bpffs. When map is unpinned or file descriptor is
5010b00628b1SAlexei Starovoitov  *		closed all timers in the map will be cancelled and freed.
5011b00628b1SAlexei Starovoitov  *
5012b00628b1SAlexei Starovoitov  * long bpf_timer_start(struct bpf_timer *timer, u64 nsecs, u64 flags)
5013b00628b1SAlexei Starovoitov  *	Description
5014b00628b1SAlexei Starovoitov  *		Set timer expiration N nanoseconds from the current time. The
5015b00628b1SAlexei Starovoitov  *		configured callback will be invoked in soft irq context on some cpu
5016b00628b1SAlexei Starovoitov  *		and will not repeat unless another bpf_timer_start() is made.
5017b00628b1SAlexei Starovoitov  *		In such case the next invocation can migrate to a different cpu.
5018b00628b1SAlexei Starovoitov  *		Since struct bpf_timer is a field inside map element the map
5019b00628b1SAlexei Starovoitov  *		owns the timer. The bpf_timer_set_callback() will increment refcnt
5020b00628b1SAlexei Starovoitov  *		of BPF program to make sure that callback_fn code stays valid.
5021b00628b1SAlexei Starovoitov  *		When user space reference to a map reaches zero all timers
5022b00628b1SAlexei Starovoitov  *		in a map are cancelled and corresponding program's refcnts are
5023b00628b1SAlexei Starovoitov  *		decremented. This is done to make sure that Ctrl-C of a user
5024b00628b1SAlexei Starovoitov  *		process doesn't leave any timers running. If map is pinned in
5025b00628b1SAlexei Starovoitov  *		bpffs the callback_fn can re-arm itself indefinitely.
5026b00628b1SAlexei Starovoitov  *		bpf_map_update/delete_elem() helpers and user space sys_bpf commands
5027b00628b1SAlexei Starovoitov  *		cancel and free the timer in the given map element.
5028b00628b1SAlexei Starovoitov  *		The map can contain timers that invoke callback_fn-s from different
5029b00628b1SAlexei Starovoitov  *		programs. The same callback_fn can serve different timers from
5030b00628b1SAlexei Starovoitov  *		different maps if key/value layout matches across maps.
5031b00628b1SAlexei Starovoitov  *		Every bpf_timer_set_callback() can have different callback_fn.
5032b00628b1SAlexei Starovoitov  *
5033f71f8530STero Kristo  *		*flags* can be one of:
5034f71f8530STero Kristo  *
5035f71f8530STero Kristo  *		**BPF_F_TIMER_ABS**
5036f71f8530STero Kristo  *			Start the timer in absolute expire value instead of the
5037f71f8530STero Kristo  *			default relative one.
5038f71f8530STero Kristo  *
5039b00628b1SAlexei Starovoitov  *	Return
5040b00628b1SAlexei Starovoitov  *		0 on success.
5041b00628b1SAlexei Starovoitov  *		**-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier
5042b00628b1SAlexei Starovoitov  *		or invalid *flags* are passed.
5043b00628b1SAlexei Starovoitov  *
5044b00628b1SAlexei Starovoitov  * long bpf_timer_cancel(struct bpf_timer *timer)
5045b00628b1SAlexei Starovoitov  *	Description
5046b00628b1SAlexei Starovoitov  *		Cancel the timer and wait for callback_fn to finish if it was running.
5047b00628b1SAlexei Starovoitov  *	Return
5048b00628b1SAlexei Starovoitov  *		0 if the timer was not active.
5049b00628b1SAlexei Starovoitov  *		1 if the timer was active.
5050b00628b1SAlexei Starovoitov  *		**-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier.
5051b00628b1SAlexei Starovoitov  *		**-EDEADLK** if callback_fn tried to call bpf_timer_cancel() on its
5052b00628b1SAlexei Starovoitov  *		own timer which would have led to a deadlock otherwise.
50539b99edcaSJiri Olsa  *
50549b99edcaSJiri Olsa  * u64 bpf_get_func_ip(void *ctx)
50559b99edcaSJiri Olsa  * 	Description
50569ffd9f3fSJiri Olsa  * 		Get address of the traced function (for tracing and kprobe programs).
50579b99edcaSJiri Olsa  * 	Return
50589b99edcaSJiri Olsa  * 		Address of the traced function.
50590e253f7eSJiri Olsa  * 		0 for kprobes placed within the function (not at the entry).
50607adfc6c9SAndrii Nakryiko  *
50617adfc6c9SAndrii Nakryiko  * u64 bpf_get_attach_cookie(void *ctx)
50627adfc6c9SAndrii Nakryiko  * 	Description
50637adfc6c9SAndrii Nakryiko  * 		Get bpf_cookie value provided (optionally) during the program
50647adfc6c9SAndrii Nakryiko  * 		attachment. It might be different for each individual
50657adfc6c9SAndrii Nakryiko  * 		attachment, even if BPF program itself is the same.
50667adfc6c9SAndrii Nakryiko  * 		Expects BPF program context *ctx* as a first argument.
50677adfc6c9SAndrii Nakryiko  *
50687adfc6c9SAndrii Nakryiko  * 		Supported for the following program types:
50697adfc6c9SAndrii Nakryiko  *			- kprobe/uprobe;
50707adfc6c9SAndrii Nakryiko  *			- tracepoint;
50717adfc6c9SAndrii Nakryiko  *			- perf_event.
50727adfc6c9SAndrii Nakryiko  * 	Return
50737adfc6c9SAndrii Nakryiko  *		Value specified by user at BPF link creation/attachment time
50747adfc6c9SAndrii Nakryiko  *		or 0, if it was not specified.
5075dd6e10fbSDaniel Xu  *
5076dd6e10fbSDaniel Xu  * long bpf_task_pt_regs(struct task_struct *task)
5077dd6e10fbSDaniel Xu  *	Description
5078dd6e10fbSDaniel Xu  *		Get the struct pt_regs associated with **task**.
5079dd6e10fbSDaniel Xu  *	Return
5080dd6e10fbSDaniel Xu  *		A pointer to struct pt_regs.
5081856c02dbSSong Liu  *
5082856c02dbSSong Liu  * long bpf_get_branch_snapshot(void *entries, u32 size, u64 flags)
5083856c02dbSSong Liu  *	Description
5084856c02dbSSong Liu  *		Get branch trace from hardware engines like Intel LBR. The
5085856c02dbSSong Liu  *		hardware engine is stopped shortly after the helper is
5086856c02dbSSong Liu  *		called. Therefore, the user need to filter branch entries
5087856c02dbSSong Liu  *		based on the actual use case. To capture branch trace
5088856c02dbSSong Liu  *		before the trigger point of the BPF program, the helper
5089856c02dbSSong Liu  *		should be called at the beginning of the BPF program.
5090856c02dbSSong Liu  *
5091856c02dbSSong Liu  *		The data is stored as struct perf_branch_entry into output
5092856c02dbSSong Liu  *		buffer *entries*. *size* is the size of *entries* in bytes.
5093856c02dbSSong Liu  *		*flags* is reserved for now and must be zero.
5094856c02dbSSong Liu  *
5095856c02dbSSong Liu  *	Return
5096856c02dbSSong Liu  *		On success, number of bytes written to *buf*. On error, a
5097856c02dbSSong Liu  *		negative value.
5098856c02dbSSong Liu  *
5099856c02dbSSong Liu  *		**-EINVAL** if *flags* is not zero.
5100856c02dbSSong Liu  *
5101856c02dbSSong Liu  *		**-ENOENT** if architecture does not support branch records.
510210aceb62SDave Marchevsky  *
510310aceb62SDave Marchevsky  * long bpf_trace_vprintk(const char *fmt, u32 fmt_size, const void *data, u32 data_len)
510410aceb62SDave Marchevsky  *	Description
510510aceb62SDave Marchevsky  *		Behaves like **bpf_trace_printk**\ () helper, but takes an array of u64
510610aceb62SDave Marchevsky  *		to format and can handle more format args as a result.
510710aceb62SDave Marchevsky  *
510810aceb62SDave Marchevsky  *		Arguments are to be used as in **bpf_seq_printf**\ () helper.
510910aceb62SDave Marchevsky  *	Return
511010aceb62SDave Marchevsky  *		The number of bytes written to the buffer, or a negative error
511110aceb62SDave Marchevsky  *		in case of failure.
51129eeb3aa3SHengqi Chen  *
51139eeb3aa3SHengqi Chen  * struct unix_sock *bpf_skc_to_unix_sock(void *sk)
51149eeb3aa3SHengqi Chen  * 	Description
51159eeb3aa3SHengqi Chen  *		Dynamically cast a *sk* pointer to a *unix_sock* pointer.
51169eeb3aa3SHengqi Chen  *	Return
51179eeb3aa3SHengqi Chen  *		*sk* if casting is valid, or **NULL** otherwise.
5118d6aef08aSKumar Kartikeya Dwivedi  *
5119d6aef08aSKumar Kartikeya Dwivedi  * long bpf_kallsyms_lookup_name(const char *name, int name_sz, int flags, u64 *res)
5120d6aef08aSKumar Kartikeya Dwivedi  *	Description
5121d6aef08aSKumar Kartikeya Dwivedi  *		Get the address of a kernel symbol, returned in *res*. *res* is
5122d6aef08aSKumar Kartikeya Dwivedi  *		set to 0 if the symbol is not found.
5123d6aef08aSKumar Kartikeya Dwivedi  *	Return
5124d6aef08aSKumar Kartikeya Dwivedi  *		On success, zero. On error, a negative value.
5125d6aef08aSKumar Kartikeya Dwivedi  *
5126d6aef08aSKumar Kartikeya Dwivedi  *		**-EINVAL** if *flags* is not zero.
5127d6aef08aSKumar Kartikeya Dwivedi  *
5128d6aef08aSKumar Kartikeya Dwivedi  *		**-EINVAL** if string *name* is not the same size as *name_sz*.
5129d6aef08aSKumar Kartikeya Dwivedi  *
5130d6aef08aSKumar Kartikeya Dwivedi  *		**-ENOENT** if symbol is not found.
5131d6aef08aSKumar Kartikeya Dwivedi  *
5132d6aef08aSKumar Kartikeya Dwivedi  *		**-EPERM** if caller does not have permission to obtain kernel address.
51337c7e3d31SSong Liu  *
51347c7e3d31SSong Liu  * long bpf_find_vma(struct task_struct *task, u64 addr, void *callback_fn, void *callback_ctx, u64 flags)
51357c7e3d31SSong Liu  *	Description
51367c7e3d31SSong Liu  *		Find vma of *task* that contains *addr*, call *callback_fn*
51377c7e3d31SSong Liu  *		function with *task*, *vma*, and *callback_ctx*.
51387c7e3d31SSong Liu  *		The *callback_fn* should be a static function and
51397c7e3d31SSong Liu  *		the *callback_ctx* should be a pointer to the stack.
51407c7e3d31SSong Liu  *		The *flags* is used to control certain aspects of the helper.
51417c7e3d31SSong Liu  *		Currently, the *flags* must be 0.
51427c7e3d31SSong Liu  *
51437c7e3d31SSong Liu  *		The expected callback signature is
51447c7e3d31SSong Liu  *
51457c7e3d31SSong Liu  *		long (\*callback_fn)(struct task_struct \*task, struct vm_area_struct \*vma, void \*callback_ctx);
51467c7e3d31SSong Liu  *
51477c7e3d31SSong Liu  *	Return
51487c7e3d31SSong Liu  *		0 on success.
51497c7e3d31SSong Liu  *		**-ENOENT** if *task->mm* is NULL, or no vma contains *addr*.
51507c7e3d31SSong Liu  *		**-EBUSY** if failed to try lock mmap_lock.
51517c7e3d31SSong Liu  *		**-EINVAL** for invalid **flags**.
5152e6f2dd0fSJoanne Koong  *
5153e6f2dd0fSJoanne Koong  * long bpf_loop(u32 nr_loops, void *callback_fn, void *callback_ctx, u64 flags)
5154e6f2dd0fSJoanne Koong  *	Description
5155e6f2dd0fSJoanne Koong  *		For **nr_loops**, call **callback_fn** function
5156e6f2dd0fSJoanne Koong  *		with **callback_ctx** as the context parameter.
5157e6f2dd0fSJoanne Koong  *		The **callback_fn** should be a static function and
5158e6f2dd0fSJoanne Koong  *		the **callback_ctx** should be a pointer to the stack.
5159e6f2dd0fSJoanne Koong  *		The **flags** is used to control certain aspects of the helper.
5160e6f2dd0fSJoanne Koong  *		Currently, the **flags** must be 0. Currently, nr_loops is
5161e6f2dd0fSJoanne Koong  *		limited to 1 << 23 (~8 million) loops.
5162e6f2dd0fSJoanne Koong  *
5163e6f2dd0fSJoanne Koong  *		long (\*callback_fn)(u32 index, void \*ctx);
5164e6f2dd0fSJoanne Koong  *
5165e6f2dd0fSJoanne Koong  *		where **index** is the current index in the loop. The index
5166e6f2dd0fSJoanne Koong  *		is zero-indexed.
5167e6f2dd0fSJoanne Koong  *
5168e6f2dd0fSJoanne Koong  *		If **callback_fn** returns 0, the helper will continue to the next
5169e6f2dd0fSJoanne Koong  *		loop. If return value is 1, the helper will skip the rest of
5170e6f2dd0fSJoanne Koong  *		the loops and return. Other return values are not used now,
5171e6f2dd0fSJoanne Koong  *		and will be rejected by the verifier.
5172e6f2dd0fSJoanne Koong  *
5173e6f2dd0fSJoanne Koong  *	Return
5174e6f2dd0fSJoanne Koong  *		The number of loops performed, **-EINVAL** for invalid **flags**,
5175e6f2dd0fSJoanne Koong  *		**-E2BIG** if **nr_loops** exceeds the maximum number of loops.
5176c5fb1993SHou Tao  *
5177c5fb1993SHou Tao  * long bpf_strncmp(const char *s1, u32 s1_sz, const char *s2)
5178c5fb1993SHou Tao  *	Description
5179c5fb1993SHou Tao  *		Do strncmp() between **s1** and **s2**. **s1** doesn't need
5180c5fb1993SHou Tao  *		to be null-terminated and **s1_sz** is the maximum storage
5181c5fb1993SHou Tao  *		size of **s1**. **s2** must be a read-only string.
5182c5fb1993SHou Tao  *	Return
5183c5fb1993SHou Tao  *		An integer less than, equal to, or greater than zero
5184c5fb1993SHou Tao  *		if the first **s1_sz** bytes of **s1** is found to be
5185c5fb1993SHou Tao  *		less than, to match, or be greater than **s2**.
5186f92c1e18SJiri Olsa  *
5187f92c1e18SJiri Olsa  * long bpf_get_func_arg(void *ctx, u32 n, u64 *value)
5188f92c1e18SJiri Olsa  *	Description
518927ed9353SYonghong Song  *		Get **n**-th argument register (zero based) of the traced function (for tracing programs)
5190f92c1e18SJiri Olsa  *		returned in **value**.
5191f92c1e18SJiri Olsa  *
5192f92c1e18SJiri Olsa  *	Return
5193f92c1e18SJiri Olsa  *		0 on success.
519427ed9353SYonghong Song  *		**-EINVAL** if n >= argument register count of traced function.
5195f92c1e18SJiri Olsa  *
5196f92c1e18SJiri Olsa  * long bpf_get_func_ret(void *ctx, u64 *value)
5197f92c1e18SJiri Olsa  *	Description
5198f92c1e18SJiri Olsa  *		Get return value of the traced function (for tracing programs)
5199f92c1e18SJiri Olsa  *		in **value**.
5200f92c1e18SJiri Olsa  *
5201f92c1e18SJiri Olsa  *	Return
5202f92c1e18SJiri Olsa  *		0 on success.
5203f92c1e18SJiri Olsa  *		**-EOPNOTSUPP** for tracing programs other than BPF_TRACE_FEXIT or BPF_MODIFY_RETURN.
5204f92c1e18SJiri Olsa  *
5205f92c1e18SJiri Olsa  * long bpf_get_func_arg_cnt(void *ctx)
5206f92c1e18SJiri Olsa  *	Description
520727ed9353SYonghong Song  *		Get number of registers of the traced function (for tracing programs) where
520827ed9353SYonghong Song  *		function arguments are stored in these registers.
5209f92c1e18SJiri Olsa  *
5210f92c1e18SJiri Olsa  *	Return
521127ed9353SYonghong Song  *		The number of argument registers of the traced function.
5212b44123b4SYiFei Zhu  *
5213b44123b4SYiFei Zhu  * int bpf_get_retval(void)
5214b44123b4SYiFei Zhu  *	Description
52152172fb80SStanislav Fomichev  *		Get the BPF program's return value that will be returned to the upper layers.
5216b44123b4SYiFei Zhu  *
52172172fb80SStanislav Fomichev  *		This helper is currently supported by cgroup programs and only by the hooks
52182172fb80SStanislav Fomichev  *		where BPF program's return value is returned to the userspace via errno.
5219b44123b4SYiFei Zhu  *	Return
52202172fb80SStanislav Fomichev  *		The BPF program's return value.
5221b44123b4SYiFei Zhu  *
5222b44123b4SYiFei Zhu  * int bpf_set_retval(int retval)
5223b44123b4SYiFei Zhu  *	Description
52242172fb80SStanislav Fomichev  *		Set the BPF program's return value that will be returned to the upper layers.
5225b44123b4SYiFei Zhu  *
52262172fb80SStanislav Fomichev  *		This helper is currently supported by cgroup programs and only by the hooks
52272172fb80SStanislav Fomichev  *		where BPF program's return value is returned to the userspace via errno.
52282172fb80SStanislav Fomichev  *
52292172fb80SStanislav Fomichev  *		Note that there is the following corner case where the program exports an error
52302172fb80SStanislav Fomichev  *		via bpf_set_retval but signals success via 'return 1':
52312172fb80SStanislav Fomichev  *
52322172fb80SStanislav Fomichev  *			bpf_set_retval(-EPERM);
52332172fb80SStanislav Fomichev  *			return 1;
52342172fb80SStanislav Fomichev  *
52352172fb80SStanislav Fomichev  *		In this case, the BPF program's return value will use helper's -EPERM. This
52362172fb80SStanislav Fomichev  *		still holds true for cgroup/bind{4,6} which supports extra 'return 3' success case.
52372172fb80SStanislav Fomichev  *
5238b44123b4SYiFei Zhu  *	Return
5239b44123b4SYiFei Zhu  *		0 on success, or a negative error in case of failure.
52400165cc81SLorenzo Bianconi  *
52410165cc81SLorenzo Bianconi  * u64 bpf_xdp_get_buff_len(struct xdp_buff *xdp_md)
52420165cc81SLorenzo Bianconi  *	Description
52430165cc81SLorenzo Bianconi  *		Get the total size of a given xdp buff (linear and paged area)
52440165cc81SLorenzo Bianconi  *	Return
52450165cc81SLorenzo Bianconi  *		The total size of a given xdp buffer.
52463f364222SLorenzo Bianconi  *
52473f364222SLorenzo Bianconi  * long bpf_xdp_load_bytes(struct xdp_buff *xdp_md, u32 offset, void *buf, u32 len)
52483f364222SLorenzo Bianconi  *	Description
52493f364222SLorenzo Bianconi  *		This helper is provided as an easy way to load data from a
52503f364222SLorenzo Bianconi  *		xdp buffer. It can be used to load *len* bytes from *offset* from
52513f364222SLorenzo Bianconi  *		the frame associated to *xdp_md*, into the buffer pointed by
52523f364222SLorenzo Bianconi  *		*buf*.
52533f364222SLorenzo Bianconi  *	Return
52543f364222SLorenzo Bianconi  *		0 on success, or a negative error in case of failure.
52553f364222SLorenzo Bianconi  *
52563f364222SLorenzo Bianconi  * long bpf_xdp_store_bytes(struct xdp_buff *xdp_md, u32 offset, void *buf, u32 len)
52573f364222SLorenzo Bianconi  *	Description
52583f364222SLorenzo Bianconi  *		Store *len* bytes from buffer *buf* into the frame
52593f364222SLorenzo Bianconi  *		associated to *xdp_md*, at *offset*.
52603f364222SLorenzo Bianconi  *	Return
52613f364222SLorenzo Bianconi  *		0 on success, or a negative error in case of failure.
5262376040e4SKenny Yu  *
5263376040e4SKenny Yu  * long bpf_copy_from_user_task(void *dst, u32 size, const void *user_ptr, struct task_struct *tsk, u64 flags)
5264376040e4SKenny Yu  *	Description
5265376040e4SKenny Yu  *		Read *size* bytes from user space address *user_ptr* in *tsk*'s
5266376040e4SKenny Yu  *		address space, and stores the data in *dst*. *flags* is not
5267376040e4SKenny Yu  *		used yet and is provided for future extensibility. This helper
5268376040e4SKenny Yu  *		can only be used by sleepable programs.
5269376040e4SKenny Yu  *	Return
5270376040e4SKenny Yu  *		0 on success, or a negative error in case of failure. On error
5271376040e4SKenny Yu  *		*dst* buffer is zeroed out.
52728d21ec0eSMartin KaFai Lau  *
52739bb984f2SMartin KaFai Lau  * long bpf_skb_set_tstamp(struct sk_buff *skb, u64 tstamp, u32 tstamp_type)
52748d21ec0eSMartin KaFai Lau  *	Description
52759bb984f2SMartin KaFai Lau  *		Change the __sk_buff->tstamp_type to *tstamp_type*
52769bb984f2SMartin KaFai Lau  *		and set *tstamp* to the __sk_buff->tstamp together.
52778d21ec0eSMartin KaFai Lau  *
52789bb984f2SMartin KaFai Lau  *		If there is no need to change the __sk_buff->tstamp_type,
52799bb984f2SMartin KaFai Lau  *		the tstamp value can be directly written to __sk_buff->tstamp
52808d21ec0eSMartin KaFai Lau  *		instead.
52818d21ec0eSMartin KaFai Lau  *
52829bb984f2SMartin KaFai Lau  *		BPF_SKB_TSTAMP_DELIVERY_MONO is the only tstamp that
52839bb984f2SMartin KaFai Lau  *		will be kept during bpf_redirect_*().  A non zero
52849bb984f2SMartin KaFai Lau  *		*tstamp* must be used with the BPF_SKB_TSTAMP_DELIVERY_MONO
52859bb984f2SMartin KaFai Lau  *		*tstamp_type*.
52869bb984f2SMartin KaFai Lau  *
52879bb984f2SMartin KaFai Lau  *		A BPF_SKB_TSTAMP_UNSPEC *tstamp_type* can only be used
52889bb984f2SMartin KaFai Lau  *		with a zero *tstamp*.
52898d21ec0eSMartin KaFai Lau  *
52908d21ec0eSMartin KaFai Lau  *		Only IPv4 and IPv6 skb->protocol are supported.
52918d21ec0eSMartin KaFai Lau  *
52928d21ec0eSMartin KaFai Lau  *		This function is most useful when it needs to set a
52938d21ec0eSMartin KaFai Lau  *		mono delivery time to __sk_buff->tstamp and then
52948d21ec0eSMartin KaFai Lau  *		bpf_redirect_*() to the egress of an iface.  For example,
52958d21ec0eSMartin KaFai Lau  *		changing the (rcv) timestamp in __sk_buff->tstamp at
52968d21ec0eSMartin KaFai Lau  *		ingress to a mono delivery time and then bpf_redirect_*()
52978d21ec0eSMartin KaFai Lau  *		to sch_fq@phy-dev.
52988d21ec0eSMartin KaFai Lau  *	Return
52998d21ec0eSMartin KaFai Lau  *		0 on success.
53008d21ec0eSMartin KaFai Lau  *		**-EINVAL** for invalid input
53019bb984f2SMartin KaFai Lau  *		**-EOPNOTSUPP** for unsupported protocol
5302174b1694SRoberto Sassu  *
5303174b1694SRoberto Sassu  * long bpf_ima_file_hash(struct file *file, void *dst, u32 size)
5304174b1694SRoberto Sassu  *	Description
5305174b1694SRoberto Sassu  *		Returns a calculated IMA hash of the *file*.
5306174b1694SRoberto Sassu  *		If the hash is larger than *size*, then only *size*
5307174b1694SRoberto Sassu  *		bytes will be copied to *dst*
5308174b1694SRoberto Sassu  *	Return
5309174b1694SRoberto Sassu  *		The **hash_algo** is returned on success,
5310174b1694SRoberto Sassu  *		**-EOPNOTSUP** if the hash calculation failed or **-EINVAL** if
5311174b1694SRoberto Sassu  *		invalid arguments are passed.
5312c0a5a21cSKumar Kartikeya Dwivedi  *
5313c0a5a21cSKumar Kartikeya Dwivedi  * void *bpf_kptr_xchg(void *map_value, void *ptr)
5314c0a5a21cSKumar Kartikeya Dwivedi  *	Description
5315c0a5a21cSKumar Kartikeya Dwivedi  *		Exchange kptr at pointer *map_value* with *ptr*, and return the
5316c0a5a21cSKumar Kartikeya Dwivedi  *		old value. *ptr* can be NULL, otherwise it must be a referenced
5317c0a5a21cSKumar Kartikeya Dwivedi  *		pointer which will be released when this helper is called.
5318c0a5a21cSKumar Kartikeya Dwivedi  *	Return
5319c0a5a21cSKumar Kartikeya Dwivedi  *		The old value of kptr (which can be NULL). The returned pointer
5320c0a5a21cSKumar Kartikeya Dwivedi  *		if not NULL, is a reference which must be released using its
5321c0a5a21cSKumar Kartikeya Dwivedi  *		corresponding release function, or moved into a BPF map before
5322c0a5a21cSKumar Kartikeya Dwivedi  *		program exit.
532307343110SFeng Zhou  *
532407343110SFeng Zhou  * void *bpf_map_lookup_percpu_elem(struct bpf_map *map, const void *key, u32 cpu)
532507343110SFeng Zhou  * 	Description
532607343110SFeng Zhou  * 		Perform a lookup in *percpu map* for an entry associated to
532707343110SFeng Zhou  * 		*key* on *cpu*.
532807343110SFeng Zhou  * 	Return
532907343110SFeng Zhou  * 		Map value associated to *key* on *cpu*, or **NULL** if no entry
533007343110SFeng Zhou  * 		was found or *cpu* is invalid.
53313bc253c2SGeliang Tang  *
53323bc253c2SGeliang Tang  * struct mptcp_sock *bpf_skc_to_mptcp_sock(void *sk)
53333bc253c2SGeliang Tang  *	Description
53343bc253c2SGeliang Tang  *		Dynamically cast a *sk* pointer to a *mptcp_sock* pointer.
53353bc253c2SGeliang Tang  *	Return
53363bc253c2SGeliang Tang  *		*sk* if casting is valid, or **NULL** otherwise.
5337263ae152SJoanne Koong  *
5338263ae152SJoanne Koong  * long bpf_dynptr_from_mem(void *data, u32 size, u64 flags, struct bpf_dynptr *ptr)
5339263ae152SJoanne Koong  *	Description
5340263ae152SJoanne Koong  *		Get a dynptr to local memory *data*.
5341263ae152SJoanne Koong  *
5342263ae152SJoanne Koong  *		*data* must be a ptr to a map value.
5343263ae152SJoanne Koong  *		The maximum *size* supported is DYNPTR_MAX_SIZE.
5344263ae152SJoanne Koong  *		*flags* is currently unused.
5345263ae152SJoanne Koong  *	Return
5346263ae152SJoanne Koong  *		0 on success, -E2BIG if the size exceeds DYNPTR_MAX_SIZE,
5347263ae152SJoanne Koong  *		-EINVAL if flags is not 0.
5348bc34dee6SJoanne Koong  *
5349bc34dee6SJoanne Koong  * long bpf_ringbuf_reserve_dynptr(void *ringbuf, u32 size, u64 flags, struct bpf_dynptr *ptr)
5350bc34dee6SJoanne Koong  *	Description
5351bc34dee6SJoanne Koong  *		Reserve *size* bytes of payload in a ring buffer *ringbuf*
5352bc34dee6SJoanne Koong  *		through the dynptr interface. *flags* must be 0.
5353bc34dee6SJoanne Koong  *
5354bc34dee6SJoanne Koong  *		Please note that a corresponding bpf_ringbuf_submit_dynptr or
5355bc34dee6SJoanne Koong  *		bpf_ringbuf_discard_dynptr must be called on *ptr*, even if the
5356bc34dee6SJoanne Koong  *		reservation fails. This is enforced by the verifier.
5357bc34dee6SJoanne Koong  *	Return
5358bc34dee6SJoanne Koong  *		0 on success, or a negative error in case of failure.
5359bc34dee6SJoanne Koong  *
5360bc34dee6SJoanne Koong  * void bpf_ringbuf_submit_dynptr(struct bpf_dynptr *ptr, u64 flags)
5361bc34dee6SJoanne Koong  *	Description
5362bc34dee6SJoanne Koong  *		Submit reserved ring buffer sample, pointed to by *data*,
5363bc34dee6SJoanne Koong  *		through the dynptr interface. This is a no-op if the dynptr is
5364bc34dee6SJoanne Koong  *		invalid/null.
5365bc34dee6SJoanne Koong  *
5366bc34dee6SJoanne Koong  *		For more information on *flags*, please see
5367bc34dee6SJoanne Koong  *		'bpf_ringbuf_submit'.
5368bc34dee6SJoanne Koong  *	Return
5369bc34dee6SJoanne Koong  *		Nothing. Always succeeds.
5370bc34dee6SJoanne Koong  *
5371bc34dee6SJoanne Koong  * void bpf_ringbuf_discard_dynptr(struct bpf_dynptr *ptr, u64 flags)
5372bc34dee6SJoanne Koong  *	Description
5373bc34dee6SJoanne Koong  *		Discard reserved ring buffer sample through the dynptr
5374bc34dee6SJoanne Koong  *		interface. This is a no-op if the dynptr is invalid/null.
5375bc34dee6SJoanne Koong  *
5376bc34dee6SJoanne Koong  *		For more information on *flags*, please see
5377bc34dee6SJoanne Koong  *		'bpf_ringbuf_discard'.
5378bc34dee6SJoanne Koong  *	Return
5379bc34dee6SJoanne Koong  *		Nothing. Always succeeds.
538013bbbfbeSJoanne Koong  *
538127060531SKumar Kartikeya Dwivedi  * long bpf_dynptr_read(void *dst, u32 len, const struct bpf_dynptr *src, u32 offset, u64 flags)
538213bbbfbeSJoanne Koong  *	Description
538313bbbfbeSJoanne Koong  *		Read *len* bytes from *src* into *dst*, starting from *offset*
538413bbbfbeSJoanne Koong  *		into *src*.
5385f8d3da4eSJoanne Koong  *		*flags* is currently unused.
538613bbbfbeSJoanne Koong  *	Return
538713bbbfbeSJoanne Koong  *		0 on success, -E2BIG if *offset* + *len* exceeds the length
5388f8d3da4eSJoanne Koong  *		of *src*'s data, -EINVAL if *src* is an invalid dynptr or if
5389f8d3da4eSJoanne Koong  *		*flags* is not 0.
539013bbbfbeSJoanne Koong  *
539127060531SKumar Kartikeya Dwivedi  * long bpf_dynptr_write(const struct bpf_dynptr *dst, u32 offset, void *src, u32 len, u64 flags)
539213bbbfbeSJoanne Koong  *	Description
539313bbbfbeSJoanne Koong  *		Write *len* bytes from *src* into *dst*, starting from *offset*
539413bbbfbeSJoanne Koong  *		into *dst*.
5395b5964b96SJoanne Koong  *
5396b5964b96SJoanne Koong  *		*flags* must be 0 except for skb-type dynptrs.
5397b5964b96SJoanne Koong  *
5398b5964b96SJoanne Koong  *		For skb-type dynptrs:
539966e3a13eSJoanne Koong  *		    *  All data slices of the dynptr are automatically
540066e3a13eSJoanne Koong  *		       invalidated after **bpf_dynptr_write**\ (). This is
540166e3a13eSJoanne Koong  *		       because writing may pull the skb and change the
540266e3a13eSJoanne Koong  *		       underlying packet buffer.
540366e3a13eSJoanne Koong  *
5404b5964b96SJoanne Koong  *		    *  For *flags*, please see the flags accepted by
5405b5964b96SJoanne Koong  *		       **bpf_skb_store_bytes**\ ().
540613bbbfbeSJoanne Koong  *	Return
540713bbbfbeSJoanne Koong  *		0 on success, -E2BIG if *offset* + *len* exceeds the length
540813bbbfbeSJoanne Koong  *		of *dst*'s data, -EINVAL if *dst* is an invalid dynptr or if *dst*
5409b5964b96SJoanne Koong  *		is a read-only dynptr or if *flags* is not correct. For skb-type dynptrs,
5410b5964b96SJoanne Koong  *		other errors correspond to errors returned by **bpf_skb_store_bytes**\ ().
541134d4ef57SJoanne Koong  *
541227060531SKumar Kartikeya Dwivedi  * void *bpf_dynptr_data(const struct bpf_dynptr *ptr, u32 offset, u32 len)
541334d4ef57SJoanne Koong  *	Description
541434d4ef57SJoanne Koong  *		Get a pointer to the underlying dynptr data.
541534d4ef57SJoanne Koong  *
541634d4ef57SJoanne Koong  *		*len* must be a statically known value. The returned data slice
541734d4ef57SJoanne Koong  *		is invalidated whenever the dynptr is invalidated.
5418b5964b96SJoanne Koong  *
541905421aecSJoanne Koong  *		skb and xdp type dynptrs may not use bpf_dynptr_data. They should
5420b5964b96SJoanne Koong  *		instead use bpf_dynptr_slice and bpf_dynptr_slice_rdwr.
542134d4ef57SJoanne Koong  *	Return
542234d4ef57SJoanne Koong  *		Pointer to the underlying dynptr data, NULL if the dynptr is
542334d4ef57SJoanne Koong  *		read-only, if the dynptr is invalid, or if the offset and length
542434d4ef57SJoanne Koong  *		is out of bounds.
542533bf9885SMaxim Mikityanskiy  *
542633bf9885SMaxim Mikityanskiy  * s64 bpf_tcp_raw_gen_syncookie_ipv4(struct iphdr *iph, struct tcphdr *th, u32 th_len)
542733bf9885SMaxim Mikityanskiy  *	Description
542833bf9885SMaxim Mikityanskiy  *		Try to issue a SYN cookie for the packet with corresponding
542933bf9885SMaxim Mikityanskiy  *		IPv4/TCP headers, *iph* and *th*, without depending on a
543033bf9885SMaxim Mikityanskiy  *		listening socket.
543133bf9885SMaxim Mikityanskiy  *
543233bf9885SMaxim Mikityanskiy  *		*iph* points to the IPv4 header.
543333bf9885SMaxim Mikityanskiy  *
543433bf9885SMaxim Mikityanskiy  *		*th* points to the start of the TCP header, while *th_len*
543533bf9885SMaxim Mikityanskiy  *		contains the length of the TCP header (at least
543633bf9885SMaxim Mikityanskiy  *		**sizeof**\ (**struct tcphdr**)).
543733bf9885SMaxim Mikityanskiy  *	Return
543833bf9885SMaxim Mikityanskiy  *		On success, lower 32 bits hold the generated SYN cookie in
543933bf9885SMaxim Mikityanskiy  *		followed by 16 bits which hold the MSS value for that cookie,
544033bf9885SMaxim Mikityanskiy  *		and the top 16 bits are unused.
544133bf9885SMaxim Mikityanskiy  *
544233bf9885SMaxim Mikityanskiy  *		On failure, the returned value is one of the following:
544333bf9885SMaxim Mikityanskiy  *
544433bf9885SMaxim Mikityanskiy  *		**-EINVAL** if *th_len* is invalid.
544533bf9885SMaxim Mikityanskiy  *
544633bf9885SMaxim Mikityanskiy  * s64 bpf_tcp_raw_gen_syncookie_ipv6(struct ipv6hdr *iph, struct tcphdr *th, u32 th_len)
544733bf9885SMaxim Mikityanskiy  *	Description
544833bf9885SMaxim Mikityanskiy  *		Try to issue a SYN cookie for the packet with corresponding
544933bf9885SMaxim Mikityanskiy  *		IPv6/TCP headers, *iph* and *th*, without depending on a
545033bf9885SMaxim Mikityanskiy  *		listening socket.
545133bf9885SMaxim Mikityanskiy  *
545233bf9885SMaxim Mikityanskiy  *		*iph* points to the IPv6 header.
545333bf9885SMaxim Mikityanskiy  *
545433bf9885SMaxim Mikityanskiy  *		*th* points to the start of the TCP header, while *th_len*
545533bf9885SMaxim Mikityanskiy  *		contains the length of the TCP header (at least
545633bf9885SMaxim Mikityanskiy  *		**sizeof**\ (**struct tcphdr**)).
545733bf9885SMaxim Mikityanskiy  *	Return
545833bf9885SMaxim Mikityanskiy  *		On success, lower 32 bits hold the generated SYN cookie in
545933bf9885SMaxim Mikityanskiy  *		followed by 16 bits which hold the MSS value for that cookie,
546033bf9885SMaxim Mikityanskiy  *		and the top 16 bits are unused.
546133bf9885SMaxim Mikityanskiy  *
546233bf9885SMaxim Mikityanskiy  *		On failure, the returned value is one of the following:
546333bf9885SMaxim Mikityanskiy  *
546433bf9885SMaxim Mikityanskiy  *		**-EINVAL** if *th_len* is invalid.
546533bf9885SMaxim Mikityanskiy  *
546633bf9885SMaxim Mikityanskiy  *		**-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
546733bf9885SMaxim Mikityanskiy  *
546833bf9885SMaxim Mikityanskiy  * long bpf_tcp_raw_check_syncookie_ipv4(struct iphdr *iph, struct tcphdr *th)
546933bf9885SMaxim Mikityanskiy  *	Description
547033bf9885SMaxim Mikityanskiy  *		Check whether *iph* and *th* contain a valid SYN cookie ACK
547133bf9885SMaxim Mikityanskiy  *		without depending on a listening socket.
547233bf9885SMaxim Mikityanskiy  *
547333bf9885SMaxim Mikityanskiy  *		*iph* points to the IPv4 header.
547433bf9885SMaxim Mikityanskiy  *
547533bf9885SMaxim Mikityanskiy  *		*th* points to the TCP header.
547633bf9885SMaxim Mikityanskiy  *	Return
547733bf9885SMaxim Mikityanskiy  *		0 if *iph* and *th* are a valid SYN cookie ACK.
547833bf9885SMaxim Mikityanskiy  *
547933bf9885SMaxim Mikityanskiy  *		On failure, the returned value is one of the following:
548033bf9885SMaxim Mikityanskiy  *
548133bf9885SMaxim Mikityanskiy  *		**-EACCES** if the SYN cookie is not valid.
548233bf9885SMaxim Mikityanskiy  *
548333bf9885SMaxim Mikityanskiy  * long bpf_tcp_raw_check_syncookie_ipv6(struct ipv6hdr *iph, struct tcphdr *th)
548433bf9885SMaxim Mikityanskiy  *	Description
548533bf9885SMaxim Mikityanskiy  *		Check whether *iph* and *th* contain a valid SYN cookie ACK
548633bf9885SMaxim Mikityanskiy  *		without depending on a listening socket.
548733bf9885SMaxim Mikityanskiy  *
548833bf9885SMaxim Mikityanskiy  *		*iph* points to the IPv6 header.
548933bf9885SMaxim Mikityanskiy  *
549033bf9885SMaxim Mikityanskiy  *		*th* points to the TCP header.
549133bf9885SMaxim Mikityanskiy  *	Return
549233bf9885SMaxim Mikityanskiy  *		0 if *iph* and *th* are a valid SYN cookie ACK.
549333bf9885SMaxim Mikityanskiy  *
549433bf9885SMaxim Mikityanskiy  *		On failure, the returned value is one of the following:
549533bf9885SMaxim Mikityanskiy  *
549633bf9885SMaxim Mikityanskiy  *		**-EACCES** if the SYN cookie is not valid.
549733bf9885SMaxim Mikityanskiy  *
549833bf9885SMaxim Mikityanskiy  *		**-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
5499c8996c98SJesper Dangaard Brouer  *
5500c8996c98SJesper Dangaard Brouer  * u64 bpf_ktime_get_tai_ns(void)
5501c8996c98SJesper Dangaard Brouer  *	Description
5502c8996c98SJesper Dangaard Brouer  *		A nonsettable system-wide clock derived from wall-clock time but
5503c8996c98SJesper Dangaard Brouer  *		ignoring leap seconds.  This clock does not experience
5504c8996c98SJesper Dangaard Brouer  *		discontinuities and backwards jumps caused by NTP inserting leap
5505c8996c98SJesper Dangaard Brouer  *		seconds as CLOCK_REALTIME does.
5506c8996c98SJesper Dangaard Brouer  *
5507c8996c98SJesper Dangaard Brouer  *		See: **clock_gettime**\ (**CLOCK_TAI**)
5508c8996c98SJesper Dangaard Brouer  *	Return
5509c8996c98SJesper Dangaard Brouer  *		Current *ktime*.
5510c8996c98SJesper Dangaard Brouer  *
551120571567SDavid Vernet  * long bpf_user_ringbuf_drain(struct bpf_map *map, void *callback_fn, void *ctx, u64 flags)
551220571567SDavid Vernet  *	Description
551320571567SDavid Vernet  *		Drain samples from the specified user ring buffer, and invoke
551420571567SDavid Vernet  *		the provided callback for each such sample:
551520571567SDavid Vernet  *
551627060531SKumar Kartikeya Dwivedi  *		long (\*callback_fn)(const struct bpf_dynptr \*dynptr, void \*ctx);
551720571567SDavid Vernet  *
551820571567SDavid Vernet  *		If **callback_fn** returns 0, the helper will continue to try
551920571567SDavid Vernet  *		and drain the next sample, up to a maximum of
552020571567SDavid Vernet  *		BPF_MAX_USER_RINGBUF_SAMPLES samples. If the return value is 1,
552120571567SDavid Vernet  *		the helper will skip the rest of the samples and return. Other
552220571567SDavid Vernet  *		return values are not used now, and will be rejected by the
552320571567SDavid Vernet  *		verifier.
552420571567SDavid Vernet  *	Return
552520571567SDavid Vernet  *		The number of drained samples if no error was encountered while
552620571567SDavid Vernet  *		draining samples, or 0 if no samples were present in the ring
552720571567SDavid Vernet  *		buffer. If a user-space producer was epoll-waiting on this map,
552820571567SDavid Vernet  *		and at least one sample was drained, they will receive an event
552920571567SDavid Vernet  *		notification notifying them of available space in the ring
553020571567SDavid Vernet  *		buffer. If the BPF_RB_NO_WAKEUP flag is passed to this
553120571567SDavid Vernet  *		function, no wakeup notification will be sent. If the
553220571567SDavid Vernet  *		BPF_RB_FORCE_WAKEUP flag is passed, a wakeup notification will
553320571567SDavid Vernet  *		be sent even if no sample was drained.
553420571567SDavid Vernet  *
553520571567SDavid Vernet  *		On failure, the returned value is one of the following:
553620571567SDavid Vernet  *
553720571567SDavid Vernet  *		**-EBUSY** if the ring buffer is contended, and another calling
553820571567SDavid Vernet  *		context was concurrently draining the ring buffer.
553920571567SDavid Vernet  *
554020571567SDavid Vernet  *		**-EINVAL** if user-space is not properly tracking the ring
554120571567SDavid Vernet  *		buffer due to the producer position not being aligned to 8
554220571567SDavid Vernet  *		bytes, a sample not being aligned to 8 bytes, or the producer
554320571567SDavid Vernet  *		position not matching the advertised length of a sample.
554420571567SDavid Vernet  *
554520571567SDavid Vernet  *		**-E2BIG** if user-space has tried to publish a sample which is
554620571567SDavid Vernet  *		larger than the size of the ring buffer, or which cannot fit
554720571567SDavid Vernet  *		within a struct bpf_dynptr.
5548c4bcfb38SYonghong Song  *
5549c4bcfb38SYonghong Song  * void *bpf_cgrp_storage_get(struct bpf_map *map, struct cgroup *cgroup, void *value, u64 flags)
5550c4bcfb38SYonghong Song  *	Description
5551c4bcfb38SYonghong Song  *		Get a bpf_local_storage from the *cgroup*.
5552c4bcfb38SYonghong Song  *
5553c4bcfb38SYonghong Song  *		Logically, it could be thought of as getting the value from
5554c4bcfb38SYonghong Song  *		a *map* with *cgroup* as the **key**.  From this
5555c4bcfb38SYonghong Song  *		perspective,  the usage is not much different from
5556c4bcfb38SYonghong Song  *		**bpf_map_lookup_elem**\ (*map*, **&**\ *cgroup*) except this
5557c4bcfb38SYonghong Song  *		helper enforces the key must be a cgroup struct and the map must also
5558c4bcfb38SYonghong Song  *		be a **BPF_MAP_TYPE_CGRP_STORAGE**.
5559c4bcfb38SYonghong Song  *
5560c4bcfb38SYonghong Song  *		In reality, the local-storage value is embedded directly inside of the
5561c4bcfb38SYonghong Song  *		*cgroup* object itself, rather than being located in the
5562c4bcfb38SYonghong Song  *		**BPF_MAP_TYPE_CGRP_STORAGE** map. When the local-storage value is
5563c4bcfb38SYonghong Song  *		queried for some *map* on a *cgroup* object, the kernel will perform an
5564c4bcfb38SYonghong Song  *		O(n) iteration over all of the live local-storage values for that
5565c4bcfb38SYonghong Song  *		*cgroup* object until the local-storage value for the *map* is found.
5566c4bcfb38SYonghong Song  *
5567c4bcfb38SYonghong Song  *		An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
5568c4bcfb38SYonghong Song  *		used such that a new bpf_local_storage will be
5569c4bcfb38SYonghong Song  *		created if one does not exist.  *value* can be used
5570c4bcfb38SYonghong Song  *		together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
5571c4bcfb38SYonghong Song  *		the initial value of a bpf_local_storage.  If *value* is
5572c4bcfb38SYonghong Song  *		**NULL**, the new bpf_local_storage will be zero initialized.
5573c4bcfb38SYonghong Song  *	Return
5574c4bcfb38SYonghong Song  *		A bpf_local_storage pointer is returned on success.
5575c4bcfb38SYonghong Song  *
5576c4bcfb38SYonghong Song  *		**NULL** if not found or there was an error in adding
5577c4bcfb38SYonghong Song  *		a new bpf_local_storage.
5578c4bcfb38SYonghong Song  *
5579c4bcfb38SYonghong Song  * long bpf_cgrp_storage_delete(struct bpf_map *map, struct cgroup *cgroup)
5580c4bcfb38SYonghong Song  *	Description
5581c4bcfb38SYonghong Song  *		Delete a bpf_local_storage from a *cgroup*.
5582c4bcfb38SYonghong Song  *	Return
5583c4bcfb38SYonghong Song  *		0 on success.
5584c4bcfb38SYonghong Song  *
5585c4bcfb38SYonghong Song  *		**-ENOENT** if the bpf_local_storage cannot be found.
55867a4b28c6SDaniel Borkmann  */
55878a76145aSAndrii Nakryiko #define ___BPF_FUNC_MAPPER(FN, ctx...)			\
55888a76145aSAndrii Nakryiko 	FN(unspec, 0, ##ctx)				\
55898a76145aSAndrii Nakryiko 	FN(map_lookup_elem, 1, ##ctx)			\
55908a76145aSAndrii Nakryiko 	FN(map_update_elem, 2, ##ctx)			\
55918a76145aSAndrii Nakryiko 	FN(map_delete_elem, 3, ##ctx)			\
55928a76145aSAndrii Nakryiko 	FN(probe_read, 4, ##ctx)			\
55938a76145aSAndrii Nakryiko 	FN(ktime_get_ns, 5, ##ctx)			\
55948a76145aSAndrii Nakryiko 	FN(trace_printk, 6, ##ctx)			\
55958a76145aSAndrii Nakryiko 	FN(get_prandom_u32, 7, ##ctx)			\
55968a76145aSAndrii Nakryiko 	FN(get_smp_processor_id, 8, ##ctx)		\
55978a76145aSAndrii Nakryiko 	FN(skb_store_bytes, 9, ##ctx)			\
55988a76145aSAndrii Nakryiko 	FN(l3_csum_replace, 10, ##ctx)			\
55998a76145aSAndrii Nakryiko 	FN(l4_csum_replace, 11, ##ctx)			\
56008a76145aSAndrii Nakryiko 	FN(tail_call, 12, ##ctx)			\
56018a76145aSAndrii Nakryiko 	FN(clone_redirect, 13, ##ctx)			\
56028a76145aSAndrii Nakryiko 	FN(get_current_pid_tgid, 14, ##ctx)		\
56038a76145aSAndrii Nakryiko 	FN(get_current_uid_gid, 15, ##ctx)		\
56048a76145aSAndrii Nakryiko 	FN(get_current_comm, 16, ##ctx)			\
56058a76145aSAndrii Nakryiko 	FN(get_cgroup_classid, 17, ##ctx)		\
56068a76145aSAndrii Nakryiko 	FN(skb_vlan_push, 18, ##ctx)			\
56078a76145aSAndrii Nakryiko 	FN(skb_vlan_pop, 19, ##ctx)			\
56088a76145aSAndrii Nakryiko 	FN(skb_get_tunnel_key, 20, ##ctx)		\
56098a76145aSAndrii Nakryiko 	FN(skb_set_tunnel_key, 21, ##ctx)		\
56108a76145aSAndrii Nakryiko 	FN(perf_event_read, 22, ##ctx)			\
56118a76145aSAndrii Nakryiko 	FN(redirect, 23, ##ctx)				\
56128a76145aSAndrii Nakryiko 	FN(get_route_realm, 24, ##ctx)			\
56138a76145aSAndrii Nakryiko 	FN(perf_event_output, 25, ##ctx)		\
56148a76145aSAndrii Nakryiko 	FN(skb_load_bytes, 26, ##ctx)			\
56158a76145aSAndrii Nakryiko 	FN(get_stackid, 27, ##ctx)			\
56168a76145aSAndrii Nakryiko 	FN(csum_diff, 28, ##ctx)			\
56178a76145aSAndrii Nakryiko 	FN(skb_get_tunnel_opt, 29, ##ctx)		\
56188a76145aSAndrii Nakryiko 	FN(skb_set_tunnel_opt, 30, ##ctx)		\
56198a76145aSAndrii Nakryiko 	FN(skb_change_proto, 31, ##ctx)			\
56208a76145aSAndrii Nakryiko 	FN(skb_change_type, 32, ##ctx)			\
56218a76145aSAndrii Nakryiko 	FN(skb_under_cgroup, 33, ##ctx)			\
56228a76145aSAndrii Nakryiko 	FN(get_hash_recalc, 34, ##ctx)			\
56238a76145aSAndrii Nakryiko 	FN(get_current_task, 35, ##ctx)			\
56248a76145aSAndrii Nakryiko 	FN(probe_write_user, 36, ##ctx)			\
56258a76145aSAndrii Nakryiko 	FN(current_task_under_cgroup, 37, ##ctx)	\
56268a76145aSAndrii Nakryiko 	FN(skb_change_tail, 38, ##ctx)			\
56278a76145aSAndrii Nakryiko 	FN(skb_pull_data, 39, ##ctx)			\
56288a76145aSAndrii Nakryiko 	FN(csum_update, 40, ##ctx)			\
56298a76145aSAndrii Nakryiko 	FN(set_hash_invalid, 41, ##ctx)			\
56308a76145aSAndrii Nakryiko 	FN(get_numa_node_id, 42, ##ctx)			\
56318a76145aSAndrii Nakryiko 	FN(skb_change_head, 43, ##ctx)			\
56328a76145aSAndrii Nakryiko 	FN(xdp_adjust_head, 44, ##ctx)			\
56338a76145aSAndrii Nakryiko 	FN(probe_read_str, 45, ##ctx)			\
56348a76145aSAndrii Nakryiko 	FN(get_socket_cookie, 46, ##ctx)		\
56358a76145aSAndrii Nakryiko 	FN(get_socket_uid, 47, ##ctx)			\
56368a76145aSAndrii Nakryiko 	FN(set_hash, 48, ##ctx)				\
56378a76145aSAndrii Nakryiko 	FN(setsockopt, 49, ##ctx)			\
56388a76145aSAndrii Nakryiko 	FN(skb_adjust_room, 50, ##ctx)			\
56398a76145aSAndrii Nakryiko 	FN(redirect_map, 51, ##ctx)			\
56408a76145aSAndrii Nakryiko 	FN(sk_redirect_map, 52, ##ctx)			\
56418a76145aSAndrii Nakryiko 	FN(sock_map_update, 53, ##ctx)			\
56428a76145aSAndrii Nakryiko 	FN(xdp_adjust_meta, 54, ##ctx)			\
56438a76145aSAndrii Nakryiko 	FN(perf_event_read_value, 55, ##ctx)		\
56448a76145aSAndrii Nakryiko 	FN(perf_prog_read_value, 56, ##ctx)		\
56458a76145aSAndrii Nakryiko 	FN(getsockopt, 57, ##ctx)			\
56468a76145aSAndrii Nakryiko 	FN(override_return, 58, ##ctx)			\
56478a76145aSAndrii Nakryiko 	FN(sock_ops_cb_flags_set, 59, ##ctx)		\
56488a76145aSAndrii Nakryiko 	FN(msg_redirect_map, 60, ##ctx)			\
56498a76145aSAndrii Nakryiko 	FN(msg_apply_bytes, 61, ##ctx)			\
56508a76145aSAndrii Nakryiko 	FN(msg_cork_bytes, 62, ##ctx)			\
56518a76145aSAndrii Nakryiko 	FN(msg_pull_data, 63, ##ctx)			\
56528a76145aSAndrii Nakryiko 	FN(bind, 64, ##ctx)				\
56538a76145aSAndrii Nakryiko 	FN(xdp_adjust_tail, 65, ##ctx)			\
56548a76145aSAndrii Nakryiko 	FN(skb_get_xfrm_state, 66, ##ctx)		\
56558a76145aSAndrii Nakryiko 	FN(get_stack, 67, ##ctx)			\
56568a76145aSAndrii Nakryiko 	FN(skb_load_bytes_relative, 68, ##ctx)		\
56578a76145aSAndrii Nakryiko 	FN(fib_lookup, 69, ##ctx)			\
56588a76145aSAndrii Nakryiko 	FN(sock_hash_update, 70, ##ctx)			\
56598a76145aSAndrii Nakryiko 	FN(msg_redirect_hash, 71, ##ctx)		\
56608a76145aSAndrii Nakryiko 	FN(sk_redirect_hash, 72, ##ctx)			\
56618a76145aSAndrii Nakryiko 	FN(lwt_push_encap, 73, ##ctx)			\
56628a76145aSAndrii Nakryiko 	FN(lwt_seg6_store_bytes, 74, ##ctx)		\
56638a76145aSAndrii Nakryiko 	FN(lwt_seg6_adjust_srh, 75, ##ctx)		\
56648a76145aSAndrii Nakryiko 	FN(lwt_seg6_action, 76, ##ctx)			\
56658a76145aSAndrii Nakryiko 	FN(rc_repeat, 77, ##ctx)			\
56668a76145aSAndrii Nakryiko 	FN(rc_keydown, 78, ##ctx)			\
56678a76145aSAndrii Nakryiko 	FN(skb_cgroup_id, 79, ##ctx)			\
56688a76145aSAndrii Nakryiko 	FN(get_current_cgroup_id, 80, ##ctx)		\
56698a76145aSAndrii Nakryiko 	FN(get_local_storage, 81, ##ctx)		\
56708a76145aSAndrii Nakryiko 	FN(sk_select_reuseport, 82, ##ctx)		\
56718a76145aSAndrii Nakryiko 	FN(skb_ancestor_cgroup_id, 83, ##ctx)		\
56728a76145aSAndrii Nakryiko 	FN(sk_lookup_tcp, 84, ##ctx)			\
56738a76145aSAndrii Nakryiko 	FN(sk_lookup_udp, 85, ##ctx)			\
56748a76145aSAndrii Nakryiko 	FN(sk_release, 86, ##ctx)			\
56758a76145aSAndrii Nakryiko 	FN(map_push_elem, 87, ##ctx)			\
56768a76145aSAndrii Nakryiko 	FN(map_pop_elem, 88, ##ctx)			\
56778a76145aSAndrii Nakryiko 	FN(map_peek_elem, 89, ##ctx)			\
56788a76145aSAndrii Nakryiko 	FN(msg_push_data, 90, ##ctx)			\
56798a76145aSAndrii Nakryiko 	FN(msg_pop_data, 91, ##ctx)			\
56808a76145aSAndrii Nakryiko 	FN(rc_pointer_rel, 92, ##ctx)			\
56818a76145aSAndrii Nakryiko 	FN(spin_lock, 93, ##ctx)			\
56828a76145aSAndrii Nakryiko 	FN(spin_unlock, 94, ##ctx)			\
56838a76145aSAndrii Nakryiko 	FN(sk_fullsock, 95, ##ctx)			\
56848a76145aSAndrii Nakryiko 	FN(tcp_sock, 96, ##ctx)				\
56858a76145aSAndrii Nakryiko 	FN(skb_ecn_set_ce, 97, ##ctx)			\
56868a76145aSAndrii Nakryiko 	FN(get_listener_sock, 98, ##ctx)		\
56878a76145aSAndrii Nakryiko 	FN(skc_lookup_tcp, 99, ##ctx)			\
56888a76145aSAndrii Nakryiko 	FN(tcp_check_syncookie, 100, ##ctx)		\
56898a76145aSAndrii Nakryiko 	FN(sysctl_get_name, 101, ##ctx)			\
56908a76145aSAndrii Nakryiko 	FN(sysctl_get_current_value, 102, ##ctx)	\
56918a76145aSAndrii Nakryiko 	FN(sysctl_get_new_value, 103, ##ctx)		\
56928a76145aSAndrii Nakryiko 	FN(sysctl_set_new_value, 104, ##ctx)		\
56938a76145aSAndrii Nakryiko 	FN(strtol, 105, ##ctx)				\
56948a76145aSAndrii Nakryiko 	FN(strtoul, 106, ##ctx)				\
56958a76145aSAndrii Nakryiko 	FN(sk_storage_get, 107, ##ctx)			\
56968a76145aSAndrii Nakryiko 	FN(sk_storage_delete, 108, ##ctx)		\
56978a76145aSAndrii Nakryiko 	FN(send_signal, 109, ##ctx)			\
56988a76145aSAndrii Nakryiko 	FN(tcp_gen_syncookie, 110, ##ctx)		\
56998a76145aSAndrii Nakryiko 	FN(skb_output, 111, ##ctx)			\
57008a76145aSAndrii Nakryiko 	FN(probe_read_user, 112, ##ctx)			\
57018a76145aSAndrii Nakryiko 	FN(probe_read_kernel, 113, ##ctx)		\
57028a76145aSAndrii Nakryiko 	FN(probe_read_user_str, 114, ##ctx)		\
57038a76145aSAndrii Nakryiko 	FN(probe_read_kernel_str, 115, ##ctx)		\
57048a76145aSAndrii Nakryiko 	FN(tcp_send_ack, 116, ##ctx)			\
57058a76145aSAndrii Nakryiko 	FN(send_signal_thread, 117, ##ctx)		\
57068a76145aSAndrii Nakryiko 	FN(jiffies64, 118, ##ctx)			\
57078a76145aSAndrii Nakryiko 	FN(read_branch_records, 119, ##ctx)		\
57088a76145aSAndrii Nakryiko 	FN(get_ns_current_pid_tgid, 120, ##ctx)		\
57098a76145aSAndrii Nakryiko 	FN(xdp_output, 121, ##ctx)			\
57108a76145aSAndrii Nakryiko 	FN(get_netns_cookie, 122, ##ctx)		\
57118a76145aSAndrii Nakryiko 	FN(get_current_ancestor_cgroup_id, 123, ##ctx)	\
57128a76145aSAndrii Nakryiko 	FN(sk_assign, 124, ##ctx)			\
57138a76145aSAndrii Nakryiko 	FN(ktime_get_boot_ns, 125, ##ctx)		\
57148a76145aSAndrii Nakryiko 	FN(seq_printf, 126, ##ctx)			\
57158a76145aSAndrii Nakryiko 	FN(seq_write, 127, ##ctx)			\
57168a76145aSAndrii Nakryiko 	FN(sk_cgroup_id, 128, ##ctx)			\
57178a76145aSAndrii Nakryiko 	FN(sk_ancestor_cgroup_id, 129, ##ctx)		\
57188a76145aSAndrii Nakryiko 	FN(ringbuf_output, 130, ##ctx)			\
57198a76145aSAndrii Nakryiko 	FN(ringbuf_reserve, 131, ##ctx)			\
57208a76145aSAndrii Nakryiko 	FN(ringbuf_submit, 132, ##ctx)			\
57218a76145aSAndrii Nakryiko 	FN(ringbuf_discard, 133, ##ctx)			\
57228a76145aSAndrii Nakryiko 	FN(ringbuf_query, 134, ##ctx)			\
57238a76145aSAndrii Nakryiko 	FN(csum_level, 135, ##ctx)			\
57248a76145aSAndrii Nakryiko 	FN(skc_to_tcp6_sock, 136, ##ctx)		\
57258a76145aSAndrii Nakryiko 	FN(skc_to_tcp_sock, 137, ##ctx)			\
57268a76145aSAndrii Nakryiko 	FN(skc_to_tcp_timewait_sock, 138, ##ctx)	\
57278a76145aSAndrii Nakryiko 	FN(skc_to_tcp_request_sock, 139, ##ctx)		\
57288a76145aSAndrii Nakryiko 	FN(skc_to_udp6_sock, 140, ##ctx)		\
57298a76145aSAndrii Nakryiko 	FN(get_task_stack, 141, ##ctx)			\
57308a76145aSAndrii Nakryiko 	FN(load_hdr_opt, 142, ##ctx)			\
57318a76145aSAndrii Nakryiko 	FN(store_hdr_opt, 143, ##ctx)			\
57328a76145aSAndrii Nakryiko 	FN(reserve_hdr_opt, 144, ##ctx)			\
57338a76145aSAndrii Nakryiko 	FN(inode_storage_get, 145, ##ctx)		\
57348a76145aSAndrii Nakryiko 	FN(inode_storage_delete, 146, ##ctx)		\
57358a76145aSAndrii Nakryiko 	FN(d_path, 147, ##ctx)				\
57368a76145aSAndrii Nakryiko 	FN(copy_from_user, 148, ##ctx)			\
57378a76145aSAndrii Nakryiko 	FN(snprintf_btf, 149, ##ctx)			\
57388a76145aSAndrii Nakryiko 	FN(seq_printf_btf, 150, ##ctx)			\
57398a76145aSAndrii Nakryiko 	FN(skb_cgroup_classid, 151, ##ctx)		\
57408a76145aSAndrii Nakryiko 	FN(redirect_neigh, 152, ##ctx)			\
57418a76145aSAndrii Nakryiko 	FN(per_cpu_ptr, 153, ##ctx)			\
57428a76145aSAndrii Nakryiko 	FN(this_cpu_ptr, 154, ##ctx)			\
57438a76145aSAndrii Nakryiko 	FN(redirect_peer, 155, ##ctx)			\
57448a76145aSAndrii Nakryiko 	FN(task_storage_get, 156, ##ctx)		\
57458a76145aSAndrii Nakryiko 	FN(task_storage_delete, 157, ##ctx)		\
57468a76145aSAndrii Nakryiko 	FN(get_current_task_btf, 158, ##ctx)		\
57478a76145aSAndrii Nakryiko 	FN(bprm_opts_set, 159, ##ctx)			\
57488a76145aSAndrii Nakryiko 	FN(ktime_get_coarse_ns, 160, ##ctx)		\
57498a76145aSAndrii Nakryiko 	FN(ima_inode_hash, 161, ##ctx)			\
57508a76145aSAndrii Nakryiko 	FN(sock_from_file, 162, ##ctx)			\
57518a76145aSAndrii Nakryiko 	FN(check_mtu, 163, ##ctx)			\
57528a76145aSAndrii Nakryiko 	FN(for_each_map_elem, 164, ##ctx)		\
57538a76145aSAndrii Nakryiko 	FN(snprintf, 165, ##ctx)			\
57548a76145aSAndrii Nakryiko 	FN(sys_bpf, 166, ##ctx)				\
57558a76145aSAndrii Nakryiko 	FN(btf_find_by_name_kind, 167, ##ctx)		\
57568a76145aSAndrii Nakryiko 	FN(sys_close, 168, ##ctx)			\
57578a76145aSAndrii Nakryiko 	FN(timer_init, 169, ##ctx)			\
57588a76145aSAndrii Nakryiko 	FN(timer_set_callback, 170, ##ctx)		\
57598a76145aSAndrii Nakryiko 	FN(timer_start, 171, ##ctx)			\
57608a76145aSAndrii Nakryiko 	FN(timer_cancel, 172, ##ctx)			\
57618a76145aSAndrii Nakryiko 	FN(get_func_ip, 173, ##ctx)			\
57628a76145aSAndrii Nakryiko 	FN(get_attach_cookie, 174, ##ctx)		\
57638a76145aSAndrii Nakryiko 	FN(task_pt_regs, 175, ##ctx)			\
57648a76145aSAndrii Nakryiko 	FN(get_branch_snapshot, 176, ##ctx)		\
57658a76145aSAndrii Nakryiko 	FN(trace_vprintk, 177, ##ctx)			\
57668a76145aSAndrii Nakryiko 	FN(skc_to_unix_sock, 178, ##ctx)		\
57678a76145aSAndrii Nakryiko 	FN(kallsyms_lookup_name, 179, ##ctx)		\
57688a76145aSAndrii Nakryiko 	FN(find_vma, 180, ##ctx)			\
57698a76145aSAndrii Nakryiko 	FN(loop, 181, ##ctx)				\
57708a76145aSAndrii Nakryiko 	FN(strncmp, 182, ##ctx)				\
57718a76145aSAndrii Nakryiko 	FN(get_func_arg, 183, ##ctx)			\
57728a76145aSAndrii Nakryiko 	FN(get_func_ret, 184, ##ctx)			\
57738a76145aSAndrii Nakryiko 	FN(get_func_arg_cnt, 185, ##ctx)		\
57748a76145aSAndrii Nakryiko 	FN(get_retval, 186, ##ctx)			\
57758a76145aSAndrii Nakryiko 	FN(set_retval, 187, ##ctx)			\
57768a76145aSAndrii Nakryiko 	FN(xdp_get_buff_len, 188, ##ctx)		\
57778a76145aSAndrii Nakryiko 	FN(xdp_load_bytes, 189, ##ctx)			\
57788a76145aSAndrii Nakryiko 	FN(xdp_store_bytes, 190, ##ctx)			\
57798a76145aSAndrii Nakryiko 	FN(copy_from_user_task, 191, ##ctx)		\
57808a76145aSAndrii Nakryiko 	FN(skb_set_tstamp, 192, ##ctx)			\
57818a76145aSAndrii Nakryiko 	FN(ima_file_hash, 193, ##ctx)			\
57828a76145aSAndrii Nakryiko 	FN(kptr_xchg, 194, ##ctx)			\
57838a76145aSAndrii Nakryiko 	FN(map_lookup_percpu_elem, 195, ##ctx)		\
57848a76145aSAndrii Nakryiko 	FN(skc_to_mptcp_sock, 196, ##ctx)		\
57858a76145aSAndrii Nakryiko 	FN(dynptr_from_mem, 197, ##ctx)			\
57868a76145aSAndrii Nakryiko 	FN(ringbuf_reserve_dynptr, 198, ##ctx)		\
57878a76145aSAndrii Nakryiko 	FN(ringbuf_submit_dynptr, 199, ##ctx)		\
57888a76145aSAndrii Nakryiko 	FN(ringbuf_discard_dynptr, 200, ##ctx)		\
57898a76145aSAndrii Nakryiko 	FN(dynptr_read, 201, ##ctx)			\
57908a76145aSAndrii Nakryiko 	FN(dynptr_write, 202, ##ctx)			\
57918a76145aSAndrii Nakryiko 	FN(dynptr_data, 203, ##ctx)			\
57928a76145aSAndrii Nakryiko 	FN(tcp_raw_gen_syncookie_ipv4, 204, ##ctx)	\
57938a76145aSAndrii Nakryiko 	FN(tcp_raw_gen_syncookie_ipv6, 205, ##ctx)	\
57948a76145aSAndrii Nakryiko 	FN(tcp_raw_check_syncookie_ipv4, 206, ##ctx)	\
57958a76145aSAndrii Nakryiko 	FN(tcp_raw_check_syncookie_ipv6, 207, ##ctx)	\
57968a76145aSAndrii Nakryiko 	FN(ktime_get_tai_ns, 208, ##ctx)		\
57978a76145aSAndrii Nakryiko 	FN(user_ringbuf_drain, 209, ##ctx)		\
5798c4bcfb38SYonghong Song 	FN(cgrp_storage_get, 210, ##ctx)		\
5799c4bcfb38SYonghong Song 	FN(cgrp_storage_delete, 211, ##ctx)		\
5800fa28dcb8SSong Liu 	/* */
58017a4b28c6SDaniel Borkmann 
58028a76145aSAndrii Nakryiko /* backwards-compatibility macros for users of __BPF_FUNC_MAPPER that don't
58038a76145aSAndrii Nakryiko  * know or care about integer value that is now passed as second argument
58048a76145aSAndrii Nakryiko  */
58058a76145aSAndrii Nakryiko #define __BPF_FUNC_MAPPER_APPLY(name, value, FN) FN(name),
58068a76145aSAndrii Nakryiko #define __BPF_FUNC_MAPPER(FN) ___BPF_FUNC_MAPPER(__BPF_FUNC_MAPPER_APPLY, FN)
58078a76145aSAndrii Nakryiko 
5808ebb676daSThomas Graf /* integer value in 'imm' field of BPF_CALL instruction selects which helper
5809ebb676daSThomas Graf  * function eBPF program intends to call
58102d0e30c3SDaniel Borkmann  */
58118a76145aSAndrii Nakryiko #define __BPF_ENUM_FN(x, y) BPF_FUNC_ ## x = y,
5812ebb676daSThomas Graf enum bpf_func_id {
58138a76145aSAndrii Nakryiko 	___BPF_FUNC_MAPPER(__BPF_ENUM_FN)
581409756af4SAlexei Starovoitov 	__BPF_FUNC_MAX_ID,
581509756af4SAlexei Starovoitov };
5816ebb676daSThomas Graf #undef __BPF_ENUM_FN
581709756af4SAlexei Starovoitov 
5818781c53bcSDaniel Borkmann /* All flags used by eBPF helper functions, placed here. */
5819781c53bcSDaniel Borkmann 
5820781c53bcSDaniel Borkmann /* BPF_FUNC_skb_store_bytes flags. */
58211aae4bddSAndrii Nakryiko enum {
58221aae4bddSAndrii Nakryiko 	BPF_F_RECOMPUTE_CSUM		= (1ULL << 0),
58231aae4bddSAndrii Nakryiko 	BPF_F_INVALIDATE_HASH		= (1ULL << 1),
58241aae4bddSAndrii Nakryiko };
5825781c53bcSDaniel Borkmann 
5826781c53bcSDaniel Borkmann /* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
5827781c53bcSDaniel Borkmann  * First 4 bits are for passing the header field size.
5828781c53bcSDaniel Borkmann  */
58291aae4bddSAndrii Nakryiko enum {
58301aae4bddSAndrii Nakryiko 	BPF_F_HDR_FIELD_MASK		= 0xfULL,
58311aae4bddSAndrii Nakryiko };
5832781c53bcSDaniel Borkmann 
5833781c53bcSDaniel Borkmann /* BPF_FUNC_l4_csum_replace flags. */
58341aae4bddSAndrii Nakryiko enum {
58351aae4bddSAndrii Nakryiko 	BPF_F_PSEUDO_HDR		= (1ULL << 4),
58361aae4bddSAndrii Nakryiko 	BPF_F_MARK_MANGLED_0		= (1ULL << 5),
58371aae4bddSAndrii Nakryiko 	BPF_F_MARK_ENFORCE		= (1ULL << 6),
58381aae4bddSAndrii Nakryiko };
5839781c53bcSDaniel Borkmann 
5840781c53bcSDaniel Borkmann /* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */
58411aae4bddSAndrii Nakryiko enum {
58421aae4bddSAndrii Nakryiko 	BPF_F_INGRESS			= (1ULL << 0),
58431aae4bddSAndrii Nakryiko };
5844781c53bcSDaniel Borkmann 
5845c6c33454SDaniel Borkmann /* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */
58461aae4bddSAndrii Nakryiko enum {
58471aae4bddSAndrii Nakryiko 	BPF_F_TUNINFO_IPV6		= (1ULL << 0),
58481aae4bddSAndrii Nakryiko };
5849c6c33454SDaniel Borkmann 
5850c195651eSYonghong Song /* flags for both BPF_FUNC_get_stackid and BPF_FUNC_get_stack. */
58511aae4bddSAndrii Nakryiko enum {
58521aae4bddSAndrii Nakryiko 	BPF_F_SKIP_FIELD_MASK		= 0xffULL,
58531aae4bddSAndrii Nakryiko 	BPF_F_USER_STACK		= (1ULL << 8),
5854c195651eSYonghong Song /* flags used by BPF_FUNC_get_stackid only. */
58551aae4bddSAndrii Nakryiko 	BPF_F_FAST_STACK_CMP		= (1ULL << 9),
58561aae4bddSAndrii Nakryiko 	BPF_F_REUSE_STACKID		= (1ULL << 10),
5857c195651eSYonghong Song /* flags used by BPF_FUNC_get_stack only. */
58581aae4bddSAndrii Nakryiko 	BPF_F_USER_BUILD_ID		= (1ULL << 11),
58591aae4bddSAndrii Nakryiko };
5860d5a3b1f6SAlexei Starovoitov 
58612da897e5SDaniel Borkmann /* BPF_FUNC_skb_set_tunnel_key flags. */
58621aae4bddSAndrii Nakryiko enum {
58631aae4bddSAndrii Nakryiko 	BPF_F_ZERO_CSUM_TX		= (1ULL << 1),
58641aae4bddSAndrii Nakryiko 	BPF_F_DONT_FRAGMENT		= (1ULL << 2),
58651aae4bddSAndrii Nakryiko 	BPF_F_SEQ_NUMBER		= (1ULL << 3),
5866e26aa600SChristian Ehrig 	BPF_F_NO_TUNNEL_KEY		= (1ULL << 4),
58671aae4bddSAndrii Nakryiko };
58682da897e5SDaniel Borkmann 
586944c51472SShmulik Ladkani /* BPF_FUNC_skb_get_tunnel_key flags. */
587044c51472SShmulik Ladkani enum {
587144c51472SShmulik Ladkani 	BPF_F_TUNINFO_FLAGS		= (1ULL << 4),
587244c51472SShmulik Ladkani };
587344c51472SShmulik Ladkani 
5874908432caSYonghong Song /* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
5875908432caSYonghong Song  * BPF_FUNC_perf_event_read_value flags.
5876908432caSYonghong Song  */
58771aae4bddSAndrii Nakryiko enum {
58781aae4bddSAndrii Nakryiko 	BPF_F_INDEX_MASK		= 0xffffffffULL,
58791aae4bddSAndrii Nakryiko 	BPF_F_CURRENT_CPU		= BPF_F_INDEX_MASK,
5880555c8a86SDaniel Borkmann /* BPF_FUNC_perf_event_output for sk_buff input context. */
58811aae4bddSAndrii Nakryiko 	BPF_F_CTXLEN_MASK		= (0xfffffULL << 32),
58821aae4bddSAndrii Nakryiko };
58831e33759cSDaniel Borkmann 
5884f71c6143SJoe Stringer /* Current network namespace */
58851aae4bddSAndrii Nakryiko enum {
58861aae4bddSAndrii Nakryiko 	BPF_F_CURRENT_NETNS		= (-1L),
58871aae4bddSAndrii Nakryiko };
5888f71c6143SJoe Stringer 
58897cdec54fSDaniel Borkmann /* BPF_FUNC_csum_level level values. */
58907cdec54fSDaniel Borkmann enum {
58917cdec54fSDaniel Borkmann 	BPF_CSUM_LEVEL_QUERY,
58927cdec54fSDaniel Borkmann 	BPF_CSUM_LEVEL_INC,
58937cdec54fSDaniel Borkmann 	BPF_CSUM_LEVEL_DEC,
58947cdec54fSDaniel Borkmann 	BPF_CSUM_LEVEL_RESET,
58957cdec54fSDaniel Borkmann };
58967cdec54fSDaniel Borkmann 
58972278f6ccSWillem de Bruijn /* BPF_FUNC_skb_adjust_room flags. */
58981aae4bddSAndrii Nakryiko enum {
58991aae4bddSAndrii Nakryiko 	BPF_F_ADJ_ROOM_FIXED_GSO	= (1ULL << 0),
59001aae4bddSAndrii Nakryiko 	BPF_F_ADJ_ROOM_ENCAP_L3_IPV4	= (1ULL << 1),
59011aae4bddSAndrii Nakryiko 	BPF_F_ADJ_ROOM_ENCAP_L3_IPV6	= (1ULL << 2),
59021aae4bddSAndrii Nakryiko 	BPF_F_ADJ_ROOM_ENCAP_L4_GRE	= (1ULL << 3),
59031aae4bddSAndrii Nakryiko 	BPF_F_ADJ_ROOM_ENCAP_L4_UDP	= (1ULL << 4),
5904836e66c2SDaniel Borkmann 	BPF_F_ADJ_ROOM_NO_CSUM_RESET	= (1ULL << 5),
5905d01b59c9SXuesen Huang 	BPF_F_ADJ_ROOM_ENCAP_L2_ETH	= (1ULL << 6),
5906d219df60SZiyang Xuan 	BPF_F_ADJ_ROOM_DECAP_L3_IPV4	= (1ULL << 7),
5907d219df60SZiyang Xuan 	BPF_F_ADJ_ROOM_DECAP_L3_IPV6	= (1ULL << 8),
59081aae4bddSAndrii Nakryiko };
59092278f6ccSWillem de Bruijn 
59101aae4bddSAndrii Nakryiko enum {
59111aae4bddSAndrii Nakryiko 	BPF_ADJ_ROOM_ENCAP_L2_MASK	= 0xff,
59121aae4bddSAndrii Nakryiko 	BPF_ADJ_ROOM_ENCAP_L2_SHIFT	= 56,
59131aae4bddSAndrii Nakryiko };
591458dfc900SAlan Maguire 
591558dfc900SAlan Maguire #define BPF_F_ADJ_ROOM_ENCAP_L2(len)	(((__u64)len & \
591658dfc900SAlan Maguire 					  BPF_ADJ_ROOM_ENCAP_L2_MASK) \
591758dfc900SAlan Maguire 					 << BPF_ADJ_ROOM_ENCAP_L2_SHIFT)
5918868d5235SWillem de Bruijn 
5919808649fbSAndrey Ignatov /* BPF_FUNC_sysctl_get_name flags. */
59201aae4bddSAndrii Nakryiko enum {
59211aae4bddSAndrii Nakryiko 	BPF_F_SYSCTL_BASE_NAME		= (1ULL << 0),
59221aae4bddSAndrii Nakryiko };
5923808649fbSAndrey Ignatov 
5924f836a56eSKP Singh /* BPF_FUNC_<kernel_obj>_storage_get flags */
59251aae4bddSAndrii Nakryiko enum {
5926f836a56eSKP Singh 	BPF_LOCAL_STORAGE_GET_F_CREATE	= (1ULL << 0),
5927f836a56eSKP Singh 	/* BPF_SK_STORAGE_GET_F_CREATE is only kept for backward compatibility
5928f836a56eSKP Singh 	 * and BPF_LOCAL_STORAGE_GET_F_CREATE must be used instead.
5929f836a56eSKP Singh 	 */
5930f836a56eSKP Singh 	BPF_SK_STORAGE_GET_F_CREATE  = BPF_LOCAL_STORAGE_GET_F_CREATE,
59311aae4bddSAndrii Nakryiko };
59326ac99e8fSMartin KaFai Lau 
5933fff7b643SDaniel Xu /* BPF_FUNC_read_branch_records flags. */
59341aae4bddSAndrii Nakryiko enum {
59351aae4bddSAndrii Nakryiko 	BPF_F_GET_BRANCH_RECORDS_SIZE	= (1ULL << 0),
59361aae4bddSAndrii Nakryiko };
5937fff7b643SDaniel Xu 
5938457f4436SAndrii Nakryiko /* BPF_FUNC_bpf_ringbuf_commit, BPF_FUNC_bpf_ringbuf_discard, and
5939457f4436SAndrii Nakryiko  * BPF_FUNC_bpf_ringbuf_output flags.
5940457f4436SAndrii Nakryiko  */
5941457f4436SAndrii Nakryiko enum {
5942457f4436SAndrii Nakryiko 	BPF_RB_NO_WAKEUP		= (1ULL << 0),
5943457f4436SAndrii Nakryiko 	BPF_RB_FORCE_WAKEUP		= (1ULL << 1),
5944457f4436SAndrii Nakryiko };
5945457f4436SAndrii Nakryiko 
5946457f4436SAndrii Nakryiko /* BPF_FUNC_bpf_ringbuf_query flags */
5947457f4436SAndrii Nakryiko enum {
5948457f4436SAndrii Nakryiko 	BPF_RB_AVAIL_DATA = 0,
5949457f4436SAndrii Nakryiko 	BPF_RB_RING_SIZE = 1,
5950457f4436SAndrii Nakryiko 	BPF_RB_CONS_POS = 2,
5951457f4436SAndrii Nakryiko 	BPF_RB_PROD_POS = 3,
5952457f4436SAndrii Nakryiko };
5953457f4436SAndrii Nakryiko 
5954457f4436SAndrii Nakryiko /* BPF ring buffer constants */
5955457f4436SAndrii Nakryiko enum {
5956457f4436SAndrii Nakryiko 	BPF_RINGBUF_BUSY_BIT		= (1U << 31),
5957457f4436SAndrii Nakryiko 	BPF_RINGBUF_DISCARD_BIT		= (1U << 30),
5958457f4436SAndrii Nakryiko 	BPF_RINGBUF_HDR_SZ		= 8,
5959457f4436SAndrii Nakryiko };
5960457f4436SAndrii Nakryiko 
5961e9ddbb77SJakub Sitnicki /* BPF_FUNC_sk_assign flags in bpf_sk_lookup context. */
5962e9ddbb77SJakub Sitnicki enum {
5963e9ddbb77SJakub Sitnicki 	BPF_SK_LOOKUP_F_REPLACE		= (1ULL << 0),
5964e9ddbb77SJakub Sitnicki 	BPF_SK_LOOKUP_F_NO_REUSEPORT	= (1ULL << 1),
5965e9ddbb77SJakub Sitnicki };
5966e9ddbb77SJakub Sitnicki 
59672be7e212SDaniel Borkmann /* Mode for BPF_FUNC_skb_adjust_room helper. */
59682be7e212SDaniel Borkmann enum bpf_adj_room_mode {
59692be7e212SDaniel Borkmann 	BPF_ADJ_ROOM_NET,
597014aa3192SWillem de Bruijn 	BPF_ADJ_ROOM_MAC,
59712be7e212SDaniel Borkmann };
59722be7e212SDaniel Borkmann 
59734e1ec56cSDaniel Borkmann /* Mode for BPF_FUNC_skb_load_bytes_relative helper. */
59744e1ec56cSDaniel Borkmann enum bpf_hdr_start_off {
59754e1ec56cSDaniel Borkmann 	BPF_HDR_START_MAC,
59764e1ec56cSDaniel Borkmann 	BPF_HDR_START_NET,
59774e1ec56cSDaniel Borkmann };
59784e1ec56cSDaniel Borkmann 
5979fe94cc29SMathieu Xhonneux /* Encapsulation type for BPF_FUNC_lwt_push_encap helper. */
5980fe94cc29SMathieu Xhonneux enum bpf_lwt_encap_mode {
5981fe94cc29SMathieu Xhonneux 	BPF_LWT_ENCAP_SEG6,
59823e0bd37cSPeter Oskolkov 	BPF_LWT_ENCAP_SEG6_INLINE,
59833e0bd37cSPeter Oskolkov 	BPF_LWT_ENCAP_IP,
5984fe94cc29SMathieu Xhonneux };
5985fe94cc29SMathieu Xhonneux 
59863f6719c7SKP Singh /* Flags for bpf_bprm_opts_set helper */
59873f6719c7SKP Singh enum {
59883f6719c7SKP Singh 	BPF_F_BPRM_SECUREEXEC	= (1ULL << 0),
59893f6719c7SKP Singh };
59903f6719c7SKP Singh 
5991e624d4edSHangbin Liu /* Flags for bpf_redirect_map helper */
5992e624d4edSHangbin Liu enum {
5993e624d4edSHangbin Liu 	BPF_F_BROADCAST		= (1ULL << 3),
5994e624d4edSHangbin Liu 	BPF_F_EXCLUDE_INGRESS	= (1ULL << 4),
5995e624d4edSHangbin Liu };
5996e624d4edSHangbin Liu 
5997b7df9adaSDaniel Borkmann #define __bpf_md_ptr(type, name)	\
5998b7df9adaSDaniel Borkmann union {					\
5999b7df9adaSDaniel Borkmann 	type name;			\
6000b7df9adaSDaniel Borkmann 	__u64 :64;			\
6001b7df9adaSDaniel Borkmann } __attribute__((aligned(8)))
6002b7df9adaSDaniel Borkmann 
60038d21ec0eSMartin KaFai Lau enum {
60049bb984f2SMartin KaFai Lau 	BPF_SKB_TSTAMP_UNSPEC,
60059bb984f2SMartin KaFai Lau 	BPF_SKB_TSTAMP_DELIVERY_MONO,	/* tstamp has mono delivery time */
60069bb984f2SMartin KaFai Lau 	/* For any BPF_SKB_TSTAMP_* that the bpf prog cannot handle,
60079bb984f2SMartin KaFai Lau 	 * the bpf prog should handle it like BPF_SKB_TSTAMP_UNSPEC
60089bb984f2SMartin KaFai Lau 	 * and try to deduce it by ingress, egress or skb->sk->sk_clockid.
60099bb984f2SMartin KaFai Lau 	 */
60108d21ec0eSMartin KaFai Lau };
60118d21ec0eSMartin KaFai Lau 
60129bac3d6dSAlexei Starovoitov /* user accessible mirror of in-kernel sk_buff.
60139bac3d6dSAlexei Starovoitov  * new fields can only be added to the end of this structure
60149bac3d6dSAlexei Starovoitov  */
60159bac3d6dSAlexei Starovoitov struct __sk_buff {
60169bac3d6dSAlexei Starovoitov 	__u32 len;
60179bac3d6dSAlexei Starovoitov 	__u32 pkt_type;
60189bac3d6dSAlexei Starovoitov 	__u32 mark;
60199bac3d6dSAlexei Starovoitov 	__u32 queue_mapping;
6020c2497395SAlexei Starovoitov 	__u32 protocol;
6021c2497395SAlexei Starovoitov 	__u32 vlan_present;
6022c2497395SAlexei Starovoitov 	__u32 vlan_tci;
602327cd5452SMichal Sekletar 	__u32 vlan_proto;
6024bcad5718SDaniel Borkmann 	__u32 priority;
602537e82c2fSAlexei Starovoitov 	__u32 ingress_ifindex;
602637e82c2fSAlexei Starovoitov 	__u32 ifindex;
6027d691f9e8SAlexei Starovoitov 	__u32 tc_index;
6028d691f9e8SAlexei Starovoitov 	__u32 cb[5];
6029ba7591d8SDaniel Borkmann 	__u32 hash;
6030045efa82SDaniel Borkmann 	__u32 tc_classid;
6031969bf05eSAlexei Starovoitov 	__u32 data;
6032969bf05eSAlexei Starovoitov 	__u32 data_end;
6033b1d9fc41SDaniel Borkmann 	__u32 napi_id;
60348a31db56SJohn Fastabend 
6035de8f3a83SDaniel Borkmann 	/* Accessed by BPF_PROG_TYPE_sk_skb types from here to ... */
60368a31db56SJohn Fastabend 	__u32 family;
60378a31db56SJohn Fastabend 	__u32 remote_ip4;	/* Stored in network byte order */
60388a31db56SJohn Fastabend 	__u32 local_ip4;	/* Stored in network byte order */
60398a31db56SJohn Fastabend 	__u32 remote_ip6[4];	/* Stored in network byte order */
60408a31db56SJohn Fastabend 	__u32 local_ip6[4];	/* Stored in network byte order */
60418a31db56SJohn Fastabend 	__u32 remote_port;	/* Stored in network byte order */
60428a31db56SJohn Fastabend 	__u32 local_port;	/* stored in host byte order */
6043de8f3a83SDaniel Borkmann 	/* ... here. */
6044de8f3a83SDaniel Borkmann 
6045de8f3a83SDaniel Borkmann 	__u32 data_meta;
6046b7df9adaSDaniel Borkmann 	__bpf_md_ptr(struct bpf_flow_keys *, flow_keys);
6047f11216b2SVlad Dumitrescu 	__u64 tstamp;
6048e3da08d0SPetar Penkov 	__u32 wire_len;
6049d9ff286aSEric Dumazet 	__u32 gso_segs;
605046f8bc92SMartin KaFai Lau 	__bpf_md_ptr(struct bpf_sock *, sk);
6051cf62089bSWillem de Bruijn 	__u32 gso_size;
60529bb984f2SMartin KaFai Lau 	__u8  tstamp_type;
60538d21ec0eSMartin KaFai Lau 	__u32 :24;		/* Padding, future use. */
6054f64c4aceSVadim Fedorenko 	__u64 hwtstamp;
60559bac3d6dSAlexei Starovoitov };
60569bac3d6dSAlexei Starovoitov 
6057d3aa45ceSAlexei Starovoitov struct bpf_tunnel_key {
6058d3aa45ceSAlexei Starovoitov 	__u32 tunnel_id;
6059c6c33454SDaniel Borkmann 	union {
6060d3aa45ceSAlexei Starovoitov 		__u32 remote_ipv4;
6061c6c33454SDaniel Borkmann 		__u32 remote_ipv6[4];
6062c6c33454SDaniel Borkmann 	};
6063c6c33454SDaniel Borkmann 	__u8 tunnel_tos;
6064c6c33454SDaniel Borkmann 	__u8 tunnel_ttl;
606544c51472SShmulik Ladkani 	union {
606644c51472SShmulik Ladkani 		__u16 tunnel_ext;	/* compat */
606744c51472SShmulik Ladkani 		__be16 tunnel_flags;
606844c51472SShmulik Ladkani 	};
60694018ab18SDaniel Borkmann 	__u32 tunnel_label;
607026101f5aSKaixi Fan 	union {
607126101f5aSKaixi Fan 		__u32 local_ipv4;
607226101f5aSKaixi Fan 		__u32 local_ipv6[4];
607326101f5aSKaixi Fan 	};
6074d3aa45ceSAlexei Starovoitov };
6075d3aa45ceSAlexei Starovoitov 
607612bed760SEyal Birger /* user accessible mirror of in-kernel xfrm_state.
607712bed760SEyal Birger  * new fields can only be added to the end of this structure
607812bed760SEyal Birger  */
607912bed760SEyal Birger struct bpf_xfrm_state {
608012bed760SEyal Birger 	__u32 reqid;
608112bed760SEyal Birger 	__u32 spi;	/* Stored in network byte order */
608212bed760SEyal Birger 	__u16 family;
60831fbc2e0cSDaniel Borkmann 	__u16 ext;	/* Padding, future use. */
608412bed760SEyal Birger 	union {
608512bed760SEyal Birger 		__u32 remote_ipv4;	/* Stored in network byte order */
608612bed760SEyal Birger 		__u32 remote_ipv6[4];	/* Stored in network byte order */
608712bed760SEyal Birger 	};
608812bed760SEyal Birger };
608912bed760SEyal Birger 
60903a0af8fdSThomas Graf /* Generic BPF return codes which all BPF program types may support.
60913a0af8fdSThomas Graf  * The values are binary compatible with their TC_ACT_* counter-part to
60923a0af8fdSThomas Graf  * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT
60933a0af8fdSThomas Graf  * programs.
60943a0af8fdSThomas Graf  *
60953a0af8fdSThomas Graf  * XDP is handled seprately, see XDP_*.
60963a0af8fdSThomas Graf  */
60973a0af8fdSThomas Graf enum bpf_ret_code {
60983a0af8fdSThomas Graf 	BPF_OK = 0,
60993a0af8fdSThomas Graf 	/* 1 reserved */
61003a0af8fdSThomas Graf 	BPF_DROP = 2,
61013a0af8fdSThomas Graf 	/* 3-6 reserved */
61023a0af8fdSThomas Graf 	BPF_REDIRECT = 7,
61033e0bd37cSPeter Oskolkov 	/* >127 are reserved for prog type specific return codes.
61043e0bd37cSPeter Oskolkov 	 *
61053e0bd37cSPeter Oskolkov 	 * BPF_LWT_REROUTE: used by BPF_PROG_TYPE_LWT_IN and
61063e0bd37cSPeter Oskolkov 	 *    BPF_PROG_TYPE_LWT_XMIT to indicate that skb had been
61073e0bd37cSPeter Oskolkov 	 *    changed and should be routed based on its new L3 header.
61083e0bd37cSPeter Oskolkov 	 *    (This is an L3 redirect, as opposed to L2 redirect
61093e0bd37cSPeter Oskolkov 	 *    represented by BPF_REDIRECT above).
61103e0bd37cSPeter Oskolkov 	 */
61113e0bd37cSPeter Oskolkov 	BPF_LWT_REROUTE = 128,
611291350fe1SShmulik Ladkani 	/* BPF_FLOW_DISSECTOR_CONTINUE: used by BPF_PROG_TYPE_FLOW_DISSECTOR
611391350fe1SShmulik Ladkani 	 *   to indicate that no custom dissection was performed, and
611491350fe1SShmulik Ladkani 	 *   fallback to standard dissector is requested.
611591350fe1SShmulik Ladkani 	 */
611691350fe1SShmulik Ladkani 	BPF_FLOW_DISSECTOR_CONTINUE = 129,
61173a0af8fdSThomas Graf };
61183a0af8fdSThomas Graf 
611961023658SDavid Ahern struct bpf_sock {
612061023658SDavid Ahern 	__u32 bound_dev_if;
6121aa4c1037SDavid Ahern 	__u32 family;
6122aa4c1037SDavid Ahern 	__u32 type;
6123aa4c1037SDavid Ahern 	__u32 protocol;
6124482dca93SDavid Ahern 	__u32 mark;
6125482dca93SDavid Ahern 	__u32 priority;
6126aa65d696SMartin KaFai Lau 	/* IP address also allows 1 and 2 bytes access */
6127aa65d696SMartin KaFai Lau 	__u32 src_ip4;
6128aa65d696SMartin KaFai Lau 	__u32 src_ip6[4];
6129aa65d696SMartin KaFai Lau 	__u32 src_port;		/* host byte order */
61304421a582SJakub Sitnicki 	__be16 dst_port;	/* network byte order */
61314421a582SJakub Sitnicki 	__u16 :16;		/* zero padding */
6132aa65d696SMartin KaFai Lau 	__u32 dst_ip4;
6133aa65d696SMartin KaFai Lau 	__u32 dst_ip6[4];
6134aa65d696SMartin KaFai Lau 	__u32 state;
6135c3c16f2eSAmritha Nambiar 	__s32 rx_queue_mapping;
613661023658SDavid Ahern };
613761023658SDavid Ahern 
6138655a51e5SMartin KaFai Lau struct bpf_tcp_sock {
6139655a51e5SMartin KaFai Lau 	__u32 snd_cwnd;		/* Sending congestion window		*/
6140655a51e5SMartin KaFai Lau 	__u32 srtt_us;		/* smoothed round trip time << 3 in usecs */
6141655a51e5SMartin KaFai Lau 	__u32 rtt_min;
6142655a51e5SMartin KaFai Lau 	__u32 snd_ssthresh;	/* Slow start size threshold		*/
6143655a51e5SMartin KaFai Lau 	__u32 rcv_nxt;		/* What we want to receive next		*/
6144655a51e5SMartin KaFai Lau 	__u32 snd_nxt;		/* Next sequence we send		*/
6145655a51e5SMartin KaFai Lau 	__u32 snd_una;		/* First byte we want an ack for	*/
6146655a51e5SMartin KaFai Lau 	__u32 mss_cache;	/* Cached effective mss, not including SACKS */
6147655a51e5SMartin KaFai Lau 	__u32 ecn_flags;	/* ECN status bits.			*/
6148655a51e5SMartin KaFai Lau 	__u32 rate_delivered;	/* saved rate sample: packets delivered */
6149655a51e5SMartin KaFai Lau 	__u32 rate_interval_us;	/* saved rate sample: time elapsed */
6150655a51e5SMartin KaFai Lau 	__u32 packets_out;	/* Packets which are "in flight"	*/
6151655a51e5SMartin KaFai Lau 	__u32 retrans_out;	/* Retransmitted packets out		*/
6152655a51e5SMartin KaFai Lau 	__u32 total_retrans;	/* Total retransmits for entire connection */
6153655a51e5SMartin KaFai Lau 	__u32 segs_in;		/* RFC4898 tcpEStatsPerfSegsIn
6154655a51e5SMartin KaFai Lau 				 * total number of segments in.
6155655a51e5SMartin KaFai Lau 				 */
6156655a51e5SMartin KaFai Lau 	__u32 data_segs_in;	/* RFC4898 tcpEStatsPerfDataSegsIn
6157655a51e5SMartin KaFai Lau 				 * total number of data segments in.
6158655a51e5SMartin KaFai Lau 				 */
6159655a51e5SMartin KaFai Lau 	__u32 segs_out;		/* RFC4898 tcpEStatsPerfSegsOut
6160655a51e5SMartin KaFai Lau 				 * The total number of segments sent.
6161655a51e5SMartin KaFai Lau 				 */
6162655a51e5SMartin KaFai Lau 	__u32 data_segs_out;	/* RFC4898 tcpEStatsPerfDataSegsOut
6163655a51e5SMartin KaFai Lau 				 * total number of data segments sent.
6164655a51e5SMartin KaFai Lau 				 */
6165655a51e5SMartin KaFai Lau 	__u32 lost_out;		/* Lost packets			*/
6166655a51e5SMartin KaFai Lau 	__u32 sacked_out;	/* SACK'd packets			*/
6167655a51e5SMartin KaFai Lau 	__u64 bytes_received;	/* RFC4898 tcpEStatsAppHCThruOctetsReceived
6168655a51e5SMartin KaFai Lau 				 * sum(delta(rcv_nxt)), or how many bytes
6169655a51e5SMartin KaFai Lau 				 * were acked.
6170655a51e5SMartin KaFai Lau 				 */
6171655a51e5SMartin KaFai Lau 	__u64 bytes_acked;	/* RFC4898 tcpEStatsAppHCThruOctetsAcked
6172655a51e5SMartin KaFai Lau 				 * sum(delta(snd_una)), or how many bytes
6173655a51e5SMartin KaFai Lau 				 * were acked.
6174655a51e5SMartin KaFai Lau 				 */
61750357746dSStanislav Fomichev 	__u32 dsack_dups;	/* RFC4898 tcpEStatsStackDSACKDups
61760357746dSStanislav Fomichev 				 * total number of DSACK blocks received
61770357746dSStanislav Fomichev 				 */
61780357746dSStanislav Fomichev 	__u32 delivered;	/* Total data packets delivered incl. rexmits */
61790357746dSStanislav Fomichev 	__u32 delivered_ce;	/* Like the above but only ECE marked packets */
6180c2cb5e82SStanislav Fomichev 	__u32 icsk_retransmits;	/* Number of unrecovered [RTO] timeouts */
6181655a51e5SMartin KaFai Lau };
6182655a51e5SMartin KaFai Lau 
61836acc9b43SJoe Stringer struct bpf_sock_tuple {
61846acc9b43SJoe Stringer 	union {
61856acc9b43SJoe Stringer 		struct {
61866acc9b43SJoe Stringer 			__be32 saddr;
61876acc9b43SJoe Stringer 			__be32 daddr;
61886acc9b43SJoe Stringer 			__be16 sport;
61896acc9b43SJoe Stringer 			__be16 dport;
61906acc9b43SJoe Stringer 		} ipv4;
61916acc9b43SJoe Stringer 		struct {
61926acc9b43SJoe Stringer 			__be32 saddr[4];
61936acc9b43SJoe Stringer 			__be32 daddr[4];
61946acc9b43SJoe Stringer 			__be16 sport;
61956acc9b43SJoe Stringer 			__be16 dport;
61966acc9b43SJoe Stringer 		} ipv6;
61976acc9b43SJoe Stringer 	};
61986acc9b43SJoe Stringer };
61996acc9b43SJoe Stringer 
6200fada7fdcSJonathan Lemon struct bpf_xdp_sock {
6201fada7fdcSJonathan Lemon 	__u32 queue_id;
6202fada7fdcSJonathan Lemon };
6203fada7fdcSJonathan Lemon 
620417bedab2SMartin KaFai Lau #define XDP_PACKET_HEADROOM 256
620517bedab2SMartin KaFai Lau 
62066a773a15SBrenden Blanco /* User return codes for XDP prog type.
62076a773a15SBrenden Blanco  * A valid XDP program must return one of these defined values. All other
62089beb8bedSDaniel Borkmann  * return codes are reserved for future use. Unknown return codes will
62099beb8bedSDaniel Borkmann  * result in packet drops and a warning via bpf_warn_invalid_xdp_action().
62106a773a15SBrenden Blanco  */
62116a773a15SBrenden Blanco enum xdp_action {
62126a773a15SBrenden Blanco 	XDP_ABORTED = 0,
62136a773a15SBrenden Blanco 	XDP_DROP,
62146a773a15SBrenden Blanco 	XDP_PASS,
62156ce96ca3SBrenden Blanco 	XDP_TX,
6216814abfabSJohn Fastabend 	XDP_REDIRECT,
62176a773a15SBrenden Blanco };
62186a773a15SBrenden Blanco 
62196a773a15SBrenden Blanco /* user accessible metadata for XDP packet hook
62206a773a15SBrenden Blanco  * new fields must be added to the end of this structure
62216a773a15SBrenden Blanco  */
62226a773a15SBrenden Blanco struct xdp_md {
62236a773a15SBrenden Blanco 	__u32 data;
62246a773a15SBrenden Blanco 	__u32 data_end;
6225de8f3a83SDaniel Borkmann 	__u32 data_meta;
6226daaf24c6SJesper Dangaard Brouer 	/* Below access go through struct xdp_rxq_info */
622702dd3291SJesper Dangaard Brouer 	__u32 ingress_ifindex; /* rxq->dev->ifindex */
622802dd3291SJesper Dangaard Brouer 	__u32 rx_queue_index;  /* rxq->queue_index  */
622964b59025SDavid Ahern 
623064b59025SDavid Ahern 	__u32 egress_ifindex;  /* txq->dev->ifindex */
62316a773a15SBrenden Blanco };
62326a773a15SBrenden Blanco 
6233281920b7SJesper Dangaard Brouer /* DEVMAP map-value layout
6234281920b7SJesper Dangaard Brouer  *
6235281920b7SJesper Dangaard Brouer  * The struct data-layout of map-value is a configuration interface.
6236281920b7SJesper Dangaard Brouer  * New members can only be added to the end of this structure.
6237281920b7SJesper Dangaard Brouer  */
6238281920b7SJesper Dangaard Brouer struct bpf_devmap_val {
6239281920b7SJesper Dangaard Brouer 	__u32 ifindex;   /* device index */
6240281920b7SJesper Dangaard Brouer 	union {
6241281920b7SJesper Dangaard Brouer 		int   fd;  /* prog fd on map write */
6242281920b7SJesper Dangaard Brouer 		__u32 id;  /* prog id on map read */
6243281920b7SJesper Dangaard Brouer 	} bpf_prog;
6244281920b7SJesper Dangaard Brouer };
6245281920b7SJesper Dangaard Brouer 
6246644bfe51SLorenzo Bianconi /* CPUMAP map-value layout
6247644bfe51SLorenzo Bianconi  *
6248644bfe51SLorenzo Bianconi  * The struct data-layout of map-value is a configuration interface.
6249644bfe51SLorenzo Bianconi  * New members can only be added to the end of this structure.
6250644bfe51SLorenzo Bianconi  */
6251644bfe51SLorenzo Bianconi struct bpf_cpumap_val {
6252644bfe51SLorenzo Bianconi 	__u32 qsize;	/* queue size to remote target CPU */
625392164774SLorenzo Bianconi 	union {
625492164774SLorenzo Bianconi 		int   fd;	/* prog fd on map write */
625592164774SLorenzo Bianconi 		__u32 id;	/* prog id on map read */
625692164774SLorenzo Bianconi 	} bpf_prog;
6257644bfe51SLorenzo Bianconi };
6258644bfe51SLorenzo Bianconi 
6259174a79ffSJohn Fastabend enum sk_action {
6260bfa64075SJohn Fastabend 	SK_DROP = 0,
6261bfa64075SJohn Fastabend 	SK_PASS,
6262174a79ffSJohn Fastabend };
6263174a79ffSJohn Fastabend 
62644f738adbSJohn Fastabend /* user accessible metadata for SK_MSG packet hook, new fields must
62654f738adbSJohn Fastabend  * be added to the end of this structure
62664f738adbSJohn Fastabend  */
62674f738adbSJohn Fastabend struct sk_msg_md {
6268b7df9adaSDaniel Borkmann 	__bpf_md_ptr(void *, data);
6269b7df9adaSDaniel Borkmann 	__bpf_md_ptr(void *, data_end);
6270303def35SJohn Fastabend 
6271303def35SJohn Fastabend 	__u32 family;
6272303def35SJohn Fastabend 	__u32 remote_ip4;	/* Stored in network byte order */
6273303def35SJohn Fastabend 	__u32 local_ip4;	/* Stored in network byte order */
6274303def35SJohn Fastabend 	__u32 remote_ip6[4];	/* Stored in network byte order */
6275303def35SJohn Fastabend 	__u32 local_ip6[4];	/* Stored in network byte order */
6276303def35SJohn Fastabend 	__u32 remote_port;	/* Stored in network byte order */
6277303def35SJohn Fastabend 	__u32 local_port;	/* stored in host byte order */
62783bdbd022SJohn Fastabend 	__u32 size;		/* Total size of sk_msg */
627913d70f5aSJohn Fastabend 
628013d70f5aSJohn Fastabend 	__bpf_md_ptr(struct bpf_sock *, sk); /* current socket */
62814f738adbSJohn Fastabend };
62824f738adbSJohn Fastabend 
62832dbb9b9eSMartin KaFai Lau struct sk_reuseport_md {
62842dbb9b9eSMartin KaFai Lau 	/*
62852dbb9b9eSMartin KaFai Lau 	 * Start of directly accessible data. It begins from
62862dbb9b9eSMartin KaFai Lau 	 * the tcp/udp header.
62872dbb9b9eSMartin KaFai Lau 	 */
6288b7df9adaSDaniel Borkmann 	__bpf_md_ptr(void *, data);
6289b7df9adaSDaniel Borkmann 	/* End of directly accessible data */
6290b7df9adaSDaniel Borkmann 	__bpf_md_ptr(void *, data_end);
62912dbb9b9eSMartin KaFai Lau 	/*
62922dbb9b9eSMartin KaFai Lau 	 * Total length of packet (starting from the tcp/udp header).
62932dbb9b9eSMartin KaFai Lau 	 * Note that the directly accessible bytes (data_end - data)
62942dbb9b9eSMartin KaFai Lau 	 * could be less than this "len".  Those bytes could be
62952dbb9b9eSMartin KaFai Lau 	 * indirectly read by a helper "bpf_skb_load_bytes()".
62962dbb9b9eSMartin KaFai Lau 	 */
62972dbb9b9eSMartin KaFai Lau 	__u32 len;
62982dbb9b9eSMartin KaFai Lau 	/*
62992dbb9b9eSMartin KaFai Lau 	 * Eth protocol in the mac header (network byte order). e.g.
63002dbb9b9eSMartin KaFai Lau 	 * ETH_P_IP(0x0800) and ETH_P_IPV6(0x86DD)
63012dbb9b9eSMartin KaFai Lau 	 */
63022dbb9b9eSMartin KaFai Lau 	__u32 eth_protocol;
63032dbb9b9eSMartin KaFai Lau 	__u32 ip_protocol;	/* IP protocol. e.g. IPPROTO_TCP, IPPROTO_UDP */
63042dbb9b9eSMartin KaFai Lau 	__u32 bind_inany;	/* Is sock bound to an INANY address? */
63052dbb9b9eSMartin KaFai Lau 	__u32 hash;		/* A hash of the packet 4 tuples */
6306d5e4ddaeSKuniyuki Iwashima 	/* When reuse->migrating_sk is NULL, it is selecting a sk for the
6307d5e4ddaeSKuniyuki Iwashima 	 * new incoming connection request (e.g. selecting a listen sk for
6308d5e4ddaeSKuniyuki Iwashima 	 * the received SYN in the TCP case).  reuse->sk is one of the sk
6309d5e4ddaeSKuniyuki Iwashima 	 * in the reuseport group. The bpf prog can use reuse->sk to learn
6310d5e4ddaeSKuniyuki Iwashima 	 * the local listening ip/port without looking into the skb.
6311d5e4ddaeSKuniyuki Iwashima 	 *
6312d5e4ddaeSKuniyuki Iwashima 	 * When reuse->migrating_sk is not NULL, reuse->sk is closed and
6313d5e4ddaeSKuniyuki Iwashima 	 * reuse->migrating_sk is the socket that needs to be migrated
6314d5e4ddaeSKuniyuki Iwashima 	 * to another listening socket.  migrating_sk could be a fullsock
6315d5e4ddaeSKuniyuki Iwashima 	 * sk that is fully established or a reqsk that is in-the-middle
6316d5e4ddaeSKuniyuki Iwashima 	 * of 3-way handshake.
6317d5e4ddaeSKuniyuki Iwashima 	 */
6318e0610476SKuniyuki Iwashima 	__bpf_md_ptr(struct bpf_sock *, sk);
6319d5e4ddaeSKuniyuki Iwashima 	__bpf_md_ptr(struct bpf_sock *, migrating_sk);
63202dbb9b9eSMartin KaFai Lau };
63212dbb9b9eSMartin KaFai Lau 
63221e270976SMartin KaFai Lau #define BPF_TAG_SIZE	8
63231e270976SMartin KaFai Lau 
63241e270976SMartin KaFai Lau struct bpf_prog_info {
63251e270976SMartin KaFai Lau 	__u32 type;
63261e270976SMartin KaFai Lau 	__u32 id;
63271e270976SMartin KaFai Lau 	__u8  tag[BPF_TAG_SIZE];
63281e270976SMartin KaFai Lau 	__u32 jited_prog_len;
63291e270976SMartin KaFai Lau 	__u32 xlated_prog_len;
63301e270976SMartin KaFai Lau 	__aligned_u64 jited_prog_insns;
63311e270976SMartin KaFai Lau 	__aligned_u64 xlated_prog_insns;
6332cb4d2b3fSMartin KaFai Lau 	__u64 load_time;	/* ns since boottime */
6333cb4d2b3fSMartin KaFai Lau 	__u32 created_by_uid;
6334cb4d2b3fSMartin KaFai Lau 	__u32 nr_map_ids;
6335cb4d2b3fSMartin KaFai Lau 	__aligned_u64 map_ids;
6336067cae47SMartin KaFai Lau 	char name[BPF_OBJ_NAME_LEN];
6337675fc275SJakub Kicinski 	__u32 ifindex;
6338b85fab0eSJiri Olsa 	__u32 gpl_compatible:1;
63390472301aSBaruch Siach 	__u32 :31; /* alignment pad */
6340675fc275SJakub Kicinski 	__u64 netns_dev;
6341675fc275SJakub Kicinski 	__u64 netns_ino;
6342dbecd738SSandipan Das 	__u32 nr_jited_ksyms;
6343815581c1SSandipan Das 	__u32 nr_jited_func_lens;
6344dbecd738SSandipan Das 	__aligned_u64 jited_ksyms;
6345815581c1SSandipan Das 	__aligned_u64 jited_func_lens;
6346838e9690SYonghong Song 	__u32 btf_id;
6347838e9690SYonghong Song 	__u32 func_info_rec_size;
6348838e9690SYonghong Song 	__aligned_u64 func_info;
634911d8b82dSYonghong Song 	__u32 nr_func_info;
635011d8b82dSYonghong Song 	__u32 nr_line_info;
6351c454a46bSMartin KaFai Lau 	__aligned_u64 line_info;
6352c454a46bSMartin KaFai Lau 	__aligned_u64 jited_line_info;
635311d8b82dSYonghong Song 	__u32 nr_jited_line_info;
6354c454a46bSMartin KaFai Lau 	__u32 line_info_rec_size;
6355c454a46bSMartin KaFai Lau 	__u32 jited_line_info_rec_size;
6356c872bdb3SSong Liu 	__u32 nr_prog_tags;
6357c872bdb3SSong Liu 	__aligned_u64 prog_tags;
63585f8f8b93SAlexei Starovoitov 	__u64 run_time_ns;
63595f8f8b93SAlexei Starovoitov 	__u64 run_cnt;
63609ed9e9baSAlexei Starovoitov 	__u64 recursion_misses;
6361aba64c7dSDave Marchevsky 	__u32 verified_insns;
6362b79c9fc9SStanislav Fomichev 	__u32 attach_btf_obj_id;
6363b79c9fc9SStanislav Fomichev 	__u32 attach_btf_id;
63641e270976SMartin KaFai Lau } __attribute__((aligned(8)));
63651e270976SMartin KaFai Lau 
63661e270976SMartin KaFai Lau struct bpf_map_info {
63671e270976SMartin KaFai Lau 	__u32 type;
63681e270976SMartin KaFai Lau 	__u32 id;
63691e270976SMartin KaFai Lau 	__u32 key_size;
63701e270976SMartin KaFai Lau 	__u32 value_size;
63711e270976SMartin KaFai Lau 	__u32 max_entries;
63721e270976SMartin KaFai Lau 	__u32 map_flags;
6373067cae47SMartin KaFai Lau 	char  name[BPF_OBJ_NAME_LEN];
637452775b33SJakub Kicinski 	__u32 ifindex;
637585d33df3SMartin KaFai Lau 	__u32 btf_vmlinux_value_type_id;
637652775b33SJakub Kicinski 	__u64 netns_dev;
637752775b33SJakub Kicinski 	__u64 netns_ino;
637878958fcaSMartin KaFai Lau 	__u32 btf_id;
63799b2cf328SMartin KaFai Lau 	__u32 btf_key_type_id;
63809b2cf328SMartin KaFai Lau 	__u32 btf_value_type_id;
63818845b468SJoanne Koong 	__u32 :32;	/* alignment pad */
63829330986cSJoanne Koong 	__u64 map_extra;
63831e270976SMartin KaFai Lau } __attribute__((aligned(8)));
63841e270976SMartin KaFai Lau 
638562dab84cSMartin KaFai Lau struct bpf_btf_info {
638662dab84cSMartin KaFai Lau 	__aligned_u64 btf;
638762dab84cSMartin KaFai Lau 	__u32 btf_size;
638862dab84cSMartin KaFai Lau 	__u32 id;
638953297220SAndrii Nakryiko 	__aligned_u64 name;
639053297220SAndrii Nakryiko 	__u32 name_len;
639153297220SAndrii Nakryiko 	__u32 kernel_btf;
639262dab84cSMartin KaFai Lau } __attribute__((aligned(8)));
639362dab84cSMartin KaFai Lau 
6394f2e10bffSAndrii Nakryiko struct bpf_link_info {
6395f2e10bffSAndrii Nakryiko 	__u32 type;
6396f2e10bffSAndrii Nakryiko 	__u32 id;
6397f2e10bffSAndrii Nakryiko 	__u32 prog_id;
6398f2e10bffSAndrii Nakryiko 	union {
6399f2e10bffSAndrii Nakryiko 		struct {
6400f2e10bffSAndrii Nakryiko 			__aligned_u64 tp_name; /* in/out: tp_name buffer ptr */
6401f2e10bffSAndrii Nakryiko 			__u32 tp_name_len;     /* in/out: tp_name buffer len */
6402f2e10bffSAndrii Nakryiko 		} raw_tracepoint;
6403f2e10bffSAndrii Nakryiko 		struct {
6404f2e10bffSAndrii Nakryiko 			__u32 attach_type;
6405441e8c66SToke Høiland-Jørgensen 			__u32 target_obj_id; /* prog_id for PROG_EXT, otherwise btf object id */
6406441e8c66SToke Høiland-Jørgensen 			__u32 target_btf_id; /* BTF type id inside the object */
6407f2e10bffSAndrii Nakryiko 		} tracing;
6408f2e10bffSAndrii Nakryiko 		struct {
6409f2e10bffSAndrii Nakryiko 			__u64 cgroup_id;
6410f2e10bffSAndrii Nakryiko 			__u32 attach_type;
6411f2e10bffSAndrii Nakryiko 		} cgroup;
64127f045a49SJakub Sitnicki 		struct {
64136b0a249aSYonghong Song 			__aligned_u64 target_name; /* in/out: target_name buffer ptr */
64146b0a249aSYonghong Song 			__u32 target_name_len;	   /* in/out: target_name buffer len */
6415d4ccaf58SHao Luo 
6416d4ccaf58SHao Luo 			/* If the iter specific field is 32 bits, it can be put
6417d4ccaf58SHao Luo 			 * in the first or second union. Otherwise it should be
6418d4ccaf58SHao Luo 			 * put in the second union.
6419d4ccaf58SHao Luo 			 */
64206b0a249aSYonghong Song 			union {
6421b0c9eb37SYonghong Song 				struct {
64226b0a249aSYonghong Song 					__u32 map_id;
64236b0a249aSYonghong Song 				} map;
6424b0c9eb37SYonghong Song 			};
6425d4ccaf58SHao Luo 			union {
6426d4ccaf58SHao Luo 				struct {
6427d4ccaf58SHao Luo 					__u64 cgroup_id;
6428d4ccaf58SHao Luo 					__u32 order;
6429d4ccaf58SHao Luo 				} cgroup;
643021fb6f2aSKui-Feng Lee 				struct {
643121fb6f2aSKui-Feng Lee 					__u32 tid;
643221fb6f2aSKui-Feng Lee 					__u32 pid;
643321fb6f2aSKui-Feng Lee 				} task;
6434d4ccaf58SHao Luo 			};
64356b0a249aSYonghong Song 		} iter;
64366b0a249aSYonghong Song 		struct  {
64377f045a49SJakub Sitnicki 			__u32 netns_ino;
64387f045a49SJakub Sitnicki 			__u32 attach_type;
64397f045a49SJakub Sitnicki 		} netns;
6440c1931c97SAndrii Nakryiko 		struct {
6441c1931c97SAndrii Nakryiko 			__u32 ifindex;
6442c1931c97SAndrii Nakryiko 		} xdp;
644368b04864SKui-Feng Lee 		struct {
644468b04864SKui-Feng Lee 			__u32 map_id;
644568b04864SKui-Feng Lee 		} struct_ops;
644684601d6eSFlorian Westphal 		struct {
644784601d6eSFlorian Westphal 			__u32 pf;
644884601d6eSFlorian Westphal 			__u32 hooknum;
644984601d6eSFlorian Westphal 			__s32 priority;
645084601d6eSFlorian Westphal 			__u32 flags;
645184601d6eSFlorian Westphal 		} netfilter;
64527ac8d0d2SYafang Shao 		struct {
64537ac8d0d2SYafang Shao 			__aligned_u64 addrs;
64547ac8d0d2SYafang Shao 			__u32 count; /* in/out: kprobe_multi function count */
64557ac8d0d2SYafang Shao 			__u32 flags;
64567ac8d0d2SYafang Shao 		} kprobe_multi;
6457*1b715e1bSYafang Shao 		struct {
6458*1b715e1bSYafang Shao 			__u32 type; /* enum bpf_perf_event_type */
6459*1b715e1bSYafang Shao 			__u32 :32;
6460*1b715e1bSYafang Shao 			union {
6461*1b715e1bSYafang Shao 				struct {
6462*1b715e1bSYafang Shao 					__aligned_u64 file_name; /* in/out */
6463*1b715e1bSYafang Shao 					__u32 name_len;
6464*1b715e1bSYafang Shao 					__u32 offset; /* offset from file_name */
6465*1b715e1bSYafang Shao 				} uprobe; /* BPF_PERF_EVENT_UPROBE, BPF_PERF_EVENT_URETPROBE */
6466*1b715e1bSYafang Shao 				struct {
6467*1b715e1bSYafang Shao 					__aligned_u64 func_name; /* in/out */
6468*1b715e1bSYafang Shao 					__u32 name_len;
6469*1b715e1bSYafang Shao 					__u32 offset; /* offset from func_name */
6470*1b715e1bSYafang Shao 					__u64 addr;
6471*1b715e1bSYafang Shao 				} kprobe; /* BPF_PERF_EVENT_KPROBE, BPF_PERF_EVENT_KRETPROBE */
6472*1b715e1bSYafang Shao 				struct {
6473*1b715e1bSYafang Shao 					__aligned_u64 tp_name;   /* in/out */
6474*1b715e1bSYafang Shao 					__u32 name_len;
6475*1b715e1bSYafang Shao 				} tracepoint; /* BPF_PERF_EVENT_TRACEPOINT */
6476*1b715e1bSYafang Shao 				struct {
6477*1b715e1bSYafang Shao 					__u64 config;
6478*1b715e1bSYafang Shao 					__u32 type;
6479*1b715e1bSYafang Shao 				} event; /* BPF_PERF_EVENT_EVENT */
6480*1b715e1bSYafang Shao 			};
6481*1b715e1bSYafang Shao 		} perf_event;
6482f2e10bffSAndrii Nakryiko 	};
6483f2e10bffSAndrii Nakryiko } __attribute__((aligned(8)));
6484f2e10bffSAndrii Nakryiko 
64854fbac77dSAndrey Ignatov /* User bpf_sock_addr struct to access socket fields and sockaddr struct passed
64864fbac77dSAndrey Ignatov  * by user and intended to be used by socket (e.g. to bind to, depends on
6487bfdfa517SRandy Dunlap  * attach type).
64884fbac77dSAndrey Ignatov  */
64894fbac77dSAndrey Ignatov struct bpf_sock_addr {
64904fbac77dSAndrey Ignatov 	__u32 user_family;	/* Allows 4-byte read, but no write. */
64914fbac77dSAndrey Ignatov 	__u32 user_ip4;		/* Allows 1,2,4-byte read and 4-byte write.
64924fbac77dSAndrey Ignatov 				 * Stored in network byte order.
64934fbac77dSAndrey Ignatov 				 */
6494d4ecfeb1SStanislav Fomichev 	__u32 user_ip6[4];	/* Allows 1,2,4,8-byte read and 4,8-byte write.
64954fbac77dSAndrey Ignatov 				 * Stored in network byte order.
64964fbac77dSAndrey Ignatov 				 */
64977aebfa1bSAndrey Ignatov 	__u32 user_port;	/* Allows 1,2,4-byte read and 4-byte write.
64984fbac77dSAndrey Ignatov 				 * Stored in network byte order
64994fbac77dSAndrey Ignatov 				 */
65004fbac77dSAndrey Ignatov 	__u32 family;		/* Allows 4-byte read, but no write */
65014fbac77dSAndrey Ignatov 	__u32 type;		/* Allows 4-byte read, but no write */
65024fbac77dSAndrey Ignatov 	__u32 protocol;		/* Allows 4-byte read, but no write */
6503600c70baSStanislav Fomichev 	__u32 msg_src_ip4;	/* Allows 1,2,4-byte read and 4-byte write.
65041cedee13SAndrey Ignatov 				 * Stored in network byte order.
65051cedee13SAndrey Ignatov 				 */
6506d4ecfeb1SStanislav Fomichev 	__u32 msg_src_ip6[4];	/* Allows 1,2,4,8-byte read and 4,8-byte write.
65071cedee13SAndrey Ignatov 				 * Stored in network byte order.
65081cedee13SAndrey Ignatov 				 */
6509fb85c4a7SStanislav Fomichev 	__bpf_md_ptr(struct bpf_sock *, sk);
65104fbac77dSAndrey Ignatov };
65114fbac77dSAndrey Ignatov 
651240304b2aSLawrence Brakmo /* User bpf_sock_ops struct to access socket values and specify request ops
651340304b2aSLawrence Brakmo  * and their replies.
651440304b2aSLawrence Brakmo  * Some of this fields are in network (bigendian) byte order and may need
651540304b2aSLawrence Brakmo  * to be converted before use (bpf_ntohl() defined in samples/bpf/bpf_endian.h).
651640304b2aSLawrence Brakmo  * New fields can only be added at the end of this structure
651740304b2aSLawrence Brakmo  */
651840304b2aSLawrence Brakmo struct bpf_sock_ops {
651940304b2aSLawrence Brakmo 	__u32 op;
652040304b2aSLawrence Brakmo 	union {
6521de525be2SLawrence Brakmo 		__u32 args[4];		/* Optionally passed to bpf program */
6522de525be2SLawrence Brakmo 		__u32 reply;		/* Returned by bpf program	    */
6523de525be2SLawrence Brakmo 		__u32 replylong[4];	/* Optionally returned by bpf prog  */
652440304b2aSLawrence Brakmo 	};
652540304b2aSLawrence Brakmo 	__u32 family;
652640304b2aSLawrence Brakmo 	__u32 remote_ip4;	/* Stored in network byte order */
652740304b2aSLawrence Brakmo 	__u32 local_ip4;	/* Stored in network byte order */
652840304b2aSLawrence Brakmo 	__u32 remote_ip6[4];	/* Stored in network byte order */
652940304b2aSLawrence Brakmo 	__u32 local_ip6[4];	/* Stored in network byte order */
653040304b2aSLawrence Brakmo 	__u32 remote_port;	/* Stored in network byte order */
653140304b2aSLawrence Brakmo 	__u32 local_port;	/* stored in host byte order */
6532f19397a5SLawrence Brakmo 	__u32 is_fullsock;	/* Some TCP fields are only valid if
6533f19397a5SLawrence Brakmo 				 * there is a full socket. If not, the
6534f19397a5SLawrence Brakmo 				 * fields read as zero.
6535f19397a5SLawrence Brakmo 				 */
6536f19397a5SLawrence Brakmo 	__u32 snd_cwnd;
6537f19397a5SLawrence Brakmo 	__u32 srtt_us;		/* Averaged RTT << 3 in usecs */
6538b13d8807SLawrence Brakmo 	__u32 bpf_sock_ops_cb_flags; /* flags defined in uapi/linux/tcp.h */
653944f0e430SLawrence Brakmo 	__u32 state;
654044f0e430SLawrence Brakmo 	__u32 rtt_min;
654144f0e430SLawrence Brakmo 	__u32 snd_ssthresh;
654244f0e430SLawrence Brakmo 	__u32 rcv_nxt;
654344f0e430SLawrence Brakmo 	__u32 snd_nxt;
654444f0e430SLawrence Brakmo 	__u32 snd_una;
654544f0e430SLawrence Brakmo 	__u32 mss_cache;
654644f0e430SLawrence Brakmo 	__u32 ecn_flags;
654744f0e430SLawrence Brakmo 	__u32 rate_delivered;
654844f0e430SLawrence Brakmo 	__u32 rate_interval_us;
654944f0e430SLawrence Brakmo 	__u32 packets_out;
655044f0e430SLawrence Brakmo 	__u32 retrans_out;
655144f0e430SLawrence Brakmo 	__u32 total_retrans;
655244f0e430SLawrence Brakmo 	__u32 segs_in;
655344f0e430SLawrence Brakmo 	__u32 data_segs_in;
655444f0e430SLawrence Brakmo 	__u32 segs_out;
655544f0e430SLawrence Brakmo 	__u32 data_segs_out;
655644f0e430SLawrence Brakmo 	__u32 lost_out;
655744f0e430SLawrence Brakmo 	__u32 sacked_out;
655844f0e430SLawrence Brakmo 	__u32 sk_txhash;
655944f0e430SLawrence Brakmo 	__u64 bytes_received;
656044f0e430SLawrence Brakmo 	__u64 bytes_acked;
65611314ef56SStanislav Fomichev 	__bpf_md_ptr(struct bpf_sock *, sk);
65620813a841SMartin KaFai Lau 	/* [skb_data, skb_data_end) covers the whole TCP header.
65630813a841SMartin KaFai Lau 	 *
65640813a841SMartin KaFai Lau 	 * BPF_SOCK_OPS_PARSE_HDR_OPT_CB: The packet received
65650813a841SMartin KaFai Lau 	 * BPF_SOCK_OPS_HDR_OPT_LEN_CB:   Not useful because the
65660813a841SMartin KaFai Lau 	 *                                header has not been written.
65670813a841SMartin KaFai Lau 	 * BPF_SOCK_OPS_WRITE_HDR_OPT_CB: The header and options have
65680813a841SMartin KaFai Lau 	 *				  been written so far.
65690813a841SMartin KaFai Lau 	 * BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:  The SYNACK that concludes
65700813a841SMartin KaFai Lau 	 *					the 3WHS.
65710813a841SMartin KaFai Lau 	 * BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB: The ACK that concludes
65720813a841SMartin KaFai Lau 	 *					the 3WHS.
65730813a841SMartin KaFai Lau 	 *
65740813a841SMartin KaFai Lau 	 * bpf_load_hdr_opt() can also be used to read a particular option.
65750813a841SMartin KaFai Lau 	 */
65760813a841SMartin KaFai Lau 	__bpf_md_ptr(void *, skb_data);
65770813a841SMartin KaFai Lau 	__bpf_md_ptr(void *, skb_data_end);
65780813a841SMartin KaFai Lau 	__u32 skb_len;		/* The total length of a packet.
65790813a841SMartin KaFai Lau 				 * It includes the header, options,
65800813a841SMartin KaFai Lau 				 * and payload.
65810813a841SMartin KaFai Lau 				 */
65820813a841SMartin KaFai Lau 	__u32 skb_tcp_flags;	/* tcp_flags of the header.  It provides
65830813a841SMartin KaFai Lau 				 * an easy way to check for tcp_flags
65840813a841SMartin KaFai Lau 				 * without parsing skb_data.
65850813a841SMartin KaFai Lau 				 *
65860813a841SMartin KaFai Lau 				 * In particular, the skb_tcp_flags
65870813a841SMartin KaFai Lau 				 * will still be available in
65880813a841SMartin KaFai Lau 				 * BPF_SOCK_OPS_HDR_OPT_LEN even though
65890813a841SMartin KaFai Lau 				 * the outgoing header has not
65900813a841SMartin KaFai Lau 				 * been written yet.
65910813a841SMartin KaFai Lau 				 */
65929bb05349SMartin KaFai Lau 	__u64 skb_hwtstamp;
659340304b2aSLawrence Brakmo };
659440304b2aSLawrence Brakmo 
6595b13d8807SLawrence Brakmo /* Definitions for bpf_sock_ops_cb_flags */
65961aae4bddSAndrii Nakryiko enum {
65971aae4bddSAndrii Nakryiko 	BPF_SOCK_OPS_RTO_CB_FLAG	= (1<<0),
65981aae4bddSAndrii Nakryiko 	BPF_SOCK_OPS_RETRANS_CB_FLAG	= (1<<1),
65991aae4bddSAndrii Nakryiko 	BPF_SOCK_OPS_STATE_CB_FLAG	= (1<<2),
66001aae4bddSAndrii Nakryiko 	BPF_SOCK_OPS_RTT_CB_FLAG	= (1<<3),
66010813a841SMartin KaFai Lau 	/* Call bpf for all received TCP headers.  The bpf prog will be
66020813a841SMartin KaFai Lau 	 * called under sock_ops->op == BPF_SOCK_OPS_PARSE_HDR_OPT_CB
66030813a841SMartin KaFai Lau 	 *
66040813a841SMartin KaFai Lau 	 * Please refer to the comment in BPF_SOCK_OPS_PARSE_HDR_OPT_CB
66050813a841SMartin KaFai Lau 	 * for the header option related helpers that will be useful
66060813a841SMartin KaFai Lau 	 * to the bpf programs.
66070813a841SMartin KaFai Lau 	 *
66080813a841SMartin KaFai Lau 	 * It could be used at the client/active side (i.e. connect() side)
66090813a841SMartin KaFai Lau 	 * when the server told it that the server was in syncookie
66100813a841SMartin KaFai Lau 	 * mode and required the active side to resend the bpf-written
66110813a841SMartin KaFai Lau 	 * options.  The active side can keep writing the bpf-options until
66120813a841SMartin KaFai Lau 	 * it received a valid packet from the server side to confirm
66130813a841SMartin KaFai Lau 	 * the earlier packet (and options) has been received.  The later
66140813a841SMartin KaFai Lau 	 * example patch is using it like this at the active side when the
66150813a841SMartin KaFai Lau 	 * server is in syncookie mode.
66160813a841SMartin KaFai Lau 	 *
66170813a841SMartin KaFai Lau 	 * The bpf prog will usually turn this off in the common cases.
66180813a841SMartin KaFai Lau 	 */
661900d211a4SMartin KaFai Lau 	BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG	= (1<<4),
66200813a841SMartin KaFai Lau 	/* Call bpf when kernel has received a header option that
66210813a841SMartin KaFai Lau 	 * the kernel cannot handle.  The bpf prog will be called under
66220813a841SMartin KaFai Lau 	 * sock_ops->op == BPF_SOCK_OPS_PARSE_HDR_OPT_CB.
66230813a841SMartin KaFai Lau 	 *
66240813a841SMartin KaFai Lau 	 * Please refer to the comment in BPF_SOCK_OPS_PARSE_HDR_OPT_CB
66250813a841SMartin KaFai Lau 	 * for the header option related helpers that will be useful
66260813a841SMartin KaFai Lau 	 * to the bpf programs.
66270813a841SMartin KaFai Lau 	 */
662800d211a4SMartin KaFai Lau 	BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG = (1<<5),
66290813a841SMartin KaFai Lau 	/* Call bpf when the kernel is writing header options for the
66300813a841SMartin KaFai Lau 	 * outgoing packet.  The bpf prog will first be called
66310813a841SMartin KaFai Lau 	 * to reserve space in a skb under
66320813a841SMartin KaFai Lau 	 * sock_ops->op == BPF_SOCK_OPS_HDR_OPT_LEN_CB.  Then
66330813a841SMartin KaFai Lau 	 * the bpf prog will be called to write the header option(s)
66340813a841SMartin KaFai Lau 	 * under sock_ops->op == BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
66350813a841SMartin KaFai Lau 	 *
66360813a841SMartin KaFai Lau 	 * Please refer to the comment in BPF_SOCK_OPS_HDR_OPT_LEN_CB
66370813a841SMartin KaFai Lau 	 * and BPF_SOCK_OPS_WRITE_HDR_OPT_CB for the header option
66380813a841SMartin KaFai Lau 	 * related helpers that will be useful to the bpf programs.
66390813a841SMartin KaFai Lau 	 *
66400813a841SMartin KaFai Lau 	 * The kernel gets its chance to reserve space and write
66410813a841SMartin KaFai Lau 	 * options first before the BPF program does.
66420813a841SMartin KaFai Lau 	 */
6643331fca43SMartin KaFai Lau 	BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG = (1<<6),
66441aae4bddSAndrii Nakryiko /* Mask of all currently supported cb flags */
6645331fca43SMartin KaFai Lau 	BPF_SOCK_OPS_ALL_CB_FLAGS       = 0x7F,
66461aae4bddSAndrii Nakryiko };
6647b13d8807SLawrence Brakmo 
664840304b2aSLawrence Brakmo /* List of known BPF sock_ops operators.
664940304b2aSLawrence Brakmo  * New entries can only be added at the end
665040304b2aSLawrence Brakmo  */
665140304b2aSLawrence Brakmo enum {
665240304b2aSLawrence Brakmo 	BPF_SOCK_OPS_VOID,
66538550f328SLawrence Brakmo 	BPF_SOCK_OPS_TIMEOUT_INIT,	/* Should return SYN-RTO value to use or
66548550f328SLawrence Brakmo 					 * -1 if default value should be used
66558550f328SLawrence Brakmo 					 */
665613d3b1ebSLawrence Brakmo 	BPF_SOCK_OPS_RWND_INIT,		/* Should return initial advertized
665713d3b1ebSLawrence Brakmo 					 * window (in packets) or -1 if default
665813d3b1ebSLawrence Brakmo 					 * value should be used
665913d3b1ebSLawrence Brakmo 					 */
66609872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_TCP_CONNECT_CB,	/* Calls BPF program right before an
66619872a4bdSLawrence Brakmo 					 * active connection is initialized
66629872a4bdSLawrence Brakmo 					 */
66639872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB,	/* Calls BPF program when an
66649872a4bdSLawrence Brakmo 						 * active connection is
66659872a4bdSLawrence Brakmo 						 * established
66669872a4bdSLawrence Brakmo 						 */
66679872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB,	/* Calls BPF program when a
66689872a4bdSLawrence Brakmo 						 * passive connection is
66699872a4bdSLawrence Brakmo 						 * established
66709872a4bdSLawrence Brakmo 						 */
667191b5b21cSLawrence Brakmo 	BPF_SOCK_OPS_NEEDS_ECN,		/* If connection's congestion control
667291b5b21cSLawrence Brakmo 					 * needs ECN
667391b5b21cSLawrence Brakmo 					 */
6674e6546ef6SLawrence Brakmo 	BPF_SOCK_OPS_BASE_RTT,		/* Get base RTT. The correct value is
6675e6546ef6SLawrence Brakmo 					 * based on the path and may be
6676e6546ef6SLawrence Brakmo 					 * dependent on the congestion control
6677e6546ef6SLawrence Brakmo 					 * algorithm. In general it indicates
6678e6546ef6SLawrence Brakmo 					 * a congestion threshold. RTTs above
6679e6546ef6SLawrence Brakmo 					 * this indicate congestion
6680e6546ef6SLawrence Brakmo 					 */
6681f89013f6SLawrence Brakmo 	BPF_SOCK_OPS_RTO_CB,		/* Called when an RTO has triggered.
6682f89013f6SLawrence Brakmo 					 * Arg1: value of icsk_retransmits
6683f89013f6SLawrence Brakmo 					 * Arg2: value of icsk_rto
6684f89013f6SLawrence Brakmo 					 * Arg3: whether RTO has expired
6685f89013f6SLawrence Brakmo 					 */
6686a31ad29eSLawrence Brakmo 	BPF_SOCK_OPS_RETRANS_CB,	/* Called when skb is retransmitted.
6687a31ad29eSLawrence Brakmo 					 * Arg1: sequence number of 1st byte
6688a31ad29eSLawrence Brakmo 					 * Arg2: # segments
6689a31ad29eSLawrence Brakmo 					 * Arg3: return value of
6690a31ad29eSLawrence Brakmo 					 *       tcp_transmit_skb (0 => success)
6691a31ad29eSLawrence Brakmo 					 */
6692d4487491SLawrence Brakmo 	BPF_SOCK_OPS_STATE_CB,		/* Called when TCP changes state.
6693d4487491SLawrence Brakmo 					 * Arg1: old_state
6694d4487491SLawrence Brakmo 					 * Arg2: new_state
6695d4487491SLawrence Brakmo 					 */
6696f333ee0cSAndrey Ignatov 	BPF_SOCK_OPS_TCP_LISTEN_CB,	/* Called on listen(2), right after
6697f333ee0cSAndrey Ignatov 					 * socket transition to LISTEN state.
6698f333ee0cSAndrey Ignatov 					 */
669923729ff2SStanislav Fomichev 	BPF_SOCK_OPS_RTT_CB,		/* Called on every RTT.
670023729ff2SStanislav Fomichev 					 */
67010813a841SMartin KaFai Lau 	BPF_SOCK_OPS_PARSE_HDR_OPT_CB,	/* Parse the header option.
67020813a841SMartin KaFai Lau 					 * It will be called to handle
67030813a841SMartin KaFai Lau 					 * the packets received at
67040813a841SMartin KaFai Lau 					 * an already established
67050813a841SMartin KaFai Lau 					 * connection.
67060813a841SMartin KaFai Lau 					 *
67070813a841SMartin KaFai Lau 					 * sock_ops->skb_data:
67080813a841SMartin KaFai Lau 					 * Referring to the received skb.
67090813a841SMartin KaFai Lau 					 * It covers the TCP header only.
67100813a841SMartin KaFai Lau 					 *
67110813a841SMartin KaFai Lau 					 * bpf_load_hdr_opt() can also
67120813a841SMartin KaFai Lau 					 * be used to search for a
67130813a841SMartin KaFai Lau 					 * particular option.
67140813a841SMartin KaFai Lau 					 */
67150813a841SMartin KaFai Lau 	BPF_SOCK_OPS_HDR_OPT_LEN_CB,	/* Reserve space for writing the
67160813a841SMartin KaFai Lau 					 * header option later in
67170813a841SMartin KaFai Lau 					 * BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
67180813a841SMartin KaFai Lau 					 * Arg1: bool want_cookie. (in
67190813a841SMartin KaFai Lau 					 *       writing SYNACK only)
67200813a841SMartin KaFai Lau 					 *
67210813a841SMartin KaFai Lau 					 * sock_ops->skb_data:
67220813a841SMartin KaFai Lau 					 * Not available because no header has
67230813a841SMartin KaFai Lau 					 * been	written yet.
67240813a841SMartin KaFai Lau 					 *
67250813a841SMartin KaFai Lau 					 * sock_ops->skb_tcp_flags:
67260813a841SMartin KaFai Lau 					 * The tcp_flags of the
67270813a841SMartin KaFai Lau 					 * outgoing skb. (e.g. SYN, ACK, FIN).
67280813a841SMartin KaFai Lau 					 *
67290813a841SMartin KaFai Lau 					 * bpf_reserve_hdr_opt() should
67300813a841SMartin KaFai Lau 					 * be used to reserve space.
67310813a841SMartin KaFai Lau 					 */
67320813a841SMartin KaFai Lau 	BPF_SOCK_OPS_WRITE_HDR_OPT_CB,	/* Write the header options
67330813a841SMartin KaFai Lau 					 * Arg1: bool want_cookie. (in
67340813a841SMartin KaFai Lau 					 *       writing SYNACK only)
67350813a841SMartin KaFai Lau 					 *
67360813a841SMartin KaFai Lau 					 * sock_ops->skb_data:
67370813a841SMartin KaFai Lau 					 * Referring to the outgoing skb.
67380813a841SMartin KaFai Lau 					 * It covers the TCP header
67390813a841SMartin KaFai Lau 					 * that has already been written
67400813a841SMartin KaFai Lau 					 * by the kernel and the
67410813a841SMartin KaFai Lau 					 * earlier bpf-progs.
67420813a841SMartin KaFai Lau 					 *
67430813a841SMartin KaFai Lau 					 * sock_ops->skb_tcp_flags:
67440813a841SMartin KaFai Lau 					 * The tcp_flags of the outgoing
67450813a841SMartin KaFai Lau 					 * skb. (e.g. SYN, ACK, FIN).
67460813a841SMartin KaFai Lau 					 *
67470813a841SMartin KaFai Lau 					 * bpf_store_hdr_opt() should
67480813a841SMartin KaFai Lau 					 * be used to write the
67490813a841SMartin KaFai Lau 					 * option.
67500813a841SMartin KaFai Lau 					 *
67510813a841SMartin KaFai Lau 					 * bpf_load_hdr_opt() can also
67520813a841SMartin KaFai Lau 					 * be used to search for a
67530813a841SMartin KaFai Lau 					 * particular option that
67540813a841SMartin KaFai Lau 					 * has already been written
67550813a841SMartin KaFai Lau 					 * by the kernel or the
67560813a841SMartin KaFai Lau 					 * earlier bpf-progs.
67570813a841SMartin KaFai Lau 					 */
6758d4487491SLawrence Brakmo };
6759d4487491SLawrence Brakmo 
6760d4487491SLawrence Brakmo /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
6761d4487491SLawrence Brakmo  * changes between the TCP and BPF versions. Ideally this should never happen.
6762d4487491SLawrence Brakmo  * If it does, we need to add code to convert them before calling
6763d4487491SLawrence Brakmo  * the BPF sock_ops function.
6764d4487491SLawrence Brakmo  */
6765d4487491SLawrence Brakmo enum {
6766d4487491SLawrence Brakmo 	BPF_TCP_ESTABLISHED = 1,
6767d4487491SLawrence Brakmo 	BPF_TCP_SYN_SENT,
6768d4487491SLawrence Brakmo 	BPF_TCP_SYN_RECV,
6769d4487491SLawrence Brakmo 	BPF_TCP_FIN_WAIT1,
6770d4487491SLawrence Brakmo 	BPF_TCP_FIN_WAIT2,
6771d4487491SLawrence Brakmo 	BPF_TCP_TIME_WAIT,
6772d4487491SLawrence Brakmo 	BPF_TCP_CLOSE,
6773d4487491SLawrence Brakmo 	BPF_TCP_CLOSE_WAIT,
6774d4487491SLawrence Brakmo 	BPF_TCP_LAST_ACK,
6775d4487491SLawrence Brakmo 	BPF_TCP_LISTEN,
6776d4487491SLawrence Brakmo 	BPF_TCP_CLOSING,	/* Now a valid state */
6777d4487491SLawrence Brakmo 	BPF_TCP_NEW_SYN_RECV,
6778d4487491SLawrence Brakmo 
6779d4487491SLawrence Brakmo 	BPF_TCP_MAX_STATES	/* Leave at the end! */
678040304b2aSLawrence Brakmo };
678140304b2aSLawrence Brakmo 
67821aae4bddSAndrii Nakryiko enum {
67831aae4bddSAndrii Nakryiko 	TCP_BPF_IW		= 1001,	/* Set TCP initial congestion window */
67841aae4bddSAndrii Nakryiko 	TCP_BPF_SNDCWND_CLAMP	= 1002,	/* Set sndcwnd_clamp */
67852b8ee4f0SMartin KaFai Lau 	TCP_BPF_DELACK_MAX	= 1003, /* Max delay ack in usecs */
6786ca584ba0SMartin KaFai Lau 	TCP_BPF_RTO_MIN		= 1004, /* Min delay ack in usecs */
67870813a841SMartin KaFai Lau 	/* Copy the SYN pkt to optval
67880813a841SMartin KaFai Lau 	 *
67890813a841SMartin KaFai Lau 	 * BPF_PROG_TYPE_SOCK_OPS only.  It is similar to the
67900813a841SMartin KaFai Lau 	 * bpf_getsockopt(TCP_SAVED_SYN) but it does not limit
67910813a841SMartin KaFai Lau 	 * to only getting from the saved_syn.  It can either get the
67920813a841SMartin KaFai Lau 	 * syn packet from:
67930813a841SMartin KaFai Lau 	 *
67940813a841SMartin KaFai Lau 	 * 1. the just-received SYN packet (only available when writing the
67950813a841SMartin KaFai Lau 	 *    SYNACK).  It will be useful when it is not necessary to
67960813a841SMartin KaFai Lau 	 *    save the SYN packet for latter use.  It is also the only way
67970813a841SMartin KaFai Lau 	 *    to get the SYN during syncookie mode because the syn
67980813a841SMartin KaFai Lau 	 *    packet cannot be saved during syncookie.
67990813a841SMartin KaFai Lau 	 *
68000813a841SMartin KaFai Lau 	 * OR
68010813a841SMartin KaFai Lau 	 *
68020813a841SMartin KaFai Lau 	 * 2. the earlier saved syn which was done by
68030813a841SMartin KaFai Lau 	 *    bpf_setsockopt(TCP_SAVE_SYN).
68040813a841SMartin KaFai Lau 	 *
68050813a841SMartin KaFai Lau 	 * The bpf_getsockopt(TCP_BPF_SYN*) option will hide where the
68060813a841SMartin KaFai Lau 	 * SYN packet is obtained.
68070813a841SMartin KaFai Lau 	 *
68080813a841SMartin KaFai Lau 	 * If the bpf-prog does not need the IP[46] header,  the
68090813a841SMartin KaFai Lau 	 * bpf-prog can avoid parsing the IP header by using
68100813a841SMartin KaFai Lau 	 * TCP_BPF_SYN.  Otherwise, the bpf-prog can get both
68110813a841SMartin KaFai Lau 	 * IP[46] and TCP header by using TCP_BPF_SYN_IP.
68120813a841SMartin KaFai Lau 	 *
68130813a841SMartin KaFai Lau 	 *      >0: Total number of bytes copied
68140813a841SMartin KaFai Lau 	 * -ENOSPC: Not enough space in optval. Only optlen number of
68150813a841SMartin KaFai Lau 	 *          bytes is copied.
68160813a841SMartin KaFai Lau 	 * -ENOENT: The SYN skb is not available now and the earlier SYN pkt
68170813a841SMartin KaFai Lau 	 *	    is not saved by setsockopt(TCP_SAVE_SYN).
68180813a841SMartin KaFai Lau 	 */
68190813a841SMartin KaFai Lau 	TCP_BPF_SYN		= 1005, /* Copy the TCP header */
68200813a841SMartin KaFai Lau 	TCP_BPF_SYN_IP		= 1006, /* Copy the IP[46] and TCP header */
6821267cf9faSMartin KaFai Lau 	TCP_BPF_SYN_MAC         = 1007, /* Copy the MAC, IP[46], and TCP header */
68220813a841SMartin KaFai Lau };
68230813a841SMartin KaFai Lau 
68240813a841SMartin KaFai Lau enum {
68250813a841SMartin KaFai Lau 	BPF_LOAD_HDR_OPT_TCP_SYN = (1ULL << 0),
68260813a841SMartin KaFai Lau };
68270813a841SMartin KaFai Lau 
68280813a841SMartin KaFai Lau /* args[0] value during BPF_SOCK_OPS_HDR_OPT_LEN_CB and
68290813a841SMartin KaFai Lau  * BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
68300813a841SMartin KaFai Lau  */
68310813a841SMartin KaFai Lau enum {
68320813a841SMartin KaFai Lau 	BPF_WRITE_HDR_TCP_CURRENT_MSS = 1,	/* Kernel is finding the
68330813a841SMartin KaFai Lau 						 * total option spaces
68340813a841SMartin KaFai Lau 						 * required for an established
68350813a841SMartin KaFai Lau 						 * sk in order to calculate the
68360813a841SMartin KaFai Lau 						 * MSS.  No skb is actually
68370813a841SMartin KaFai Lau 						 * sent.
68380813a841SMartin KaFai Lau 						 */
68390813a841SMartin KaFai Lau 	BPF_WRITE_HDR_TCP_SYNACK_COOKIE = 2,	/* Kernel is in syncookie mode
68400813a841SMartin KaFai Lau 						 * when sending a SYN.
68410813a841SMartin KaFai Lau 						 */
68421aae4bddSAndrii Nakryiko };
6843fc747810SLawrence Brakmo 
6844908432caSYonghong Song struct bpf_perf_event_value {
6845908432caSYonghong Song 	__u64 counter;
6846908432caSYonghong Song 	__u64 enabled;
6847908432caSYonghong Song 	__u64 running;
6848908432caSYonghong Song };
6849908432caSYonghong Song 
68501aae4bddSAndrii Nakryiko enum {
68511aae4bddSAndrii Nakryiko 	BPF_DEVCG_ACC_MKNOD	= (1ULL << 0),
68521aae4bddSAndrii Nakryiko 	BPF_DEVCG_ACC_READ	= (1ULL << 1),
68531aae4bddSAndrii Nakryiko 	BPF_DEVCG_ACC_WRITE	= (1ULL << 2),
68541aae4bddSAndrii Nakryiko };
6855ebc614f6SRoman Gushchin 
68561aae4bddSAndrii Nakryiko enum {
68571aae4bddSAndrii Nakryiko 	BPF_DEVCG_DEV_BLOCK	= (1ULL << 0),
68581aae4bddSAndrii Nakryiko 	BPF_DEVCG_DEV_CHAR	= (1ULL << 1),
68591aae4bddSAndrii Nakryiko };
6860ebc614f6SRoman Gushchin 
6861ebc614f6SRoman Gushchin struct bpf_cgroup_dev_ctx {
686206ef0ccbSYonghong Song 	/* access_type encoded as (BPF_DEVCG_ACC_* << 16) | BPF_DEVCG_DEV_* */
686306ef0ccbSYonghong Song 	__u32 access_type;
6864ebc614f6SRoman Gushchin 	__u32 major;
6865ebc614f6SRoman Gushchin 	__u32 minor;
6866ebc614f6SRoman Gushchin };
6867ebc614f6SRoman Gushchin 
6868c4f6699dSAlexei Starovoitov struct bpf_raw_tracepoint_args {
6869c4f6699dSAlexei Starovoitov 	__u64 args[0];
6870c4f6699dSAlexei Starovoitov };
6871c4f6699dSAlexei Starovoitov 
687287f5fc7eSDavid Ahern /* DIRECT:  Skip the FIB rules and go to FIB table associated with device
687387f5fc7eSDavid Ahern  * OUTPUT:  Do lookup from egress perspective; default is ingress
687487f5fc7eSDavid Ahern  */
68751aae4bddSAndrii Nakryiko enum {
68761aae4bddSAndrii Nakryiko 	BPF_FIB_LOOKUP_DIRECT  = (1U << 0),
68771aae4bddSAndrii Nakryiko 	BPF_FIB_LOOKUP_OUTPUT  = (1U << 1),
687831de4105SMartin KaFai Lau 	BPF_FIB_LOOKUP_SKIP_NEIGH = (1U << 2),
68798ad77e72SLouis DeLosSantos 	BPF_FIB_LOOKUP_TBID    = (1U << 3),
68801aae4bddSAndrii Nakryiko };
688187f5fc7eSDavid Ahern 
68824c79579bSDavid Ahern enum {
68834c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_SUCCESS,      /* lookup successful */
68844c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_BLACKHOLE,    /* dest is blackholed; can be dropped */
68854c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_UNREACHABLE,  /* dest is unreachable; can be dropped */
68864c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_PROHIBIT,     /* dest not allowed; can be dropped */
68874c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_NOT_FWDED,    /* packet is not forwarded */
68884c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_FWD_DISABLED, /* fwding is not enabled on ingress */
68894c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_UNSUPP_LWT,   /* fwd requires encapsulation */
68904c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_NO_NEIGH,     /* no neighbor entry for nh */
68914c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_FRAG_NEEDED,  /* fragmentation required to fwd */
68924c79579bSDavid Ahern };
68934c79579bSDavid Ahern 
689487f5fc7eSDavid Ahern struct bpf_fib_lookup {
6895fa898d76SDavid Ahern 	/* input:  network family for lookup (AF_INET, AF_INET6)
6896fa898d76SDavid Ahern 	 * output: network family of egress nexthop
6897fa898d76SDavid Ahern 	 */
6898fa898d76SDavid Ahern 	__u8	family;
689987f5fc7eSDavid Ahern 
690087f5fc7eSDavid Ahern 	/* set if lookup is to consider L4 data - e.g., FIB rules */
690187f5fc7eSDavid Ahern 	__u8	l4_protocol;
690287f5fc7eSDavid Ahern 	__be16	sport;
690387f5fc7eSDavid Ahern 	__be16	dport;
690487f5fc7eSDavid Ahern 
6905e1850ea9SJesper Dangaard Brouer 	union {	/* used for MTU check */
6906e1850ea9SJesper Dangaard Brouer 		/* input to lookup */
6907e1850ea9SJesper Dangaard Brouer 		__u16	tot_len; /* L3 length from network hdr (iph->tot_len) */
69084c79579bSDavid Ahern 
6909e1850ea9SJesper Dangaard Brouer 		/* output: MTU value */
6910e1850ea9SJesper Dangaard Brouer 		__u16	mtu_result;
6911e1850ea9SJesper Dangaard Brouer 	};
69124c79579bSDavid Ahern 	/* input: L3 device index for lookup
69134c79579bSDavid Ahern 	 * output: device index from FIB lookup
69144c79579bSDavid Ahern 	 */
69154c79579bSDavid Ahern 	__u32	ifindex;
691687f5fc7eSDavid Ahern 
691787f5fc7eSDavid Ahern 	union {
691887f5fc7eSDavid Ahern 		/* inputs to lookup */
691987f5fc7eSDavid Ahern 		__u8	tos;		/* AF_INET  */
6920bd3a08aaSDavid Ahern 		__be32	flowinfo;	/* AF_INET6, flow_label + priority */
692187f5fc7eSDavid Ahern 
6922fa898d76SDavid Ahern 		/* output: metric of fib result (IPv4/IPv6 only) */
692387f5fc7eSDavid Ahern 		__u32	rt_metric;
692487f5fc7eSDavid Ahern 	};
692587f5fc7eSDavid Ahern 
692687f5fc7eSDavid Ahern 	union {
692787f5fc7eSDavid Ahern 		__be32		ipv4_src;
692887f5fc7eSDavid Ahern 		__u32		ipv6_src[4];  /* in6_addr; network order */
692987f5fc7eSDavid Ahern 	};
693087f5fc7eSDavid Ahern 
6931fa898d76SDavid Ahern 	/* input to bpf_fib_lookup, ipv{4,6}_dst is destination address in
6932fa898d76SDavid Ahern 	 * network header. output: bpf_fib_lookup sets to gateway address
6933fa898d76SDavid Ahern 	 * if FIB lookup returns gateway route
693487f5fc7eSDavid Ahern 	 */
693587f5fc7eSDavid Ahern 	union {
693687f5fc7eSDavid Ahern 		__be32		ipv4_dst;
693787f5fc7eSDavid Ahern 		__u32		ipv6_dst[4];  /* in6_addr; network order */
693887f5fc7eSDavid Ahern 	};
693987f5fc7eSDavid Ahern 
69408ad77e72SLouis DeLosSantos 	union {
69418ad77e72SLouis DeLosSantos 		struct {
694287f5fc7eSDavid Ahern 			/* output */
694387f5fc7eSDavid Ahern 			__be16	h_vlan_proto;
694487f5fc7eSDavid Ahern 			__be16	h_vlan_TCI;
69458ad77e72SLouis DeLosSantos 		};
69468ad77e72SLouis DeLosSantos 		/* input: when accompanied with the
69478ad77e72SLouis DeLosSantos 		 * 'BPF_FIB_LOOKUP_DIRECT | BPF_FIB_LOOKUP_TBID` flags, a
69488ad77e72SLouis DeLosSantos 		 * specific routing table to use for the fib lookup.
69498ad77e72SLouis DeLosSantos 		 */
69508ad77e72SLouis DeLosSantos 		__u32	tbid;
69518ad77e72SLouis DeLosSantos 	};
69528ad77e72SLouis DeLosSantos 
695387f5fc7eSDavid Ahern 	__u8	smac[6];     /* ETH_ALEN */
695487f5fc7eSDavid Ahern 	__u8	dmac[6];     /* ETH_ALEN */
695587f5fc7eSDavid Ahern };
695687f5fc7eSDavid Ahern 
6957ba452c9eSToke Høiland-Jørgensen struct bpf_redir_neigh {
6958ba452c9eSToke Høiland-Jørgensen 	/* network family for lookup (AF_INET, AF_INET6) */
6959ba452c9eSToke Høiland-Jørgensen 	__u32 nh_family;
6960ba452c9eSToke Høiland-Jørgensen 	/* network address of nexthop; skips fib lookup to find gateway */
6961ba452c9eSToke Høiland-Jørgensen 	union {
6962ba452c9eSToke Høiland-Jørgensen 		__be32		ipv4_nh;
6963ba452c9eSToke Høiland-Jørgensen 		__u32		ipv6_nh[4];  /* in6_addr; network order */
6964ba452c9eSToke Høiland-Jørgensen 	};
6965ba452c9eSToke Høiland-Jørgensen };
6966ba452c9eSToke Høiland-Jørgensen 
696734b2021cSJesper Dangaard Brouer /* bpf_check_mtu flags*/
696834b2021cSJesper Dangaard Brouer enum  bpf_check_mtu_flags {
696934b2021cSJesper Dangaard Brouer 	BPF_MTU_CHK_SEGS  = (1U << 0),
697034b2021cSJesper Dangaard Brouer };
697134b2021cSJesper Dangaard Brouer 
697234b2021cSJesper Dangaard Brouer enum bpf_check_mtu_ret {
697334b2021cSJesper Dangaard Brouer 	BPF_MTU_CHK_RET_SUCCESS,      /* check and lookup successful */
697434b2021cSJesper Dangaard Brouer 	BPF_MTU_CHK_RET_FRAG_NEEDED,  /* fragmentation required to fwd */
697534b2021cSJesper Dangaard Brouer 	BPF_MTU_CHK_RET_SEGS_TOOBIG,  /* GSO re-segmentation needed to fwd */
697634b2021cSJesper Dangaard Brouer };
697734b2021cSJesper Dangaard Brouer 
697841bdc4b4SYonghong Song enum bpf_task_fd_type {
697941bdc4b4SYonghong Song 	BPF_FD_TYPE_RAW_TRACEPOINT,	/* tp name */
698041bdc4b4SYonghong Song 	BPF_FD_TYPE_TRACEPOINT,		/* tp name */
698141bdc4b4SYonghong Song 	BPF_FD_TYPE_KPROBE,		/* (symbol + offset) or addr */
698241bdc4b4SYonghong Song 	BPF_FD_TYPE_KRETPROBE,		/* (symbol + offset) or addr */
698341bdc4b4SYonghong Song 	BPF_FD_TYPE_UPROBE,		/* filename + offset */
698441bdc4b4SYonghong Song 	BPF_FD_TYPE_URETPROBE,		/* filename + offset */
698541bdc4b4SYonghong Song };
698641bdc4b4SYonghong Song 
69871aae4bddSAndrii Nakryiko enum {
69881aae4bddSAndrii Nakryiko 	BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG		= (1U << 0),
69891aae4bddSAndrii Nakryiko 	BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL		= (1U << 1),
69901aae4bddSAndrii Nakryiko 	BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP		= (1U << 2),
69911aae4bddSAndrii Nakryiko };
6992086f9568SStanislav Fomichev 
6993d58e468bSPetar Penkov struct bpf_flow_keys {
6994d58e468bSPetar Penkov 	__u16	nhoff;
6995d58e468bSPetar Penkov 	__u16	thoff;
6996d58e468bSPetar Penkov 	__u16	addr_proto;			/* ETH_P_* of valid addrs */
6997d58e468bSPetar Penkov 	__u8	is_frag;
6998d58e468bSPetar Penkov 	__u8	is_first_frag;
6999d58e468bSPetar Penkov 	__u8	is_encap;
7000d58e468bSPetar Penkov 	__u8	ip_proto;
7001d58e468bSPetar Penkov 	__be16	n_proto;
7002d58e468bSPetar Penkov 	__be16	sport;
7003d58e468bSPetar Penkov 	__be16	dport;
7004d58e468bSPetar Penkov 	union {
7005d58e468bSPetar Penkov 		struct {
7006d58e468bSPetar Penkov 			__be32	ipv4_src;
7007d58e468bSPetar Penkov 			__be32	ipv4_dst;
7008d58e468bSPetar Penkov 		};
7009d58e468bSPetar Penkov 		struct {
7010d58e468bSPetar Penkov 			__u32	ipv6_src[4];	/* in6_addr; network order */
7011d58e468bSPetar Penkov 			__u32	ipv6_dst[4];	/* in6_addr; network order */
7012d58e468bSPetar Penkov 		};
7013d58e468bSPetar Penkov 	};
7014086f9568SStanislav Fomichev 	__u32	flags;
701571c99e32SStanislav Fomichev 	__be32	flow_label;
7016d58e468bSPetar Penkov };
7017d58e468bSPetar Penkov 
7018838e9690SYonghong Song struct bpf_func_info {
7019d30d42e0SMartin KaFai Lau 	__u32	insn_off;
7020838e9690SYonghong Song 	__u32	type_id;
7021838e9690SYonghong Song };
7022838e9690SYonghong Song 
7023c454a46bSMartin KaFai Lau #define BPF_LINE_INFO_LINE_NUM(line_col)	((line_col) >> 10)
7024c454a46bSMartin KaFai Lau #define BPF_LINE_INFO_LINE_COL(line_col)	((line_col) & 0x3ff)
7025c454a46bSMartin KaFai Lau 
7026c454a46bSMartin KaFai Lau struct bpf_line_info {
7027c454a46bSMartin KaFai Lau 	__u32	insn_off;
7028c454a46bSMartin KaFai Lau 	__u32	file_name_off;
7029c454a46bSMartin KaFai Lau 	__u32	line_off;
7030c454a46bSMartin KaFai Lau 	__u32	line_col;
7031c454a46bSMartin KaFai Lau };
7032c454a46bSMartin KaFai Lau 
7033d83525caSAlexei Starovoitov struct bpf_spin_lock {
7034d83525caSAlexei Starovoitov 	__u32	val;
7035d83525caSAlexei Starovoitov };
70367b146cebSAndrey Ignatov 
7037b00628b1SAlexei Starovoitov struct bpf_timer {
7038b00628b1SAlexei Starovoitov 	__u64 :64;
7039b00628b1SAlexei Starovoitov 	__u64 :64;
7040b00628b1SAlexei Starovoitov } __attribute__((aligned(8)));
7041b00628b1SAlexei Starovoitov 
704297e03f52SJoanne Koong struct bpf_dynptr {
704397e03f52SJoanne Koong 	__u64 :64;
704497e03f52SJoanne Koong 	__u64 :64;
704597e03f52SJoanne Koong } __attribute__((aligned(8)));
704697e03f52SJoanne Koong 
7047f0c5941fSKumar Kartikeya Dwivedi struct bpf_list_head {
7048f0c5941fSKumar Kartikeya Dwivedi 	__u64 :64;
7049f0c5941fSKumar Kartikeya Dwivedi 	__u64 :64;
7050f0c5941fSKumar Kartikeya Dwivedi } __attribute__((aligned(8)));
7051f0c5941fSKumar Kartikeya Dwivedi 
7052f0c5941fSKumar Kartikeya Dwivedi struct bpf_list_node {
7053f0c5941fSKumar Kartikeya Dwivedi 	__u64 :64;
7054f0c5941fSKumar Kartikeya Dwivedi 	__u64 :64;
7055f0c5941fSKumar Kartikeya Dwivedi } __attribute__((aligned(8)));
7056f0c5941fSKumar Kartikeya Dwivedi 
70579c395c1bSDave Marchevsky struct bpf_rb_root {
70589c395c1bSDave Marchevsky 	__u64 :64;
70599c395c1bSDave Marchevsky 	__u64 :64;
70609c395c1bSDave Marchevsky } __attribute__((aligned(8)));
70619c395c1bSDave Marchevsky 
70629c395c1bSDave Marchevsky struct bpf_rb_node {
70639c395c1bSDave Marchevsky 	__u64 :64;
70649c395c1bSDave Marchevsky 	__u64 :64;
70659c395c1bSDave Marchevsky 	__u64 :64;
70669c395c1bSDave Marchevsky } __attribute__((aligned(8)));
70679c395c1bSDave Marchevsky 
7068d54730b5SDave Marchevsky struct bpf_refcount {
7069d54730b5SDave Marchevsky 	__u32 :32;
7070d54730b5SDave Marchevsky } __attribute__((aligned(4)));
7071d54730b5SDave Marchevsky 
70727b146cebSAndrey Ignatov struct bpf_sysctl {
70737b146cebSAndrey Ignatov 	__u32	write;		/* Sysctl is being read (= 0) or written (= 1).
70747b146cebSAndrey Ignatov 				 * Allows 1,2,4-byte read, but no write.
70757b146cebSAndrey Ignatov 				 */
7076e1550bfeSAndrey Ignatov 	__u32	file_pos;	/* Sysctl file position to read from, write to.
7077e1550bfeSAndrey Ignatov 				 * Allows 1,2,4-byte read an 4-byte write.
7078e1550bfeSAndrey Ignatov 				 */
70797b146cebSAndrey Ignatov };
70807b146cebSAndrey Ignatov 
70810d01da6aSStanislav Fomichev struct bpf_sockopt {
70820d01da6aSStanislav Fomichev 	__bpf_md_ptr(struct bpf_sock *, sk);
70830d01da6aSStanislav Fomichev 	__bpf_md_ptr(void *, optval);
70840d01da6aSStanislav Fomichev 	__bpf_md_ptr(void *, optval_end);
70850d01da6aSStanislav Fomichev 
70860d01da6aSStanislav Fomichev 	__s32	level;
70870d01da6aSStanislav Fomichev 	__s32	optname;
70880d01da6aSStanislav Fomichev 	__s32	optlen;
70890d01da6aSStanislav Fomichev 	__s32	retval;
70900d01da6aSStanislav Fomichev };
70910d01da6aSStanislav Fomichev 
7092b4490c5cSCarlos Neira struct bpf_pidns_info {
7093b4490c5cSCarlos Neira 	__u32 pid;
7094b4490c5cSCarlos Neira 	__u32 tgid;
7095b4490c5cSCarlos Neira };
7096e9ddbb77SJakub Sitnicki 
7097e9ddbb77SJakub Sitnicki /* User accessible data for SK_LOOKUP programs. Add new fields at the end. */
7098e9ddbb77SJakub Sitnicki struct bpf_sk_lookup {
70997c32e8f8SLorenz Bauer 	union {
7100e9ddbb77SJakub Sitnicki 		__bpf_md_ptr(struct bpf_sock *, sk); /* Selected socket */
71017c32e8f8SLorenz Bauer 		__u64 cookie; /* Non-zero if socket was selected in PROG_TEST_RUN */
71027c32e8f8SLorenz Bauer 	};
7103e9ddbb77SJakub Sitnicki 
7104e9ddbb77SJakub Sitnicki 	__u32 family;		/* Protocol family (AF_INET, AF_INET6) */
7105e9ddbb77SJakub Sitnicki 	__u32 protocol;		/* IP protocol (IPPROTO_TCP, IPPROTO_UDP) */
7106e9ddbb77SJakub Sitnicki 	__u32 remote_ip4;	/* Network byte order */
7107e9ddbb77SJakub Sitnicki 	__u32 remote_ip6[4];	/* Network byte order */
71089a69e2b3SJakub Sitnicki 	__be16 remote_port;	/* Network byte order */
71099a69e2b3SJakub Sitnicki 	__u16 :16;		/* Zero padding */
7110e9ddbb77SJakub Sitnicki 	__u32 local_ip4;	/* Network byte order */
7111e9ddbb77SJakub Sitnicki 	__u32 local_ip6[4];	/* Network byte order */
7112e9ddbb77SJakub Sitnicki 	__u32 local_port;	/* Host byte order */
7113f8931565SMark Pashmfouroush 	__u32 ingress_ifindex;		/* The arriving interface. Determined by inet_iif. */
7114e9ddbb77SJakub Sitnicki };
7115e9ddbb77SJakub Sitnicki 
7116c4d0bfb4SAlan Maguire /*
7117c4d0bfb4SAlan Maguire  * struct btf_ptr is used for typed pointer representation; the
7118c4d0bfb4SAlan Maguire  * type id is used to render the pointer data as the appropriate type
7119c4d0bfb4SAlan Maguire  * via the bpf_snprintf_btf() helper described above.  A flags field -
7120c4d0bfb4SAlan Maguire  * potentially to specify additional details about the BTF pointer
7121c4d0bfb4SAlan Maguire  * (rather than its mode of display) - is included for future use.
7122c4d0bfb4SAlan Maguire  * Display flags - BTF_F_* - are passed to bpf_snprintf_btf separately.
7123c4d0bfb4SAlan Maguire  */
7124c4d0bfb4SAlan Maguire struct btf_ptr {
7125c4d0bfb4SAlan Maguire 	void *ptr;
7126c4d0bfb4SAlan Maguire 	__u32 type_id;
7127c4d0bfb4SAlan Maguire 	__u32 flags;		/* BTF ptr flags; unused at present. */
7128c4d0bfb4SAlan Maguire };
7129c4d0bfb4SAlan Maguire 
7130c4d0bfb4SAlan Maguire /*
7131c4d0bfb4SAlan Maguire  * Flags to control bpf_snprintf_btf() behaviour.
7132c4d0bfb4SAlan Maguire  *     - BTF_F_COMPACT: no formatting around type information
7133c4d0bfb4SAlan Maguire  *     - BTF_F_NONAME: no struct/union member names/types
7134c4d0bfb4SAlan Maguire  *     - BTF_F_PTR_RAW: show raw (unobfuscated) pointer values;
7135c4d0bfb4SAlan Maguire  *       equivalent to %px.
7136c4d0bfb4SAlan Maguire  *     - BTF_F_ZERO: show zero-valued struct/union members; they
7137c4d0bfb4SAlan Maguire  *       are not displayed by default
7138c4d0bfb4SAlan Maguire  */
7139c4d0bfb4SAlan Maguire enum {
7140c4d0bfb4SAlan Maguire 	BTF_F_COMPACT	=	(1ULL << 0),
7141c4d0bfb4SAlan Maguire 	BTF_F_NONAME	=	(1ULL << 1),
7142c4d0bfb4SAlan Maguire 	BTF_F_PTR_RAW	=	(1ULL << 2),
7143c4d0bfb4SAlan Maguire 	BTF_F_ZERO	=	(1ULL << 3),
7144c4d0bfb4SAlan Maguire };
7145c4d0bfb4SAlan Maguire 
714646334a0cSAlexei Starovoitov /* bpf_core_relo_kind encodes which aspect of captured field/type/enum value
714746334a0cSAlexei Starovoitov  * has to be adjusted by relocations. It is emitted by llvm and passed to
714846334a0cSAlexei Starovoitov  * libbpf and later to the kernel.
714946334a0cSAlexei Starovoitov  */
715046334a0cSAlexei Starovoitov enum bpf_core_relo_kind {
715146334a0cSAlexei Starovoitov 	BPF_CORE_FIELD_BYTE_OFFSET = 0,      /* field byte offset */
715246334a0cSAlexei Starovoitov 	BPF_CORE_FIELD_BYTE_SIZE = 1,        /* field size in bytes */
715346334a0cSAlexei Starovoitov 	BPF_CORE_FIELD_EXISTS = 2,           /* field existence in target kernel */
715446334a0cSAlexei Starovoitov 	BPF_CORE_FIELD_SIGNED = 3,           /* field signedness (0 - unsigned, 1 - signed) */
715546334a0cSAlexei Starovoitov 	BPF_CORE_FIELD_LSHIFT_U64 = 4,       /* bitfield-specific left bitshift */
715646334a0cSAlexei Starovoitov 	BPF_CORE_FIELD_RSHIFT_U64 = 5,       /* bitfield-specific right bitshift */
715746334a0cSAlexei Starovoitov 	BPF_CORE_TYPE_ID_LOCAL = 6,          /* type ID in local BPF object */
715846334a0cSAlexei Starovoitov 	BPF_CORE_TYPE_ID_TARGET = 7,         /* type ID in target kernel */
715946334a0cSAlexei Starovoitov 	BPF_CORE_TYPE_EXISTS = 8,            /* type existence in target kernel */
716046334a0cSAlexei Starovoitov 	BPF_CORE_TYPE_SIZE = 9,              /* type size in bytes */
716146334a0cSAlexei Starovoitov 	BPF_CORE_ENUMVAL_EXISTS = 10,        /* enum value existence in target kernel */
716246334a0cSAlexei Starovoitov 	BPF_CORE_ENUMVAL_VALUE = 11,         /* enum value integer value */
71633c660a5dSDaniel Müller 	BPF_CORE_TYPE_MATCHES = 12,          /* type match in target kernel */
716446334a0cSAlexei Starovoitov };
716546334a0cSAlexei Starovoitov 
7166fbd94c7aSAlexei Starovoitov /*
7167fbd94c7aSAlexei Starovoitov  * "struct bpf_core_relo" is used to pass relocation data form LLVM to libbpf
7168fbd94c7aSAlexei Starovoitov  * and from libbpf to the kernel.
7169fbd94c7aSAlexei Starovoitov  *
7170fbd94c7aSAlexei Starovoitov  * CO-RE relocation captures the following data:
7171fbd94c7aSAlexei Starovoitov  * - insn_off - instruction offset (in bytes) within a BPF program that needs
7172fbd94c7aSAlexei Starovoitov  *   its insn->imm field to be relocated with actual field info;
7173fbd94c7aSAlexei Starovoitov  * - type_id - BTF type ID of the "root" (containing) entity of a relocatable
7174fbd94c7aSAlexei Starovoitov  *   type or field;
7175fbd94c7aSAlexei Starovoitov  * - access_str_off - offset into corresponding .BTF string section. String
7176fbd94c7aSAlexei Starovoitov  *   interpretation depends on specific relocation kind:
7177fbd94c7aSAlexei Starovoitov  *     - for field-based relocations, string encodes an accessed field using
7178fbd94c7aSAlexei Starovoitov  *       a sequence of field and array indices, separated by colon (:). It's
7179fbd94c7aSAlexei Starovoitov  *       conceptually very close to LLVM's getelementptr ([0]) instruction's
7180fbd94c7aSAlexei Starovoitov  *       arguments for identifying offset to a field.
7181fbd94c7aSAlexei Starovoitov  *     - for type-based relocations, strings is expected to be just "0";
7182fbd94c7aSAlexei Starovoitov  *     - for enum value-based relocations, string contains an index of enum
7183fbd94c7aSAlexei Starovoitov  *       value within its enum type;
7184fbd94c7aSAlexei Starovoitov  * - kind - one of enum bpf_core_relo_kind;
7185fbd94c7aSAlexei Starovoitov  *
7186fbd94c7aSAlexei Starovoitov  * Example:
7187fbd94c7aSAlexei Starovoitov  *   struct sample {
7188fbd94c7aSAlexei Starovoitov  *       int a;
7189fbd94c7aSAlexei Starovoitov  *       struct {
7190fbd94c7aSAlexei Starovoitov  *           int b[10];
7191fbd94c7aSAlexei Starovoitov  *       };
7192fbd94c7aSAlexei Starovoitov  *   };
7193fbd94c7aSAlexei Starovoitov  *
7194fbd94c7aSAlexei Starovoitov  *   struct sample *s = ...;
7195fbd94c7aSAlexei Starovoitov  *   int *x = &s->a;     // encoded as "0:0" (a is field #0)
7196fbd94c7aSAlexei Starovoitov  *   int *y = &s->b[5];  // encoded as "0:1:0:5" (anon struct is field #1,
7197fbd94c7aSAlexei Starovoitov  *                       // b is field #0 inside anon struct, accessing elem #5)
7198fbd94c7aSAlexei Starovoitov  *   int *z = &s[10]->b; // encoded as "10:1" (ptr is used as an array)
7199fbd94c7aSAlexei Starovoitov  *
7200fbd94c7aSAlexei Starovoitov  * type_id for all relocs in this example will capture BTF type id of
7201fbd94c7aSAlexei Starovoitov  * `struct sample`.
7202fbd94c7aSAlexei Starovoitov  *
7203fbd94c7aSAlexei Starovoitov  * Such relocation is emitted when using __builtin_preserve_access_index()
7204fbd94c7aSAlexei Starovoitov  * Clang built-in, passing expression that captures field address, e.g.:
7205fbd94c7aSAlexei Starovoitov  *
7206fbd94c7aSAlexei Starovoitov  * bpf_probe_read(&dst, sizeof(dst),
7207fbd94c7aSAlexei Starovoitov  *		  __builtin_preserve_access_index(&src->a.b.c));
7208fbd94c7aSAlexei Starovoitov  *
7209fbd94c7aSAlexei Starovoitov  * In this case Clang will emit field relocation recording necessary data to
7210fbd94c7aSAlexei Starovoitov  * be able to find offset of embedded `a.b.c` field within `src` struct.
7211fbd94c7aSAlexei Starovoitov  *
7212fbd94c7aSAlexei Starovoitov  * [0] https://llvm.org/docs/LangRef.html#getelementptr-instruction
7213fbd94c7aSAlexei Starovoitov  */
7214fbd94c7aSAlexei Starovoitov struct bpf_core_relo {
7215fbd94c7aSAlexei Starovoitov 	__u32 insn_off;
7216fbd94c7aSAlexei Starovoitov 	__u32 type_id;
7217fbd94c7aSAlexei Starovoitov 	__u32 access_str_off;
7218fbd94c7aSAlexei Starovoitov 	enum bpf_core_relo_kind kind;
7219fbd94c7aSAlexei Starovoitov };
7220fbd94c7aSAlexei Starovoitov 
7221f71f8530STero Kristo /*
7222f71f8530STero Kristo  * Flags to control bpf_timer_start() behaviour.
7223f71f8530STero Kristo  *     - BPF_F_TIMER_ABS: Timeout passed is absolute time, by default it is
7224f71f8530STero Kristo  *       relative to current time.
7225f71f8530STero Kristo  */
7226f71f8530STero Kristo enum {
7227f71f8530STero Kristo 	BPF_F_TIMER_ABS = (1ULL << 0),
7228f71f8530STero Kristo };
7229f71f8530STero Kristo 
72306018e1f4SAndrii Nakryiko /* BPF numbers iterator state */
72316018e1f4SAndrii Nakryiko struct bpf_iter_num {
72326018e1f4SAndrii Nakryiko 	/* opaque iterator state; having __u64 here allows to preserve correct
72336018e1f4SAndrii Nakryiko 	 * alignment requirements in vmlinux.h, generated from BTF
72346018e1f4SAndrii Nakryiko 	 */
72356018e1f4SAndrii Nakryiko 	__u64 __opaque[1];
72366018e1f4SAndrii Nakryiko } __attribute__((aligned(8)));
72376018e1f4SAndrii Nakryiko 
7238daedfb22SAlexei Starovoitov #endif /* _UAPI__LINUX_BPF_H__ */
7239