xref: /linux/include/uapi/linux/bpf.h (revision 0cb804547927c05f6aa7e28c8d4a1e02fec1a6d4)
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 */
821e6e9d0fSGustavo A. R. Silva 	__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 */
87de9cbbaaSRoman Gushchin 	__u32	attach_type;		/* program attach type */
88de9cbbaaSRoman Gushchin };
89de9cbbaaSRoman Gushchin 
905e7b3020SYonghong Song union bpf_iter_link_info {
915e7b3020SYonghong Song 	struct {
925e7b3020SYonghong Song 		__u32	map_fd;
935e7b3020SYonghong Song 	} map;
945e7b3020SYonghong Song };
955e7b3020SYonghong Song 
967799e4d9SJoe Stringer /* BPF syscall commands, see bpf(2) man-page for more details. */
977799e4d9SJoe Stringer /**
987799e4d9SJoe Stringer  * DOC: eBPF Syscall Preamble
997799e4d9SJoe Stringer  *
1007799e4d9SJoe Stringer  * The operation to be performed by the **bpf**\ () system call is determined
1017799e4d9SJoe Stringer  * by the *cmd* argument. Each operation takes an accompanying argument,
1027799e4d9SJoe Stringer  * provided via *attr*, which is a pointer to a union of type *bpf_attr* (see
1037799e4d9SJoe Stringer  * below). The size argument is the size of the union pointed to by *attr*.
1047799e4d9SJoe Stringer  */
1057799e4d9SJoe Stringer /**
1067799e4d9SJoe Stringer  * DOC: eBPF Syscall Commands
1077799e4d9SJoe Stringer  *
1087799e4d9SJoe Stringer  * BPF_MAP_CREATE
1097799e4d9SJoe Stringer  *	Description
1107799e4d9SJoe Stringer  *		Create a map and return a file descriptor that refers to the
1117799e4d9SJoe Stringer  *		map. The close-on-exec file descriptor flag (see **fcntl**\ (2))
1127799e4d9SJoe Stringer  *		is automatically enabled for the new file descriptor.
1137799e4d9SJoe Stringer  *
1147799e4d9SJoe Stringer  *		Applying **close**\ (2) to the file descriptor returned by
1157799e4d9SJoe Stringer  *		**BPF_MAP_CREATE** will delete the map (but see NOTES).
1167799e4d9SJoe Stringer  *
1177799e4d9SJoe Stringer  *	Return
1187799e4d9SJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
1197799e4d9SJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
1207799e4d9SJoe Stringer  *
1217799e4d9SJoe Stringer  * BPF_MAP_LOOKUP_ELEM
1227799e4d9SJoe Stringer  *	Description
1237799e4d9SJoe Stringer  *		Look up an element with a given *key* in the map referred to
1247799e4d9SJoe Stringer  *		by the file descriptor *map_fd*.
1257799e4d9SJoe Stringer  *
1266690523bSJoe Stringer  *		The *flags* argument may be specified as one of the
1276690523bSJoe Stringer  *		following:
1286690523bSJoe Stringer  *
1296690523bSJoe Stringer  *		**BPF_F_LOCK**
1306690523bSJoe Stringer  *			Look up the value of a spin-locked map without
1316690523bSJoe Stringer  *			returning the lock. This must be specified if the
1326690523bSJoe Stringer  *			elements contain a spinlock.
1336690523bSJoe Stringer  *
1347799e4d9SJoe Stringer  *	Return
1357799e4d9SJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
1367799e4d9SJoe Stringer  *		is set appropriately.
1377799e4d9SJoe Stringer  *
1387799e4d9SJoe Stringer  * BPF_MAP_UPDATE_ELEM
1397799e4d9SJoe Stringer  *	Description
1407799e4d9SJoe Stringer  *		Create or update an element (key/value pair) in a specified map.
1417799e4d9SJoe Stringer  *
1427799e4d9SJoe Stringer  *		The *flags* argument should be specified as one of the
1437799e4d9SJoe Stringer  *		following:
1447799e4d9SJoe Stringer  *
1457799e4d9SJoe Stringer  *		**BPF_ANY**
1467799e4d9SJoe Stringer  *			Create a new element or update an existing element.
1477799e4d9SJoe Stringer  *		**BPF_NOEXIST**
1487799e4d9SJoe Stringer  *			Create a new element only if it did not exist.
1497799e4d9SJoe Stringer  *		**BPF_EXIST**
1507799e4d9SJoe Stringer  *			Update an existing element.
1516690523bSJoe Stringer  *		**BPF_F_LOCK**
1526690523bSJoe Stringer  *			Update a spin_lock-ed map element.
1537799e4d9SJoe Stringer  *
1547799e4d9SJoe Stringer  *	Return
1557799e4d9SJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
1567799e4d9SJoe Stringer  *		is set appropriately.
1577799e4d9SJoe Stringer  *
1587799e4d9SJoe Stringer  *		May set *errno* to **EINVAL**, **EPERM**, **ENOMEM**,
1597799e4d9SJoe Stringer  *		**E2BIG**, **EEXIST**, or **ENOENT**.
1607799e4d9SJoe Stringer  *
1617799e4d9SJoe Stringer  *		**E2BIG**
1627799e4d9SJoe Stringer  *			The number of elements in the map reached the
1637799e4d9SJoe Stringer  *			*max_entries* limit specified at map creation time.
1647799e4d9SJoe Stringer  *		**EEXIST**
1657799e4d9SJoe Stringer  *			If *flags* specifies **BPF_NOEXIST** and the element
1667799e4d9SJoe Stringer  *			with *key* already exists in the map.
1677799e4d9SJoe Stringer  *		**ENOENT**
1687799e4d9SJoe Stringer  *			If *flags* specifies **BPF_EXIST** and the element with
1697799e4d9SJoe Stringer  *			*key* does not exist in the map.
1707799e4d9SJoe Stringer  *
1717799e4d9SJoe Stringer  * BPF_MAP_DELETE_ELEM
1727799e4d9SJoe Stringer  *	Description
1737799e4d9SJoe Stringer  *		Look up and delete an element by key in a specified map.
1747799e4d9SJoe Stringer  *
1757799e4d9SJoe Stringer  *	Return
1767799e4d9SJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
1777799e4d9SJoe Stringer  *		is set appropriately.
1787799e4d9SJoe Stringer  *
1797799e4d9SJoe Stringer  * BPF_MAP_GET_NEXT_KEY
1807799e4d9SJoe Stringer  *	Description
1817799e4d9SJoe Stringer  *		Look up an element by key in a specified map and return the key
1827799e4d9SJoe Stringer  *		of the next element. Can be used to iterate over all elements
1837799e4d9SJoe Stringer  *		in the map.
1847799e4d9SJoe Stringer  *
1857799e4d9SJoe Stringer  *	Return
1867799e4d9SJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
1877799e4d9SJoe Stringer  *		is set appropriately.
1887799e4d9SJoe Stringer  *
1897799e4d9SJoe Stringer  *		The following cases can be used to iterate over all elements of
1907799e4d9SJoe Stringer  *		the map:
1917799e4d9SJoe Stringer  *
1927799e4d9SJoe Stringer  *		* If *key* is not found, the operation returns zero and sets
1937799e4d9SJoe Stringer  *		  the *next_key* pointer to the key of the first element.
1947799e4d9SJoe Stringer  *		* If *key* is found, the operation returns zero and sets the
1957799e4d9SJoe Stringer  *		  *next_key* pointer to the key of the next element.
1967799e4d9SJoe Stringer  *		* If *key* is the last element, returns -1 and *errno* is set
1977799e4d9SJoe Stringer  *		  to **ENOENT**.
1987799e4d9SJoe Stringer  *
1997799e4d9SJoe Stringer  *		May set *errno* to **ENOMEM**, **EFAULT**, **EPERM**, or
2007799e4d9SJoe Stringer  *		**EINVAL** on error.
2017799e4d9SJoe Stringer  *
2027799e4d9SJoe Stringer  * BPF_PROG_LOAD
2037799e4d9SJoe Stringer  *	Description
2047799e4d9SJoe Stringer  *		Verify and load an eBPF program, returning a new file
2057799e4d9SJoe Stringer  *		descriptor associated with the program.
2067799e4d9SJoe Stringer  *
2077799e4d9SJoe Stringer  *		Applying **close**\ (2) to the file descriptor returned by
2087799e4d9SJoe Stringer  *		**BPF_PROG_LOAD** will unload the eBPF program (but see NOTES).
2097799e4d9SJoe Stringer  *
2107799e4d9SJoe Stringer  *		The close-on-exec file descriptor flag (see **fcntl**\ (2)) is
2117799e4d9SJoe Stringer  *		automatically enabled for the new file descriptor.
2127799e4d9SJoe Stringer  *
2137799e4d9SJoe Stringer  *	Return
2147799e4d9SJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
2157799e4d9SJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
2167799e4d9SJoe Stringer  *
217f67c9cbfSJoe Stringer  * BPF_OBJ_PIN
218f67c9cbfSJoe Stringer  *	Description
219f67c9cbfSJoe Stringer  *		Pin an eBPF program or map referred by the specified *bpf_fd*
220f67c9cbfSJoe Stringer  *		to the provided *pathname* on the filesystem.
221f67c9cbfSJoe Stringer  *
2228aacb3c8SJoe Stringer  *		The *pathname* argument must not contain a dot (".").
2238aacb3c8SJoe Stringer  *
2248aacb3c8SJoe Stringer  *		On success, *pathname* retains a reference to the eBPF object,
2258aacb3c8SJoe Stringer  *		preventing deallocation of the object when the original
2268aacb3c8SJoe Stringer  *		*bpf_fd* is closed. This allow the eBPF object to live beyond
2278aacb3c8SJoe Stringer  *		**close**\ (\ *bpf_fd*\ ), and hence the lifetime of the parent
2288aacb3c8SJoe Stringer  *		process.
2298aacb3c8SJoe Stringer  *
2308aacb3c8SJoe Stringer  *		Applying **unlink**\ (2) or similar calls to the *pathname*
2318aacb3c8SJoe Stringer  *		unpins the object from the filesystem, removing the reference.
2328aacb3c8SJoe Stringer  *		If no other file descriptors or filesystem nodes refer to the
2338aacb3c8SJoe Stringer  *		same object, it will be deallocated (see NOTES).
2348aacb3c8SJoe Stringer  *
2358aacb3c8SJoe Stringer  *		The filesystem type for the parent directory of *pathname* must
2368aacb3c8SJoe Stringer  *		be **BPF_FS_MAGIC**.
2378aacb3c8SJoe Stringer  *
238f67c9cbfSJoe Stringer  *	Return
239f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
240f67c9cbfSJoe Stringer  *		is set appropriately.
241f67c9cbfSJoe Stringer  *
242f67c9cbfSJoe Stringer  * BPF_OBJ_GET
243f67c9cbfSJoe Stringer  *	Description
244f67c9cbfSJoe Stringer  *		Open a file descriptor for the eBPF object pinned to the
245f67c9cbfSJoe Stringer  *		specified *pathname*.
246f67c9cbfSJoe Stringer  *
247f67c9cbfSJoe Stringer  *	Return
248f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
249f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
250f67c9cbfSJoe Stringer  *
251f67c9cbfSJoe Stringer  * BPF_PROG_ATTACH
252f67c9cbfSJoe Stringer  *	Description
253f67c9cbfSJoe Stringer  *		Attach an eBPF program to a *target_fd* at the specified
254f67c9cbfSJoe Stringer  *		*attach_type* hook.
255f67c9cbfSJoe Stringer  *
25632e76b18SJoe Stringer  *		The *attach_type* specifies the eBPF attachment point to
25732e76b18SJoe Stringer  *		attach the program to, and must be one of *bpf_attach_type*
25832e76b18SJoe Stringer  *		(see below).
25932e76b18SJoe Stringer  *
26032e76b18SJoe Stringer  *		The *attach_bpf_fd* must be a valid file descriptor for a
26132e76b18SJoe Stringer  *		loaded eBPF program of a cgroup, flow dissector, LIRC, sockmap
26232e76b18SJoe Stringer  *		or sock_ops type corresponding to the specified *attach_type*.
26332e76b18SJoe Stringer  *
26432e76b18SJoe Stringer  *		The *target_fd* must be a valid file descriptor for a kernel
26532e76b18SJoe Stringer  *		object which depends on the attach type of *attach_bpf_fd*:
26632e76b18SJoe Stringer  *
26732e76b18SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_DEVICE**,
26832e76b18SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SKB**,
26932e76b18SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SOCK**,
27032e76b18SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,
27132e76b18SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SOCKOPT**,
27232e76b18SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SYSCTL**,
27332e76b18SJoe Stringer  *		**BPF_PROG_TYPE_SOCK_OPS**
27432e76b18SJoe Stringer  *
27532e76b18SJoe Stringer  *			Control Group v2 hierarchy with the eBPF controller
27632e76b18SJoe Stringer  *			enabled. Requires the kernel to be compiled with
27732e76b18SJoe Stringer  *			**CONFIG_CGROUP_BPF**.
27832e76b18SJoe Stringer  *
27932e76b18SJoe Stringer  *		**BPF_PROG_TYPE_FLOW_DISSECTOR**
28032e76b18SJoe Stringer  *
28132e76b18SJoe Stringer  *			Network namespace (eg /proc/self/ns/net).
28232e76b18SJoe Stringer  *
28332e76b18SJoe Stringer  *		**BPF_PROG_TYPE_LIRC_MODE2**
28432e76b18SJoe Stringer  *
28532e76b18SJoe Stringer  *			LIRC device path (eg /dev/lircN). Requires the kernel
28632e76b18SJoe Stringer  *			to be compiled with **CONFIG_BPF_LIRC_MODE2**.
28732e76b18SJoe Stringer  *
28832e76b18SJoe Stringer  *		**BPF_PROG_TYPE_SK_SKB**,
28932e76b18SJoe Stringer  *		**BPF_PROG_TYPE_SK_MSG**
29032e76b18SJoe Stringer  *
29132e76b18SJoe Stringer  *			eBPF map of socket type (eg **BPF_MAP_TYPE_SOCKHASH**).
29232e76b18SJoe Stringer  *
293f67c9cbfSJoe Stringer  *	Return
294f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
295f67c9cbfSJoe Stringer  *		is set appropriately.
296f67c9cbfSJoe Stringer  *
297f67c9cbfSJoe Stringer  * BPF_PROG_DETACH
298f67c9cbfSJoe Stringer  *	Description
299f67c9cbfSJoe Stringer  *		Detach the eBPF program associated with the *target_fd* at the
300f67c9cbfSJoe Stringer  *		hook specified by *attach_type*. The program must have been
301f67c9cbfSJoe Stringer  *		previously attached using **BPF_PROG_ATTACH**.
302f67c9cbfSJoe Stringer  *
303f67c9cbfSJoe Stringer  *	Return
304f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
305f67c9cbfSJoe Stringer  *		is set appropriately.
306f67c9cbfSJoe Stringer  *
307f67c9cbfSJoe Stringer  * BPF_PROG_TEST_RUN
308f67c9cbfSJoe Stringer  *	Description
3092a3fdca4SJoe Stringer  *		Run the eBPF program associated with the *prog_fd* a *repeat*
3102a3fdca4SJoe Stringer  *		number of times against a provided program context *ctx_in* and
3112a3fdca4SJoe Stringer  *		data *data_in*, and return the modified program context
3122a3fdca4SJoe Stringer  *		*ctx_out*, *data_out* (for example, packet data), result of the
3132a3fdca4SJoe Stringer  *		execution *retval*, and *duration* of the test run.
314f67c9cbfSJoe Stringer  *
315f67c9cbfSJoe Stringer  *	Return
316f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
317f67c9cbfSJoe Stringer  *		is set appropriately.
318f67c9cbfSJoe Stringer  *
3192a3fdca4SJoe Stringer  *		**ENOSPC**
3202a3fdca4SJoe Stringer  *			Either *data_size_out* or *ctx_size_out* is too small.
3212a3fdca4SJoe Stringer  *		**ENOTSUPP**
3222a3fdca4SJoe Stringer  *			This command is not supported by the program type of
3232a3fdca4SJoe Stringer  *			the program referred to by *prog_fd*.
3242a3fdca4SJoe Stringer  *
325f67c9cbfSJoe Stringer  * BPF_PROG_GET_NEXT_ID
326f67c9cbfSJoe Stringer  *	Description
327f67c9cbfSJoe Stringer  *		Fetch the next eBPF program currently loaded into the kernel.
328f67c9cbfSJoe Stringer  *
329f67c9cbfSJoe Stringer  *		Looks for the eBPF program with an id greater than *start_id*
330f67c9cbfSJoe Stringer  *		and updates *next_id* on success. If no other eBPF programs
331f67c9cbfSJoe Stringer  *		remain with ids higher than *start_id*, returns -1 and sets
332f67c9cbfSJoe Stringer  *		*errno* to **ENOENT**.
333f67c9cbfSJoe Stringer  *
334f67c9cbfSJoe Stringer  *	Return
335f67c9cbfSJoe Stringer  *		Returns zero on success. On error, or when no id remains, -1
336f67c9cbfSJoe Stringer  *		is returned and *errno* is set appropriately.
337f67c9cbfSJoe Stringer  *
338f67c9cbfSJoe Stringer  * BPF_MAP_GET_NEXT_ID
339f67c9cbfSJoe Stringer  *	Description
340f67c9cbfSJoe Stringer  *		Fetch the next eBPF map currently loaded into the kernel.
341f67c9cbfSJoe Stringer  *
342f67c9cbfSJoe Stringer  *		Looks for the eBPF map with an id greater than *start_id*
343f67c9cbfSJoe Stringer  *		and updates *next_id* on success. If no other eBPF maps
344f67c9cbfSJoe Stringer  *		remain with ids higher than *start_id*, returns -1 and sets
345f67c9cbfSJoe Stringer  *		*errno* to **ENOENT**.
346f67c9cbfSJoe Stringer  *
347f67c9cbfSJoe Stringer  *	Return
348f67c9cbfSJoe Stringer  *		Returns zero on success. On error, or when no id remains, -1
349f67c9cbfSJoe Stringer  *		is returned and *errno* is set appropriately.
350f67c9cbfSJoe Stringer  *
351f67c9cbfSJoe Stringer  * BPF_PROG_GET_FD_BY_ID
352f67c9cbfSJoe Stringer  *	Description
353f67c9cbfSJoe Stringer  *		Open a file descriptor for the eBPF program corresponding to
354f67c9cbfSJoe Stringer  *		*prog_id*.
355f67c9cbfSJoe Stringer  *
356f67c9cbfSJoe Stringer  *	Return
357f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
358f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
359f67c9cbfSJoe Stringer  *
360f67c9cbfSJoe Stringer  * BPF_MAP_GET_FD_BY_ID
361f67c9cbfSJoe Stringer  *	Description
362f67c9cbfSJoe Stringer  *		Open a file descriptor for the eBPF map corresponding to
363f67c9cbfSJoe Stringer  *		*map_id*.
364f67c9cbfSJoe Stringer  *
365f67c9cbfSJoe Stringer  *	Return
366f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
367f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
368f67c9cbfSJoe Stringer  *
369f67c9cbfSJoe Stringer  * BPF_OBJ_GET_INFO_BY_FD
370f67c9cbfSJoe Stringer  *	Description
371f67c9cbfSJoe Stringer  *		Obtain information about the eBPF object corresponding to
372f67c9cbfSJoe Stringer  *		*bpf_fd*.
373f67c9cbfSJoe Stringer  *
374f67c9cbfSJoe Stringer  *		Populates up to *info_len* bytes of *info*, which will be in
375f67c9cbfSJoe Stringer  *		one of the following formats depending on the eBPF object type
376f67c9cbfSJoe Stringer  *		of *bpf_fd*:
377f67c9cbfSJoe Stringer  *
378f67c9cbfSJoe Stringer  *		* **struct bpf_prog_info**
379f67c9cbfSJoe Stringer  *		* **struct bpf_map_info**
380f67c9cbfSJoe Stringer  *		* **struct bpf_btf_info**
381f67c9cbfSJoe Stringer  *		* **struct bpf_link_info**
382f67c9cbfSJoe Stringer  *
383f67c9cbfSJoe Stringer  *	Return
384f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
385f67c9cbfSJoe Stringer  *		is set appropriately.
386f67c9cbfSJoe Stringer  *
387f67c9cbfSJoe Stringer  * BPF_PROG_QUERY
388f67c9cbfSJoe Stringer  *	Description
389f67c9cbfSJoe Stringer  *		Obtain information about eBPF programs associated with the
390f67c9cbfSJoe Stringer  *		specified *attach_type* hook.
391f67c9cbfSJoe Stringer  *
3925d999994SJoe Stringer  *		The *target_fd* must be a valid file descriptor for a kernel
3935d999994SJoe Stringer  *		object which depends on the attach type of *attach_bpf_fd*:
3945d999994SJoe Stringer  *
3955d999994SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_DEVICE**,
3965d999994SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SKB**,
3975d999994SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SOCK**,
3985d999994SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,
3995d999994SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SOCKOPT**,
4005d999994SJoe Stringer  *		**BPF_PROG_TYPE_CGROUP_SYSCTL**,
4015d999994SJoe Stringer  *		**BPF_PROG_TYPE_SOCK_OPS**
4025d999994SJoe Stringer  *
4035d999994SJoe Stringer  *			Control Group v2 hierarchy with the eBPF controller
4045d999994SJoe Stringer  *			enabled. Requires the kernel to be compiled with
4055d999994SJoe Stringer  *			**CONFIG_CGROUP_BPF**.
4065d999994SJoe Stringer  *
4075d999994SJoe Stringer  *		**BPF_PROG_TYPE_FLOW_DISSECTOR**
4085d999994SJoe Stringer  *
4095d999994SJoe Stringer  *			Network namespace (eg /proc/self/ns/net).
4105d999994SJoe Stringer  *
4115d999994SJoe Stringer  *		**BPF_PROG_TYPE_LIRC_MODE2**
4125d999994SJoe Stringer  *
4135d999994SJoe Stringer  *			LIRC device path (eg /dev/lircN). Requires the kernel
4145d999994SJoe Stringer  *			to be compiled with **CONFIG_BPF_LIRC_MODE2**.
4155d999994SJoe Stringer  *
4165d999994SJoe Stringer  *		**BPF_PROG_QUERY** always fetches the number of programs
4175d999994SJoe Stringer  *		attached and the *attach_flags* which were used to attach those
4185d999994SJoe Stringer  *		programs. Additionally, if *prog_ids* is nonzero and the number
4195d999994SJoe Stringer  *		of attached programs is less than *prog_cnt*, populates
4205d999994SJoe Stringer  *		*prog_ids* with the eBPF program ids of the programs attached
4215d999994SJoe Stringer  *		at *target_fd*.
4225d999994SJoe Stringer  *
4235d999994SJoe Stringer  *		The following flags may alter the result:
4245d999994SJoe Stringer  *
4255d999994SJoe Stringer  *		**BPF_F_QUERY_EFFECTIVE**
4265d999994SJoe Stringer  *			Only return information regarding programs which are
4275d999994SJoe Stringer  *			currently effective at the specified *target_fd*.
4285d999994SJoe Stringer  *
429f67c9cbfSJoe Stringer  *	Return
430f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
431f67c9cbfSJoe Stringer  *		is set appropriately.
432f67c9cbfSJoe Stringer  *
433f67c9cbfSJoe Stringer  * BPF_RAW_TRACEPOINT_OPEN
434f67c9cbfSJoe Stringer  *	Description
435f67c9cbfSJoe Stringer  *		Attach an eBPF program to a tracepoint *name* to access kernel
436f67c9cbfSJoe Stringer  *		internal arguments of the tracepoint in their raw form.
437f67c9cbfSJoe Stringer  *
438f67c9cbfSJoe Stringer  *		The *prog_fd* must be a valid file descriptor associated with
439f67c9cbfSJoe Stringer  *		a loaded eBPF program of type **BPF_PROG_TYPE_RAW_TRACEPOINT**.
440f67c9cbfSJoe Stringer  *
441f67c9cbfSJoe Stringer  *		No ABI guarantees are made about the content of tracepoint
442f67c9cbfSJoe Stringer  *		arguments exposed to the corresponding eBPF program.
443f67c9cbfSJoe Stringer  *
444f67c9cbfSJoe Stringer  *		Applying **close**\ (2) to the file descriptor returned by
445f67c9cbfSJoe Stringer  *		**BPF_RAW_TRACEPOINT_OPEN** will delete the map (but see NOTES).
446f67c9cbfSJoe Stringer  *
447f67c9cbfSJoe Stringer  *	Return
448f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
449f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
450f67c9cbfSJoe Stringer  *
451f67c9cbfSJoe Stringer  * BPF_BTF_LOAD
452f67c9cbfSJoe Stringer  *	Description
453f67c9cbfSJoe Stringer  *		Verify and load BPF Type Format (BTF) metadata into the kernel,
454f67c9cbfSJoe Stringer  *		returning a new file descriptor associated with the metadata.
455f67c9cbfSJoe Stringer  *		BTF is described in more detail at
456f67c9cbfSJoe Stringer  *		https://www.kernel.org/doc/html/latest/bpf/btf.html.
457f67c9cbfSJoe Stringer  *
458f67c9cbfSJoe Stringer  *		The *btf* parameter must point to valid memory providing
459f67c9cbfSJoe Stringer  *		*btf_size* bytes of BTF binary metadata.
460f67c9cbfSJoe Stringer  *
461f67c9cbfSJoe Stringer  *		The returned file descriptor can be passed to other **bpf**\ ()
462f67c9cbfSJoe Stringer  *		subcommands such as **BPF_PROG_LOAD** or **BPF_MAP_CREATE** to
463f67c9cbfSJoe Stringer  *		associate the BTF with those objects.
464f67c9cbfSJoe Stringer  *
465f67c9cbfSJoe Stringer  *		Similar to **BPF_PROG_LOAD**, **BPF_BTF_LOAD** has optional
466f67c9cbfSJoe Stringer  *		parameters to specify a *btf_log_buf*, *btf_log_size* and
467f67c9cbfSJoe Stringer  *		*btf_log_level* which allow the kernel to return freeform log
468f67c9cbfSJoe Stringer  *		output regarding the BTF verification process.
469f67c9cbfSJoe Stringer  *
470f67c9cbfSJoe Stringer  *	Return
471f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
472f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
473f67c9cbfSJoe Stringer  *
474f67c9cbfSJoe Stringer  * BPF_BTF_GET_FD_BY_ID
475f67c9cbfSJoe Stringer  *	Description
476f67c9cbfSJoe Stringer  *		Open a file descriptor for the BPF Type Format (BTF)
477f67c9cbfSJoe Stringer  *		corresponding to *btf_id*.
478f67c9cbfSJoe Stringer  *
479f67c9cbfSJoe Stringer  *	Return
480f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
481f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
482f67c9cbfSJoe Stringer  *
483f67c9cbfSJoe Stringer  * BPF_TASK_FD_QUERY
484f67c9cbfSJoe Stringer  *	Description
485f67c9cbfSJoe Stringer  *		Obtain information about eBPF programs associated with the
486f67c9cbfSJoe Stringer  *		target process identified by *pid* and *fd*.
487f67c9cbfSJoe Stringer  *
488f67c9cbfSJoe Stringer  *		If the *pid* and *fd* are associated with a tracepoint, kprobe
489f67c9cbfSJoe Stringer  *		or uprobe perf event, then the *prog_id* and *fd_type* will
490f67c9cbfSJoe Stringer  *		be populated with the eBPF program id and file descriptor type
491f67c9cbfSJoe Stringer  *		of type **bpf_task_fd_type**. If associated with a kprobe or
492f67c9cbfSJoe Stringer  *		uprobe, the  *probe_offset* and *probe_addr* will also be
493f67c9cbfSJoe Stringer  *		populated. Optionally, if *buf* is provided, then up to
494f67c9cbfSJoe Stringer  *		*buf_len* bytes of *buf* will be populated with the name of
495f67c9cbfSJoe Stringer  *		the tracepoint, kprobe or uprobe.
496f67c9cbfSJoe Stringer  *
497f67c9cbfSJoe Stringer  *		The resulting *prog_id* may be introspected in deeper detail
498f67c9cbfSJoe Stringer  *		using **BPF_PROG_GET_FD_BY_ID** and **BPF_OBJ_GET_INFO_BY_FD**.
499f67c9cbfSJoe Stringer  *
500f67c9cbfSJoe Stringer  *	Return
501f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
502f67c9cbfSJoe Stringer  *		is set appropriately.
503f67c9cbfSJoe Stringer  *
504f67c9cbfSJoe Stringer  * BPF_MAP_LOOKUP_AND_DELETE_ELEM
505f67c9cbfSJoe Stringer  *	Description
506f67c9cbfSJoe Stringer  *		Look up an element with the given *key* in the map referred to
507f67c9cbfSJoe Stringer  *		by the file descriptor *fd*, and if found, delete the element.
508f67c9cbfSJoe Stringer  *
509f67c9cbfSJoe Stringer  *		The **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map types
510f67c9cbfSJoe Stringer  *		implement this command as a "pop" operation, deleting the top
511f67c9cbfSJoe Stringer  *		element rather than one corresponding to *key*.
512f67c9cbfSJoe Stringer  *		The *key* and *key_len* parameters should be zeroed when
513f67c9cbfSJoe Stringer  *		issuing this operation for these map types.
514f67c9cbfSJoe Stringer  *
515f67c9cbfSJoe Stringer  *		This command is only valid for the following map types:
516f67c9cbfSJoe Stringer  *		* **BPF_MAP_TYPE_QUEUE**
517f67c9cbfSJoe Stringer  *		* **BPF_MAP_TYPE_STACK**
518f67c9cbfSJoe Stringer  *
519f67c9cbfSJoe Stringer  *	Return
520f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
521f67c9cbfSJoe Stringer  *		is set appropriately.
522f67c9cbfSJoe Stringer  *
523f67c9cbfSJoe Stringer  * BPF_MAP_FREEZE
524f67c9cbfSJoe Stringer  *	Description
525f67c9cbfSJoe Stringer  *		Freeze the permissions of the specified map.
526f67c9cbfSJoe Stringer  *
527f67c9cbfSJoe Stringer  *		Write permissions may be frozen by passing zero *flags*.
528f67c9cbfSJoe Stringer  *		Upon success, no future syscall invocations may alter the
529f67c9cbfSJoe Stringer  *		map state of *map_fd*. Write operations from eBPF programs
530f67c9cbfSJoe Stringer  *		are still possible for a frozen map.
531f67c9cbfSJoe Stringer  *
532f67c9cbfSJoe Stringer  *		Not supported for maps of type **BPF_MAP_TYPE_STRUCT_OPS**.
533f67c9cbfSJoe Stringer  *
534f67c9cbfSJoe Stringer  *	Return
535f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
536f67c9cbfSJoe Stringer  *		is set appropriately.
537f67c9cbfSJoe Stringer  *
538f67c9cbfSJoe Stringer  * BPF_BTF_GET_NEXT_ID
539f67c9cbfSJoe Stringer  *	Description
540f67c9cbfSJoe Stringer  *		Fetch the next BPF Type Format (BTF) object currently loaded
541f67c9cbfSJoe Stringer  *		into the kernel.
542f67c9cbfSJoe Stringer  *
543f67c9cbfSJoe Stringer  *		Looks for the BTF object with an id greater than *start_id*
544f67c9cbfSJoe Stringer  *		and updates *next_id* on success. If no other BTF objects
545f67c9cbfSJoe Stringer  *		remain with ids higher than *start_id*, returns -1 and sets
546f67c9cbfSJoe Stringer  *		*errno* to **ENOENT**.
547f67c9cbfSJoe Stringer  *
548f67c9cbfSJoe Stringer  *	Return
549f67c9cbfSJoe Stringer  *		Returns zero on success. On error, or when no id remains, -1
550f67c9cbfSJoe Stringer  *		is returned and *errno* is set appropriately.
551f67c9cbfSJoe Stringer  *
552f67c9cbfSJoe Stringer  * BPF_MAP_LOOKUP_BATCH
553f67c9cbfSJoe Stringer  *	Description
554f67c9cbfSJoe Stringer  *		Iterate and fetch multiple elements in a map.
555f67c9cbfSJoe Stringer  *
556*0cb80454SJoe Stringer  *		Two opaque values are used to manage batch operations,
557*0cb80454SJoe Stringer  *		*in_batch* and *out_batch*. Initially, *in_batch* must be set
558*0cb80454SJoe Stringer  *		to NULL to begin the batched operation. After each subsequent
559*0cb80454SJoe Stringer  *		**BPF_MAP_LOOKUP_BATCH**, the caller should pass the resultant
560*0cb80454SJoe Stringer  *		*out_batch* as the *in_batch* for the next operation to
561*0cb80454SJoe Stringer  *		continue iteration from the current point.
562*0cb80454SJoe Stringer  *
563*0cb80454SJoe Stringer  *		The *keys* and *values* are output parameters which must point
564*0cb80454SJoe Stringer  *		to memory large enough to hold *count* items based on the key
565*0cb80454SJoe Stringer  *		and value size of the map *map_fd*. The *keys* buffer must be
566*0cb80454SJoe Stringer  *		of *key_size* * *count*. The *values* buffer must be of
567*0cb80454SJoe Stringer  *		*value_size* * *count*.
568*0cb80454SJoe Stringer  *
569*0cb80454SJoe Stringer  *		The *elem_flags* argument may be specified as one of the
570*0cb80454SJoe Stringer  *		following:
571*0cb80454SJoe Stringer  *
572*0cb80454SJoe Stringer  *		**BPF_F_LOCK**
573*0cb80454SJoe Stringer  *			Look up the value of a spin-locked map without
574*0cb80454SJoe Stringer  *			returning the lock. This must be specified if the
575*0cb80454SJoe Stringer  *			elements contain a spinlock.
576*0cb80454SJoe Stringer  *
577*0cb80454SJoe Stringer  *		On success, *count* elements from the map are copied into the
578*0cb80454SJoe Stringer  *		user buffer, with the keys copied into *keys* and the values
579*0cb80454SJoe Stringer  *		copied into the corresponding indices in *values*.
580*0cb80454SJoe Stringer  *
581*0cb80454SJoe Stringer  *		If an error is returned and *errno* is not **EFAULT**, *count*
582*0cb80454SJoe Stringer  *		is set to the number of successfully processed elements.
583*0cb80454SJoe Stringer  *
584f67c9cbfSJoe Stringer  *	Return
585f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
586f67c9cbfSJoe Stringer  *		is set appropriately.
587f67c9cbfSJoe Stringer  *
588*0cb80454SJoe Stringer  *		May set *errno* to **ENOSPC** to indicate that *keys* or
589*0cb80454SJoe Stringer  *		*values* is too small to dump an entire bucket during
590*0cb80454SJoe Stringer  *		iteration of a hash-based map type.
591*0cb80454SJoe Stringer  *
592f67c9cbfSJoe Stringer  * BPF_MAP_LOOKUP_AND_DELETE_BATCH
593f67c9cbfSJoe Stringer  *	Description
594*0cb80454SJoe Stringer  *		Iterate and delete all elements in a map.
595*0cb80454SJoe Stringer  *
596*0cb80454SJoe Stringer  *		This operation has the same behavior as
597*0cb80454SJoe Stringer  *		**BPF_MAP_LOOKUP_BATCH** with two exceptions:
598*0cb80454SJoe Stringer  *
599*0cb80454SJoe Stringer  *		* Every element that is successfully returned is also deleted
600*0cb80454SJoe Stringer  *		  from the map. This is at least *count* elements. Note that
601*0cb80454SJoe Stringer  *		  *count* is both an input and an output parameter.
602*0cb80454SJoe Stringer  *		* Upon returning with *errno* set to **EFAULT**, up to
603*0cb80454SJoe Stringer  *		  *count* elements may be deleted without returning the keys
604*0cb80454SJoe Stringer  *		  and values of the deleted elements.
605f67c9cbfSJoe Stringer  *
606f67c9cbfSJoe Stringer  *	Return
607f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
608f67c9cbfSJoe Stringer  *		is set appropriately.
609f67c9cbfSJoe Stringer  *
610f67c9cbfSJoe Stringer  * BPF_MAP_UPDATE_BATCH
611f67c9cbfSJoe Stringer  *	Description
612*0cb80454SJoe Stringer  *		Update multiple elements in a map by *key*.
613*0cb80454SJoe Stringer  *
614*0cb80454SJoe Stringer  *		The *keys* and *values* are input parameters which must point
615*0cb80454SJoe Stringer  *		to memory large enough to hold *count* items based on the key
616*0cb80454SJoe Stringer  *		and value size of the map *map_fd*. The *keys* buffer must be
617*0cb80454SJoe Stringer  *		of *key_size* * *count*. The *values* buffer must be of
618*0cb80454SJoe Stringer  *		*value_size* * *count*.
619*0cb80454SJoe Stringer  *
620*0cb80454SJoe Stringer  *		Each element specified in *keys* is sequentially updated to the
621*0cb80454SJoe Stringer  *		value in the corresponding index in *values*. The *in_batch*
622*0cb80454SJoe Stringer  *		and *out_batch* parameters are ignored and should be zeroed.
623*0cb80454SJoe Stringer  *
624*0cb80454SJoe Stringer  *		The *elem_flags* argument should be specified as one of the
625*0cb80454SJoe Stringer  *		following:
626*0cb80454SJoe Stringer  *
627*0cb80454SJoe Stringer  *		**BPF_ANY**
628*0cb80454SJoe Stringer  *			Create new elements or update a existing elements.
629*0cb80454SJoe Stringer  *		**BPF_NOEXIST**
630*0cb80454SJoe Stringer  *			Create new elements only if they do not exist.
631*0cb80454SJoe Stringer  *		**BPF_EXIST**
632*0cb80454SJoe Stringer  *			Update existing elements.
633*0cb80454SJoe Stringer  *		**BPF_F_LOCK**
634*0cb80454SJoe Stringer  *			Update spin_lock-ed map elements. This must be
635*0cb80454SJoe Stringer  *			specified if the map value contains a spinlock.
636*0cb80454SJoe Stringer  *
637*0cb80454SJoe Stringer  *		On success, *count* elements from the map are updated.
638*0cb80454SJoe Stringer  *
639*0cb80454SJoe Stringer  *		If an error is returned and *errno* is not **EFAULT**, *count*
640*0cb80454SJoe Stringer  *		is set to the number of successfully processed elements.
641f67c9cbfSJoe Stringer  *
642f67c9cbfSJoe Stringer  *	Return
643f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
644f67c9cbfSJoe Stringer  *		is set appropriately.
645f67c9cbfSJoe Stringer  *
646*0cb80454SJoe Stringer  *		May set *errno* to **EINVAL**, **EPERM**, **ENOMEM**, or
647*0cb80454SJoe Stringer  *		**E2BIG**. **E2BIG** indicates that the number of elements in
648*0cb80454SJoe Stringer  *		the map reached the *max_entries* limit specified at map
649*0cb80454SJoe Stringer  *		creation time.
650*0cb80454SJoe Stringer  *
651*0cb80454SJoe Stringer  *		May set *errno* to one of the following error codes under
652*0cb80454SJoe Stringer  *		specific circumstances:
653*0cb80454SJoe Stringer  *
654*0cb80454SJoe Stringer  *		**EEXIST**
655*0cb80454SJoe Stringer  *			If *flags* specifies **BPF_NOEXIST** and the element
656*0cb80454SJoe Stringer  *			with *key* already exists in the map.
657*0cb80454SJoe Stringer  *		**ENOENT**
658*0cb80454SJoe Stringer  *			If *flags* specifies **BPF_EXIST** and the element with
659*0cb80454SJoe Stringer  *			*key* does not exist in the map.
660*0cb80454SJoe Stringer  *
661f67c9cbfSJoe Stringer  * BPF_MAP_DELETE_BATCH
662f67c9cbfSJoe Stringer  *	Description
663*0cb80454SJoe Stringer  *		Delete multiple elements in a map by *key*.
664*0cb80454SJoe Stringer  *
665*0cb80454SJoe Stringer  *		The *keys* parameter is an input parameter which must point
666*0cb80454SJoe Stringer  *		to memory large enough to hold *count* items based on the key
667*0cb80454SJoe Stringer  *		size of the map *map_fd*, that is, *key_size* * *count*.
668*0cb80454SJoe Stringer  *
669*0cb80454SJoe Stringer  *		Each element specified in *keys* is sequentially deleted. The
670*0cb80454SJoe Stringer  *		*in_batch*, *out_batch*, and *values* parameters are ignored
671*0cb80454SJoe Stringer  *		and should be zeroed.
672*0cb80454SJoe Stringer  *
673*0cb80454SJoe Stringer  *		The *elem_flags* argument may be specified as one of the
674*0cb80454SJoe Stringer  *		following:
675*0cb80454SJoe Stringer  *
676*0cb80454SJoe Stringer  *		**BPF_F_LOCK**
677*0cb80454SJoe Stringer  *			Look up the value of a spin-locked map without
678*0cb80454SJoe Stringer  *			returning the lock. This must be specified if the
679*0cb80454SJoe Stringer  *			elements contain a spinlock.
680*0cb80454SJoe Stringer  *
681*0cb80454SJoe Stringer  *		On success, *count* elements from the map are updated.
682*0cb80454SJoe Stringer  *
683*0cb80454SJoe Stringer  *		If an error is returned and *errno* is not **EFAULT**, *count*
684*0cb80454SJoe Stringer  *		is set to the number of successfully processed elements. If
685*0cb80454SJoe Stringer  *		*errno* is **EFAULT**, up to *count* elements may be been
686*0cb80454SJoe Stringer  *		deleted.
687f67c9cbfSJoe Stringer  *
688f67c9cbfSJoe Stringer  *	Return
689f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
690f67c9cbfSJoe Stringer  *		is set appropriately.
691f67c9cbfSJoe Stringer  *
692f67c9cbfSJoe Stringer  * BPF_LINK_CREATE
693f67c9cbfSJoe Stringer  *	Description
694f67c9cbfSJoe Stringer  *		Attach an eBPF program to a *target_fd* at the specified
695f67c9cbfSJoe Stringer  *		*attach_type* hook and return a file descriptor handle for
696f67c9cbfSJoe Stringer  *		managing the link.
697f67c9cbfSJoe Stringer  *
698f67c9cbfSJoe Stringer  *	Return
699f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
700f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
701f67c9cbfSJoe Stringer  *
702f67c9cbfSJoe Stringer  * BPF_LINK_UPDATE
703f67c9cbfSJoe Stringer  *	Description
704f67c9cbfSJoe Stringer  *		Update the eBPF program in the specified *link_fd* to
705f67c9cbfSJoe Stringer  *		*new_prog_fd*.
706f67c9cbfSJoe Stringer  *
707f67c9cbfSJoe Stringer  *	Return
708f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
709f67c9cbfSJoe Stringer  *		is set appropriately.
710f67c9cbfSJoe Stringer  *
711f67c9cbfSJoe Stringer  * BPF_LINK_GET_FD_BY_ID
712f67c9cbfSJoe Stringer  *	Description
713f67c9cbfSJoe Stringer  *		Open a file descriptor for the eBPF Link corresponding to
714f67c9cbfSJoe Stringer  *		*link_id*.
715f67c9cbfSJoe Stringer  *
716f67c9cbfSJoe Stringer  *	Return
717f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
718f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
719f67c9cbfSJoe Stringer  *
720f67c9cbfSJoe Stringer  * BPF_LINK_GET_NEXT_ID
721f67c9cbfSJoe Stringer  *	Description
722f67c9cbfSJoe Stringer  *		Fetch the next eBPF link currently loaded into the kernel.
723f67c9cbfSJoe Stringer  *
724f67c9cbfSJoe Stringer  *		Looks for the eBPF link with an id greater than *start_id*
725f67c9cbfSJoe Stringer  *		and updates *next_id* on success. If no other eBPF links
726f67c9cbfSJoe Stringer  *		remain with ids higher than *start_id*, returns -1 and sets
727f67c9cbfSJoe Stringer  *		*errno* to **ENOENT**.
728f67c9cbfSJoe Stringer  *
729f67c9cbfSJoe Stringer  *	Return
730f67c9cbfSJoe Stringer  *		Returns zero on success. On error, or when no id remains, -1
731f67c9cbfSJoe Stringer  *		is returned and *errno* is set appropriately.
732f67c9cbfSJoe Stringer  *
733f67c9cbfSJoe Stringer  * BPF_ENABLE_STATS
734f67c9cbfSJoe Stringer  *	Description
735f67c9cbfSJoe Stringer  *		Enable eBPF runtime statistics gathering.
736f67c9cbfSJoe Stringer  *
737f67c9cbfSJoe Stringer  *		Runtime statistics gathering for the eBPF runtime is disabled
738f67c9cbfSJoe Stringer  *		by default to minimize the corresponding performance overhead.
739f67c9cbfSJoe Stringer  *		This command enables statistics globally.
740f67c9cbfSJoe Stringer  *
741f67c9cbfSJoe Stringer  *		Multiple programs may independently enable statistics.
742f67c9cbfSJoe Stringer  *		After gathering the desired statistics, eBPF runtime statistics
743f67c9cbfSJoe Stringer  *		may be disabled again by calling **close**\ (2) for the file
744f67c9cbfSJoe Stringer  *		descriptor returned by this function. Statistics will only be
745f67c9cbfSJoe Stringer  *		disabled system-wide when all outstanding file descriptors
746f67c9cbfSJoe Stringer  *		returned by prior calls for this subcommand are closed.
747f67c9cbfSJoe Stringer  *
748f67c9cbfSJoe Stringer  *	Return
749f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
750f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
751f67c9cbfSJoe Stringer  *
752f67c9cbfSJoe Stringer  * BPF_ITER_CREATE
753f67c9cbfSJoe Stringer  *	Description
754f67c9cbfSJoe Stringer  *		Create an iterator on top of the specified *link_fd* (as
755f67c9cbfSJoe Stringer  *		previously created using **BPF_LINK_CREATE**) and return a
756f67c9cbfSJoe Stringer  *		file descriptor that can be used to trigger the iteration.
757f67c9cbfSJoe Stringer  *
758f67c9cbfSJoe Stringer  *		If the resulting file descriptor is pinned to the filesystem
759f67c9cbfSJoe Stringer  *		using  **BPF_OBJ_PIN**, then subsequent **read**\ (2) syscalls
760f67c9cbfSJoe Stringer  *		for that path will trigger the iterator to read kernel state
761f67c9cbfSJoe Stringer  *		using the eBPF program attached to *link_fd*.
762f67c9cbfSJoe Stringer  *
763f67c9cbfSJoe Stringer  *	Return
764f67c9cbfSJoe Stringer  *		A new file descriptor (a nonnegative integer), or -1 if an
765f67c9cbfSJoe Stringer  *		error occurred (in which case, *errno* is set appropriately).
766f67c9cbfSJoe Stringer  *
767f67c9cbfSJoe Stringer  * BPF_LINK_DETACH
768f67c9cbfSJoe Stringer  *	Description
769f67c9cbfSJoe Stringer  *		Forcefully detach the specified *link_fd* from its
770f67c9cbfSJoe Stringer  *		corresponding attachment point.
771f67c9cbfSJoe Stringer  *
772f67c9cbfSJoe Stringer  *	Return
773f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
774f67c9cbfSJoe Stringer  *		is set appropriately.
775f67c9cbfSJoe Stringer  *
776f67c9cbfSJoe Stringer  * BPF_PROG_BIND_MAP
777f67c9cbfSJoe Stringer  *	Description
778f67c9cbfSJoe Stringer  *		Bind a map to the lifetime of an eBPF program.
779f67c9cbfSJoe Stringer  *
780f67c9cbfSJoe Stringer  *		The map identified by *map_fd* is bound to the program
781f67c9cbfSJoe Stringer  *		identified by *prog_fd* and only released when *prog_fd* is
782f67c9cbfSJoe Stringer  *		released. This may be used in cases where metadata should be
783f67c9cbfSJoe Stringer  *		associated with a program which otherwise does not contain any
784f67c9cbfSJoe Stringer  *		references to the map (for example, embedded in the eBPF
785f67c9cbfSJoe Stringer  *		program instructions).
786f67c9cbfSJoe Stringer  *
787f67c9cbfSJoe Stringer  *	Return
788f67c9cbfSJoe Stringer  *		Returns zero on success. On error, -1 is returned and *errno*
789f67c9cbfSJoe Stringer  *		is set appropriately.
790f67c9cbfSJoe Stringer  *
7917799e4d9SJoe Stringer  * NOTES
7927799e4d9SJoe Stringer  *	eBPF objects (maps and programs) can be shared between processes.
7938aacb3c8SJoe Stringer  *
7948aacb3c8SJoe Stringer  *	* After **fork**\ (2), the child inherits file descriptors
7958aacb3c8SJoe Stringer  *	  referring to the same eBPF objects.
7968aacb3c8SJoe Stringer  *	* File descriptors referring to eBPF objects can be transferred over
7978aacb3c8SJoe Stringer  *	  **unix**\ (7) domain sockets.
7988aacb3c8SJoe Stringer  *	* File descriptors referring to eBPF objects can be duplicated in the
7998aacb3c8SJoe Stringer  *	  usual way, using **dup**\ (2) and similar calls.
8008aacb3c8SJoe Stringer  *	* File descriptors referring to eBPF objects can be pinned to the
8018aacb3c8SJoe Stringer  *	  filesystem using the **BPF_OBJ_PIN** command of **bpf**\ (2).
8028aacb3c8SJoe Stringer  *
8038aacb3c8SJoe Stringer  *	An eBPF object is deallocated only after all file descriptors referring
8048aacb3c8SJoe Stringer  *	to the object have been closed and no references remain pinned to the
8058aacb3c8SJoe Stringer  *	filesystem or attached (for example, bound to a program or device).
8067799e4d9SJoe Stringer  */
80799c55f7dSAlexei Starovoitov enum bpf_cmd {
80899c55f7dSAlexei Starovoitov 	BPF_MAP_CREATE,
809db20fd2bSAlexei Starovoitov 	BPF_MAP_LOOKUP_ELEM,
810db20fd2bSAlexei Starovoitov 	BPF_MAP_UPDATE_ELEM,
811db20fd2bSAlexei Starovoitov 	BPF_MAP_DELETE_ELEM,
812db20fd2bSAlexei Starovoitov 	BPF_MAP_GET_NEXT_KEY,
81309756af4SAlexei Starovoitov 	BPF_PROG_LOAD,
814b2197755SDaniel Borkmann 	BPF_OBJ_PIN,
815b2197755SDaniel Borkmann 	BPF_OBJ_GET,
816f4324551SDaniel Mack 	BPF_PROG_ATTACH,
817f4324551SDaniel Mack 	BPF_PROG_DETACH,
8181cf1cae9SAlexei Starovoitov 	BPF_PROG_TEST_RUN,
81934ad5580SMartin KaFai Lau 	BPF_PROG_GET_NEXT_ID,
82034ad5580SMartin KaFai Lau 	BPF_MAP_GET_NEXT_ID,
821b16d9aa4SMartin KaFai Lau 	BPF_PROG_GET_FD_BY_ID,
822bd5f5f4eSMartin KaFai Lau 	BPF_MAP_GET_FD_BY_ID,
8231e270976SMartin KaFai Lau 	BPF_OBJ_GET_INFO_BY_FD,
824468e2f64SAlexei Starovoitov 	BPF_PROG_QUERY,
825c4f6699dSAlexei Starovoitov 	BPF_RAW_TRACEPOINT_OPEN,
826f56a653cSMartin KaFai Lau 	BPF_BTF_LOAD,
82778958fcaSMartin KaFai Lau 	BPF_BTF_GET_FD_BY_ID,
82841bdc4b4SYonghong Song 	BPF_TASK_FD_QUERY,
829bd513cd0SMauricio Vasquez B 	BPF_MAP_LOOKUP_AND_DELETE_ELEM,
83087df15deSDaniel Borkmann 	BPF_MAP_FREEZE,
8311b9ed84eSQuentin Monnet 	BPF_BTF_GET_NEXT_ID,
832cb4d03abSBrian Vazquez 	BPF_MAP_LOOKUP_BATCH,
83305799638SYonghong Song 	BPF_MAP_LOOKUP_AND_DELETE_BATCH,
834aa2e93b8SBrian Vazquez 	BPF_MAP_UPDATE_BATCH,
835aa2e93b8SBrian Vazquez 	BPF_MAP_DELETE_BATCH,
836af6eea57SAndrii Nakryiko 	BPF_LINK_CREATE,
8370c991ebcSAndrii Nakryiko 	BPF_LINK_UPDATE,
8382d602c8cSAndrii Nakryiko 	BPF_LINK_GET_FD_BY_ID,
8392d602c8cSAndrii Nakryiko 	BPF_LINK_GET_NEXT_ID,
840d46edd67SSong Liu 	BPF_ENABLE_STATS,
841ac51d99bSYonghong Song 	BPF_ITER_CREATE,
84273b11c2aSAndrii Nakryiko 	BPF_LINK_DETACH,
843ef15314aSYiFei Zhu 	BPF_PROG_BIND_MAP,
84499c55f7dSAlexei Starovoitov };
84599c55f7dSAlexei Starovoitov 
84699c55f7dSAlexei Starovoitov enum bpf_map_type {
84799c55f7dSAlexei Starovoitov 	BPF_MAP_TYPE_UNSPEC,
8480f8e4bd8SAlexei Starovoitov 	BPF_MAP_TYPE_HASH,
84928fbcfa0SAlexei Starovoitov 	BPF_MAP_TYPE_ARRAY,
85004fd61abSAlexei Starovoitov 	BPF_MAP_TYPE_PROG_ARRAY,
851ea317b26SKaixu Xia 	BPF_MAP_TYPE_PERF_EVENT_ARRAY,
852824bd0ceSAlexei Starovoitov 	BPF_MAP_TYPE_PERCPU_HASH,
853a10423b8SAlexei Starovoitov 	BPF_MAP_TYPE_PERCPU_ARRAY,
854d5a3b1f6SAlexei Starovoitov 	BPF_MAP_TYPE_STACK_TRACE,
8554ed8ec52SMartin KaFai Lau 	BPF_MAP_TYPE_CGROUP_ARRAY,
85629ba732aSMartin KaFai Lau 	BPF_MAP_TYPE_LRU_HASH,
8578f844938SMartin KaFai Lau 	BPF_MAP_TYPE_LRU_PERCPU_HASH,
858b95a5c4dSDaniel Mack 	BPF_MAP_TYPE_LPM_TRIE,
85956f668dfSMartin KaFai Lau 	BPF_MAP_TYPE_ARRAY_OF_MAPS,
860bcc6b1b7SMartin KaFai Lau 	BPF_MAP_TYPE_HASH_OF_MAPS,
861546ac1ffSJohn Fastabend 	BPF_MAP_TYPE_DEVMAP,
862174a79ffSJohn Fastabend 	BPF_MAP_TYPE_SOCKMAP,
8636710e112SJesper Dangaard Brouer 	BPF_MAP_TYPE_CPUMAP,
864fbfc504aSBjörn Töpel 	BPF_MAP_TYPE_XSKMAP,
86581110384SJohn Fastabend 	BPF_MAP_TYPE_SOCKHASH,
866de9cbbaaSRoman Gushchin 	BPF_MAP_TYPE_CGROUP_STORAGE,
8675dc4c4b7SMartin KaFai Lau 	BPF_MAP_TYPE_REUSEPORT_SOCKARRAY,
868b741f163SRoman Gushchin 	BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE,
869f1a2e44aSMauricio Vasquez B 	BPF_MAP_TYPE_QUEUE,
870f1a2e44aSMauricio Vasquez B 	BPF_MAP_TYPE_STACK,
8716ac99e8fSMartin KaFai Lau 	BPF_MAP_TYPE_SK_STORAGE,
8726f9d451aSToke Høiland-Jørgensen 	BPF_MAP_TYPE_DEVMAP_HASH,
87385d33df3SMartin KaFai Lau 	BPF_MAP_TYPE_STRUCT_OPS,
874457f4436SAndrii Nakryiko 	BPF_MAP_TYPE_RINGBUF,
8758ea63684SKP Singh 	BPF_MAP_TYPE_INODE_STORAGE,
8764cf1bc1fSKP Singh 	BPF_MAP_TYPE_TASK_STORAGE,
87799c55f7dSAlexei Starovoitov };
87899c55f7dSAlexei Starovoitov 
8796c4fc209SDaniel Borkmann /* Note that tracing related programs such as
8806c4fc209SDaniel Borkmann  * BPF_PROG_TYPE_{KPROBE,TRACEPOINT,PERF_EVENT,RAW_TRACEPOINT}
8816c4fc209SDaniel Borkmann  * are not subject to a stable API since kernel internal data
8826c4fc209SDaniel Borkmann  * structures can change from release to release and may
8836c4fc209SDaniel Borkmann  * therefore break existing tracing BPF programs. Tracing BPF
8846c4fc209SDaniel Borkmann  * programs correspond to /a/ specific kernel which is to be
8856c4fc209SDaniel Borkmann  * analyzed, and not /a/ specific kernel /and/ all future ones.
8866c4fc209SDaniel Borkmann  */
88709756af4SAlexei Starovoitov enum bpf_prog_type {
88809756af4SAlexei Starovoitov 	BPF_PROG_TYPE_UNSPEC,
889ddd872bcSAlexei Starovoitov 	BPF_PROG_TYPE_SOCKET_FILTER,
8902541517cSAlexei Starovoitov 	BPF_PROG_TYPE_KPROBE,
89196be4325SDaniel Borkmann 	BPF_PROG_TYPE_SCHED_CLS,
89294caee8cSDaniel Borkmann 	BPF_PROG_TYPE_SCHED_ACT,
89398b5c2c6SAlexei Starovoitov 	BPF_PROG_TYPE_TRACEPOINT,
8946a773a15SBrenden Blanco 	BPF_PROG_TYPE_XDP,
8950515e599SAlexei Starovoitov 	BPF_PROG_TYPE_PERF_EVENT,
8960e33661dSDaniel Mack 	BPF_PROG_TYPE_CGROUP_SKB,
89761023658SDavid Ahern 	BPF_PROG_TYPE_CGROUP_SOCK,
8983a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_IN,
8993a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_OUT,
9003a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_XMIT,
90140304b2aSLawrence Brakmo 	BPF_PROG_TYPE_SOCK_OPS,
902b005fd18SJohn Fastabend 	BPF_PROG_TYPE_SK_SKB,
903ebc614f6SRoman Gushchin 	BPF_PROG_TYPE_CGROUP_DEVICE,
9044f738adbSJohn Fastabend 	BPF_PROG_TYPE_SK_MSG,
905c4f6699dSAlexei Starovoitov 	BPF_PROG_TYPE_RAW_TRACEPOINT,
9064fbac77dSAndrey Ignatov 	BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
907004d4b27SMathieu Xhonneux 	BPF_PROG_TYPE_LWT_SEG6LOCAL,
908f4364dcfSSean Young 	BPF_PROG_TYPE_LIRC_MODE2,
9092dbb9b9eSMartin KaFai Lau 	BPF_PROG_TYPE_SK_REUSEPORT,
910d58e468bSPetar Penkov 	BPF_PROG_TYPE_FLOW_DISSECTOR,
9117b146cebSAndrey Ignatov 	BPF_PROG_TYPE_CGROUP_SYSCTL,
9129df1c28bSMatt Mullins 	BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
9130d01da6aSStanislav Fomichev 	BPF_PROG_TYPE_CGROUP_SOCKOPT,
914f1b9509cSAlexei Starovoitov 	BPF_PROG_TYPE_TRACING,
91527ae7997SMartin KaFai Lau 	BPF_PROG_TYPE_STRUCT_OPS,
916be8704ffSAlexei Starovoitov 	BPF_PROG_TYPE_EXT,
917fc611f47SKP Singh 	BPF_PROG_TYPE_LSM,
918e9ddbb77SJakub Sitnicki 	BPF_PROG_TYPE_SK_LOOKUP,
91909756af4SAlexei Starovoitov };
92009756af4SAlexei Starovoitov 
9210e33661dSDaniel Mack enum bpf_attach_type {
9220e33661dSDaniel Mack 	BPF_CGROUP_INET_INGRESS,
9230e33661dSDaniel Mack 	BPF_CGROUP_INET_EGRESS,
92461023658SDavid Ahern 	BPF_CGROUP_INET_SOCK_CREATE,
92540304b2aSLawrence Brakmo 	BPF_CGROUP_SOCK_OPS,
926464bc0fdSJohn Fastabend 	BPF_SK_SKB_STREAM_PARSER,
927464bc0fdSJohn Fastabend 	BPF_SK_SKB_STREAM_VERDICT,
928ebc614f6SRoman Gushchin 	BPF_CGROUP_DEVICE,
9294f738adbSJohn Fastabend 	BPF_SK_MSG_VERDICT,
9304fbac77dSAndrey Ignatov 	BPF_CGROUP_INET4_BIND,
9314fbac77dSAndrey Ignatov 	BPF_CGROUP_INET6_BIND,
932d74bad4eSAndrey Ignatov 	BPF_CGROUP_INET4_CONNECT,
933d74bad4eSAndrey Ignatov 	BPF_CGROUP_INET6_CONNECT,
934aac3fc32SAndrey Ignatov 	BPF_CGROUP_INET4_POST_BIND,
935aac3fc32SAndrey Ignatov 	BPF_CGROUP_INET6_POST_BIND,
9361cedee13SAndrey Ignatov 	BPF_CGROUP_UDP4_SENDMSG,
9371cedee13SAndrey Ignatov 	BPF_CGROUP_UDP6_SENDMSG,
938f4364dcfSSean Young 	BPF_LIRC_MODE2,
939d58e468bSPetar Penkov 	BPF_FLOW_DISSECTOR,
9407b146cebSAndrey Ignatov 	BPF_CGROUP_SYSCTL,
941983695faSDaniel Borkmann 	BPF_CGROUP_UDP4_RECVMSG,
942983695faSDaniel Borkmann 	BPF_CGROUP_UDP6_RECVMSG,
9430d01da6aSStanislav Fomichev 	BPF_CGROUP_GETSOCKOPT,
9440d01da6aSStanislav Fomichev 	BPF_CGROUP_SETSOCKOPT,
945f1b9509cSAlexei Starovoitov 	BPF_TRACE_RAW_TP,
946fec56f58SAlexei Starovoitov 	BPF_TRACE_FENTRY,
947fec56f58SAlexei Starovoitov 	BPF_TRACE_FEXIT,
948ae240823SKP Singh 	BPF_MODIFY_RETURN,
949fc611f47SKP Singh 	BPF_LSM_MAC,
95015d83c4dSYonghong Song 	BPF_TRACE_ITER,
9511b66d253SDaniel Borkmann 	BPF_CGROUP_INET4_GETPEERNAME,
9521b66d253SDaniel Borkmann 	BPF_CGROUP_INET6_GETPEERNAME,
9531b66d253SDaniel Borkmann 	BPF_CGROUP_INET4_GETSOCKNAME,
9541b66d253SDaniel Borkmann 	BPF_CGROUP_INET6_GETSOCKNAME,
955fbee97feSDavid Ahern 	BPF_XDP_DEVMAP,
956f5836749SStanislav Fomichev 	BPF_CGROUP_INET_SOCK_RELEASE,
95792164774SLorenzo Bianconi 	BPF_XDP_CPUMAP,
958e9ddbb77SJakub Sitnicki 	BPF_SK_LOOKUP,
959aa8d3a71SAndrii Nakryiko 	BPF_XDP,
9600e33661dSDaniel Mack 	__MAX_BPF_ATTACH_TYPE
9610e33661dSDaniel Mack };
9620e33661dSDaniel Mack 
9630e33661dSDaniel Mack #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
9640e33661dSDaniel Mack 
965f2e10bffSAndrii Nakryiko enum bpf_link_type {
966f2e10bffSAndrii Nakryiko 	BPF_LINK_TYPE_UNSPEC = 0,
967f2e10bffSAndrii Nakryiko 	BPF_LINK_TYPE_RAW_TRACEPOINT = 1,
968f2e10bffSAndrii Nakryiko 	BPF_LINK_TYPE_TRACING = 2,
969f2e10bffSAndrii Nakryiko 	BPF_LINK_TYPE_CGROUP = 3,
970de4e05caSYonghong Song 	BPF_LINK_TYPE_ITER = 4,
9717f045a49SJakub Sitnicki 	BPF_LINK_TYPE_NETNS = 5,
972aa8d3a71SAndrii Nakryiko 	BPF_LINK_TYPE_XDP = 6,
973f2e10bffSAndrii Nakryiko 
974f2e10bffSAndrii Nakryiko 	MAX_BPF_LINK_TYPE,
975f2e10bffSAndrii Nakryiko };
976f2e10bffSAndrii Nakryiko 
977324bda9eSAlexei Starovoitov /* cgroup-bpf attach flags used in BPF_PROG_ATTACH command
978324bda9eSAlexei Starovoitov  *
979324bda9eSAlexei Starovoitov  * NONE(default): No further bpf programs allowed in the subtree.
980324bda9eSAlexei Starovoitov  *
981324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_OVERRIDE: If a sub-cgroup installs some bpf program,
982324bda9eSAlexei Starovoitov  * the program in this cgroup yields to sub-cgroup program.
983324bda9eSAlexei Starovoitov  *
984324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_MULTI: If a sub-cgroup installs some bpf program,
985324bda9eSAlexei Starovoitov  * that cgroup program gets run in addition to the program in this cgroup.
986324bda9eSAlexei Starovoitov  *
987324bda9eSAlexei Starovoitov  * Only one program is allowed to be attached to a cgroup with
988324bda9eSAlexei Starovoitov  * NONE or BPF_F_ALLOW_OVERRIDE flag.
989324bda9eSAlexei Starovoitov  * Attaching another program on top of NONE or BPF_F_ALLOW_OVERRIDE will
990324bda9eSAlexei Starovoitov  * release old program and attach the new one. Attach flags has to match.
991324bda9eSAlexei Starovoitov  *
992324bda9eSAlexei Starovoitov  * Multiple programs are allowed to be attached to a cgroup with
993324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_MULTI flag. They are executed in FIFO order
994324bda9eSAlexei Starovoitov  * (those that were attached first, run first)
995324bda9eSAlexei Starovoitov  * The programs of sub-cgroup are executed first, then programs of
996324bda9eSAlexei Starovoitov  * this cgroup and then programs of parent cgroup.
997324bda9eSAlexei Starovoitov  * When children program makes decision (like picking TCP CA or sock bind)
998324bda9eSAlexei Starovoitov  * parent program has a chance to override it.
999324bda9eSAlexei Starovoitov  *
10007dd68b32SAndrey Ignatov  * With BPF_F_ALLOW_MULTI a new program is added to the end of the list of
10017dd68b32SAndrey Ignatov  * programs for a cgroup. Though it's possible to replace an old program at
10027dd68b32SAndrey Ignatov  * any position by also specifying BPF_F_REPLACE flag and position itself in
10037dd68b32SAndrey Ignatov  * replace_bpf_fd attribute. Old program at this position will be released.
10047dd68b32SAndrey Ignatov  *
1005324bda9eSAlexei Starovoitov  * A cgroup with MULTI or OVERRIDE flag allows any attach flags in sub-cgroups.
1006324bda9eSAlexei Starovoitov  * A cgroup with NONE doesn't allow any programs in sub-cgroups.
1007324bda9eSAlexei Starovoitov  * Ex1:
1008324bda9eSAlexei Starovoitov  * cgrp1 (MULTI progs A, B) ->
1009324bda9eSAlexei Starovoitov  *    cgrp2 (OVERRIDE prog C) ->
1010324bda9eSAlexei Starovoitov  *      cgrp3 (MULTI prog D) ->
1011324bda9eSAlexei Starovoitov  *        cgrp4 (OVERRIDE prog E) ->
1012324bda9eSAlexei Starovoitov  *          cgrp5 (NONE prog F)
1013324bda9eSAlexei Starovoitov  * the event in cgrp5 triggers execution of F,D,A,B in that order.
1014324bda9eSAlexei Starovoitov  * if prog F is detached, the execution is E,D,A,B
1015324bda9eSAlexei Starovoitov  * if prog F and D are detached, the execution is E,A,B
1016324bda9eSAlexei Starovoitov  * if prog F, E and D are detached, the execution is C,A,B
1017324bda9eSAlexei Starovoitov  *
1018324bda9eSAlexei Starovoitov  * All eligible programs are executed regardless of return code from
1019324bda9eSAlexei Starovoitov  * earlier programs.
10207f677633SAlexei Starovoitov  */
10217f677633SAlexei Starovoitov #define BPF_F_ALLOW_OVERRIDE	(1U << 0)
1022324bda9eSAlexei Starovoitov #define BPF_F_ALLOW_MULTI	(1U << 1)
10237dd68b32SAndrey Ignatov #define BPF_F_REPLACE		(1U << 2)
10247f677633SAlexei Starovoitov 
1025e07b98d9SDavid S. Miller /* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the
1026e07b98d9SDavid S. Miller  * verifier will perform strict alignment checking as if the kernel
1027e07b98d9SDavid S. Miller  * has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set,
1028e07b98d9SDavid S. Miller  * and NET_IP_ALIGN defined to 2.
1029e07b98d9SDavid S. Miller  */
1030e07b98d9SDavid S. Miller #define BPF_F_STRICT_ALIGNMENT	(1U << 0)
1031e07b98d9SDavid S. Miller 
1032e9ee9efcSDavid Miller /* If BPF_F_ANY_ALIGNMENT is used in BPF_PROF_LOAD command, the
1033e9ee9efcSDavid Miller  * verifier will allow any alignment whatsoever.  On platforms
1034e9ee9efcSDavid Miller  * with strict alignment requirements for loads ands stores (such
1035e9ee9efcSDavid Miller  * as sparc and mips) the verifier validates that all loads and
1036e9ee9efcSDavid Miller  * stores provably follow this requirement.  This flag turns that
1037e9ee9efcSDavid Miller  * checking and enforcement off.
1038e9ee9efcSDavid Miller  *
1039e9ee9efcSDavid Miller  * It is mostly used for testing when we want to validate the
1040e9ee9efcSDavid Miller  * context and memory access aspects of the verifier, but because
1041e9ee9efcSDavid Miller  * of an unaligned access the alignment check would trigger before
1042e9ee9efcSDavid Miller  * the one we are interested in.
1043e9ee9efcSDavid Miller  */
1044e9ee9efcSDavid Miller #define BPF_F_ANY_ALIGNMENT	(1U << 1)
1045e9ee9efcSDavid Miller 
1046c240eff6SJiong Wang /* BPF_F_TEST_RND_HI32 is used in BPF_PROG_LOAD command for testing purpose.
1047c240eff6SJiong Wang  * Verifier does sub-register def/use analysis and identifies instructions whose
1048c240eff6SJiong Wang  * def only matters for low 32-bit, high 32-bit is never referenced later
1049c240eff6SJiong Wang  * through implicit zero extension. Therefore verifier notifies JIT back-ends
1050c240eff6SJiong Wang  * that it is safe to ignore clearing high 32-bit for these instructions. This
1051c240eff6SJiong Wang  * saves some back-ends a lot of code-gen. However such optimization is not
1052c240eff6SJiong Wang  * necessary on some arches, for example x86_64, arm64 etc, whose JIT back-ends
1053c240eff6SJiong Wang  * hence hasn't used verifier's analysis result. But, we really want to have a
1054c240eff6SJiong Wang  * way to be able to verify the correctness of the described optimization on
1055c240eff6SJiong Wang  * x86_64 on which testsuites are frequently exercised.
1056c240eff6SJiong Wang  *
1057c240eff6SJiong Wang  * So, this flag is introduced. Once it is set, verifier will randomize high
1058c240eff6SJiong Wang  * 32-bit for those instructions who has been identified as safe to ignore them.
1059c240eff6SJiong Wang  * Then, if verifier is not doing correct analysis, such randomization will
1060c240eff6SJiong Wang  * regress tests to expose bugs.
1061c240eff6SJiong Wang  */
1062c240eff6SJiong Wang #define BPF_F_TEST_RND_HI32	(1U << 2)
1063c240eff6SJiong Wang 
106410d274e8SAlexei Starovoitov /* The verifier internal test flag. Behavior is undefined */
106510d274e8SAlexei Starovoitov #define BPF_F_TEST_STATE_FREQ	(1U << 3)
106610d274e8SAlexei Starovoitov 
10671e6c62a8SAlexei Starovoitov /* If BPF_F_SLEEPABLE is used in BPF_PROG_LOAD command, the verifier will
10681e6c62a8SAlexei Starovoitov  * restrict map and helper usage for such programs. Sleepable BPF programs can
10691e6c62a8SAlexei Starovoitov  * only be attached to hooks where kernel execution context allows sleeping.
10701e6c62a8SAlexei Starovoitov  * Such programs are allowed to use helpers that may sleep like
10711e6c62a8SAlexei Starovoitov  * bpf_copy_from_user().
10721e6c62a8SAlexei Starovoitov  */
10731e6c62a8SAlexei Starovoitov #define BPF_F_SLEEPABLE		(1U << 4)
10741e6c62a8SAlexei Starovoitov 
1075d8eca5bbSDaniel Borkmann /* When BPF ldimm64's insn[0].src_reg != 0 then this can have
10764976b718SHao Luo  * the following extensions:
1077d8eca5bbSDaniel Borkmann  *
10784976b718SHao Luo  * insn[0].src_reg:  BPF_PSEUDO_MAP_FD
10794976b718SHao Luo  * insn[0].imm:      map fd
10804976b718SHao Luo  * insn[1].imm:      0
10814976b718SHao Luo  * insn[0].off:      0
10824976b718SHao Luo  * insn[1].off:      0
10834976b718SHao Luo  * ldimm64 rewrite:  address of map
10844976b718SHao Luo  * verifier type:    CONST_PTR_TO_MAP
1085d8eca5bbSDaniel Borkmann  */
1086f1a66f85SDaniel Borkmann #define BPF_PSEUDO_MAP_FD	1
10874976b718SHao Luo /* insn[0].src_reg:  BPF_PSEUDO_MAP_VALUE
10884976b718SHao Luo  * insn[0].imm:      map fd
10894976b718SHao Luo  * insn[1].imm:      offset into value
10904976b718SHao Luo  * insn[0].off:      0
10914976b718SHao Luo  * insn[1].off:      0
10924976b718SHao Luo  * ldimm64 rewrite:  address of map[0]+offset
10934976b718SHao Luo  * verifier type:    PTR_TO_MAP_VALUE
10944976b718SHao Luo  */
1095d8eca5bbSDaniel Borkmann #define BPF_PSEUDO_MAP_VALUE	2
10964976b718SHao Luo /* insn[0].src_reg:  BPF_PSEUDO_BTF_ID
10974976b718SHao Luo  * insn[0].imm:      kernel btd id of VAR
10984976b718SHao Luo  * insn[1].imm:      0
10994976b718SHao Luo  * insn[0].off:      0
11004976b718SHao Luo  * insn[1].off:      0
11014976b718SHao Luo  * ldimm64 rewrite:  address of the kernel variable
11024976b718SHao Luo  * verifier type:    PTR_TO_BTF_ID or PTR_TO_MEM, depending on whether the var
11034976b718SHao Luo  *                   is struct/union.
11044976b718SHao Luo  */
11054976b718SHao Luo #define BPF_PSEUDO_BTF_ID	3
110669c087baSYonghong Song /* insn[0].src_reg:  BPF_PSEUDO_FUNC
110769c087baSYonghong Song  * insn[0].imm:      insn offset to the func
110869c087baSYonghong Song  * insn[1].imm:      0
110969c087baSYonghong Song  * insn[0].off:      0
111069c087baSYonghong Song  * insn[1].off:      0
111169c087baSYonghong Song  * ldimm64 rewrite:  address of the function
111269c087baSYonghong Song  * verifier type:    PTR_TO_FUNC.
111369c087baSYonghong Song  */
111469c087baSYonghong Song #define BPF_PSEUDO_FUNC		4
1115f1a66f85SDaniel Borkmann 
1116cc8b0b92SAlexei Starovoitov /* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative
1117cc8b0b92SAlexei Starovoitov  * offset to another bpf function
1118cc8b0b92SAlexei Starovoitov  */
1119cc8b0b92SAlexei Starovoitov #define BPF_PSEUDO_CALL		1
1120cc8b0b92SAlexei Starovoitov 
11213274f520SAlexei Starovoitov /* flags for BPF_MAP_UPDATE_ELEM command */
11221aae4bddSAndrii Nakryiko enum {
11231aae4bddSAndrii Nakryiko 	BPF_ANY		= 0, /* create new element or update existing */
11241aae4bddSAndrii Nakryiko 	BPF_NOEXIST	= 1, /* create new element if it didn't exist */
11251aae4bddSAndrii Nakryiko 	BPF_EXIST	= 2, /* update existing element */
11261aae4bddSAndrii Nakryiko 	BPF_F_LOCK	= 4, /* spin_lock-ed map_lookup/map_update */
11271aae4bddSAndrii Nakryiko };
11283274f520SAlexei Starovoitov 
112996eabe7aSMartin KaFai Lau /* flags for BPF_MAP_CREATE command */
11301aae4bddSAndrii Nakryiko enum {
11311aae4bddSAndrii Nakryiko 	BPF_F_NO_PREALLOC	= (1U << 0),
113229ba732aSMartin KaFai Lau /* Instead of having one common LRU list in the
11338f844938SMartin KaFai Lau  * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list
113429ba732aSMartin KaFai Lau  * which can scale and perform better.
113529ba732aSMartin KaFai Lau  * Note, the LRU nodes (including free nodes) cannot be moved
113629ba732aSMartin KaFai Lau  * across different LRU lists.
113729ba732aSMartin KaFai Lau  */
11381aae4bddSAndrii Nakryiko 	BPF_F_NO_COMMON_LRU	= (1U << 1),
113996eabe7aSMartin KaFai Lau /* Specify numa node during map creation */
11401aae4bddSAndrii Nakryiko 	BPF_F_NUMA_NODE		= (1U << 2),
1141cb4d2b3fSMartin KaFai Lau 
1142591fe988SDaniel Borkmann /* Flags for accessing BPF object from syscall side. */
11431aae4bddSAndrii Nakryiko 	BPF_F_RDONLY		= (1U << 3),
11441aae4bddSAndrii Nakryiko 	BPF_F_WRONLY		= (1U << 4),
11456e71b04aSChenbo Feng 
1146615755a7SSong Liu /* Flag for stack_map, store build_id+offset instead of pointer */
11471aae4bddSAndrii Nakryiko 	BPF_F_STACK_BUILD_ID	= (1U << 5),
1148615755a7SSong Liu 
114996b3b6c9SLorenz Bauer /* Zero-initialize hash function seed. This should only be used for testing. */
11501aae4bddSAndrii Nakryiko 	BPF_F_ZERO_SEED		= (1U << 6),
115196b3b6c9SLorenz Bauer 
1152591fe988SDaniel Borkmann /* Flags for accessing BPF object from program side. */
11531aae4bddSAndrii Nakryiko 	BPF_F_RDONLY_PROG	= (1U << 7),
11541aae4bddSAndrii Nakryiko 	BPF_F_WRONLY_PROG	= (1U << 8),
1155591fe988SDaniel Borkmann 
11568f51dfc7SStanislav Fomichev /* Clone map from listener for newly accepted socket */
11571aae4bddSAndrii Nakryiko 	BPF_F_CLONE		= (1U << 9),
11588f51dfc7SStanislav Fomichev 
1159fc970227SAndrii Nakryiko /* Enable memory-mapping BPF map */
11601aae4bddSAndrii Nakryiko 	BPF_F_MMAPABLE		= (1U << 10),
1161792cacccSSong Liu 
1162792cacccSSong Liu /* Share perf_event among processes */
1163792cacccSSong Liu 	BPF_F_PRESERVE_ELEMS	= (1U << 11),
11644a8f87e6SDaniel Borkmann 
11654a8f87e6SDaniel Borkmann /* Create a map that is suitable to be an inner map with dynamic max entries */
11664a8f87e6SDaniel Borkmann 	BPF_F_INNER_MAP		= (1U << 12),
11671aae4bddSAndrii Nakryiko };
1168fc970227SAndrii Nakryiko 
1169f5bfcd95SAndrey Ignatov /* Flags for BPF_PROG_QUERY. */
1170f5bfcd95SAndrey Ignatov 
1171f5bfcd95SAndrey Ignatov /* Query effective (directly attached + inherited from ancestor cgroups)
1172f5bfcd95SAndrey Ignatov  * programs that will be executed for events within a cgroup.
1173f5bfcd95SAndrey Ignatov  * attach_flags with this flag are returned only for directly attached programs.
1174f5bfcd95SAndrey Ignatov  */
11752f183360SLorenz Bauer #define BPF_F_QUERY_EFFECTIVE	(1U << 0)
11762f183360SLorenz Bauer 
11771b4d60ecSSong Liu /* Flags for BPF_PROG_TEST_RUN */
11781b4d60ecSSong Liu 
11791b4d60ecSSong Liu /* If set, run the test on the cpu specified by bpf_attr.test.cpu */
11801b4d60ecSSong Liu #define BPF_F_TEST_RUN_ON_CPU	(1U << 0)
11811b4d60ecSSong Liu 
1182d46edd67SSong Liu /* type for BPF_ENABLE_STATS */
1183d46edd67SSong Liu enum bpf_stats_type {
1184d46edd67SSong Liu 	/* enabled run_time_ns and run_cnt */
1185d46edd67SSong Liu 	BPF_STATS_RUN_TIME = 0,
1186d46edd67SSong Liu };
1187d46edd67SSong Liu 
1188615755a7SSong Liu enum bpf_stack_build_id_status {
1189615755a7SSong Liu 	/* user space need an empty entry to identify end of a trace */
1190615755a7SSong Liu 	BPF_STACK_BUILD_ID_EMPTY = 0,
1191615755a7SSong Liu 	/* with valid build_id and offset */
1192615755a7SSong Liu 	BPF_STACK_BUILD_ID_VALID = 1,
1193615755a7SSong Liu 	/* couldn't get build_id, fallback to ip */
1194615755a7SSong Liu 	BPF_STACK_BUILD_ID_IP = 2,
1195615755a7SSong Liu };
1196615755a7SSong Liu 
1197615755a7SSong Liu #define BPF_BUILD_ID_SIZE 20
1198615755a7SSong Liu struct bpf_stack_build_id {
1199615755a7SSong Liu 	__s32		status;
1200615755a7SSong Liu 	unsigned char	build_id[BPF_BUILD_ID_SIZE];
1201615755a7SSong Liu 	union {
1202615755a7SSong Liu 		__u64	offset;
1203615755a7SSong Liu 		__u64	ip;
1204615755a7SSong Liu 	};
1205615755a7SSong Liu };
1206615755a7SSong Liu 
12071aae4bddSAndrii Nakryiko #define BPF_OBJ_NAME_LEN 16U
12081aae4bddSAndrii Nakryiko 
120999c55f7dSAlexei Starovoitov union bpf_attr {
121099c55f7dSAlexei Starovoitov 	struct { /* anonymous struct used by BPF_MAP_CREATE command */
121199c55f7dSAlexei Starovoitov 		__u32	map_type;	/* one of enum bpf_map_type */
121299c55f7dSAlexei Starovoitov 		__u32	key_size;	/* size of key in bytes */
121399c55f7dSAlexei Starovoitov 		__u32	value_size;	/* size of value in bytes */
121499c55f7dSAlexei Starovoitov 		__u32	max_entries;	/* max number of entries in a map */
121596eabe7aSMartin KaFai Lau 		__u32	map_flags;	/* BPF_MAP_CREATE related
121696eabe7aSMartin KaFai Lau 					 * flags defined above.
121796eabe7aSMartin KaFai Lau 					 */
121856f668dfSMartin KaFai Lau 		__u32	inner_map_fd;	/* fd pointing to the inner map */
121996eabe7aSMartin KaFai Lau 		__u32	numa_node;	/* numa node (effective only if
122096eabe7aSMartin KaFai Lau 					 * BPF_F_NUMA_NODE is set).
122196eabe7aSMartin KaFai Lau 					 */
1222067cae47SMartin KaFai Lau 		char	map_name[BPF_OBJ_NAME_LEN];
1223a3884572SJakub Kicinski 		__u32	map_ifindex;	/* ifindex of netdev to create on */
1224a26ca7c9SMartin KaFai Lau 		__u32	btf_fd;		/* fd pointing to a BTF type data */
12259b2cf328SMartin KaFai Lau 		__u32	btf_key_type_id;	/* BTF type_id of the key */
12269b2cf328SMartin KaFai Lau 		__u32	btf_value_type_id;	/* BTF type_id of the value */
122785d33df3SMartin KaFai Lau 		__u32	btf_vmlinux_value_type_id;/* BTF type_id of a kernel-
122885d33df3SMartin KaFai Lau 						   * struct stored as the
122985d33df3SMartin KaFai Lau 						   * map value
123085d33df3SMartin KaFai Lau 						   */
123199c55f7dSAlexei Starovoitov 	};
1232db20fd2bSAlexei Starovoitov 
1233db20fd2bSAlexei Starovoitov 	struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
1234db20fd2bSAlexei Starovoitov 		__u32		map_fd;
1235db20fd2bSAlexei Starovoitov 		__aligned_u64	key;
1236db20fd2bSAlexei Starovoitov 		union {
1237db20fd2bSAlexei Starovoitov 			__aligned_u64 value;
1238db20fd2bSAlexei Starovoitov 			__aligned_u64 next_key;
1239db20fd2bSAlexei Starovoitov 		};
12403274f520SAlexei Starovoitov 		__u64		flags;
1241db20fd2bSAlexei Starovoitov 	};
124209756af4SAlexei Starovoitov 
1243cb4d03abSBrian Vazquez 	struct { /* struct used by BPF_MAP_*_BATCH commands */
1244cb4d03abSBrian Vazquez 		__aligned_u64	in_batch;	/* start batch,
1245cb4d03abSBrian Vazquez 						 * NULL to start from beginning
1246cb4d03abSBrian Vazquez 						 */
1247cb4d03abSBrian Vazquez 		__aligned_u64	out_batch;	/* output: next start batch */
1248cb4d03abSBrian Vazquez 		__aligned_u64	keys;
1249cb4d03abSBrian Vazquez 		__aligned_u64	values;
1250cb4d03abSBrian Vazquez 		__u32		count;		/* input/output:
1251cb4d03abSBrian Vazquez 						 * input: # of key/value
1252cb4d03abSBrian Vazquez 						 * elements
1253cb4d03abSBrian Vazquez 						 * output: # of filled elements
1254cb4d03abSBrian Vazquez 						 */
1255cb4d03abSBrian Vazquez 		__u32		map_fd;
1256cb4d03abSBrian Vazquez 		__u64		elem_flags;
1257cb4d03abSBrian Vazquez 		__u64		flags;
1258cb4d03abSBrian Vazquez 	} batch;
1259cb4d03abSBrian Vazquez 
126009756af4SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_LOAD command */
126109756af4SAlexei Starovoitov 		__u32		prog_type;	/* one of enum bpf_prog_type */
126209756af4SAlexei Starovoitov 		__u32		insn_cnt;
126309756af4SAlexei Starovoitov 		__aligned_u64	insns;
126409756af4SAlexei Starovoitov 		__aligned_u64	license;
1265cbd35700SAlexei Starovoitov 		__u32		log_level;	/* verbosity level of verifier */
1266cbd35700SAlexei Starovoitov 		__u32		log_size;	/* size of user buffer */
1267cbd35700SAlexei Starovoitov 		__aligned_u64	log_buf;	/* user supplied buffer */
12686c4fc209SDaniel Borkmann 		__u32		kern_version;	/* not used */
1269e07b98d9SDavid S. Miller 		__u32		prog_flags;
1270067cae47SMartin KaFai Lau 		char		prog_name[BPF_OBJ_NAME_LEN];
12711f6f4cb7SJakub Kicinski 		__u32		prog_ifindex;	/* ifindex of netdev to prep for */
12725e43f899SAndrey Ignatov 		/* For some prog types expected attach type must be known at
12735e43f899SAndrey Ignatov 		 * load time to verify attach type specific parts of prog
12745e43f899SAndrey Ignatov 		 * (context accesses, allowed helpers, etc).
12755e43f899SAndrey Ignatov 		 */
12765e43f899SAndrey Ignatov 		__u32		expected_attach_type;
1277838e9690SYonghong Song 		__u32		prog_btf_fd;	/* fd pointing to BTF type data */
1278838e9690SYonghong Song 		__u32		func_info_rec_size;	/* userspace bpf_func_info size */
1279838e9690SYonghong Song 		__aligned_u64	func_info;	/* func info */
1280838e9690SYonghong Song 		__u32		func_info_cnt;	/* number of bpf_func_info records */
1281c454a46bSMartin KaFai Lau 		__u32		line_info_rec_size;	/* userspace bpf_line_info size */
1282c454a46bSMartin KaFai Lau 		__aligned_u64	line_info;	/* line info */
1283c454a46bSMartin KaFai Lau 		__u32		line_info_cnt;	/* number of bpf_line_info records */
1284ccfe29ebSAlexei Starovoitov 		__u32		attach_btf_id;	/* in-kernel BTF type id to attach to */
1285290248a5SAndrii Nakryiko 		union {
1286290248a5SAndrii Nakryiko 			/* valid prog_fd to attach to bpf prog */
1287290248a5SAndrii Nakryiko 			__u32		attach_prog_fd;
1288290248a5SAndrii Nakryiko 			/* or valid module BTF object fd or 0 to attach to vmlinux */
1289290248a5SAndrii Nakryiko 			__u32		attach_btf_obj_fd;
1290290248a5SAndrii Nakryiko 		};
129109756af4SAlexei Starovoitov 	};
1292b2197755SDaniel Borkmann 
1293b2197755SDaniel Borkmann 	struct { /* anonymous struct used by BPF_OBJ_* commands */
1294b2197755SDaniel Borkmann 		__aligned_u64	pathname;
1295b2197755SDaniel Borkmann 		__u32		bpf_fd;
12966e71b04aSChenbo Feng 		__u32		file_flags;
1297b2197755SDaniel Borkmann 	};
1298f4324551SDaniel Mack 
1299f4324551SDaniel Mack 	struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
1300f4324551SDaniel Mack 		__u32		target_fd;	/* container object to attach to */
1301f4324551SDaniel Mack 		__u32		attach_bpf_fd;	/* eBPF program to attach */
1302f4324551SDaniel Mack 		__u32		attach_type;
13037f677633SAlexei Starovoitov 		__u32		attach_flags;
13047dd68b32SAndrey Ignatov 		__u32		replace_bpf_fd;	/* previously attached eBPF
13057dd68b32SAndrey Ignatov 						 * program to replace if
13067dd68b32SAndrey Ignatov 						 * BPF_F_REPLACE is used
13077dd68b32SAndrey Ignatov 						 */
1308f4324551SDaniel Mack 	};
13091cf1cae9SAlexei Starovoitov 
13101cf1cae9SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
13111cf1cae9SAlexei Starovoitov 		__u32		prog_fd;
13121cf1cae9SAlexei Starovoitov 		__u32		retval;
1313b5a36b1eSLorenz Bauer 		__u32		data_size_in;	/* input: len of data_in */
1314b5a36b1eSLorenz Bauer 		__u32		data_size_out;	/* input/output: len of data_out
1315b5a36b1eSLorenz Bauer 						 *   returns ENOSPC if data_out
1316b5a36b1eSLorenz Bauer 						 *   is too small.
1317b5a36b1eSLorenz Bauer 						 */
13181cf1cae9SAlexei Starovoitov 		__aligned_u64	data_in;
13191cf1cae9SAlexei Starovoitov 		__aligned_u64	data_out;
13201cf1cae9SAlexei Starovoitov 		__u32		repeat;
13211cf1cae9SAlexei Starovoitov 		__u32		duration;
1322b0b9395dSStanislav Fomichev 		__u32		ctx_size_in;	/* input: len of ctx_in */
1323b0b9395dSStanislav Fomichev 		__u32		ctx_size_out;	/* input/output: len of ctx_out
1324b0b9395dSStanislav Fomichev 						 *   returns ENOSPC if ctx_out
1325b0b9395dSStanislav Fomichev 						 *   is too small.
1326b0b9395dSStanislav Fomichev 						 */
1327b0b9395dSStanislav Fomichev 		__aligned_u64	ctx_in;
1328b0b9395dSStanislav Fomichev 		__aligned_u64	ctx_out;
13291b4d60ecSSong Liu 		__u32		flags;
13301b4d60ecSSong Liu 		__u32		cpu;
13311cf1cae9SAlexei Starovoitov 	} test;
133234ad5580SMartin KaFai Lau 
1333b16d9aa4SMartin KaFai Lau 	struct { /* anonymous struct used by BPF_*_GET_*_ID */
1334b16d9aa4SMartin KaFai Lau 		union {
133534ad5580SMartin KaFai Lau 			__u32		start_id;
1336b16d9aa4SMartin KaFai Lau 			__u32		prog_id;
1337bd5f5f4eSMartin KaFai Lau 			__u32		map_id;
133878958fcaSMartin KaFai Lau 			__u32		btf_id;
1339a3b80e10SAndrii Nakryiko 			__u32		link_id;
1340b16d9aa4SMartin KaFai Lau 		};
134134ad5580SMartin KaFai Lau 		__u32		next_id;
13426e71b04aSChenbo Feng 		__u32		open_flags;
134334ad5580SMartin KaFai Lau 	};
13441e270976SMartin KaFai Lau 
13451e270976SMartin KaFai Lau 	struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
13461e270976SMartin KaFai Lau 		__u32		bpf_fd;
13471e270976SMartin KaFai Lau 		__u32		info_len;
13481e270976SMartin KaFai Lau 		__aligned_u64	info;
13491e270976SMartin KaFai Lau 	} info;
1350468e2f64SAlexei Starovoitov 
1351468e2f64SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_QUERY command */
1352468e2f64SAlexei Starovoitov 		__u32		target_fd;	/* container object to query */
1353468e2f64SAlexei Starovoitov 		__u32		attach_type;
1354468e2f64SAlexei Starovoitov 		__u32		query_flags;
1355468e2f64SAlexei Starovoitov 		__u32		attach_flags;
1356468e2f64SAlexei Starovoitov 		__aligned_u64	prog_ids;
1357468e2f64SAlexei Starovoitov 		__u32		prog_cnt;
1358468e2f64SAlexei Starovoitov 	} query;
1359c4f6699dSAlexei Starovoitov 
1360af6eea57SAndrii Nakryiko 	struct { /* anonymous struct used by BPF_RAW_TRACEPOINT_OPEN command */
1361c4f6699dSAlexei Starovoitov 		__u64 name;
1362c4f6699dSAlexei Starovoitov 		__u32 prog_fd;
1363c4f6699dSAlexei Starovoitov 	} raw_tracepoint;
1364f56a653cSMartin KaFai Lau 
1365f56a653cSMartin KaFai Lau 	struct { /* anonymous struct for BPF_BTF_LOAD */
1366f56a653cSMartin KaFai Lau 		__aligned_u64	btf;
1367f56a653cSMartin KaFai Lau 		__aligned_u64	btf_log_buf;
1368f56a653cSMartin KaFai Lau 		__u32		btf_size;
1369f56a653cSMartin KaFai Lau 		__u32		btf_log_size;
1370f56a653cSMartin KaFai Lau 		__u32		btf_log_level;
1371f56a653cSMartin KaFai Lau 	};
137241bdc4b4SYonghong Song 
137341bdc4b4SYonghong Song 	struct {
137441bdc4b4SYonghong Song 		__u32		pid;		/* input: pid */
137541bdc4b4SYonghong Song 		__u32		fd;		/* input: fd */
137641bdc4b4SYonghong Song 		__u32		flags;		/* input: flags */
137741bdc4b4SYonghong Song 		__u32		buf_len;	/* input/output: buf len */
137841bdc4b4SYonghong Song 		__aligned_u64	buf;		/* input/output:
137941bdc4b4SYonghong Song 						 *   tp_name for tracepoint
138041bdc4b4SYonghong Song 						 *   symbol for kprobe
138141bdc4b4SYonghong Song 						 *   filename for uprobe
138241bdc4b4SYonghong Song 						 */
138341bdc4b4SYonghong Song 		__u32		prog_id;	/* output: prod_id */
138441bdc4b4SYonghong Song 		__u32		fd_type;	/* output: BPF_FD_TYPE_* */
138541bdc4b4SYonghong Song 		__u64		probe_offset;	/* output: probe_offset */
138641bdc4b4SYonghong Song 		__u64		probe_addr;	/* output: probe_addr */
138741bdc4b4SYonghong Song 	} task_fd_query;
1388af6eea57SAndrii Nakryiko 
1389af6eea57SAndrii Nakryiko 	struct { /* struct used by BPF_LINK_CREATE command */
1390af6eea57SAndrii Nakryiko 		__u32		prog_fd;	/* eBPF program to attach */
1391aa8d3a71SAndrii Nakryiko 		union {
1392af6eea57SAndrii Nakryiko 			__u32		target_fd;	/* object to attach to */
1393aa8d3a71SAndrii Nakryiko 			__u32		target_ifindex; /* target ifindex */
1394aa8d3a71SAndrii Nakryiko 		};
1395af6eea57SAndrii Nakryiko 		__u32		attach_type;	/* attach type */
1396af6eea57SAndrii Nakryiko 		__u32		flags;		/* extra flags */
13974a1e7c0cSToke Høiland-Jørgensen 		union {
13984a1e7c0cSToke Høiland-Jørgensen 			__u32		target_btf_id;	/* btf_id of target to attach to */
13994a1e7c0cSToke Høiland-Jørgensen 			struct {
14005e7b3020SYonghong Song 				__aligned_u64	iter_info;	/* extra bpf_iter_link_info */
14015e7b3020SYonghong Song 				__u32		iter_info_len;	/* iter_info length */
14024a1e7c0cSToke Høiland-Jørgensen 			};
14034a1e7c0cSToke Høiland-Jørgensen 		};
1404af6eea57SAndrii Nakryiko 	} link_create;
14050c991ebcSAndrii Nakryiko 
14060c991ebcSAndrii Nakryiko 	struct { /* struct used by BPF_LINK_UPDATE command */
14070c991ebcSAndrii Nakryiko 		__u32		link_fd;	/* link fd */
14080c991ebcSAndrii Nakryiko 		/* new program fd to update link with */
14090c991ebcSAndrii Nakryiko 		__u32		new_prog_fd;
14100c991ebcSAndrii Nakryiko 		__u32		flags;		/* extra flags */
14110c991ebcSAndrii Nakryiko 		/* expected link's program fd; is specified only if
14120c991ebcSAndrii Nakryiko 		 * BPF_F_REPLACE flag is set in flags */
14130c991ebcSAndrii Nakryiko 		__u32		old_prog_fd;
14140c991ebcSAndrii Nakryiko 	} link_update;
14150c991ebcSAndrii Nakryiko 
141673b11c2aSAndrii Nakryiko 	struct {
141773b11c2aSAndrii Nakryiko 		__u32		link_fd;
141873b11c2aSAndrii Nakryiko 	} link_detach;
141973b11c2aSAndrii Nakryiko 
1420d46edd67SSong Liu 	struct { /* struct used by BPF_ENABLE_STATS command */
1421d46edd67SSong Liu 		__u32		type;
1422d46edd67SSong Liu 	} enable_stats;
1423d46edd67SSong Liu 
1424ac51d99bSYonghong Song 	struct { /* struct used by BPF_ITER_CREATE command */
1425ac51d99bSYonghong Song 		__u32		link_fd;
1426ac51d99bSYonghong Song 		__u32		flags;
1427ac51d99bSYonghong Song 	} iter_create;
1428ac51d99bSYonghong Song 
1429ef15314aSYiFei Zhu 	struct { /* struct used by BPF_PROG_BIND_MAP command */
1430ef15314aSYiFei Zhu 		__u32		prog_fd;
1431ef15314aSYiFei Zhu 		__u32		map_fd;
1432ef15314aSYiFei Zhu 		__u32		flags;		/* extra flags */
1433ef15314aSYiFei Zhu 	} prog_bind_map;
1434ef15314aSYiFei Zhu 
143599c55f7dSAlexei Starovoitov } __attribute__((aligned(8)));
143699c55f7dSAlexei Starovoitov 
143756a092c8SQuentin Monnet /* The description below is an attempt at providing documentation to eBPF
143856a092c8SQuentin Monnet  * developers about the multiple available eBPF helper functions. It can be
143956a092c8SQuentin Monnet  * parsed and used to produce a manual page. The workflow is the following,
144056a092c8SQuentin Monnet  * and requires the rst2man utility:
1441ebb676daSThomas Graf  *
144256a092c8SQuentin Monnet  *     $ ./scripts/bpf_helpers_doc.py \
144356a092c8SQuentin Monnet  *             --filename include/uapi/linux/bpf.h > /tmp/bpf-helpers.rst
144456a092c8SQuentin Monnet  *     $ rst2man /tmp/bpf-helpers.rst > /tmp/bpf-helpers.7
144556a092c8SQuentin Monnet  *     $ man /tmp/bpf-helpers.7
1446ebb676daSThomas Graf  *
144756a092c8SQuentin Monnet  * Note that in order to produce this external documentation, some RST
144856a092c8SQuentin Monnet  * formatting is used in the descriptions to get "bold" and "italics" in
144956a092c8SQuentin Monnet  * manual pages. Also note that the few trailing white spaces are
145056a092c8SQuentin Monnet  * intentional, removing them would break paragraphs for rst2man.
1451ebb676daSThomas Graf  *
145256a092c8SQuentin Monnet  * Start of BPF helper function descriptions:
1453ad4a5223SQuentin Monnet  *
1454ad4a5223SQuentin Monnet  * void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)
1455ad4a5223SQuentin Monnet  * 	Description
1456ad4a5223SQuentin Monnet  * 		Perform a lookup in *map* for an entry associated to *key*.
1457ad4a5223SQuentin Monnet  * 	Return
1458ad4a5223SQuentin Monnet  * 		Map value associated to *key*, or **NULL** if no entry was
1459ad4a5223SQuentin Monnet  * 		found.
1460ad4a5223SQuentin Monnet  *
1461bdb7b79bSAndrii Nakryiko  * long bpf_map_update_elem(struct bpf_map *map, const void *key, const void *value, u64 flags)
1462ad4a5223SQuentin Monnet  * 	Description
1463ad4a5223SQuentin Monnet  * 		Add or update the value of the entry associated to *key* in
1464ad4a5223SQuentin Monnet  * 		*map* with *value*. *flags* is one of:
1465ad4a5223SQuentin Monnet  *
1466ad4a5223SQuentin Monnet  * 		**BPF_NOEXIST**
1467ad4a5223SQuentin Monnet  * 			The entry for *key* must not exist in the map.
1468ad4a5223SQuentin Monnet  * 		**BPF_EXIST**
1469ad4a5223SQuentin Monnet  * 			The entry for *key* must already exist in the map.
1470ad4a5223SQuentin Monnet  * 		**BPF_ANY**
1471ad4a5223SQuentin Monnet  * 			No condition on the existence of the entry for *key*.
1472ad4a5223SQuentin Monnet  *
1473ad4a5223SQuentin Monnet  * 		Flag value **BPF_NOEXIST** cannot be used for maps of types
1474ad4a5223SQuentin Monnet  * 		**BPF_MAP_TYPE_ARRAY** or **BPF_MAP_TYPE_PERCPU_ARRAY**  (all
1475ad4a5223SQuentin Monnet  * 		elements always exist), the helper would return an error.
1476ad4a5223SQuentin Monnet  * 	Return
1477ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1478ad4a5223SQuentin Monnet  *
1479bdb7b79bSAndrii Nakryiko  * long bpf_map_delete_elem(struct bpf_map *map, const void *key)
1480ad4a5223SQuentin Monnet  * 	Description
1481ad4a5223SQuentin Monnet  * 		Delete entry with *key* from *map*.
1482ad4a5223SQuentin Monnet  * 	Return
1483ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1484ad4a5223SQuentin Monnet  *
1485bdb7b79bSAndrii Nakryiko  * long bpf_probe_read(void *dst, u32 size, const void *unsafe_ptr)
1486ad4a5223SQuentin Monnet  * 	Description
1487ad4a5223SQuentin Monnet  * 		For tracing programs, safely attempt to read *size* bytes from
14886ae08ae3SDaniel Borkmann  * 		kernel space address *unsafe_ptr* and store the data in *dst*.
14896ae08ae3SDaniel Borkmann  *
1490ab8d7809SQuentin Monnet  * 		Generally, use **bpf_probe_read_user**\ () or
1491ab8d7809SQuentin Monnet  * 		**bpf_probe_read_kernel**\ () instead.
1492ad4a5223SQuentin Monnet  * 	Return
1493ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1494ad4a5223SQuentin Monnet  *
1495ad4a5223SQuentin Monnet  * u64 bpf_ktime_get_ns(void)
1496ad4a5223SQuentin Monnet  * 	Description
1497ad4a5223SQuentin Monnet  * 		Return the time elapsed since system boot, in nanoseconds.
149871d19214SMaciej Żenczykowski  * 		Does not include time the system was suspended.
1499ab8d7809SQuentin Monnet  * 		See: **clock_gettime**\ (**CLOCK_MONOTONIC**)
1500ad4a5223SQuentin Monnet  * 	Return
1501ad4a5223SQuentin Monnet  * 		Current *ktime*.
1502ad4a5223SQuentin Monnet  *
1503bdb7b79bSAndrii Nakryiko  * long bpf_trace_printk(const char *fmt, u32 fmt_size, ...)
1504ad4a5223SQuentin Monnet  * 	Description
1505ad4a5223SQuentin Monnet  * 		This helper is a "printk()-like" facility for debugging. It
1506ad4a5223SQuentin Monnet  * 		prints a message defined by format *fmt* (of size *fmt_size*)
1507ad4a5223SQuentin Monnet  * 		to file *\/sys/kernel/debug/tracing/trace* from DebugFS, if
1508ad4a5223SQuentin Monnet  * 		available. It can take up to three additional **u64**
1509ad4a5223SQuentin Monnet  * 		arguments (as an eBPF helpers, the total number of arguments is
1510ad4a5223SQuentin Monnet  * 		limited to five).
1511ad4a5223SQuentin Monnet  *
1512ad4a5223SQuentin Monnet  * 		Each time the helper is called, it appends a line to the trace.
151355c33dfbSPeter Wu  * 		Lines are discarded while *\/sys/kernel/debug/tracing/trace* is
151455c33dfbSPeter Wu  * 		open, use *\/sys/kernel/debug/tracing/trace_pipe* to avoid this.
1515ad4a5223SQuentin Monnet  * 		The format of the trace is customizable, and the exact output
1516ad4a5223SQuentin Monnet  * 		one will get depends on the options set in
1517ad4a5223SQuentin Monnet  * 		*\/sys/kernel/debug/tracing/trace_options* (see also the
1518ad4a5223SQuentin Monnet  * 		*README* file under the same directory). However, it usually
1519ad4a5223SQuentin Monnet  * 		defaults to something like:
1520ad4a5223SQuentin Monnet  *
1521ad4a5223SQuentin Monnet  * 		::
1522ad4a5223SQuentin Monnet  *
1523ad4a5223SQuentin Monnet  * 			telnet-470   [001] .N.. 419421.045894: 0x00000001: <formatted msg>
1524ad4a5223SQuentin Monnet  *
1525ad4a5223SQuentin Monnet  * 		In the above:
1526ad4a5223SQuentin Monnet  *
1527ad4a5223SQuentin Monnet  * 			* ``telnet`` is the name of the current task.
1528ad4a5223SQuentin Monnet  * 			* ``470`` is the PID of the current task.
1529ad4a5223SQuentin Monnet  * 			* ``001`` is the CPU number on which the task is
1530ad4a5223SQuentin Monnet  * 			  running.
1531ad4a5223SQuentin Monnet  * 			* In ``.N..``, each character refers to a set of
1532ad4a5223SQuentin Monnet  * 			  options (whether irqs are enabled, scheduling
1533ad4a5223SQuentin Monnet  * 			  options, whether hard/softirqs are running, level of
1534ad4a5223SQuentin Monnet  * 			  preempt_disabled respectively). **N** means that
1535ad4a5223SQuentin Monnet  * 			  **TIF_NEED_RESCHED** and **PREEMPT_NEED_RESCHED**
1536ad4a5223SQuentin Monnet  * 			  are set.
1537ad4a5223SQuentin Monnet  * 			* ``419421.045894`` is a timestamp.
1538ad4a5223SQuentin Monnet  * 			* ``0x00000001`` is a fake value used by BPF for the
1539ad4a5223SQuentin Monnet  * 			  instruction pointer register.
1540ad4a5223SQuentin Monnet  * 			* ``<formatted msg>`` is the message formatted with
1541ad4a5223SQuentin Monnet  * 			  *fmt*.
1542ad4a5223SQuentin Monnet  *
1543ad4a5223SQuentin Monnet  * 		The conversion specifiers supported by *fmt* are similar, but
1544ad4a5223SQuentin Monnet  * 		more limited than for printk(). They are **%d**, **%i**,
1545ad4a5223SQuentin Monnet  * 		**%u**, **%x**, **%ld**, **%li**, **%lu**, **%lx**, **%lld**,
1546ad4a5223SQuentin Monnet  * 		**%lli**, **%llu**, **%llx**, **%p**, **%s**. No modifier (size
1547ad4a5223SQuentin Monnet  * 		of field, padding with zeroes, etc.) is available, and the
1548ad4a5223SQuentin Monnet  * 		helper will return **-EINVAL** (but print nothing) if it
1549ad4a5223SQuentin Monnet  * 		encounters an unknown specifier.
1550ad4a5223SQuentin Monnet  *
1551ad4a5223SQuentin Monnet  * 		Also, note that **bpf_trace_printk**\ () is slow, and should
1552ad4a5223SQuentin Monnet  * 		only be used for debugging purposes. For this reason, a notice
1553b16fc097STobias Klauser  * 		block (spanning several lines) is printed to kernel logs and
1554ad4a5223SQuentin Monnet  * 		states that the helper should not be used "for production use"
1555ad4a5223SQuentin Monnet  * 		the first time this helper is used (or more precisely, when
1556ad4a5223SQuentin Monnet  * 		**trace_printk**\ () buffers are allocated). For passing values
1557ad4a5223SQuentin Monnet  * 		to user space, perf events should be preferred.
1558ad4a5223SQuentin Monnet  * 	Return
1559ad4a5223SQuentin Monnet  * 		The number of bytes written to the buffer, or a negative error
1560ad4a5223SQuentin Monnet  * 		in case of failure.
1561ad4a5223SQuentin Monnet  *
15621fdd08beSQuentin Monnet  * u32 bpf_get_prandom_u32(void)
15631fdd08beSQuentin Monnet  * 	Description
15641fdd08beSQuentin Monnet  * 		Get a pseudo-random number.
15651fdd08beSQuentin Monnet  *
15661fdd08beSQuentin Monnet  * 		From a security point of view, this helper uses its own
15671fdd08beSQuentin Monnet  * 		pseudo-random internal state, and cannot be used to infer the
15681fdd08beSQuentin Monnet  * 		seed of other random functions in the kernel. However, it is
15691fdd08beSQuentin Monnet  * 		essential to note that the generator used by the helper is not
15701fdd08beSQuentin Monnet  * 		cryptographically secure.
15711fdd08beSQuentin Monnet  * 	Return
15721fdd08beSQuentin Monnet  * 		A random 32-bit unsigned value.
15731fdd08beSQuentin Monnet  *
15741fdd08beSQuentin Monnet  * u32 bpf_get_smp_processor_id(void)
15751fdd08beSQuentin Monnet  * 	Description
15761fdd08beSQuentin Monnet  * 		Get the SMP (symmetric multiprocessing) processor id. Note that
15771fdd08beSQuentin Monnet  * 		all programs run with preemption disabled, which means that the
15781fdd08beSQuentin Monnet  * 		SMP processor id is stable during all the execution of the
15791fdd08beSQuentin Monnet  * 		program.
15801fdd08beSQuentin Monnet  * 	Return
15811fdd08beSQuentin Monnet  * 		The SMP id of the processor running the program.
15821fdd08beSQuentin Monnet  *
1583bdb7b79bSAndrii Nakryiko  * long bpf_skb_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len, u64 flags)
1584ad4a5223SQuentin Monnet  * 	Description
1585ad4a5223SQuentin Monnet  * 		Store *len* bytes from address *from* into the packet
1586ad4a5223SQuentin Monnet  * 		associated to *skb*, at *offset*. *flags* are a combination of
1587ad4a5223SQuentin Monnet  * 		**BPF_F_RECOMPUTE_CSUM** (automatically recompute the
1588ad4a5223SQuentin Monnet  * 		checksum for the packet after storing the bytes) and
1589ad4a5223SQuentin Monnet  * 		**BPF_F_INVALIDATE_HASH** (set *skb*\ **->hash**, *skb*\
1590ad4a5223SQuentin Monnet  * 		**->swhash** and *skb*\ **->l4hash** to 0).
1591ad4a5223SQuentin Monnet  *
159232e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
1593ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1594ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1595ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
1596ad4a5223SQuentin Monnet  * 		direct packet access.
1597ad4a5223SQuentin Monnet  * 	Return
1598ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1599ad4a5223SQuentin Monnet  *
1600bdb7b79bSAndrii Nakryiko  * long bpf_l3_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 size)
1601ad4a5223SQuentin Monnet  * 	Description
1602ad4a5223SQuentin Monnet  * 		Recompute the layer 3 (e.g. IP) checksum for the packet
1603ad4a5223SQuentin Monnet  * 		associated to *skb*. Computation is incremental, so the helper
1604ad4a5223SQuentin Monnet  * 		must know the former value of the header field that was
1605ad4a5223SQuentin Monnet  * 		modified (*from*), the new value of this field (*to*), and the
1606ad4a5223SQuentin Monnet  * 		number of bytes (2 or 4) for this field, stored in *size*.
1607ad4a5223SQuentin Monnet  * 		Alternatively, it is possible to store the difference between
1608ad4a5223SQuentin Monnet  * 		the previous and the new values of the header field in *to*, by
1609ad4a5223SQuentin Monnet  * 		setting *from* and *size* to 0. For both methods, *offset*
1610ad4a5223SQuentin Monnet  * 		indicates the location of the IP checksum within the packet.
1611ad4a5223SQuentin Monnet  *
1612ad4a5223SQuentin Monnet  * 		This helper works in combination with **bpf_csum_diff**\ (),
1613ad4a5223SQuentin Monnet  * 		which does not update the checksum in-place, but offers more
1614ad4a5223SQuentin Monnet  * 		flexibility and can handle sizes larger than 2 or 4 for the
1615ad4a5223SQuentin Monnet  * 		checksum to update.
1616ad4a5223SQuentin Monnet  *
161732e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
1618ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1619ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1620ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
1621ad4a5223SQuentin Monnet  * 		direct packet access.
1622ad4a5223SQuentin Monnet  * 	Return
1623ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1624ad4a5223SQuentin Monnet  *
1625bdb7b79bSAndrii Nakryiko  * long bpf_l4_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 flags)
1626ad4a5223SQuentin Monnet  * 	Description
1627ad4a5223SQuentin Monnet  * 		Recompute the layer 4 (e.g. TCP, UDP or ICMP) checksum for the
1628ad4a5223SQuentin Monnet  * 		packet associated to *skb*. Computation is incremental, so the
1629ad4a5223SQuentin Monnet  * 		helper must know the former value of the header field that was
1630ad4a5223SQuentin Monnet  * 		modified (*from*), the new value of this field (*to*), and the
1631ad4a5223SQuentin Monnet  * 		number of bytes (2 or 4) for this field, stored on the lowest
1632ad4a5223SQuentin Monnet  * 		four bits of *flags*. Alternatively, it is possible to store
1633ad4a5223SQuentin Monnet  * 		the difference between the previous and the new values of the
1634ad4a5223SQuentin Monnet  * 		header field in *to*, by setting *from* and the four lowest
1635ad4a5223SQuentin Monnet  * 		bits of *flags* to 0. For both methods, *offset* indicates the
1636ad4a5223SQuentin Monnet  * 		location of the IP checksum within the packet. In addition to
1637ad4a5223SQuentin Monnet  * 		the size of the field, *flags* can be added (bitwise OR) actual
1638ad4a5223SQuentin Monnet  * 		flags. With **BPF_F_MARK_MANGLED_0**, a null checksum is left
1639ad4a5223SQuentin Monnet  * 		untouched (unless **BPF_F_MARK_ENFORCE** is added as well), and
1640ad4a5223SQuentin Monnet  * 		for updates resulting in a null checksum the value is set to
1641ad4a5223SQuentin Monnet  * 		**CSUM_MANGLED_0** instead. Flag **BPF_F_PSEUDO_HDR** indicates
1642ad4a5223SQuentin Monnet  * 		the checksum is to be computed against a pseudo-header.
1643ad4a5223SQuentin Monnet  *
1644ad4a5223SQuentin Monnet  * 		This helper works in combination with **bpf_csum_diff**\ (),
1645ad4a5223SQuentin Monnet  * 		which does not update the checksum in-place, but offers more
1646ad4a5223SQuentin Monnet  * 		flexibility and can handle sizes larger than 2 or 4 for the
1647ad4a5223SQuentin Monnet  * 		checksum to update.
1648ad4a5223SQuentin Monnet  *
164932e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
1650ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1651ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1652ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
1653ad4a5223SQuentin Monnet  * 		direct packet access.
1654ad4a5223SQuentin Monnet  * 	Return
1655ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1656ad4a5223SQuentin Monnet  *
1657bdb7b79bSAndrii Nakryiko  * long bpf_tail_call(void *ctx, struct bpf_map *prog_array_map, u32 index)
1658ad4a5223SQuentin Monnet  * 	Description
1659ad4a5223SQuentin Monnet  * 		This special helper is used to trigger a "tail call", or in
1660ad4a5223SQuentin Monnet  * 		other words, to jump into another eBPF program. The same stack
1661ad4a5223SQuentin Monnet  * 		frame is used (but values on stack and in registers for the
1662ad4a5223SQuentin Monnet  * 		caller are not accessible to the callee). This mechanism allows
1663ad4a5223SQuentin Monnet  * 		for program chaining, either for raising the maximum number of
1664ad4a5223SQuentin Monnet  * 		available eBPF instructions, or to execute given programs in
1665ad4a5223SQuentin Monnet  * 		conditional blocks. For security reasons, there is an upper
1666ad4a5223SQuentin Monnet  * 		limit to the number of successive tail calls that can be
1667ad4a5223SQuentin Monnet  * 		performed.
1668ad4a5223SQuentin Monnet  *
1669ad4a5223SQuentin Monnet  * 		Upon call of this helper, the program attempts to jump into a
1670ad4a5223SQuentin Monnet  * 		program referenced at index *index* in *prog_array_map*, a
1671ad4a5223SQuentin Monnet  * 		special map of type **BPF_MAP_TYPE_PROG_ARRAY**, and passes
1672ad4a5223SQuentin Monnet  * 		*ctx*, a pointer to the context.
1673ad4a5223SQuentin Monnet  *
1674ad4a5223SQuentin Monnet  * 		If the call succeeds, the kernel immediately runs the first
1675ad4a5223SQuentin Monnet  * 		instruction of the new program. This is not a function call,
1676ad4a5223SQuentin Monnet  * 		and it never returns to the previous program. If the call
1677ad4a5223SQuentin Monnet  * 		fails, then the helper has no effect, and the caller continues
1678ad4a5223SQuentin Monnet  * 		to run its subsequent instructions. A call can fail if the
1679ad4a5223SQuentin Monnet  * 		destination program for the jump does not exist (i.e. *index*
1680ad4a5223SQuentin Monnet  * 		is superior to the number of entries in *prog_array_map*), or
1681ad4a5223SQuentin Monnet  * 		if the maximum number of tail calls has been reached for this
1682ad4a5223SQuentin Monnet  * 		chain of programs. This limit is defined in the kernel by the
1683ad4a5223SQuentin Monnet  * 		macro **MAX_TAIL_CALL_CNT** (not accessible to user space),
1684ad4a5223SQuentin Monnet  * 		which is currently set to 32.
1685ad4a5223SQuentin Monnet  * 	Return
1686ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1687ad4a5223SQuentin Monnet  *
1688bdb7b79bSAndrii Nakryiko  * long bpf_clone_redirect(struct sk_buff *skb, u32 ifindex, u64 flags)
1689ad4a5223SQuentin Monnet  * 	Description
1690ad4a5223SQuentin Monnet  * 		Clone and redirect the packet associated to *skb* to another
1691ad4a5223SQuentin Monnet  * 		net device of index *ifindex*. Both ingress and egress
1692ad4a5223SQuentin Monnet  * 		interfaces can be used for redirection. The **BPF_F_INGRESS**
1693ad4a5223SQuentin Monnet  * 		value in *flags* is used to make the distinction (ingress path
1694ad4a5223SQuentin Monnet  * 		is selected if the flag is present, egress path otherwise).
1695ad4a5223SQuentin Monnet  * 		This is the only flag supported for now.
1696ad4a5223SQuentin Monnet  *
1697ad4a5223SQuentin Monnet  * 		In comparison with **bpf_redirect**\ () helper,
1698ad4a5223SQuentin Monnet  * 		**bpf_clone_redirect**\ () has the associated cost of
1699ad4a5223SQuentin Monnet  * 		duplicating the packet buffer, but this can be executed out of
1700ad4a5223SQuentin Monnet  * 		the eBPF program. Conversely, **bpf_redirect**\ () is more
1701ad4a5223SQuentin Monnet  * 		efficient, but it is handled through an action code where the
1702ad4a5223SQuentin Monnet  * 		redirection happens only after the eBPF program has returned.
1703ad4a5223SQuentin Monnet  *
170432e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
1705ad4a5223SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1706ad4a5223SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1707ad4a5223SQuentin Monnet  * 		performed again, if the helper is used in combination with
1708ad4a5223SQuentin Monnet  * 		direct packet access.
1709ad4a5223SQuentin Monnet  * 	Return
1710ad4a5223SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1711c456dec4SQuentin Monnet  *
1712c456dec4SQuentin Monnet  * u64 bpf_get_current_pid_tgid(void)
1713c456dec4SQuentin Monnet  * 	Return
1714c456dec4SQuentin Monnet  * 		A 64-bit integer containing the current tgid and pid, and
1715c456dec4SQuentin Monnet  * 		created as such:
1716c456dec4SQuentin Monnet  * 		*current_task*\ **->tgid << 32 \|**
1717c456dec4SQuentin Monnet  * 		*current_task*\ **->pid**.
1718c456dec4SQuentin Monnet  *
1719c456dec4SQuentin Monnet  * u64 bpf_get_current_uid_gid(void)
1720c456dec4SQuentin Monnet  * 	Return
1721c456dec4SQuentin Monnet  * 		A 64-bit integer containing the current GID and UID, and
1722c456dec4SQuentin Monnet  * 		created as such: *current_gid* **<< 32 \|** *current_uid*.
1723c456dec4SQuentin Monnet  *
1724bdb7b79bSAndrii Nakryiko  * long bpf_get_current_comm(void *buf, u32 size_of_buf)
1725c456dec4SQuentin Monnet  * 	Description
1726c456dec4SQuentin Monnet  * 		Copy the **comm** attribute of the current task into *buf* of
1727c456dec4SQuentin Monnet  * 		*size_of_buf*. The **comm** attribute contains the name of
1728c456dec4SQuentin Monnet  * 		the executable (excluding the path) for the current task. The
1729c456dec4SQuentin Monnet  * 		*size_of_buf* must be strictly positive. On success, the
1730c456dec4SQuentin Monnet  * 		helper makes sure that the *buf* is NUL-terminated. On failure,
1731c456dec4SQuentin Monnet  * 		it is filled with zeroes.
1732c456dec4SQuentin Monnet  * 	Return
1733c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1734c456dec4SQuentin Monnet  *
17351fdd08beSQuentin Monnet  * u32 bpf_get_cgroup_classid(struct sk_buff *skb)
17361fdd08beSQuentin Monnet  * 	Description
17371fdd08beSQuentin Monnet  * 		Retrieve the classid for the current task, i.e. for the net_cls
17381fdd08beSQuentin Monnet  * 		cgroup to which *skb* belongs.
17391fdd08beSQuentin Monnet  *
17401fdd08beSQuentin Monnet  * 		This helper can be used on TC egress path, but not on ingress.
17411fdd08beSQuentin Monnet  *
17421fdd08beSQuentin Monnet  * 		The net_cls cgroup provides an interface to tag network packets
17431fdd08beSQuentin Monnet  * 		based on a user-provided identifier for all traffic coming from
17441fdd08beSQuentin Monnet  * 		the tasks belonging to the related cgroup. See also the related
17451fdd08beSQuentin Monnet  * 		kernel documentation, available from the Linux sources in file
1746da82c92fSMauro Carvalho Chehab  * 		*Documentation/admin-guide/cgroup-v1/net_cls.rst*.
17471fdd08beSQuentin Monnet  *
17481fdd08beSQuentin Monnet  * 		The Linux kernel has two versions for cgroups: there are
17491fdd08beSQuentin Monnet  * 		cgroups v1 and cgroups v2. Both are available to users, who can
17501fdd08beSQuentin Monnet  * 		use a mixture of them, but note that the net_cls cgroup is for
17511fdd08beSQuentin Monnet  * 		cgroup v1 only. This makes it incompatible with BPF programs
17521fdd08beSQuentin Monnet  * 		run on cgroups, which is a cgroup-v2-only feature (a socket can
17531fdd08beSQuentin Monnet  * 		only hold data for one version of cgroups at a time).
17541fdd08beSQuentin Monnet  *
17551fdd08beSQuentin Monnet  * 		This helper is only available is the kernel was compiled with
17561fdd08beSQuentin Monnet  * 		the **CONFIG_CGROUP_NET_CLASSID** configuration option set to
17571fdd08beSQuentin Monnet  * 		"**y**" or to "**m**".
17581fdd08beSQuentin Monnet  * 	Return
17591fdd08beSQuentin Monnet  * 		The classid, or 0 for the default unconfigured classid.
17601fdd08beSQuentin Monnet  *
1761bdb7b79bSAndrii Nakryiko  * long bpf_skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)
1762c456dec4SQuentin Monnet  * 	Description
1763c456dec4SQuentin Monnet  * 		Push a *vlan_tci* (VLAN tag control information) of protocol
1764c456dec4SQuentin Monnet  * 		*vlan_proto* to the packet associated to *skb*, then update
1765c456dec4SQuentin Monnet  * 		the checksum. Note that if *vlan_proto* is different from
1766c456dec4SQuentin Monnet  * 		**ETH_P_8021Q** and **ETH_P_8021AD**, it is considered to
1767c456dec4SQuentin Monnet  * 		be **ETH_P_8021Q**.
1768c456dec4SQuentin Monnet  *
176932e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
1770c456dec4SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1771c456dec4SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1772c456dec4SQuentin Monnet  * 		performed again, if the helper is used in combination with
1773c456dec4SQuentin Monnet  * 		direct packet access.
1774c456dec4SQuentin Monnet  * 	Return
1775c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1776c456dec4SQuentin Monnet  *
1777bdb7b79bSAndrii Nakryiko  * long bpf_skb_vlan_pop(struct sk_buff *skb)
1778c456dec4SQuentin Monnet  * 	Description
1779c456dec4SQuentin Monnet  * 		Pop a VLAN header from the packet associated to *skb*.
1780c456dec4SQuentin Monnet  *
178132e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
1782c456dec4SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
1783c456dec4SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
1784c456dec4SQuentin Monnet  * 		performed again, if the helper is used in combination with
1785c456dec4SQuentin Monnet  * 		direct packet access.
1786c456dec4SQuentin Monnet  * 	Return
1787c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1788c456dec4SQuentin Monnet  *
1789bdb7b79bSAndrii Nakryiko  * long bpf_skb_get_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
1790c456dec4SQuentin Monnet  * 	Description
1791c456dec4SQuentin Monnet  * 		Get tunnel metadata. This helper takes a pointer *key* to an
1792c456dec4SQuentin Monnet  * 		empty **struct bpf_tunnel_key** of **size**, that will be
1793c456dec4SQuentin Monnet  * 		filled with tunnel metadata for the packet associated to *skb*.
1794c456dec4SQuentin Monnet  * 		The *flags* can be set to **BPF_F_TUNINFO_IPV6**, which
1795c456dec4SQuentin Monnet  * 		indicates that the tunnel is based on IPv6 protocol instead of
1796c456dec4SQuentin Monnet  * 		IPv4.
1797c456dec4SQuentin Monnet  *
1798c456dec4SQuentin Monnet  * 		The **struct bpf_tunnel_key** is an object that generalizes the
1799c456dec4SQuentin Monnet  * 		principal parameters used by various tunneling protocols into a
1800c456dec4SQuentin Monnet  * 		single struct. This way, it can be used to easily make a
1801c456dec4SQuentin Monnet  * 		decision based on the contents of the encapsulation header,
1802c456dec4SQuentin Monnet  * 		"summarized" in this struct. In particular, it holds the IP
1803c456dec4SQuentin Monnet  * 		address of the remote end (IPv4 or IPv6, depending on the case)
1804c456dec4SQuentin Monnet  * 		in *key*\ **->remote_ipv4** or *key*\ **->remote_ipv6**. Also,
1805c456dec4SQuentin Monnet  * 		this struct exposes the *key*\ **->tunnel_id**, which is
1806c456dec4SQuentin Monnet  * 		generally mapped to a VNI (Virtual Network Identifier), making
1807c456dec4SQuentin Monnet  * 		it programmable together with the **bpf_skb_set_tunnel_key**\
1808c456dec4SQuentin Monnet  * 		() helper.
1809c456dec4SQuentin Monnet  *
1810c456dec4SQuentin Monnet  * 		Let's imagine that the following code is part of a program
1811c456dec4SQuentin Monnet  * 		attached to the TC ingress interface, on one end of a GRE
1812c456dec4SQuentin Monnet  * 		tunnel, and is supposed to filter out all messages coming from
1813c456dec4SQuentin Monnet  * 		remote ends with IPv4 address other than 10.0.0.1:
1814c456dec4SQuentin Monnet  *
1815c456dec4SQuentin Monnet  * 		::
1816c456dec4SQuentin Monnet  *
1817c456dec4SQuentin Monnet  * 			int ret;
1818c456dec4SQuentin Monnet  * 			struct bpf_tunnel_key key = {};
1819c456dec4SQuentin Monnet  *
1820c456dec4SQuentin Monnet  * 			ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
1821c456dec4SQuentin Monnet  * 			if (ret < 0)
1822c456dec4SQuentin Monnet  * 				return TC_ACT_SHOT;	// drop packet
1823c456dec4SQuentin Monnet  *
1824c456dec4SQuentin Monnet  * 			if (key.remote_ipv4 != 0x0a000001)
1825c456dec4SQuentin Monnet  * 				return TC_ACT_SHOT;	// drop packet
1826c456dec4SQuentin Monnet  *
1827c456dec4SQuentin Monnet  * 			return TC_ACT_OK;		// accept packet
1828c456dec4SQuentin Monnet  *
1829c456dec4SQuentin Monnet  * 		This interface can also be used with all encapsulation devices
1830c456dec4SQuentin Monnet  * 		that can operate in "collect metadata" mode: instead of having
1831c456dec4SQuentin Monnet  * 		one network device per specific configuration, the "collect
1832c456dec4SQuentin Monnet  * 		metadata" mode only requires a single device where the
1833c456dec4SQuentin Monnet  * 		configuration can be extracted from this helper.
1834c456dec4SQuentin Monnet  *
1835c456dec4SQuentin Monnet  * 		This can be used together with various tunnels such as VXLan,
1836c456dec4SQuentin Monnet  * 		Geneve, GRE or IP in IP (IPIP).
1837c456dec4SQuentin Monnet  * 	Return
1838c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1839c456dec4SQuentin Monnet  *
1840bdb7b79bSAndrii Nakryiko  * long bpf_skb_set_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
1841c456dec4SQuentin Monnet  * 	Description
1842c456dec4SQuentin Monnet  * 		Populate tunnel metadata for packet associated to *skb.* The
1843c456dec4SQuentin Monnet  * 		tunnel metadata is set to the contents of *key*, of *size*. The
1844c456dec4SQuentin Monnet  * 		*flags* can be set to a combination of the following values:
1845c456dec4SQuentin Monnet  *
1846c456dec4SQuentin Monnet  * 		**BPF_F_TUNINFO_IPV6**
1847c456dec4SQuentin Monnet  * 			Indicate that the tunnel is based on IPv6 protocol
1848c456dec4SQuentin Monnet  * 			instead of IPv4.
1849c456dec4SQuentin Monnet  * 		**BPF_F_ZERO_CSUM_TX**
1850c456dec4SQuentin Monnet  * 			For IPv4 packets, add a flag to tunnel metadata
1851c456dec4SQuentin Monnet  * 			indicating that checksum computation should be skipped
1852c456dec4SQuentin Monnet  * 			and checksum set to zeroes.
1853c456dec4SQuentin Monnet  * 		**BPF_F_DONT_FRAGMENT**
1854c456dec4SQuentin Monnet  * 			Add a flag to tunnel metadata indicating that the
1855c456dec4SQuentin Monnet  * 			packet should not be fragmented.
1856c456dec4SQuentin Monnet  * 		**BPF_F_SEQ_NUMBER**
1857c456dec4SQuentin Monnet  * 			Add a flag to tunnel metadata indicating that a
1858c456dec4SQuentin Monnet  * 			sequence number should be added to tunnel header before
1859c456dec4SQuentin Monnet  * 			sending the packet. This flag was added for GRE
1860c456dec4SQuentin Monnet  * 			encapsulation, but might be used with other protocols
1861c456dec4SQuentin Monnet  * 			as well in the future.
1862c456dec4SQuentin Monnet  *
1863c456dec4SQuentin Monnet  * 		Here is a typical usage on the transmit path:
1864c456dec4SQuentin Monnet  *
1865c456dec4SQuentin Monnet  * 		::
1866c456dec4SQuentin Monnet  *
1867c456dec4SQuentin Monnet  * 			struct bpf_tunnel_key key;
1868c456dec4SQuentin Monnet  * 			     populate key ...
1869c456dec4SQuentin Monnet  * 			bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0);
1870c456dec4SQuentin Monnet  * 			bpf_clone_redirect(skb, vxlan_dev_ifindex, 0);
1871c456dec4SQuentin Monnet  *
1872c456dec4SQuentin Monnet  * 		See also the description of the **bpf_skb_get_tunnel_key**\ ()
1873c456dec4SQuentin Monnet  * 		helper for additional information.
1874c456dec4SQuentin Monnet  * 	Return
1875c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1876c456dec4SQuentin Monnet  *
1877c6b5fb86SQuentin Monnet  * u64 bpf_perf_event_read(struct bpf_map *map, u64 flags)
1878c6b5fb86SQuentin Monnet  * 	Description
1879c6b5fb86SQuentin Monnet  * 		Read the value of a perf event counter. This helper relies on a
1880c6b5fb86SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of
1881c6b5fb86SQuentin Monnet  * 		the perf event counter is selected when *map* is updated with
1882c6b5fb86SQuentin Monnet  * 		perf event file descriptors. The *map* is an array whose size
1883c6b5fb86SQuentin Monnet  * 		is the number of available CPUs, and each cell contains a value
1884c6b5fb86SQuentin Monnet  * 		relative to one CPU. The value to retrieve is indicated by
1885c6b5fb86SQuentin Monnet  * 		*flags*, that contains the index of the CPU to look up, masked
1886c6b5fb86SQuentin Monnet  * 		with **BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
1887c6b5fb86SQuentin Monnet  * 		**BPF_F_CURRENT_CPU** to indicate that the value for the
1888c6b5fb86SQuentin Monnet  * 		current CPU should be retrieved.
1889c6b5fb86SQuentin Monnet  *
1890c6b5fb86SQuentin Monnet  * 		Note that before Linux 4.13, only hardware perf event can be
1891c6b5fb86SQuentin Monnet  * 		retrieved.
1892c6b5fb86SQuentin Monnet  *
1893c6b5fb86SQuentin Monnet  * 		Also, be aware that the newer helper
1894c6b5fb86SQuentin Monnet  * 		**bpf_perf_event_read_value**\ () is recommended over
18953bd5a09bSQuentin Monnet  * 		**bpf_perf_event_read**\ () in general. The latter has some ABI
1896c6b5fb86SQuentin Monnet  * 		quirks where error and counter value are used as a return code
1897c6b5fb86SQuentin Monnet  * 		(which is wrong to do since ranges may overlap). This issue is
18983bd5a09bSQuentin Monnet  * 		fixed with **bpf_perf_event_read_value**\ (), which at the same
18993bd5a09bSQuentin Monnet  * 		time provides more features over the **bpf_perf_event_read**\
19003bd5a09bSQuentin Monnet  * 		() interface. Please refer to the description of
1901c6b5fb86SQuentin Monnet  * 		**bpf_perf_event_read_value**\ () for details.
1902c6b5fb86SQuentin Monnet  * 	Return
1903c6b5fb86SQuentin Monnet  * 		The value of the perf event counter read from the map, or a
1904c6b5fb86SQuentin Monnet  * 		negative error code in case of failure.
1905c6b5fb86SQuentin Monnet  *
1906bdb7b79bSAndrii Nakryiko  * long bpf_redirect(u32 ifindex, u64 flags)
1907c456dec4SQuentin Monnet  * 	Description
1908c456dec4SQuentin Monnet  * 		Redirect the packet to another net device of index *ifindex*.
1909c456dec4SQuentin Monnet  * 		This helper is somewhat similar to **bpf_clone_redirect**\
1910c456dec4SQuentin Monnet  * 		(), except that the packet is not cloned, which provides
1911c456dec4SQuentin Monnet  * 		increased performance.
1912c456dec4SQuentin Monnet  *
1913c456dec4SQuentin Monnet  * 		Except for XDP, both ingress and egress interfaces can be used
1914c456dec4SQuentin Monnet  * 		for redirection. The **BPF_F_INGRESS** value in *flags* is used
1915c456dec4SQuentin Monnet  * 		to make the distinction (ingress path is selected if the flag
1916c456dec4SQuentin Monnet  * 		is present, egress path otherwise). Currently, XDP only
1917c456dec4SQuentin Monnet  * 		supports redirection to the egress interface, and accepts no
1918c456dec4SQuentin Monnet  * 		flag at all.
1919c456dec4SQuentin Monnet  *
1920f25975f4SToke Høiland-Jørgensen  * 		The same effect can also be attained with the more generic
1921f25975f4SToke Høiland-Jørgensen  * 		**bpf_redirect_map**\ (), which uses a BPF map to store the
1922f25975f4SToke Høiland-Jørgensen  * 		redirect target instead of providing it directly to the helper.
1923c456dec4SQuentin Monnet  * 	Return
1924c456dec4SQuentin Monnet  * 		For XDP, the helper returns **XDP_REDIRECT** on success or
1925c456dec4SQuentin Monnet  * 		**XDP_ABORTED** on error. For other program types, the values
1926c456dec4SQuentin Monnet  * 		are **TC_ACT_REDIRECT** on success or **TC_ACT_SHOT** on
1927c456dec4SQuentin Monnet  * 		error.
1928c456dec4SQuentin Monnet  *
19291fdd08beSQuentin Monnet  * u32 bpf_get_route_realm(struct sk_buff *skb)
19301fdd08beSQuentin Monnet  * 	Description
19311fdd08beSQuentin Monnet  * 		Retrieve the realm or the route, that is to say the
19321fdd08beSQuentin Monnet  * 		**tclassid** field of the destination for the *skb*. The
1933b16fc097STobias Klauser  * 		identifier retrieved is a user-provided tag, similar to the
19341fdd08beSQuentin Monnet  * 		one used with the net_cls cgroup (see description for
19351fdd08beSQuentin Monnet  * 		**bpf_get_cgroup_classid**\ () helper), but here this tag is
19361fdd08beSQuentin Monnet  * 		held by a route (a destination entry), not by a task.
19371fdd08beSQuentin Monnet  *
19381fdd08beSQuentin Monnet  * 		Retrieving this identifier works with the clsact TC egress hook
19391fdd08beSQuentin Monnet  * 		(see also **tc-bpf(8)**), or alternatively on conventional
19401fdd08beSQuentin Monnet  * 		classful egress qdiscs, but not on TC ingress path. In case of
19411fdd08beSQuentin Monnet  * 		clsact TC egress hook, this has the advantage that, internally,
19421fdd08beSQuentin Monnet  * 		the destination entry has not been dropped yet in the transmit
19431fdd08beSQuentin Monnet  * 		path. Therefore, the destination entry does not need to be
19441fdd08beSQuentin Monnet  * 		artificially held via **netif_keep_dst**\ () for a classful
19451fdd08beSQuentin Monnet  * 		qdisc until the *skb* is freed.
19461fdd08beSQuentin Monnet  *
19471fdd08beSQuentin Monnet  * 		This helper is available only if the kernel was compiled with
19481fdd08beSQuentin Monnet  * 		**CONFIG_IP_ROUTE_CLASSID** configuration option.
19491fdd08beSQuentin Monnet  * 	Return
19501fdd08beSQuentin Monnet  * 		The realm of the route for the packet associated to *skb*, or 0
19511fdd08beSQuentin Monnet  * 		if none was found.
19521fdd08beSQuentin Monnet  *
1953bdb7b79bSAndrii Nakryiko  * long bpf_perf_event_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
1954c456dec4SQuentin Monnet  * 	Description
1955c456dec4SQuentin Monnet  * 		Write raw *data* blob into a special BPF perf event held by
1956c456dec4SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
1957c456dec4SQuentin Monnet  * 		event must have the following attributes: **PERF_SAMPLE_RAW**
1958c456dec4SQuentin Monnet  * 		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
1959c456dec4SQuentin Monnet  * 		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
1960c456dec4SQuentin Monnet  *
1961c456dec4SQuentin Monnet  * 		The *flags* are used to indicate the index in *map* for which
1962c456dec4SQuentin Monnet  * 		the value must be put, masked with **BPF_F_INDEX_MASK**.
1963c456dec4SQuentin Monnet  * 		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
1964c456dec4SQuentin Monnet  * 		to indicate that the index of the current CPU core should be
1965c456dec4SQuentin Monnet  * 		used.
1966c456dec4SQuentin Monnet  *
1967c456dec4SQuentin Monnet  * 		The value to write, of *size*, is passed through eBPF stack and
1968c456dec4SQuentin Monnet  * 		pointed by *data*.
1969c456dec4SQuentin Monnet  *
1970c456dec4SQuentin Monnet  * 		The context of the program *ctx* needs also be passed to the
1971c456dec4SQuentin Monnet  * 		helper.
1972c456dec4SQuentin Monnet  *
1973c456dec4SQuentin Monnet  * 		On user space, a program willing to read the values needs to
1974c456dec4SQuentin Monnet  * 		call **perf_event_open**\ () on the perf event (either for
1975c456dec4SQuentin Monnet  * 		one or for all CPUs) and to store the file descriptor into the
1976c456dec4SQuentin Monnet  * 		*map*. This must be done before the eBPF program can send data
1977c456dec4SQuentin Monnet  * 		into it. An example is available in file
1978c456dec4SQuentin Monnet  * 		*samples/bpf/trace_output_user.c* in the Linux kernel source
1979c456dec4SQuentin Monnet  * 		tree (the eBPF program counterpart is in
1980c456dec4SQuentin Monnet  * 		*samples/bpf/trace_output_kern.c*).
1981c456dec4SQuentin Monnet  *
1982c456dec4SQuentin Monnet  * 		**bpf_perf_event_output**\ () achieves better performance
1983c456dec4SQuentin Monnet  * 		than **bpf_trace_printk**\ () for sharing data with user
1984c456dec4SQuentin Monnet  * 		space, and is much better suitable for streaming data from eBPF
1985c456dec4SQuentin Monnet  * 		programs.
1986c456dec4SQuentin Monnet  *
1987c456dec4SQuentin Monnet  * 		Note that this helper is not restricted to tracing use cases
1988c456dec4SQuentin Monnet  * 		and can be used with programs attached to TC or XDP as well,
1989c456dec4SQuentin Monnet  * 		where it allows for passing data to user space listeners. Data
1990c456dec4SQuentin Monnet  * 		can be:
1991c456dec4SQuentin Monnet  *
1992c456dec4SQuentin Monnet  * 		* Only custom structs,
1993c456dec4SQuentin Monnet  * 		* Only the packet payload, or
1994c456dec4SQuentin Monnet  * 		* A combination of both.
1995c456dec4SQuentin Monnet  * 	Return
1996c456dec4SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
1997c456dec4SQuentin Monnet  *
1998bdb7b79bSAndrii Nakryiko  * long bpf_skb_load_bytes(const void *skb, u32 offset, void *to, u32 len)
19991fdd08beSQuentin Monnet  * 	Description
20001fdd08beSQuentin Monnet  * 		This helper was provided as an easy way to load data from a
20011fdd08beSQuentin Monnet  * 		packet. It can be used to load *len* bytes from *offset* from
20021fdd08beSQuentin Monnet  * 		the packet associated to *skb*, into the buffer pointed by
20031fdd08beSQuentin Monnet  * 		*to*.
20041fdd08beSQuentin Monnet  *
20051fdd08beSQuentin Monnet  * 		Since Linux 4.7, usage of this helper has mostly been replaced
20061fdd08beSQuentin Monnet  * 		by "direct packet access", enabling packet data to be
20071fdd08beSQuentin Monnet  * 		manipulated with *skb*\ **->data** and *skb*\ **->data_end**
20081fdd08beSQuentin Monnet  * 		pointing respectively to the first byte of packet data and to
20091fdd08beSQuentin Monnet  * 		the byte after the last byte of packet data. However, it
20101fdd08beSQuentin Monnet  * 		remains useful if one wishes to read large quantities of data
20111fdd08beSQuentin Monnet  * 		at once from a packet into the eBPF stack.
20121fdd08beSQuentin Monnet  * 	Return
20131fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
20141fdd08beSQuentin Monnet  *
2015bdb7b79bSAndrii Nakryiko  * long bpf_get_stackid(void *ctx, struct bpf_map *map, u64 flags)
2016c456dec4SQuentin Monnet  * 	Description
2017c456dec4SQuentin Monnet  * 		Walk a user or a kernel stack and return its id. To achieve
2018c456dec4SQuentin Monnet  * 		this, the helper needs *ctx*, which is a pointer to the context
2019c456dec4SQuentin Monnet  * 		on which the tracing program is executed, and a pointer to a
2020c456dec4SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_STACK_TRACE**.
2021c456dec4SQuentin Monnet  *
2022c456dec4SQuentin Monnet  * 		The last argument, *flags*, holds the number of stack frames to
2023c456dec4SQuentin Monnet  * 		skip (from 0 to 255), masked with
2024c456dec4SQuentin Monnet  * 		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
2025c456dec4SQuentin Monnet  * 		a combination of the following flags:
2026c456dec4SQuentin Monnet  *
2027c456dec4SQuentin Monnet  * 		**BPF_F_USER_STACK**
2028c456dec4SQuentin Monnet  * 			Collect a user space stack instead of a kernel stack.
2029c456dec4SQuentin Monnet  * 		**BPF_F_FAST_STACK_CMP**
2030c456dec4SQuentin Monnet  * 			Compare stacks by hash only.
2031c456dec4SQuentin Monnet  * 		**BPF_F_REUSE_STACKID**
2032c456dec4SQuentin Monnet  * 			If two different stacks hash into the same *stackid*,
2033c456dec4SQuentin Monnet  * 			discard the old one.
2034c456dec4SQuentin Monnet  *
2035c456dec4SQuentin Monnet  * 		The stack id retrieved is a 32 bit long integer handle which
2036c456dec4SQuentin Monnet  * 		can be further combined with other data (including other stack
2037c456dec4SQuentin Monnet  * 		ids) and used as a key into maps. This can be useful for
2038c456dec4SQuentin Monnet  * 		generating a variety of graphs (such as flame graphs or off-cpu
2039c456dec4SQuentin Monnet  * 		graphs).
2040c456dec4SQuentin Monnet  *
2041c456dec4SQuentin Monnet  * 		For walking a stack, this helper is an improvement over
2042c456dec4SQuentin Monnet  * 		**bpf_probe_read**\ (), which can be used with unrolled loops
2043c456dec4SQuentin Monnet  * 		but is not efficient and consumes a lot of eBPF instructions.
2044c456dec4SQuentin Monnet  * 		Instead, **bpf_get_stackid**\ () can collect up to
2045c456dec4SQuentin Monnet  * 		**PERF_MAX_STACK_DEPTH** both kernel and user frames. Note that
2046c456dec4SQuentin Monnet  * 		this limit can be controlled with the **sysctl** program, and
2047c456dec4SQuentin Monnet  * 		that it should be manually increased in order to profile long
2048c456dec4SQuentin Monnet  * 		user stacks (such as stacks for Java programs). To do so, use:
2049c456dec4SQuentin Monnet  *
2050c456dec4SQuentin Monnet  * 		::
2051c456dec4SQuentin Monnet  *
2052c456dec4SQuentin Monnet  * 			# sysctl kernel.perf_event_max_stack=<new value>
2053c456dec4SQuentin Monnet  * 	Return
2054c456dec4SQuentin Monnet  * 		The positive or null stack id on success, or a negative error
2055c456dec4SQuentin Monnet  * 		in case of failure.
2056c456dec4SQuentin Monnet  *
20571fdd08beSQuentin Monnet  * s64 bpf_csum_diff(__be32 *from, u32 from_size, __be32 *to, u32 to_size, __wsum seed)
20581fdd08beSQuentin Monnet  * 	Description
20591fdd08beSQuentin Monnet  * 		Compute a checksum difference, from the raw buffer pointed by
20601fdd08beSQuentin Monnet  * 		*from*, of length *from_size* (that must be a multiple of 4),
20611fdd08beSQuentin Monnet  * 		towards the raw buffer pointed by *to*, of size *to_size*
20621fdd08beSQuentin Monnet  * 		(same remark). An optional *seed* can be added to the value
20631fdd08beSQuentin Monnet  * 		(this can be cascaded, the seed may come from a previous call
20641fdd08beSQuentin Monnet  * 		to the helper).
20651fdd08beSQuentin Monnet  *
20661fdd08beSQuentin Monnet  * 		This is flexible enough to be used in several ways:
20671fdd08beSQuentin Monnet  *
20681fdd08beSQuentin Monnet  * 		* With *from_size* == 0, *to_size* > 0 and *seed* set to
20691fdd08beSQuentin Monnet  * 		  checksum, it can be used when pushing new data.
20701fdd08beSQuentin Monnet  * 		* With *from_size* > 0, *to_size* == 0 and *seed* set to
20711fdd08beSQuentin Monnet  * 		  checksum, it can be used when removing data from a packet.
20721fdd08beSQuentin Monnet  * 		* With *from_size* > 0, *to_size* > 0 and *seed* set to 0, it
20731fdd08beSQuentin Monnet  * 		  can be used to compute a diff. Note that *from_size* and
20741fdd08beSQuentin Monnet  * 		  *to_size* do not need to be equal.
20751fdd08beSQuentin Monnet  *
20761fdd08beSQuentin Monnet  * 		This helper can be used in combination with
20771fdd08beSQuentin Monnet  * 		**bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\ (), to
20781fdd08beSQuentin Monnet  * 		which one can feed in the difference computed with
20791fdd08beSQuentin Monnet  * 		**bpf_csum_diff**\ ().
20801fdd08beSQuentin Monnet  * 	Return
20811fdd08beSQuentin Monnet  * 		The checksum result, or a negative error code in case of
20821fdd08beSQuentin Monnet  * 		failure.
20831fdd08beSQuentin Monnet  *
2084bdb7b79bSAndrii Nakryiko  * long bpf_skb_get_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)
20851fdd08beSQuentin Monnet  * 	Description
20861fdd08beSQuentin Monnet  * 		Retrieve tunnel options metadata for the packet associated to
20871fdd08beSQuentin Monnet  * 		*skb*, and store the raw tunnel option data to the buffer *opt*
20881fdd08beSQuentin Monnet  * 		of *size*.
20891fdd08beSQuentin Monnet  *
20901fdd08beSQuentin Monnet  * 		This helper can be used with encapsulation devices that can
20911fdd08beSQuentin Monnet  * 		operate in "collect metadata" mode (please refer to the related
20921fdd08beSQuentin Monnet  * 		note in the description of **bpf_skb_get_tunnel_key**\ () for
20931fdd08beSQuentin Monnet  * 		more details). A particular example where this can be used is
20941fdd08beSQuentin Monnet  * 		in combination with the Geneve encapsulation protocol, where it
20951fdd08beSQuentin Monnet  * 		allows for pushing (with **bpf_skb_get_tunnel_opt**\ () helper)
20961fdd08beSQuentin Monnet  * 		and retrieving arbitrary TLVs (Type-Length-Value headers) from
20971fdd08beSQuentin Monnet  * 		the eBPF program. This allows for full customization of these
20981fdd08beSQuentin Monnet  * 		headers.
20991fdd08beSQuentin Monnet  * 	Return
21001fdd08beSQuentin Monnet  * 		The size of the option data retrieved.
21011fdd08beSQuentin Monnet  *
2102bdb7b79bSAndrii Nakryiko  * long bpf_skb_set_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)
21031fdd08beSQuentin Monnet  * 	Description
21041fdd08beSQuentin Monnet  * 		Set tunnel options metadata for the packet associated to *skb*
21051fdd08beSQuentin Monnet  * 		to the option data contained in the raw buffer *opt* of *size*.
21061fdd08beSQuentin Monnet  *
21071fdd08beSQuentin Monnet  * 		See also the description of the **bpf_skb_get_tunnel_opt**\ ()
21081fdd08beSQuentin Monnet  * 		helper for additional information.
21091fdd08beSQuentin Monnet  * 	Return
21101fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
21111fdd08beSQuentin Monnet  *
2112bdb7b79bSAndrii Nakryiko  * long bpf_skb_change_proto(struct sk_buff *skb, __be16 proto, u64 flags)
21131fdd08beSQuentin Monnet  * 	Description
21141fdd08beSQuentin Monnet  * 		Change the protocol of the *skb* to *proto*. Currently
21151fdd08beSQuentin Monnet  * 		supported are transition from IPv4 to IPv6, and from IPv6 to
21161fdd08beSQuentin Monnet  * 		IPv4. The helper takes care of the groundwork for the
21171fdd08beSQuentin Monnet  * 		transition, including resizing the socket buffer. The eBPF
21181fdd08beSQuentin Monnet  * 		program is expected to fill the new headers, if any, via
21191fdd08beSQuentin Monnet  * 		**skb_store_bytes**\ () and to recompute the checksums with
21201fdd08beSQuentin Monnet  * 		**bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\
21211fdd08beSQuentin Monnet  * 		(). The main case for this helper is to perform NAT64
21221fdd08beSQuentin Monnet  * 		operations out of an eBPF program.
21231fdd08beSQuentin Monnet  *
21241fdd08beSQuentin Monnet  * 		Internally, the GSO type is marked as dodgy so that headers are
21251fdd08beSQuentin Monnet  * 		checked and segments are recalculated by the GSO/GRO engine.
21261fdd08beSQuentin Monnet  * 		The size for GSO target is adapted as well.
21271fdd08beSQuentin Monnet  *
21281fdd08beSQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
21291fdd08beSQuentin Monnet  * 		be left at zero.
21301fdd08beSQuentin Monnet  *
213132e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
21321fdd08beSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
21331fdd08beSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
21341fdd08beSQuentin Monnet  * 		performed again, if the helper is used in combination with
21351fdd08beSQuentin Monnet  * 		direct packet access.
21361fdd08beSQuentin Monnet  * 	Return
21371fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
21381fdd08beSQuentin Monnet  *
2139bdb7b79bSAndrii Nakryiko  * long bpf_skb_change_type(struct sk_buff *skb, u32 type)
21401fdd08beSQuentin Monnet  * 	Description
21411fdd08beSQuentin Monnet  * 		Change the packet type for the packet associated to *skb*. This
21421fdd08beSQuentin Monnet  * 		comes down to setting *skb*\ **->pkt_type** to *type*, except
21431fdd08beSQuentin Monnet  * 		the eBPF program does not have a write access to *skb*\
21441fdd08beSQuentin Monnet  * 		**->pkt_type** beside this helper. Using a helper here allows
21451fdd08beSQuentin Monnet  * 		for graceful handling of errors.
21461fdd08beSQuentin Monnet  *
21471fdd08beSQuentin Monnet  * 		The major use case is to change incoming *skb*s to
21481fdd08beSQuentin Monnet  * 		**PACKET_HOST** in a programmatic way instead of having to
21491fdd08beSQuentin Monnet  * 		recirculate via **redirect**\ (..., **BPF_F_INGRESS**), for
21501fdd08beSQuentin Monnet  * 		example.
21511fdd08beSQuentin Monnet  *
21521fdd08beSQuentin Monnet  * 		Note that *type* only allows certain values. At this time, they
21531fdd08beSQuentin Monnet  * 		are:
21541fdd08beSQuentin Monnet  *
21551fdd08beSQuentin Monnet  * 		**PACKET_HOST**
21561fdd08beSQuentin Monnet  * 			Packet is for us.
21571fdd08beSQuentin Monnet  * 		**PACKET_BROADCAST**
21581fdd08beSQuentin Monnet  * 			Send packet to all.
21591fdd08beSQuentin Monnet  * 		**PACKET_MULTICAST**
21601fdd08beSQuentin Monnet  * 			Send packet to group.
21611fdd08beSQuentin Monnet  * 		**PACKET_OTHERHOST**
21621fdd08beSQuentin Monnet  * 			Send packet to someone else.
21631fdd08beSQuentin Monnet  * 	Return
21641fdd08beSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
21651fdd08beSQuentin Monnet  *
2166bdb7b79bSAndrii Nakryiko  * long bpf_skb_under_cgroup(struct sk_buff *skb, struct bpf_map *map, u32 index)
2167c6b5fb86SQuentin Monnet  * 	Description
2168c6b5fb86SQuentin Monnet  * 		Check whether *skb* is a descendant of the cgroup2 held by
2169c6b5fb86SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
2170c6b5fb86SQuentin Monnet  * 	Return
2171c6b5fb86SQuentin Monnet  * 		The return value depends on the result of the test, and can be:
2172c6b5fb86SQuentin Monnet  *
2173c6b5fb86SQuentin Monnet  * 		* 0, if the *skb* failed the cgroup2 descendant test.
2174c6b5fb86SQuentin Monnet  * 		* 1, if the *skb* succeeded the cgroup2 descendant test.
2175c6b5fb86SQuentin Monnet  * 		* A negative error code, if an error occurred.
2176c6b5fb86SQuentin Monnet  *
2177fa15601aSQuentin Monnet  * u32 bpf_get_hash_recalc(struct sk_buff *skb)
2178fa15601aSQuentin Monnet  * 	Description
2179fa15601aSQuentin Monnet  * 		Retrieve the hash of the packet, *skb*\ **->hash**. If it is
2180fa15601aSQuentin Monnet  * 		not set, in particular if the hash was cleared due to mangling,
2181fa15601aSQuentin Monnet  * 		recompute this hash. Later accesses to the hash can be done
2182fa15601aSQuentin Monnet  * 		directly with *skb*\ **->hash**.
2183fa15601aSQuentin Monnet  *
2184fa15601aSQuentin Monnet  * 		Calling **bpf_set_hash_invalid**\ (), changing a packet
2185fa15601aSQuentin Monnet  * 		prototype with **bpf_skb_change_proto**\ (), or calling
2186fa15601aSQuentin Monnet  * 		**bpf_skb_store_bytes**\ () with the
2187fa15601aSQuentin Monnet  * 		**BPF_F_INVALIDATE_HASH** are actions susceptible to clear
2188fa15601aSQuentin Monnet  * 		the hash and to trigger a new computation for the next call to
2189fa15601aSQuentin Monnet  * 		**bpf_get_hash_recalc**\ ().
2190fa15601aSQuentin Monnet  * 	Return
2191fa15601aSQuentin Monnet  * 		The 32-bit hash.
2192fa15601aSQuentin Monnet  *
2193c456dec4SQuentin Monnet  * u64 bpf_get_current_task(void)
2194c456dec4SQuentin Monnet  * 	Return
2195c456dec4SQuentin Monnet  * 		A pointer to the current task struct.
2196fa15601aSQuentin Monnet  *
2197bdb7b79bSAndrii Nakryiko  * long bpf_probe_write_user(void *dst, const void *src, u32 len)
2198c6b5fb86SQuentin Monnet  * 	Description
2199c6b5fb86SQuentin Monnet  * 		Attempt in a safe way to write *len* bytes from the buffer
2200c6b5fb86SQuentin Monnet  * 		*src* to *dst* in memory. It only works for threads that are in
2201c6b5fb86SQuentin Monnet  * 		user context, and *dst* must be a valid user space address.
2202c6b5fb86SQuentin Monnet  *
2203c6b5fb86SQuentin Monnet  * 		This helper should not be used to implement any kind of
2204c6b5fb86SQuentin Monnet  * 		security mechanism because of TOC-TOU attacks, but rather to
2205c6b5fb86SQuentin Monnet  * 		debug, divert, and manipulate execution of semi-cooperative
2206c6b5fb86SQuentin Monnet  * 		processes.
2207c6b5fb86SQuentin Monnet  *
2208c6b5fb86SQuentin Monnet  * 		Keep in mind that this feature is meant for experiments, and it
2209c6b5fb86SQuentin Monnet  * 		has a risk of crashing the system and running programs.
2210c6b5fb86SQuentin Monnet  * 		Therefore, when an eBPF program using this helper is attached,
2211c6b5fb86SQuentin Monnet  * 		a warning including PID and process name is printed to kernel
2212c6b5fb86SQuentin Monnet  * 		logs.
2213c6b5fb86SQuentin Monnet  * 	Return
2214c6b5fb86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2215c6b5fb86SQuentin Monnet  *
2216bdb7b79bSAndrii Nakryiko  * long bpf_current_task_under_cgroup(struct bpf_map *map, u32 index)
2217c6b5fb86SQuentin Monnet  * 	Description
2218c6b5fb86SQuentin Monnet  * 		Check whether the probe is being run is the context of a given
2219c6b5fb86SQuentin Monnet  * 		subset of the cgroup2 hierarchy. The cgroup2 to test is held by
2220c6b5fb86SQuentin Monnet  * 		*map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
2221c6b5fb86SQuentin Monnet  * 	Return
2222c6b5fb86SQuentin Monnet  * 		The return value depends on the result of the test, and can be:
2223c6b5fb86SQuentin Monnet  *
22241aef5b43SSong Liu  *		* 0, if current task belongs to the cgroup2.
22251aef5b43SSong Liu  *		* 1, if current task does not belong to the cgroup2.
2226c6b5fb86SQuentin Monnet  * 		* A negative error code, if an error occurred.
2227c6b5fb86SQuentin Monnet  *
2228bdb7b79bSAndrii Nakryiko  * long bpf_skb_change_tail(struct sk_buff *skb, u32 len, u64 flags)
2229fa15601aSQuentin Monnet  * 	Description
2230fa15601aSQuentin Monnet  * 		Resize (trim or grow) the packet associated to *skb* to the
2231fa15601aSQuentin Monnet  * 		new *len*. The *flags* are reserved for future usage, and must
2232fa15601aSQuentin Monnet  * 		be left at zero.
2233fa15601aSQuentin Monnet  *
2234fa15601aSQuentin Monnet  * 		The basic idea is that the helper performs the needed work to
2235fa15601aSQuentin Monnet  * 		change the size of the packet, then the eBPF program rewrites
2236fa15601aSQuentin Monnet  * 		the rest via helpers like **bpf_skb_store_bytes**\ (),
2237fa15601aSQuentin Monnet  * 		**bpf_l3_csum_replace**\ (), **bpf_l3_csum_replace**\ ()
2238fa15601aSQuentin Monnet  * 		and others. This helper is a slow path utility intended for
2239fa15601aSQuentin Monnet  * 		replies with control messages. And because it is targeted for
2240fa15601aSQuentin Monnet  * 		slow path, the helper itself can afford to be slow: it
2241fa15601aSQuentin Monnet  * 		implicitly linearizes, unclones and drops offloads from the
2242fa15601aSQuentin Monnet  * 		*skb*.
2243fa15601aSQuentin Monnet  *
224432e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
2245fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
2246fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
2247fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
2248fa15601aSQuentin Monnet  * 		direct packet access.
2249fa15601aSQuentin Monnet  * 	Return
2250fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2251fa15601aSQuentin Monnet  *
2252bdb7b79bSAndrii Nakryiko  * long bpf_skb_pull_data(struct sk_buff *skb, u32 len)
2253fa15601aSQuentin Monnet  * 	Description
2254fa15601aSQuentin Monnet  * 		Pull in non-linear data in case the *skb* is non-linear and not
2255fa15601aSQuentin Monnet  * 		all of *len* are part of the linear section. Make *len* bytes
2256fa15601aSQuentin Monnet  * 		from *skb* readable and writable. If a zero value is passed for
2257fa15601aSQuentin Monnet  * 		*len*, then the whole length of the *skb* is pulled.
2258fa15601aSQuentin Monnet  *
2259fa15601aSQuentin Monnet  * 		This helper is only needed for reading and writing with direct
2260fa15601aSQuentin Monnet  * 		packet access.
2261fa15601aSQuentin Monnet  *
2262fa15601aSQuentin Monnet  * 		For direct packet access, testing that offsets to access
2263fa15601aSQuentin Monnet  * 		are within packet boundaries (test on *skb*\ **->data_end**) is
2264fa15601aSQuentin Monnet  * 		susceptible to fail if offsets are invalid, or if the requested
2265fa15601aSQuentin Monnet  * 		data is in non-linear parts of the *skb*. On failure the
2266fa15601aSQuentin Monnet  * 		program can just bail out, or in the case of a non-linear
2267fa15601aSQuentin Monnet  * 		buffer, use a helper to make the data available. The
2268fa15601aSQuentin Monnet  * 		**bpf_skb_load_bytes**\ () helper is a first solution to access
2269fa15601aSQuentin Monnet  * 		the data. Another one consists in using **bpf_skb_pull_data**
2270fa15601aSQuentin Monnet  * 		to pull in once the non-linear parts, then retesting and
2271fa15601aSQuentin Monnet  * 		eventually access the data.
2272fa15601aSQuentin Monnet  *
2273fa15601aSQuentin Monnet  * 		At the same time, this also makes sure the *skb* is uncloned,
2274fa15601aSQuentin Monnet  * 		which is a necessary condition for direct write. As this needs
2275fa15601aSQuentin Monnet  * 		to be an invariant for the write part only, the verifier
2276fa15601aSQuentin Monnet  * 		detects writes and adds a prologue that is calling
2277fa15601aSQuentin Monnet  * 		**bpf_skb_pull_data()** to effectively unclone the *skb* from
2278fa15601aSQuentin Monnet  * 		the very beginning in case it is indeed cloned.
2279fa15601aSQuentin Monnet  *
228032e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
2281fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
2282fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
2283fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
2284fa15601aSQuentin Monnet  * 		direct packet access.
2285fa15601aSQuentin Monnet  * 	Return
2286fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2287fa15601aSQuentin Monnet  *
2288fa15601aSQuentin Monnet  * s64 bpf_csum_update(struct sk_buff *skb, __wsum csum)
2289fa15601aSQuentin Monnet  * 	Description
2290fa15601aSQuentin Monnet  * 		Add the checksum *csum* into *skb*\ **->csum** in case the
2291fa15601aSQuentin Monnet  * 		driver has supplied a checksum for the entire packet into that
2292fa15601aSQuentin Monnet  * 		field. Return an error otherwise. This helper is intended to be
2293fa15601aSQuentin Monnet  * 		used in combination with **bpf_csum_diff**\ (), in particular
2294fa15601aSQuentin Monnet  * 		when the checksum needs to be updated after data has been
2295fa15601aSQuentin Monnet  * 		written into the packet through direct packet access.
2296fa15601aSQuentin Monnet  * 	Return
2297fa15601aSQuentin Monnet  * 		The checksum on success, or a negative error code in case of
2298fa15601aSQuentin Monnet  * 		failure.
2299fa15601aSQuentin Monnet  *
2300fa15601aSQuentin Monnet  * void bpf_set_hash_invalid(struct sk_buff *skb)
2301fa15601aSQuentin Monnet  * 	Description
2302fa15601aSQuentin Monnet  * 		Invalidate the current *skb*\ **->hash**. It can be used after
2303fa15601aSQuentin Monnet  * 		mangling on headers through direct packet access, in order to
2304fa15601aSQuentin Monnet  * 		indicate that the hash is outdated and to trigger a
2305fa15601aSQuentin Monnet  * 		recalculation the next time the kernel tries to access this
2306fa15601aSQuentin Monnet  * 		hash or when the **bpf_get_hash_recalc**\ () helper is called.
2307fa15601aSQuentin Monnet  *
2308bdb7b79bSAndrii Nakryiko  * long bpf_get_numa_node_id(void)
2309fa15601aSQuentin Monnet  * 	Description
2310fa15601aSQuentin Monnet  * 		Return the id of the current NUMA node. The primary use case
2311fa15601aSQuentin Monnet  * 		for this helper is the selection of sockets for the local NUMA
2312fa15601aSQuentin Monnet  * 		node, when the program is attached to sockets using the
2313fa15601aSQuentin Monnet  * 		**SO_ATTACH_REUSEPORT_EBPF** option (see also **socket(7)**),
2314fa15601aSQuentin Monnet  * 		but the helper is also available to other eBPF program types,
2315fa15601aSQuentin Monnet  * 		similarly to **bpf_get_smp_processor_id**\ ().
2316fa15601aSQuentin Monnet  * 	Return
2317fa15601aSQuentin Monnet  * 		The id of current NUMA node.
2318fa15601aSQuentin Monnet  *
2319bdb7b79bSAndrii Nakryiko  * long bpf_skb_change_head(struct sk_buff *skb, u32 len, u64 flags)
2320c6b5fb86SQuentin Monnet  * 	Description
2321c6b5fb86SQuentin Monnet  * 		Grows headroom of packet associated to *skb* and adjusts the
2322c6b5fb86SQuentin Monnet  * 		offset of the MAC header accordingly, adding *len* bytes of
2323c6b5fb86SQuentin Monnet  * 		space. It automatically extends and reallocates memory as
2324c6b5fb86SQuentin Monnet  * 		required.
2325c6b5fb86SQuentin Monnet  *
2326c6b5fb86SQuentin Monnet  * 		This helper can be used on a layer 3 *skb* to push a MAC header
2327c6b5fb86SQuentin Monnet  * 		for redirection into a layer 2 device.
2328c6b5fb86SQuentin Monnet  *
2329c6b5fb86SQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
2330c6b5fb86SQuentin Monnet  * 		be left at zero.
2331c6b5fb86SQuentin Monnet  *
233232e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
2333c6b5fb86SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
2334c6b5fb86SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
2335c6b5fb86SQuentin Monnet  * 		performed again, if the helper is used in combination with
2336c6b5fb86SQuentin Monnet  * 		direct packet access.
2337c6b5fb86SQuentin Monnet  * 	Return
2338c6b5fb86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2339c6b5fb86SQuentin Monnet  *
2340bdb7b79bSAndrii Nakryiko  * long bpf_xdp_adjust_head(struct xdp_buff *xdp_md, int delta)
2341c6b5fb86SQuentin Monnet  * 	Description
2342c6b5fb86SQuentin Monnet  * 		Adjust (move) *xdp_md*\ **->data** by *delta* bytes. Note that
2343c6b5fb86SQuentin Monnet  * 		it is possible to use a negative value for *delta*. This helper
2344c6b5fb86SQuentin Monnet  * 		can be used to prepare the packet for pushing or popping
2345c6b5fb86SQuentin Monnet  * 		headers.
2346c6b5fb86SQuentin Monnet  *
234732e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
2348c6b5fb86SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
2349c6b5fb86SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
2350c6b5fb86SQuentin Monnet  * 		performed again, if the helper is used in combination with
2351c6b5fb86SQuentin Monnet  * 		direct packet access.
2352c6b5fb86SQuentin Monnet  * 	Return
2353c6b5fb86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2354c6b5fb86SQuentin Monnet  *
2355bdb7b79bSAndrii Nakryiko  * long bpf_probe_read_str(void *dst, u32 size, const void *unsafe_ptr)
2356c6b5fb86SQuentin Monnet  * 	Description
23576ae08ae3SDaniel Borkmann  * 		Copy a NUL terminated string from an unsafe kernel address
2358ab8d7809SQuentin Monnet  * 		*unsafe_ptr* to *dst*. See **bpf_probe_read_kernel_str**\ () for
23596ae08ae3SDaniel Borkmann  * 		more details.
2360c6b5fb86SQuentin Monnet  *
2361ab8d7809SQuentin Monnet  * 		Generally, use **bpf_probe_read_user_str**\ () or
2362ab8d7809SQuentin Monnet  * 		**bpf_probe_read_kernel_str**\ () instead.
2363c6b5fb86SQuentin Monnet  * 	Return
2364c6b5fb86SQuentin Monnet  * 		On success, the strictly positive length of the string,
2365c6b5fb86SQuentin Monnet  * 		including the trailing NUL character. On error, a negative
2366c6b5fb86SQuentin Monnet  * 		value.
2367c6b5fb86SQuentin Monnet  *
2368c6b5fb86SQuentin Monnet  * u64 bpf_get_socket_cookie(struct sk_buff *skb)
2369c6b5fb86SQuentin Monnet  * 	Description
2370c6b5fb86SQuentin Monnet  * 		If the **struct sk_buff** pointed by *skb* has a known socket,
2371c6b5fb86SQuentin Monnet  * 		retrieve the cookie (generated by the kernel) of this socket.
2372c6b5fb86SQuentin Monnet  * 		If no cookie has been set yet, generate a new cookie. Once
2373c6b5fb86SQuentin Monnet  * 		generated, the socket cookie remains stable for the life of the
2374c6b5fb86SQuentin Monnet  * 		socket. This helper can be useful for monitoring per socket
2375cd48bddaSDaniel Borkmann  * 		networking traffic statistics as it provides a global socket
2376cd48bddaSDaniel Borkmann  * 		identifier that can be assumed unique.
2377c6b5fb86SQuentin Monnet  * 	Return
237807881ccbSFlorent Revest  * 		A 8-byte long unique number on success, or 0 if the socket
237907881ccbSFlorent Revest  * 		field is missing inside *skb*.
2380c6b5fb86SQuentin Monnet  *
2381d692f113SAndrey Ignatov  * u64 bpf_get_socket_cookie(struct bpf_sock_addr *ctx)
2382d692f113SAndrey Ignatov  * 	Description
2383d692f113SAndrey Ignatov  * 		Equivalent to bpf_get_socket_cookie() helper that accepts
238462369db2SQuentin Monnet  * 		*skb*, but gets socket from **struct bpf_sock_addr** context.
2385d692f113SAndrey Ignatov  * 	Return
238607881ccbSFlorent Revest  * 		A 8-byte long unique number.
2387d692f113SAndrey Ignatov  *
2388d692f113SAndrey Ignatov  * u64 bpf_get_socket_cookie(struct bpf_sock_ops *ctx)
2389d692f113SAndrey Ignatov  * 	Description
2390ab8d7809SQuentin Monnet  * 		Equivalent to **bpf_get_socket_cookie**\ () helper that accepts
239162369db2SQuentin Monnet  * 		*skb*, but gets socket from **struct bpf_sock_ops** context.
2392d692f113SAndrey Ignatov  * 	Return
239307881ccbSFlorent Revest  * 		A 8-byte long unique number.
2394d692f113SAndrey Ignatov  *
2395c5dbb89fSFlorent Revest  * u64 bpf_get_socket_cookie(struct sock *sk)
2396c5dbb89fSFlorent Revest  * 	Description
2397c5dbb89fSFlorent Revest  * 		Equivalent to **bpf_get_socket_cookie**\ () helper that accepts
2398c5dbb89fSFlorent Revest  * 		*sk*, but gets socket from a BTF **struct sock**. This helper
2399c5dbb89fSFlorent Revest  * 		also works for sleepable programs.
2400c5dbb89fSFlorent Revest  * 	Return
2401c5dbb89fSFlorent Revest  * 		A 8-byte long unique number or 0 if *sk* is NULL.
2402c5dbb89fSFlorent Revest  *
2403c6b5fb86SQuentin Monnet  * u32 bpf_get_socket_uid(struct sk_buff *skb)
2404c6b5fb86SQuentin Monnet  * 	Return
2405c6b5fb86SQuentin Monnet  * 		The owner UID of the socket associated to *skb*. If the socket
2406c6b5fb86SQuentin Monnet  * 		is **NULL**, or if it is not a full socket (i.e. if it is a
2407c6b5fb86SQuentin Monnet  * 		time-wait or a request socket instead), **overflowuid** value
2408c6b5fb86SQuentin Monnet  * 		is returned (note that **overflowuid** might also be the actual
2409c6b5fb86SQuentin Monnet  * 		UID value for the socket).
2410c6b5fb86SQuentin Monnet  *
2411bdb7b79bSAndrii Nakryiko  * long bpf_set_hash(struct sk_buff *skb, u32 hash)
2412fa15601aSQuentin Monnet  * 	Description
2413fa15601aSQuentin Monnet  * 		Set the full hash for *skb* (set the field *skb*\ **->hash**)
2414fa15601aSQuentin Monnet  * 		to value *hash*.
2415fa15601aSQuentin Monnet  * 	Return
2416fa15601aSQuentin Monnet  * 		0
2417fa15601aSQuentin Monnet  *
2418bdb7b79bSAndrii Nakryiko  * long bpf_setsockopt(void *bpf_socket, int level, int optname, void *optval, int optlen)
24197aa79a86SQuentin Monnet  * 	Description
24207aa79a86SQuentin Monnet  * 		Emulate a call to **setsockopt()** on the socket associated to
24217aa79a86SQuentin Monnet  * 		*bpf_socket*, which must be a full socket. The *level* at
24227aa79a86SQuentin Monnet  * 		which the option resides and the name *optname* of the option
24237aa79a86SQuentin Monnet  * 		must be specified, see **setsockopt(2)** for more information.
24247aa79a86SQuentin Monnet  * 		The option value of length *optlen* is pointed by *optval*.
24257aa79a86SQuentin Monnet  *
2426beecf11bSStanislav Fomichev  * 		*bpf_socket* should be one of the following:
2427ab8d7809SQuentin Monnet  *
2428beecf11bSStanislav Fomichev  * 		* **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
2429beecf11bSStanislav Fomichev  * 		* **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**
2430beecf11bSStanislav Fomichev  * 		  and **BPF_CGROUP_INET6_CONNECT**.
2431beecf11bSStanislav Fomichev  *
24327aa79a86SQuentin Monnet  * 		This helper actually implements a subset of **setsockopt()**.
24337aa79a86SQuentin Monnet  * 		It supports the following *level*\ s:
24347aa79a86SQuentin Monnet  *
24357aa79a86SQuentin Monnet  * 		* **SOL_SOCKET**, which supports the following *optname*\ s:
24367aa79a86SQuentin Monnet  * 		  **SO_RCVBUF**, **SO_SNDBUF**, **SO_MAX_PACING_RATE**,
2437f9bcf968SDmitry Yakunin  * 		  **SO_PRIORITY**, **SO_RCVLOWAT**, **SO_MARK**,
2438f9bcf968SDmitry Yakunin  * 		  **SO_BINDTODEVICE**, **SO_KEEPALIVE**.
24397aa79a86SQuentin Monnet  * 		* **IPPROTO_TCP**, which supports the following *optname*\ s:
24407aa79a86SQuentin Monnet  * 		  **TCP_CONGESTION**, **TCP_BPF_IW**,
2441f9bcf968SDmitry Yakunin  * 		  **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,
2442f9bcf968SDmitry Yakunin  * 		  **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,
2443eca43ee6SNikita V. Shirokov  *		  **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**.
24447aa79a86SQuentin Monnet  * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
24457aa79a86SQuentin Monnet  * 		* **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
24467aa79a86SQuentin Monnet  * 	Return
24477aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
24487aa79a86SQuentin Monnet  *
2449bdb7b79bSAndrii Nakryiko  * long bpf_skb_adjust_room(struct sk_buff *skb, s32 len_diff, u32 mode, u64 flags)
2450fa15601aSQuentin Monnet  * 	Description
2451fa15601aSQuentin Monnet  * 		Grow or shrink the room for data in the packet associated to
2452fa15601aSQuentin Monnet  * 		*skb* by *len_diff*, and according to the selected *mode*.
2453fa15601aSQuentin Monnet  *
2454836e66c2SDaniel Borkmann  * 		By default, the helper will reset any offloaded checksum
2455836e66c2SDaniel Borkmann  * 		indicator of the skb to CHECKSUM_NONE. This can be avoided
2456836e66c2SDaniel Borkmann  * 		by the following flag:
2457836e66c2SDaniel Borkmann  *
2458836e66c2SDaniel Borkmann  * 		* **BPF_F_ADJ_ROOM_NO_CSUM_RESET**: Do not reset offloaded
2459836e66c2SDaniel Borkmann  * 		  checksum data of the skb to CHECKSUM_NONE.
2460836e66c2SDaniel Borkmann  *
246114aa3192SWillem de Bruijn  *		There are two supported modes at this time:
246214aa3192SWillem de Bruijn  *
246314aa3192SWillem de Bruijn  *		* **BPF_ADJ_ROOM_MAC**: Adjust room at the mac layer
246414aa3192SWillem de Bruijn  *		  (room space is added or removed below the layer 2 header).
2465fa15601aSQuentin Monnet  *
2466fa15601aSQuentin Monnet  * 		* **BPF_ADJ_ROOM_NET**: Adjust room at the network layer
2467fa15601aSQuentin Monnet  * 		  (room space is added or removed below the layer 3 header).
2468fa15601aSQuentin Monnet  *
2469868d5235SWillem de Bruijn  *		The following flags are supported at this time:
24702278f6ccSWillem de Bruijn  *
24712278f6ccSWillem de Bruijn  *		* **BPF_F_ADJ_ROOM_FIXED_GSO**: Do not adjust gso_size.
24722278f6ccSWillem de Bruijn  *		  Adjusting mss in this way is not allowed for datagrams.
2473fa15601aSQuentin Monnet  *
247480867c5eSQuentin Monnet  *		* **BPF_F_ADJ_ROOM_ENCAP_L3_IPV4**,
247580867c5eSQuentin Monnet  *		  **BPF_F_ADJ_ROOM_ENCAP_L3_IPV6**:
2476868d5235SWillem de Bruijn  *		  Any new space is reserved to hold a tunnel header.
2477868d5235SWillem de Bruijn  *		  Configure skb offsets and other fields accordingly.
2478868d5235SWillem de Bruijn  *
247980867c5eSQuentin Monnet  *		* **BPF_F_ADJ_ROOM_ENCAP_L4_GRE**,
248080867c5eSQuentin Monnet  *		  **BPF_F_ADJ_ROOM_ENCAP_L4_UDP**:
2481868d5235SWillem de Bruijn  *		  Use with ENCAP_L3 flags to further specify the tunnel type.
2482868d5235SWillem de Bruijn  *
248380867c5eSQuentin Monnet  *		* **BPF_F_ADJ_ROOM_ENCAP_L2**\ (*len*):
248458dfc900SAlan Maguire  *		  Use with ENCAP_L3/L4 flags to further specify the tunnel
248580867c5eSQuentin Monnet  *		  type; *len* is the length of the inner MAC header.
248658dfc900SAlan Maguire  *
248732e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
2488fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
2489fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
2490fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
2491fa15601aSQuentin Monnet  * 		direct packet access.
2492fa15601aSQuentin Monnet  * 	Return
2493fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2494fa15601aSQuentin Monnet  *
2495bdb7b79bSAndrii Nakryiko  * long bpf_redirect_map(struct bpf_map *map, u32 key, u64 flags)
2496ab127040SQuentin Monnet  * 	Description
2497ab127040SQuentin Monnet  * 		Redirect the packet to the endpoint referenced by *map* at
2498ab127040SQuentin Monnet  * 		index *key*. Depending on its type, this *map* can contain
2499ab127040SQuentin Monnet  * 		references to net devices (for forwarding packets through other
2500ab127040SQuentin Monnet  * 		ports), or to CPUs (for redirecting XDP frames to another CPU;
2501ab127040SQuentin Monnet  * 		but this is only implemented for native XDP (with driver
2502ab127040SQuentin Monnet  * 		support) as of this writing).
2503ab127040SQuentin Monnet  *
250443e74c02SToke Høiland-Jørgensen  * 		The lower two bits of *flags* are used as the return code if
250543e74c02SToke Høiland-Jørgensen  * 		the map lookup fails. This is so that the return value can be
2506ab8d7809SQuentin Monnet  * 		one of the XDP program return codes up to **XDP_TX**, as chosen
2507ab8d7809SQuentin Monnet  * 		by the caller. Any higher bits in the *flags* argument must be
250843e74c02SToke Høiland-Jørgensen  * 		unset.
2509ab127040SQuentin Monnet  *
2510ab8d7809SQuentin Monnet  * 		See also **bpf_redirect**\ (), which only supports redirecting
2511ab8d7809SQuentin Monnet  * 		to an ifindex, but doesn't require a map to do so.
2512ab127040SQuentin Monnet  * 	Return
2513f25975f4SToke Høiland-Jørgensen  * 		**XDP_REDIRECT** on success, or the value of the two lower bits
2514a33d3147SJakub Wilk  * 		of the *flags* argument on error.
2515ab127040SQuentin Monnet  *
2516bdb7b79bSAndrii Nakryiko  * long bpf_sk_redirect_map(struct sk_buff *skb, struct bpf_map *map, u32 key, u64 flags)
2517ab127040SQuentin Monnet  * 	Description
2518ab127040SQuentin Monnet  * 		Redirect the packet to the socket referenced by *map* (of type
2519ab127040SQuentin Monnet  * 		**BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
2520ab127040SQuentin Monnet  * 		egress interfaces can be used for redirection. The
2521ab127040SQuentin Monnet  * 		**BPF_F_INGRESS** value in *flags* is used to make the
2522ab127040SQuentin Monnet  * 		distinction (ingress path is selected if the flag is present,
2523ab127040SQuentin Monnet  * 		egress path otherwise). This is the only flag supported for now.
2524ab127040SQuentin Monnet  * 	Return
2525ab127040SQuentin Monnet  * 		**SK_PASS** on success, or **SK_DROP** on error.
2526ab127040SQuentin Monnet  *
2527bdb7b79bSAndrii Nakryiko  * long bpf_sock_map_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
2528ab127040SQuentin Monnet  * 	Description
2529ab127040SQuentin Monnet  * 		Add an entry to, or update a *map* referencing sockets. The
2530ab127040SQuentin Monnet  * 		*skops* is used as a new value for the entry associated to
2531ab127040SQuentin Monnet  * 		*key*. *flags* is one of:
2532ab127040SQuentin Monnet  *
2533ab127040SQuentin Monnet  * 		**BPF_NOEXIST**
2534ab127040SQuentin Monnet  * 			The entry for *key* must not exist in the map.
2535ab127040SQuentin Monnet  * 		**BPF_EXIST**
2536ab127040SQuentin Monnet  * 			The entry for *key* must already exist in the map.
2537ab127040SQuentin Monnet  * 		**BPF_ANY**
2538ab127040SQuentin Monnet  * 			No condition on the existence of the entry for *key*.
2539ab127040SQuentin Monnet  *
2540ab127040SQuentin Monnet  * 		If the *map* has eBPF programs (parser and verdict), those will
2541ab127040SQuentin Monnet  * 		be inherited by the socket being added. If the socket is
2542ab127040SQuentin Monnet  * 		already attached to eBPF programs, this results in an error.
2543ab127040SQuentin Monnet  * 	Return
2544ab127040SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2545ab127040SQuentin Monnet  *
2546bdb7b79bSAndrii Nakryiko  * long bpf_xdp_adjust_meta(struct xdp_buff *xdp_md, int delta)
2547fa15601aSQuentin Monnet  * 	Description
2548fa15601aSQuentin Monnet  * 		Adjust the address pointed by *xdp_md*\ **->data_meta** by
2549fa15601aSQuentin Monnet  * 		*delta* (which can be positive or negative). Note that this
2550fa15601aSQuentin Monnet  * 		operation modifies the address stored in *xdp_md*\ **->data**,
2551fa15601aSQuentin Monnet  * 		so the latter must be loaded only after the helper has been
2552fa15601aSQuentin Monnet  * 		called.
2553fa15601aSQuentin Monnet  *
2554fa15601aSQuentin Monnet  * 		The use of *xdp_md*\ **->data_meta** is optional and programs
2555fa15601aSQuentin Monnet  * 		are not required to use it. The rationale is that when the
2556fa15601aSQuentin Monnet  * 		packet is processed with XDP (e.g. as DoS filter), it is
2557fa15601aSQuentin Monnet  * 		possible to push further meta data along with it before passing
2558fa15601aSQuentin Monnet  * 		to the stack, and to give the guarantee that an ingress eBPF
2559fa15601aSQuentin Monnet  * 		program attached as a TC classifier on the same device can pick
2560fa15601aSQuentin Monnet  * 		this up for further post-processing. Since TC works with socket
2561fa15601aSQuentin Monnet  * 		buffers, it remains possible to set from XDP the **mark** or
2562fa15601aSQuentin Monnet  * 		**priority** pointers, or other pointers for the socket buffer.
2563fa15601aSQuentin Monnet  * 		Having this scratch space generic and programmable allows for
2564fa15601aSQuentin Monnet  * 		more flexibility as the user is free to store whatever meta
2565fa15601aSQuentin Monnet  * 		data they need.
2566fa15601aSQuentin Monnet  *
256732e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
2568fa15601aSQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
2569fa15601aSQuentin Monnet  * 		previously done by the verifier are invalidated and must be
2570fa15601aSQuentin Monnet  * 		performed again, if the helper is used in combination with
2571fa15601aSQuentin Monnet  * 		direct packet access.
2572fa15601aSQuentin Monnet  * 	Return
2573fa15601aSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
25747aa79a86SQuentin Monnet  *
2575bdb7b79bSAndrii Nakryiko  * long bpf_perf_event_read_value(struct bpf_map *map, u64 flags, struct bpf_perf_event_value *buf, u32 buf_size)
25767aa79a86SQuentin Monnet  * 	Description
25777aa79a86SQuentin Monnet  * 		Read the value of a perf event counter, and store it into *buf*
25787aa79a86SQuentin Monnet  * 		of size *buf_size*. This helper relies on a *map* of type
25797aa79a86SQuentin Monnet  * 		**BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of the perf event
25807aa79a86SQuentin Monnet  * 		counter is selected when *map* is updated with perf event file
25817aa79a86SQuentin Monnet  * 		descriptors. The *map* is an array whose size is the number of
25827aa79a86SQuentin Monnet  * 		available CPUs, and each cell contains a value relative to one
25837aa79a86SQuentin Monnet  * 		CPU. The value to retrieve is indicated by *flags*, that
25847aa79a86SQuentin Monnet  * 		contains the index of the CPU to look up, masked with
25857aa79a86SQuentin Monnet  * 		**BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
25867aa79a86SQuentin Monnet  * 		**BPF_F_CURRENT_CPU** to indicate that the value for the
25877aa79a86SQuentin Monnet  * 		current CPU should be retrieved.
25887aa79a86SQuentin Monnet  *
25897aa79a86SQuentin Monnet  * 		This helper behaves in a way close to
25907aa79a86SQuentin Monnet  * 		**bpf_perf_event_read**\ () helper, save that instead of
25917aa79a86SQuentin Monnet  * 		just returning the value observed, it fills the *buf*
25927aa79a86SQuentin Monnet  * 		structure. This allows for additional data to be retrieved: in
25937aa79a86SQuentin Monnet  * 		particular, the enabled and running times (in *buf*\
25947aa79a86SQuentin Monnet  * 		**->enabled** and *buf*\ **->running**, respectively) are
25957aa79a86SQuentin Monnet  * 		copied. In general, **bpf_perf_event_read_value**\ () is
25967aa79a86SQuentin Monnet  * 		recommended over **bpf_perf_event_read**\ (), which has some
25977aa79a86SQuentin Monnet  * 		ABI issues and provides fewer functionalities.
25987aa79a86SQuentin Monnet  *
25997aa79a86SQuentin Monnet  * 		These values are interesting, because hardware PMU (Performance
26007aa79a86SQuentin Monnet  * 		Monitoring Unit) counters are limited resources. When there are
26017aa79a86SQuentin Monnet  * 		more PMU based perf events opened than available counters,
26027aa79a86SQuentin Monnet  * 		kernel will multiplex these events so each event gets certain
26037aa79a86SQuentin Monnet  * 		percentage (but not all) of the PMU time. In case that
26047aa79a86SQuentin Monnet  * 		multiplexing happens, the number of samples or counter value
26057aa79a86SQuentin Monnet  * 		will not reflect the case compared to when no multiplexing
26067aa79a86SQuentin Monnet  * 		occurs. This makes comparison between different runs difficult.
26077aa79a86SQuentin Monnet  * 		Typically, the counter value should be normalized before
26087aa79a86SQuentin Monnet  * 		comparing to other experiments. The usual normalization is done
26097aa79a86SQuentin Monnet  * 		as follows.
26107aa79a86SQuentin Monnet  *
26117aa79a86SQuentin Monnet  * 		::
26127aa79a86SQuentin Monnet  *
26137aa79a86SQuentin Monnet  * 			normalized_counter = counter * t_enabled / t_running
26147aa79a86SQuentin Monnet  *
26157aa79a86SQuentin Monnet  * 		Where t_enabled is the time enabled for event and t_running is
26167aa79a86SQuentin Monnet  * 		the time running for event since last normalization. The
26177aa79a86SQuentin Monnet  * 		enabled and running times are accumulated since the perf event
26187aa79a86SQuentin Monnet  * 		open. To achieve scaling factor between two invocations of an
2619ab8d7809SQuentin Monnet  * 		eBPF program, users can use CPU id as the key (which is
26207aa79a86SQuentin Monnet  * 		typical for perf array usage model) to remember the previous
26217aa79a86SQuentin Monnet  * 		value and do the calculation inside the eBPF program.
26227aa79a86SQuentin Monnet  * 	Return
26237aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
26247aa79a86SQuentin Monnet  *
2625bdb7b79bSAndrii Nakryiko  * long bpf_perf_prog_read_value(struct bpf_perf_event_data *ctx, struct bpf_perf_event_value *buf, u32 buf_size)
26267aa79a86SQuentin Monnet  * 	Description
26277aa79a86SQuentin Monnet  * 		For en eBPF program attached to a perf event, retrieve the
26287aa79a86SQuentin Monnet  * 		value of the event counter associated to *ctx* and store it in
26297aa79a86SQuentin Monnet  * 		the structure pointed by *buf* and of size *buf_size*. Enabled
26307aa79a86SQuentin Monnet  * 		and running times are also stored in the structure (see
26317aa79a86SQuentin Monnet  * 		description of helper **bpf_perf_event_read_value**\ () for
26327aa79a86SQuentin Monnet  * 		more details).
26337aa79a86SQuentin Monnet  * 	Return
26347aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
26357aa79a86SQuentin Monnet  *
2636bdb7b79bSAndrii Nakryiko  * long bpf_getsockopt(void *bpf_socket, int level, int optname, void *optval, int optlen)
26377aa79a86SQuentin Monnet  * 	Description
26387aa79a86SQuentin Monnet  * 		Emulate a call to **getsockopt()** on the socket associated to
26397aa79a86SQuentin Monnet  * 		*bpf_socket*, which must be a full socket. The *level* at
26407aa79a86SQuentin Monnet  * 		which the option resides and the name *optname* of the option
26417aa79a86SQuentin Monnet  * 		must be specified, see **getsockopt(2)** for more information.
26427aa79a86SQuentin Monnet  * 		The retrieved value is stored in the structure pointed by
26437aa79a86SQuentin Monnet  * 		*opval* and of length *optlen*.
26447aa79a86SQuentin Monnet  *
2645beecf11bSStanislav Fomichev  * 		*bpf_socket* should be one of the following:
2646ab8d7809SQuentin Monnet  *
2647beecf11bSStanislav Fomichev  * 		* **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
2648beecf11bSStanislav Fomichev  * 		* **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**
2649beecf11bSStanislav Fomichev  * 		  and **BPF_CGROUP_INET6_CONNECT**.
2650beecf11bSStanislav Fomichev  *
26517aa79a86SQuentin Monnet  * 		This helper actually implements a subset of **getsockopt()**.
26527aa79a86SQuentin Monnet  * 		It supports the following *level*\ s:
26537aa79a86SQuentin Monnet  *
26547aa79a86SQuentin Monnet  * 		* **IPPROTO_TCP**, which supports *optname*
26557aa79a86SQuentin Monnet  * 		  **TCP_CONGESTION**.
26567aa79a86SQuentin Monnet  * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
26577aa79a86SQuentin Monnet  * 		* **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
26587aa79a86SQuentin Monnet  * 	Return
26597aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
26607aa79a86SQuentin Monnet  *
2661bdb7b79bSAndrii Nakryiko  * long bpf_override_return(struct pt_regs *regs, u64 rc)
26627aa79a86SQuentin Monnet  * 	Description
26637aa79a86SQuentin Monnet  * 		Used for error injection, this helper uses kprobes to override
26647aa79a86SQuentin Monnet  * 		the return value of the probed function, and to set it to *rc*.
26657aa79a86SQuentin Monnet  * 		The first argument is the context *regs* on which the kprobe
26667aa79a86SQuentin Monnet  * 		works.
26677aa79a86SQuentin Monnet  *
2668ab8d7809SQuentin Monnet  * 		This helper works by setting the PC (program counter)
26697aa79a86SQuentin Monnet  * 		to an override function which is run in place of the original
26707aa79a86SQuentin Monnet  * 		probed function. This means the probed function is not run at
26717aa79a86SQuentin Monnet  * 		all. The replacement function just returns with the required
26727aa79a86SQuentin Monnet  * 		value.
26737aa79a86SQuentin Monnet  *
26747aa79a86SQuentin Monnet  * 		This helper has security implications, and thus is subject to
26757aa79a86SQuentin Monnet  * 		restrictions. It is only available if the kernel was compiled
26767aa79a86SQuentin Monnet  * 		with the **CONFIG_BPF_KPROBE_OVERRIDE** configuration
26777aa79a86SQuentin Monnet  * 		option, and in this case it only works on functions tagged with
26787aa79a86SQuentin Monnet  * 		**ALLOW_ERROR_INJECTION** in the kernel code.
26797aa79a86SQuentin Monnet  *
26807aa79a86SQuentin Monnet  * 		Also, the helper is only available for the architectures having
26817aa79a86SQuentin Monnet  * 		the CONFIG_FUNCTION_ERROR_INJECTION option. As of this writing,
26827aa79a86SQuentin Monnet  * 		x86 architecture is the only one to support this feature.
26837aa79a86SQuentin Monnet  * 	Return
26847aa79a86SQuentin Monnet  * 		0
26857aa79a86SQuentin Monnet  *
2686bdb7b79bSAndrii Nakryiko  * long bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *bpf_sock, int argval)
26877aa79a86SQuentin Monnet  * 	Description
26887aa79a86SQuentin Monnet  * 		Attempt to set the value of the **bpf_sock_ops_cb_flags** field
26897aa79a86SQuentin Monnet  * 		for the full TCP socket associated to *bpf_sock_ops* to
26907aa79a86SQuentin Monnet  * 		*argval*.
26917aa79a86SQuentin Monnet  *
26927aa79a86SQuentin Monnet  * 		The primary use of this field is to determine if there should
26937aa79a86SQuentin Monnet  * 		be calls to eBPF programs of type
26947aa79a86SQuentin Monnet  * 		**BPF_PROG_TYPE_SOCK_OPS** at various points in the TCP
26957aa79a86SQuentin Monnet  * 		code. A program of the same type can change its value, per
26967aa79a86SQuentin Monnet  * 		connection and as necessary, when the connection is
26977aa79a86SQuentin Monnet  * 		established. This field is directly accessible for reading, but
26987aa79a86SQuentin Monnet  * 		this helper must be used for updates in order to return an
26997aa79a86SQuentin Monnet  * 		error if an eBPF program tries to set a callback that is not
27007aa79a86SQuentin Monnet  * 		supported in the current kernel.
27017aa79a86SQuentin Monnet  *
2702725721a6SViet Hoang Tran  * 		*argval* is a flag array which can combine these flags:
27037aa79a86SQuentin Monnet  *
27047aa79a86SQuentin Monnet  * 		* **BPF_SOCK_OPS_RTO_CB_FLAG** (retransmission time out)
27057aa79a86SQuentin Monnet  * 		* **BPF_SOCK_OPS_RETRANS_CB_FLAG** (retransmission)
27067aa79a86SQuentin Monnet  * 		* **BPF_SOCK_OPS_STATE_CB_FLAG** (TCP state change)
270723729ff2SStanislav Fomichev  * 		* **BPF_SOCK_OPS_RTT_CB_FLAG** (every RTT)
27087aa79a86SQuentin Monnet  *
2709725721a6SViet Hoang Tran  * 		Therefore, this function can be used to clear a callback flag by
2710725721a6SViet Hoang Tran  * 		setting the appropriate bit to zero. e.g. to disable the RTO
2711725721a6SViet Hoang Tran  * 		callback:
2712725721a6SViet Hoang Tran  *
2713725721a6SViet Hoang Tran  * 		**bpf_sock_ops_cb_flags_set(bpf_sock,**
2714725721a6SViet Hoang Tran  * 			**bpf_sock->bpf_sock_ops_cb_flags & ~BPF_SOCK_OPS_RTO_CB_FLAG)**
2715725721a6SViet Hoang Tran  *
27167aa79a86SQuentin Monnet  * 		Here are some examples of where one could call such eBPF
27177aa79a86SQuentin Monnet  * 		program:
27187aa79a86SQuentin Monnet  *
27197aa79a86SQuentin Monnet  * 		* When RTO fires.
27207aa79a86SQuentin Monnet  * 		* When a packet is retransmitted.
27217aa79a86SQuentin Monnet  * 		* When the connection terminates.
27227aa79a86SQuentin Monnet  * 		* When a packet is sent.
27237aa79a86SQuentin Monnet  * 		* When a packet is received.
27247aa79a86SQuentin Monnet  * 	Return
27257aa79a86SQuentin Monnet  * 		Code **-EINVAL** if the socket is not a full TCP socket;
27267aa79a86SQuentin Monnet  * 		otherwise, a positive number containing the bits that could not
27277aa79a86SQuentin Monnet  * 		be set is returned (which comes down to 0 if all bits were set
27287aa79a86SQuentin Monnet  * 		as required).
27297aa79a86SQuentin Monnet  *
2730bdb7b79bSAndrii Nakryiko  * long bpf_msg_redirect_map(struct sk_msg_buff *msg, struct bpf_map *map, u32 key, u64 flags)
2731ab127040SQuentin Monnet  * 	Description
2732ab127040SQuentin Monnet  * 		This helper is used in programs implementing policies at the
2733ab127040SQuentin Monnet  * 		socket level. If the message *msg* is allowed to pass (i.e. if
2734ab127040SQuentin Monnet  * 		the verdict eBPF program returns **SK_PASS**), redirect it to
2735ab127040SQuentin Monnet  * 		the socket referenced by *map* (of type
2736ab127040SQuentin Monnet  * 		**BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
2737ab127040SQuentin Monnet  * 		egress interfaces can be used for redirection. The
2738ab127040SQuentin Monnet  * 		**BPF_F_INGRESS** value in *flags* is used to make the
2739ab127040SQuentin Monnet  * 		distinction (ingress path is selected if the flag is present,
2740ab127040SQuentin Monnet  * 		egress path otherwise). This is the only flag supported for now.
2741ab127040SQuentin Monnet  * 	Return
2742ab127040SQuentin Monnet  * 		**SK_PASS** on success, or **SK_DROP** on error.
2743ab127040SQuentin Monnet  *
2744bdb7b79bSAndrii Nakryiko  * long bpf_msg_apply_bytes(struct sk_msg_buff *msg, u32 bytes)
2745ab127040SQuentin Monnet  * 	Description
2746ab127040SQuentin Monnet  * 		For socket policies, apply the verdict of the eBPF program to
2747ab127040SQuentin Monnet  * 		the next *bytes* (number of bytes) of message *msg*.
2748ab127040SQuentin Monnet  *
2749ab127040SQuentin Monnet  * 		For example, this helper can be used in the following cases:
2750ab127040SQuentin Monnet  *
2751ab127040SQuentin Monnet  * 		* A single **sendmsg**\ () or **sendfile**\ () system call
2752ab127040SQuentin Monnet  * 		  contains multiple logical messages that the eBPF program is
2753ab127040SQuentin Monnet  * 		  supposed to read and for which it should apply a verdict.
2754ab127040SQuentin Monnet  * 		* An eBPF program only cares to read the first *bytes* of a
2755ab127040SQuentin Monnet  * 		  *msg*. If the message has a large payload, then setting up
2756ab127040SQuentin Monnet  * 		  and calling the eBPF program repeatedly for all bytes, even
2757ab127040SQuentin Monnet  * 		  though the verdict is already known, would create unnecessary
2758ab127040SQuentin Monnet  * 		  overhead.
2759ab127040SQuentin Monnet  *
2760ab127040SQuentin Monnet  * 		When called from within an eBPF program, the helper sets a
2761ab127040SQuentin Monnet  * 		counter internal to the BPF infrastructure, that is used to
2762ab127040SQuentin Monnet  * 		apply the last verdict to the next *bytes*. If *bytes* is
2763ab127040SQuentin Monnet  * 		smaller than the current data being processed from a
2764ab127040SQuentin Monnet  * 		**sendmsg**\ () or **sendfile**\ () system call, the first
2765ab127040SQuentin Monnet  * 		*bytes* will be sent and the eBPF program will be re-run with
2766ab127040SQuentin Monnet  * 		the pointer for start of data pointing to byte number *bytes*
2767ab127040SQuentin Monnet  * 		**+ 1**. If *bytes* is larger than the current data being
2768ab127040SQuentin Monnet  * 		processed, then the eBPF verdict will be applied to multiple
2769ab127040SQuentin Monnet  * 		**sendmsg**\ () or **sendfile**\ () calls until *bytes* are
2770ab127040SQuentin Monnet  * 		consumed.
2771ab127040SQuentin Monnet  *
2772ab127040SQuentin Monnet  * 		Note that if a socket closes with the internal counter holding
2773ab127040SQuentin Monnet  * 		a non-zero value, this is not a problem because data is not
2774ab127040SQuentin Monnet  * 		being buffered for *bytes* and is sent as it is received.
2775ab127040SQuentin Monnet  * 	Return
2776ab127040SQuentin Monnet  * 		0
2777ab127040SQuentin Monnet  *
2778bdb7b79bSAndrii Nakryiko  * long bpf_msg_cork_bytes(struct sk_msg_buff *msg, u32 bytes)
2779ab127040SQuentin Monnet  * 	Description
2780ab127040SQuentin Monnet  * 		For socket policies, prevent the execution of the verdict eBPF
2781ab127040SQuentin Monnet  * 		program for message *msg* until *bytes* (byte number) have been
2782ab127040SQuentin Monnet  * 		accumulated.
2783ab127040SQuentin Monnet  *
2784ab127040SQuentin Monnet  * 		This can be used when one needs a specific number of bytes
2785ab127040SQuentin Monnet  * 		before a verdict can be assigned, even if the data spans
2786ab127040SQuentin Monnet  * 		multiple **sendmsg**\ () or **sendfile**\ () calls. The extreme
2787ab127040SQuentin Monnet  * 		case would be a user calling **sendmsg**\ () repeatedly with
2788ab127040SQuentin Monnet  * 		1-byte long message segments. Obviously, this is bad for
2789ab127040SQuentin Monnet  * 		performance, but it is still valid. If the eBPF program needs
2790ab127040SQuentin Monnet  * 		*bytes* bytes to validate a header, this helper can be used to
2791ab127040SQuentin Monnet  * 		prevent the eBPF program to be called again until *bytes* have
2792ab127040SQuentin Monnet  * 		been accumulated.
2793ab127040SQuentin Monnet  * 	Return
2794ab127040SQuentin Monnet  * 		0
2795ab127040SQuentin Monnet  *
2796bdb7b79bSAndrii Nakryiko  * long bpf_msg_pull_data(struct sk_msg_buff *msg, u32 start, u32 end, u64 flags)
2797ab127040SQuentin Monnet  * 	Description
2798ab127040SQuentin Monnet  * 		For socket policies, pull in non-linear data from user space
2799ab127040SQuentin Monnet  * 		for *msg* and set pointers *msg*\ **->data** and *msg*\
2800ab127040SQuentin Monnet  * 		**->data_end** to *start* and *end* bytes offsets into *msg*,
2801ab127040SQuentin Monnet  * 		respectively.
2802ab127040SQuentin Monnet  *
2803ab127040SQuentin Monnet  * 		If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
2804ab127040SQuentin Monnet  * 		*msg* it can only parse data that the (**data**, **data_end**)
2805ab127040SQuentin Monnet  * 		pointers have already consumed. For **sendmsg**\ () hooks this
2806ab127040SQuentin Monnet  * 		is likely the first scatterlist element. But for calls relying
2807ab127040SQuentin Monnet  * 		on the **sendpage** handler (e.g. **sendfile**\ ()) this will
2808ab127040SQuentin Monnet  * 		be the range (**0**, **0**) because the data is shared with
2809ab127040SQuentin Monnet  * 		user space and by default the objective is to avoid allowing
2810ab127040SQuentin Monnet  * 		user space to modify data while (or after) eBPF verdict is
2811ab127040SQuentin Monnet  * 		being decided. This helper can be used to pull in data and to
2812ab127040SQuentin Monnet  * 		set the start and end pointer to given values. Data will be
2813ab127040SQuentin Monnet  * 		copied if necessary (i.e. if data was not linear and if start
2814ab127040SQuentin Monnet  * 		and end pointers do not point to the same chunk).
2815ab127040SQuentin Monnet  *
281632e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
2817ab127040SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
2818ab127040SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
2819ab127040SQuentin Monnet  * 		performed again, if the helper is used in combination with
2820ab127040SQuentin Monnet  * 		direct packet access.
2821ab127040SQuentin Monnet  *
2822ab127040SQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
2823ab127040SQuentin Monnet  * 		be left at zero.
2824ab127040SQuentin Monnet  * 	Return
2825ab127040SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2826ab127040SQuentin Monnet  *
2827bdb7b79bSAndrii Nakryiko  * long bpf_bind(struct bpf_sock_addr *ctx, struct sockaddr *addr, int addr_len)
28287aa79a86SQuentin Monnet  * 	Description
28297aa79a86SQuentin Monnet  * 		Bind the socket associated to *ctx* to the address pointed by
28307aa79a86SQuentin Monnet  * 		*addr*, of length *addr_len*. This allows for making outgoing
28317aa79a86SQuentin Monnet  * 		connection from the desired IP address, which can be useful for
28327aa79a86SQuentin Monnet  * 		example when all processes inside a cgroup should use one
28337aa79a86SQuentin Monnet  * 		single IP address on a host that has multiple IP configured.
28347aa79a86SQuentin Monnet  *
28357aa79a86SQuentin Monnet  * 		This helper works for IPv4 and IPv6, TCP and UDP sockets. The
28367aa79a86SQuentin Monnet  * 		domain (*addr*\ **->sa_family**) must be **AF_INET** (or
28378086fbafSStanislav Fomichev  * 		**AF_INET6**). It's advised to pass zero port (**sin_port**
28388086fbafSStanislav Fomichev  * 		or **sin6_port**) which triggers IP_BIND_ADDRESS_NO_PORT-like
28398086fbafSStanislav Fomichev  * 		behavior and lets the kernel efficiently pick up an unused
28408086fbafSStanislav Fomichev  * 		port as long as 4-tuple is unique. Passing non-zero port might
28418086fbafSStanislav Fomichev  * 		lead to degraded performance.
28427aa79a86SQuentin Monnet  * 	Return
28437aa79a86SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
28442d020dd7SQuentin Monnet  *
2845bdb7b79bSAndrii Nakryiko  * long bpf_xdp_adjust_tail(struct xdp_buff *xdp_md, int delta)
28462d020dd7SQuentin Monnet  * 	Description
28472d020dd7SQuentin Monnet  * 		Adjust (move) *xdp_md*\ **->data_end** by *delta* bytes. It is
2848c8741e2bSJesper Dangaard Brouer  * 		possible to both shrink and grow the packet tail.
2849c8741e2bSJesper Dangaard Brouer  * 		Shrink done via *delta* being a negative integer.
28502d020dd7SQuentin Monnet  *
285132e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
28522d020dd7SQuentin Monnet  * 		packet buffer. Therefore, at load time, all checks on pointers
28532d020dd7SQuentin Monnet  * 		previously done by the verifier are invalidated and must be
28542d020dd7SQuentin Monnet  * 		performed again, if the helper is used in combination with
28552d020dd7SQuentin Monnet  * 		direct packet access.
28562d020dd7SQuentin Monnet  * 	Return
28572d020dd7SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
28582d020dd7SQuentin Monnet  *
2859bdb7b79bSAndrii Nakryiko  * long bpf_skb_get_xfrm_state(struct sk_buff *skb, u32 index, struct bpf_xfrm_state *xfrm_state, u32 size, u64 flags)
28602d020dd7SQuentin Monnet  * 	Description
28612d020dd7SQuentin Monnet  * 		Retrieve the XFRM state (IP transform framework, see also
28622d020dd7SQuentin Monnet  * 		**ip-xfrm(8)**) at *index* in XFRM "security path" for *skb*.
28632d020dd7SQuentin Monnet  *
28642d020dd7SQuentin Monnet  * 		The retrieved value is stored in the **struct bpf_xfrm_state**
28652d020dd7SQuentin Monnet  * 		pointed by *xfrm_state* and of length *size*.
28662d020dd7SQuentin Monnet  *
28672d020dd7SQuentin Monnet  * 		All values for *flags* are reserved for future usage, and must
28682d020dd7SQuentin Monnet  * 		be left at zero.
28692d020dd7SQuentin Monnet  *
28702d020dd7SQuentin Monnet  * 		This helper is available only if the kernel was compiled with
28712d020dd7SQuentin Monnet  * 		**CONFIG_XFRM** configuration option.
28722d020dd7SQuentin Monnet  * 	Return
28732d020dd7SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
2874c195651eSYonghong Song  *
2875bdb7b79bSAndrii Nakryiko  * long bpf_get_stack(void *ctx, void *buf, u32 size, u64 flags)
2876c195651eSYonghong Song  * 	Description
2877c195651eSYonghong Song  * 		Return a user or a kernel stack in bpf program provided buffer.
2878c195651eSYonghong Song  * 		To achieve this, the helper needs *ctx*, which is a pointer
2879c195651eSYonghong Song  * 		to the context on which the tracing program is executed.
2880c195651eSYonghong Song  * 		To store the stacktrace, the bpf program provides *buf* with
2881c195651eSYonghong Song  * 		a nonnegative *size*.
2882c195651eSYonghong Song  *
2883c195651eSYonghong Song  * 		The last argument, *flags*, holds the number of stack frames to
2884c195651eSYonghong Song  * 		skip (from 0 to 255), masked with
2885c195651eSYonghong Song  * 		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
2886c195651eSYonghong Song  * 		the following flags:
2887c195651eSYonghong Song  *
2888c195651eSYonghong Song  * 		**BPF_F_USER_STACK**
2889c195651eSYonghong Song  * 			Collect a user space stack instead of a kernel stack.
2890c195651eSYonghong Song  * 		**BPF_F_USER_BUILD_ID**
2891c195651eSYonghong Song  * 			Collect buildid+offset instead of ips for user stack,
2892c195651eSYonghong Song  * 			only valid if **BPF_F_USER_STACK** is also specified.
2893c195651eSYonghong Song  *
2894c195651eSYonghong Song  * 		**bpf_get_stack**\ () can collect up to
2895c195651eSYonghong Song  * 		**PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
2896c195651eSYonghong Song  * 		to sufficient large buffer size. Note that
2897c195651eSYonghong Song  * 		this limit can be controlled with the **sysctl** program, and
2898c195651eSYonghong Song  * 		that it should be manually increased in order to profile long
2899c195651eSYonghong Song  * 		user stacks (such as stacks for Java programs). To do so, use:
2900c195651eSYonghong Song  *
2901c195651eSYonghong Song  * 		::
2902c195651eSYonghong Song  *
2903c195651eSYonghong Song  * 			# sysctl kernel.perf_event_max_stack=<new value>
2904c195651eSYonghong Song  * 	Return
29057a279e93SQuentin Monnet  * 		A non-negative value equal to or less than *size* on success,
29067a279e93SQuentin Monnet  * 		or a negative error in case of failure.
29074e1ec56cSDaniel Borkmann  *
2908bdb7b79bSAndrii Nakryiko  * long bpf_skb_load_bytes_relative(const void *skb, u32 offset, void *to, u32 len, u32 start_header)
29094e1ec56cSDaniel Borkmann  * 	Description
29104e1ec56cSDaniel Borkmann  * 		This helper is similar to **bpf_skb_load_bytes**\ () in that
29114e1ec56cSDaniel Borkmann  * 		it provides an easy way to load *len* bytes from *offset*
29124e1ec56cSDaniel Borkmann  * 		from the packet associated to *skb*, into the buffer pointed
29134e1ec56cSDaniel Borkmann  * 		by *to*. The difference to **bpf_skb_load_bytes**\ () is that
29144e1ec56cSDaniel Borkmann  * 		a fifth argument *start_header* exists in order to select a
29154e1ec56cSDaniel Borkmann  * 		base offset to start from. *start_header* can be one of:
29164e1ec56cSDaniel Borkmann  *
29174e1ec56cSDaniel Borkmann  * 		**BPF_HDR_START_MAC**
29184e1ec56cSDaniel Borkmann  * 			Base offset to load data from is *skb*'s mac header.
29194e1ec56cSDaniel Borkmann  * 		**BPF_HDR_START_NET**
29204e1ec56cSDaniel Borkmann  * 			Base offset to load data from is *skb*'s network header.
29214e1ec56cSDaniel Borkmann  *
29224e1ec56cSDaniel Borkmann  * 		In general, "direct packet access" is the preferred method to
29234e1ec56cSDaniel Borkmann  * 		access packet data, however, this helper is in particular useful
29244e1ec56cSDaniel Borkmann  * 		in socket filters where *skb*\ **->data** does not always point
29254e1ec56cSDaniel Borkmann  * 		to the start of the mac header and where "direct packet access"
29264e1ec56cSDaniel Borkmann  * 		is not available.
29274e1ec56cSDaniel Borkmann  * 	Return
29284e1ec56cSDaniel Borkmann  * 		0 on success, or a negative error in case of failure.
29294e1ec56cSDaniel Borkmann  *
2930bdb7b79bSAndrii Nakryiko  * long bpf_fib_lookup(void *ctx, struct bpf_fib_lookup *params, int plen, u32 flags)
293187f5fc7eSDavid Ahern  *	Description
293287f5fc7eSDavid Ahern  *		Do FIB lookup in kernel tables using parameters in *params*.
293387f5fc7eSDavid Ahern  *		If lookup is successful and result shows packet is to be
293487f5fc7eSDavid Ahern  *		forwarded, the neighbor tables are searched for the nexthop.
293587f5fc7eSDavid Ahern  *		If successful (ie., FIB lookup shows forwarding and nexthop
2936fa898d76SDavid Ahern  *		is resolved), the nexthop address is returned in ipv4_dst
2937fa898d76SDavid Ahern  *		or ipv6_dst based on family, smac is set to mac address of
2938fa898d76SDavid Ahern  *		egress device, dmac is set to nexthop mac address, rt_metric
29394c79579bSDavid Ahern  *		is set to metric from route (IPv4/IPv6 only), and ifindex
29404c79579bSDavid Ahern  *		is set to the device index of the nexthop from the FIB lookup.
294187f5fc7eSDavid Ahern  *
294287f5fc7eSDavid Ahern  *		*plen* argument is the size of the passed in struct.
29437a279e93SQuentin Monnet  *		*flags* argument can be a combination of one or more of the
29447a279e93SQuentin Monnet  *		following values:
294587f5fc7eSDavid Ahern  *
29467a279e93SQuentin Monnet  *		**BPF_FIB_LOOKUP_DIRECT**
29477a279e93SQuentin Monnet  *			Do a direct table lookup vs full lookup using FIB
29487a279e93SQuentin Monnet  *			rules.
29497a279e93SQuentin Monnet  *		**BPF_FIB_LOOKUP_OUTPUT**
29507a279e93SQuentin Monnet  *			Perform lookup from an egress perspective (default is
29517a279e93SQuentin Monnet  *			ingress).
295287f5fc7eSDavid Ahern  *
295387f5fc7eSDavid Ahern  *		*ctx* is either **struct xdp_md** for XDP programs or
295487f5fc7eSDavid Ahern  *		**struct sk_buff** tc cls_act programs.
295587f5fc7eSDavid Ahern  *	Return
29564c79579bSDavid Ahern  *		* < 0 if any input argument is invalid
29574c79579bSDavid Ahern  *		*   0 on success (packet is forwarded, nexthop neighbor exists)
29584c79579bSDavid Ahern  *		* > 0 one of **BPF_FIB_LKUP_RET_** codes explaining why the
29592bae79d2SQuentin Monnet  *		  packet is not forwarded or needs assist from full stack
296081110384SJohn Fastabend  *
2961e1850ea9SJesper Dangaard Brouer  *		If lookup fails with BPF_FIB_LKUP_RET_FRAG_NEEDED, then the MTU
2962e1850ea9SJesper Dangaard Brouer  *		was exceeded and output params->mtu_result contains the MTU.
2963e1850ea9SJesper Dangaard Brouer  *
2964bdb7b79bSAndrii Nakryiko  * long bpf_sock_hash_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
296581110384SJohn Fastabend  *	Description
296681110384SJohn Fastabend  *		Add an entry to, or update a sockhash *map* referencing sockets.
296781110384SJohn Fastabend  *		The *skops* is used as a new value for the entry associated to
296881110384SJohn Fastabend  *		*key*. *flags* is one of:
296981110384SJohn Fastabend  *
297081110384SJohn Fastabend  *		**BPF_NOEXIST**
297181110384SJohn Fastabend  *			The entry for *key* must not exist in the map.
297281110384SJohn Fastabend  *		**BPF_EXIST**
297381110384SJohn Fastabend  *			The entry for *key* must already exist in the map.
297481110384SJohn Fastabend  *		**BPF_ANY**
297581110384SJohn Fastabend  *			No condition on the existence of the entry for *key*.
297681110384SJohn Fastabend  *
297781110384SJohn Fastabend  *		If the *map* has eBPF programs (parser and verdict), those will
297881110384SJohn Fastabend  *		be inherited by the socket being added. If the socket is
297981110384SJohn Fastabend  *		already attached to eBPF programs, this results in an error.
298081110384SJohn Fastabend  *	Return
298181110384SJohn Fastabend  *		0 on success, or a negative error in case of failure.
298281110384SJohn Fastabend  *
2983bdb7b79bSAndrii Nakryiko  * long bpf_msg_redirect_hash(struct sk_msg_buff *msg, struct bpf_map *map, void *key, u64 flags)
298481110384SJohn Fastabend  *	Description
298581110384SJohn Fastabend  *		This helper is used in programs implementing policies at the
298681110384SJohn Fastabend  *		socket level. If the message *msg* is allowed to pass (i.e. if
298781110384SJohn Fastabend  *		the verdict eBPF program returns **SK_PASS**), redirect it to
298881110384SJohn Fastabend  *		the socket referenced by *map* (of type
298981110384SJohn Fastabend  *		**BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
299081110384SJohn Fastabend  *		egress interfaces can be used for redirection. The
299181110384SJohn Fastabend  *		**BPF_F_INGRESS** value in *flags* is used to make the
299281110384SJohn Fastabend  *		distinction (ingress path is selected if the flag is present,
299381110384SJohn Fastabend  *		egress path otherwise). This is the only flag supported for now.
299481110384SJohn Fastabend  *	Return
299581110384SJohn Fastabend  *		**SK_PASS** on success, or **SK_DROP** on error.
299681110384SJohn Fastabend  *
2997bdb7b79bSAndrii Nakryiko  * long bpf_sk_redirect_hash(struct sk_buff *skb, struct bpf_map *map, void *key, u64 flags)
299881110384SJohn Fastabend  *	Description
299981110384SJohn Fastabend  *		This helper is used in programs implementing policies at the
300081110384SJohn Fastabend  *		skb socket level. If the sk_buff *skb* is allowed to pass (i.e.
300149f3d12bSJakub Wilk  *		if the verdict eBPF program returns **SK_PASS**), redirect it
300281110384SJohn Fastabend  *		to the socket referenced by *map* (of type
300381110384SJohn Fastabend  *		**BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
300481110384SJohn Fastabend  *		egress interfaces can be used for redirection. The
300581110384SJohn Fastabend  *		**BPF_F_INGRESS** value in *flags* is used to make the
300681110384SJohn Fastabend  *		distinction (ingress path is selected if the flag is present,
300781110384SJohn Fastabend  *		egress otherwise). This is the only flag supported for now.
300881110384SJohn Fastabend  *	Return
300981110384SJohn Fastabend  *		**SK_PASS** on success, or **SK_DROP** on error.
3010fe94cc29SMathieu Xhonneux  *
3011bdb7b79bSAndrii Nakryiko  * long bpf_lwt_push_encap(struct sk_buff *skb, u32 type, void *hdr, u32 len)
3012fe94cc29SMathieu Xhonneux  *	Description
3013fe94cc29SMathieu Xhonneux  *		Encapsulate the packet associated to *skb* within a Layer 3
3014fe94cc29SMathieu Xhonneux  *		protocol header. This header is provided in the buffer at
3015fe94cc29SMathieu Xhonneux  *		address *hdr*, with *len* its size in bytes. *type* indicates
3016fe94cc29SMathieu Xhonneux  *		the protocol of the header and can be one of:
3017fe94cc29SMathieu Xhonneux  *
3018fe94cc29SMathieu Xhonneux  *		**BPF_LWT_ENCAP_SEG6**
3019fe94cc29SMathieu Xhonneux  *			IPv6 encapsulation with Segment Routing Header
3020fe94cc29SMathieu Xhonneux  *			(**struct ipv6_sr_hdr**). *hdr* only contains the SRH,
3021fe94cc29SMathieu Xhonneux  *			the IPv6 header is computed by the kernel.
3022fe94cc29SMathieu Xhonneux  *		**BPF_LWT_ENCAP_SEG6_INLINE**
3023fe94cc29SMathieu Xhonneux  *			Only works if *skb* contains an IPv6 packet. Insert a
3024fe94cc29SMathieu Xhonneux  *			Segment Routing Header (**struct ipv6_sr_hdr**) inside
3025fe94cc29SMathieu Xhonneux  *			the IPv6 header.
30263e0bd37cSPeter Oskolkov  *		**BPF_LWT_ENCAP_IP**
30273e0bd37cSPeter Oskolkov  *			IP encapsulation (GRE/GUE/IPIP/etc). The outer header
30283e0bd37cSPeter Oskolkov  *			must be IPv4 or IPv6, followed by zero or more
302980867c5eSQuentin Monnet  *			additional headers, up to **LWT_BPF_MAX_HEADROOM**
303080867c5eSQuentin Monnet  *			total bytes in all prepended headers. Please note that
303180867c5eSQuentin Monnet  *			if **skb_is_gso**\ (*skb*) is true, no more than two
303280867c5eSQuentin Monnet  *			headers can be prepended, and the inner header, if
303380867c5eSQuentin Monnet  *			present, should be either GRE or UDP/GUE.
30343e0bd37cSPeter Oskolkov  *
303580867c5eSQuentin Monnet  *		**BPF_LWT_ENCAP_SEG6**\ \* types can be called by BPF programs
303680867c5eSQuentin Monnet  *		of type **BPF_PROG_TYPE_LWT_IN**; **BPF_LWT_ENCAP_IP** type can
303780867c5eSQuentin Monnet  *		be called by bpf programs of types **BPF_PROG_TYPE_LWT_IN** and
303880867c5eSQuentin Monnet  *		**BPF_PROG_TYPE_LWT_XMIT**.
3039fe94cc29SMathieu Xhonneux  *
304032e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
3041fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
3042fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
3043fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
3044fe94cc29SMathieu Xhonneux  * 		direct packet access.
3045fe94cc29SMathieu Xhonneux  *	Return
3046fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
3047fe94cc29SMathieu Xhonneux  *
3048bdb7b79bSAndrii Nakryiko  * long bpf_lwt_seg6_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len)
3049fe94cc29SMathieu Xhonneux  *	Description
3050fe94cc29SMathieu Xhonneux  *		Store *len* bytes from address *from* into the packet
3051fe94cc29SMathieu Xhonneux  *		associated to *skb*, at *offset*. Only the flags, tag and TLVs
3052fe94cc29SMathieu Xhonneux  *		inside the outermost IPv6 Segment Routing Header can be
3053fe94cc29SMathieu Xhonneux  *		modified through this helper.
3054fe94cc29SMathieu Xhonneux  *
305532e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
3056fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
3057fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
3058fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
3059fe94cc29SMathieu Xhonneux  * 		direct packet access.
3060fe94cc29SMathieu Xhonneux  *	Return
3061fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
3062fe94cc29SMathieu Xhonneux  *
3063bdb7b79bSAndrii Nakryiko  * long bpf_lwt_seg6_adjust_srh(struct sk_buff *skb, u32 offset, s32 delta)
3064fe94cc29SMathieu Xhonneux  *	Description
3065fe94cc29SMathieu Xhonneux  *		Adjust the size allocated to TLVs in the outermost IPv6
3066fe94cc29SMathieu Xhonneux  *		Segment Routing Header contained in the packet associated to
3067fe94cc29SMathieu Xhonneux  *		*skb*, at position *offset* by *delta* bytes. Only offsets
3068fe94cc29SMathieu Xhonneux  *		after the segments are accepted. *delta* can be as well
3069fe94cc29SMathieu Xhonneux  *		positive (growing) as negative (shrinking).
3070fe94cc29SMathieu Xhonneux  *
307132e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
3072fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
3073fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
3074fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
3075fe94cc29SMathieu Xhonneux  * 		direct packet access.
3076fe94cc29SMathieu Xhonneux  *	Return
3077fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
3078fe94cc29SMathieu Xhonneux  *
3079bdb7b79bSAndrii Nakryiko  * long bpf_lwt_seg6_action(struct sk_buff *skb, u32 action, void *param, u32 param_len)
3080fe94cc29SMathieu Xhonneux  *	Description
3081fe94cc29SMathieu Xhonneux  *		Apply an IPv6 Segment Routing action of type *action* to the
3082fe94cc29SMathieu Xhonneux  *		packet associated to *skb*. Each action takes a parameter
3083fe94cc29SMathieu Xhonneux  *		contained at address *param*, and of length *param_len* bytes.
3084fe94cc29SMathieu Xhonneux  *		*action* can be one of:
3085fe94cc29SMathieu Xhonneux  *
3086fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_X**
3087fe94cc29SMathieu Xhonneux  *			End.X action: Endpoint with Layer-3 cross-connect.
3088fe94cc29SMathieu Xhonneux  *			Type of *param*: **struct in6_addr**.
3089fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_T**
3090fe94cc29SMathieu Xhonneux  *			End.T action: Endpoint with specific IPv6 table lookup.
3091fe94cc29SMathieu Xhonneux  *			Type of *param*: **int**.
3092fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_B6**
3093fe94cc29SMathieu Xhonneux  *			End.B6 action: Endpoint bound to an SRv6 policy.
309480867c5eSQuentin Monnet  *			Type of *param*: **struct ipv6_sr_hdr**.
3095fe94cc29SMathieu Xhonneux  *		**SEG6_LOCAL_ACTION_END_B6_ENCAP**
3096fe94cc29SMathieu Xhonneux  *			End.B6.Encap action: Endpoint bound to an SRv6
3097fe94cc29SMathieu Xhonneux  *			encapsulation policy.
309880867c5eSQuentin Monnet  *			Type of *param*: **struct ipv6_sr_hdr**.
3099fe94cc29SMathieu Xhonneux  *
310032e7dc28SQuentin Monnet  * 		A call to this helper is susceptible to change the underlying
3101fe94cc29SMathieu Xhonneux  * 		packet buffer. Therefore, at load time, all checks on pointers
3102fe94cc29SMathieu Xhonneux  * 		previously done by the verifier are invalidated and must be
3103fe94cc29SMathieu Xhonneux  * 		performed again, if the helper is used in combination with
3104fe94cc29SMathieu Xhonneux  * 		direct packet access.
3105fe94cc29SMathieu Xhonneux  *	Return
3106fe94cc29SMathieu Xhonneux  * 		0 on success, or a negative error in case of failure.
3107f4364dcfSSean Young  *
3108bdb7b79bSAndrii Nakryiko  * long bpf_rc_repeat(void *ctx)
310962369db2SQuentin Monnet  *	Description
311062369db2SQuentin Monnet  *		This helper is used in programs implementing IR decoding, to
311162369db2SQuentin Monnet  *		report a successfully decoded repeat key message. This delays
311262369db2SQuentin Monnet  *		the generation of a key up event for previously generated
311362369db2SQuentin Monnet  *		key down event.
311462369db2SQuentin Monnet  *
311562369db2SQuentin Monnet  *		Some IR protocols like NEC have a special IR message for
311662369db2SQuentin Monnet  *		repeating last button, for when a button is held down.
311762369db2SQuentin Monnet  *
311862369db2SQuentin Monnet  *		The *ctx* should point to the lirc sample as passed into
311962369db2SQuentin Monnet  *		the program.
312062369db2SQuentin Monnet  *
312162369db2SQuentin Monnet  *		This helper is only available is the kernel was compiled with
312262369db2SQuentin Monnet  *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
312362369db2SQuentin Monnet  *		"**y**".
312462369db2SQuentin Monnet  *	Return
312562369db2SQuentin Monnet  *		0
312662369db2SQuentin Monnet  *
3127bdb7b79bSAndrii Nakryiko  * long bpf_rc_keydown(void *ctx, u32 protocol, u64 scancode, u32 toggle)
3128f4364dcfSSean Young  *	Description
3129f4364dcfSSean Young  *		This helper is used in programs implementing IR decoding, to
3130f4364dcfSSean Young  *		report a successfully decoded key press with *scancode*,
3131f4364dcfSSean Young  *		*toggle* value in the given *protocol*. The scancode will be
3132f4364dcfSSean Young  *		translated to a keycode using the rc keymap, and reported as
3133f4364dcfSSean Young  *		an input key down event. After a period a key up event is
3134f4364dcfSSean Young  *		generated. This period can be extended by calling either
313590b1023fSQuentin Monnet  *		**bpf_rc_keydown**\ () again with the same values, or calling
313690b1023fSQuentin Monnet  *		**bpf_rc_repeat**\ ().
3137f4364dcfSSean Young  *
3138f4364dcfSSean Young  *		Some protocols include a toggle bit, in case the button was
3139f4364dcfSSean Young  *		released and pressed again between consecutive scancodes.
3140f4364dcfSSean Young  *
3141f4364dcfSSean Young  *		The *ctx* should point to the lirc sample as passed into
3142f4364dcfSSean Young  *		the program.
3143f4364dcfSSean Young  *
3144f4364dcfSSean Young  *		The *protocol* is the decoded protocol number (see
3145f4364dcfSSean Young  *		**enum rc_proto** for some predefined values).
3146f4364dcfSSean Young  *
3147f4364dcfSSean Young  *		This helper is only available is the kernel was compiled with
3148f4364dcfSSean Young  *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
3149f4364dcfSSean Young  *		"**y**".
3150f4364dcfSSean Young  *	Return
3151f4364dcfSSean Young  *		0
3152f4364dcfSSean Young  *
315362369db2SQuentin Monnet  * u64 bpf_skb_cgroup_id(struct sk_buff *skb)
3154cb20b08eSDaniel Borkmann  * 	Description
3155cb20b08eSDaniel Borkmann  * 		Return the cgroup v2 id of the socket associated with the *skb*.
3156cb20b08eSDaniel Borkmann  * 		This is roughly similar to the **bpf_get_cgroup_classid**\ ()
3157cb20b08eSDaniel Borkmann  * 		helper for cgroup v1 by providing a tag resp. identifier that
3158cb20b08eSDaniel Borkmann  * 		can be matched on or used for map lookups e.g. to implement
3159cb20b08eSDaniel Borkmann  * 		policy. The cgroup v2 id of a given path in the hierarchy is
3160cb20b08eSDaniel Borkmann  * 		exposed in user space through the f_handle API in order to get
3161cb20b08eSDaniel Borkmann  * 		to the same 64-bit id.
3162cb20b08eSDaniel Borkmann  *
3163cb20b08eSDaniel Borkmann  * 		This helper can be used on TC egress path, but not on ingress,
3164cb20b08eSDaniel Borkmann  * 		and is available only if the kernel was compiled with the
3165cb20b08eSDaniel Borkmann  * 		**CONFIG_SOCK_CGROUP_DATA** configuration option.
3166cb20b08eSDaniel Borkmann  * 	Return
3167cb20b08eSDaniel Borkmann  * 		The id is returned or 0 in case the id could not be retrieved.
3168bf6fa2c8SYonghong Song  *
3169bf6fa2c8SYonghong Song  * u64 bpf_get_current_cgroup_id(void)
3170bf6fa2c8SYonghong Song  * 	Return
3171bf6fa2c8SYonghong Song  * 		A 64-bit integer containing the current cgroup id based
3172bf6fa2c8SYonghong Song  * 		on the cgroup within which the current task is running.
3173cd339431SRoman Gushchin  *
317462369db2SQuentin Monnet  * void *bpf_get_local_storage(void *map, u64 flags)
3175cd339431SRoman Gushchin  *	Description
3176cd339431SRoman Gushchin  *		Get the pointer to the local storage area.
3177cd339431SRoman Gushchin  *		The type and the size of the local storage is defined
3178cd339431SRoman Gushchin  *		by the *map* argument.
3179cd339431SRoman Gushchin  *		The *flags* meaning is specific for each map type,
3180cd339431SRoman Gushchin  *		and has to be 0 for cgroup local storage.
3181cd339431SRoman Gushchin  *
318290b1023fSQuentin Monnet  *		Depending on the BPF program type, a local storage area
318390b1023fSQuentin Monnet  *		can be shared between multiple instances of the BPF program,
3184cd339431SRoman Gushchin  *		running simultaneously.
3185cd339431SRoman Gushchin  *
3186cd339431SRoman Gushchin  *		A user should care about the synchronization by himself.
318791c960b0SBrendan Jackman  *		For example, by using the **BPF_ATOMIC** instructions to alter
3188cd339431SRoman Gushchin  *		the shared data.
3189cd339431SRoman Gushchin  *	Return
319090b1023fSQuentin Monnet  *		A pointer to the local storage area.
31912dbb9b9eSMartin KaFai Lau  *
3192bdb7b79bSAndrii Nakryiko  * long bpf_sk_select_reuseport(struct sk_reuseport_md *reuse, struct bpf_map *map, void *key, u64 flags)
31932dbb9b9eSMartin KaFai Lau  *	Description
319490b1023fSQuentin Monnet  *		Select a **SO_REUSEPORT** socket from a
319590b1023fSQuentin Monnet  *		**BPF_MAP_TYPE_REUSEPORT_ARRAY** *map*.
319690b1023fSQuentin Monnet  *		It checks the selected socket is matching the incoming
319790b1023fSQuentin Monnet  *		request in the socket buffer.
31982dbb9b9eSMartin KaFai Lau  *	Return
31992dbb9b9eSMartin KaFai Lau  *		0 on success, or a negative error in case of failure.
32006acc9b43SJoe Stringer  *
320162369db2SQuentin Monnet  * u64 bpf_skb_ancestor_cgroup_id(struct sk_buff *skb, int ancestor_level)
320262369db2SQuentin Monnet  *	Description
320362369db2SQuentin Monnet  *		Return id of cgroup v2 that is ancestor of cgroup associated
320462369db2SQuentin Monnet  *		with the *skb* at the *ancestor_level*.  The root cgroup is at
320562369db2SQuentin Monnet  *		*ancestor_level* zero and each step down the hierarchy
320662369db2SQuentin Monnet  *		increments the level. If *ancestor_level* == level of cgroup
320762369db2SQuentin Monnet  *		associated with *skb*, then return value will be same as that
320862369db2SQuentin Monnet  *		of **bpf_skb_cgroup_id**\ ().
320962369db2SQuentin Monnet  *
321062369db2SQuentin Monnet  *		The helper is useful to implement policies based on cgroups
321162369db2SQuentin Monnet  *		that are upper in hierarchy than immediate cgroup associated
321262369db2SQuentin Monnet  *		with *skb*.
321362369db2SQuentin Monnet  *
321462369db2SQuentin Monnet  *		The format of returned id and helper limitations are same as in
321562369db2SQuentin Monnet  *		**bpf_skb_cgroup_id**\ ().
321662369db2SQuentin Monnet  *	Return
321762369db2SQuentin Monnet  *		The id is returned or 0 in case the id could not be retrieved.
321862369db2SQuentin Monnet  *
3219f71c6143SJoe Stringer  * struct bpf_sock *bpf_sk_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
32206acc9b43SJoe Stringer  *	Description
32216acc9b43SJoe Stringer  *		Look for TCP socket matching *tuple*, optionally in a child
32226acc9b43SJoe Stringer  *		network namespace *netns*. The return value must be checked,
322390b1023fSQuentin Monnet  *		and if non-**NULL**, released via **bpf_sk_release**\ ().
32246acc9b43SJoe Stringer  *
32256acc9b43SJoe Stringer  *		The *ctx* should point to the context of the program, such as
32266acc9b43SJoe Stringer  *		the skb or socket (depending on the hook in use). This is used
32276acc9b43SJoe Stringer  *		to determine the base network namespace for the lookup.
32286acc9b43SJoe Stringer  *
32296acc9b43SJoe Stringer  *		*tuple_size* must be one of:
32306acc9b43SJoe Stringer  *
32316acc9b43SJoe Stringer  *		**sizeof**\ (*tuple*\ **->ipv4**)
32326acc9b43SJoe Stringer  *			Look for an IPv4 socket.
32336acc9b43SJoe Stringer  *		**sizeof**\ (*tuple*\ **->ipv6**)
32346acc9b43SJoe Stringer  *			Look for an IPv6 socket.
32356acc9b43SJoe Stringer  *
3236f71c6143SJoe Stringer  *		If the *netns* is a negative signed 32-bit integer, then the
3237bfdfa517SRandy Dunlap  *		socket lookup table in the netns associated with the *ctx*
3238f71c6143SJoe Stringer  *		will be used. For the TC hooks, this is the netns of the device
3239f71c6143SJoe Stringer  *		in the skb. For socket hooks, this is the netns of the socket.
3240f71c6143SJoe Stringer  *		If *netns* is any other signed 32-bit value greater than or
3241f71c6143SJoe Stringer  *		equal to zero then it specifies the ID of the netns relative to
3242f71c6143SJoe Stringer  *		the netns associated with the *ctx*. *netns* values beyond the
3243f71c6143SJoe Stringer  *		range of 32-bit integers are reserved for future use.
32446acc9b43SJoe Stringer  *
32456acc9b43SJoe Stringer  *		All values for *flags* are reserved for future usage, and must
32466acc9b43SJoe Stringer  *		be left at zero.
32476acc9b43SJoe Stringer  *
32486acc9b43SJoe Stringer  *		This helper is available only if the kernel was compiled with
32496acc9b43SJoe Stringer  *		**CONFIG_NET** configuration option.
32506acc9b43SJoe Stringer  *	Return
32510bd72117SDaniel Borkmann  *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
32520bd72117SDaniel Borkmann  *		For sockets with reuseport option, the **struct bpf_sock**
325380867c5eSQuentin Monnet  *		result is from *reuse*\ **->socks**\ [] using the hash of the
325480867c5eSQuentin Monnet  *		tuple.
32556acc9b43SJoe Stringer  *
3256f71c6143SJoe Stringer  * struct bpf_sock *bpf_sk_lookup_udp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
32576acc9b43SJoe Stringer  *	Description
32586acc9b43SJoe Stringer  *		Look for UDP socket matching *tuple*, optionally in a child
32596acc9b43SJoe Stringer  *		network namespace *netns*. The return value must be checked,
326090b1023fSQuentin Monnet  *		and if non-**NULL**, released via **bpf_sk_release**\ ().
32616acc9b43SJoe Stringer  *
32626acc9b43SJoe Stringer  *		The *ctx* should point to the context of the program, such as
32636acc9b43SJoe Stringer  *		the skb or socket (depending on the hook in use). This is used
32646acc9b43SJoe Stringer  *		to determine the base network namespace for the lookup.
32656acc9b43SJoe Stringer  *
32666acc9b43SJoe Stringer  *		*tuple_size* must be one of:
32676acc9b43SJoe Stringer  *
32686acc9b43SJoe Stringer  *		**sizeof**\ (*tuple*\ **->ipv4**)
32696acc9b43SJoe Stringer  *			Look for an IPv4 socket.
32706acc9b43SJoe Stringer  *		**sizeof**\ (*tuple*\ **->ipv6**)
32716acc9b43SJoe Stringer  *			Look for an IPv6 socket.
32726acc9b43SJoe Stringer  *
3273f71c6143SJoe Stringer  *		If the *netns* is a negative signed 32-bit integer, then the
3274bfdfa517SRandy Dunlap  *		socket lookup table in the netns associated with the *ctx*
3275f71c6143SJoe Stringer  *		will be used. For the TC hooks, this is the netns of the device
3276f71c6143SJoe Stringer  *		in the skb. For socket hooks, this is the netns of the socket.
3277f71c6143SJoe Stringer  *		If *netns* is any other signed 32-bit value greater than or
3278f71c6143SJoe Stringer  *		equal to zero then it specifies the ID of the netns relative to
3279f71c6143SJoe Stringer  *		the netns associated with the *ctx*. *netns* values beyond the
3280f71c6143SJoe Stringer  *		range of 32-bit integers are reserved for future use.
32816acc9b43SJoe Stringer  *
32826acc9b43SJoe Stringer  *		All values for *flags* are reserved for future usage, and must
32836acc9b43SJoe Stringer  *		be left at zero.
32846acc9b43SJoe Stringer  *
32856acc9b43SJoe Stringer  *		This helper is available only if the kernel was compiled with
32866acc9b43SJoe Stringer  *		**CONFIG_NET** configuration option.
32876acc9b43SJoe Stringer  *	Return
32880bd72117SDaniel Borkmann  *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
32890bd72117SDaniel Borkmann  *		For sockets with reuseport option, the **struct bpf_sock**
329080867c5eSQuentin Monnet  *		result is from *reuse*\ **->socks**\ [] using the hash of the
329180867c5eSQuentin Monnet  *		tuple.
32926acc9b43SJoe Stringer  *
3293a5fa25adSMartin KaFai Lau  * long bpf_sk_release(void *sock)
32946acc9b43SJoe Stringer  *	Description
329590b1023fSQuentin Monnet  *		Release the reference held by *sock*. *sock* must be a
329690b1023fSQuentin Monnet  *		non-**NULL** pointer that was returned from
329790b1023fSQuentin Monnet  *		**bpf_sk_lookup_xxx**\ ().
329890b1023fSQuentin Monnet  *	Return
329990b1023fSQuentin Monnet  *		0 on success, or a negative error in case of failure.
330090b1023fSQuentin Monnet  *
3301bdb7b79bSAndrii Nakryiko  * long bpf_map_push_elem(struct bpf_map *map, const void *value, u64 flags)
330262369db2SQuentin Monnet  * 	Description
330362369db2SQuentin Monnet  * 		Push an element *value* in *map*. *flags* is one of:
330462369db2SQuentin Monnet  *
330562369db2SQuentin Monnet  * 		**BPF_EXIST**
330662369db2SQuentin Monnet  * 			If the queue/stack is full, the oldest element is
330762369db2SQuentin Monnet  * 			removed to make room for this.
330862369db2SQuentin Monnet  * 	Return
330962369db2SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
331062369db2SQuentin Monnet  *
3311bdb7b79bSAndrii Nakryiko  * long bpf_map_pop_elem(struct bpf_map *map, void *value)
331290b1023fSQuentin Monnet  * 	Description
331390b1023fSQuentin Monnet  * 		Pop an element from *map*.
331490b1023fSQuentin Monnet  * 	Return
331590b1023fSQuentin Monnet  * 		0 on success, or a negative error in case of failure.
331690b1023fSQuentin Monnet  *
3317bdb7b79bSAndrii Nakryiko  * long bpf_map_peek_elem(struct bpf_map *map, void *value)
331890b1023fSQuentin Monnet  * 	Description
331990b1023fSQuentin Monnet  * 		Get an element from *map* without removing it.
33206acc9b43SJoe Stringer  * 	Return
33216acc9b43SJoe Stringer  * 		0 on success, or a negative error in case of failure.
33226fff607eSJohn Fastabend  *
3323bdb7b79bSAndrii Nakryiko  * long bpf_msg_push_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)
33246fff607eSJohn Fastabend  *	Description
332590b1023fSQuentin Monnet  *		For socket policies, insert *len* bytes into *msg* at offset
33266fff607eSJohn Fastabend  *		*start*.
33276fff607eSJohn Fastabend  *
33286fff607eSJohn Fastabend  *		If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
332990b1023fSQuentin Monnet  *		*msg* it may want to insert metadata or options into the *msg*.
33306fff607eSJohn Fastabend  *		This can later be read and used by any of the lower layer BPF
33316fff607eSJohn Fastabend  *		hooks.
33326fff607eSJohn Fastabend  *
33336fff607eSJohn Fastabend  *		This helper may fail if under memory pressure (a malloc
33346fff607eSJohn Fastabend  *		fails) in these cases BPF programs will get an appropriate
33356fff607eSJohn Fastabend  *		error and BPF programs will need to handle them.
33366fff607eSJohn Fastabend  *	Return
33376fff607eSJohn Fastabend  *		0 on success, or a negative error in case of failure.
33387246d8edSJohn Fastabend  *
3339bdb7b79bSAndrii Nakryiko  * long bpf_msg_pop_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)
33407246d8edSJohn Fastabend  *	Description
33415f0e5412SAndrii Nakryiko  *		Will remove *len* bytes from a *msg* starting at byte *start*.
33427246d8edSJohn Fastabend  *		This may result in **ENOMEM** errors under certain situations if
33437246d8edSJohn Fastabend  *		an allocation and copy are required due to a full ring buffer.
33447246d8edSJohn Fastabend  *		However, the helper will try to avoid doing the allocation
33457246d8edSJohn Fastabend  *		if possible. Other errors can occur if input parameters are
334690b1023fSQuentin Monnet  *		invalid either due to *start* byte not being valid part of *msg*
33477246d8edSJohn Fastabend  *		payload and/or *pop* value being to large.
33487246d8edSJohn Fastabend  *	Return
334990b1023fSQuentin Monnet  *		0 on success, or a negative error in case of failure.
335001d3240aSSean Young  *
3351bdb7b79bSAndrii Nakryiko  * long bpf_rc_pointer_rel(void *ctx, s32 rel_x, s32 rel_y)
335201d3240aSSean Young  *	Description
335301d3240aSSean Young  *		This helper is used in programs implementing IR decoding, to
335401d3240aSSean Young  *		report a successfully decoded pointer movement.
335501d3240aSSean Young  *
335601d3240aSSean Young  *		The *ctx* should point to the lirc sample as passed into
335701d3240aSSean Young  *		the program.
335801d3240aSSean Young  *
335901d3240aSSean Young  *		This helper is only available is the kernel was compiled with
336001d3240aSSean Young  *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
336101d3240aSSean Young  *		"**y**".
336201d3240aSSean Young  *	Return
336301d3240aSSean Young  *		0
336446f8bc92SMartin KaFai Lau  *
3365bdb7b79bSAndrii Nakryiko  * long bpf_spin_lock(struct bpf_spin_lock *lock)
33660eb09785SQuentin Monnet  *	Description
33670eb09785SQuentin Monnet  *		Acquire a spinlock represented by the pointer *lock*, which is
33680eb09785SQuentin Monnet  *		stored as part of a value of a map. Taking the lock allows to
33690eb09785SQuentin Monnet  *		safely update the rest of the fields in that value. The
33700eb09785SQuentin Monnet  *		spinlock can (and must) later be released with a call to
33710eb09785SQuentin Monnet  *		**bpf_spin_unlock**\ (\ *lock*\ ).
33720eb09785SQuentin Monnet  *
33730eb09785SQuentin Monnet  *		Spinlocks in BPF programs come with a number of restrictions
33740eb09785SQuentin Monnet  *		and constraints:
33750eb09785SQuentin Monnet  *
33760eb09785SQuentin Monnet  *		* **bpf_spin_lock** objects are only allowed inside maps of
33770eb09785SQuentin Monnet  *		  types **BPF_MAP_TYPE_HASH** and **BPF_MAP_TYPE_ARRAY** (this
33780eb09785SQuentin Monnet  *		  list could be extended in the future).
33790eb09785SQuentin Monnet  *		* BTF description of the map is mandatory.
33800eb09785SQuentin Monnet  *		* The BPF program can take ONE lock at a time, since taking two
33810eb09785SQuentin Monnet  *		  or more could cause dead locks.
33820eb09785SQuentin Monnet  *		* Only one **struct bpf_spin_lock** is allowed per map element.
33830eb09785SQuentin Monnet  *		* When the lock is taken, calls (either BPF to BPF or helpers)
33840eb09785SQuentin Monnet  *		  are not allowed.
33850eb09785SQuentin Monnet  *		* The **BPF_LD_ABS** and **BPF_LD_IND** instructions are not
33860eb09785SQuentin Monnet  *		  allowed inside a spinlock-ed region.
33870eb09785SQuentin Monnet  *		* The BPF program MUST call **bpf_spin_unlock**\ () to release
33880eb09785SQuentin Monnet  *		  the lock, on all execution paths, before it returns.
33890eb09785SQuentin Monnet  *		* The BPF program can access **struct bpf_spin_lock** only via
33900eb09785SQuentin Monnet  *		  the **bpf_spin_lock**\ () and **bpf_spin_unlock**\ ()
33910eb09785SQuentin Monnet  *		  helpers. Loading or storing data into the **struct
33920eb09785SQuentin Monnet  *		  bpf_spin_lock** *lock*\ **;** field of a map is not allowed.
33930eb09785SQuentin Monnet  *		* To use the **bpf_spin_lock**\ () helper, the BTF description
33940eb09785SQuentin Monnet  *		  of the map value must be a struct and have **struct
33950eb09785SQuentin Monnet  *		  bpf_spin_lock** *anyname*\ **;** field at the top level.
33960eb09785SQuentin Monnet  *		  Nested lock inside another struct is not allowed.
33970eb09785SQuentin Monnet  *		* The **struct bpf_spin_lock** *lock* field in a map value must
33980eb09785SQuentin Monnet  *		  be aligned on a multiple of 4 bytes in that value.
33990eb09785SQuentin Monnet  *		* Syscall with command **BPF_MAP_LOOKUP_ELEM** does not copy
34000eb09785SQuentin Monnet  *		  the **bpf_spin_lock** field to user space.
34010eb09785SQuentin Monnet  *		* Syscall with command **BPF_MAP_UPDATE_ELEM**, or update from
34020eb09785SQuentin Monnet  *		  a BPF program, do not update the **bpf_spin_lock** field.
34030eb09785SQuentin Monnet  *		* **bpf_spin_lock** cannot be on the stack or inside a
34040eb09785SQuentin Monnet  *		  networking packet (it can only be inside of a map values).
34050eb09785SQuentin Monnet  *		* **bpf_spin_lock** is available to root only.
34060eb09785SQuentin Monnet  *		* Tracing programs and socket filter programs cannot use
34070eb09785SQuentin Monnet  *		  **bpf_spin_lock**\ () due to insufficient preemption checks
34080eb09785SQuentin Monnet  *		  (but this may change in the future).
34090eb09785SQuentin Monnet  *		* **bpf_spin_lock** is not allowed in inner maps of map-in-map.
34100eb09785SQuentin Monnet  *	Return
34110eb09785SQuentin Monnet  *		0
34120eb09785SQuentin Monnet  *
3413bdb7b79bSAndrii Nakryiko  * long bpf_spin_unlock(struct bpf_spin_lock *lock)
34140eb09785SQuentin Monnet  *	Description
34150eb09785SQuentin Monnet  *		Release the *lock* previously locked by a call to
34160eb09785SQuentin Monnet  *		**bpf_spin_lock**\ (\ *lock*\ ).
34170eb09785SQuentin Monnet  *	Return
34180eb09785SQuentin Monnet  *		0
34190eb09785SQuentin Monnet  *
342046f8bc92SMartin KaFai Lau  * struct bpf_sock *bpf_sk_fullsock(struct bpf_sock *sk)
342146f8bc92SMartin KaFai Lau  *	Description
342246f8bc92SMartin KaFai Lau  *		This helper gets a **struct bpf_sock** pointer such
342362369db2SQuentin Monnet  *		that all the fields in this **bpf_sock** can be accessed.
342446f8bc92SMartin KaFai Lau  *	Return
342562369db2SQuentin Monnet  *		A **struct bpf_sock** pointer on success, or **NULL** in
342646f8bc92SMartin KaFai Lau  *		case of failure.
3427655a51e5SMartin KaFai Lau  *
3428655a51e5SMartin KaFai Lau  * struct bpf_tcp_sock *bpf_tcp_sock(struct bpf_sock *sk)
3429655a51e5SMartin KaFai Lau  *	Description
3430655a51e5SMartin KaFai Lau  *		This helper gets a **struct bpf_tcp_sock** pointer from a
3431655a51e5SMartin KaFai Lau  *		**struct bpf_sock** pointer.
3432655a51e5SMartin KaFai Lau  *	Return
343362369db2SQuentin Monnet  *		A **struct bpf_tcp_sock** pointer on success, or **NULL** in
3434655a51e5SMartin KaFai Lau  *		case of failure.
3435f7c917baSbrakmo  *
3436bdb7b79bSAndrii Nakryiko  * long bpf_skb_ecn_set_ce(struct sk_buff *skb)
3437f7c917baSbrakmo  *	Description
343862369db2SQuentin Monnet  *		Set ECN (Explicit Congestion Notification) field of IP header
343962369db2SQuentin Monnet  *		to **CE** (Congestion Encountered) if current value is **ECT**
344062369db2SQuentin Monnet  *		(ECN Capable Transport). Otherwise, do nothing. Works with IPv6
344162369db2SQuentin Monnet  *		and IPv4.
3442f7c917baSbrakmo  *	Return
344362369db2SQuentin Monnet  *		1 if the **CE** flag is set (either by the current helper call
344462369db2SQuentin Monnet  *		or because it was already present), 0 if it is not set.
3445dbafd7ddSMartin KaFai Lau  *
3446dbafd7ddSMartin KaFai Lau  * struct bpf_sock *bpf_get_listener_sock(struct bpf_sock *sk)
3447dbafd7ddSMartin KaFai Lau  *	Description
344862369db2SQuentin Monnet  *		Return a **struct bpf_sock** pointer in **TCP_LISTEN** state.
344962369db2SQuentin Monnet  *		**bpf_sk_release**\ () is unnecessary and not allowed.
3450dbafd7ddSMartin KaFai Lau  *	Return
345162369db2SQuentin Monnet  *		A **struct bpf_sock** pointer on success, or **NULL** in
3452dbafd7ddSMartin KaFai Lau  *		case of failure.
3453edbf8c01SLorenz Bauer  *
3454edbf8c01SLorenz Bauer  * struct bpf_sock *bpf_skc_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
3455edbf8c01SLorenz Bauer  *	Description
3456edbf8c01SLorenz Bauer  *		Look for TCP socket matching *tuple*, optionally in a child
3457edbf8c01SLorenz Bauer  *		network namespace *netns*. The return value must be checked,
3458edbf8c01SLorenz Bauer  *		and if non-**NULL**, released via **bpf_sk_release**\ ().
3459edbf8c01SLorenz Bauer  *
346080867c5eSQuentin Monnet  *		This function is identical to **bpf_sk_lookup_tcp**\ (), except
346180867c5eSQuentin Monnet  *		that it also returns timewait or request sockets. Use
346280867c5eSQuentin Monnet  *		**bpf_sk_fullsock**\ () or **bpf_tcp_sock**\ () to access the
346380867c5eSQuentin Monnet  *		full structure.
3464edbf8c01SLorenz Bauer  *
3465edbf8c01SLorenz Bauer  *		This helper is available only if the kernel was compiled with
3466edbf8c01SLorenz Bauer  *		**CONFIG_NET** configuration option.
3467edbf8c01SLorenz Bauer  *	Return
3468edbf8c01SLorenz Bauer  *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
3469edbf8c01SLorenz Bauer  *		For sockets with reuseport option, the **struct bpf_sock**
347080867c5eSQuentin Monnet  *		result is from *reuse*\ **->socks**\ [] using the hash of the
347180867c5eSQuentin Monnet  *		tuple.
347239904084SLorenz Bauer  *
3473c0df236eSMartin KaFai Lau  * long bpf_tcp_check_syncookie(void *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
347439904084SLorenz Bauer  * 	Description
347580867c5eSQuentin Monnet  * 		Check whether *iph* and *th* contain a valid SYN cookie ACK for
347680867c5eSQuentin Monnet  * 		the listening socket in *sk*.
347739904084SLorenz Bauer  *
347880867c5eSQuentin Monnet  * 		*iph* points to the start of the IPv4 or IPv6 header, while
347980867c5eSQuentin Monnet  * 		*iph_len* contains **sizeof**\ (**struct iphdr**) or
348080867c5eSQuentin Monnet  * 		**sizeof**\ (**struct ip6hdr**).
348139904084SLorenz Bauer  *
348280867c5eSQuentin Monnet  * 		*th* points to the start of the TCP header, while *th_len*
348380867c5eSQuentin Monnet  * 		contains **sizeof**\ (**struct tcphdr**).
348439904084SLorenz Bauer  * 	Return
348580867c5eSQuentin Monnet  * 		0 if *iph* and *th* are a valid SYN cookie ACK, or a negative
348680867c5eSQuentin Monnet  * 		error otherwise.
3487808649fbSAndrey Ignatov  *
3488bdb7b79bSAndrii Nakryiko  * long bpf_sysctl_get_name(struct bpf_sysctl *ctx, char *buf, size_t buf_len, u64 flags)
3489808649fbSAndrey Ignatov  *	Description
3490808649fbSAndrey Ignatov  *		Get name of sysctl in /proc/sys/ and copy it into provided by
3491808649fbSAndrey Ignatov  *		program buffer *buf* of size *buf_len*.
3492808649fbSAndrey Ignatov  *
3493808649fbSAndrey Ignatov  *		The buffer is always NUL terminated, unless it's zero-sized.
3494808649fbSAndrey Ignatov  *
3495808649fbSAndrey Ignatov  *		If *flags* is zero, full name (e.g. "net/ipv4/tcp_mem") is
3496808649fbSAndrey Ignatov  *		copied. Use **BPF_F_SYSCTL_BASE_NAME** flag to copy base name
3497808649fbSAndrey Ignatov  *		only (e.g. "tcp_mem").
3498808649fbSAndrey Ignatov  *	Return
3499808649fbSAndrey Ignatov  *		Number of character copied (not including the trailing NUL).
3500808649fbSAndrey Ignatov  *
3501808649fbSAndrey Ignatov  *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
3502808649fbSAndrey Ignatov  *		truncated name in this case).
35031d11b301SAndrey Ignatov  *
3504bdb7b79bSAndrii Nakryiko  * long bpf_sysctl_get_current_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)
35051d11b301SAndrey Ignatov  *	Description
35061d11b301SAndrey Ignatov  *		Get current value of sysctl as it is presented in /proc/sys
35071d11b301SAndrey Ignatov  *		(incl. newline, etc), and copy it as a string into provided
35081d11b301SAndrey Ignatov  *		by program buffer *buf* of size *buf_len*.
35091d11b301SAndrey Ignatov  *
35101d11b301SAndrey Ignatov  *		The whole value is copied, no matter what file position user
35111d11b301SAndrey Ignatov  *		space issued e.g. sys_read at.
35121d11b301SAndrey Ignatov  *
35131d11b301SAndrey Ignatov  *		The buffer is always NUL terminated, unless it's zero-sized.
35141d11b301SAndrey Ignatov  *	Return
35151d11b301SAndrey Ignatov  *		Number of character copied (not including the trailing NUL).
35161d11b301SAndrey Ignatov  *
35171d11b301SAndrey Ignatov  *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
35181d11b301SAndrey Ignatov  *		truncated name in this case).
35191d11b301SAndrey Ignatov  *
35201d11b301SAndrey Ignatov  *		**-EINVAL** if current value was unavailable, e.g. because
35211d11b301SAndrey Ignatov  *		sysctl is uninitialized and read returns -EIO for it.
35224e63acdfSAndrey Ignatov  *
3523bdb7b79bSAndrii Nakryiko  * long bpf_sysctl_get_new_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)
35244e63acdfSAndrey Ignatov  *	Description
35254e63acdfSAndrey Ignatov  *		Get new value being written by user space to sysctl (before
35264e63acdfSAndrey Ignatov  *		the actual write happens) and copy it as a string into
35274e63acdfSAndrey Ignatov  *		provided by program buffer *buf* of size *buf_len*.
35284e63acdfSAndrey Ignatov  *
35294e63acdfSAndrey Ignatov  *		User space may write new value at file position > 0.
35304e63acdfSAndrey Ignatov  *
35314e63acdfSAndrey Ignatov  *		The buffer is always NUL terminated, unless it's zero-sized.
35324e63acdfSAndrey Ignatov  *	Return
35334e63acdfSAndrey Ignatov  *		Number of character copied (not including the trailing NUL).
35344e63acdfSAndrey Ignatov  *
35354e63acdfSAndrey Ignatov  *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
35364e63acdfSAndrey Ignatov  *		truncated name in this case).
35374e63acdfSAndrey Ignatov  *
35384e63acdfSAndrey Ignatov  *		**-EINVAL** if sysctl is being read.
35394e63acdfSAndrey Ignatov  *
3540bdb7b79bSAndrii Nakryiko  * long bpf_sysctl_set_new_value(struct bpf_sysctl *ctx, const char *buf, size_t buf_len)
35414e63acdfSAndrey Ignatov  *	Description
35424e63acdfSAndrey Ignatov  *		Override new value being written by user space to sysctl with
35434e63acdfSAndrey Ignatov  *		value provided by program in buffer *buf* of size *buf_len*.
35444e63acdfSAndrey Ignatov  *
35454e63acdfSAndrey Ignatov  *		*buf* should contain a string in same form as provided by user
35464e63acdfSAndrey Ignatov  *		space on sysctl write.
35474e63acdfSAndrey Ignatov  *
35484e63acdfSAndrey Ignatov  *		User space may write new value at file position > 0. To override
35494e63acdfSAndrey Ignatov  *		the whole sysctl value file position should be set to zero.
35504e63acdfSAndrey Ignatov  *	Return
35514e63acdfSAndrey Ignatov  *		0 on success.
35524e63acdfSAndrey Ignatov  *
35534e63acdfSAndrey Ignatov  *		**-E2BIG** if the *buf_len* is too big.
35544e63acdfSAndrey Ignatov  *
35554e63acdfSAndrey Ignatov  *		**-EINVAL** if sysctl is being read.
3556d7a4cb9bSAndrey Ignatov  *
3557bdb7b79bSAndrii Nakryiko  * long bpf_strtol(const char *buf, size_t buf_len, u64 flags, long *res)
3558d7a4cb9bSAndrey Ignatov  *	Description
3559d7a4cb9bSAndrey Ignatov  *		Convert the initial part of the string from buffer *buf* of
3560d7a4cb9bSAndrey Ignatov  *		size *buf_len* to a long integer according to the given base
3561d7a4cb9bSAndrey Ignatov  *		and save the result in *res*.
3562d7a4cb9bSAndrey Ignatov  *
3563d7a4cb9bSAndrey Ignatov  *		The string may begin with an arbitrary amount of white space
356480867c5eSQuentin Monnet  *		(as determined by **isspace**\ (3)) followed by a single
356580867c5eSQuentin Monnet  *		optional '**-**' sign.
3566d7a4cb9bSAndrey Ignatov  *
3567d7a4cb9bSAndrey Ignatov  *		Five least significant bits of *flags* encode base, other bits
3568d7a4cb9bSAndrey Ignatov  *		are currently unused.
3569d7a4cb9bSAndrey Ignatov  *
3570d7a4cb9bSAndrey Ignatov  *		Base must be either 8, 10, 16 or 0 to detect it automatically
357180867c5eSQuentin Monnet  *		similar to user space **strtol**\ (3).
3572d7a4cb9bSAndrey Ignatov  *	Return
3573d7a4cb9bSAndrey Ignatov  *		Number of characters consumed on success. Must be positive but
357480867c5eSQuentin Monnet  *		no more than *buf_len*.
3575d7a4cb9bSAndrey Ignatov  *
3576d7a4cb9bSAndrey Ignatov  *		**-EINVAL** if no valid digits were found or unsupported base
3577d7a4cb9bSAndrey Ignatov  *		was provided.
3578d7a4cb9bSAndrey Ignatov  *
3579d7a4cb9bSAndrey Ignatov  *		**-ERANGE** if resulting value was out of range.
3580d7a4cb9bSAndrey Ignatov  *
3581bdb7b79bSAndrii Nakryiko  * long bpf_strtoul(const char *buf, size_t buf_len, u64 flags, unsigned long *res)
3582d7a4cb9bSAndrey Ignatov  *	Description
3583d7a4cb9bSAndrey Ignatov  *		Convert the initial part of the string from buffer *buf* of
3584d7a4cb9bSAndrey Ignatov  *		size *buf_len* to an unsigned long integer according to the
3585d7a4cb9bSAndrey Ignatov  *		given base and save the result in *res*.
3586d7a4cb9bSAndrey Ignatov  *
3587d7a4cb9bSAndrey Ignatov  *		The string may begin with an arbitrary amount of white space
358880867c5eSQuentin Monnet  *		(as determined by **isspace**\ (3)).
3589d7a4cb9bSAndrey Ignatov  *
3590d7a4cb9bSAndrey Ignatov  *		Five least significant bits of *flags* encode base, other bits
3591d7a4cb9bSAndrey Ignatov  *		are currently unused.
3592d7a4cb9bSAndrey Ignatov  *
3593d7a4cb9bSAndrey Ignatov  *		Base must be either 8, 10, 16 or 0 to detect it automatically
359480867c5eSQuentin Monnet  *		similar to user space **strtoul**\ (3).
3595d7a4cb9bSAndrey Ignatov  *	Return
3596d7a4cb9bSAndrey Ignatov  *		Number of characters consumed on success. Must be positive but
359780867c5eSQuentin Monnet  *		no more than *buf_len*.
3598d7a4cb9bSAndrey Ignatov  *
3599d7a4cb9bSAndrey Ignatov  *		**-EINVAL** if no valid digits were found or unsupported base
3600d7a4cb9bSAndrey Ignatov  *		was provided.
3601d7a4cb9bSAndrey Ignatov  *
3602d7a4cb9bSAndrey Ignatov  *		**-ERANGE** if resulting value was out of range.
36036ac99e8fSMartin KaFai Lau  *
360430897832SKP Singh  * void *bpf_sk_storage_get(struct bpf_map *map, void *sk, void *value, u64 flags)
36056ac99e8fSMartin KaFai Lau  *	Description
360680867c5eSQuentin Monnet  *		Get a bpf-local-storage from a *sk*.
36076ac99e8fSMartin KaFai Lau  *
36086ac99e8fSMartin KaFai Lau  *		Logically, it could be thought of getting the value from
36096ac99e8fSMartin KaFai Lau  *		a *map* with *sk* as the **key**.  From this
36106ac99e8fSMartin KaFai Lau  *		perspective,  the usage is not much different from
361180867c5eSQuentin Monnet  *		**bpf_map_lookup_elem**\ (*map*, **&**\ *sk*) except this
361280867c5eSQuentin Monnet  *		helper enforces the key must be a full socket and the map must
361380867c5eSQuentin Monnet  *		be a **BPF_MAP_TYPE_SK_STORAGE** also.
36146ac99e8fSMartin KaFai Lau  *
36156ac99e8fSMartin KaFai Lau  *		Underneath, the value is stored locally at *sk* instead of
361680867c5eSQuentin Monnet  *		the *map*.  The *map* is used as the bpf-local-storage
361780867c5eSQuentin Monnet  *		"type". The bpf-local-storage "type" (i.e. the *map*) is
361880867c5eSQuentin Monnet  *		searched against all bpf-local-storages residing at *sk*.
36196ac99e8fSMartin KaFai Lau  *
362030897832SKP Singh  *		*sk* is a kernel **struct sock** pointer for LSM program.
362130897832SKP Singh  *		*sk* is a **struct bpf_sock** pointer for other program types.
362230897832SKP Singh  *
362380867c5eSQuentin Monnet  *		An optional *flags* (**BPF_SK_STORAGE_GET_F_CREATE**) can be
36246ac99e8fSMartin KaFai Lau  *		used such that a new bpf-local-storage will be
36256ac99e8fSMartin KaFai Lau  *		created if one does not exist.  *value* can be used
362680867c5eSQuentin Monnet  *		together with **BPF_SK_STORAGE_GET_F_CREATE** to specify
36276ac99e8fSMartin KaFai Lau  *		the initial value of a bpf-local-storage.  If *value* is
362880867c5eSQuentin Monnet  *		**NULL**, the new bpf-local-storage will be zero initialized.
36296ac99e8fSMartin KaFai Lau  *	Return
36306ac99e8fSMartin KaFai Lau  *		A bpf-local-storage pointer is returned on success.
36316ac99e8fSMartin KaFai Lau  *
36326ac99e8fSMartin KaFai Lau  *		**NULL** if not found or there was an error in adding
36336ac99e8fSMartin KaFai Lau  *		a new bpf-local-storage.
36346ac99e8fSMartin KaFai Lau  *
363530897832SKP Singh  * long bpf_sk_storage_delete(struct bpf_map *map, void *sk)
36366ac99e8fSMartin KaFai Lau  *	Description
363780867c5eSQuentin Monnet  *		Delete a bpf-local-storage from a *sk*.
36386ac99e8fSMartin KaFai Lau  *	Return
36396ac99e8fSMartin KaFai Lau  *		0 on success.
36406ac99e8fSMartin KaFai Lau  *
36416ac99e8fSMartin KaFai Lau  *		**-ENOENT** if the bpf-local-storage cannot be found.
3642592a3498SMartin KaFai Lau  *		**-EINVAL** if sk is not a fullsock (e.g. a request_sock).
36438b401f9eSYonghong Song  *
3644bdb7b79bSAndrii Nakryiko  * long bpf_send_signal(u32 sig)
36458b401f9eSYonghong Song  *	Description
36468482941fSYonghong Song  *		Send signal *sig* to the process of the current task.
36478482941fSYonghong Song  *		The signal may be delivered to any of this process's threads.
36488b401f9eSYonghong Song  *	Return
36498b401f9eSYonghong Song  *		0 on success or successfully queued.
36508b401f9eSYonghong Song  *
36518b401f9eSYonghong Song  *		**-EBUSY** if work queue under nmi is full.
36528b401f9eSYonghong Song  *
36538b401f9eSYonghong Song  *		**-EINVAL** if *sig* is invalid.
36548b401f9eSYonghong Song  *
36558b401f9eSYonghong Song  *		**-EPERM** if no permission to send the *sig*.
36568b401f9eSYonghong Song  *
36578b401f9eSYonghong Song  *		**-EAGAIN** if bpf program can try again.
365870d66244SPetar Penkov  *
3659c0df236eSMartin KaFai Lau  * s64 bpf_tcp_gen_syncookie(void *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
366070d66244SPetar Penkov  *	Description
366170d66244SPetar Penkov  *		Try to issue a SYN cookie for the packet with corresponding
366270d66244SPetar Penkov  *		IP/TCP headers, *iph* and *th*, on the listening socket in *sk*.
366370d66244SPetar Penkov  *
366470d66244SPetar Penkov  *		*iph* points to the start of the IPv4 or IPv6 header, while
366570d66244SPetar Penkov  *		*iph_len* contains **sizeof**\ (**struct iphdr**) or
366670d66244SPetar Penkov  *		**sizeof**\ (**struct ip6hdr**).
366770d66244SPetar Penkov  *
366870d66244SPetar Penkov  *		*th* points to the start of the TCP header, while *th_len*
366970d66244SPetar Penkov  *		contains the length of the TCP header.
367070d66244SPetar Penkov  *	Return
367170d66244SPetar Penkov  *		On success, lower 32 bits hold the generated SYN cookie in
367270d66244SPetar Penkov  *		followed by 16 bits which hold the MSS value for that cookie,
367370d66244SPetar Penkov  *		and the top 16 bits are unused.
367470d66244SPetar Penkov  *
367570d66244SPetar Penkov  *		On failure, the returned value is one of the following:
367670d66244SPetar Penkov  *
367770d66244SPetar Penkov  *		**-EINVAL** SYN cookie cannot be issued due to error
367870d66244SPetar Penkov  *
367970d66244SPetar Penkov  *		**-ENOENT** SYN cookie should not be issued (no SYN flood)
368070d66244SPetar Penkov  *
368170d66244SPetar Penkov  *		**-EOPNOTSUPP** kernel configuration does not enable SYN cookies
368270d66244SPetar Penkov  *
368370d66244SPetar Penkov  *		**-EPROTONOSUPPORT** IP packet version is not 4 or 6
3684a7658e1aSAlexei Starovoitov  *
3685bdb7b79bSAndrii Nakryiko  * long bpf_skb_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
3686a7658e1aSAlexei Starovoitov  * 	Description
3687a7658e1aSAlexei Starovoitov  * 		Write raw *data* blob into a special BPF perf event held by
3688a7658e1aSAlexei Starovoitov  * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
3689a7658e1aSAlexei Starovoitov  * 		event must have the following attributes: **PERF_SAMPLE_RAW**
3690a7658e1aSAlexei Starovoitov  * 		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
3691a7658e1aSAlexei Starovoitov  * 		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
3692a7658e1aSAlexei Starovoitov  *
3693a7658e1aSAlexei Starovoitov  * 		The *flags* are used to indicate the index in *map* for which
3694a7658e1aSAlexei Starovoitov  * 		the value must be put, masked with **BPF_F_INDEX_MASK**.
3695a7658e1aSAlexei Starovoitov  * 		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
3696a7658e1aSAlexei Starovoitov  * 		to indicate that the index of the current CPU core should be
3697a7658e1aSAlexei Starovoitov  * 		used.
3698a7658e1aSAlexei Starovoitov  *
3699a7658e1aSAlexei Starovoitov  * 		The value to write, of *size*, is passed through eBPF stack and
3700a7658e1aSAlexei Starovoitov  * 		pointed by *data*.
3701a7658e1aSAlexei Starovoitov  *
3702a7658e1aSAlexei Starovoitov  * 		*ctx* is a pointer to in-kernel struct sk_buff.
3703a7658e1aSAlexei Starovoitov  *
3704a7658e1aSAlexei Starovoitov  * 		This helper is similar to **bpf_perf_event_output**\ () but
3705a7658e1aSAlexei Starovoitov  * 		restricted to raw_tracepoint bpf programs.
3706a7658e1aSAlexei Starovoitov  * 	Return
3707a7658e1aSAlexei Starovoitov  * 		0 on success, or a negative error in case of failure.
37086ae08ae3SDaniel Borkmann  *
3709bdb7b79bSAndrii Nakryiko  * long bpf_probe_read_user(void *dst, u32 size, const void *unsafe_ptr)
37106ae08ae3SDaniel Borkmann  * 	Description
37116ae08ae3SDaniel Borkmann  * 		Safely attempt to read *size* bytes from user space address
37126ae08ae3SDaniel Borkmann  * 		*unsafe_ptr* and store the data in *dst*.
37136ae08ae3SDaniel Borkmann  * 	Return
37146ae08ae3SDaniel Borkmann  * 		0 on success, or a negative error in case of failure.
37156ae08ae3SDaniel Borkmann  *
3716bdb7b79bSAndrii Nakryiko  * long bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
37176ae08ae3SDaniel Borkmann  * 	Description
37186ae08ae3SDaniel Borkmann  * 		Safely attempt to read *size* bytes from kernel space address
37196ae08ae3SDaniel Borkmann  * 		*unsafe_ptr* and store the data in *dst*.
37206ae08ae3SDaniel Borkmann  * 	Return
37216ae08ae3SDaniel Borkmann  * 		0 on success, or a negative error in case of failure.
37226ae08ae3SDaniel Borkmann  *
3723bdb7b79bSAndrii Nakryiko  * long bpf_probe_read_user_str(void *dst, u32 size, const void *unsafe_ptr)
37246ae08ae3SDaniel Borkmann  * 	Description
37256ae08ae3SDaniel Borkmann  * 		Copy a NUL terminated string from an unsafe user address
37266ae08ae3SDaniel Borkmann  * 		*unsafe_ptr* to *dst*. The *size* should include the
37276ae08ae3SDaniel Borkmann  * 		terminating NUL byte. In case the string length is smaller than
37286ae08ae3SDaniel Borkmann  * 		*size*, the target is not padded with further NUL bytes. If the
37296ae08ae3SDaniel Borkmann  * 		string length is larger than *size*, just *size*-1 bytes are
37306ae08ae3SDaniel Borkmann  * 		copied and the last byte is set to NUL.
37316ae08ae3SDaniel Borkmann  *
3732c6458e72SBrendan Jackman  * 		On success, returns the number of bytes that were written,
3733c6458e72SBrendan Jackman  * 		including the terminal NUL. This makes this helper useful in
3734c6458e72SBrendan Jackman  * 		tracing programs for reading strings, and more importantly to
3735c6458e72SBrendan Jackman  * 		get its length at runtime. See the following snippet:
37366ae08ae3SDaniel Borkmann  *
37376ae08ae3SDaniel Borkmann  * 		::
37386ae08ae3SDaniel Borkmann  *
37396ae08ae3SDaniel Borkmann  * 			SEC("kprobe/sys_open")
37406ae08ae3SDaniel Borkmann  * 			void bpf_sys_open(struct pt_regs *ctx)
37416ae08ae3SDaniel Borkmann  * 			{
37426ae08ae3SDaniel Borkmann  * 			        char buf[PATHLEN]; // PATHLEN is defined to 256
37436ae08ae3SDaniel Borkmann  * 			        int res = bpf_probe_read_user_str(buf, sizeof(buf),
37446ae08ae3SDaniel Borkmann  * 				                                  ctx->di);
37456ae08ae3SDaniel Borkmann  *
37466ae08ae3SDaniel Borkmann  * 				// Consume buf, for example push it to
37476ae08ae3SDaniel Borkmann  * 				// userspace via bpf_perf_event_output(); we
37486ae08ae3SDaniel Borkmann  * 				// can use res (the string length) as event
37496ae08ae3SDaniel Borkmann  * 				// size, after checking its boundaries.
37506ae08ae3SDaniel Borkmann  * 			}
37516ae08ae3SDaniel Borkmann  *
3752ab8d7809SQuentin Monnet  * 		In comparison, using **bpf_probe_read_user**\ () helper here
37536ae08ae3SDaniel Borkmann  * 		instead to read the string would require to estimate the length
37546ae08ae3SDaniel Borkmann  * 		at compile time, and would often result in copying more memory
37556ae08ae3SDaniel Borkmann  * 		than necessary.
37566ae08ae3SDaniel Borkmann  *
37576ae08ae3SDaniel Borkmann  * 		Another useful use case is when parsing individual process
37586ae08ae3SDaniel Borkmann  * 		arguments or individual environment variables navigating
37596ae08ae3SDaniel Borkmann  * 		*current*\ **->mm->arg_start** and *current*\
37606ae08ae3SDaniel Borkmann  * 		**->mm->env_start**: using this helper and the return value,
37616ae08ae3SDaniel Borkmann  * 		one can quickly iterate at the right offset of the memory area.
37626ae08ae3SDaniel Borkmann  * 	Return
3763c6458e72SBrendan Jackman  * 		On success, the strictly positive length of the output string,
37646ae08ae3SDaniel Borkmann  * 		including the trailing NUL character. On error, a negative
37656ae08ae3SDaniel Borkmann  * 		value.
37666ae08ae3SDaniel Borkmann  *
3767bdb7b79bSAndrii Nakryiko  * long bpf_probe_read_kernel_str(void *dst, u32 size, const void *unsafe_ptr)
37686ae08ae3SDaniel Borkmann  * 	Description
37696ae08ae3SDaniel Borkmann  * 		Copy a NUL terminated string from an unsafe kernel address *unsafe_ptr*
3770ab8d7809SQuentin Monnet  * 		to *dst*. Same semantics as with **bpf_probe_read_user_str**\ () apply.
37716ae08ae3SDaniel Borkmann  * 	Return
37726ae08ae3SDaniel Borkmann  * 		On success, the strictly positive length of the string, including
37736ae08ae3SDaniel Borkmann  * 		the trailing NUL character. On error, a negative value.
3774206057feSMartin KaFai Lau  *
3775bdb7b79bSAndrii Nakryiko  * long bpf_tcp_send_ack(void *tp, u32 rcv_nxt)
3776206057feSMartin KaFai Lau  *	Description
3777ab8d7809SQuentin Monnet  *		Send out a tcp-ack. *tp* is the in-kernel struct **tcp_sock**.
3778206057feSMartin KaFai Lau  *		*rcv_nxt* is the ack_seq to be sent out.
3779206057feSMartin KaFai Lau  *	Return
3780206057feSMartin KaFai Lau  *		0 on success, or a negative error in case of failure.
3781206057feSMartin KaFai Lau  *
3782bdb7b79bSAndrii Nakryiko  * long bpf_send_signal_thread(u32 sig)
37838482941fSYonghong Song  *	Description
37848482941fSYonghong Song  *		Send signal *sig* to the thread corresponding to the current task.
37858482941fSYonghong Song  *	Return
37868482941fSYonghong Song  *		0 on success or successfully queued.
37878482941fSYonghong Song  *
37888482941fSYonghong Song  *		**-EBUSY** if work queue under nmi is full.
37898482941fSYonghong Song  *
37908482941fSYonghong Song  *		**-EINVAL** if *sig* is invalid.
37918482941fSYonghong Song  *
37928482941fSYonghong Song  *		**-EPERM** if no permission to send the *sig*.
37938482941fSYonghong Song  *
37948482941fSYonghong Song  *		**-EAGAIN** if bpf program can try again.
37955576b991SMartin KaFai Lau  *
37965576b991SMartin KaFai Lau  * u64 bpf_jiffies64(void)
37975576b991SMartin KaFai Lau  *	Description
37985576b991SMartin KaFai Lau  *		Obtain the 64bit jiffies
37995576b991SMartin KaFai Lau  *	Return
38005576b991SMartin KaFai Lau  *		The 64 bit jiffies
3801fff7b643SDaniel Xu  *
3802bdb7b79bSAndrii Nakryiko  * long bpf_read_branch_records(struct bpf_perf_event_data *ctx, void *buf, u32 size, u64 flags)
3803fff7b643SDaniel Xu  *	Description
3804fff7b643SDaniel Xu  *		For an eBPF program attached to a perf event, retrieve the
3805ab8d7809SQuentin Monnet  *		branch records (**struct perf_branch_entry**) associated to *ctx*
3806fff7b643SDaniel Xu  *		and store it in the buffer pointed by *buf* up to size
3807fff7b643SDaniel Xu  *		*size* bytes.
3808fff7b643SDaniel Xu  *	Return
3809fff7b643SDaniel Xu  *		On success, number of bytes written to *buf*. On error, a
3810fff7b643SDaniel Xu  *		negative value.
3811fff7b643SDaniel Xu  *
3812fff7b643SDaniel Xu  *		The *flags* can be set to **BPF_F_GET_BRANCH_RECORDS_SIZE** to
3813fff7b643SDaniel Xu  *		instead return the number of bytes required to store all the
3814fff7b643SDaniel Xu  *		branch entries. If this flag is set, *buf* may be NULL.
3815fff7b643SDaniel Xu  *
3816fff7b643SDaniel Xu  *		**-EINVAL** if arguments invalid or **size** not a multiple
3817ab8d7809SQuentin Monnet  *		of **sizeof**\ (**struct perf_branch_entry**\ ).
3818fff7b643SDaniel Xu  *
3819fff7b643SDaniel Xu  *		**-ENOENT** if architecture does not support branch records.
3820b4490c5cSCarlos Neira  *
3821bdb7b79bSAndrii Nakryiko  * long bpf_get_ns_current_pid_tgid(u64 dev, u64 ino, struct bpf_pidns_info *nsdata, u32 size)
3822b4490c5cSCarlos Neira  *	Description
3823b4490c5cSCarlos Neira  *		Returns 0 on success, values for *pid* and *tgid* as seen from the current
3824b4490c5cSCarlos Neira  *		*namespace* will be returned in *nsdata*.
3825ab8d7809SQuentin Monnet  *	Return
3826ab8d7809SQuentin Monnet  *		0 on success, or one of the following in case of failure:
3827b4490c5cSCarlos Neira  *
3828b4490c5cSCarlos Neira  *		**-EINVAL** if dev and inum supplied don't match dev_t and inode number
3829b4490c5cSCarlos Neira  *              with nsfs of current task, or if dev conversion to dev_t lost high bits.
3830b4490c5cSCarlos Neira  *
3831b4490c5cSCarlos Neira  *		**-ENOENT** if pidns does not exists for the current task.
3832b4490c5cSCarlos Neira  *
3833bdb7b79bSAndrii Nakryiko  * long bpf_xdp_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
3834d831ee84SEelco Chaudron  *	Description
3835d831ee84SEelco Chaudron  *		Write raw *data* blob into a special BPF perf event held by
3836d831ee84SEelco Chaudron  *		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
3837d831ee84SEelco Chaudron  *		event must have the following attributes: **PERF_SAMPLE_RAW**
3838d831ee84SEelco Chaudron  *		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
3839d831ee84SEelco Chaudron  *		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
3840d831ee84SEelco Chaudron  *
3841d831ee84SEelco Chaudron  *		The *flags* are used to indicate the index in *map* for which
3842d831ee84SEelco Chaudron  *		the value must be put, masked with **BPF_F_INDEX_MASK**.
3843d831ee84SEelco Chaudron  *		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
3844d831ee84SEelco Chaudron  *		to indicate that the index of the current CPU core should be
3845d831ee84SEelco Chaudron  *		used.
3846d831ee84SEelco Chaudron  *
3847d831ee84SEelco Chaudron  *		The value to write, of *size*, is passed through eBPF stack and
3848d831ee84SEelco Chaudron  *		pointed by *data*.
3849d831ee84SEelco Chaudron  *
3850d831ee84SEelco Chaudron  *		*ctx* is a pointer to in-kernel struct xdp_buff.
3851d831ee84SEelco Chaudron  *
3852d831ee84SEelco Chaudron  *		This helper is similar to **bpf_perf_eventoutput**\ () but
3853d831ee84SEelco Chaudron  *		restricted to raw_tracepoint bpf programs.
3854d831ee84SEelco Chaudron  *	Return
3855d831ee84SEelco Chaudron  *		0 on success, or a negative error in case of failure.
3856f318903cSDaniel Borkmann  *
3857f318903cSDaniel Borkmann  * u64 bpf_get_netns_cookie(void *ctx)
3858f318903cSDaniel Borkmann  * 	Description
3859f318903cSDaniel Borkmann  * 		Retrieve the cookie (generated by the kernel) of the network
3860f318903cSDaniel Borkmann  * 		namespace the input *ctx* is associated with. The network
3861f318903cSDaniel Borkmann  * 		namespace cookie remains stable for its lifetime and provides
3862f318903cSDaniel Borkmann  * 		a global identifier that can be assumed unique. If *ctx* is
3863f318903cSDaniel Borkmann  * 		NULL, then the helper returns the cookie for the initial
3864f318903cSDaniel Borkmann  * 		network namespace. The cookie itself is very similar to that
3865ab8d7809SQuentin Monnet  * 		of **bpf_get_socket_cookie**\ () helper, but for network
3866ab8d7809SQuentin Monnet  * 		namespaces instead of sockets.
3867f318903cSDaniel Borkmann  * 	Return
3868f318903cSDaniel Borkmann  * 		A 8-byte long opaque number.
38690f09abd1SDaniel Borkmann  *
38700f09abd1SDaniel Borkmann  * u64 bpf_get_current_ancestor_cgroup_id(int ancestor_level)
38710f09abd1SDaniel Borkmann  * 	Description
38720f09abd1SDaniel Borkmann  * 		Return id of cgroup v2 that is ancestor of the cgroup associated
38730f09abd1SDaniel Borkmann  * 		with the current task at the *ancestor_level*. The root cgroup
38740f09abd1SDaniel Borkmann  * 		is at *ancestor_level* zero and each step down the hierarchy
38750f09abd1SDaniel Borkmann  * 		increments the level. If *ancestor_level* == level of cgroup
38760f09abd1SDaniel Borkmann  * 		associated with the current task, then return value will be the
38770f09abd1SDaniel Borkmann  * 		same as that of **bpf_get_current_cgroup_id**\ ().
38780f09abd1SDaniel Borkmann  *
38790f09abd1SDaniel Borkmann  * 		The helper is useful to implement policies based on cgroups
38800f09abd1SDaniel Borkmann  * 		that are upper in hierarchy than immediate cgroup associated
38810f09abd1SDaniel Borkmann  * 		with the current task.
38820f09abd1SDaniel Borkmann  *
38830f09abd1SDaniel Borkmann  * 		The format of returned id and helper limitations are same as in
38840f09abd1SDaniel Borkmann  * 		**bpf_get_current_cgroup_id**\ ().
38850f09abd1SDaniel Borkmann  * 	Return
38860f09abd1SDaniel Borkmann  * 		The id is returned or 0 in case the id could not be retrieved.
3887cf7fbe66SJoe Stringer  *
388827e5203bSMartin KaFai Lau  * long bpf_sk_assign(struct sk_buff *skb, void *sk, u64 flags)
3889cf7fbe66SJoe Stringer  *	Description
3890e9ddbb77SJakub Sitnicki  *		Helper is overloaded depending on BPF program type. This
3891e9ddbb77SJakub Sitnicki  *		description applies to **BPF_PROG_TYPE_SCHED_CLS** and
3892e9ddbb77SJakub Sitnicki  *		**BPF_PROG_TYPE_SCHED_ACT** programs.
3893e9ddbb77SJakub Sitnicki  *
3894cf7fbe66SJoe Stringer  *		Assign the *sk* to the *skb*. When combined with appropriate
3895cf7fbe66SJoe Stringer  *		routing configuration to receive the packet towards the socket,
3896cf7fbe66SJoe Stringer  *		will cause *skb* to be delivered to the specified socket.
3897cf7fbe66SJoe Stringer  *		Subsequent redirection of *skb* via  **bpf_redirect**\ (),
3898cf7fbe66SJoe Stringer  *		**bpf_clone_redirect**\ () or other methods outside of BPF may
3899cf7fbe66SJoe Stringer  *		interfere with successful delivery to the socket.
3900cf7fbe66SJoe Stringer  *
3901cf7fbe66SJoe Stringer  *		This operation is only valid from TC ingress path.
3902cf7fbe66SJoe Stringer  *
3903cf7fbe66SJoe Stringer  *		The *flags* argument must be zero.
3904cf7fbe66SJoe Stringer  *	Return
3905ab8d7809SQuentin Monnet  *		0 on success, or a negative error in case of failure:
3906cf7fbe66SJoe Stringer  *
3907ab8d7809SQuentin Monnet  *		**-EINVAL** if specified *flags* are not supported.
3908ab8d7809SQuentin Monnet  *
3909ab8d7809SQuentin Monnet  *		**-ENOENT** if the socket is unavailable for assignment.
3910ab8d7809SQuentin Monnet  *
3911ab8d7809SQuentin Monnet  *		**-ENETUNREACH** if the socket is unreachable (wrong netns).
3912ab8d7809SQuentin Monnet  *
3913ab8d7809SQuentin Monnet  *		**-EOPNOTSUPP** if the operation is not supported, for example
3914ab8d7809SQuentin Monnet  *		a call from outside of TC ingress.
3915ab8d7809SQuentin Monnet  *
3916ab8d7809SQuentin Monnet  *		**-ESOCKTNOSUPPORT** if the socket type is not supported
3917ab8d7809SQuentin Monnet  *		(reuseport).
391871d19214SMaciej Żenczykowski  *
3919e9ddbb77SJakub Sitnicki  * long bpf_sk_assign(struct bpf_sk_lookup *ctx, struct bpf_sock *sk, u64 flags)
3920e9ddbb77SJakub Sitnicki  *	Description
3921e9ddbb77SJakub Sitnicki  *		Helper is overloaded depending on BPF program type. This
3922e9ddbb77SJakub Sitnicki  *		description applies to **BPF_PROG_TYPE_SK_LOOKUP** programs.
3923e9ddbb77SJakub Sitnicki  *
3924e9ddbb77SJakub Sitnicki  *		Select the *sk* as a result of a socket lookup.
3925e9ddbb77SJakub Sitnicki  *
3926e9ddbb77SJakub Sitnicki  *		For the operation to succeed passed socket must be compatible
3927e9ddbb77SJakub Sitnicki  *		with the packet description provided by the *ctx* object.
3928e9ddbb77SJakub Sitnicki  *
3929e9ddbb77SJakub Sitnicki  *		L4 protocol (**IPPROTO_TCP** or **IPPROTO_UDP**) must
3930e9ddbb77SJakub Sitnicki  *		be an exact match. While IP family (**AF_INET** or
3931e9ddbb77SJakub Sitnicki  *		**AF_INET6**) must be compatible, that is IPv6 sockets
3932e9ddbb77SJakub Sitnicki  *		that are not v6-only can be selected for IPv4 packets.
3933e9ddbb77SJakub Sitnicki  *
3934e9ddbb77SJakub Sitnicki  *		Only TCP listeners and UDP unconnected sockets can be
3935e9ddbb77SJakub Sitnicki  *		selected. *sk* can also be NULL to reset any previous
3936e9ddbb77SJakub Sitnicki  *		selection.
3937e9ddbb77SJakub Sitnicki  *
3938e9ddbb77SJakub Sitnicki  *		*flags* argument can combination of following values:
3939e9ddbb77SJakub Sitnicki  *
3940e9ddbb77SJakub Sitnicki  *		* **BPF_SK_LOOKUP_F_REPLACE** to override the previous
3941e9ddbb77SJakub Sitnicki  *		  socket selection, potentially done by a BPF program
3942e9ddbb77SJakub Sitnicki  *		  that ran before us.
3943e9ddbb77SJakub Sitnicki  *
3944e9ddbb77SJakub Sitnicki  *		* **BPF_SK_LOOKUP_F_NO_REUSEPORT** to skip
3945e9ddbb77SJakub Sitnicki  *		  load-balancing within reuseport group for the socket
3946e9ddbb77SJakub Sitnicki  *		  being selected.
3947e9ddbb77SJakub Sitnicki  *
3948e9ddbb77SJakub Sitnicki  *		On success *ctx->sk* will point to the selected socket.
3949e9ddbb77SJakub Sitnicki  *
3950e9ddbb77SJakub Sitnicki  *	Return
3951e9ddbb77SJakub Sitnicki  *		0 on success, or a negative errno in case of failure.
3952e9ddbb77SJakub Sitnicki  *
3953e9ddbb77SJakub Sitnicki  *		* **-EAFNOSUPPORT** if socket family (*sk->family*) is
3954e9ddbb77SJakub Sitnicki  *		  not compatible with packet family (*ctx->family*).
3955e9ddbb77SJakub Sitnicki  *
3956e9ddbb77SJakub Sitnicki  *		* **-EEXIST** if socket has been already selected,
3957e9ddbb77SJakub Sitnicki  *		  potentially by another program, and
3958e9ddbb77SJakub Sitnicki  *		  **BPF_SK_LOOKUP_F_REPLACE** flag was not specified.
3959e9ddbb77SJakub Sitnicki  *
3960e9ddbb77SJakub Sitnicki  *		* **-EINVAL** if unsupported flags were specified.
3961e9ddbb77SJakub Sitnicki  *
3962e9ddbb77SJakub Sitnicki  *		* **-EPROTOTYPE** if socket L4 protocol
3963e9ddbb77SJakub Sitnicki  *		  (*sk->protocol*) doesn't match packet protocol
3964e9ddbb77SJakub Sitnicki  *		  (*ctx->protocol*).
3965e9ddbb77SJakub Sitnicki  *
3966e9ddbb77SJakub Sitnicki  *		* **-ESOCKTNOSUPPORT** if socket is not in allowed
3967e9ddbb77SJakub Sitnicki  *		  state (TCP listening or UDP unconnected).
3968e9ddbb77SJakub Sitnicki  *
396971d19214SMaciej Żenczykowski  * u64 bpf_ktime_get_boot_ns(void)
397071d19214SMaciej Żenczykowski  * 	Description
397171d19214SMaciej Żenczykowski  * 		Return the time elapsed since system boot, in nanoseconds.
397271d19214SMaciej Żenczykowski  * 		Does include the time the system was suspended.
3973ab8d7809SQuentin Monnet  * 		See: **clock_gettime**\ (**CLOCK_BOOTTIME**)
397471d19214SMaciej Żenczykowski  * 	Return
397571d19214SMaciej Żenczykowski  * 		Current *ktime*.
3976492e639fSYonghong Song  *
3977bdb7b79bSAndrii Nakryiko  * long bpf_seq_printf(struct seq_file *m, const char *fmt, u32 fmt_size, const void *data, u32 data_len)
3978492e639fSYonghong Song  * 	Description
3979ab8d7809SQuentin Monnet  * 		**bpf_seq_printf**\ () uses seq_file **seq_printf**\ () to print
3980ab8d7809SQuentin Monnet  * 		out the format string.
3981492e639fSYonghong Song  * 		The *m* represents the seq_file. The *fmt* and *fmt_size* are for
3982492e639fSYonghong Song  * 		the format string itself. The *data* and *data_len* are format string
3983ab8d7809SQuentin Monnet  * 		arguments. The *data* are a **u64** array and corresponding format string
3984492e639fSYonghong Song  * 		values are stored in the array. For strings and pointers where pointees
3985492e639fSYonghong Song  * 		are accessed, only the pointer values are stored in the *data* array.
3986ab8d7809SQuentin Monnet  * 		The *data_len* is the size of *data* in bytes.
3987492e639fSYonghong Song  *
3988492e639fSYonghong Song  *		Formats **%s**, **%p{i,I}{4,6}** requires to read kernel memory.
3989492e639fSYonghong Song  *		Reading kernel memory may fail due to either invalid address or
3990492e639fSYonghong Song  *		valid address but requiring a major memory fault. If reading kernel memory
3991492e639fSYonghong Song  *		fails, the string for **%s** will be an empty string, and the ip
3992492e639fSYonghong Song  *		address for **%p{i,I}{4,6}** will be 0. Not returning error to
3993ab8d7809SQuentin Monnet  *		bpf program is consistent with what **bpf_trace_printk**\ () does for now.
3994492e639fSYonghong Song  * 	Return
3995ab8d7809SQuentin Monnet  * 		0 on success, or a negative error in case of failure:
3996492e639fSYonghong Song  *
3997ab8d7809SQuentin Monnet  *		**-EBUSY** if per-CPU memory copy buffer is busy, can try again
3998492e639fSYonghong Song  *		by returning 1 from bpf program.
3999ab8d7809SQuentin Monnet  *
4000ab8d7809SQuentin Monnet  *		**-EINVAL** if arguments are invalid, or if *fmt* is invalid/unsupported.
4001ab8d7809SQuentin Monnet  *
4002ab8d7809SQuentin Monnet  *		**-E2BIG** if *fmt* contains too many format specifiers.
4003ab8d7809SQuentin Monnet  *
4004ab8d7809SQuentin Monnet  *		**-EOVERFLOW** if an overflow happened: The same object will be tried again.
4005492e639fSYonghong Song  *
4006bdb7b79bSAndrii Nakryiko  * long bpf_seq_write(struct seq_file *m, const void *data, u32 len)
4007492e639fSYonghong Song  * 	Description
4008ab8d7809SQuentin Monnet  * 		**bpf_seq_write**\ () uses seq_file **seq_write**\ () to write the data.
4009492e639fSYonghong Song  * 		The *m* represents the seq_file. The *data* and *len* represent the
4010492e639fSYonghong Song  * 		data to write in bytes.
4011492e639fSYonghong Song  * 	Return
4012ab8d7809SQuentin Monnet  * 		0 on success, or a negative error in case of failure:
4013492e639fSYonghong Song  *
4014ab8d7809SQuentin Monnet  *		**-EOVERFLOW** if an overflow happened: The same object will be tried again.
4015f307fa2cSAndrey Ignatov  *
4016a5fa25adSMartin KaFai Lau  * u64 bpf_sk_cgroup_id(void *sk)
4017f307fa2cSAndrey Ignatov  *	Description
4018f307fa2cSAndrey Ignatov  *		Return the cgroup v2 id of the socket *sk*.
4019f307fa2cSAndrey Ignatov  *
4020a5fa25adSMartin KaFai Lau  *		*sk* must be a non-**NULL** pointer to a socket, e.g. one
4021f307fa2cSAndrey Ignatov  *		returned from **bpf_sk_lookup_xxx**\ (),
4022f307fa2cSAndrey Ignatov  *		**bpf_sk_fullsock**\ (), etc. The format of returned id is
4023f307fa2cSAndrey Ignatov  *		same as in **bpf_skb_cgroup_id**\ ().
4024f307fa2cSAndrey Ignatov  *
4025f307fa2cSAndrey Ignatov  *		This helper is available only if the kernel was compiled with
4026f307fa2cSAndrey Ignatov  *		the **CONFIG_SOCK_CGROUP_DATA** configuration option.
4027f307fa2cSAndrey Ignatov  *	Return
4028f307fa2cSAndrey Ignatov  *		The id is returned or 0 in case the id could not be retrieved.
4029f307fa2cSAndrey Ignatov  *
4030a5fa25adSMartin KaFai Lau  * u64 bpf_sk_ancestor_cgroup_id(void *sk, int ancestor_level)
4031f307fa2cSAndrey Ignatov  *	Description
4032f307fa2cSAndrey Ignatov  *		Return id of cgroup v2 that is ancestor of cgroup associated
4033f307fa2cSAndrey Ignatov  *		with the *sk* at the *ancestor_level*.  The root cgroup is at
4034f307fa2cSAndrey Ignatov  *		*ancestor_level* zero and each step down the hierarchy
4035f307fa2cSAndrey Ignatov  *		increments the level. If *ancestor_level* == level of cgroup
4036f307fa2cSAndrey Ignatov  *		associated with *sk*, then return value will be same as that
4037f307fa2cSAndrey Ignatov  *		of **bpf_sk_cgroup_id**\ ().
4038f307fa2cSAndrey Ignatov  *
4039f307fa2cSAndrey Ignatov  *		The helper is useful to implement policies based on cgroups
4040f307fa2cSAndrey Ignatov  *		that are upper in hierarchy than immediate cgroup associated
4041f307fa2cSAndrey Ignatov  *		with *sk*.
4042f307fa2cSAndrey Ignatov  *
4043f307fa2cSAndrey Ignatov  *		The format of returned id and helper limitations are same as in
4044f307fa2cSAndrey Ignatov  *		**bpf_sk_cgroup_id**\ ().
4045f307fa2cSAndrey Ignatov  *	Return
4046f307fa2cSAndrey Ignatov  *		The id is returned or 0 in case the id could not be retrieved.
4047457f4436SAndrii Nakryiko  *
4048e1613b57SAndrii Nakryiko  * long bpf_ringbuf_output(void *ringbuf, void *data, u64 size, u64 flags)
4049457f4436SAndrii Nakryiko  * 	Description
4050457f4436SAndrii Nakryiko  * 		Copy *size* bytes from *data* into a ring buffer *ringbuf*.
4051bcc7f554SQuentin Monnet  * 		If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
4052bcc7f554SQuentin Monnet  * 		of new data availability is sent.
4053bcc7f554SQuentin Monnet  * 		If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
4054bcc7f554SQuentin Monnet  * 		of new data availability is sent unconditionally.
4055457f4436SAndrii Nakryiko  * 	Return
4056bcc7f554SQuentin Monnet  * 		0 on success, or a negative error in case of failure.
4057457f4436SAndrii Nakryiko  *
4058457f4436SAndrii Nakryiko  * void *bpf_ringbuf_reserve(void *ringbuf, u64 size, u64 flags)
4059457f4436SAndrii Nakryiko  * 	Description
4060457f4436SAndrii Nakryiko  * 		Reserve *size* bytes of payload in a ring buffer *ringbuf*.
4061457f4436SAndrii Nakryiko  * 	Return
4062457f4436SAndrii Nakryiko  * 		Valid pointer with *size* bytes of memory available; NULL,
4063457f4436SAndrii Nakryiko  * 		otherwise.
4064457f4436SAndrii Nakryiko  *
4065457f4436SAndrii Nakryiko  * void bpf_ringbuf_submit(void *data, u64 flags)
4066457f4436SAndrii Nakryiko  * 	Description
4067457f4436SAndrii Nakryiko  * 		Submit reserved ring buffer sample, pointed to by *data*.
4068bcc7f554SQuentin Monnet  * 		If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
4069bcc7f554SQuentin Monnet  * 		of new data availability is sent.
4070bcc7f554SQuentin Monnet  * 		If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
4071bcc7f554SQuentin Monnet  * 		of new data availability is sent unconditionally.
4072457f4436SAndrii Nakryiko  * 	Return
4073457f4436SAndrii Nakryiko  * 		Nothing. Always succeeds.
4074457f4436SAndrii Nakryiko  *
4075457f4436SAndrii Nakryiko  * void bpf_ringbuf_discard(void *data, u64 flags)
4076457f4436SAndrii Nakryiko  * 	Description
4077457f4436SAndrii Nakryiko  * 		Discard reserved ring buffer sample, pointed to by *data*.
4078bcc7f554SQuentin Monnet  * 		If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
4079bcc7f554SQuentin Monnet  * 		of new data availability is sent.
4080bcc7f554SQuentin Monnet  * 		If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
4081bcc7f554SQuentin Monnet  * 		of new data availability is sent unconditionally.
4082457f4436SAndrii Nakryiko  * 	Return
4083457f4436SAndrii Nakryiko  * 		Nothing. Always succeeds.
4084457f4436SAndrii Nakryiko  *
4085457f4436SAndrii Nakryiko  * u64 bpf_ringbuf_query(void *ringbuf, u64 flags)
4086457f4436SAndrii Nakryiko  *	Description
4087457f4436SAndrii Nakryiko  *		Query various characteristics of provided ring buffer. What
4088457f4436SAndrii Nakryiko  *		exactly is queries is determined by *flags*:
4089bcc7f554SQuentin Monnet  *
4090bcc7f554SQuentin Monnet  *		* **BPF_RB_AVAIL_DATA**: Amount of data not yet consumed.
4091bcc7f554SQuentin Monnet  *		* **BPF_RB_RING_SIZE**: The size of ring buffer.
4092bcc7f554SQuentin Monnet  *		* **BPF_RB_CONS_POS**: Consumer position (can wrap around).
4093bcc7f554SQuentin Monnet  *		* **BPF_RB_PROD_POS**: Producer(s) position (can wrap around).
4094bcc7f554SQuentin Monnet  *
4095bcc7f554SQuentin Monnet  *		Data returned is just a momentary snapshot of actual values
4096457f4436SAndrii Nakryiko  *		and could be inaccurate, so this facility should be used to
4097457f4436SAndrii Nakryiko  *		power heuristics and for reporting, not to make 100% correct
4098457f4436SAndrii Nakryiko  *		calculation.
4099457f4436SAndrii Nakryiko  *	Return
4100bcc7f554SQuentin Monnet  *		Requested value, or 0, if *flags* are not recognized.
41017cdec54fSDaniel Borkmann  *
4102bdb7b79bSAndrii Nakryiko  * long bpf_csum_level(struct sk_buff *skb, u64 level)
41037cdec54fSDaniel Borkmann  * 	Description
41047cdec54fSDaniel Borkmann  * 		Change the skbs checksum level by one layer up or down, or
41057cdec54fSDaniel Borkmann  * 		reset it entirely to none in order to have the stack perform
41067cdec54fSDaniel Borkmann  * 		checksum validation. The level is applicable to the following
41077cdec54fSDaniel Borkmann  * 		protocols: TCP, UDP, GRE, SCTP, FCOE. For example, a decap of
41087cdec54fSDaniel Borkmann  * 		| ETH | IP | UDP | GUE | IP | TCP | into | ETH | IP | TCP |
41097cdec54fSDaniel Borkmann  * 		through **bpf_skb_adjust_room**\ () helper with passing in
41107cdec54fSDaniel Borkmann  * 		**BPF_F_ADJ_ROOM_NO_CSUM_RESET** flag would require one	call
41117cdec54fSDaniel Borkmann  * 		to **bpf_csum_level**\ () with **BPF_CSUM_LEVEL_DEC** since
41127cdec54fSDaniel Borkmann  * 		the UDP header is removed. Similarly, an encap of the latter
41137cdec54fSDaniel Borkmann  * 		into the former could be accompanied by a helper call to
41147cdec54fSDaniel Borkmann  * 		**bpf_csum_level**\ () with **BPF_CSUM_LEVEL_INC** if the
41157cdec54fSDaniel Borkmann  * 		skb is still intended to be processed in higher layers of the
41167cdec54fSDaniel Borkmann  * 		stack instead of just egressing at tc.
41177cdec54fSDaniel Borkmann  *
41187cdec54fSDaniel Borkmann  * 		There are three supported level settings at this time:
41197cdec54fSDaniel Borkmann  *
41207cdec54fSDaniel Borkmann  * 		* **BPF_CSUM_LEVEL_INC**: Increases skb->csum_level for skbs
41217cdec54fSDaniel Borkmann  * 		  with CHECKSUM_UNNECESSARY.
41227cdec54fSDaniel Borkmann  * 		* **BPF_CSUM_LEVEL_DEC**: Decreases skb->csum_level for skbs
41237cdec54fSDaniel Borkmann  * 		  with CHECKSUM_UNNECESSARY.
41247cdec54fSDaniel Borkmann  * 		* **BPF_CSUM_LEVEL_RESET**: Resets skb->csum_level to 0 and
41257cdec54fSDaniel Borkmann  * 		  sets CHECKSUM_NONE to force checksum validation by the stack.
41267cdec54fSDaniel Borkmann  * 		* **BPF_CSUM_LEVEL_QUERY**: No-op, returns the current
41277cdec54fSDaniel Borkmann  * 		  skb->csum_level.
41287cdec54fSDaniel Borkmann  * 	Return
41297cdec54fSDaniel Borkmann  * 		0 on success, or a negative error in case of failure. In the
41307cdec54fSDaniel Borkmann  * 		case of **BPF_CSUM_LEVEL_QUERY**, the current skb->csum_level
41317cdec54fSDaniel Borkmann  * 		is returned or the error code -EACCES in case the skb is not
41327cdec54fSDaniel Borkmann  * 		subject to CHECKSUM_UNNECESSARY.
4133af7ec138SYonghong Song  *
4134af7ec138SYonghong Song  * struct tcp6_sock *bpf_skc_to_tcp6_sock(void *sk)
4135af7ec138SYonghong Song  *	Description
4136af7ec138SYonghong Song  *		Dynamically cast a *sk* pointer to a *tcp6_sock* pointer.
4137af7ec138SYonghong Song  *	Return
4138938c3efdSQuentin Monnet  *		*sk* if casting is valid, or **NULL** otherwise.
4139478cfbdfSYonghong Song  *
4140478cfbdfSYonghong Song  * struct tcp_sock *bpf_skc_to_tcp_sock(void *sk)
4141478cfbdfSYonghong Song  *	Description
4142478cfbdfSYonghong Song  *		Dynamically cast a *sk* pointer to a *tcp_sock* pointer.
4143478cfbdfSYonghong Song  *	Return
4144938c3efdSQuentin Monnet  *		*sk* if casting is valid, or **NULL** otherwise.
4145478cfbdfSYonghong Song  *
4146478cfbdfSYonghong Song  * struct tcp_timewait_sock *bpf_skc_to_tcp_timewait_sock(void *sk)
4147478cfbdfSYonghong Song  * 	Description
4148478cfbdfSYonghong Song  *		Dynamically cast a *sk* pointer to a *tcp_timewait_sock* pointer.
4149478cfbdfSYonghong Song  *	Return
4150938c3efdSQuentin Monnet  *		*sk* if casting is valid, or **NULL** otherwise.
4151478cfbdfSYonghong Song  *
4152478cfbdfSYonghong Song  * struct tcp_request_sock *bpf_skc_to_tcp_request_sock(void *sk)
4153478cfbdfSYonghong Song  * 	Description
4154478cfbdfSYonghong Song  *		Dynamically cast a *sk* pointer to a *tcp_request_sock* pointer.
4155478cfbdfSYonghong Song  *	Return
4156938c3efdSQuentin Monnet  *		*sk* if casting is valid, or **NULL** otherwise.
41570d4fad3eSYonghong Song  *
41580d4fad3eSYonghong Song  * struct udp6_sock *bpf_skc_to_udp6_sock(void *sk)
41590d4fad3eSYonghong Song  * 	Description
41600d4fad3eSYonghong Song  *		Dynamically cast a *sk* pointer to a *udp6_sock* pointer.
41610d4fad3eSYonghong Song  *	Return
4162938c3efdSQuentin Monnet  *		*sk* if casting is valid, or **NULL** otherwise.
4163fa28dcb8SSong Liu  *
4164fa28dcb8SSong Liu  * long bpf_get_task_stack(struct task_struct *task, void *buf, u32 size, u64 flags)
4165fa28dcb8SSong Liu  *	Description
4166fa28dcb8SSong Liu  *		Return a user or a kernel stack in bpf program provided buffer.
4167fa28dcb8SSong Liu  *		To achieve this, the helper needs *task*, which is a valid
4168938c3efdSQuentin Monnet  *		pointer to **struct task_struct**. To store the stacktrace, the
4169fa28dcb8SSong Liu  *		bpf program provides *buf* with a nonnegative *size*.
4170fa28dcb8SSong Liu  *
4171fa28dcb8SSong Liu  *		The last argument, *flags*, holds the number of stack frames to
4172fa28dcb8SSong Liu  *		skip (from 0 to 255), masked with
4173fa28dcb8SSong Liu  *		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
4174fa28dcb8SSong Liu  *		the following flags:
4175fa28dcb8SSong Liu  *
4176fa28dcb8SSong Liu  *		**BPF_F_USER_STACK**
4177fa28dcb8SSong Liu  *			Collect a user space stack instead of a kernel stack.
4178fa28dcb8SSong Liu  *		**BPF_F_USER_BUILD_ID**
4179fa28dcb8SSong Liu  *			Collect buildid+offset instead of ips for user stack,
4180fa28dcb8SSong Liu  *			only valid if **BPF_F_USER_STACK** is also specified.
4181fa28dcb8SSong Liu  *
4182fa28dcb8SSong Liu  *		**bpf_get_task_stack**\ () can collect up to
4183fa28dcb8SSong Liu  *		**PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
4184fa28dcb8SSong Liu  *		to sufficient large buffer size. Note that
4185fa28dcb8SSong Liu  *		this limit can be controlled with the **sysctl** program, and
4186fa28dcb8SSong Liu  *		that it should be manually increased in order to profile long
4187fa28dcb8SSong Liu  *		user stacks (such as stacks for Java programs). To do so, use:
4188fa28dcb8SSong Liu  *
4189fa28dcb8SSong Liu  *		::
4190fa28dcb8SSong Liu  *
4191fa28dcb8SSong Liu  *			# sysctl kernel.perf_event_max_stack=<new value>
4192fa28dcb8SSong Liu  *	Return
4193fa28dcb8SSong Liu  *		A non-negative value equal to or less than *size* on success,
4194fa28dcb8SSong Liu  *		or a negative error in case of failure.
4195fa28dcb8SSong Liu  *
41960813a841SMartin KaFai Lau  * long bpf_load_hdr_opt(struct bpf_sock_ops *skops, void *searchby_res, u32 len, u64 flags)
41970813a841SMartin KaFai Lau  *	Description
41980813a841SMartin KaFai Lau  *		Load header option.  Support reading a particular TCP header
4199938c3efdSQuentin Monnet  *		option for bpf program (**BPF_PROG_TYPE_SOCK_OPS**).
42000813a841SMartin KaFai Lau  *
42010813a841SMartin KaFai Lau  *		If *flags* is 0, it will search the option from the
4202938c3efdSQuentin Monnet  *		*skops*\ **->skb_data**.  The comment in **struct bpf_sock_ops**
42030813a841SMartin KaFai Lau  *		has details on what skb_data contains under different
4204938c3efdSQuentin Monnet  *		*skops*\ **->op**.
42050813a841SMartin KaFai Lau  *
42060813a841SMartin KaFai Lau  *		The first byte of the *searchby_res* specifies the
42070813a841SMartin KaFai Lau  *		kind that it wants to search.
42080813a841SMartin KaFai Lau  *
42090813a841SMartin KaFai Lau  *		If the searching kind is an experimental kind
42100813a841SMartin KaFai Lau  *		(i.e. 253 or 254 according to RFC6994).  It also
42110813a841SMartin KaFai Lau  *		needs to specify the "magic" which is either
42120813a841SMartin KaFai Lau  *		2 bytes or 4 bytes.  It then also needs to
42130813a841SMartin KaFai Lau  *		specify the size of the magic by using
42140813a841SMartin KaFai Lau  *		the 2nd byte which is "kind-length" of a TCP
42150813a841SMartin KaFai Lau  *		header option and the "kind-length" also
42160813a841SMartin KaFai Lau  *		includes the first 2 bytes "kind" and "kind-length"
42170813a841SMartin KaFai Lau  *		itself as a normal TCP header option also does.
42180813a841SMartin KaFai Lau  *
42190813a841SMartin KaFai Lau  *		For example, to search experimental kind 254 with
42200813a841SMartin KaFai Lau  *		2 byte magic 0xeB9F, the searchby_res should be
42210813a841SMartin KaFai Lau  *		[ 254, 4, 0xeB, 0x9F, 0, 0, .... 0 ].
42220813a841SMartin KaFai Lau  *
42230813a841SMartin KaFai Lau  *		To search for the standard window scale option (3),
4224938c3efdSQuentin Monnet  *		the *searchby_res* should be [ 3, 0, 0, .... 0 ].
42250813a841SMartin KaFai Lau  *		Note, kind-length must be 0 for regular option.
42260813a841SMartin KaFai Lau  *
42270813a841SMartin KaFai Lau  *		Searching for No-Op (0) and End-of-Option-List (1) are
42280813a841SMartin KaFai Lau  *		not supported.
42290813a841SMartin KaFai Lau  *
42300813a841SMartin KaFai Lau  *		*len* must be at least 2 bytes which is the minimal size
42310813a841SMartin KaFai Lau  *		of a header option.
42320813a841SMartin KaFai Lau  *
42330813a841SMartin KaFai Lau  *		Supported flags:
4234938c3efdSQuentin Monnet  *
42350813a841SMartin KaFai Lau  *		* **BPF_LOAD_HDR_OPT_TCP_SYN** to search from the
42360813a841SMartin KaFai Lau  *		  saved_syn packet or the just-received syn packet.
42370813a841SMartin KaFai Lau  *
42380813a841SMartin KaFai Lau  *	Return
42390813a841SMartin KaFai Lau  *		> 0 when found, the header option is copied to *searchby_res*.
4240938c3efdSQuentin Monnet  *		The return value is the total length copied. On failure, a
4241938c3efdSQuentin Monnet  *		negative error code is returned:
42420813a841SMartin KaFai Lau  *
4243938c3efdSQuentin Monnet  *		**-EINVAL** if a parameter is invalid.
42440813a841SMartin KaFai Lau  *
4245938c3efdSQuentin Monnet  *		**-ENOMSG** if the option is not found.
42460813a841SMartin KaFai Lau  *
4247938c3efdSQuentin Monnet  *		**-ENOENT** if no syn packet is available when
4248938c3efdSQuentin Monnet  *		**BPF_LOAD_HDR_OPT_TCP_SYN** is used.
42490813a841SMartin KaFai Lau  *
4250938c3efdSQuentin Monnet  *		**-ENOSPC** if there is not enough space.  Only *len* number of
42510813a841SMartin KaFai Lau  *		bytes are copied.
42520813a841SMartin KaFai Lau  *
4253938c3efdSQuentin Monnet  *		**-EFAULT** on failure to parse the header options in the
4254938c3efdSQuentin Monnet  *		packet.
42550813a841SMartin KaFai Lau  *
4256938c3efdSQuentin Monnet  *		**-EPERM** if the helper cannot be used under the current
4257938c3efdSQuentin Monnet  *		*skops*\ **->op**.
42580813a841SMartin KaFai Lau  *
42590813a841SMartin KaFai Lau  * long bpf_store_hdr_opt(struct bpf_sock_ops *skops, const void *from, u32 len, u64 flags)
42600813a841SMartin KaFai Lau  *	Description
42610813a841SMartin KaFai Lau  *		Store header option.  The data will be copied
42620813a841SMartin KaFai Lau  *		from buffer *from* with length *len* to the TCP header.
42630813a841SMartin KaFai Lau  *
42640813a841SMartin KaFai Lau  *		The buffer *from* should have the whole option that
42650813a841SMartin KaFai Lau  *		includes the kind, kind-length, and the actual
42660813a841SMartin KaFai Lau  *		option data.  The *len* must be at least kind-length
42670813a841SMartin KaFai Lau  *		long.  The kind-length does not have to be 4 byte
42680813a841SMartin KaFai Lau  *		aligned.  The kernel will take care of the padding
42690813a841SMartin KaFai Lau  *		and setting the 4 bytes aligned value to th->doff.
42700813a841SMartin KaFai Lau  *
42710813a841SMartin KaFai Lau  *		This helper will check for duplicated option
42720813a841SMartin KaFai Lau  *		by searching the same option in the outgoing skb.
42730813a841SMartin KaFai Lau  *
42740813a841SMartin KaFai Lau  *		This helper can only be called during
4275938c3efdSQuentin Monnet  *		**BPF_SOCK_OPS_WRITE_HDR_OPT_CB**.
42760813a841SMartin KaFai Lau  *
42770813a841SMartin KaFai Lau  *	Return
42780813a841SMartin KaFai Lau  *		0 on success, or negative error in case of failure:
42790813a841SMartin KaFai Lau  *
4280938c3efdSQuentin Monnet  *		**-EINVAL** If param is invalid.
42810813a841SMartin KaFai Lau  *
4282938c3efdSQuentin Monnet  *		**-ENOSPC** if there is not enough space in the header.
42830813a841SMartin KaFai Lau  *		Nothing has been written
42840813a841SMartin KaFai Lau  *
4285938c3efdSQuentin Monnet  *		**-EEXIST** if the option already exists.
42860813a841SMartin KaFai Lau  *
4287938c3efdSQuentin Monnet  *		**-EFAULT** on failrue to parse the existing header options.
42880813a841SMartin KaFai Lau  *
4289938c3efdSQuentin Monnet  *		**-EPERM** if the helper cannot be used under the current
4290938c3efdSQuentin Monnet  *		*skops*\ **->op**.
42910813a841SMartin KaFai Lau  *
42920813a841SMartin KaFai Lau  * long bpf_reserve_hdr_opt(struct bpf_sock_ops *skops, u32 len, u64 flags)
42930813a841SMartin KaFai Lau  *	Description
42940813a841SMartin KaFai Lau  *		Reserve *len* bytes for the bpf header option.  The
4295938c3efdSQuentin Monnet  *		space will be used by **bpf_store_hdr_opt**\ () later in
4296938c3efdSQuentin Monnet  *		**BPF_SOCK_OPS_WRITE_HDR_OPT_CB**.
42970813a841SMartin KaFai Lau  *
4298938c3efdSQuentin Monnet  *		If **bpf_reserve_hdr_opt**\ () is called multiple times,
42990813a841SMartin KaFai Lau  *		the total number of bytes will be reserved.
43000813a841SMartin KaFai Lau  *
43010813a841SMartin KaFai Lau  *		This helper can only be called during
4302938c3efdSQuentin Monnet  *		**BPF_SOCK_OPS_HDR_OPT_LEN_CB**.
43030813a841SMartin KaFai Lau  *
43040813a841SMartin KaFai Lau  *	Return
43050813a841SMartin KaFai Lau  *		0 on success, or negative error in case of failure:
43060813a841SMartin KaFai Lau  *
4307938c3efdSQuentin Monnet  *		**-EINVAL** if a parameter is invalid.
43080813a841SMartin KaFai Lau  *
4309938c3efdSQuentin Monnet  *		**-ENOSPC** if there is not enough space in the header.
43100813a841SMartin KaFai Lau  *
4311938c3efdSQuentin Monnet  *		**-EPERM** if the helper cannot be used under the current
4312938c3efdSQuentin Monnet  *		*skops*\ **->op**.
43136e22ab9dSJiri Olsa  *
43148ea63684SKP Singh  * void *bpf_inode_storage_get(struct bpf_map *map, void *inode, void *value, u64 flags)
43158ea63684SKP Singh  *	Description
43168ea63684SKP Singh  *		Get a bpf_local_storage from an *inode*.
43178ea63684SKP Singh  *
43188ea63684SKP Singh  *		Logically, it could be thought of as getting the value from
43198ea63684SKP Singh  *		a *map* with *inode* as the **key**.  From this
43208ea63684SKP Singh  *		perspective,  the usage is not much different from
43218ea63684SKP Singh  *		**bpf_map_lookup_elem**\ (*map*, **&**\ *inode*) except this
43228ea63684SKP Singh  *		helper enforces the key must be an inode and the map must also
43238ea63684SKP Singh  *		be a **BPF_MAP_TYPE_INODE_STORAGE**.
43248ea63684SKP Singh  *
43258ea63684SKP Singh  *		Underneath, the value is stored locally at *inode* instead of
43268ea63684SKP Singh  *		the *map*.  The *map* is used as the bpf-local-storage
43278ea63684SKP Singh  *		"type". The bpf-local-storage "type" (i.e. the *map*) is
43288ea63684SKP Singh  *		searched against all bpf_local_storage residing at *inode*.
43298ea63684SKP Singh  *
43308ea63684SKP Singh  *		An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
43318ea63684SKP Singh  *		used such that a new bpf_local_storage will be
43328ea63684SKP Singh  *		created if one does not exist.  *value* can be used
43338ea63684SKP Singh  *		together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
43348ea63684SKP Singh  *		the initial value of a bpf_local_storage.  If *value* is
43358ea63684SKP Singh  *		**NULL**, the new bpf_local_storage will be zero initialized.
43368ea63684SKP Singh  *	Return
43378ea63684SKP Singh  *		A bpf_local_storage pointer is returned on success.
43388ea63684SKP Singh  *
43398ea63684SKP Singh  *		**NULL** if not found or there was an error in adding
43408ea63684SKP Singh  *		a new bpf_local_storage.
43418ea63684SKP Singh  *
43428ea63684SKP Singh  * int bpf_inode_storage_delete(struct bpf_map *map, void *inode)
43438ea63684SKP Singh  *	Description
43448ea63684SKP Singh  *		Delete a bpf_local_storage from an *inode*.
43458ea63684SKP Singh  *	Return
43468ea63684SKP Singh  *		0 on success.
43478ea63684SKP Singh  *
43488ea63684SKP Singh  *		**-ENOENT** if the bpf_local_storage cannot be found.
43496e22ab9dSJiri Olsa  *
43506e22ab9dSJiri Olsa  * long bpf_d_path(struct path *path, char *buf, u32 sz)
43516e22ab9dSJiri Olsa  *	Description
4352938c3efdSQuentin Monnet  *		Return full path for given **struct path** object, which
4353938c3efdSQuentin Monnet  *		needs to be the kernel BTF *path* object. The path is
4354938c3efdSQuentin Monnet  *		returned in the provided buffer *buf* of size *sz* and
43556e22ab9dSJiri Olsa  *		is zero terminated.
43566e22ab9dSJiri Olsa  *
43576e22ab9dSJiri Olsa  *	Return
43586e22ab9dSJiri Olsa  *		On success, the strictly positive length of the string,
43596e22ab9dSJiri Olsa  *		including the trailing NUL character. On error, a negative
43606e22ab9dSJiri Olsa  *		value.
436107be4c4aSAlexei Starovoitov  *
436207be4c4aSAlexei Starovoitov  * long bpf_copy_from_user(void *dst, u32 size, const void *user_ptr)
436307be4c4aSAlexei Starovoitov  * 	Description
436407be4c4aSAlexei Starovoitov  * 		Read *size* bytes from user space address *user_ptr* and store
4365938c3efdSQuentin Monnet  * 		the data in *dst*. This is a wrapper of **copy_from_user**\ ().
436607be4c4aSAlexei Starovoitov  * 	Return
436707be4c4aSAlexei Starovoitov  * 		0 on success, or a negative error in case of failure.
4368c4d0bfb4SAlan Maguire  *
4369c4d0bfb4SAlan Maguire  * long bpf_snprintf_btf(char *str, u32 str_size, struct btf_ptr *ptr, u32 btf_ptr_size, u64 flags)
4370c4d0bfb4SAlan Maguire  *	Description
4371c4d0bfb4SAlan Maguire  *		Use BTF to store a string representation of *ptr*->ptr in *str*,
4372c4d0bfb4SAlan Maguire  *		using *ptr*->type_id.  This value should specify the type
4373c4d0bfb4SAlan Maguire  *		that *ptr*->ptr points to. LLVM __builtin_btf_type_id(type, 1)
4374c4d0bfb4SAlan Maguire  *		can be used to look up vmlinux BTF type ids. Traversing the
4375c4d0bfb4SAlan Maguire  *		data structure using BTF, the type information and values are
4376c4d0bfb4SAlan Maguire  *		stored in the first *str_size* - 1 bytes of *str*.  Safe copy of
4377c4d0bfb4SAlan Maguire  *		the pointer data is carried out to avoid kernel crashes during
4378c4d0bfb4SAlan Maguire  *		operation.  Smaller types can use string space on the stack;
4379c4d0bfb4SAlan Maguire  *		larger programs can use map data to store the string
4380c4d0bfb4SAlan Maguire  *		representation.
4381c4d0bfb4SAlan Maguire  *
4382c4d0bfb4SAlan Maguire  *		The string can be subsequently shared with userspace via
4383c4d0bfb4SAlan Maguire  *		bpf_perf_event_output() or ring buffer interfaces.
4384c4d0bfb4SAlan Maguire  *		bpf_trace_printk() is to be avoided as it places too small
4385c4d0bfb4SAlan Maguire  *		a limit on string size to be useful.
4386c4d0bfb4SAlan Maguire  *
4387c4d0bfb4SAlan Maguire  *		*flags* is a combination of
4388c4d0bfb4SAlan Maguire  *
4389c4d0bfb4SAlan Maguire  *		**BTF_F_COMPACT**
4390c4d0bfb4SAlan Maguire  *			no formatting around type information
4391c4d0bfb4SAlan Maguire  *		**BTF_F_NONAME**
4392c4d0bfb4SAlan Maguire  *			no struct/union member names/types
4393c4d0bfb4SAlan Maguire  *		**BTF_F_PTR_RAW**
4394c4d0bfb4SAlan Maguire  *			show raw (unobfuscated) pointer values;
4395c4d0bfb4SAlan Maguire  *			equivalent to printk specifier %px.
4396c4d0bfb4SAlan Maguire  *		**BTF_F_ZERO**
4397c4d0bfb4SAlan Maguire  *			show zero-valued struct/union members; they
4398c4d0bfb4SAlan Maguire  *			are not displayed by default
4399c4d0bfb4SAlan Maguire  *
4400c4d0bfb4SAlan Maguire  *	Return
4401c4d0bfb4SAlan Maguire  *		The number of bytes that were written (or would have been
4402c4d0bfb4SAlan Maguire  *		written if output had to be truncated due to string size),
4403c4d0bfb4SAlan Maguire  *		or a negative error in cases of failure.
4404eb411377SAlan Maguire  *
4405eb411377SAlan Maguire  * long bpf_seq_printf_btf(struct seq_file *m, struct btf_ptr *ptr, u32 ptr_size, u64 flags)
4406eb411377SAlan Maguire  *	Description
4407eb411377SAlan Maguire  *		Use BTF to write to seq_write a string representation of
4408eb411377SAlan Maguire  *		*ptr*->ptr, using *ptr*->type_id as per bpf_snprintf_btf().
4409eb411377SAlan Maguire  *		*flags* are identical to those used for bpf_snprintf_btf.
4410eb411377SAlan Maguire  *	Return
4411eb411377SAlan Maguire  *		0 on success or a negative error in case of failure.
4412b426ce83SDaniel Borkmann  *
4413b426ce83SDaniel Borkmann  * u64 bpf_skb_cgroup_classid(struct sk_buff *skb)
4414b426ce83SDaniel Borkmann  * 	Description
4415b426ce83SDaniel Borkmann  * 		See **bpf_get_cgroup_classid**\ () for the main description.
4416b426ce83SDaniel Borkmann  * 		This helper differs from **bpf_get_cgroup_classid**\ () in that
4417b426ce83SDaniel Borkmann  * 		the cgroup v1 net_cls class is retrieved only from the *skb*'s
4418b426ce83SDaniel Borkmann  * 		associated socket instead of the current process.
4419b426ce83SDaniel Borkmann  * 	Return
4420b426ce83SDaniel Borkmann  * 		The id is returned or 0 in case the id could not be retrieved.
4421b4ab3141SDaniel Borkmann  *
4422ba452c9eSToke Høiland-Jørgensen  * long bpf_redirect_neigh(u32 ifindex, struct bpf_redir_neigh *params, int plen, u64 flags)
4423b4ab3141SDaniel Borkmann  * 	Description
4424b4ab3141SDaniel Borkmann  * 		Redirect the packet to another net device of index *ifindex*
4425b4ab3141SDaniel Borkmann  * 		and fill in L2 addresses from neighboring subsystem. This helper
4426b4ab3141SDaniel Borkmann  * 		is somewhat similar to **bpf_redirect**\ (), except that it
4427dd2ce6a5SDaniel Borkmann  * 		populates L2 addresses as well, meaning, internally, the helper
4428ba452c9eSToke Høiland-Jørgensen  * 		relies on the neighbor lookup for the L2 address of the nexthop.
4429ba452c9eSToke Høiland-Jørgensen  *
4430ba452c9eSToke Høiland-Jørgensen  * 		The helper will perform a FIB lookup based on the skb's
4431ba452c9eSToke Høiland-Jørgensen  * 		networking header to get the address of the next hop, unless
4432ba452c9eSToke Høiland-Jørgensen  * 		this is supplied by the caller in the *params* argument. The
4433ba452c9eSToke Høiland-Jørgensen  * 		*plen* argument indicates the len of *params* and should be set
4434ba452c9eSToke Høiland-Jørgensen  * 		to 0 if *params* is NULL.
4435dd2ce6a5SDaniel Borkmann  *
4436b4ab3141SDaniel Borkmann  * 		The *flags* argument is reserved and must be 0. The helper is
4437dd2ce6a5SDaniel Borkmann  * 		currently only supported for tc BPF program types, and enabled
4438dd2ce6a5SDaniel Borkmann  * 		for IPv4 and IPv6 protocols.
4439b4ab3141SDaniel Borkmann  * 	Return
4440b4ab3141SDaniel Borkmann  * 		The helper returns **TC_ACT_REDIRECT** on success or
4441b4ab3141SDaniel Borkmann  * 		**TC_ACT_SHOT** on error.
4442eaa6bcb7SHao Luo  *
4443eaa6bcb7SHao Luo  * void *bpf_per_cpu_ptr(const void *percpu_ptr, u32 cpu)
4444eaa6bcb7SHao Luo  *     Description
4445eaa6bcb7SHao Luo  *             Take a pointer to a percpu ksym, *percpu_ptr*, and return a
4446eaa6bcb7SHao Luo  *             pointer to the percpu kernel variable on *cpu*. A ksym is an
4447eaa6bcb7SHao Luo  *             extern variable decorated with '__ksym'. For ksym, there is a
4448eaa6bcb7SHao Luo  *             global var (either static or global) defined of the same name
4449eaa6bcb7SHao Luo  *             in the kernel. The ksym is percpu if the global var is percpu.
4450eaa6bcb7SHao Luo  *             The returned pointer points to the global percpu var on *cpu*.
4451eaa6bcb7SHao Luo  *
4452eaa6bcb7SHao Luo  *             bpf_per_cpu_ptr() has the same semantic as per_cpu_ptr() in the
4453eaa6bcb7SHao Luo  *             kernel, except that bpf_per_cpu_ptr() may return NULL. This
4454eaa6bcb7SHao Luo  *             happens if *cpu* is larger than nr_cpu_ids. The caller of
4455eaa6bcb7SHao Luo  *             bpf_per_cpu_ptr() must check the returned value.
4456eaa6bcb7SHao Luo  *     Return
4457eaa6bcb7SHao Luo  *             A pointer pointing to the kernel percpu variable on *cpu*, or
4458eaa6bcb7SHao Luo  *             NULL, if *cpu* is invalid.
445963d9b80dSHao Luo  *
446063d9b80dSHao Luo  * void *bpf_this_cpu_ptr(const void *percpu_ptr)
446163d9b80dSHao Luo  *	Description
446263d9b80dSHao Luo  *		Take a pointer to a percpu ksym, *percpu_ptr*, and return a
446363d9b80dSHao Luo  *		pointer to the percpu kernel variable on this cpu. See the
446463d9b80dSHao Luo  *		description of 'ksym' in **bpf_per_cpu_ptr**\ ().
446563d9b80dSHao Luo  *
446663d9b80dSHao Luo  *		bpf_this_cpu_ptr() has the same semantic as this_cpu_ptr() in
446763d9b80dSHao Luo  *		the kernel. Different from **bpf_per_cpu_ptr**\ (), it would
446863d9b80dSHao Luo  *		never return NULL.
446963d9b80dSHao Luo  *	Return
447063d9b80dSHao Luo  *		A pointer pointing to the kernel percpu variable on this cpu.
44719aa1206eSDaniel Borkmann  *
44729aa1206eSDaniel Borkmann  * long bpf_redirect_peer(u32 ifindex, u64 flags)
44739aa1206eSDaniel Borkmann  * 	Description
44749aa1206eSDaniel Borkmann  * 		Redirect the packet to another net device of index *ifindex*.
44759aa1206eSDaniel Borkmann  * 		This helper is somewhat similar to **bpf_redirect**\ (), except
44769aa1206eSDaniel Borkmann  * 		that the redirection happens to the *ifindex*' peer device and
44779aa1206eSDaniel Borkmann  * 		the netns switch takes place from ingress to ingress without
44789aa1206eSDaniel Borkmann  * 		going through the CPU's backlog queue.
44799aa1206eSDaniel Borkmann  *
44809aa1206eSDaniel Borkmann  * 		The *flags* argument is reserved and must be 0. The helper is
44819aa1206eSDaniel Borkmann  * 		currently only supported for tc BPF program types at the ingress
44829aa1206eSDaniel Borkmann  * 		hook and for veth device types. The peer device must reside in a
44839aa1206eSDaniel Borkmann  * 		different network namespace.
44849aa1206eSDaniel Borkmann  * 	Return
44859aa1206eSDaniel Borkmann  * 		The helper returns **TC_ACT_REDIRECT** on success or
44869aa1206eSDaniel Borkmann  * 		**TC_ACT_SHOT** on error.
44874cf1bc1fSKP Singh  *
44884cf1bc1fSKP Singh  * void *bpf_task_storage_get(struct bpf_map *map, struct task_struct *task, void *value, u64 flags)
44894cf1bc1fSKP Singh  *	Description
44904cf1bc1fSKP Singh  *		Get a bpf_local_storage from the *task*.
44914cf1bc1fSKP Singh  *
44924cf1bc1fSKP Singh  *		Logically, it could be thought of as getting the value from
44934cf1bc1fSKP Singh  *		a *map* with *task* as the **key**.  From this
44944cf1bc1fSKP Singh  *		perspective,  the usage is not much different from
44954cf1bc1fSKP Singh  *		**bpf_map_lookup_elem**\ (*map*, **&**\ *task*) except this
44964cf1bc1fSKP Singh  *		helper enforces the key must be an task_struct and the map must also
44974cf1bc1fSKP Singh  *		be a **BPF_MAP_TYPE_TASK_STORAGE**.
44984cf1bc1fSKP Singh  *
44994cf1bc1fSKP Singh  *		Underneath, the value is stored locally at *task* instead of
45004cf1bc1fSKP Singh  *		the *map*.  The *map* is used as the bpf-local-storage
45014cf1bc1fSKP Singh  *		"type". The bpf-local-storage "type" (i.e. the *map*) is
45024cf1bc1fSKP Singh  *		searched against all bpf_local_storage residing at *task*.
45034cf1bc1fSKP Singh  *
45044cf1bc1fSKP Singh  *		An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
45054cf1bc1fSKP Singh  *		used such that a new bpf_local_storage will be
45064cf1bc1fSKP Singh  *		created if one does not exist.  *value* can be used
45074cf1bc1fSKP Singh  *		together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
45084cf1bc1fSKP Singh  *		the initial value of a bpf_local_storage.  If *value* is
45094cf1bc1fSKP Singh  *		**NULL**, the new bpf_local_storage will be zero initialized.
45104cf1bc1fSKP Singh  *	Return
45114cf1bc1fSKP Singh  *		A bpf_local_storage pointer is returned on success.
45124cf1bc1fSKP Singh  *
45134cf1bc1fSKP Singh  *		**NULL** if not found or there was an error in adding
45144cf1bc1fSKP Singh  *		a new bpf_local_storage.
45154cf1bc1fSKP Singh  *
45164cf1bc1fSKP Singh  * long bpf_task_storage_delete(struct bpf_map *map, struct task_struct *task)
45174cf1bc1fSKP Singh  *	Description
45184cf1bc1fSKP Singh  *		Delete a bpf_local_storage from a *task*.
45194cf1bc1fSKP Singh  *	Return
45204cf1bc1fSKP Singh  *		0 on success.
45214cf1bc1fSKP Singh  *
45224cf1bc1fSKP Singh  *		**-ENOENT** if the bpf_local_storage cannot be found.
45233ca1032aSKP Singh  *
45243ca1032aSKP Singh  * struct task_struct *bpf_get_current_task_btf(void)
45253ca1032aSKP Singh  *	Description
45263ca1032aSKP Singh  *		Return a BTF pointer to the "current" task.
45273ca1032aSKP Singh  *		This pointer can also be used in helpers that accept an
45283ca1032aSKP Singh  *		*ARG_PTR_TO_BTF_ID* of type *task_struct*.
45293ca1032aSKP Singh  *	Return
45303ca1032aSKP Singh  *		Pointer to the current task.
45313f6719c7SKP Singh  *
45323f6719c7SKP Singh  * long bpf_bprm_opts_set(struct linux_binprm *bprm, u64 flags)
45333f6719c7SKP Singh  *	Description
45343f6719c7SKP Singh  *		Set or clear certain options on *bprm*:
45353f6719c7SKP Singh  *
45363f6719c7SKP Singh  *		**BPF_F_BPRM_SECUREEXEC** Set the secureexec bit
45373f6719c7SKP Singh  *		which sets the **AT_SECURE** auxv for glibc. The bit
45383f6719c7SKP Singh  *		is cleared if the flag is not specified.
45393f6719c7SKP Singh  *	Return
45403f6719c7SKP Singh  *		**-EINVAL** if invalid *flags* are passed, zero otherwise.
4541d0551261SDmitrii Banshchikov  *
4542d0551261SDmitrii Banshchikov  * u64 bpf_ktime_get_coarse_ns(void)
4543d0551261SDmitrii Banshchikov  * 	Description
4544d0551261SDmitrii Banshchikov  * 		Return a coarse-grained version of the time elapsed since
4545d0551261SDmitrii Banshchikov  * 		system boot, in nanoseconds. Does not include time the system
4546d0551261SDmitrii Banshchikov  * 		was suspended.
4547d0551261SDmitrii Banshchikov  *
4548d0551261SDmitrii Banshchikov  * 		See: **clock_gettime**\ (**CLOCK_MONOTONIC_COARSE**)
4549d0551261SDmitrii Banshchikov  * 	Return
4550d0551261SDmitrii Banshchikov  * 		Current *ktime*.
455127672f0dSKP Singh  *
455227672f0dSKP Singh  * long bpf_ima_inode_hash(struct inode *inode, void *dst, u32 size)
455327672f0dSKP Singh  *	Description
455427672f0dSKP Singh  *		Returns the stored IMA hash of the *inode* (if it's avaialable).
455527672f0dSKP Singh  *		If the hash is larger than *size*, then only *size*
455627672f0dSKP Singh  *		bytes will be copied to *dst*
455727672f0dSKP Singh  *	Return
455827672f0dSKP Singh  *		The **hash_algo** is returned on success,
455927672f0dSKP Singh  *		**-EOPNOTSUP** if IMA is disabled or **-EINVAL** if
456027672f0dSKP Singh  *		invalid arguments are passed.
45614f19cab7SFlorent Revest  *
45624f19cab7SFlorent Revest  * struct socket *bpf_sock_from_file(struct file *file)
45634f19cab7SFlorent Revest  *	Description
45644f19cab7SFlorent Revest  *		If the given file represents a socket, returns the associated
45654f19cab7SFlorent Revest  *		socket.
45664f19cab7SFlorent Revest  *	Return
45674f19cab7SFlorent Revest  *		A pointer to a struct socket on success or NULL if the file is
45684f19cab7SFlorent Revest  *		not a socket.
456934b2021cSJesper Dangaard Brouer  *
457034b2021cSJesper Dangaard Brouer  * long bpf_check_mtu(void *ctx, u32 ifindex, u32 *mtu_len, s32 len_diff, u64 flags)
457134b2021cSJesper Dangaard Brouer  *	Description
457234b2021cSJesper Dangaard Brouer  *		Check ctx packet size against exceeding MTU of net device (based
457334b2021cSJesper Dangaard Brouer  *		on *ifindex*).  This helper will likely be used in combination
457434b2021cSJesper Dangaard Brouer  *		with helpers that adjust/change the packet size.
457534b2021cSJesper Dangaard Brouer  *
457634b2021cSJesper Dangaard Brouer  *		The argument *len_diff* can be used for querying with a planned
457734b2021cSJesper Dangaard Brouer  *		size change. This allows to check MTU prior to changing packet
457834b2021cSJesper Dangaard Brouer  *		ctx. Providing an *len_diff* adjustment that is larger than the
457934b2021cSJesper Dangaard Brouer  *		actual packet size (resulting in negative packet size) will in
458034b2021cSJesper Dangaard Brouer  *		principle not exceed the MTU, why it is not considered a
458134b2021cSJesper Dangaard Brouer  *		failure.  Other BPF-helpers are needed for performing the
458234b2021cSJesper Dangaard Brouer  *		planned size change, why the responsability for catch a negative
458334b2021cSJesper Dangaard Brouer  *		packet size belong in those helpers.
458434b2021cSJesper Dangaard Brouer  *
458534b2021cSJesper Dangaard Brouer  *		Specifying *ifindex* zero means the MTU check is performed
458634b2021cSJesper Dangaard Brouer  *		against the current net device.  This is practical if this isn't
458734b2021cSJesper Dangaard Brouer  *		used prior to redirect.
458834b2021cSJesper Dangaard Brouer  *
458934b2021cSJesper Dangaard Brouer  *		The Linux kernel route table can configure MTUs on a more
459034b2021cSJesper Dangaard Brouer  *		specific per route level, which is not provided by this helper.
459134b2021cSJesper Dangaard Brouer  *		For route level MTU checks use the **bpf_fib_lookup**\ ()
459234b2021cSJesper Dangaard Brouer  *		helper.
459334b2021cSJesper Dangaard Brouer  *
459434b2021cSJesper Dangaard Brouer  *		*ctx* is either **struct xdp_md** for XDP programs or
459534b2021cSJesper Dangaard Brouer  *		**struct sk_buff** for tc cls_act programs.
459634b2021cSJesper Dangaard Brouer  *
459734b2021cSJesper Dangaard Brouer  *		The *flags* argument can be a combination of one or more of the
459834b2021cSJesper Dangaard Brouer  *		following values:
459934b2021cSJesper Dangaard Brouer  *
460034b2021cSJesper Dangaard Brouer  *		**BPF_MTU_CHK_SEGS**
460134b2021cSJesper Dangaard Brouer  *			This flag will only works for *ctx* **struct sk_buff**.
460234b2021cSJesper Dangaard Brouer  *			If packet context contains extra packet segment buffers
460334b2021cSJesper Dangaard Brouer  *			(often knows as GSO skb), then MTU check is harder to
460434b2021cSJesper Dangaard Brouer  *			check at this point, because in transmit path it is
460534b2021cSJesper Dangaard Brouer  *			possible for the skb packet to get re-segmented
460634b2021cSJesper Dangaard Brouer  *			(depending on net device features).  This could still be
460734b2021cSJesper Dangaard Brouer  *			a MTU violation, so this flag enables performing MTU
460834b2021cSJesper Dangaard Brouer  *			check against segments, with a different violation
460934b2021cSJesper Dangaard Brouer  *			return code to tell it apart. Check cannot use len_diff.
461034b2021cSJesper Dangaard Brouer  *
461134b2021cSJesper Dangaard Brouer  *		On return *mtu_len* pointer contains the MTU value of the net
461234b2021cSJesper Dangaard Brouer  *		device.  Remember the net device configured MTU is the L3 size,
461334b2021cSJesper Dangaard Brouer  *		which is returned here and XDP and TX length operate at L2.
461434b2021cSJesper Dangaard Brouer  *		Helper take this into account for you, but remember when using
461534b2021cSJesper Dangaard Brouer  *		MTU value in your BPF-code.  On input *mtu_len* must be a valid
461634b2021cSJesper Dangaard Brouer  *		pointer and be initialized (to zero), else verifier will reject
461734b2021cSJesper Dangaard Brouer  *		BPF program.
461834b2021cSJesper Dangaard Brouer  *
461934b2021cSJesper Dangaard Brouer  *	Return
462034b2021cSJesper Dangaard Brouer  *		* 0 on success, and populate MTU value in *mtu_len* pointer.
462134b2021cSJesper Dangaard Brouer  *
462234b2021cSJesper Dangaard Brouer  *		* < 0 if any input argument is invalid (*mtu_len* not updated)
462334b2021cSJesper Dangaard Brouer  *
462434b2021cSJesper Dangaard Brouer  *		MTU violations return positive values, but also populate MTU
462534b2021cSJesper Dangaard Brouer  *		value in *mtu_len* pointer, as this can be needed for
462634b2021cSJesper Dangaard Brouer  *		implementing PMTU handing:
462734b2021cSJesper Dangaard Brouer  *
462834b2021cSJesper Dangaard Brouer  *		* **BPF_MTU_CHK_RET_FRAG_NEEDED**
462934b2021cSJesper Dangaard Brouer  *		* **BPF_MTU_CHK_RET_SEGS_TOOBIG**
463034b2021cSJesper Dangaard Brouer  *
463169c087baSYonghong Song  * long bpf_for_each_map_elem(struct bpf_map *map, void *callback_fn, void *callback_ctx, u64 flags)
463269c087baSYonghong Song  *	Description
463369c087baSYonghong Song  *		For each element in **map**, call **callback_fn** function with
463469c087baSYonghong Song  *		**map**, **callback_ctx** and other map-specific parameters.
463569c087baSYonghong Song  *		The **callback_fn** should be a static function and
463669c087baSYonghong Song  *		the **callback_ctx** should be a pointer to the stack.
463769c087baSYonghong Song  *		The **flags** is used to control certain aspects of the helper.
463869c087baSYonghong Song  *		Currently, the **flags** must be 0.
463969c087baSYonghong Song  *
464069c087baSYonghong Song  *		The following are a list of supported map types and their
464169c087baSYonghong Song  *		respective expected callback signatures:
464269c087baSYonghong Song  *
464369c087baSYonghong Song  *		BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_PERCPU_HASH,
464469c087baSYonghong Song  *		BPF_MAP_TYPE_LRU_HASH, BPF_MAP_TYPE_LRU_PERCPU_HASH,
464569c087baSYonghong Song  *		BPF_MAP_TYPE_ARRAY, BPF_MAP_TYPE_PERCPU_ARRAY
464669c087baSYonghong Song  *
464769c087baSYonghong Song  *		long (\*callback_fn)(struct bpf_map \*map, const void \*key, void \*value, void \*ctx);
464869c087baSYonghong Song  *
464969c087baSYonghong Song  *		For per_cpu maps, the map_value is the value on the cpu where the
465069c087baSYonghong Song  *		bpf_prog is running.
465169c087baSYonghong Song  *
465269c087baSYonghong Song  *		If **callback_fn** return 0, the helper will continue to the next
465369c087baSYonghong Song  *		element. If return value is 1, the helper will skip the rest of
465469c087baSYonghong Song  *		elements and return. Other return values are not used now.
465569c087baSYonghong Song  *
465669c087baSYonghong Song  *	Return
465769c087baSYonghong Song  *		The number of traversed map elements for success, **-EINVAL** for
465869c087baSYonghong Song  *		invalid **flags**.
46597a4b28c6SDaniel Borkmann  */
4660ebb676daSThomas Graf #define __BPF_FUNC_MAPPER(FN)		\
4661ebb676daSThomas Graf 	FN(unspec),			\
4662ebb676daSThomas Graf 	FN(map_lookup_elem),		\
4663ebb676daSThomas Graf 	FN(map_update_elem),		\
4664ebb676daSThomas Graf 	FN(map_delete_elem),		\
4665ebb676daSThomas Graf 	FN(probe_read),			\
4666ebb676daSThomas Graf 	FN(ktime_get_ns),		\
4667ebb676daSThomas Graf 	FN(trace_printk),		\
4668ebb676daSThomas Graf 	FN(get_prandom_u32),		\
4669ebb676daSThomas Graf 	FN(get_smp_processor_id),	\
4670ebb676daSThomas Graf 	FN(skb_store_bytes),		\
4671ebb676daSThomas Graf 	FN(l3_csum_replace),		\
4672ebb676daSThomas Graf 	FN(l4_csum_replace),		\
4673ebb676daSThomas Graf 	FN(tail_call),			\
4674ebb676daSThomas Graf 	FN(clone_redirect),		\
4675ebb676daSThomas Graf 	FN(get_current_pid_tgid),	\
4676ebb676daSThomas Graf 	FN(get_current_uid_gid),	\
4677ebb676daSThomas Graf 	FN(get_current_comm),		\
4678ebb676daSThomas Graf 	FN(get_cgroup_classid),		\
4679ebb676daSThomas Graf 	FN(skb_vlan_push),		\
4680ebb676daSThomas Graf 	FN(skb_vlan_pop),		\
4681ebb676daSThomas Graf 	FN(skb_get_tunnel_key),		\
4682ebb676daSThomas Graf 	FN(skb_set_tunnel_key),		\
4683ebb676daSThomas Graf 	FN(perf_event_read),		\
4684ebb676daSThomas Graf 	FN(redirect),			\
4685ebb676daSThomas Graf 	FN(get_route_realm),		\
4686ebb676daSThomas Graf 	FN(perf_event_output),		\
4687ebb676daSThomas Graf 	FN(skb_load_bytes),		\
4688ebb676daSThomas Graf 	FN(get_stackid),		\
4689ebb676daSThomas Graf 	FN(csum_diff),			\
4690ebb676daSThomas Graf 	FN(skb_get_tunnel_opt),		\
4691ebb676daSThomas Graf 	FN(skb_set_tunnel_opt),		\
4692ebb676daSThomas Graf 	FN(skb_change_proto),		\
4693ebb676daSThomas Graf 	FN(skb_change_type),		\
4694ebb676daSThomas Graf 	FN(skb_under_cgroup),		\
4695ebb676daSThomas Graf 	FN(get_hash_recalc),		\
4696ebb676daSThomas Graf 	FN(get_current_task),		\
4697ebb676daSThomas Graf 	FN(probe_write_user),		\
4698ebb676daSThomas Graf 	FN(current_task_under_cgroup),	\
4699ebb676daSThomas Graf 	FN(skb_change_tail),		\
4700ebb676daSThomas Graf 	FN(skb_pull_data),		\
4701ebb676daSThomas Graf 	FN(csum_update),		\
4702ebb676daSThomas Graf 	FN(set_hash_invalid),		\
47033a0af8fdSThomas Graf 	FN(get_numa_node_id),		\
470417bedab2SMartin KaFai Lau 	FN(skb_change_head),		\
4705a5e8c070SGianluca Borello 	FN(xdp_adjust_head),		\
470691b8270fSChenbo Feng 	FN(probe_read_str),		\
47076acc5c29SChenbo Feng 	FN(get_socket_cookie),		\
4708ded092cdSDaniel Borkmann 	FN(get_socket_uid),		\
47098c4b4c7eSLawrence Brakmo 	FN(set_hash),			\
47102be7e212SDaniel Borkmann 	FN(setsockopt),			\
471197f91a7cSJohn Fastabend 	FN(skb_adjust_room),		\
4712174a79ffSJohn Fastabend 	FN(redirect_map),		\
4713174a79ffSJohn Fastabend 	FN(sk_redirect_map),		\
4714174a79ffSJohn Fastabend 	FN(sock_map_update),		\
4715908432caSYonghong Song 	FN(xdp_adjust_meta),		\
47164bebdc7aSYonghong Song 	FN(perf_event_read_value),	\
4717cd86d1fdSLawrence Brakmo 	FN(perf_prog_read_value),	\
47189802d865SJosef Bacik 	FN(getsockopt),			\
4719b13d8807SLawrence Brakmo 	FN(override_return),		\
47204f738adbSJohn Fastabend 	FN(sock_ops_cb_flags_set),	\
47212a100317SJohn Fastabend 	FN(msg_redirect_map),		\
472291843d54SJohn Fastabend 	FN(msg_apply_bytes),		\
4723015632bbSJohn Fastabend 	FN(msg_cork_bytes),		\
4724d74bad4eSAndrey Ignatov 	FN(msg_pull_data),		\
4725b32cc5b9SNikita V. Shirokov 	FN(bind),			\
472612bed760SEyal Birger 	FN(xdp_adjust_tail),		\
4727c195651eSYonghong Song 	FN(skb_get_xfrm_state),		\
47284e1ec56cSDaniel Borkmann 	FN(get_stack),			\
472987f5fc7eSDavid Ahern 	FN(skb_load_bytes_relative),	\
473081110384SJohn Fastabend 	FN(fib_lookup),			\
473181110384SJohn Fastabend 	FN(sock_hash_update),		\
473281110384SJohn Fastabend 	FN(msg_redirect_hash),		\
4733fe94cc29SMathieu Xhonneux 	FN(sk_redirect_hash),		\
4734fe94cc29SMathieu Xhonneux 	FN(lwt_push_encap),		\
4735fe94cc29SMathieu Xhonneux 	FN(lwt_seg6_store_bytes),	\
4736fe94cc29SMathieu Xhonneux 	FN(lwt_seg6_adjust_srh),	\
4737f4364dcfSSean Young 	FN(lwt_seg6_action),		\
4738f4364dcfSSean Young 	FN(rc_repeat),			\
4739cb20b08eSDaniel Borkmann 	FN(rc_keydown),			\
4740bf6fa2c8SYonghong Song 	FN(skb_cgroup_id),		\
4741cd339431SRoman Gushchin 	FN(get_current_cgroup_id),	\
47422dbb9b9eSMartin KaFai Lau 	FN(get_local_storage),		\
474377236281SAndrey Ignatov 	FN(sk_select_reuseport),	\
47446acc9b43SJoe Stringer 	FN(skb_ancestor_cgroup_id),	\
47456acc9b43SJoe Stringer 	FN(sk_lookup_tcp),		\
47466acc9b43SJoe Stringer 	FN(sk_lookup_udp),		\
4747f1a2e44aSMauricio Vasquez B 	FN(sk_release),			\
4748f1a2e44aSMauricio Vasquez B 	FN(map_push_elem),		\
4749f1a2e44aSMauricio Vasquez B 	FN(map_pop_elem),		\
47506fff607eSJohn Fastabend 	FN(map_peek_elem),		\
47517246d8edSJohn Fastabend 	FN(msg_push_data),		\
475201d3240aSSean Young 	FN(msg_pop_data),		\
4753d83525caSAlexei Starovoitov 	FN(rc_pointer_rel),		\
4754d83525caSAlexei Starovoitov 	FN(spin_lock),			\
475546f8bc92SMartin KaFai Lau 	FN(spin_unlock),		\
4756655a51e5SMartin KaFai Lau 	FN(sk_fullsock),		\
4757f7c917baSbrakmo 	FN(tcp_sock),			\
4758dbafd7ddSMartin KaFai Lau 	FN(skb_ecn_set_ce),		\
4759edbf8c01SLorenz Bauer 	FN(get_listener_sock),		\
476039904084SLorenz Bauer 	FN(skc_lookup_tcp),		\
4761808649fbSAndrey Ignatov 	FN(tcp_check_syncookie),	\
47621d11b301SAndrey Ignatov 	FN(sysctl_get_name),		\
47634e63acdfSAndrey Ignatov 	FN(sysctl_get_current_value),	\
47644e63acdfSAndrey Ignatov 	FN(sysctl_get_new_value),	\
4765d7a4cb9bSAndrey Ignatov 	FN(sysctl_set_new_value),	\
4766d7a4cb9bSAndrey Ignatov 	FN(strtol),			\
47676ac99e8fSMartin KaFai Lau 	FN(strtoul),			\
47686ac99e8fSMartin KaFai Lau 	FN(sk_storage_get),		\
47698b401f9eSYonghong Song 	FN(sk_storage_delete),		\
477070d66244SPetar Penkov 	FN(send_signal),		\
4771a7658e1aSAlexei Starovoitov 	FN(tcp_gen_syncookie),		\
47726ae08ae3SDaniel Borkmann 	FN(skb_output),			\
47736ae08ae3SDaniel Borkmann 	FN(probe_read_user),		\
47746ae08ae3SDaniel Borkmann 	FN(probe_read_kernel),		\
47756ae08ae3SDaniel Borkmann 	FN(probe_read_user_str),	\
4776206057feSMartin KaFai Lau 	FN(probe_read_kernel_str),	\
47778482941fSYonghong Song 	FN(tcp_send_ack),		\
47785576b991SMartin KaFai Lau 	FN(send_signal_thread),		\
4779fff7b643SDaniel Xu 	FN(jiffies64),			\
4780b4490c5cSCarlos Neira 	FN(read_branch_records),	\
4781d831ee84SEelco Chaudron 	FN(get_ns_current_pid_tgid),	\
4782f318903cSDaniel Borkmann 	FN(xdp_output),			\
47830f09abd1SDaniel Borkmann 	FN(get_netns_cookie),		\
4784cf7fbe66SJoe Stringer 	FN(get_current_ancestor_cgroup_id),	\
478571d19214SMaciej Żenczykowski 	FN(sk_assign),			\
4786492e639fSYonghong Song 	FN(ktime_get_boot_ns),		\
4787492e639fSYonghong Song 	FN(seq_printf),			\
4788f307fa2cSAndrey Ignatov 	FN(seq_write),			\
4789f307fa2cSAndrey Ignatov 	FN(sk_cgroup_id),		\
4790457f4436SAndrii Nakryiko 	FN(sk_ancestor_cgroup_id),	\
4791457f4436SAndrii Nakryiko 	FN(ringbuf_output),		\
4792457f4436SAndrii Nakryiko 	FN(ringbuf_reserve),		\
4793457f4436SAndrii Nakryiko 	FN(ringbuf_submit),		\
4794457f4436SAndrii Nakryiko 	FN(ringbuf_discard),		\
47957cdec54fSDaniel Borkmann 	FN(ringbuf_query),		\
4796af7ec138SYonghong Song 	FN(csum_level),			\
4797478cfbdfSYonghong Song 	FN(skc_to_tcp6_sock),		\
4798478cfbdfSYonghong Song 	FN(skc_to_tcp_sock),		\
4799478cfbdfSYonghong Song 	FN(skc_to_tcp_timewait_sock),	\
48000d4fad3eSYonghong Song 	FN(skc_to_tcp_request_sock),	\
4801fa28dcb8SSong Liu 	FN(skc_to_udp6_sock),		\
4802fa28dcb8SSong Liu 	FN(get_task_stack),		\
48030813a841SMartin KaFai Lau 	FN(load_hdr_opt),		\
48040813a841SMartin KaFai Lau 	FN(store_hdr_opt),		\
48058ea63684SKP Singh 	FN(reserve_hdr_opt),		\
48068ea63684SKP Singh 	FN(inode_storage_get),		\
48078ea63684SKP Singh 	FN(inode_storage_delete),	\
48086e22ab9dSJiri Olsa 	FN(d_path),			\
480907be4c4aSAlexei Starovoitov 	FN(copy_from_user),		\
4810c4d0bfb4SAlan Maguire 	FN(snprintf_btf),		\
4811eb411377SAlan Maguire 	FN(seq_printf_btf),		\
4812b426ce83SDaniel Borkmann 	FN(skb_cgroup_classid),		\
4813b4ab3141SDaniel Borkmann 	FN(redirect_neigh),		\
4814b7906b70SAndrii Nakryiko 	FN(per_cpu_ptr),		\
4815b7906b70SAndrii Nakryiko 	FN(this_cpu_ptr),		\
48169aa1206eSDaniel Borkmann 	FN(redirect_peer),		\
48174cf1bc1fSKP Singh 	FN(task_storage_get),		\
48184cf1bc1fSKP Singh 	FN(task_storage_delete),	\
48193ca1032aSKP Singh 	FN(get_current_task_btf),	\
48203f6719c7SKP Singh 	FN(bprm_opts_set),		\
4821d0551261SDmitrii Banshchikov 	FN(ktime_get_coarse_ns),	\
482227672f0dSKP Singh 	FN(ima_inode_hash),		\
48234f19cab7SFlorent Revest 	FN(sock_from_file),		\
482434b2021cSJesper Dangaard Brouer 	FN(check_mtu),			\
482569c087baSYonghong Song 	FN(for_each_map_elem),		\
4826fa28dcb8SSong Liu 	/* */
48277a4b28c6SDaniel Borkmann 
4828ebb676daSThomas Graf /* integer value in 'imm' field of BPF_CALL instruction selects which helper
4829ebb676daSThomas Graf  * function eBPF program intends to call
48302d0e30c3SDaniel Borkmann  */
4831ebb676daSThomas Graf #define __BPF_ENUM_FN(x) BPF_FUNC_ ## x
4832ebb676daSThomas Graf enum bpf_func_id {
4833ebb676daSThomas Graf 	__BPF_FUNC_MAPPER(__BPF_ENUM_FN)
483409756af4SAlexei Starovoitov 	__BPF_FUNC_MAX_ID,
483509756af4SAlexei Starovoitov };
4836ebb676daSThomas Graf #undef __BPF_ENUM_FN
483709756af4SAlexei Starovoitov 
4838781c53bcSDaniel Borkmann /* All flags used by eBPF helper functions, placed here. */
4839781c53bcSDaniel Borkmann 
4840781c53bcSDaniel Borkmann /* BPF_FUNC_skb_store_bytes flags. */
48411aae4bddSAndrii Nakryiko enum {
48421aae4bddSAndrii Nakryiko 	BPF_F_RECOMPUTE_CSUM		= (1ULL << 0),
48431aae4bddSAndrii Nakryiko 	BPF_F_INVALIDATE_HASH		= (1ULL << 1),
48441aae4bddSAndrii Nakryiko };
4845781c53bcSDaniel Borkmann 
4846781c53bcSDaniel Borkmann /* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
4847781c53bcSDaniel Borkmann  * First 4 bits are for passing the header field size.
4848781c53bcSDaniel Borkmann  */
48491aae4bddSAndrii Nakryiko enum {
48501aae4bddSAndrii Nakryiko 	BPF_F_HDR_FIELD_MASK		= 0xfULL,
48511aae4bddSAndrii Nakryiko };
4852781c53bcSDaniel Borkmann 
4853781c53bcSDaniel Borkmann /* BPF_FUNC_l4_csum_replace flags. */
48541aae4bddSAndrii Nakryiko enum {
48551aae4bddSAndrii Nakryiko 	BPF_F_PSEUDO_HDR		= (1ULL << 4),
48561aae4bddSAndrii Nakryiko 	BPF_F_MARK_MANGLED_0		= (1ULL << 5),
48571aae4bddSAndrii Nakryiko 	BPF_F_MARK_ENFORCE		= (1ULL << 6),
48581aae4bddSAndrii Nakryiko };
4859781c53bcSDaniel Borkmann 
4860781c53bcSDaniel Borkmann /* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */
48611aae4bddSAndrii Nakryiko enum {
48621aae4bddSAndrii Nakryiko 	BPF_F_INGRESS			= (1ULL << 0),
48631aae4bddSAndrii Nakryiko };
4864781c53bcSDaniel Borkmann 
4865c6c33454SDaniel Borkmann /* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */
48661aae4bddSAndrii Nakryiko enum {
48671aae4bddSAndrii Nakryiko 	BPF_F_TUNINFO_IPV6		= (1ULL << 0),
48681aae4bddSAndrii Nakryiko };
4869c6c33454SDaniel Borkmann 
4870c195651eSYonghong Song /* flags for both BPF_FUNC_get_stackid and BPF_FUNC_get_stack. */
48711aae4bddSAndrii Nakryiko enum {
48721aae4bddSAndrii Nakryiko 	BPF_F_SKIP_FIELD_MASK		= 0xffULL,
48731aae4bddSAndrii Nakryiko 	BPF_F_USER_STACK		= (1ULL << 8),
4874c195651eSYonghong Song /* flags used by BPF_FUNC_get_stackid only. */
48751aae4bddSAndrii Nakryiko 	BPF_F_FAST_STACK_CMP		= (1ULL << 9),
48761aae4bddSAndrii Nakryiko 	BPF_F_REUSE_STACKID		= (1ULL << 10),
4877c195651eSYonghong Song /* flags used by BPF_FUNC_get_stack only. */
48781aae4bddSAndrii Nakryiko 	BPF_F_USER_BUILD_ID		= (1ULL << 11),
48791aae4bddSAndrii Nakryiko };
4880d5a3b1f6SAlexei Starovoitov 
48812da897e5SDaniel Borkmann /* BPF_FUNC_skb_set_tunnel_key flags. */
48821aae4bddSAndrii Nakryiko enum {
48831aae4bddSAndrii Nakryiko 	BPF_F_ZERO_CSUM_TX		= (1ULL << 1),
48841aae4bddSAndrii Nakryiko 	BPF_F_DONT_FRAGMENT		= (1ULL << 2),
48851aae4bddSAndrii Nakryiko 	BPF_F_SEQ_NUMBER		= (1ULL << 3),
48861aae4bddSAndrii Nakryiko };
48872da897e5SDaniel Borkmann 
4888908432caSYonghong Song /* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
4889908432caSYonghong Song  * BPF_FUNC_perf_event_read_value flags.
4890908432caSYonghong Song  */
48911aae4bddSAndrii Nakryiko enum {
48921aae4bddSAndrii Nakryiko 	BPF_F_INDEX_MASK		= 0xffffffffULL,
48931aae4bddSAndrii Nakryiko 	BPF_F_CURRENT_CPU		= BPF_F_INDEX_MASK,
4894555c8a86SDaniel Borkmann /* BPF_FUNC_perf_event_output for sk_buff input context. */
48951aae4bddSAndrii Nakryiko 	BPF_F_CTXLEN_MASK		= (0xfffffULL << 32),
48961aae4bddSAndrii Nakryiko };
48971e33759cSDaniel Borkmann 
4898f71c6143SJoe Stringer /* Current network namespace */
48991aae4bddSAndrii Nakryiko enum {
49001aae4bddSAndrii Nakryiko 	BPF_F_CURRENT_NETNS		= (-1L),
49011aae4bddSAndrii Nakryiko };
4902f71c6143SJoe Stringer 
49037cdec54fSDaniel Borkmann /* BPF_FUNC_csum_level level values. */
49047cdec54fSDaniel Borkmann enum {
49057cdec54fSDaniel Borkmann 	BPF_CSUM_LEVEL_QUERY,
49067cdec54fSDaniel Borkmann 	BPF_CSUM_LEVEL_INC,
49077cdec54fSDaniel Borkmann 	BPF_CSUM_LEVEL_DEC,
49087cdec54fSDaniel Borkmann 	BPF_CSUM_LEVEL_RESET,
49097cdec54fSDaniel Borkmann };
49107cdec54fSDaniel Borkmann 
49112278f6ccSWillem de Bruijn /* BPF_FUNC_skb_adjust_room flags. */
49121aae4bddSAndrii Nakryiko enum {
49131aae4bddSAndrii Nakryiko 	BPF_F_ADJ_ROOM_FIXED_GSO	= (1ULL << 0),
49141aae4bddSAndrii Nakryiko 	BPF_F_ADJ_ROOM_ENCAP_L3_IPV4	= (1ULL << 1),
49151aae4bddSAndrii Nakryiko 	BPF_F_ADJ_ROOM_ENCAP_L3_IPV6	= (1ULL << 2),
49161aae4bddSAndrii Nakryiko 	BPF_F_ADJ_ROOM_ENCAP_L4_GRE	= (1ULL << 3),
49171aae4bddSAndrii Nakryiko 	BPF_F_ADJ_ROOM_ENCAP_L4_UDP	= (1ULL << 4),
4918836e66c2SDaniel Borkmann 	BPF_F_ADJ_ROOM_NO_CSUM_RESET	= (1ULL << 5),
49191aae4bddSAndrii Nakryiko };
49202278f6ccSWillem de Bruijn 
49211aae4bddSAndrii Nakryiko enum {
49221aae4bddSAndrii Nakryiko 	BPF_ADJ_ROOM_ENCAP_L2_MASK	= 0xff,
49231aae4bddSAndrii Nakryiko 	BPF_ADJ_ROOM_ENCAP_L2_SHIFT	= 56,
49241aae4bddSAndrii Nakryiko };
492558dfc900SAlan Maguire 
492658dfc900SAlan Maguire #define BPF_F_ADJ_ROOM_ENCAP_L2(len)	(((__u64)len & \
492758dfc900SAlan Maguire 					  BPF_ADJ_ROOM_ENCAP_L2_MASK) \
492858dfc900SAlan Maguire 					 << BPF_ADJ_ROOM_ENCAP_L2_SHIFT)
4929868d5235SWillem de Bruijn 
4930808649fbSAndrey Ignatov /* BPF_FUNC_sysctl_get_name flags. */
49311aae4bddSAndrii Nakryiko enum {
49321aae4bddSAndrii Nakryiko 	BPF_F_SYSCTL_BASE_NAME		= (1ULL << 0),
49331aae4bddSAndrii Nakryiko };
4934808649fbSAndrey Ignatov 
4935f836a56eSKP Singh /* BPF_FUNC_<kernel_obj>_storage_get flags */
49361aae4bddSAndrii Nakryiko enum {
4937f836a56eSKP Singh 	BPF_LOCAL_STORAGE_GET_F_CREATE	= (1ULL << 0),
4938f836a56eSKP Singh 	/* BPF_SK_STORAGE_GET_F_CREATE is only kept for backward compatibility
4939f836a56eSKP Singh 	 * and BPF_LOCAL_STORAGE_GET_F_CREATE must be used instead.
4940f836a56eSKP Singh 	 */
4941f836a56eSKP Singh 	BPF_SK_STORAGE_GET_F_CREATE  = BPF_LOCAL_STORAGE_GET_F_CREATE,
49421aae4bddSAndrii Nakryiko };
49436ac99e8fSMartin KaFai Lau 
4944fff7b643SDaniel Xu /* BPF_FUNC_read_branch_records flags. */
49451aae4bddSAndrii Nakryiko enum {
49461aae4bddSAndrii Nakryiko 	BPF_F_GET_BRANCH_RECORDS_SIZE	= (1ULL << 0),
49471aae4bddSAndrii Nakryiko };
4948fff7b643SDaniel Xu 
4949457f4436SAndrii Nakryiko /* BPF_FUNC_bpf_ringbuf_commit, BPF_FUNC_bpf_ringbuf_discard, and
4950457f4436SAndrii Nakryiko  * BPF_FUNC_bpf_ringbuf_output flags.
4951457f4436SAndrii Nakryiko  */
4952457f4436SAndrii Nakryiko enum {
4953457f4436SAndrii Nakryiko 	BPF_RB_NO_WAKEUP		= (1ULL << 0),
4954457f4436SAndrii Nakryiko 	BPF_RB_FORCE_WAKEUP		= (1ULL << 1),
4955457f4436SAndrii Nakryiko };
4956457f4436SAndrii Nakryiko 
4957457f4436SAndrii Nakryiko /* BPF_FUNC_bpf_ringbuf_query flags */
4958457f4436SAndrii Nakryiko enum {
4959457f4436SAndrii Nakryiko 	BPF_RB_AVAIL_DATA = 0,
4960457f4436SAndrii Nakryiko 	BPF_RB_RING_SIZE = 1,
4961457f4436SAndrii Nakryiko 	BPF_RB_CONS_POS = 2,
4962457f4436SAndrii Nakryiko 	BPF_RB_PROD_POS = 3,
4963457f4436SAndrii Nakryiko };
4964457f4436SAndrii Nakryiko 
4965457f4436SAndrii Nakryiko /* BPF ring buffer constants */
4966457f4436SAndrii Nakryiko enum {
4967457f4436SAndrii Nakryiko 	BPF_RINGBUF_BUSY_BIT		= (1U << 31),
4968457f4436SAndrii Nakryiko 	BPF_RINGBUF_DISCARD_BIT		= (1U << 30),
4969457f4436SAndrii Nakryiko 	BPF_RINGBUF_HDR_SZ		= 8,
4970457f4436SAndrii Nakryiko };
4971457f4436SAndrii Nakryiko 
4972e9ddbb77SJakub Sitnicki /* BPF_FUNC_sk_assign flags in bpf_sk_lookup context. */
4973e9ddbb77SJakub Sitnicki enum {
4974e9ddbb77SJakub Sitnicki 	BPF_SK_LOOKUP_F_REPLACE		= (1ULL << 0),
4975e9ddbb77SJakub Sitnicki 	BPF_SK_LOOKUP_F_NO_REUSEPORT	= (1ULL << 1),
4976e9ddbb77SJakub Sitnicki };
4977e9ddbb77SJakub Sitnicki 
49782be7e212SDaniel Borkmann /* Mode for BPF_FUNC_skb_adjust_room helper. */
49792be7e212SDaniel Borkmann enum bpf_adj_room_mode {
49802be7e212SDaniel Borkmann 	BPF_ADJ_ROOM_NET,
498114aa3192SWillem de Bruijn 	BPF_ADJ_ROOM_MAC,
49822be7e212SDaniel Borkmann };
49832be7e212SDaniel Borkmann 
49844e1ec56cSDaniel Borkmann /* Mode for BPF_FUNC_skb_load_bytes_relative helper. */
49854e1ec56cSDaniel Borkmann enum bpf_hdr_start_off {
49864e1ec56cSDaniel Borkmann 	BPF_HDR_START_MAC,
49874e1ec56cSDaniel Borkmann 	BPF_HDR_START_NET,
49884e1ec56cSDaniel Borkmann };
49894e1ec56cSDaniel Borkmann 
4990fe94cc29SMathieu Xhonneux /* Encapsulation type for BPF_FUNC_lwt_push_encap helper. */
4991fe94cc29SMathieu Xhonneux enum bpf_lwt_encap_mode {
4992fe94cc29SMathieu Xhonneux 	BPF_LWT_ENCAP_SEG6,
49933e0bd37cSPeter Oskolkov 	BPF_LWT_ENCAP_SEG6_INLINE,
49943e0bd37cSPeter Oskolkov 	BPF_LWT_ENCAP_IP,
4995fe94cc29SMathieu Xhonneux };
4996fe94cc29SMathieu Xhonneux 
49973f6719c7SKP Singh /* Flags for bpf_bprm_opts_set helper */
49983f6719c7SKP Singh enum {
49993f6719c7SKP Singh 	BPF_F_BPRM_SECUREEXEC	= (1ULL << 0),
50003f6719c7SKP Singh };
50013f6719c7SKP Singh 
5002b7df9adaSDaniel Borkmann #define __bpf_md_ptr(type, name)	\
5003b7df9adaSDaniel Borkmann union {					\
5004b7df9adaSDaniel Borkmann 	type name;			\
5005b7df9adaSDaniel Borkmann 	__u64 :64;			\
5006b7df9adaSDaniel Borkmann } __attribute__((aligned(8)))
5007b7df9adaSDaniel Borkmann 
50089bac3d6dSAlexei Starovoitov /* user accessible mirror of in-kernel sk_buff.
50099bac3d6dSAlexei Starovoitov  * new fields can only be added to the end of this structure
50109bac3d6dSAlexei Starovoitov  */
50119bac3d6dSAlexei Starovoitov struct __sk_buff {
50129bac3d6dSAlexei Starovoitov 	__u32 len;
50139bac3d6dSAlexei Starovoitov 	__u32 pkt_type;
50149bac3d6dSAlexei Starovoitov 	__u32 mark;
50159bac3d6dSAlexei Starovoitov 	__u32 queue_mapping;
5016c2497395SAlexei Starovoitov 	__u32 protocol;
5017c2497395SAlexei Starovoitov 	__u32 vlan_present;
5018c2497395SAlexei Starovoitov 	__u32 vlan_tci;
501927cd5452SMichal Sekletar 	__u32 vlan_proto;
5020bcad5718SDaniel Borkmann 	__u32 priority;
502137e82c2fSAlexei Starovoitov 	__u32 ingress_ifindex;
502237e82c2fSAlexei Starovoitov 	__u32 ifindex;
5023d691f9e8SAlexei Starovoitov 	__u32 tc_index;
5024d691f9e8SAlexei Starovoitov 	__u32 cb[5];
5025ba7591d8SDaniel Borkmann 	__u32 hash;
5026045efa82SDaniel Borkmann 	__u32 tc_classid;
5027969bf05eSAlexei Starovoitov 	__u32 data;
5028969bf05eSAlexei Starovoitov 	__u32 data_end;
5029b1d9fc41SDaniel Borkmann 	__u32 napi_id;
50308a31db56SJohn Fastabend 
5031de8f3a83SDaniel Borkmann 	/* Accessed by BPF_PROG_TYPE_sk_skb types from here to ... */
50328a31db56SJohn Fastabend 	__u32 family;
50338a31db56SJohn Fastabend 	__u32 remote_ip4;	/* Stored in network byte order */
50348a31db56SJohn Fastabend 	__u32 local_ip4;	/* Stored in network byte order */
50358a31db56SJohn Fastabend 	__u32 remote_ip6[4];	/* Stored in network byte order */
50368a31db56SJohn Fastabend 	__u32 local_ip6[4];	/* Stored in network byte order */
50378a31db56SJohn Fastabend 	__u32 remote_port;	/* Stored in network byte order */
50388a31db56SJohn Fastabend 	__u32 local_port;	/* stored in host byte order */
5039de8f3a83SDaniel Borkmann 	/* ... here. */
5040de8f3a83SDaniel Borkmann 
5041de8f3a83SDaniel Borkmann 	__u32 data_meta;
5042b7df9adaSDaniel Borkmann 	__bpf_md_ptr(struct bpf_flow_keys *, flow_keys);
5043f11216b2SVlad Dumitrescu 	__u64 tstamp;
5044e3da08d0SPetar Penkov 	__u32 wire_len;
5045d9ff286aSEric Dumazet 	__u32 gso_segs;
504646f8bc92SMartin KaFai Lau 	__bpf_md_ptr(struct bpf_sock *, sk);
5047cf62089bSWillem de Bruijn 	__u32 gso_size;
50489bac3d6dSAlexei Starovoitov };
50499bac3d6dSAlexei Starovoitov 
5050d3aa45ceSAlexei Starovoitov struct bpf_tunnel_key {
5051d3aa45ceSAlexei Starovoitov 	__u32 tunnel_id;
5052c6c33454SDaniel Borkmann 	union {
5053d3aa45ceSAlexei Starovoitov 		__u32 remote_ipv4;
5054c6c33454SDaniel Borkmann 		__u32 remote_ipv6[4];
5055c6c33454SDaniel Borkmann 	};
5056c6c33454SDaniel Borkmann 	__u8 tunnel_tos;
5057c6c33454SDaniel Borkmann 	__u8 tunnel_ttl;
50581fbc2e0cSDaniel Borkmann 	__u16 tunnel_ext;	/* Padding, future use. */
50594018ab18SDaniel Borkmann 	__u32 tunnel_label;
5060d3aa45ceSAlexei Starovoitov };
5061d3aa45ceSAlexei Starovoitov 
506212bed760SEyal Birger /* user accessible mirror of in-kernel xfrm_state.
506312bed760SEyal Birger  * new fields can only be added to the end of this structure
506412bed760SEyal Birger  */
506512bed760SEyal Birger struct bpf_xfrm_state {
506612bed760SEyal Birger 	__u32 reqid;
506712bed760SEyal Birger 	__u32 spi;	/* Stored in network byte order */
506812bed760SEyal Birger 	__u16 family;
50691fbc2e0cSDaniel Borkmann 	__u16 ext;	/* Padding, future use. */
507012bed760SEyal Birger 	union {
507112bed760SEyal Birger 		__u32 remote_ipv4;	/* Stored in network byte order */
507212bed760SEyal Birger 		__u32 remote_ipv6[4];	/* Stored in network byte order */
507312bed760SEyal Birger 	};
507412bed760SEyal Birger };
507512bed760SEyal Birger 
50763a0af8fdSThomas Graf /* Generic BPF return codes which all BPF program types may support.
50773a0af8fdSThomas Graf  * The values are binary compatible with their TC_ACT_* counter-part to
50783a0af8fdSThomas Graf  * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT
50793a0af8fdSThomas Graf  * programs.
50803a0af8fdSThomas Graf  *
50813a0af8fdSThomas Graf  * XDP is handled seprately, see XDP_*.
50823a0af8fdSThomas Graf  */
50833a0af8fdSThomas Graf enum bpf_ret_code {
50843a0af8fdSThomas Graf 	BPF_OK = 0,
50853a0af8fdSThomas Graf 	/* 1 reserved */
50863a0af8fdSThomas Graf 	BPF_DROP = 2,
50873a0af8fdSThomas Graf 	/* 3-6 reserved */
50883a0af8fdSThomas Graf 	BPF_REDIRECT = 7,
50893e0bd37cSPeter Oskolkov 	/* >127 are reserved for prog type specific return codes.
50903e0bd37cSPeter Oskolkov 	 *
50913e0bd37cSPeter Oskolkov 	 * BPF_LWT_REROUTE: used by BPF_PROG_TYPE_LWT_IN and
50923e0bd37cSPeter Oskolkov 	 *    BPF_PROG_TYPE_LWT_XMIT to indicate that skb had been
50933e0bd37cSPeter Oskolkov 	 *    changed and should be routed based on its new L3 header.
50943e0bd37cSPeter Oskolkov 	 *    (This is an L3 redirect, as opposed to L2 redirect
50953e0bd37cSPeter Oskolkov 	 *    represented by BPF_REDIRECT above).
50963e0bd37cSPeter Oskolkov 	 */
50973e0bd37cSPeter Oskolkov 	BPF_LWT_REROUTE = 128,
50983a0af8fdSThomas Graf };
50993a0af8fdSThomas Graf 
510061023658SDavid Ahern struct bpf_sock {
510161023658SDavid Ahern 	__u32 bound_dev_if;
5102aa4c1037SDavid Ahern 	__u32 family;
5103aa4c1037SDavid Ahern 	__u32 type;
5104aa4c1037SDavid Ahern 	__u32 protocol;
5105482dca93SDavid Ahern 	__u32 mark;
5106482dca93SDavid Ahern 	__u32 priority;
5107aa65d696SMartin KaFai Lau 	/* IP address also allows 1 and 2 bytes access */
5108aa65d696SMartin KaFai Lau 	__u32 src_ip4;
5109aa65d696SMartin KaFai Lau 	__u32 src_ip6[4];
5110aa65d696SMartin KaFai Lau 	__u32 src_port;		/* host byte order */
5111aa65d696SMartin KaFai Lau 	__u32 dst_port;		/* network byte order */
5112aa65d696SMartin KaFai Lau 	__u32 dst_ip4;
5113aa65d696SMartin KaFai Lau 	__u32 dst_ip6[4];
5114aa65d696SMartin KaFai Lau 	__u32 state;
5115c3c16f2eSAmritha Nambiar 	__s32 rx_queue_mapping;
511661023658SDavid Ahern };
511761023658SDavid Ahern 
5118655a51e5SMartin KaFai Lau struct bpf_tcp_sock {
5119655a51e5SMartin KaFai Lau 	__u32 snd_cwnd;		/* Sending congestion window		*/
5120655a51e5SMartin KaFai Lau 	__u32 srtt_us;		/* smoothed round trip time << 3 in usecs */
5121655a51e5SMartin KaFai Lau 	__u32 rtt_min;
5122655a51e5SMartin KaFai Lau 	__u32 snd_ssthresh;	/* Slow start size threshold		*/
5123655a51e5SMartin KaFai Lau 	__u32 rcv_nxt;		/* What we want to receive next		*/
5124655a51e5SMartin KaFai Lau 	__u32 snd_nxt;		/* Next sequence we send		*/
5125655a51e5SMartin KaFai Lau 	__u32 snd_una;		/* First byte we want an ack for	*/
5126655a51e5SMartin KaFai Lau 	__u32 mss_cache;	/* Cached effective mss, not including SACKS */
5127655a51e5SMartin KaFai Lau 	__u32 ecn_flags;	/* ECN status bits.			*/
5128655a51e5SMartin KaFai Lau 	__u32 rate_delivered;	/* saved rate sample: packets delivered */
5129655a51e5SMartin KaFai Lau 	__u32 rate_interval_us;	/* saved rate sample: time elapsed */
5130655a51e5SMartin KaFai Lau 	__u32 packets_out;	/* Packets which are "in flight"	*/
5131655a51e5SMartin KaFai Lau 	__u32 retrans_out;	/* Retransmitted packets out		*/
5132655a51e5SMartin KaFai Lau 	__u32 total_retrans;	/* Total retransmits for entire connection */
5133655a51e5SMartin KaFai Lau 	__u32 segs_in;		/* RFC4898 tcpEStatsPerfSegsIn
5134655a51e5SMartin KaFai Lau 				 * total number of segments in.
5135655a51e5SMartin KaFai Lau 				 */
5136655a51e5SMartin KaFai Lau 	__u32 data_segs_in;	/* RFC4898 tcpEStatsPerfDataSegsIn
5137655a51e5SMartin KaFai Lau 				 * total number of data segments in.
5138655a51e5SMartin KaFai Lau 				 */
5139655a51e5SMartin KaFai Lau 	__u32 segs_out;		/* RFC4898 tcpEStatsPerfSegsOut
5140655a51e5SMartin KaFai Lau 				 * The total number of segments sent.
5141655a51e5SMartin KaFai Lau 				 */
5142655a51e5SMartin KaFai Lau 	__u32 data_segs_out;	/* RFC4898 tcpEStatsPerfDataSegsOut
5143655a51e5SMartin KaFai Lau 				 * total number of data segments sent.
5144655a51e5SMartin KaFai Lau 				 */
5145655a51e5SMartin KaFai Lau 	__u32 lost_out;		/* Lost packets			*/
5146655a51e5SMartin KaFai Lau 	__u32 sacked_out;	/* SACK'd packets			*/
5147655a51e5SMartin KaFai Lau 	__u64 bytes_received;	/* RFC4898 tcpEStatsAppHCThruOctetsReceived
5148655a51e5SMartin KaFai Lau 				 * sum(delta(rcv_nxt)), or how many bytes
5149655a51e5SMartin KaFai Lau 				 * were acked.
5150655a51e5SMartin KaFai Lau 				 */
5151655a51e5SMartin KaFai Lau 	__u64 bytes_acked;	/* RFC4898 tcpEStatsAppHCThruOctetsAcked
5152655a51e5SMartin KaFai Lau 				 * sum(delta(snd_una)), or how many bytes
5153655a51e5SMartin KaFai Lau 				 * were acked.
5154655a51e5SMartin KaFai Lau 				 */
51550357746dSStanislav Fomichev 	__u32 dsack_dups;	/* RFC4898 tcpEStatsStackDSACKDups
51560357746dSStanislav Fomichev 				 * total number of DSACK blocks received
51570357746dSStanislav Fomichev 				 */
51580357746dSStanislav Fomichev 	__u32 delivered;	/* Total data packets delivered incl. rexmits */
51590357746dSStanislav Fomichev 	__u32 delivered_ce;	/* Like the above but only ECE marked packets */
5160c2cb5e82SStanislav Fomichev 	__u32 icsk_retransmits;	/* Number of unrecovered [RTO] timeouts */
5161655a51e5SMartin KaFai Lau };
5162655a51e5SMartin KaFai Lau 
51636acc9b43SJoe Stringer struct bpf_sock_tuple {
51646acc9b43SJoe Stringer 	union {
51656acc9b43SJoe Stringer 		struct {
51666acc9b43SJoe Stringer 			__be32 saddr;
51676acc9b43SJoe Stringer 			__be32 daddr;
51686acc9b43SJoe Stringer 			__be16 sport;
51696acc9b43SJoe Stringer 			__be16 dport;
51706acc9b43SJoe Stringer 		} ipv4;
51716acc9b43SJoe Stringer 		struct {
51726acc9b43SJoe Stringer 			__be32 saddr[4];
51736acc9b43SJoe Stringer 			__be32 daddr[4];
51746acc9b43SJoe Stringer 			__be16 sport;
51756acc9b43SJoe Stringer 			__be16 dport;
51766acc9b43SJoe Stringer 		} ipv6;
51776acc9b43SJoe Stringer 	};
51786acc9b43SJoe Stringer };
51796acc9b43SJoe Stringer 
5180fada7fdcSJonathan Lemon struct bpf_xdp_sock {
5181fada7fdcSJonathan Lemon 	__u32 queue_id;
5182fada7fdcSJonathan Lemon };
5183fada7fdcSJonathan Lemon 
518417bedab2SMartin KaFai Lau #define XDP_PACKET_HEADROOM 256
518517bedab2SMartin KaFai Lau 
51866a773a15SBrenden Blanco /* User return codes for XDP prog type.
51876a773a15SBrenden Blanco  * A valid XDP program must return one of these defined values. All other
51889beb8bedSDaniel Borkmann  * return codes are reserved for future use. Unknown return codes will
51899beb8bedSDaniel Borkmann  * result in packet drops and a warning via bpf_warn_invalid_xdp_action().
51906a773a15SBrenden Blanco  */
51916a773a15SBrenden Blanco enum xdp_action {
51926a773a15SBrenden Blanco 	XDP_ABORTED = 0,
51936a773a15SBrenden Blanco 	XDP_DROP,
51946a773a15SBrenden Blanco 	XDP_PASS,
51956ce96ca3SBrenden Blanco 	XDP_TX,
5196814abfabSJohn Fastabend 	XDP_REDIRECT,
51976a773a15SBrenden Blanco };
51986a773a15SBrenden Blanco 
51996a773a15SBrenden Blanco /* user accessible metadata for XDP packet hook
52006a773a15SBrenden Blanco  * new fields must be added to the end of this structure
52016a773a15SBrenden Blanco  */
52026a773a15SBrenden Blanco struct xdp_md {
52036a773a15SBrenden Blanco 	__u32 data;
52046a773a15SBrenden Blanco 	__u32 data_end;
5205de8f3a83SDaniel Borkmann 	__u32 data_meta;
5206daaf24c6SJesper Dangaard Brouer 	/* Below access go through struct xdp_rxq_info */
520702dd3291SJesper Dangaard Brouer 	__u32 ingress_ifindex; /* rxq->dev->ifindex */
520802dd3291SJesper Dangaard Brouer 	__u32 rx_queue_index;  /* rxq->queue_index  */
520964b59025SDavid Ahern 
521064b59025SDavid Ahern 	__u32 egress_ifindex;  /* txq->dev->ifindex */
52116a773a15SBrenden Blanco };
52126a773a15SBrenden Blanco 
5213281920b7SJesper Dangaard Brouer /* DEVMAP map-value layout
5214281920b7SJesper Dangaard Brouer  *
5215281920b7SJesper Dangaard Brouer  * The struct data-layout of map-value is a configuration interface.
5216281920b7SJesper Dangaard Brouer  * New members can only be added to the end of this structure.
5217281920b7SJesper Dangaard Brouer  */
5218281920b7SJesper Dangaard Brouer struct bpf_devmap_val {
5219281920b7SJesper Dangaard Brouer 	__u32 ifindex;   /* device index */
5220281920b7SJesper Dangaard Brouer 	union {
5221281920b7SJesper Dangaard Brouer 		int   fd;  /* prog fd on map write */
5222281920b7SJesper Dangaard Brouer 		__u32 id;  /* prog id on map read */
5223281920b7SJesper Dangaard Brouer 	} bpf_prog;
5224281920b7SJesper Dangaard Brouer };
5225281920b7SJesper Dangaard Brouer 
5226644bfe51SLorenzo Bianconi /* CPUMAP map-value layout
5227644bfe51SLorenzo Bianconi  *
5228644bfe51SLorenzo Bianconi  * The struct data-layout of map-value is a configuration interface.
5229644bfe51SLorenzo Bianconi  * New members can only be added to the end of this structure.
5230644bfe51SLorenzo Bianconi  */
5231644bfe51SLorenzo Bianconi struct bpf_cpumap_val {
5232644bfe51SLorenzo Bianconi 	__u32 qsize;	/* queue size to remote target CPU */
523392164774SLorenzo Bianconi 	union {
523492164774SLorenzo Bianconi 		int   fd;	/* prog fd on map write */
523592164774SLorenzo Bianconi 		__u32 id;	/* prog id on map read */
523692164774SLorenzo Bianconi 	} bpf_prog;
5237644bfe51SLorenzo Bianconi };
5238644bfe51SLorenzo Bianconi 
5239174a79ffSJohn Fastabend enum sk_action {
5240bfa64075SJohn Fastabend 	SK_DROP = 0,
5241bfa64075SJohn Fastabend 	SK_PASS,
5242174a79ffSJohn Fastabend };
5243174a79ffSJohn Fastabend 
52444f738adbSJohn Fastabend /* user accessible metadata for SK_MSG packet hook, new fields must
52454f738adbSJohn Fastabend  * be added to the end of this structure
52464f738adbSJohn Fastabend  */
52474f738adbSJohn Fastabend struct sk_msg_md {
5248b7df9adaSDaniel Borkmann 	__bpf_md_ptr(void *, data);
5249b7df9adaSDaniel Borkmann 	__bpf_md_ptr(void *, data_end);
5250303def35SJohn Fastabend 
5251303def35SJohn Fastabend 	__u32 family;
5252303def35SJohn Fastabend 	__u32 remote_ip4;	/* Stored in network byte order */
5253303def35SJohn Fastabend 	__u32 local_ip4;	/* Stored in network byte order */
5254303def35SJohn Fastabend 	__u32 remote_ip6[4];	/* Stored in network byte order */
5255303def35SJohn Fastabend 	__u32 local_ip6[4];	/* Stored in network byte order */
5256303def35SJohn Fastabend 	__u32 remote_port;	/* Stored in network byte order */
5257303def35SJohn Fastabend 	__u32 local_port;	/* stored in host byte order */
52583bdbd022SJohn Fastabend 	__u32 size;		/* Total size of sk_msg */
525913d70f5aSJohn Fastabend 
526013d70f5aSJohn Fastabend 	__bpf_md_ptr(struct bpf_sock *, sk); /* current socket */
52614f738adbSJohn Fastabend };
52624f738adbSJohn Fastabend 
52632dbb9b9eSMartin KaFai Lau struct sk_reuseport_md {
52642dbb9b9eSMartin KaFai Lau 	/*
52652dbb9b9eSMartin KaFai Lau 	 * Start of directly accessible data. It begins from
52662dbb9b9eSMartin KaFai Lau 	 * the tcp/udp header.
52672dbb9b9eSMartin KaFai Lau 	 */
5268b7df9adaSDaniel Borkmann 	__bpf_md_ptr(void *, data);
5269b7df9adaSDaniel Borkmann 	/* End of directly accessible data */
5270b7df9adaSDaniel Borkmann 	__bpf_md_ptr(void *, data_end);
52712dbb9b9eSMartin KaFai Lau 	/*
52722dbb9b9eSMartin KaFai Lau 	 * Total length of packet (starting from the tcp/udp header).
52732dbb9b9eSMartin KaFai Lau 	 * Note that the directly accessible bytes (data_end - data)
52742dbb9b9eSMartin KaFai Lau 	 * could be less than this "len".  Those bytes could be
52752dbb9b9eSMartin KaFai Lau 	 * indirectly read by a helper "bpf_skb_load_bytes()".
52762dbb9b9eSMartin KaFai Lau 	 */
52772dbb9b9eSMartin KaFai Lau 	__u32 len;
52782dbb9b9eSMartin KaFai Lau 	/*
52792dbb9b9eSMartin KaFai Lau 	 * Eth protocol in the mac header (network byte order). e.g.
52802dbb9b9eSMartin KaFai Lau 	 * ETH_P_IP(0x0800) and ETH_P_IPV6(0x86DD)
52812dbb9b9eSMartin KaFai Lau 	 */
52822dbb9b9eSMartin KaFai Lau 	__u32 eth_protocol;
52832dbb9b9eSMartin KaFai Lau 	__u32 ip_protocol;	/* IP protocol. e.g. IPPROTO_TCP, IPPROTO_UDP */
52842dbb9b9eSMartin KaFai Lau 	__u32 bind_inany;	/* Is sock bound to an INANY address? */
52852dbb9b9eSMartin KaFai Lau 	__u32 hash;		/* A hash of the packet 4 tuples */
52862dbb9b9eSMartin KaFai Lau };
52872dbb9b9eSMartin KaFai Lau 
52881e270976SMartin KaFai Lau #define BPF_TAG_SIZE	8
52891e270976SMartin KaFai Lau 
52901e270976SMartin KaFai Lau struct bpf_prog_info {
52911e270976SMartin KaFai Lau 	__u32 type;
52921e270976SMartin KaFai Lau 	__u32 id;
52931e270976SMartin KaFai Lau 	__u8  tag[BPF_TAG_SIZE];
52941e270976SMartin KaFai Lau 	__u32 jited_prog_len;
52951e270976SMartin KaFai Lau 	__u32 xlated_prog_len;
52961e270976SMartin KaFai Lau 	__aligned_u64 jited_prog_insns;
52971e270976SMartin KaFai Lau 	__aligned_u64 xlated_prog_insns;
5298cb4d2b3fSMartin KaFai Lau 	__u64 load_time;	/* ns since boottime */
5299cb4d2b3fSMartin KaFai Lau 	__u32 created_by_uid;
5300cb4d2b3fSMartin KaFai Lau 	__u32 nr_map_ids;
5301cb4d2b3fSMartin KaFai Lau 	__aligned_u64 map_ids;
5302067cae47SMartin KaFai Lau 	char name[BPF_OBJ_NAME_LEN];
5303675fc275SJakub Kicinski 	__u32 ifindex;
5304b85fab0eSJiri Olsa 	__u32 gpl_compatible:1;
53050472301aSBaruch Siach 	__u32 :31; /* alignment pad */
5306675fc275SJakub Kicinski 	__u64 netns_dev;
5307675fc275SJakub Kicinski 	__u64 netns_ino;
5308dbecd738SSandipan Das 	__u32 nr_jited_ksyms;
5309815581c1SSandipan Das 	__u32 nr_jited_func_lens;
5310dbecd738SSandipan Das 	__aligned_u64 jited_ksyms;
5311815581c1SSandipan Das 	__aligned_u64 jited_func_lens;
5312838e9690SYonghong Song 	__u32 btf_id;
5313838e9690SYonghong Song 	__u32 func_info_rec_size;
5314838e9690SYonghong Song 	__aligned_u64 func_info;
531511d8b82dSYonghong Song 	__u32 nr_func_info;
531611d8b82dSYonghong Song 	__u32 nr_line_info;
5317c454a46bSMartin KaFai Lau 	__aligned_u64 line_info;
5318c454a46bSMartin KaFai Lau 	__aligned_u64 jited_line_info;
531911d8b82dSYonghong Song 	__u32 nr_jited_line_info;
5320c454a46bSMartin KaFai Lau 	__u32 line_info_rec_size;
5321c454a46bSMartin KaFai Lau 	__u32 jited_line_info_rec_size;
5322c872bdb3SSong Liu 	__u32 nr_prog_tags;
5323c872bdb3SSong Liu 	__aligned_u64 prog_tags;
53245f8f8b93SAlexei Starovoitov 	__u64 run_time_ns;
53255f8f8b93SAlexei Starovoitov 	__u64 run_cnt;
53269ed9e9baSAlexei Starovoitov 	__u64 recursion_misses;
53271e270976SMartin KaFai Lau } __attribute__((aligned(8)));
53281e270976SMartin KaFai Lau 
53291e270976SMartin KaFai Lau struct bpf_map_info {
53301e270976SMartin KaFai Lau 	__u32 type;
53311e270976SMartin KaFai Lau 	__u32 id;
53321e270976SMartin KaFai Lau 	__u32 key_size;
53331e270976SMartin KaFai Lau 	__u32 value_size;
53341e270976SMartin KaFai Lau 	__u32 max_entries;
53351e270976SMartin KaFai Lau 	__u32 map_flags;
5336067cae47SMartin KaFai Lau 	char  name[BPF_OBJ_NAME_LEN];
533752775b33SJakub Kicinski 	__u32 ifindex;
533885d33df3SMartin KaFai Lau 	__u32 btf_vmlinux_value_type_id;
533952775b33SJakub Kicinski 	__u64 netns_dev;
534052775b33SJakub Kicinski 	__u64 netns_ino;
534178958fcaSMartin KaFai Lau 	__u32 btf_id;
53429b2cf328SMartin KaFai Lau 	__u32 btf_key_type_id;
53439b2cf328SMartin KaFai Lau 	__u32 btf_value_type_id;
53441e270976SMartin KaFai Lau } __attribute__((aligned(8)));
53451e270976SMartin KaFai Lau 
534662dab84cSMartin KaFai Lau struct bpf_btf_info {
534762dab84cSMartin KaFai Lau 	__aligned_u64 btf;
534862dab84cSMartin KaFai Lau 	__u32 btf_size;
534962dab84cSMartin KaFai Lau 	__u32 id;
535053297220SAndrii Nakryiko 	__aligned_u64 name;
535153297220SAndrii Nakryiko 	__u32 name_len;
535253297220SAndrii Nakryiko 	__u32 kernel_btf;
535362dab84cSMartin KaFai Lau } __attribute__((aligned(8)));
535462dab84cSMartin KaFai Lau 
5355f2e10bffSAndrii Nakryiko struct bpf_link_info {
5356f2e10bffSAndrii Nakryiko 	__u32 type;
5357f2e10bffSAndrii Nakryiko 	__u32 id;
5358f2e10bffSAndrii Nakryiko 	__u32 prog_id;
5359f2e10bffSAndrii Nakryiko 	union {
5360f2e10bffSAndrii Nakryiko 		struct {
5361f2e10bffSAndrii Nakryiko 			__aligned_u64 tp_name; /* in/out: tp_name buffer ptr */
5362f2e10bffSAndrii Nakryiko 			__u32 tp_name_len;     /* in/out: tp_name buffer len */
5363f2e10bffSAndrii Nakryiko 		} raw_tracepoint;
5364f2e10bffSAndrii Nakryiko 		struct {
5365f2e10bffSAndrii Nakryiko 			__u32 attach_type;
5366f2e10bffSAndrii Nakryiko 		} tracing;
5367f2e10bffSAndrii Nakryiko 		struct {
5368f2e10bffSAndrii Nakryiko 			__u64 cgroup_id;
5369f2e10bffSAndrii Nakryiko 			__u32 attach_type;
5370f2e10bffSAndrii Nakryiko 		} cgroup;
53717f045a49SJakub Sitnicki 		struct {
53726b0a249aSYonghong Song 			__aligned_u64 target_name; /* in/out: target_name buffer ptr */
53736b0a249aSYonghong Song 			__u32 target_name_len;	   /* in/out: target_name buffer len */
53746b0a249aSYonghong Song 			union {
5375b0c9eb37SYonghong Song 				struct {
53766b0a249aSYonghong Song 					__u32 map_id;
53776b0a249aSYonghong Song 				} map;
5378b0c9eb37SYonghong Song 			};
53796b0a249aSYonghong Song 		} iter;
53806b0a249aSYonghong Song 		struct  {
53817f045a49SJakub Sitnicki 			__u32 netns_ino;
53827f045a49SJakub Sitnicki 			__u32 attach_type;
53837f045a49SJakub Sitnicki 		} netns;
5384c1931c97SAndrii Nakryiko 		struct {
5385c1931c97SAndrii Nakryiko 			__u32 ifindex;
5386c1931c97SAndrii Nakryiko 		} xdp;
5387f2e10bffSAndrii Nakryiko 	};
5388f2e10bffSAndrii Nakryiko } __attribute__((aligned(8)));
5389f2e10bffSAndrii Nakryiko 
53904fbac77dSAndrey Ignatov /* User bpf_sock_addr struct to access socket fields and sockaddr struct passed
53914fbac77dSAndrey Ignatov  * by user and intended to be used by socket (e.g. to bind to, depends on
5392bfdfa517SRandy Dunlap  * attach type).
53934fbac77dSAndrey Ignatov  */
53944fbac77dSAndrey Ignatov struct bpf_sock_addr {
53954fbac77dSAndrey Ignatov 	__u32 user_family;	/* Allows 4-byte read, but no write. */
53964fbac77dSAndrey Ignatov 	__u32 user_ip4;		/* Allows 1,2,4-byte read and 4-byte write.
53974fbac77dSAndrey Ignatov 				 * Stored in network byte order.
53984fbac77dSAndrey Ignatov 				 */
5399d4ecfeb1SStanislav Fomichev 	__u32 user_ip6[4];	/* Allows 1,2,4,8-byte read and 4,8-byte write.
54004fbac77dSAndrey Ignatov 				 * Stored in network byte order.
54014fbac77dSAndrey Ignatov 				 */
54027aebfa1bSAndrey Ignatov 	__u32 user_port;	/* Allows 1,2,4-byte read and 4-byte write.
54034fbac77dSAndrey Ignatov 				 * Stored in network byte order
54044fbac77dSAndrey Ignatov 				 */
54054fbac77dSAndrey Ignatov 	__u32 family;		/* Allows 4-byte read, but no write */
54064fbac77dSAndrey Ignatov 	__u32 type;		/* Allows 4-byte read, but no write */
54074fbac77dSAndrey Ignatov 	__u32 protocol;		/* Allows 4-byte read, but no write */
5408600c70baSStanislav Fomichev 	__u32 msg_src_ip4;	/* Allows 1,2,4-byte read and 4-byte write.
54091cedee13SAndrey Ignatov 				 * Stored in network byte order.
54101cedee13SAndrey Ignatov 				 */
5411d4ecfeb1SStanislav Fomichev 	__u32 msg_src_ip6[4];	/* Allows 1,2,4,8-byte read and 4,8-byte write.
54121cedee13SAndrey Ignatov 				 * Stored in network byte order.
54131cedee13SAndrey Ignatov 				 */
5414fb85c4a7SStanislav Fomichev 	__bpf_md_ptr(struct bpf_sock *, sk);
54154fbac77dSAndrey Ignatov };
54164fbac77dSAndrey Ignatov 
541740304b2aSLawrence Brakmo /* User bpf_sock_ops struct to access socket values and specify request ops
541840304b2aSLawrence Brakmo  * and their replies.
541940304b2aSLawrence Brakmo  * Some of this fields are in network (bigendian) byte order and may need
542040304b2aSLawrence Brakmo  * to be converted before use (bpf_ntohl() defined in samples/bpf/bpf_endian.h).
542140304b2aSLawrence Brakmo  * New fields can only be added at the end of this structure
542240304b2aSLawrence Brakmo  */
542340304b2aSLawrence Brakmo struct bpf_sock_ops {
542440304b2aSLawrence Brakmo 	__u32 op;
542540304b2aSLawrence Brakmo 	union {
5426de525be2SLawrence Brakmo 		__u32 args[4];		/* Optionally passed to bpf program */
5427de525be2SLawrence Brakmo 		__u32 reply;		/* Returned by bpf program	    */
5428de525be2SLawrence Brakmo 		__u32 replylong[4];	/* Optionally returned by bpf prog  */
542940304b2aSLawrence Brakmo 	};
543040304b2aSLawrence Brakmo 	__u32 family;
543140304b2aSLawrence Brakmo 	__u32 remote_ip4;	/* Stored in network byte order */
543240304b2aSLawrence Brakmo 	__u32 local_ip4;	/* Stored in network byte order */
543340304b2aSLawrence Brakmo 	__u32 remote_ip6[4];	/* Stored in network byte order */
543440304b2aSLawrence Brakmo 	__u32 local_ip6[4];	/* Stored in network byte order */
543540304b2aSLawrence Brakmo 	__u32 remote_port;	/* Stored in network byte order */
543640304b2aSLawrence Brakmo 	__u32 local_port;	/* stored in host byte order */
5437f19397a5SLawrence Brakmo 	__u32 is_fullsock;	/* Some TCP fields are only valid if
5438f19397a5SLawrence Brakmo 				 * there is a full socket. If not, the
5439f19397a5SLawrence Brakmo 				 * fields read as zero.
5440f19397a5SLawrence Brakmo 				 */
5441f19397a5SLawrence Brakmo 	__u32 snd_cwnd;
5442f19397a5SLawrence Brakmo 	__u32 srtt_us;		/* Averaged RTT << 3 in usecs */
5443b13d8807SLawrence Brakmo 	__u32 bpf_sock_ops_cb_flags; /* flags defined in uapi/linux/tcp.h */
544444f0e430SLawrence Brakmo 	__u32 state;
544544f0e430SLawrence Brakmo 	__u32 rtt_min;
544644f0e430SLawrence Brakmo 	__u32 snd_ssthresh;
544744f0e430SLawrence Brakmo 	__u32 rcv_nxt;
544844f0e430SLawrence Brakmo 	__u32 snd_nxt;
544944f0e430SLawrence Brakmo 	__u32 snd_una;
545044f0e430SLawrence Brakmo 	__u32 mss_cache;
545144f0e430SLawrence Brakmo 	__u32 ecn_flags;
545244f0e430SLawrence Brakmo 	__u32 rate_delivered;
545344f0e430SLawrence Brakmo 	__u32 rate_interval_us;
545444f0e430SLawrence Brakmo 	__u32 packets_out;
545544f0e430SLawrence Brakmo 	__u32 retrans_out;
545644f0e430SLawrence Brakmo 	__u32 total_retrans;
545744f0e430SLawrence Brakmo 	__u32 segs_in;
545844f0e430SLawrence Brakmo 	__u32 data_segs_in;
545944f0e430SLawrence Brakmo 	__u32 segs_out;
546044f0e430SLawrence Brakmo 	__u32 data_segs_out;
546144f0e430SLawrence Brakmo 	__u32 lost_out;
546244f0e430SLawrence Brakmo 	__u32 sacked_out;
546344f0e430SLawrence Brakmo 	__u32 sk_txhash;
546444f0e430SLawrence Brakmo 	__u64 bytes_received;
546544f0e430SLawrence Brakmo 	__u64 bytes_acked;
54661314ef56SStanislav Fomichev 	__bpf_md_ptr(struct bpf_sock *, sk);
54670813a841SMartin KaFai Lau 	/* [skb_data, skb_data_end) covers the whole TCP header.
54680813a841SMartin KaFai Lau 	 *
54690813a841SMartin KaFai Lau 	 * BPF_SOCK_OPS_PARSE_HDR_OPT_CB: The packet received
54700813a841SMartin KaFai Lau 	 * BPF_SOCK_OPS_HDR_OPT_LEN_CB:   Not useful because the
54710813a841SMartin KaFai Lau 	 *                                header has not been written.
54720813a841SMartin KaFai Lau 	 * BPF_SOCK_OPS_WRITE_HDR_OPT_CB: The header and options have
54730813a841SMartin KaFai Lau 	 *				  been written so far.
54740813a841SMartin KaFai Lau 	 * BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:  The SYNACK that concludes
54750813a841SMartin KaFai Lau 	 *					the 3WHS.
54760813a841SMartin KaFai Lau 	 * BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB: The ACK that concludes
54770813a841SMartin KaFai Lau 	 *					the 3WHS.
54780813a841SMartin KaFai Lau 	 *
54790813a841SMartin KaFai Lau 	 * bpf_load_hdr_opt() can also be used to read a particular option.
54800813a841SMartin KaFai Lau 	 */
54810813a841SMartin KaFai Lau 	__bpf_md_ptr(void *, skb_data);
54820813a841SMartin KaFai Lau 	__bpf_md_ptr(void *, skb_data_end);
54830813a841SMartin KaFai Lau 	__u32 skb_len;		/* The total length of a packet.
54840813a841SMartin KaFai Lau 				 * It includes the header, options,
54850813a841SMartin KaFai Lau 				 * and payload.
54860813a841SMartin KaFai Lau 				 */
54870813a841SMartin KaFai Lau 	__u32 skb_tcp_flags;	/* tcp_flags of the header.  It provides
54880813a841SMartin KaFai Lau 				 * an easy way to check for tcp_flags
54890813a841SMartin KaFai Lau 				 * without parsing skb_data.
54900813a841SMartin KaFai Lau 				 *
54910813a841SMartin KaFai Lau 				 * In particular, the skb_tcp_flags
54920813a841SMartin KaFai Lau 				 * will still be available in
54930813a841SMartin KaFai Lau 				 * BPF_SOCK_OPS_HDR_OPT_LEN even though
54940813a841SMartin KaFai Lau 				 * the outgoing header has not
54950813a841SMartin KaFai Lau 				 * been written yet.
54960813a841SMartin KaFai Lau 				 */
549740304b2aSLawrence Brakmo };
549840304b2aSLawrence Brakmo 
5499b13d8807SLawrence Brakmo /* Definitions for bpf_sock_ops_cb_flags */
55001aae4bddSAndrii Nakryiko enum {
55011aae4bddSAndrii Nakryiko 	BPF_SOCK_OPS_RTO_CB_FLAG	= (1<<0),
55021aae4bddSAndrii Nakryiko 	BPF_SOCK_OPS_RETRANS_CB_FLAG	= (1<<1),
55031aae4bddSAndrii Nakryiko 	BPF_SOCK_OPS_STATE_CB_FLAG	= (1<<2),
55041aae4bddSAndrii Nakryiko 	BPF_SOCK_OPS_RTT_CB_FLAG	= (1<<3),
55050813a841SMartin KaFai Lau 	/* Call bpf for all received TCP headers.  The bpf prog will be
55060813a841SMartin KaFai Lau 	 * called under sock_ops->op == BPF_SOCK_OPS_PARSE_HDR_OPT_CB
55070813a841SMartin KaFai Lau 	 *
55080813a841SMartin KaFai Lau 	 * Please refer to the comment in BPF_SOCK_OPS_PARSE_HDR_OPT_CB
55090813a841SMartin KaFai Lau 	 * for the header option related helpers that will be useful
55100813a841SMartin KaFai Lau 	 * to the bpf programs.
55110813a841SMartin KaFai Lau 	 *
55120813a841SMartin KaFai Lau 	 * It could be used at the client/active side (i.e. connect() side)
55130813a841SMartin KaFai Lau 	 * when the server told it that the server was in syncookie
55140813a841SMartin KaFai Lau 	 * mode and required the active side to resend the bpf-written
55150813a841SMartin KaFai Lau 	 * options.  The active side can keep writing the bpf-options until
55160813a841SMartin KaFai Lau 	 * it received a valid packet from the server side to confirm
55170813a841SMartin KaFai Lau 	 * the earlier packet (and options) has been received.  The later
55180813a841SMartin KaFai Lau 	 * example patch is using it like this at the active side when the
55190813a841SMartin KaFai Lau 	 * server is in syncookie mode.
55200813a841SMartin KaFai Lau 	 *
55210813a841SMartin KaFai Lau 	 * The bpf prog will usually turn this off in the common cases.
55220813a841SMartin KaFai Lau 	 */
552300d211a4SMartin KaFai Lau 	BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG	= (1<<4),
55240813a841SMartin KaFai Lau 	/* Call bpf when kernel has received a header option that
55250813a841SMartin KaFai Lau 	 * the kernel cannot handle.  The bpf prog will be called under
55260813a841SMartin KaFai Lau 	 * sock_ops->op == BPF_SOCK_OPS_PARSE_HDR_OPT_CB.
55270813a841SMartin KaFai Lau 	 *
55280813a841SMartin KaFai Lau 	 * Please refer to the comment in BPF_SOCK_OPS_PARSE_HDR_OPT_CB
55290813a841SMartin KaFai Lau 	 * for the header option related helpers that will be useful
55300813a841SMartin KaFai Lau 	 * to the bpf programs.
55310813a841SMartin KaFai Lau 	 */
553200d211a4SMartin KaFai Lau 	BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG = (1<<5),
55330813a841SMartin KaFai Lau 	/* Call bpf when the kernel is writing header options for the
55340813a841SMartin KaFai Lau 	 * outgoing packet.  The bpf prog will first be called
55350813a841SMartin KaFai Lau 	 * to reserve space in a skb under
55360813a841SMartin KaFai Lau 	 * sock_ops->op == BPF_SOCK_OPS_HDR_OPT_LEN_CB.  Then
55370813a841SMartin KaFai Lau 	 * the bpf prog will be called to write the header option(s)
55380813a841SMartin KaFai Lau 	 * under sock_ops->op == BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
55390813a841SMartin KaFai Lau 	 *
55400813a841SMartin KaFai Lau 	 * Please refer to the comment in BPF_SOCK_OPS_HDR_OPT_LEN_CB
55410813a841SMartin KaFai Lau 	 * and BPF_SOCK_OPS_WRITE_HDR_OPT_CB for the header option
55420813a841SMartin KaFai Lau 	 * related helpers that will be useful to the bpf programs.
55430813a841SMartin KaFai Lau 	 *
55440813a841SMartin KaFai Lau 	 * The kernel gets its chance to reserve space and write
55450813a841SMartin KaFai Lau 	 * options first before the BPF program does.
55460813a841SMartin KaFai Lau 	 */
5547331fca43SMartin KaFai Lau 	BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG = (1<<6),
55481aae4bddSAndrii Nakryiko /* Mask of all currently supported cb flags */
5549331fca43SMartin KaFai Lau 	BPF_SOCK_OPS_ALL_CB_FLAGS       = 0x7F,
55501aae4bddSAndrii Nakryiko };
5551b13d8807SLawrence Brakmo 
555240304b2aSLawrence Brakmo /* List of known BPF sock_ops operators.
555340304b2aSLawrence Brakmo  * New entries can only be added at the end
555440304b2aSLawrence Brakmo  */
555540304b2aSLawrence Brakmo enum {
555640304b2aSLawrence Brakmo 	BPF_SOCK_OPS_VOID,
55578550f328SLawrence Brakmo 	BPF_SOCK_OPS_TIMEOUT_INIT,	/* Should return SYN-RTO value to use or
55588550f328SLawrence Brakmo 					 * -1 if default value should be used
55598550f328SLawrence Brakmo 					 */
556013d3b1ebSLawrence Brakmo 	BPF_SOCK_OPS_RWND_INIT,		/* Should return initial advertized
556113d3b1ebSLawrence Brakmo 					 * window (in packets) or -1 if default
556213d3b1ebSLawrence Brakmo 					 * value should be used
556313d3b1ebSLawrence Brakmo 					 */
55649872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_TCP_CONNECT_CB,	/* Calls BPF program right before an
55659872a4bdSLawrence Brakmo 					 * active connection is initialized
55669872a4bdSLawrence Brakmo 					 */
55679872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB,	/* Calls BPF program when an
55689872a4bdSLawrence Brakmo 						 * active connection is
55699872a4bdSLawrence Brakmo 						 * established
55709872a4bdSLawrence Brakmo 						 */
55719872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB,	/* Calls BPF program when a
55729872a4bdSLawrence Brakmo 						 * passive connection is
55739872a4bdSLawrence Brakmo 						 * established
55749872a4bdSLawrence Brakmo 						 */
557591b5b21cSLawrence Brakmo 	BPF_SOCK_OPS_NEEDS_ECN,		/* If connection's congestion control
557691b5b21cSLawrence Brakmo 					 * needs ECN
557791b5b21cSLawrence Brakmo 					 */
5578e6546ef6SLawrence Brakmo 	BPF_SOCK_OPS_BASE_RTT,		/* Get base RTT. The correct value is
5579e6546ef6SLawrence Brakmo 					 * based on the path and may be
5580e6546ef6SLawrence Brakmo 					 * dependent on the congestion control
5581e6546ef6SLawrence Brakmo 					 * algorithm. In general it indicates
5582e6546ef6SLawrence Brakmo 					 * a congestion threshold. RTTs above
5583e6546ef6SLawrence Brakmo 					 * this indicate congestion
5584e6546ef6SLawrence Brakmo 					 */
5585f89013f6SLawrence Brakmo 	BPF_SOCK_OPS_RTO_CB,		/* Called when an RTO has triggered.
5586f89013f6SLawrence Brakmo 					 * Arg1: value of icsk_retransmits
5587f89013f6SLawrence Brakmo 					 * Arg2: value of icsk_rto
5588f89013f6SLawrence Brakmo 					 * Arg3: whether RTO has expired
5589f89013f6SLawrence Brakmo 					 */
5590a31ad29eSLawrence Brakmo 	BPF_SOCK_OPS_RETRANS_CB,	/* Called when skb is retransmitted.
5591a31ad29eSLawrence Brakmo 					 * Arg1: sequence number of 1st byte
5592a31ad29eSLawrence Brakmo 					 * Arg2: # segments
5593a31ad29eSLawrence Brakmo 					 * Arg3: return value of
5594a31ad29eSLawrence Brakmo 					 *       tcp_transmit_skb (0 => success)
5595a31ad29eSLawrence Brakmo 					 */
5596d4487491SLawrence Brakmo 	BPF_SOCK_OPS_STATE_CB,		/* Called when TCP changes state.
5597d4487491SLawrence Brakmo 					 * Arg1: old_state
5598d4487491SLawrence Brakmo 					 * Arg2: new_state
5599d4487491SLawrence Brakmo 					 */
5600f333ee0cSAndrey Ignatov 	BPF_SOCK_OPS_TCP_LISTEN_CB,	/* Called on listen(2), right after
5601f333ee0cSAndrey Ignatov 					 * socket transition to LISTEN state.
5602f333ee0cSAndrey Ignatov 					 */
560323729ff2SStanislav Fomichev 	BPF_SOCK_OPS_RTT_CB,		/* Called on every RTT.
560423729ff2SStanislav Fomichev 					 */
56050813a841SMartin KaFai Lau 	BPF_SOCK_OPS_PARSE_HDR_OPT_CB,	/* Parse the header option.
56060813a841SMartin KaFai Lau 					 * It will be called to handle
56070813a841SMartin KaFai Lau 					 * the packets received at
56080813a841SMartin KaFai Lau 					 * an already established
56090813a841SMartin KaFai Lau 					 * connection.
56100813a841SMartin KaFai Lau 					 *
56110813a841SMartin KaFai Lau 					 * sock_ops->skb_data:
56120813a841SMartin KaFai Lau 					 * Referring to the received skb.
56130813a841SMartin KaFai Lau 					 * It covers the TCP header only.
56140813a841SMartin KaFai Lau 					 *
56150813a841SMartin KaFai Lau 					 * bpf_load_hdr_opt() can also
56160813a841SMartin KaFai Lau 					 * be used to search for a
56170813a841SMartin KaFai Lau 					 * particular option.
56180813a841SMartin KaFai Lau 					 */
56190813a841SMartin KaFai Lau 	BPF_SOCK_OPS_HDR_OPT_LEN_CB,	/* Reserve space for writing the
56200813a841SMartin KaFai Lau 					 * header option later in
56210813a841SMartin KaFai Lau 					 * BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
56220813a841SMartin KaFai Lau 					 * Arg1: bool want_cookie. (in
56230813a841SMartin KaFai Lau 					 *       writing SYNACK only)
56240813a841SMartin KaFai Lau 					 *
56250813a841SMartin KaFai Lau 					 * sock_ops->skb_data:
56260813a841SMartin KaFai Lau 					 * Not available because no header has
56270813a841SMartin KaFai Lau 					 * been	written yet.
56280813a841SMartin KaFai Lau 					 *
56290813a841SMartin KaFai Lau 					 * sock_ops->skb_tcp_flags:
56300813a841SMartin KaFai Lau 					 * The tcp_flags of the
56310813a841SMartin KaFai Lau 					 * outgoing skb. (e.g. SYN, ACK, FIN).
56320813a841SMartin KaFai Lau 					 *
56330813a841SMartin KaFai Lau 					 * bpf_reserve_hdr_opt() should
56340813a841SMartin KaFai Lau 					 * be used to reserve space.
56350813a841SMartin KaFai Lau 					 */
56360813a841SMartin KaFai Lau 	BPF_SOCK_OPS_WRITE_HDR_OPT_CB,	/* Write the header options
56370813a841SMartin KaFai Lau 					 * Arg1: bool want_cookie. (in
56380813a841SMartin KaFai Lau 					 *       writing SYNACK only)
56390813a841SMartin KaFai Lau 					 *
56400813a841SMartin KaFai Lau 					 * sock_ops->skb_data:
56410813a841SMartin KaFai Lau 					 * Referring to the outgoing skb.
56420813a841SMartin KaFai Lau 					 * It covers the TCP header
56430813a841SMartin KaFai Lau 					 * that has already been written
56440813a841SMartin KaFai Lau 					 * by the kernel and the
56450813a841SMartin KaFai Lau 					 * earlier bpf-progs.
56460813a841SMartin KaFai Lau 					 *
56470813a841SMartin KaFai Lau 					 * sock_ops->skb_tcp_flags:
56480813a841SMartin KaFai Lau 					 * The tcp_flags of the outgoing
56490813a841SMartin KaFai Lau 					 * skb. (e.g. SYN, ACK, FIN).
56500813a841SMartin KaFai Lau 					 *
56510813a841SMartin KaFai Lau 					 * bpf_store_hdr_opt() should
56520813a841SMartin KaFai Lau 					 * be used to write the
56530813a841SMartin KaFai Lau 					 * option.
56540813a841SMartin KaFai Lau 					 *
56550813a841SMartin KaFai Lau 					 * bpf_load_hdr_opt() can also
56560813a841SMartin KaFai Lau 					 * be used to search for a
56570813a841SMartin KaFai Lau 					 * particular option that
56580813a841SMartin KaFai Lau 					 * has already been written
56590813a841SMartin KaFai Lau 					 * by the kernel or the
56600813a841SMartin KaFai Lau 					 * earlier bpf-progs.
56610813a841SMartin KaFai Lau 					 */
5662d4487491SLawrence Brakmo };
5663d4487491SLawrence Brakmo 
5664d4487491SLawrence Brakmo /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
5665d4487491SLawrence Brakmo  * changes between the TCP and BPF versions. Ideally this should never happen.
5666d4487491SLawrence Brakmo  * If it does, we need to add code to convert them before calling
5667d4487491SLawrence Brakmo  * the BPF sock_ops function.
5668d4487491SLawrence Brakmo  */
5669d4487491SLawrence Brakmo enum {
5670d4487491SLawrence Brakmo 	BPF_TCP_ESTABLISHED = 1,
5671d4487491SLawrence Brakmo 	BPF_TCP_SYN_SENT,
5672d4487491SLawrence Brakmo 	BPF_TCP_SYN_RECV,
5673d4487491SLawrence Brakmo 	BPF_TCP_FIN_WAIT1,
5674d4487491SLawrence Brakmo 	BPF_TCP_FIN_WAIT2,
5675d4487491SLawrence Brakmo 	BPF_TCP_TIME_WAIT,
5676d4487491SLawrence Brakmo 	BPF_TCP_CLOSE,
5677d4487491SLawrence Brakmo 	BPF_TCP_CLOSE_WAIT,
5678d4487491SLawrence Brakmo 	BPF_TCP_LAST_ACK,
5679d4487491SLawrence Brakmo 	BPF_TCP_LISTEN,
5680d4487491SLawrence Brakmo 	BPF_TCP_CLOSING,	/* Now a valid state */
5681d4487491SLawrence Brakmo 	BPF_TCP_NEW_SYN_RECV,
5682d4487491SLawrence Brakmo 
5683d4487491SLawrence Brakmo 	BPF_TCP_MAX_STATES	/* Leave at the end! */
568440304b2aSLawrence Brakmo };
568540304b2aSLawrence Brakmo 
56861aae4bddSAndrii Nakryiko enum {
56871aae4bddSAndrii Nakryiko 	TCP_BPF_IW		= 1001,	/* Set TCP initial congestion window */
56881aae4bddSAndrii Nakryiko 	TCP_BPF_SNDCWND_CLAMP	= 1002,	/* Set sndcwnd_clamp */
56892b8ee4f0SMartin KaFai Lau 	TCP_BPF_DELACK_MAX	= 1003, /* Max delay ack in usecs */
5690ca584ba0SMartin KaFai Lau 	TCP_BPF_RTO_MIN		= 1004, /* Min delay ack in usecs */
56910813a841SMartin KaFai Lau 	/* Copy the SYN pkt to optval
56920813a841SMartin KaFai Lau 	 *
56930813a841SMartin KaFai Lau 	 * BPF_PROG_TYPE_SOCK_OPS only.  It is similar to the
56940813a841SMartin KaFai Lau 	 * bpf_getsockopt(TCP_SAVED_SYN) but it does not limit
56950813a841SMartin KaFai Lau 	 * to only getting from the saved_syn.  It can either get the
56960813a841SMartin KaFai Lau 	 * syn packet from:
56970813a841SMartin KaFai Lau 	 *
56980813a841SMartin KaFai Lau 	 * 1. the just-received SYN packet (only available when writing the
56990813a841SMartin KaFai Lau 	 *    SYNACK).  It will be useful when it is not necessary to
57000813a841SMartin KaFai Lau 	 *    save the SYN packet for latter use.  It is also the only way
57010813a841SMartin KaFai Lau 	 *    to get the SYN during syncookie mode because the syn
57020813a841SMartin KaFai Lau 	 *    packet cannot be saved during syncookie.
57030813a841SMartin KaFai Lau 	 *
57040813a841SMartin KaFai Lau 	 * OR
57050813a841SMartin KaFai Lau 	 *
57060813a841SMartin KaFai Lau 	 * 2. the earlier saved syn which was done by
57070813a841SMartin KaFai Lau 	 *    bpf_setsockopt(TCP_SAVE_SYN).
57080813a841SMartin KaFai Lau 	 *
57090813a841SMartin KaFai Lau 	 * The bpf_getsockopt(TCP_BPF_SYN*) option will hide where the
57100813a841SMartin KaFai Lau 	 * SYN packet is obtained.
57110813a841SMartin KaFai Lau 	 *
57120813a841SMartin KaFai Lau 	 * If the bpf-prog does not need the IP[46] header,  the
57130813a841SMartin KaFai Lau 	 * bpf-prog can avoid parsing the IP header by using
57140813a841SMartin KaFai Lau 	 * TCP_BPF_SYN.  Otherwise, the bpf-prog can get both
57150813a841SMartin KaFai Lau 	 * IP[46] and TCP header by using TCP_BPF_SYN_IP.
57160813a841SMartin KaFai Lau 	 *
57170813a841SMartin KaFai Lau 	 *      >0: Total number of bytes copied
57180813a841SMartin KaFai Lau 	 * -ENOSPC: Not enough space in optval. Only optlen number of
57190813a841SMartin KaFai Lau 	 *          bytes is copied.
57200813a841SMartin KaFai Lau 	 * -ENOENT: The SYN skb is not available now and the earlier SYN pkt
57210813a841SMartin KaFai Lau 	 *	    is not saved by setsockopt(TCP_SAVE_SYN).
57220813a841SMartin KaFai Lau 	 */
57230813a841SMartin KaFai Lau 	TCP_BPF_SYN		= 1005, /* Copy the TCP header */
57240813a841SMartin KaFai Lau 	TCP_BPF_SYN_IP		= 1006, /* Copy the IP[46] and TCP header */
5725267cf9faSMartin KaFai Lau 	TCP_BPF_SYN_MAC         = 1007, /* Copy the MAC, IP[46], and TCP header */
57260813a841SMartin KaFai Lau };
57270813a841SMartin KaFai Lau 
57280813a841SMartin KaFai Lau enum {
57290813a841SMartin KaFai Lau 	BPF_LOAD_HDR_OPT_TCP_SYN = (1ULL << 0),
57300813a841SMartin KaFai Lau };
57310813a841SMartin KaFai Lau 
57320813a841SMartin KaFai Lau /* args[0] value during BPF_SOCK_OPS_HDR_OPT_LEN_CB and
57330813a841SMartin KaFai Lau  * BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
57340813a841SMartin KaFai Lau  */
57350813a841SMartin KaFai Lau enum {
57360813a841SMartin KaFai Lau 	BPF_WRITE_HDR_TCP_CURRENT_MSS = 1,	/* Kernel is finding the
57370813a841SMartin KaFai Lau 						 * total option spaces
57380813a841SMartin KaFai Lau 						 * required for an established
57390813a841SMartin KaFai Lau 						 * sk in order to calculate the
57400813a841SMartin KaFai Lau 						 * MSS.  No skb is actually
57410813a841SMartin KaFai Lau 						 * sent.
57420813a841SMartin KaFai Lau 						 */
57430813a841SMartin KaFai Lau 	BPF_WRITE_HDR_TCP_SYNACK_COOKIE = 2,	/* Kernel is in syncookie mode
57440813a841SMartin KaFai Lau 						 * when sending a SYN.
57450813a841SMartin KaFai Lau 						 */
57461aae4bddSAndrii Nakryiko };
5747fc747810SLawrence Brakmo 
5748908432caSYonghong Song struct bpf_perf_event_value {
5749908432caSYonghong Song 	__u64 counter;
5750908432caSYonghong Song 	__u64 enabled;
5751908432caSYonghong Song 	__u64 running;
5752908432caSYonghong Song };
5753908432caSYonghong Song 
57541aae4bddSAndrii Nakryiko enum {
57551aae4bddSAndrii Nakryiko 	BPF_DEVCG_ACC_MKNOD	= (1ULL << 0),
57561aae4bddSAndrii Nakryiko 	BPF_DEVCG_ACC_READ	= (1ULL << 1),
57571aae4bddSAndrii Nakryiko 	BPF_DEVCG_ACC_WRITE	= (1ULL << 2),
57581aae4bddSAndrii Nakryiko };
5759ebc614f6SRoman Gushchin 
57601aae4bddSAndrii Nakryiko enum {
57611aae4bddSAndrii Nakryiko 	BPF_DEVCG_DEV_BLOCK	= (1ULL << 0),
57621aae4bddSAndrii Nakryiko 	BPF_DEVCG_DEV_CHAR	= (1ULL << 1),
57631aae4bddSAndrii Nakryiko };
5764ebc614f6SRoman Gushchin 
5765ebc614f6SRoman Gushchin struct bpf_cgroup_dev_ctx {
576606ef0ccbSYonghong Song 	/* access_type encoded as (BPF_DEVCG_ACC_* << 16) | BPF_DEVCG_DEV_* */
576706ef0ccbSYonghong Song 	__u32 access_type;
5768ebc614f6SRoman Gushchin 	__u32 major;
5769ebc614f6SRoman Gushchin 	__u32 minor;
5770ebc614f6SRoman Gushchin };
5771ebc614f6SRoman Gushchin 
5772c4f6699dSAlexei Starovoitov struct bpf_raw_tracepoint_args {
5773c4f6699dSAlexei Starovoitov 	__u64 args[0];
5774c4f6699dSAlexei Starovoitov };
5775c4f6699dSAlexei Starovoitov 
577687f5fc7eSDavid Ahern /* DIRECT:  Skip the FIB rules and go to FIB table associated with device
577787f5fc7eSDavid Ahern  * OUTPUT:  Do lookup from egress perspective; default is ingress
577887f5fc7eSDavid Ahern  */
57791aae4bddSAndrii Nakryiko enum {
57801aae4bddSAndrii Nakryiko 	BPF_FIB_LOOKUP_DIRECT  = (1U << 0),
57811aae4bddSAndrii Nakryiko 	BPF_FIB_LOOKUP_OUTPUT  = (1U << 1),
57821aae4bddSAndrii Nakryiko };
578387f5fc7eSDavid Ahern 
57844c79579bSDavid Ahern enum {
57854c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_SUCCESS,      /* lookup successful */
57864c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_BLACKHOLE,    /* dest is blackholed; can be dropped */
57874c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_UNREACHABLE,  /* dest is unreachable; can be dropped */
57884c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_PROHIBIT,     /* dest not allowed; can be dropped */
57894c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_NOT_FWDED,    /* packet is not forwarded */
57904c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_FWD_DISABLED, /* fwding is not enabled on ingress */
57914c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_UNSUPP_LWT,   /* fwd requires encapsulation */
57924c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_NO_NEIGH,     /* no neighbor entry for nh */
57934c79579bSDavid Ahern 	BPF_FIB_LKUP_RET_FRAG_NEEDED,  /* fragmentation required to fwd */
57944c79579bSDavid Ahern };
57954c79579bSDavid Ahern 
579687f5fc7eSDavid Ahern struct bpf_fib_lookup {
5797fa898d76SDavid Ahern 	/* input:  network family for lookup (AF_INET, AF_INET6)
5798fa898d76SDavid Ahern 	 * output: network family of egress nexthop
5799fa898d76SDavid Ahern 	 */
5800fa898d76SDavid Ahern 	__u8	family;
580187f5fc7eSDavid Ahern 
580287f5fc7eSDavid Ahern 	/* set if lookup is to consider L4 data - e.g., FIB rules */
580387f5fc7eSDavid Ahern 	__u8	l4_protocol;
580487f5fc7eSDavid Ahern 	__be16	sport;
580587f5fc7eSDavid Ahern 	__be16	dport;
580687f5fc7eSDavid Ahern 
5807e1850ea9SJesper Dangaard Brouer 	union {	/* used for MTU check */
5808e1850ea9SJesper Dangaard Brouer 		/* input to lookup */
5809e1850ea9SJesper Dangaard Brouer 		__u16	tot_len; /* L3 length from network hdr (iph->tot_len) */
58104c79579bSDavid Ahern 
5811e1850ea9SJesper Dangaard Brouer 		/* output: MTU value */
5812e1850ea9SJesper Dangaard Brouer 		__u16	mtu_result;
5813e1850ea9SJesper Dangaard Brouer 	};
58144c79579bSDavid Ahern 	/* input: L3 device index for lookup
58154c79579bSDavid Ahern 	 * output: device index from FIB lookup
58164c79579bSDavid Ahern 	 */
58174c79579bSDavid Ahern 	__u32	ifindex;
581887f5fc7eSDavid Ahern 
581987f5fc7eSDavid Ahern 	union {
582087f5fc7eSDavid Ahern 		/* inputs to lookup */
582187f5fc7eSDavid Ahern 		__u8	tos;		/* AF_INET  */
5822bd3a08aaSDavid Ahern 		__be32	flowinfo;	/* AF_INET6, flow_label + priority */
582387f5fc7eSDavid Ahern 
5824fa898d76SDavid Ahern 		/* output: metric of fib result (IPv4/IPv6 only) */
582587f5fc7eSDavid Ahern 		__u32	rt_metric;
582687f5fc7eSDavid Ahern 	};
582787f5fc7eSDavid Ahern 
582887f5fc7eSDavid Ahern 	union {
582987f5fc7eSDavid Ahern 		__be32		ipv4_src;
583087f5fc7eSDavid Ahern 		__u32		ipv6_src[4];  /* in6_addr; network order */
583187f5fc7eSDavid Ahern 	};
583287f5fc7eSDavid Ahern 
5833fa898d76SDavid Ahern 	/* input to bpf_fib_lookup, ipv{4,6}_dst is destination address in
5834fa898d76SDavid Ahern 	 * network header. output: bpf_fib_lookup sets to gateway address
5835fa898d76SDavid Ahern 	 * if FIB lookup returns gateway route
583687f5fc7eSDavid Ahern 	 */
583787f5fc7eSDavid Ahern 	union {
583887f5fc7eSDavid Ahern 		__be32		ipv4_dst;
583987f5fc7eSDavid Ahern 		__u32		ipv6_dst[4];  /* in6_addr; network order */
584087f5fc7eSDavid Ahern 	};
584187f5fc7eSDavid Ahern 
584287f5fc7eSDavid Ahern 	/* output */
584387f5fc7eSDavid Ahern 	__be16	h_vlan_proto;
584487f5fc7eSDavid Ahern 	__be16	h_vlan_TCI;
584587f5fc7eSDavid Ahern 	__u8	smac[6];     /* ETH_ALEN */
584687f5fc7eSDavid Ahern 	__u8	dmac[6];     /* ETH_ALEN */
584787f5fc7eSDavid Ahern };
584887f5fc7eSDavid Ahern 
5849ba452c9eSToke Høiland-Jørgensen struct bpf_redir_neigh {
5850ba452c9eSToke Høiland-Jørgensen 	/* network family for lookup (AF_INET, AF_INET6) */
5851ba452c9eSToke Høiland-Jørgensen 	__u32 nh_family;
5852ba452c9eSToke Høiland-Jørgensen 	/* network address of nexthop; skips fib lookup to find gateway */
5853ba452c9eSToke Høiland-Jørgensen 	union {
5854ba452c9eSToke Høiland-Jørgensen 		__be32		ipv4_nh;
5855ba452c9eSToke Høiland-Jørgensen 		__u32		ipv6_nh[4];  /* in6_addr; network order */
5856ba452c9eSToke Høiland-Jørgensen 	};
5857ba452c9eSToke Høiland-Jørgensen };
5858ba452c9eSToke Høiland-Jørgensen 
585934b2021cSJesper Dangaard Brouer /* bpf_check_mtu flags*/
586034b2021cSJesper Dangaard Brouer enum  bpf_check_mtu_flags {
586134b2021cSJesper Dangaard Brouer 	BPF_MTU_CHK_SEGS  = (1U << 0),
586234b2021cSJesper Dangaard Brouer };
586334b2021cSJesper Dangaard Brouer 
586434b2021cSJesper Dangaard Brouer enum bpf_check_mtu_ret {
586534b2021cSJesper Dangaard Brouer 	BPF_MTU_CHK_RET_SUCCESS,      /* check and lookup successful */
586634b2021cSJesper Dangaard Brouer 	BPF_MTU_CHK_RET_FRAG_NEEDED,  /* fragmentation required to fwd */
586734b2021cSJesper Dangaard Brouer 	BPF_MTU_CHK_RET_SEGS_TOOBIG,  /* GSO re-segmentation needed to fwd */
586834b2021cSJesper Dangaard Brouer };
586934b2021cSJesper Dangaard Brouer 
587041bdc4b4SYonghong Song enum bpf_task_fd_type {
587141bdc4b4SYonghong Song 	BPF_FD_TYPE_RAW_TRACEPOINT,	/* tp name */
587241bdc4b4SYonghong Song 	BPF_FD_TYPE_TRACEPOINT,		/* tp name */
587341bdc4b4SYonghong Song 	BPF_FD_TYPE_KPROBE,		/* (symbol + offset) or addr */
587441bdc4b4SYonghong Song 	BPF_FD_TYPE_KRETPROBE,		/* (symbol + offset) or addr */
587541bdc4b4SYonghong Song 	BPF_FD_TYPE_UPROBE,		/* filename + offset */
587641bdc4b4SYonghong Song 	BPF_FD_TYPE_URETPROBE,		/* filename + offset */
587741bdc4b4SYonghong Song };
587841bdc4b4SYonghong Song 
58791aae4bddSAndrii Nakryiko enum {
58801aae4bddSAndrii Nakryiko 	BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG		= (1U << 0),
58811aae4bddSAndrii Nakryiko 	BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL		= (1U << 1),
58821aae4bddSAndrii Nakryiko 	BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP		= (1U << 2),
58831aae4bddSAndrii Nakryiko };
5884086f9568SStanislav Fomichev 
5885d58e468bSPetar Penkov struct bpf_flow_keys {
5886d58e468bSPetar Penkov 	__u16	nhoff;
5887d58e468bSPetar Penkov 	__u16	thoff;
5888d58e468bSPetar Penkov 	__u16	addr_proto;			/* ETH_P_* of valid addrs */
5889d58e468bSPetar Penkov 	__u8	is_frag;
5890d58e468bSPetar Penkov 	__u8	is_first_frag;
5891d58e468bSPetar Penkov 	__u8	is_encap;
5892d58e468bSPetar Penkov 	__u8	ip_proto;
5893d58e468bSPetar Penkov 	__be16	n_proto;
5894d58e468bSPetar Penkov 	__be16	sport;
5895d58e468bSPetar Penkov 	__be16	dport;
5896d58e468bSPetar Penkov 	union {
5897d58e468bSPetar Penkov 		struct {
5898d58e468bSPetar Penkov 			__be32	ipv4_src;
5899d58e468bSPetar Penkov 			__be32	ipv4_dst;
5900d58e468bSPetar Penkov 		};
5901d58e468bSPetar Penkov 		struct {
5902d58e468bSPetar Penkov 			__u32	ipv6_src[4];	/* in6_addr; network order */
5903d58e468bSPetar Penkov 			__u32	ipv6_dst[4];	/* in6_addr; network order */
5904d58e468bSPetar Penkov 		};
5905d58e468bSPetar Penkov 	};
5906086f9568SStanislav Fomichev 	__u32	flags;
590771c99e32SStanislav Fomichev 	__be32	flow_label;
5908d58e468bSPetar Penkov };
5909d58e468bSPetar Penkov 
5910838e9690SYonghong Song struct bpf_func_info {
5911d30d42e0SMartin KaFai Lau 	__u32	insn_off;
5912838e9690SYonghong Song 	__u32	type_id;
5913838e9690SYonghong Song };
5914838e9690SYonghong Song 
5915c454a46bSMartin KaFai Lau #define BPF_LINE_INFO_LINE_NUM(line_col)	((line_col) >> 10)
5916c454a46bSMartin KaFai Lau #define BPF_LINE_INFO_LINE_COL(line_col)	((line_col) & 0x3ff)
5917c454a46bSMartin KaFai Lau 
5918c454a46bSMartin KaFai Lau struct bpf_line_info {
5919c454a46bSMartin KaFai Lau 	__u32	insn_off;
5920c454a46bSMartin KaFai Lau 	__u32	file_name_off;
5921c454a46bSMartin KaFai Lau 	__u32	line_off;
5922c454a46bSMartin KaFai Lau 	__u32	line_col;
5923c454a46bSMartin KaFai Lau };
5924c454a46bSMartin KaFai Lau 
5925d83525caSAlexei Starovoitov struct bpf_spin_lock {
5926d83525caSAlexei Starovoitov 	__u32	val;
5927d83525caSAlexei Starovoitov };
59287b146cebSAndrey Ignatov 
59297b146cebSAndrey Ignatov struct bpf_sysctl {
59307b146cebSAndrey Ignatov 	__u32	write;		/* Sysctl is being read (= 0) or written (= 1).
59317b146cebSAndrey Ignatov 				 * Allows 1,2,4-byte read, but no write.
59327b146cebSAndrey Ignatov 				 */
5933e1550bfeSAndrey Ignatov 	__u32	file_pos;	/* Sysctl file position to read from, write to.
5934e1550bfeSAndrey Ignatov 				 * Allows 1,2,4-byte read an 4-byte write.
5935e1550bfeSAndrey Ignatov 				 */
59367b146cebSAndrey Ignatov };
59377b146cebSAndrey Ignatov 
59380d01da6aSStanislav Fomichev struct bpf_sockopt {
59390d01da6aSStanislav Fomichev 	__bpf_md_ptr(struct bpf_sock *, sk);
59400d01da6aSStanislav Fomichev 	__bpf_md_ptr(void *, optval);
59410d01da6aSStanislav Fomichev 	__bpf_md_ptr(void *, optval_end);
59420d01da6aSStanislav Fomichev 
59430d01da6aSStanislav Fomichev 	__s32	level;
59440d01da6aSStanislav Fomichev 	__s32	optname;
59450d01da6aSStanislav Fomichev 	__s32	optlen;
59460d01da6aSStanislav Fomichev 	__s32	retval;
59470d01da6aSStanislav Fomichev };
59480d01da6aSStanislav Fomichev 
5949b4490c5cSCarlos Neira struct bpf_pidns_info {
5950b4490c5cSCarlos Neira 	__u32 pid;
5951b4490c5cSCarlos Neira 	__u32 tgid;
5952b4490c5cSCarlos Neira };
5953e9ddbb77SJakub Sitnicki 
5954e9ddbb77SJakub Sitnicki /* User accessible data for SK_LOOKUP programs. Add new fields at the end. */
5955e9ddbb77SJakub Sitnicki struct bpf_sk_lookup {
5956e9ddbb77SJakub Sitnicki 	__bpf_md_ptr(struct bpf_sock *, sk); /* Selected socket */
5957e9ddbb77SJakub Sitnicki 
5958e9ddbb77SJakub Sitnicki 	__u32 family;		/* Protocol family (AF_INET, AF_INET6) */
5959e9ddbb77SJakub Sitnicki 	__u32 protocol;		/* IP protocol (IPPROTO_TCP, IPPROTO_UDP) */
5960e9ddbb77SJakub Sitnicki 	__u32 remote_ip4;	/* Network byte order */
5961e9ddbb77SJakub Sitnicki 	__u32 remote_ip6[4];	/* Network byte order */
5962e9ddbb77SJakub Sitnicki 	__u32 remote_port;	/* Network byte order */
5963e9ddbb77SJakub Sitnicki 	__u32 local_ip4;	/* Network byte order */
5964e9ddbb77SJakub Sitnicki 	__u32 local_ip6[4];	/* Network byte order */
5965e9ddbb77SJakub Sitnicki 	__u32 local_port;	/* Host byte order */
5966e9ddbb77SJakub Sitnicki };
5967e9ddbb77SJakub Sitnicki 
5968c4d0bfb4SAlan Maguire /*
5969c4d0bfb4SAlan Maguire  * struct btf_ptr is used for typed pointer representation; the
5970c4d0bfb4SAlan Maguire  * type id is used to render the pointer data as the appropriate type
5971c4d0bfb4SAlan Maguire  * via the bpf_snprintf_btf() helper described above.  A flags field -
5972c4d0bfb4SAlan Maguire  * potentially to specify additional details about the BTF pointer
5973c4d0bfb4SAlan Maguire  * (rather than its mode of display) - is included for future use.
5974c4d0bfb4SAlan Maguire  * Display flags - BTF_F_* - are passed to bpf_snprintf_btf separately.
5975c4d0bfb4SAlan Maguire  */
5976c4d0bfb4SAlan Maguire struct btf_ptr {
5977c4d0bfb4SAlan Maguire 	void *ptr;
5978c4d0bfb4SAlan Maguire 	__u32 type_id;
5979c4d0bfb4SAlan Maguire 	__u32 flags;		/* BTF ptr flags; unused at present. */
5980c4d0bfb4SAlan Maguire };
5981c4d0bfb4SAlan Maguire 
5982c4d0bfb4SAlan Maguire /*
5983c4d0bfb4SAlan Maguire  * Flags to control bpf_snprintf_btf() behaviour.
5984c4d0bfb4SAlan Maguire  *     - BTF_F_COMPACT: no formatting around type information
5985c4d0bfb4SAlan Maguire  *     - BTF_F_NONAME: no struct/union member names/types
5986c4d0bfb4SAlan Maguire  *     - BTF_F_PTR_RAW: show raw (unobfuscated) pointer values;
5987c4d0bfb4SAlan Maguire  *       equivalent to %px.
5988c4d0bfb4SAlan Maguire  *     - BTF_F_ZERO: show zero-valued struct/union members; they
5989c4d0bfb4SAlan Maguire  *       are not displayed by default
5990c4d0bfb4SAlan Maguire  */
5991c4d0bfb4SAlan Maguire enum {
5992c4d0bfb4SAlan Maguire 	BTF_F_COMPACT	=	(1ULL << 0),
5993c4d0bfb4SAlan Maguire 	BTF_F_NONAME	=	(1ULL << 1),
5994c4d0bfb4SAlan Maguire 	BTF_F_PTR_RAW	=	(1ULL << 2),
5995c4d0bfb4SAlan Maguire 	BTF_F_ZERO	=	(1ULL << 3),
5996c4d0bfb4SAlan Maguire };
5997c4d0bfb4SAlan Maguire 
5998daedfb22SAlexei Starovoitov #endif /* _UAPI__LINUX_BPF_H__ */
5999