• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 R"********(
2 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
3 /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 2 of the GNU General Public
7  * License as published by the Free Software Foundation.
8  */
9 #ifndef _UAPI__LINUX_BPF_H__
10 #define _UAPI__LINUX_BPF_H__
11 
12 #include <linux/types.h>
13 #include <linux/bpf_common.h>
14 
15 /* Extended instruction set based on top of classic BPF */
16 
17 /* instruction classes */
18 #define BPF_JMP32	0x06	/* jmp mode in word width */
19 #define BPF_ALU64	0x07	/* alu mode in double word width */
20 
21 /* ld/ldx fields */
22 #define BPF_DW		0x18	/* double word (64-bit) */
23 #define BPF_ATOMIC	0xc0	/* atomic memory ops - op type in immediate */
24 #define BPF_XADD	0xc0	/* exclusive add - legacy name */
25 
26 /* alu/jmp fields */
27 #define BPF_MOV		0xb0	/* mov reg to reg */
28 #define BPF_ARSH	0xc0	/* sign extending arithmetic shift right */
29 
30 /* change endianness of a register */
31 #define BPF_END		0xd0	/* flags for endianness conversion: */
32 #define BPF_TO_LE	0x00	/* convert to little-endian */
33 #define BPF_TO_BE	0x08	/* convert to big-endian */
34 #define BPF_FROM_LE	BPF_TO_LE
35 #define BPF_FROM_BE	BPF_TO_BE
36 
37 /* jmp encodings */
38 #define BPF_JNE		0x50	/* jump != */
39 #define BPF_JLT		0xa0	/* LT is unsigned, '<' */
40 #define BPF_JLE		0xb0	/* LE is unsigned, '<=' */
41 #define BPF_JSGT	0x60	/* SGT is signed '>', GT in x86 */
42 #define BPF_JSGE	0x70	/* SGE is signed '>=', GE in x86 */
43 #define BPF_JSLT	0xc0	/* SLT is signed, '<' */
44 #define BPF_JSLE	0xd0	/* SLE is signed, '<=' */
45 #define BPF_CALL	0x80	/* function call */
46 #define BPF_EXIT	0x90	/* function return */
47 
48 /* atomic op type fields (stored in immediate) */
49 #define BPF_FETCH	0x01	/* not an opcode on its own, used to build others */
50 #define BPF_XCHG	(0xe0 | BPF_FETCH)	/* atomic exchange */
51 #define BPF_CMPXCHG	(0xf0 | BPF_FETCH)	/* atomic compare-and-write */
52 
53 /* Register numbers */
54 enum {
55 	BPF_REG_0 = 0,
56 	BPF_REG_1,
57 	BPF_REG_2,
58 	BPF_REG_3,
59 	BPF_REG_4,
60 	BPF_REG_5,
61 	BPF_REG_6,
62 	BPF_REG_7,
63 	BPF_REG_8,
64 	BPF_REG_9,
65 	BPF_REG_10,
66 	__MAX_BPF_REG,
67 };
68 
69 /* BPF has 10 general purpose 64-bit registers and stack frame. */
70 #define MAX_BPF_REG	__MAX_BPF_REG
71 
72 struct bpf_insn {
73 	__u8	code;		/* opcode */
74 	__u8	dst_reg:4;	/* dest register */
75 	__u8	src_reg:4;	/* source register */
76 	__s16	off;		/* signed offset */
77 	__s32	imm;		/* signed immediate constant */
78 };
79 
80 /* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */
81 struct bpf_lpm_trie_key {
82 	__u32	prefixlen;	/* up to 32 for AF_INET, 128 for AF_INET6 */
83 	__u8	data[0];	/* Arbitrary size */
84 };
85 
86 struct bpf_cgroup_storage_key {
87 	__u64	cgroup_inode_id;	/* cgroup inode id */
88 	__u32	attach_type;		/* program attach type (enum bpf_attach_type) */
89 };
90 
91 union bpf_iter_link_info {
92 	struct {
93 		__u32	map_fd;
94 	} map;
95 };
96 
97 /* BPF syscall commands, see bpf(2) man-page for more details. */
98 /**
99  * DOC: eBPF Syscall Preamble
100  *
101  * The operation to be performed by the **bpf**\ () system call is determined
102  * by the *cmd* argument. Each operation takes an accompanying argument,
103  * provided via *attr*, which is a pointer to a union of type *bpf_attr* (see
104  * below). The size argument is the size of the union pointed to by *attr*.
105  */
106 /**
107  * DOC: eBPF Syscall Commands
108  *
109  * BPF_MAP_CREATE
110  *	Description
111  *		Create a map and return a file descriptor that refers to the
112  *		map. The close-on-exec file descriptor flag (see **fcntl**\ (2))
113  *		is automatically enabled for the new file descriptor.
114  *
115  *		Applying **close**\ (2) to the file descriptor returned by
116  *		**BPF_MAP_CREATE** will delete the map (but see NOTES).
117  *
118  *	Return
119  *		A new file descriptor (a nonnegative integer), or -1 if an
120  *		error occurred (in which case, *errno* is set appropriately).
121  *
122  * BPF_MAP_LOOKUP_ELEM
123  *	Description
124  *		Look up an element with a given *key* in the map referred to
125  *		by the file descriptor *map_fd*.
126  *
127  *		The *flags* argument may be specified as one of the
128  *		following:
129  *
130  *		**BPF_F_LOCK**
131  *			Look up the value of a spin-locked map without
132  *			returning the lock. This must be specified if the
133  *			elements contain a spinlock.
134  *
135  *	Return
136  *		Returns zero on success. On error, -1 is returned and *errno*
137  *		is set appropriately.
138  *
139  * BPF_MAP_UPDATE_ELEM
140  *	Description
141  *		Create or update an element (key/value pair) in a specified map.
142  *
143  *		The *flags* argument should be specified as one of the
144  *		following:
145  *
146  *		**BPF_ANY**
147  *			Create a new element or update an existing element.
148  *		**BPF_NOEXIST**
149  *			Create a new element only if it did not exist.
150  *		**BPF_EXIST**
151  *			Update an existing element.
152  *		**BPF_F_LOCK**
153  *			Update a spin_lock-ed map element.
154  *
155  *	Return
156  *		Returns zero on success. On error, -1 is returned and *errno*
157  *		is set appropriately.
158  *
159  *		May set *errno* to **EINVAL**, **EPERM**, **ENOMEM**,
160  *		**E2BIG**, **EEXIST**, or **ENOENT**.
161  *
162  *		**E2BIG**
163  *			The number of elements in the map reached the
164  *			*max_entries* limit specified at map creation time.
165  *		**EEXIST**
166  *			If *flags* specifies **BPF_NOEXIST** and the element
167  *			with *key* already exists in the map.
168  *		**ENOENT**
169  *			If *flags* specifies **BPF_EXIST** and the element with
170  *			*key* does not exist in the map.
171  *
172  * BPF_MAP_DELETE_ELEM
173  *	Description
174  *		Look up and delete an element by key in a specified map.
175  *
176  *	Return
177  *		Returns zero on success. On error, -1 is returned and *errno*
178  *		is set appropriately.
179  *
180  * BPF_MAP_GET_NEXT_KEY
181  *	Description
182  *		Look up an element by key in a specified map and return the key
183  *		of the next element. Can be used to iterate over all elements
184  *		in the map.
185  *
186  *	Return
187  *		Returns zero on success. On error, -1 is returned and *errno*
188  *		is set appropriately.
189  *
190  *		The following cases can be used to iterate over all elements of
191  *		the map:
192  *
193  *		* If *key* is not found, the operation returns zero and sets
194  *		  the *next_key* pointer to the key of the first element.
195  *		* If *key* is found, the operation returns zero and sets the
196  *		  *next_key* pointer to the key of the next element.
197  *		* If *key* is the last element, returns -1 and *errno* is set
198  *		  to **ENOENT**.
199  *
200  *		May set *errno* to **ENOMEM**, **EFAULT**, **EPERM**, or
201  *		**EINVAL** on error.
202  *
203  * BPF_PROG_LOAD
204  *	Description
205  *		Verify and load an eBPF program, returning a new file
206  *		descriptor associated with the program.
207  *
208  *		Applying **close**\ (2) to the file descriptor returned by
209  *		**BPF_PROG_LOAD** will unload the eBPF program (but see NOTES).
210  *
211  *		The close-on-exec file descriptor flag (see **fcntl**\ (2)) is
212  *		automatically enabled for the new file descriptor.
213  *
214  *	Return
215  *		A new file descriptor (a nonnegative integer), or -1 if an
216  *		error occurred (in which case, *errno* is set appropriately).
217  *
218  * BPF_OBJ_PIN
219  *	Description
220  *		Pin an eBPF program or map referred by the specified *bpf_fd*
221  *		to the provided *pathname* on the filesystem.
222  *
223  *		The *pathname* argument must not contain a dot (".").
224  *
225  *		On success, *pathname* retains a reference to the eBPF object,
226  *		preventing deallocation of the object when the original
227  *		*bpf_fd* is closed. This allow the eBPF object to live beyond
228  *		**close**\ (\ *bpf_fd*\ ), and hence the lifetime of the parent
229  *		process.
230  *
231  *		Applying **unlink**\ (2) or similar calls to the *pathname*
232  *		unpins the object from the filesystem, removing the reference.
233  *		If no other file descriptors or filesystem nodes refer to the
234  *		same object, it will be deallocated (see NOTES).
235  *
236  *		The filesystem type for the parent directory of *pathname* must
237  *		be **BPF_FS_MAGIC**.
238  *
239  *	Return
240  *		Returns zero on success. On error, -1 is returned and *errno*
241  *		is set appropriately.
242  *
243  * BPF_OBJ_GET
244  *	Description
245  *		Open a file descriptor for the eBPF object pinned to the
246  *		specified *pathname*.
247  *
248  *	Return
249  *		A new file descriptor (a nonnegative integer), or -1 if an
250  *		error occurred (in which case, *errno* is set appropriately).
251  *
252  * BPF_PROG_ATTACH
253  *	Description
254  *		Attach an eBPF program to a *target_fd* at the specified
255  *		*attach_type* hook.
256  *
257  *		The *attach_type* specifies the eBPF attachment point to
258  *		attach the program to, and must be one of *bpf_attach_type*
259  *		(see below).
260  *
261  *		The *attach_bpf_fd* must be a valid file descriptor for a
262  *		loaded eBPF program of a cgroup, flow dissector, LIRC, sockmap
263  *		or sock_ops type corresponding to the specified *attach_type*.
264  *
265  *		The *target_fd* must be a valid file descriptor for a kernel
266  *		object which depends on the attach type of *attach_bpf_fd*:
267  *
268  *		**BPF_PROG_TYPE_CGROUP_DEVICE**,
269  *		**BPF_PROG_TYPE_CGROUP_SKB**,
270  *		**BPF_PROG_TYPE_CGROUP_SOCK**,
271  *		**BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,
272  *		**BPF_PROG_TYPE_CGROUP_SOCKOPT**,
273  *		**BPF_PROG_TYPE_CGROUP_SYSCTL**,
274  *		**BPF_PROG_TYPE_SOCK_OPS**
275  *
276  *			Control Group v2 hierarchy with the eBPF controller
277  *			enabled. Requires the kernel to be compiled with
278  *			**CONFIG_CGROUP_BPF**.
279  *
280  *		**BPF_PROG_TYPE_FLOW_DISSECTOR**
281  *
282  *			Network namespace (eg /proc/self/ns/net).
283  *
284  *		**BPF_PROG_TYPE_LIRC_MODE2**
285  *
286  *			LIRC device path (eg /dev/lircN). Requires the kernel
287  *			to be compiled with **CONFIG_BPF_LIRC_MODE2**.
288  *
289  *		**BPF_PROG_TYPE_SK_SKB**,
290  *		**BPF_PROG_TYPE_SK_MSG**
291  *
292  *			eBPF map of socket type (eg **BPF_MAP_TYPE_SOCKHASH**).
293  *
294  *	Return
295  *		Returns zero on success. On error, -1 is returned and *errno*
296  *		is set appropriately.
297  *
298  * BPF_PROG_DETACH
299  *	Description
300  *		Detach the eBPF program associated with the *target_fd* at the
301  *		hook specified by *attach_type*. The program must have been
302  *		previously attached using **BPF_PROG_ATTACH**.
303  *
304  *	Return
305  *		Returns zero on success. On error, -1 is returned and *errno*
306  *		is set appropriately.
307  *
308  * BPF_PROG_TEST_RUN
309  *	Description
310  *		Run the eBPF program associated with the *prog_fd* a *repeat*
311  *		number of times against a provided program context *ctx_in* and
312  *		data *data_in*, and return the modified program context
313  *		*ctx_out*, *data_out* (for example, packet data), result of the
314  *		execution *retval*, and *duration* of the test run.
315  *
316  *		The sizes of the buffers provided as input and output
317  *		parameters *ctx_in*, *ctx_out*, *data_in*, and *data_out* must
318  *		be provided in the corresponding variables *ctx_size_in*,
319  *		*ctx_size_out*, *data_size_in*, and/or *data_size_out*. If any
320  *		of these parameters are not provided (ie set to NULL), the
321  *		corresponding size field must be zero.
322  *
323  *		Some program types have particular requirements:
324  *
325  *		**BPF_PROG_TYPE_SK_LOOKUP**
326  *			*data_in* and *data_out* must be NULL.
327  *
328  *		**BPF_PROG_TYPE_RAW_TRACEPOINT**,
329  *		**BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE**
330  *
331  *			*ctx_out*, *data_in* and *data_out* must be NULL.
332  *			*repeat* must be zero.
333  *
334  *		BPF_PROG_RUN is an alias for BPF_PROG_TEST_RUN.
335  *
336  *	Return
337  *		Returns zero on success. On error, -1 is returned and *errno*
338  *		is set appropriately.
339  *
340  *		**ENOSPC**
341  *			Either *data_size_out* or *ctx_size_out* is too small.
342  *		**ENOTSUPP**
343  *			This command is not supported by the program type of
344  *			the program referred to by *prog_fd*.
345  *
346  * BPF_PROG_GET_NEXT_ID
347  *	Description
348  *		Fetch the next eBPF program currently loaded into the kernel.
349  *
350  *		Looks for the eBPF program with an id greater than *start_id*
351  *		and updates *next_id* on success. If no other eBPF programs
352  *		remain with ids higher than *start_id*, returns -1 and sets
353  *		*errno* to **ENOENT**.
354  *
355  *	Return
356  *		Returns zero on success. On error, or when no id remains, -1
357  *		is returned and *errno* is set appropriately.
358  *
359  * BPF_MAP_GET_NEXT_ID
360  *	Description
361  *		Fetch the next eBPF map currently loaded into the kernel.
362  *
363  *		Looks for the eBPF map with an id greater than *start_id*
364  *		and updates *next_id* on success. If no other eBPF maps
365  *		remain with ids higher than *start_id*, returns -1 and sets
366  *		*errno* to **ENOENT**.
367  *
368  *	Return
369  *		Returns zero on success. On error, or when no id remains, -1
370  *		is returned and *errno* is set appropriately.
371  *
372  * BPF_PROG_GET_FD_BY_ID
373  *	Description
374  *		Open a file descriptor for the eBPF program corresponding to
375  *		*prog_id*.
376  *
377  *	Return
378  *		A new file descriptor (a nonnegative integer), or -1 if an
379  *		error occurred (in which case, *errno* is set appropriately).
380  *
381  * BPF_MAP_GET_FD_BY_ID
382  *	Description
383  *		Open a file descriptor for the eBPF map corresponding to
384  *		*map_id*.
385  *
386  *	Return
387  *		A new file descriptor (a nonnegative integer), or -1 if an
388  *		error occurred (in which case, *errno* is set appropriately).
389  *
390  * BPF_OBJ_GET_INFO_BY_FD
391  *	Description
392  *		Obtain information about the eBPF object corresponding to
393  *		*bpf_fd*.
394  *
395  *		Populates up to *info_len* bytes of *info*, which will be in
396  *		one of the following formats depending on the eBPF object type
397  *		of *bpf_fd*:
398  *
399  *		* **struct bpf_prog_info**
400  *		* **struct bpf_map_info**
401  *		* **struct bpf_btf_info**
402  *		* **struct bpf_link_info**
403  *
404  *	Return
405  *		Returns zero on success. On error, -1 is returned and *errno*
406  *		is set appropriately.
407  *
408  * BPF_PROG_QUERY
409  *	Description
410  *		Obtain information about eBPF programs associated with the
411  *		specified *attach_type* hook.
412  *
413  *		The *target_fd* must be a valid file descriptor for a kernel
414  *		object which depends on the attach type of *attach_bpf_fd*:
415  *
416  *		**BPF_PROG_TYPE_CGROUP_DEVICE**,
417  *		**BPF_PROG_TYPE_CGROUP_SKB**,
418  *		**BPF_PROG_TYPE_CGROUP_SOCK**,
419  *		**BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,
420  *		**BPF_PROG_TYPE_CGROUP_SOCKOPT**,
421  *		**BPF_PROG_TYPE_CGROUP_SYSCTL**,
422  *		**BPF_PROG_TYPE_SOCK_OPS**
423  *
424  *			Control Group v2 hierarchy with the eBPF controller
425  *			enabled. Requires the kernel to be compiled with
426  *			**CONFIG_CGROUP_BPF**.
427  *
428  *		**BPF_PROG_TYPE_FLOW_DISSECTOR**
429  *
430  *			Network namespace (eg /proc/self/ns/net).
431  *
432  *		**BPF_PROG_TYPE_LIRC_MODE2**
433  *
434  *			LIRC device path (eg /dev/lircN). Requires the kernel
435  *			to be compiled with **CONFIG_BPF_LIRC_MODE2**.
436  *
437  *		**BPF_PROG_QUERY** always fetches the number of programs
438  *		attached and the *attach_flags* which were used to attach those
439  *		programs. Additionally, if *prog_ids* is nonzero and the number
440  *		of attached programs is less than *prog_cnt*, populates
441  *		*prog_ids* with the eBPF program ids of the programs attached
442  *		at *target_fd*.
443  *
444  *		The following flags may alter the result:
445  *
446  *		**BPF_F_QUERY_EFFECTIVE**
447  *			Only return information regarding programs which are
448  *			currently effective at the specified *target_fd*.
449  *
450  *	Return
451  *		Returns zero on success. On error, -1 is returned and *errno*
452  *		is set appropriately.
453  *
454  * BPF_RAW_TRACEPOINT_OPEN
455  *	Description
456  *		Attach an eBPF program to a tracepoint *name* to access kernel
457  *		internal arguments of the tracepoint in their raw form.
458  *
459  *		The *prog_fd* must be a valid file descriptor associated with
460  *		a loaded eBPF program of type **BPF_PROG_TYPE_RAW_TRACEPOINT**.
461  *
462  *		No ABI guarantees are made about the content of tracepoint
463  *		arguments exposed to the corresponding eBPF program.
464  *
465  *		Applying **close**\ (2) to the file descriptor returned by
466  *		**BPF_RAW_TRACEPOINT_OPEN** will delete the map (but see NOTES).
467  *
468  *	Return
469  *		A new file descriptor (a nonnegative integer), or -1 if an
470  *		error occurred (in which case, *errno* is set appropriately).
471  *
472  * BPF_BTF_LOAD
473  *	Description
474  *		Verify and load BPF Type Format (BTF) metadata into the kernel,
475  *		returning a new file descriptor associated with the metadata.
476  *		BTF is described in more detail at
477  *		https://www.kernel.org/doc/html/latest/bpf/btf.html.
478  *
479  *		The *btf* parameter must point to valid memory providing
480  *		*btf_size* bytes of BTF binary metadata.
481  *
482  *		The returned file descriptor can be passed to other **bpf**\ ()
483  *		subcommands such as **BPF_PROG_LOAD** or **BPF_MAP_CREATE** to
484  *		associate the BTF with those objects.
485  *
486  *		Similar to **BPF_PROG_LOAD**, **BPF_BTF_LOAD** has optional
487  *		parameters to specify a *btf_log_buf*, *btf_log_size* and
488  *		*btf_log_level* which allow the kernel to return freeform log
489  *		output regarding the BTF verification process.
490  *
491  *	Return
492  *		A new file descriptor (a nonnegative integer), or -1 if an
493  *		error occurred (in which case, *errno* is set appropriately).
494  *
495  * BPF_BTF_GET_FD_BY_ID
496  *	Description
497  *		Open a file descriptor for the BPF Type Format (BTF)
498  *		corresponding to *btf_id*.
499  *
500  *	Return
501  *		A new file descriptor (a nonnegative integer), or -1 if an
502  *		error occurred (in which case, *errno* is set appropriately).
503  *
504  * BPF_TASK_FD_QUERY
505  *	Description
506  *		Obtain information about eBPF programs associated with the
507  *		target process identified by *pid* and *fd*.
508  *
509  *		If the *pid* and *fd* are associated with a tracepoint, kprobe
510  *		or uprobe perf event, then the *prog_id* and *fd_type* will
511  *		be populated with the eBPF program id and file descriptor type
512  *		of type **bpf_task_fd_type**. If associated with a kprobe or
513  *		uprobe, the  *probe_offset* and *probe_addr* will also be
514  *		populated. Optionally, if *buf* is provided, then up to
515  *		*buf_len* bytes of *buf* will be populated with the name of
516  *		the tracepoint, kprobe or uprobe.
517  *
518  *		The resulting *prog_id* may be introspected in deeper detail
519  *		using **BPF_PROG_GET_FD_BY_ID** and **BPF_OBJ_GET_INFO_BY_FD**.
520  *
521  *	Return
522  *		Returns zero on success. On error, -1 is returned and *errno*
523  *		is set appropriately.
524  *
525  * BPF_MAP_LOOKUP_AND_DELETE_ELEM
526  *	Description
527  *		Look up an element with the given *key* in the map referred to
528  *		by the file descriptor *fd*, and if found, delete the element.
529  *
530  *		For **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map
531  *		types, the *flags* argument needs to be set to 0, but for other
532  *		map types, it may be specified as:
533  *
534  *		**BPF_F_LOCK**
535  *			Look up and delete the value of a spin-locked map
536  *			without returning the lock. This must be specified if
537  *			the elements contain a spinlock.
538  *
539  *		The **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map types
540  *		implement this command as a "pop" operation, deleting the top
541  *		element rather than one corresponding to *key*.
542  *		The *key* and *key_len* parameters should be zeroed when
543  *		issuing this operation for these map types.
544  *
545  *		This command is only valid for the following map types:
546  *		* **BPF_MAP_TYPE_QUEUE**
547  *		* **BPF_MAP_TYPE_STACK**
548  *		* **BPF_MAP_TYPE_HASH**
549  *		* **BPF_MAP_TYPE_PERCPU_HASH**
550  *		* **BPF_MAP_TYPE_LRU_HASH**
551  *		* **BPF_MAP_TYPE_LRU_PERCPU_HASH**
552  *
553  *	Return
554  *		Returns zero on success. On error, -1 is returned and *errno*
555  *		is set appropriately.
556  *
557  * BPF_MAP_FREEZE
558  *	Description
559  *		Freeze the permissions of the specified map.
560  *
561  *		Write permissions may be frozen by passing zero *flags*.
562  *		Upon success, no future syscall invocations may alter the
563  *		map state of *map_fd*. Write operations from eBPF programs
564  *		are still possible for a frozen map.
565  *
566  *		Not supported for maps of type **BPF_MAP_TYPE_STRUCT_OPS**.
567  *
568  *	Return
569  *		Returns zero on success. On error, -1 is returned and *errno*
570  *		is set appropriately.
571  *
572  * BPF_BTF_GET_NEXT_ID
573  *	Description
574  *		Fetch the next BPF Type Format (BTF) object currently loaded
575  *		into the kernel.
576  *
577  *		Looks for the BTF object with an id greater than *start_id*
578  *		and updates *next_id* on success. If no other BTF objects
579  *		remain with ids higher than *start_id*, returns -1 and sets
580  *		*errno* to **ENOENT**.
581  *
582  *	Return
583  *		Returns zero on success. On error, or when no id remains, -1
584  *		is returned and *errno* is set appropriately.
585  *
586  * BPF_MAP_LOOKUP_BATCH
587  *	Description
588  *		Iterate and fetch multiple elements in a map.
589  *
590  *		Two opaque values are used to manage batch operations,
591  *		*in_batch* and *out_batch*. Initially, *in_batch* must be set
592  *		to NULL to begin the batched operation. After each subsequent
593  *		**BPF_MAP_LOOKUP_BATCH**, the caller should pass the resultant
594  *		*out_batch* as the *in_batch* for the next operation to
595  *		continue iteration from the current point.
596  *
597  *		The *keys* and *values* are output parameters which must point
598  *		to memory large enough to hold *count* items based on the key
599  *		and value size of the map *map_fd*. The *keys* buffer must be
600  *		of *key_size* * *count*. The *values* buffer must be of
601  *		*value_size* * *count*.
602  *
603  *		The *elem_flags* argument may be specified as one of the
604  *		following:
605  *
606  *		**BPF_F_LOCK**
607  *			Look up the value of a spin-locked map without
608  *			returning the lock. This must be specified if the
609  *			elements contain a spinlock.
610  *
611  *		On success, *count* elements from the map are copied into the
612  *		user buffer, with the keys copied into *keys* and the values
613  *		copied into the corresponding indices in *values*.
614  *
615  *		If an error is returned and *errno* is not **EFAULT**, *count*
616  *		is set to the number of successfully processed elements.
617  *
618  *	Return
619  *		Returns zero on success. On error, -1 is returned and *errno*
620  *		is set appropriately.
621  *
622  *		May set *errno* to **ENOSPC** to indicate that *keys* or
623  *		*values* is too small to dump an entire bucket during
624  *		iteration of a hash-based map type.
625  *
626  * BPF_MAP_LOOKUP_AND_DELETE_BATCH
627  *	Description
628  *		Iterate and delete all elements in a map.
629  *
630  *		This operation has the same behavior as
631  *		**BPF_MAP_LOOKUP_BATCH** with two exceptions:
632  *
633  *		* Every element that is successfully returned is also deleted
634  *		  from the map. This is at least *count* elements. Note that
635  *		  *count* is both an input and an output parameter.
636  *		* Upon returning with *errno* set to **EFAULT**, up to
637  *		  *count* elements may be deleted without returning the keys
638  *		  and values of the deleted elements.
639  *
640  *	Return
641  *		Returns zero on success. On error, -1 is returned and *errno*
642  *		is set appropriately.
643  *
644  * BPF_MAP_UPDATE_BATCH
645  *	Description
646  *		Update multiple elements in a map by *key*.
647  *
648  *		The *keys* and *values* are input parameters which must point
649  *		to memory large enough to hold *count* items based on the key
650  *		and value size of the map *map_fd*. The *keys* buffer must be
651  *		of *key_size* * *count*. The *values* buffer must be of
652  *		*value_size* * *count*.
653  *
654  *		Each element specified in *keys* is sequentially updated to the
655  *		value in the corresponding index in *values*. The *in_batch*
656  *		and *out_batch* parameters are ignored and should be zeroed.
657  *
658  *		The *elem_flags* argument should be specified as one of the
659  *		following:
660  *
661  *		**BPF_ANY**
662  *			Create new elements or update a existing elements.
663  *		**BPF_NOEXIST**
664  *			Create new elements only if they do not exist.
665  *		**BPF_EXIST**
666  *			Update existing elements.
667  *		**BPF_F_LOCK**
668  *			Update spin_lock-ed map elements. This must be
669  *			specified if the map value contains a spinlock.
670  *
671  *		On success, *count* elements from the map are updated.
672  *
673  *		If an error is returned and *errno* is not **EFAULT**, *count*
674  *		is set to the number of successfully processed elements.
675  *
676  *	Return
677  *		Returns zero on success. On error, -1 is returned and *errno*
678  *		is set appropriately.
679  *
680  *		May set *errno* to **EINVAL**, **EPERM**, **ENOMEM**, or
681  *		**E2BIG**. **E2BIG** indicates that the number of elements in
682  *		the map reached the *max_entries* limit specified at map
683  *		creation time.
684  *
685  *		May set *errno* to one of the following error codes under
686  *		specific circumstances:
687  *
688  *		**EEXIST**
689  *			If *flags* specifies **BPF_NOEXIST** and the element
690  *			with *key* already exists in the map.
691  *		**ENOENT**
692  *			If *flags* specifies **BPF_EXIST** and the element with
693  *			*key* does not exist in the map.
694  *
695  * BPF_MAP_DELETE_BATCH
696  *	Description
697  *		Delete multiple elements in a map by *key*.
698  *
699  *		The *keys* parameter is an input parameter which must point
700  *		to memory large enough to hold *count* items based on the key
701  *		size of the map *map_fd*, that is, *key_size* * *count*.
702  *
703  *		Each element specified in *keys* is sequentially deleted. The
704  *		*in_batch*, *out_batch*, and *values* parameters are ignored
705  *		and should be zeroed.
706  *
707  *		The *elem_flags* argument may be specified as one of the
708  *		following:
709  *
710  *		**BPF_F_LOCK**
711  *			Look up the value of a spin-locked map without
712  *			returning the lock. This must be specified if the
713  *			elements contain a spinlock.
714  *
715  *		On success, *count* elements from the map are updated.
716  *
717  *		If an error is returned and *errno* is not **EFAULT**, *count*
718  *		is set to the number of successfully processed elements. If
719  *		*errno* is **EFAULT**, up to *count* elements may be been
720  *		deleted.
721  *
722  *	Return
723  *		Returns zero on success. On error, -1 is returned and *errno*
724  *		is set appropriately.
725  *
726  * BPF_LINK_CREATE
727  *	Description
728  *		Attach an eBPF program to a *target_fd* at the specified
729  *		*attach_type* hook and return a file descriptor handle for
730  *		managing the link.
731  *
732  *	Return
733  *		A new file descriptor (a nonnegative integer), or -1 if an
734  *		error occurred (in which case, *errno* is set appropriately).
735  *
736  * BPF_LINK_UPDATE
737  *	Description
738  *		Update the eBPF program in the specified *link_fd* to
739  *		*new_prog_fd*.
740  *
741  *	Return
742  *		Returns zero on success. On error, -1 is returned and *errno*
743  *		is set appropriately.
744  *
745  * BPF_LINK_GET_FD_BY_ID
746  *	Description
747  *		Open a file descriptor for the eBPF Link corresponding to
748  *		*link_id*.
749  *
750  *	Return
751  *		A new file descriptor (a nonnegative integer), or -1 if an
752  *		error occurred (in which case, *errno* is set appropriately).
753  *
754  * BPF_LINK_GET_NEXT_ID
755  *	Description
756  *		Fetch the next eBPF link currently loaded into the kernel.
757  *
758  *		Looks for the eBPF link with an id greater than *start_id*
759  *		and updates *next_id* on success. If no other eBPF links
760  *		remain with ids higher than *start_id*, returns -1 and sets
761  *		*errno* to **ENOENT**.
762  *
763  *	Return
764  *		Returns zero on success. On error, or when no id remains, -1
765  *		is returned and *errno* is set appropriately.
766  *
767  * BPF_ENABLE_STATS
768  *	Description
769  *		Enable eBPF runtime statistics gathering.
770  *
771  *		Runtime statistics gathering for the eBPF runtime is disabled
772  *		by default to minimize the corresponding performance overhead.
773  *		This command enables statistics globally.
774  *
775  *		Multiple programs may independently enable statistics.
776  *		After gathering the desired statistics, eBPF runtime statistics
777  *		may be disabled again by calling **close**\ (2) for the file
778  *		descriptor returned by this function. Statistics will only be
779  *		disabled system-wide when all outstanding file descriptors
780  *		returned by prior calls for this subcommand are closed.
781  *
782  *	Return
783  *		A new file descriptor (a nonnegative integer), or -1 if an
784  *		error occurred (in which case, *errno* is set appropriately).
785  *
786  * BPF_ITER_CREATE
787  *	Description
788  *		Create an iterator on top of the specified *link_fd* (as
789  *		previously created using **BPF_LINK_CREATE**) and return a
790  *		file descriptor that can be used to trigger the iteration.
791  *
792  *		If the resulting file descriptor is pinned to the filesystem
793  *		using  **BPF_OBJ_PIN**, then subsequent **read**\ (2) syscalls
794  *		for that path will trigger the iterator to read kernel state
795  *		using the eBPF program attached to *link_fd*.
796  *
797  *	Return
798  *		A new file descriptor (a nonnegative integer), or -1 if an
799  *		error occurred (in which case, *errno* is set appropriately).
800  *
801  * BPF_LINK_DETACH
802  *	Description
803  *		Forcefully detach the specified *link_fd* from its
804  *		corresponding attachment point.
805  *
806  *	Return
807  *		Returns zero on success. On error, -1 is returned and *errno*
808  *		is set appropriately.
809  *
810  * BPF_PROG_BIND_MAP
811  *	Description
812  *		Bind a map to the lifetime of an eBPF program.
813  *
814  *		The map identified by *map_fd* is bound to the program
815  *		identified by *prog_fd* and only released when *prog_fd* is
816  *		released. This may be used in cases where metadata should be
817  *		associated with a program which otherwise does not contain any
818  *		references to the map (for example, embedded in the eBPF
819  *		program instructions).
820  *
821  *	Return
822  *		Returns zero on success. On error, -1 is returned and *errno*
823  *		is set appropriately.
824  *
825  * NOTES
826  *	eBPF objects (maps and programs) can be shared between processes.
827  *
828  *	* After **fork**\ (2), the child inherits file descriptors
829  *	  referring to the same eBPF objects.
830  *	* File descriptors referring to eBPF objects can be transferred over
831  *	  **unix**\ (7) domain sockets.
832  *	* File descriptors referring to eBPF objects can be duplicated in the
833  *	  usual way, using **dup**\ (2) and similar calls.
834  *	* File descriptors referring to eBPF objects can be pinned to the
835  *	  filesystem using the **BPF_OBJ_PIN** command of **bpf**\ (2).
836  *
837  *	An eBPF object is deallocated only after all file descriptors referring
838  *	to the object have been closed and no references remain pinned to the
839  *	filesystem or attached (for example, bound to a program or device).
840  */
841 enum bpf_cmd {
842 	BPF_MAP_CREATE,
843 	BPF_MAP_LOOKUP_ELEM,
844 	BPF_MAP_UPDATE_ELEM,
845 	BPF_MAP_DELETE_ELEM,
846 	BPF_MAP_GET_NEXT_KEY,
847 	BPF_PROG_LOAD,
848 	BPF_OBJ_PIN,
849 	BPF_OBJ_GET,
850 	BPF_PROG_ATTACH,
851 	BPF_PROG_DETACH,
852 	BPF_PROG_TEST_RUN,
853 	BPF_PROG_RUN = BPF_PROG_TEST_RUN,
854 	BPF_PROG_GET_NEXT_ID,
855 	BPF_MAP_GET_NEXT_ID,
856 	BPF_PROG_GET_FD_BY_ID,
857 	BPF_MAP_GET_FD_BY_ID,
858 	BPF_OBJ_GET_INFO_BY_FD,
859 	BPF_PROG_QUERY,
860 	BPF_RAW_TRACEPOINT_OPEN,
861 	BPF_BTF_LOAD,
862 	BPF_BTF_GET_FD_BY_ID,
863 	BPF_TASK_FD_QUERY,
864 	BPF_MAP_LOOKUP_AND_DELETE_ELEM,
865 	BPF_MAP_FREEZE,
866 	BPF_BTF_GET_NEXT_ID,
867 	BPF_MAP_LOOKUP_BATCH,
868 	BPF_MAP_LOOKUP_AND_DELETE_BATCH,
869 	BPF_MAP_UPDATE_BATCH,
870 	BPF_MAP_DELETE_BATCH,
871 	BPF_LINK_CREATE,
872 	BPF_LINK_UPDATE,
873 	BPF_LINK_GET_FD_BY_ID,
874 	BPF_LINK_GET_NEXT_ID,
875 	BPF_ENABLE_STATS,
876 	BPF_ITER_CREATE,
877 	BPF_LINK_DETACH,
878 	BPF_PROG_BIND_MAP,
879 };
880 
881 enum bpf_map_type {
882 	BPF_MAP_TYPE_UNSPEC,
883 	BPF_MAP_TYPE_HASH,
884 	BPF_MAP_TYPE_ARRAY,
885 	BPF_MAP_TYPE_PROG_ARRAY,
886 	BPF_MAP_TYPE_PERF_EVENT_ARRAY,
887 	BPF_MAP_TYPE_PERCPU_HASH,
888 	BPF_MAP_TYPE_PERCPU_ARRAY,
889 	BPF_MAP_TYPE_STACK_TRACE,
890 	BPF_MAP_TYPE_CGROUP_ARRAY,
891 	BPF_MAP_TYPE_LRU_HASH,
892 	BPF_MAP_TYPE_LRU_PERCPU_HASH,
893 	BPF_MAP_TYPE_LPM_TRIE,
894 	BPF_MAP_TYPE_ARRAY_OF_MAPS,
895 	BPF_MAP_TYPE_HASH_OF_MAPS,
896 	BPF_MAP_TYPE_DEVMAP,
897 	BPF_MAP_TYPE_SOCKMAP,
898 	BPF_MAP_TYPE_CPUMAP,
899 	BPF_MAP_TYPE_XSKMAP,
900 	BPF_MAP_TYPE_SOCKHASH,
901 	BPF_MAP_TYPE_CGROUP_STORAGE,
902 	BPF_MAP_TYPE_REUSEPORT_SOCKARRAY,
903 	BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE,
904 	BPF_MAP_TYPE_QUEUE,
905 	BPF_MAP_TYPE_STACK,
906 	BPF_MAP_TYPE_SK_STORAGE,
907 	BPF_MAP_TYPE_DEVMAP_HASH,
908 	BPF_MAP_TYPE_STRUCT_OPS,
909 	BPF_MAP_TYPE_RINGBUF,
910 	BPF_MAP_TYPE_INODE_STORAGE,
911 	BPF_MAP_TYPE_TASK_STORAGE,
912 	BPF_MAP_TYPE_BLOOM_FILTER,
913 };
914 
915 /* Note that tracing related programs such as
916  * BPF_PROG_TYPE_{KPROBE,TRACEPOINT,PERF_EVENT,RAW_TRACEPOINT}
917  * are not subject to a stable API since kernel internal data
918  * structures can change from release to release and may
919  * therefore break existing tracing BPF programs. Tracing BPF
920  * programs correspond to /a/ specific kernel which is to be
921  * analyzed, and not /a/ specific kernel /and/ all future ones.
922  */
923 enum bpf_prog_type {
924 	BPF_PROG_TYPE_UNSPEC,
925 	BPF_PROG_TYPE_SOCKET_FILTER,
926 	BPF_PROG_TYPE_KPROBE,
927 	BPF_PROG_TYPE_SCHED_CLS,
928 	BPF_PROG_TYPE_SCHED_ACT,
929 	BPF_PROG_TYPE_TRACEPOINT,
930 	BPF_PROG_TYPE_XDP,
931 	BPF_PROG_TYPE_PERF_EVENT,
932 	BPF_PROG_TYPE_CGROUP_SKB,
933 	BPF_PROG_TYPE_CGROUP_SOCK,
934 	BPF_PROG_TYPE_LWT_IN,
935 	BPF_PROG_TYPE_LWT_OUT,
936 	BPF_PROG_TYPE_LWT_XMIT,
937 	BPF_PROG_TYPE_SOCK_OPS,
938 	BPF_PROG_TYPE_SK_SKB,
939 	BPF_PROG_TYPE_CGROUP_DEVICE,
940 	BPF_PROG_TYPE_SK_MSG,
941 	BPF_PROG_TYPE_RAW_TRACEPOINT,
942 	BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
943 	BPF_PROG_TYPE_LWT_SEG6LOCAL,
944 	BPF_PROG_TYPE_LIRC_MODE2,
945 	BPF_PROG_TYPE_SK_REUSEPORT,
946 	BPF_PROG_TYPE_FLOW_DISSECTOR,
947 	BPF_PROG_TYPE_CGROUP_SYSCTL,
948 	BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
949 	BPF_PROG_TYPE_CGROUP_SOCKOPT,
950 	BPF_PROG_TYPE_TRACING,
951 	BPF_PROG_TYPE_STRUCT_OPS,
952 	BPF_PROG_TYPE_EXT,
953 	BPF_PROG_TYPE_LSM,
954 	BPF_PROG_TYPE_SK_LOOKUP,
955 	BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */
956 };
957 
958 enum bpf_attach_type {
959 	BPF_CGROUP_INET_INGRESS,
960 	BPF_CGROUP_INET_EGRESS,
961 	BPF_CGROUP_INET_SOCK_CREATE,
962 	BPF_CGROUP_SOCK_OPS,
963 	BPF_SK_SKB_STREAM_PARSER,
964 	BPF_SK_SKB_STREAM_VERDICT,
965 	BPF_CGROUP_DEVICE,
966 	BPF_SK_MSG_VERDICT,
967 	BPF_CGROUP_INET4_BIND,
968 	BPF_CGROUP_INET6_BIND,
969 	BPF_CGROUP_INET4_CONNECT,
970 	BPF_CGROUP_INET6_CONNECT,
971 	BPF_CGROUP_INET4_POST_BIND,
972 	BPF_CGROUP_INET6_POST_BIND,
973 	BPF_CGROUP_UDP4_SENDMSG,
974 	BPF_CGROUP_UDP6_SENDMSG,
975 	BPF_LIRC_MODE2,
976 	BPF_FLOW_DISSECTOR,
977 	BPF_CGROUP_SYSCTL,
978 	BPF_CGROUP_UDP4_RECVMSG,
979 	BPF_CGROUP_UDP6_RECVMSG,
980 	BPF_CGROUP_GETSOCKOPT,
981 	BPF_CGROUP_SETSOCKOPT,
982 	BPF_TRACE_RAW_TP,
983 	BPF_TRACE_FENTRY,
984 	BPF_TRACE_FEXIT,
985 	BPF_MODIFY_RETURN,
986 	BPF_LSM_MAC,
987 	BPF_TRACE_ITER,
988 	BPF_CGROUP_INET4_GETPEERNAME,
989 	BPF_CGROUP_INET6_GETPEERNAME,
990 	BPF_CGROUP_INET4_GETSOCKNAME,
991 	BPF_CGROUP_INET6_GETSOCKNAME,
992 	BPF_XDP_DEVMAP,
993 	BPF_CGROUP_INET_SOCK_RELEASE,
994 	BPF_XDP_CPUMAP,
995 	BPF_SK_LOOKUP,
996 	BPF_XDP,
997 	BPF_SK_SKB_VERDICT,
998 	BPF_SK_REUSEPORT_SELECT,
999 	BPF_SK_REUSEPORT_SELECT_OR_MIGRATE,
1000 	BPF_PERF_EVENT,
1001 	BPF_TRACE_KPROBE_MULTI,
1002 	__MAX_BPF_ATTACH_TYPE
1003 };
1004 
1005 #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
1006 
1007 enum bpf_link_type {
1008 	BPF_LINK_TYPE_UNSPEC = 0,
1009 	BPF_LINK_TYPE_RAW_TRACEPOINT = 1,
1010 	BPF_LINK_TYPE_TRACING = 2,
1011 	BPF_LINK_TYPE_CGROUP = 3,
1012 	BPF_LINK_TYPE_ITER = 4,
1013 	BPF_LINK_TYPE_NETNS = 5,
1014 	BPF_LINK_TYPE_XDP = 6,
1015 	BPF_LINK_TYPE_PERF_EVENT = 7,
1016 	BPF_LINK_TYPE_KPROBE_MULTI = 8,
1017 
1018 	MAX_BPF_LINK_TYPE,
1019 };
1020 
1021 /* cgroup-bpf attach flags used in BPF_PROG_ATTACH command
1022  *
1023  * NONE(default): No further bpf programs allowed in the subtree.
1024  *
1025  * BPF_F_ALLOW_OVERRIDE: If a sub-cgroup installs some bpf program,
1026  * the program in this cgroup yields to sub-cgroup program.
1027  *
1028  * BPF_F_ALLOW_MULTI: If a sub-cgroup installs some bpf program,
1029  * that cgroup program gets run in addition to the program in this cgroup.
1030  *
1031  * Only one program is allowed to be attached to a cgroup with
1032  * NONE or BPF_F_ALLOW_OVERRIDE flag.
1033  * Attaching another program on top of NONE or BPF_F_ALLOW_OVERRIDE will
1034  * release old program and attach the new one. Attach flags has to match.
1035  *
1036  * Multiple programs are allowed to be attached to a cgroup with
1037  * BPF_F_ALLOW_MULTI flag. They are executed in FIFO order
1038  * (those that were attached first, run first)
1039  * The programs of sub-cgroup are executed first, then programs of
1040  * this cgroup and then programs of parent cgroup.
1041  * When children program makes decision (like picking TCP CA or sock bind)
1042  * parent program has a chance to override it.
1043  *
1044  * With BPF_F_ALLOW_MULTI a new program is added to the end of the list of
1045  * programs for a cgroup. Though it's possible to replace an old program at
1046  * any position by also specifying BPF_F_REPLACE flag and position itself in
1047  * replace_bpf_fd attribute. Old program at this position will be released.
1048  *
1049  * A cgroup with MULTI or OVERRIDE flag allows any attach flags in sub-cgroups.
1050  * A cgroup with NONE doesn't allow any programs in sub-cgroups.
1051  * Ex1:
1052  * cgrp1 (MULTI progs A, B) ->
1053  *    cgrp2 (OVERRIDE prog C) ->
1054  *      cgrp3 (MULTI prog D) ->
1055  *        cgrp4 (OVERRIDE prog E) ->
1056  *          cgrp5 (NONE prog F)
1057  * the event in cgrp5 triggers execution of F,D,A,B in that order.
1058  * if prog F is detached, the execution is E,D,A,B
1059  * if prog F and D are detached, the execution is E,A,B
1060  * if prog F, E and D are detached, the execution is C,A,B
1061  *
1062  * All eligible programs are executed regardless of return code from
1063  * earlier programs.
1064  */
1065 #define BPF_F_ALLOW_OVERRIDE	(1U << 0)
1066 #define BPF_F_ALLOW_MULTI	(1U << 1)
1067 #define BPF_F_REPLACE		(1U << 2)
1068 
1069 /* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the
1070  * verifier will perform strict alignment checking as if the kernel
1071  * has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set,
1072  * and NET_IP_ALIGN defined to 2.
1073  */
1074 #define BPF_F_STRICT_ALIGNMENT	(1U << 0)
1075 
1076 /* If BPF_F_ANY_ALIGNMENT is used in BPF_PROF_LOAD command, the
1077  * verifier will allow any alignment whatsoever.  On platforms
1078  * with strict alignment requirements for loads ands stores (such
1079  * as sparc and mips) the verifier validates that all loads and
1080  * stores provably follow this requirement.  This flag turns that
1081  * checking and enforcement off.
1082  *
1083  * It is mostly used for testing when we want to validate the
1084  * context and memory access aspects of the verifier, but because
1085  * of an unaligned access the alignment check would trigger before
1086  * the one we are interested in.
1087  */
1088 #define BPF_F_ANY_ALIGNMENT	(1U << 1)
1089 
1090 /* BPF_F_TEST_RND_HI32 is used in BPF_PROG_LOAD command for testing purpose.
1091  * Verifier does sub-register def/use analysis and identifies instructions whose
1092  * def only matters for low 32-bit, high 32-bit is never referenced later
1093  * through implicit zero extension. Therefore verifier notifies JIT back-ends
1094  * that it is safe to ignore clearing high 32-bit for these instructions. This
1095  * saves some back-ends a lot of code-gen. However such optimization is not
1096  * necessary on some arches, for example x86_64, arm64 etc, whose JIT back-ends
1097  * hence hasn't used verifier's analysis result. But, we really want to have a
1098  * way to be able to verify the correctness of the described optimization on
1099  * x86_64 on which testsuites are frequently exercised.
1100  *
1101  * So, this flag is introduced. Once it is set, verifier will randomize high
1102  * 32-bit for those instructions who has been identified as safe to ignore them.
1103  * Then, if verifier is not doing correct analysis, such randomization will
1104  * regress tests to expose bugs.
1105  */
1106 #define BPF_F_TEST_RND_HI32	(1U << 2)
1107 
1108 /* The verifier internal test flag. Behavior is undefined */
1109 #define BPF_F_TEST_STATE_FREQ	(1U << 3)
1110 
1111 /* If BPF_F_SLEEPABLE is used in BPF_PROG_LOAD command, the verifier will
1112  * restrict map and helper usage for such programs. Sleepable BPF programs can
1113  * only be attached to hooks where kernel execution context allows sleeping.
1114  * Such programs are allowed to use helpers that may sleep like
1115  * bpf_copy_from_user().
1116  */
1117 #define BPF_F_SLEEPABLE		(1U << 4)
1118 
1119 /* If BPF_F_XDP_HAS_FRAGS is used in BPF_PROG_LOAD command, the loaded program
1120  * fully support xdp frags.
1121  */
1122 #define BPF_F_XDP_HAS_FRAGS	(1U << 5)
1123 
1124 /* link_create.kprobe_multi.flags used in LINK_CREATE command for
1125  * BPF_TRACE_KPROBE_MULTI attach type to create return probe.
1126  */
1127 #define BPF_F_KPROBE_MULTI_RETURN	(1U << 0)
1128 
1129 /* When BPF ldimm64's insn[0].src_reg != 0 then this can have
1130  * the following extensions:
1131  *
1132  * insn[0].src_reg:  BPF_PSEUDO_MAP_[FD|IDX]
1133  * insn[0].imm:      map fd or fd_idx
1134  * insn[1].imm:      0
1135  * insn[0].off:      0
1136  * insn[1].off:      0
1137  * ldimm64 rewrite:  address of map
1138  * verifier type:    CONST_PTR_TO_MAP
1139  */
1140 #define BPF_PSEUDO_MAP_FD	1
1141 #define BPF_PSEUDO_MAP_IDX	5
1142 
1143 /* insn[0].src_reg:  BPF_PSEUDO_MAP_[IDX_]VALUE
1144  * insn[0].imm:      map fd or fd_idx
1145  * insn[1].imm:      offset into value
1146  * insn[0].off:      0
1147  * insn[1].off:      0
1148  * ldimm64 rewrite:  address of map[0]+offset
1149  * verifier type:    PTR_TO_MAP_VALUE
1150  */
1151 #define BPF_PSEUDO_MAP_VALUE		2
1152 #define BPF_PSEUDO_MAP_IDX_VALUE	6
1153 
1154 /* insn[0].src_reg:  BPF_PSEUDO_BTF_ID
1155  * insn[0].imm:      kernel btd id of VAR
1156  * insn[1].imm:      0
1157  * insn[0].off:      0
1158  * insn[1].off:      0
1159  * ldimm64 rewrite:  address of the kernel variable
1160  * verifier type:    PTR_TO_BTF_ID or PTR_TO_MEM, depending on whether the var
1161  *                   is struct/union.
1162  */
1163 #define BPF_PSEUDO_BTF_ID	3
1164 /* insn[0].src_reg:  BPF_PSEUDO_FUNC
1165  * insn[0].imm:      insn offset to the func
1166  * insn[1].imm:      0
1167  * insn[0].off:      0
1168  * insn[1].off:      0
1169  * ldimm64 rewrite:  address of the function
1170  * verifier type:    PTR_TO_FUNC.
1171  */
1172 #define BPF_PSEUDO_FUNC		4
1173 
1174 /* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative
1175  * offset to another bpf function
1176  */
1177 #define BPF_PSEUDO_CALL		1
1178 /* when bpf_call->src_reg == BPF_PSEUDO_KFUNC_CALL,
1179  * bpf_call->imm == btf_id of a BTF_KIND_FUNC in the running kernel
1180  */
1181 #define BPF_PSEUDO_KFUNC_CALL	2
1182 
1183 /* flags for BPF_MAP_UPDATE_ELEM command */
1184 enum {
1185 	BPF_ANY		= 0, /* create new element or update existing */
1186 	BPF_NOEXIST	= 1, /* create new element if it didn't exist */
1187 	BPF_EXIST	= 2, /* update existing element */
1188 	BPF_F_LOCK	= 4, /* spin_lock-ed map_lookup/map_update */
1189 };
1190 
1191 /* flags for BPF_MAP_CREATE command */
1192 enum {
1193 	BPF_F_NO_PREALLOC	= (1U << 0),
1194 /* Instead of having one common LRU list in the
1195  * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list
1196  * which can scale and perform better.
1197  * Note, the LRU nodes (including free nodes) cannot be moved
1198  * across different LRU lists.
1199  */
1200 	BPF_F_NO_COMMON_LRU	= (1U << 1),
1201 /* Specify numa node during map creation */
1202 	BPF_F_NUMA_NODE		= (1U << 2),
1203 
1204 /* Flags for accessing BPF object from syscall side. */
1205 	BPF_F_RDONLY		= (1U << 3),
1206 	BPF_F_WRONLY		= (1U << 4),
1207 
1208 /* Flag for stack_map, store build_id+offset instead of pointer */
1209 	BPF_F_STACK_BUILD_ID	= (1U << 5),
1210 
1211 /* Zero-initialize hash function seed. This should only be used for testing. */
1212 	BPF_F_ZERO_SEED		= (1U << 6),
1213 
1214 /* Flags for accessing BPF object from program side. */
1215 	BPF_F_RDONLY_PROG	= (1U << 7),
1216 	BPF_F_WRONLY_PROG	= (1U << 8),
1217 
1218 /* Clone map from listener for newly accepted socket */
1219 	BPF_F_CLONE		= (1U << 9),
1220 
1221 /* Enable memory-mapping BPF map */
1222 	BPF_F_MMAPABLE		= (1U << 10),
1223 
1224 /* Share perf_event among processes */
1225 	BPF_F_PRESERVE_ELEMS	= (1U << 11),
1226 
1227 /* Create a map that is suitable to be an inner map with dynamic max entries */
1228 	BPF_F_INNER_MAP		= (1U << 12),
1229 };
1230 
1231 /* Flags for BPF_PROG_QUERY. */
1232 
1233 /* Query effective (directly attached + inherited from ancestor cgroups)
1234  * programs that will be executed for events within a cgroup.
1235  * attach_flags with this flag are returned only for directly attached programs.
1236  */
1237 #define BPF_F_QUERY_EFFECTIVE	(1U << 0)
1238 
1239 /* Flags for BPF_PROG_TEST_RUN */
1240 
1241 /* If set, run the test on the cpu specified by bpf_attr.test.cpu */
1242 #define BPF_F_TEST_RUN_ON_CPU	(1U << 0)
1243 /* If set, XDP frames will be transmitted after processing */
1244 #define BPF_F_TEST_XDP_LIVE_FRAMES	(1U << 1)
1245 
1246 /* type for BPF_ENABLE_STATS */
1247 enum bpf_stats_type {
1248 	/* enabled run_time_ns and run_cnt */
1249 	BPF_STATS_RUN_TIME = 0,
1250 };
1251 
1252 enum bpf_stack_build_id_status {
1253 	/* user space need an empty entry to identify end of a trace */
1254 	BPF_STACK_BUILD_ID_EMPTY = 0,
1255 	/* with valid build_id and offset */
1256 	BPF_STACK_BUILD_ID_VALID = 1,
1257 	/* couldn't get build_id, fallback to ip */
1258 	BPF_STACK_BUILD_ID_IP = 2,
1259 };
1260 
1261 #define BPF_BUILD_ID_SIZE 20
1262 struct bpf_stack_build_id {
1263 	__s32		status;
1264 	unsigned char	build_id[BPF_BUILD_ID_SIZE];
1265 	union {
1266 		__u64	offset;
1267 		__u64	ip;
1268 	};
1269 };
1270 
1271 #define BPF_OBJ_NAME_LEN 16U
1272 
1273 union bpf_attr {
1274 	struct { /* anonymous struct used by BPF_MAP_CREATE command */
1275 		__u32	map_type;	/* one of enum bpf_map_type */
1276 		__u32	key_size;	/* size of key in bytes */
1277 		__u32	value_size;	/* size of value in bytes */
1278 		__u32	max_entries;	/* max number of entries in a map */
1279 		__u32	map_flags;	/* BPF_MAP_CREATE related
1280 					 * flags defined above.
1281 					 */
1282 		__u32	inner_map_fd;	/* fd pointing to the inner map */
1283 		__u32	numa_node;	/* numa node (effective only if
1284 					 * BPF_F_NUMA_NODE is set).
1285 					 */
1286 		char	map_name[BPF_OBJ_NAME_LEN];
1287 		__u32	map_ifindex;	/* ifindex of netdev to create on */
1288 		__u32	btf_fd;		/* fd pointing to a BTF type data */
1289 		__u32	btf_key_type_id;	/* BTF type_id of the key */
1290 		__u32	btf_value_type_id;	/* BTF type_id of the value */
1291 		__u32	btf_vmlinux_value_type_id;/* BTF type_id of a kernel-
1292 						   * struct stored as the
1293 						   * map value
1294 						   */
1295 		/* Any per-map-type extra fields
1296 		 *
1297 		 * BPF_MAP_TYPE_BLOOM_FILTER - the lowest 4 bits indicate the
1298 		 * number of hash functions (if 0, the bloom filter will default
1299 		 * to using 5 hash functions).
1300 		 */
1301 		__u64	map_extra;
1302 	};
1303 
1304 	struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
1305 		__u32		map_fd;
1306 		__aligned_u64	key;
1307 		union {
1308 			__aligned_u64 value;
1309 			__aligned_u64 next_key;
1310 		};
1311 		__u64		flags;
1312 	};
1313 
1314 	struct { /* struct used by BPF_MAP_*_BATCH commands */
1315 		__aligned_u64	in_batch;	/* start batch,
1316 						 * NULL to start from beginning
1317 						 */
1318 		__aligned_u64	out_batch;	/* output: next start batch */
1319 		__aligned_u64	keys;
1320 		__aligned_u64	values;
1321 		__u32		count;		/* input/output:
1322 						 * input: # of key/value
1323 						 * elements
1324 						 * output: # of filled elements
1325 						 */
1326 		__u32		map_fd;
1327 		__u64		elem_flags;
1328 		__u64		flags;
1329 	} batch;
1330 
1331 	struct { /* anonymous struct used by BPF_PROG_LOAD command */
1332 		__u32		prog_type;	/* one of enum bpf_prog_type */
1333 		__u32		insn_cnt;
1334 		__aligned_u64	insns;
1335 		__aligned_u64	license;
1336 		__u32		log_level;	/* verbosity level of verifier */
1337 		__u32		log_size;	/* size of user buffer */
1338 		__aligned_u64	log_buf;	/* user supplied buffer */
1339 		__u32		kern_version;	/* not used */
1340 		__u32		prog_flags;
1341 		char		prog_name[BPF_OBJ_NAME_LEN];
1342 		__u32		prog_ifindex;	/* ifindex of netdev to prep for */
1343 		/* For some prog types expected attach type must be known at
1344 		 * load time to verify attach type specific parts of prog
1345 		 * (context accesses, allowed helpers, etc).
1346 		 */
1347 		__u32		expected_attach_type;
1348 		__u32		prog_btf_fd;	/* fd pointing to BTF type data */
1349 		__u32		func_info_rec_size;	/* userspace bpf_func_info size */
1350 		__aligned_u64	func_info;	/* func info */
1351 		__u32		func_info_cnt;	/* number of bpf_func_info records */
1352 		__u32		line_info_rec_size;	/* userspace bpf_line_info size */
1353 		__aligned_u64	line_info;	/* line info */
1354 		__u32		line_info_cnt;	/* number of bpf_line_info records */
1355 		__u32		attach_btf_id;	/* in-kernel BTF type id to attach to */
1356 		union {
1357 			/* valid prog_fd to attach to bpf prog */
1358 			__u32		attach_prog_fd;
1359 			/* or valid module BTF object fd or 0 to attach to vmlinux */
1360 			__u32		attach_btf_obj_fd;
1361 		};
1362 		__u32		core_relo_cnt;	/* number of bpf_core_relo */
1363 		__aligned_u64	fd_array;	/* array of FDs */
1364 		__aligned_u64	core_relos;
1365 		__u32		core_relo_rec_size; /* sizeof(struct bpf_core_relo) */
1366 	};
1367 
1368 	struct { /* anonymous struct used by BPF_OBJ_* commands */
1369 		__aligned_u64	pathname;
1370 		__u32		bpf_fd;
1371 		__u32		file_flags;
1372 	};
1373 
1374 	struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
1375 		__u32		target_fd;	/* container object to attach to */
1376 		__u32		attach_bpf_fd;	/* eBPF program to attach */
1377 		__u32		attach_type;
1378 		__u32		attach_flags;
1379 		__u32		replace_bpf_fd;	/* previously attached eBPF
1380 						 * program to replace if
1381 						 * BPF_F_REPLACE is used
1382 						 */
1383 	};
1384 
1385 	struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
1386 		__u32		prog_fd;
1387 		__u32		retval;
1388 		__u32		data_size_in;	/* input: len of data_in */
1389 		__u32		data_size_out;	/* input/output: len of data_out
1390 						 *   returns ENOSPC if data_out
1391 						 *   is too small.
1392 						 */
1393 		__aligned_u64	data_in;
1394 		__aligned_u64	data_out;
1395 		__u32		repeat;
1396 		__u32		duration;
1397 		__u32		ctx_size_in;	/* input: len of ctx_in */
1398 		__u32		ctx_size_out;	/* input/output: len of ctx_out
1399 						 *   returns ENOSPC if ctx_out
1400 						 *   is too small.
1401 						 */
1402 		__aligned_u64	ctx_in;
1403 		__aligned_u64	ctx_out;
1404 		__u32		flags;
1405 		__u32		cpu;
1406 		__u32		batch_size;
1407 	} test;
1408 
1409 	struct { /* anonymous struct used by BPF_*_GET_*_ID */
1410 		union {
1411 			__u32		start_id;
1412 			__u32		prog_id;
1413 			__u32		map_id;
1414 			__u32		btf_id;
1415 			__u32		link_id;
1416 		};
1417 		__u32		next_id;
1418 		__u32		open_flags;
1419 	};
1420 
1421 	struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
1422 		__u32		bpf_fd;
1423 		__u32		info_len;
1424 		__aligned_u64	info;
1425 	} info;
1426 
1427 	struct { /* anonymous struct used by BPF_PROG_QUERY command */
1428 		__u32		target_fd;	/* container object to query */
1429 		__u32		attach_type;
1430 		__u32		query_flags;
1431 		__u32		attach_flags;
1432 		__aligned_u64	prog_ids;
1433 		__u32		prog_cnt;
1434 	} query;
1435 
1436 	struct { /* anonymous struct used by BPF_RAW_TRACEPOINT_OPEN command */
1437 		__u64 name;
1438 		__u32 prog_fd;
1439 	} raw_tracepoint;
1440 
1441 	struct { /* anonymous struct for BPF_BTF_LOAD */
1442 		__aligned_u64	btf;
1443 		__aligned_u64	btf_log_buf;
1444 		__u32		btf_size;
1445 		__u32		btf_log_size;
1446 		__u32		btf_log_level;
1447 	};
1448 
1449 	struct {
1450 		__u32		pid;		/* input: pid */
1451 		__u32		fd;		/* input: fd */
1452 		__u32		flags;		/* input: flags */
1453 		__u32		buf_len;	/* input/output: buf len */
1454 		__aligned_u64	buf;		/* input/output:
1455 						 *   tp_name for tracepoint
1456 						 *   symbol for kprobe
1457 						 *   filename for uprobe
1458 						 */
1459 		__u32		prog_id;	/* output: prod_id */
1460 		__u32		fd_type;	/* output: BPF_FD_TYPE_* */
1461 		__u64		probe_offset;	/* output: probe_offset */
1462 		__u64		probe_addr;	/* output: probe_addr */
1463 	} task_fd_query;
1464 
1465 	struct { /* struct used by BPF_LINK_CREATE command */
1466 		__u32		prog_fd;	/* eBPF program to attach */
1467 		union {
1468 			__u32		target_fd;	/* object to attach to */
1469 			__u32		target_ifindex; /* target ifindex */
1470 		};
1471 		__u32		attach_type;	/* attach type */
1472 		__u32		flags;		/* extra flags */
1473 		union {
1474 			__u32		target_btf_id;	/* btf_id of target to attach to */
1475 			struct {
1476 				__aligned_u64	iter_info;	/* extra bpf_iter_link_info */
1477 				__u32		iter_info_len;	/* iter_info length */
1478 			};
1479 			struct {
1480 				/* black box user-provided value passed through
1481 				 * to BPF program at the execution time and
1482 				 * accessible through bpf_get_attach_cookie() BPF helper
1483 				 */
1484 				__u64		bpf_cookie;
1485 			} perf_event;
1486 			struct {
1487 				__u32		flags;
1488 				__u32		cnt;
1489 				__aligned_u64	syms;
1490 				__aligned_u64	addrs;
1491 				__aligned_u64	cookies;
1492 			} kprobe_multi;
1493 		};
1494 	} link_create;
1495 
1496 	struct { /* struct used by BPF_LINK_UPDATE command */
1497 		__u32		link_fd;	/* link fd */
1498 		/* new program fd to update link with */
1499 		__u32		new_prog_fd;
1500 		__u32		flags;		/* extra flags */
1501 		/* expected link's program fd; is specified only if
1502 		 * BPF_F_REPLACE flag is set in flags */
1503 		__u32		old_prog_fd;
1504 	} link_update;
1505 
1506 	struct {
1507 		__u32		link_fd;
1508 	} link_detach;
1509 
1510 	struct { /* struct used by BPF_ENABLE_STATS command */
1511 		__u32		type;
1512 	} enable_stats;
1513 
1514 	struct { /* struct used by BPF_ITER_CREATE command */
1515 		__u32		link_fd;
1516 		__u32		flags;
1517 	} iter_create;
1518 
1519 	struct { /* struct used by BPF_PROG_BIND_MAP command */
1520 		__u32		prog_fd;
1521 		__u32		map_fd;
1522 		__u32		flags;		/* extra flags */
1523 	} prog_bind_map;
1524 
1525 } __attribute__((aligned(8)));
1526 
1527 /* The description below is an attempt at providing documentation to eBPF
1528  * developers about the multiple available eBPF helper functions. It can be
1529  * parsed and used to produce a manual page. The workflow is the following,
1530  * and requires the rst2man utility:
1531  *
1532  *     $ ./scripts/bpf_doc.py \
1533  *             --filename include/uapi/linux/bpf.h > /tmp/bpf-helpers.rst
1534  *     $ rst2man /tmp/bpf-helpers.rst > /tmp/bpf-helpers.7
1535  *     $ man /tmp/bpf-helpers.7
1536  *
1537  * Note that in order to produce this external documentation, some RST
1538  * formatting is used in the descriptions to get "bold" and "italics" in
1539  * manual pages. Also note that the few trailing white spaces are
1540  * intentional, removing them would break paragraphs for rst2man.
1541  *
1542  * Start of BPF helper function descriptions:
1543  *
1544  * void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)
1545  * 	Description
1546  * 		Perform a lookup in *map* for an entry associated to *key*.
1547  * 	Return
1548  * 		Map value associated to *key*, or **NULL** if no entry was
1549  * 		found.
1550  *
1551  * long bpf_map_update_elem(struct bpf_map *map, const void *key, const void *value, u64 flags)
1552  * 	Description
1553  * 		Add or update the value of the entry associated to *key* in
1554  * 		*map* with *value*. *flags* is one of:
1555  *
1556  * 		**BPF_NOEXIST**
1557  * 			The entry for *key* must not exist in the map.
1558  * 		**BPF_EXIST**
1559  * 			The entry for *key* must already exist in the map.
1560  * 		**BPF_ANY**
1561  * 			No condition on the existence of the entry for *key*.
1562  *
1563  * 		Flag value **BPF_NOEXIST** cannot be used for maps of types
1564  * 		**BPF_MAP_TYPE_ARRAY** or **BPF_MAP_TYPE_PERCPU_ARRAY**  (all
1565  * 		elements always exist), the helper would return an error.
1566  * 	Return
1567  * 		0 on success, or a negative error in case of failure.
1568  *
1569  * long bpf_map_delete_elem(struct bpf_map *map, const void *key)
1570  * 	Description
1571  * 		Delete entry with *key* from *map*.
1572  * 	Return
1573  * 		0 on success, or a negative error in case of failure.
1574  *
1575  * long bpf_probe_read(void *dst, u32 size, const void *unsafe_ptr)
1576  * 	Description
1577  * 		For tracing programs, safely attempt to read *size* bytes from
1578  * 		kernel space address *unsafe_ptr* and store the data in *dst*.
1579  *
1580  * 		Generally, use **bpf_probe_read_user**\ () or
1581  * 		**bpf_probe_read_kernel**\ () instead.
1582  * 	Return
1583  * 		0 on success, or a negative error in case of failure.
1584  *
1585  * u64 bpf_ktime_get_ns(void)
1586  * 	Description
1587  * 		Return the time elapsed since system boot, in nanoseconds.
1588  * 		Does not include time the system was suspended.
1589  * 		See: **clock_gettime**\ (**CLOCK_MONOTONIC**)
1590  * 	Return
1591  * 		Current *ktime*.
1592  *
1593  * long bpf_trace_printk(const char *fmt, u32 fmt_size, ...)
1594  * 	Description
1595  * 		This helper is a "printk()-like" facility for debugging. It
1596  * 		prints a message defined by format *fmt* (of size *fmt_size*)
1597  * 		to file *\/sys/kernel/debug/tracing/trace* from DebugFS, if
1598  * 		available. It can take up to three additional **u64**
1599  * 		arguments (as an eBPF helpers, the total number of arguments is
1600  * 		limited to five).
1601  *
1602  * 		Each time the helper is called, it appends a line to the trace.
1603  * 		Lines are discarded while *\/sys/kernel/debug/tracing/trace* is
1604  * 		open, use *\/sys/kernel/debug/tracing/trace_pipe* to avoid this.
1605  * 		The format of the trace is customizable, and the exact output
1606  * 		one will get depends on the options set in
1607  * 		*\/sys/kernel/debug/tracing/trace_options* (see also the
1608  * 		*README* file under the same directory). However, it usually
1609  * 		defaults to something like:
1610  *
1611  * 		::
1612  *
1613  * 			telnet-470   [001] .N.. 419421.045894: 0x00000001: <formatted msg>
1614  *
1615  * 		In the above:
1616  *
1617  * 			* ``telnet`` is the name of the current task.
1618  * 			* ``470`` is the PID of the current task.
1619  * 			* ``001`` is the CPU number on which the task is
1620  * 			  running.
1621  * 			* In ``.N..``, each character refers to a set of
1622  * 			  options (whether irqs are enabled, scheduling
1623  * 			  options, whether hard/softirqs are running, level of
1624  * 			  preempt_disabled respectively). **N** means that
1625  * 			  **TIF_NEED_RESCHED** and **PREEMPT_NEED_RESCHED**
1626  * 			  are set.
1627  * 			* ``419421.045894`` is a timestamp.
1628  * 			* ``0x00000001`` is a fake value used by BPF for the
1629  * 			  instruction pointer register.
1630  * 			* ``<formatted msg>`` is the message formatted with
1631  * 			  *fmt*.
1632  *
1633  * 		The conversion specifiers supported by *fmt* are similar, but
1634  * 		more limited than for printk(). They are **%d**, **%i**,
1635  * 		**%u**, **%x**, **%ld**, **%li**, **%lu**, **%lx**, **%lld**,
1636  * 		**%lli**, **%llu**, **%llx**, **%p**, **%s**. No modifier (size
1637  * 		of field, padding with zeroes, etc.) is available, and the
1638  * 		helper will return **-EINVAL** (but print nothing) if it
1639  * 		encounters an unknown specifier.
1640  *
1641  * 		Also, note that **bpf_trace_printk**\ () is slow, and should
1642  * 		only be used for debugging purposes. For this reason, a notice
1643  * 		block (spanning several lines) is printed to kernel logs and
1644  * 		states that the helper should not be used "for production use"
1645  * 		the first time this helper is used (or more precisely, when
1646  * 		**trace_printk**\ () buffers are allocated). For passing values
1647  * 		to user space, perf events should be preferred.
1648  * 	Return
1649  * 		The number of bytes written to the buffer, or a negative error
1650  * 		in case of failure.
1651  *
1652  * u32 bpf_get_prandom_u32(void)
1653  * 	Description
1654  * 		Get a pseudo-random number.
1655  *
1656  * 		From a security point of view, this helper uses its own
1657  * 		pseudo-random internal state, and cannot be used to infer the
1658  * 		seed of other random functions in the kernel. However, it is
1659  * 		essential to note that the generator used by the helper is not
1660  * 		cryptographically secure.
1661  * 	Return
1662  * 		A random 32-bit unsigned value.
1663  *
1664  * u32 bpf_get_smp_processor_id(void)
1665  * 	Description
1666  * 		Get the SMP (symmetric multiprocessing) processor id. Note that
1667  * 		all programs run with migration disabled, which means that the
1668  * 		SMP processor id is stable during all the execution of the
1669  * 		program.
1670  * 	Return
1671  * 		The SMP id of the processor running the program.
1672  *
1673  * long bpf_skb_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len, u64 flags)
1674  * 	Description
1675  * 		Store *len* bytes from address *from* into the packet
1676  * 		associated to *skb*, at *offset*. *flags* are a combination of
1677  * 		**BPF_F_RECOMPUTE_CSUM** (automatically recompute the
1678  * 		checksum for the packet after storing the bytes) and
1679  * 		**BPF_F_INVALIDATE_HASH** (set *skb*\ **->hash**, *skb*\
1680  * 		**->swhash** and *skb*\ **->l4hash** to 0).
1681  *
1682  * 		A call to this helper is susceptible to change the underlying
1683  * 		packet buffer. Therefore, at load time, all checks on pointers
1684  * 		previously done by the verifier are invalidated and must be
1685  * 		performed again, if the helper is used in combination with
1686  * 		direct packet access.
1687  * 	Return
1688  * 		0 on success, or a negative error in case of failure.
1689  *
1690  * long bpf_l3_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 size)
1691  * 	Description
1692  * 		Recompute the layer 3 (e.g. IP) checksum for the packet
1693  * 		associated to *skb*. Computation is incremental, so the helper
1694  * 		must know the former value of the header field that was
1695  * 		modified (*from*), the new value of this field (*to*), and the
1696  * 		number of bytes (2 or 4) for this field, stored in *size*.
1697  * 		Alternatively, it is possible to store the difference between
1698  * 		the previous and the new values of the header field in *to*, by
1699  * 		setting *from* and *size* to 0. For both methods, *offset*
1700  * 		indicates the location of the IP checksum within the packet.
1701  *
1702  * 		This helper works in combination with **bpf_csum_diff**\ (),
1703  * 		which does not update the checksum in-place, but offers more
1704  * 		flexibility and can handle sizes larger than 2 or 4 for the
1705  * 		checksum to update.
1706  *
1707  * 		A call to this helper is susceptible to change the underlying
1708  * 		packet buffer. Therefore, at load time, all checks on pointers
1709  * 		previously done by the verifier are invalidated and must be
1710  * 		performed again, if the helper is used in combination with
1711  * 		direct packet access.
1712  * 	Return
1713  * 		0 on success, or a negative error in case of failure.
1714  *
1715  * long bpf_l4_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 flags)
1716  * 	Description
1717  * 		Recompute the layer 4 (e.g. TCP, UDP or ICMP) checksum for the
1718  * 		packet associated to *skb*. Computation is incremental, so the
1719  * 		helper must know the former value of the header field that was
1720  * 		modified (*from*), the new value of this field (*to*), and the
1721  * 		number of bytes (2 or 4) for this field, stored on the lowest
1722  * 		four bits of *flags*. Alternatively, it is possible to store
1723  * 		the difference between the previous and the new values of the
1724  * 		header field in *to*, by setting *from* and the four lowest
1725  * 		bits of *flags* to 0. For both methods, *offset* indicates the
1726  * 		location of the IP checksum within the packet. In addition to
1727  * 		the size of the field, *flags* can be added (bitwise OR) actual
1728  * 		flags. With **BPF_F_MARK_MANGLED_0**, a null checksum is left
1729  * 		untouched (unless **BPF_F_MARK_ENFORCE** is added as well), and
1730  * 		for updates resulting in a null checksum the value is set to
1731  * 		**CSUM_MANGLED_0** instead. Flag **BPF_F_PSEUDO_HDR** indicates
1732  * 		the checksum is to be computed against a pseudo-header.
1733  *
1734  * 		This helper works in combination with **bpf_csum_diff**\ (),
1735  * 		which does not update the checksum in-place, but offers more
1736  * 		flexibility and can handle sizes larger than 2 or 4 for the
1737  * 		checksum to update.
1738  *
1739  * 		A call to this helper is susceptible to change the underlying
1740  * 		packet buffer. Therefore, at load time, all checks on pointers
1741  * 		previously done by the verifier are invalidated and must be
1742  * 		performed again, if the helper is used in combination with
1743  * 		direct packet access.
1744  * 	Return
1745  * 		0 on success, or a negative error in case of failure.
1746  *
1747  * long bpf_tail_call(void *ctx, struct bpf_map *prog_array_map, u32 index)
1748  * 	Description
1749  * 		This special helper is used to trigger a "tail call", or in
1750  * 		other words, to jump into another eBPF program. The same stack
1751  * 		frame is used (but values on stack and in registers for the
1752  * 		caller are not accessible to the callee). This mechanism allows
1753  * 		for program chaining, either for raising the maximum number of
1754  * 		available eBPF instructions, or to execute given programs in
1755  * 		conditional blocks. For security reasons, there is an upper
1756  * 		limit to the number of successive tail calls that can be
1757  * 		performed.
1758  *
1759  * 		Upon call of this helper, the program attempts to jump into a
1760  * 		program referenced at index *index* in *prog_array_map*, a
1761  * 		special map of type **BPF_MAP_TYPE_PROG_ARRAY**, and passes
1762  * 		*ctx*, a pointer to the context.
1763  *
1764  * 		If the call succeeds, the kernel immediately runs the first
1765  * 		instruction of the new program. This is not a function call,
1766  * 		and it never returns to the previous program. If the call
1767  * 		fails, then the helper has no effect, and the caller continues
1768  * 		to run its subsequent instructions. A call can fail if the
1769  * 		destination program for the jump does not exist (i.e. *index*
1770  * 		is superior to the number of entries in *prog_array_map*), or
1771  * 		if the maximum number of tail calls has been reached for this
1772  * 		chain of programs. This limit is defined in the kernel by the
1773  * 		macro **MAX_TAIL_CALL_CNT** (not accessible to user space),
1774  *		which is currently set to 33.
1775  * 	Return
1776  * 		0 on success, or a negative error in case of failure.
1777  *
1778  * long bpf_clone_redirect(struct sk_buff *skb, u32 ifindex, u64 flags)
1779  * 	Description
1780  * 		Clone and redirect the packet associated to *skb* to another
1781  * 		net device of index *ifindex*. Both ingress and egress
1782  * 		interfaces can be used for redirection. The **BPF_F_INGRESS**
1783  * 		value in *flags* is used to make the distinction (ingress path
1784  * 		is selected if the flag is present, egress path otherwise).
1785  * 		This is the only flag supported for now.
1786  *
1787  * 		In comparison with **bpf_redirect**\ () helper,
1788  * 		**bpf_clone_redirect**\ () has the associated cost of
1789  * 		duplicating the packet buffer, but this can be executed out of
1790  * 		the eBPF program. Conversely, **bpf_redirect**\ () is more
1791  * 		efficient, but it is handled through an action code where the
1792  * 		redirection happens only after the eBPF program has returned.
1793  *
1794  * 		A call to this helper is susceptible to change the underlying
1795  * 		packet buffer. Therefore, at load time, all checks on pointers
1796  * 		previously done by the verifier are invalidated and must be
1797  * 		performed again, if the helper is used in combination with
1798  * 		direct packet access.
1799  * 	Return
1800  * 		0 on success, or a negative error in case of failure.
1801  *
1802  * u64 bpf_get_current_pid_tgid(void)
1803  * 	Description
1804  * 		Get the current pid and tgid.
1805  * 	Return
1806  * 		A 64-bit integer containing the current tgid and pid, and
1807  * 		created as such:
1808  * 		*current_task*\ **->tgid << 32 \|**
1809  * 		*current_task*\ **->pid**.
1810  *
1811  * u64 bpf_get_current_uid_gid(void)
1812  * 	Description
1813  * 		Get the current uid and gid.
1814  * 	Return
1815  * 		A 64-bit integer containing the current GID and UID, and
1816  * 		created as such: *current_gid* **<< 32 \|** *current_uid*.
1817  *
1818  * long bpf_get_current_comm(void *buf, u32 size_of_buf)
1819  * 	Description
1820  * 		Copy the **comm** attribute of the current task into *buf* of
1821  * 		*size_of_buf*. The **comm** attribute contains the name of
1822  * 		the executable (excluding the path) for the current task. The
1823  * 		*size_of_buf* must be strictly positive. On success, the
1824  * 		helper makes sure that the *buf* is NUL-terminated. On failure,
1825  * 		it is filled with zeroes.
1826  * 	Return
1827  * 		0 on success, or a negative error in case of failure.
1828  *
1829  * u32 bpf_get_cgroup_classid(struct sk_buff *skb)
1830  * 	Description
1831  * 		Retrieve the classid for the current task, i.e. for the net_cls
1832  * 		cgroup to which *skb* belongs.
1833  *
1834  * 		This helper can be used on TC egress path, but not on ingress.
1835  *
1836  * 		The net_cls cgroup provides an interface to tag network packets
1837  * 		based on a user-provided identifier for all traffic coming from
1838  * 		the tasks belonging to the related cgroup. See also the related
1839  * 		kernel documentation, available from the Linux sources in file
1840  * 		*Documentation/admin-guide/cgroup-v1/net_cls.rst*.
1841  *
1842  * 		The Linux kernel has two versions for cgroups: there are
1843  * 		cgroups v1 and cgroups v2. Both are available to users, who can
1844  * 		use a mixture of them, but note that the net_cls cgroup is for
1845  * 		cgroup v1 only. This makes it incompatible with BPF programs
1846  * 		run on cgroups, which is a cgroup-v2-only feature (a socket can
1847  * 		only hold data for one version of cgroups at a time).
1848  *
1849  * 		This helper is only available is the kernel was compiled with
1850  * 		the **CONFIG_CGROUP_NET_CLASSID** configuration option set to
1851  * 		"**y**" or to "**m**".
1852  * 	Return
1853  * 		The classid, or 0 for the default unconfigured classid.
1854  *
1855  * long bpf_skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)
1856  * 	Description
1857  * 		Push a *vlan_tci* (VLAN tag control information) of protocol
1858  * 		*vlan_proto* to the packet associated to *skb*, then update
1859  * 		the checksum. Note that if *vlan_proto* is different from
1860  * 		**ETH_P_8021Q** and **ETH_P_8021AD**, it is considered to
1861  * 		be **ETH_P_8021Q**.
1862  *
1863  * 		A call to this helper is susceptible to change the underlying
1864  * 		packet buffer. Therefore, at load time, all checks on pointers
1865  * 		previously done by the verifier are invalidated and must be
1866  * 		performed again, if the helper is used in combination with
1867  * 		direct packet access.
1868  * 	Return
1869  * 		0 on success, or a negative error in case of failure.
1870  *
1871  * long bpf_skb_vlan_pop(struct sk_buff *skb)
1872  * 	Description
1873  * 		Pop a VLAN header from the packet associated to *skb*.
1874  *
1875  * 		A call to this helper is susceptible to change the underlying
1876  * 		packet buffer. Therefore, at load time, all checks on pointers
1877  * 		previously done by the verifier are invalidated and must be
1878  * 		performed again, if the helper is used in combination with
1879  * 		direct packet access.
1880  * 	Return
1881  * 		0 on success, or a negative error in case of failure.
1882  *
1883  * long bpf_skb_get_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
1884  * 	Description
1885  * 		Get tunnel metadata. This helper takes a pointer *key* to an
1886  * 		empty **struct bpf_tunnel_key** of **size**, that will be
1887  * 		filled with tunnel metadata for the packet associated to *skb*.
1888  * 		The *flags* can be set to **BPF_F_TUNINFO_IPV6**, which
1889  * 		indicates that the tunnel is based on IPv6 protocol instead of
1890  * 		IPv4.
1891  *
1892  * 		The **struct bpf_tunnel_key** is an object that generalizes the
1893  * 		principal parameters used by various tunneling protocols into a
1894  * 		single struct. This way, it can be used to easily make a
1895  * 		decision based on the contents of the encapsulation header,
1896  * 		"summarized" in this struct. In particular, it holds the IP
1897  * 		address of the remote end (IPv4 or IPv6, depending on the case)
1898  * 		in *key*\ **->remote_ipv4** or *key*\ **->remote_ipv6**. Also,
1899  * 		this struct exposes the *key*\ **->tunnel_id**, which is
1900  * 		generally mapped to a VNI (Virtual Network Identifier), making
1901  * 		it programmable together with the **bpf_skb_set_tunnel_key**\
1902  * 		() helper.
1903  *
1904  * 		Let's imagine that the following code is part of a program
1905  * 		attached to the TC ingress interface, on one end of a GRE
1906  * 		tunnel, and is supposed to filter out all messages coming from
1907  * 		remote ends with IPv4 address other than 10.0.0.1:
1908  *
1909  * 		::
1910  *
1911  * 			int ret;
1912  * 			struct bpf_tunnel_key key = {};
1913  *
1914  * 			ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
1915  * 			if (ret < 0)
1916  * 				return TC_ACT_SHOT;	// drop packet
1917  *
1918  * 			if (key.remote_ipv4 != 0x0a000001)
1919  * 				return TC_ACT_SHOT;	// drop packet
1920  *
1921  * 			return TC_ACT_OK;		// accept packet
1922  *
1923  * 		This interface can also be used with all encapsulation devices
1924  * 		that can operate in "collect metadata" mode: instead of having
1925  * 		one network device per specific configuration, the "collect
1926  * 		metadata" mode only requires a single device where the
1927  * 		configuration can be extracted from this helper.
1928  *
1929  * 		This can be used together with various tunnels such as VXLan,
1930  * 		Geneve, GRE or IP in IP (IPIP).
1931  * 	Return
1932  * 		0 on success, or a negative error in case of failure.
1933  *
1934  * long bpf_skb_set_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
1935  * 	Description
1936  * 		Populate tunnel metadata for packet associated to *skb.* The
1937  * 		tunnel metadata is set to the contents of *key*, of *size*. The
1938  * 		*flags* can be set to a combination of the following values:
1939  *
1940  * 		**BPF_F_TUNINFO_IPV6**
1941  * 			Indicate that the tunnel is based on IPv6 protocol
1942  * 			instead of IPv4.
1943  * 		**BPF_F_ZERO_CSUM_TX**
1944  * 			For IPv4 packets, add a flag to tunnel metadata
1945  * 			indicating that checksum computation should be skipped
1946  * 			and checksum set to zeroes.
1947  * 		**BPF_F_DONT_FRAGMENT**
1948  * 			Add a flag to tunnel metadata indicating that the
1949  * 			packet should not be fragmented.
1950  * 		**BPF_F_SEQ_NUMBER**
1951  * 			Add a flag to tunnel metadata indicating that a
1952  * 			sequence number should be added to tunnel header before
1953  * 			sending the packet. This flag was added for GRE
1954  * 			encapsulation, but might be used with other protocols
1955  * 			as well in the future.
1956  *
1957  * 		Here is a typical usage on the transmit path:
1958  *
1959  * 		::
1960  *
1961  * 			struct bpf_tunnel_key key;
1962  * 			     populate key ...
1963  * 			bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0);
1964  * 			bpf_clone_redirect(skb, vxlan_dev_ifindex, 0);
1965  *
1966  * 		See also the description of the **bpf_skb_get_tunnel_key**\ ()
1967  * 		helper for additional information.
1968  * 	Return
1969  * 		0 on success, or a negative error in case of failure.
1970  *
1971  * u64 bpf_perf_event_read(struct bpf_map *map, u64 flags)
1972  * 	Description
1973  * 		Read the value of a perf event counter. This helper relies on a
1974  * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of
1975  * 		the perf event counter is selected when *map* is updated with
1976  * 		perf event file descriptors. The *map* is an array whose size
1977  * 		is the number of available CPUs, and each cell contains a value
1978  * 		relative to one CPU. The value to retrieve is indicated by
1979  * 		*flags*, that contains the index of the CPU to look up, masked
1980  * 		with **BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
1981  * 		**BPF_F_CURRENT_CPU** to indicate that the value for the
1982  * 		current CPU should be retrieved.
1983  *
1984  * 		Note that before Linux 4.13, only hardware perf event can be
1985  * 		retrieved.
1986  *
1987  * 		Also, be aware that the newer helper
1988  * 		**bpf_perf_event_read_value**\ () is recommended over
1989  * 		**bpf_perf_event_read**\ () in general. The latter has some ABI
1990  * 		quirks where error and counter value are used as a return code
1991  * 		(which is wrong to do since ranges may overlap). This issue is
1992  * 		fixed with **bpf_perf_event_read_value**\ (), which at the same
1993  * 		time provides more features over the **bpf_perf_event_read**\
1994  * 		() interface. Please refer to the description of
1995  * 		**bpf_perf_event_read_value**\ () for details.
1996  * 	Return
1997  * 		The value of the perf event counter read from the map, or a
1998  * 		negative error code in case of failure.
1999  *
2000  * long bpf_redirect(u32 ifindex, u64 flags)
2001  * 	Description
2002  * 		Redirect the packet to another net device of index *ifindex*.
2003  * 		This helper is somewhat similar to **bpf_clone_redirect**\
2004  * 		(), except that the packet is not cloned, which provides
2005  * 		increased performance.
2006  *
2007  * 		Except for XDP, both ingress and egress interfaces can be used
2008  * 		for redirection. The **BPF_F_INGRESS** value in *flags* is used
2009  * 		to make the distinction (ingress path is selected if the flag
2010  * 		is present, egress path otherwise). Currently, XDP only
2011  * 		supports redirection to the egress interface, and accepts no
2012  * 		flag at all.
2013  *
2014  * 		The same effect can also be attained with the more generic
2015  * 		**bpf_redirect_map**\ (), which uses a BPF map to store the
2016  * 		redirect target instead of providing it directly to the helper.
2017  * 	Return
2018  * 		For XDP, the helper returns **XDP_REDIRECT** on success or
2019  * 		**XDP_ABORTED** on error. For other program types, the values
2020  * 		are **TC_ACT_REDIRECT** on success or **TC_ACT_SHOT** on
2021  * 		error.
2022  *
2023  * u32 bpf_get_route_realm(struct sk_buff *skb)
2024  * 	Description
2025  * 		Retrieve the realm or the route, that is to say the
2026  * 		**tclassid** field of the destination for the *skb*. The
2027  * 		identifier retrieved is a user-provided tag, similar to the
2028  * 		one used with the net_cls cgroup (see description for
2029  * 		**bpf_get_cgroup_classid**\ () helper), but here this tag is
2030  * 		held by a route (a destination entry), not by a task.
2031  *
2032  * 		Retrieving this identifier works with the clsact TC egress hook
2033  * 		(see also **tc-bpf(8)**), or alternatively on conventional
2034  * 		classful egress qdiscs, but not on TC ingress path. In case of
2035  * 		clsact TC egress hook, this has the advantage that, internally,
2036  * 		the destination entry has not been dropped yet in the transmit
2037  * 		path. Therefore, the destination entry does not need to be
2038  * 		artificially held via **netif_keep_dst**\ () for a classful
2039  * 		qdisc until the *skb* is freed.
2040  *
2041  * 		This helper is available only if the kernel was compiled with
2042  * 		**CONFIG_IP_ROUTE_CLASSID** configuration option.
2043  * 	Return
2044  * 		The realm of the route for the packet associated to *skb*, or 0
2045  * 		if none was found.
2046  *
2047  * long bpf_perf_event_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
2048  * 	Description
2049  * 		Write raw *data* blob into a special BPF perf event held by
2050  * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
2051  * 		event must have the following attributes: **PERF_SAMPLE_RAW**
2052  * 		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
2053  * 		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
2054  *
2055  * 		The *flags* are used to indicate the index in *map* for which
2056  * 		the value must be put, masked with **BPF_F_INDEX_MASK**.
2057  * 		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
2058  * 		to indicate that the index of the current CPU core should be
2059  * 		used.
2060  *
2061  * 		The value to write, of *size*, is passed through eBPF stack and
2062  * 		pointed by *data*.
2063  *
2064  * 		The context of the program *ctx* needs also be passed to the
2065  * 		helper.
2066  *
2067  * 		On user space, a program willing to read the values needs to
2068  * 		call **perf_event_open**\ () on the perf event (either for
2069  * 		one or for all CPUs) and to store the file descriptor into the
2070  * 		*map*. This must be done before the eBPF program can send data
2071  * 		into it. An example is available in file
2072  * 		*samples/bpf/trace_output_user.c* in the Linux kernel source
2073  * 		tree (the eBPF program counterpart is in
2074  * 		*samples/bpf/trace_output_kern.c*).
2075  *
2076  * 		**bpf_perf_event_output**\ () achieves better performance
2077  * 		than **bpf_trace_printk**\ () for sharing data with user
2078  * 		space, and is much better suitable for streaming data from eBPF
2079  * 		programs.
2080  *
2081  * 		Note that this helper is not restricted to tracing use cases
2082  * 		and can be used with programs attached to TC or XDP as well,
2083  * 		where it allows for passing data to user space listeners. Data
2084  * 		can be:
2085  *
2086  * 		* Only custom structs,
2087  * 		* Only the packet payload, or
2088  * 		* A combination of both.
2089  * 	Return
2090  * 		0 on success, or a negative error in case of failure.
2091  *
2092  * long bpf_skb_load_bytes(const void *skb, u32 offset, void *to, u32 len)
2093  * 	Description
2094  * 		This helper was provided as an easy way to load data from a
2095  * 		packet. It can be used to load *len* bytes from *offset* from
2096  * 		the packet associated to *skb*, into the buffer pointed by
2097  * 		*to*.
2098  *
2099  * 		Since Linux 4.7, usage of this helper has mostly been replaced
2100  * 		by "direct packet access", enabling packet data to be
2101  * 		manipulated with *skb*\ **->data** and *skb*\ **->data_end**
2102  * 		pointing respectively to the first byte of packet data and to
2103  * 		the byte after the last byte of packet data. However, it
2104  * 		remains useful if one wishes to read large quantities of data
2105  * 		at once from a packet into the eBPF stack.
2106  * 	Return
2107  * 		0 on success, or a negative error in case of failure.
2108  *
2109  * long bpf_get_stackid(void *ctx, struct bpf_map *map, u64 flags)
2110  * 	Description
2111  * 		Walk a user or a kernel stack and return its id. To achieve
2112  * 		this, the helper needs *ctx*, which is a pointer to the context
2113  * 		on which the tracing program is executed, and a pointer to a
2114  * 		*map* of type **BPF_MAP_TYPE_STACK_TRACE**.
2115  *
2116  * 		The last argument, *flags*, holds the number of stack frames to
2117  * 		skip (from 0 to 255), masked with
2118  * 		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
2119  * 		a combination of the following flags:
2120  *
2121  * 		**BPF_F_USER_STACK**
2122  * 			Collect a user space stack instead of a kernel stack.
2123  * 		**BPF_F_FAST_STACK_CMP**
2124  * 			Compare stacks by hash only.
2125  * 		**BPF_F_REUSE_STACKID**
2126  * 			If two different stacks hash into the same *stackid*,
2127  * 			discard the old one.
2128  *
2129  * 		The stack id retrieved is a 32 bit long integer handle which
2130  * 		can be further combined with other data (including other stack
2131  * 		ids) and used as a key into maps. This can be useful for
2132  * 		generating a variety of graphs (such as flame graphs or off-cpu
2133  * 		graphs).
2134  *
2135  * 		For walking a stack, this helper is an improvement over
2136  * 		**bpf_probe_read**\ (), which can be used with unrolled loops
2137  * 		but is not efficient and consumes a lot of eBPF instructions.
2138  * 		Instead, **bpf_get_stackid**\ () can collect up to
2139  * 		**PERF_MAX_STACK_DEPTH** both kernel and user frames. Note that
2140  * 		this limit can be controlled with the **sysctl** program, and
2141  * 		that it should be manually increased in order to profile long
2142  * 		user stacks (such as stacks for Java programs). To do so, use:
2143  *
2144  * 		::
2145  *
2146  * 			# sysctl kernel.perf_event_max_stack=<new value>
2147  * 	Return
2148  * 		The positive or null stack id on success, or a negative error
2149  * 		in case of failure.
2150  *
2151  * s64 bpf_csum_diff(__be32 *from, u32 from_size, __be32 *to, u32 to_size, __wsum seed)
2152  * 	Description
2153  * 		Compute a checksum difference, from the raw buffer pointed by
2154  * 		*from*, of length *from_size* (that must be a multiple of 4),
2155  * 		towards the raw buffer pointed by *to*, of size *to_size*
2156  * 		(same remark). An optional *seed* can be added to the value
2157  * 		(this can be cascaded, the seed may come from a previous call
2158  * 		to the helper).
2159  *
2160  * 		This is flexible enough to be used in several ways:
2161  *
2162  * 		* With *from_size* == 0, *to_size* > 0 and *seed* set to
2163  * 		  checksum, it can be used when pushing new data.
2164  * 		* With *from_size* > 0, *to_size* == 0 and *seed* set to
2165  * 		  checksum, it can be used when removing data from a packet.
2166  * 		* With *from_size* > 0, *to_size* > 0 and *seed* set to 0, it
2167  * 		  can be used to compute a diff. Note that *from_size* and
2168  * 		  *to_size* do not need to be equal.
2169  *
2170  * 		This helper can be used in combination with
2171  * 		**bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\ (), to
2172  * 		which one can feed in the difference computed with
2173  * 		**bpf_csum_diff**\ ().
2174  * 	Return
2175  * 		The checksum result, or a negative error code in case of
2176  * 		failure.
2177  *
2178  * long bpf_skb_get_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)
2179  * 	Description
2180  * 		Retrieve tunnel options metadata for the packet associated to
2181  * 		*skb*, and store the raw tunnel option data to the buffer *opt*
2182  * 		of *size*.
2183  *
2184  * 		This helper can be used with encapsulation devices that can
2185  * 		operate in "collect metadata" mode (please refer to the related
2186  * 		note in the description of **bpf_skb_get_tunnel_key**\ () for
2187  * 		more details). A particular example where this can be used is
2188  * 		in combination with the Geneve encapsulation protocol, where it
2189  * 		allows for pushing (with **bpf_skb_get_tunnel_opt**\ () helper)
2190  * 		and retrieving arbitrary TLVs (Type-Length-Value headers) from
2191  * 		the eBPF program. This allows for full customization of these
2192  * 		headers.
2193  * 	Return
2194  * 		The size of the option data retrieved.
2195  *
2196  * long bpf_skb_set_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)
2197  * 	Description
2198  * 		Set tunnel options metadata for the packet associated to *skb*
2199  * 		to the option data contained in the raw buffer *opt* of *size*.
2200  *
2201  * 		See also the description of the **bpf_skb_get_tunnel_opt**\ ()
2202  * 		helper for additional information.
2203  * 	Return
2204  * 		0 on success, or a negative error in case of failure.
2205  *
2206  * long bpf_skb_change_proto(struct sk_buff *skb, __be16 proto, u64 flags)
2207  * 	Description
2208  * 		Change the protocol of the *skb* to *proto*. Currently
2209  * 		supported are transition from IPv4 to IPv6, and from IPv6 to
2210  * 		IPv4. The helper takes care of the groundwork for the
2211  * 		transition, including resizing the socket buffer. The eBPF
2212  * 		program is expected to fill the new headers, if any, via
2213  * 		**skb_store_bytes**\ () and to recompute the checksums with
2214  * 		**bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\
2215  * 		(). The main case for this helper is to perform NAT64
2216  * 		operations out of an eBPF program.
2217  *
2218  * 		Internally, the GSO type is marked as dodgy so that headers are
2219  * 		checked and segments are recalculated by the GSO/GRO engine.
2220  * 		The size for GSO target is adapted as well.
2221  *
2222  * 		All values for *flags* are reserved for future usage, and must
2223  * 		be left at zero.
2224  *
2225  * 		A call to this helper is susceptible to change the underlying
2226  * 		packet buffer. Therefore, at load time, all checks on pointers
2227  * 		previously done by the verifier are invalidated and must be
2228  * 		performed again, if the helper is used in combination with
2229  * 		direct packet access.
2230  * 	Return
2231  * 		0 on success, or a negative error in case of failure.
2232  *
2233  * long bpf_skb_change_type(struct sk_buff *skb, u32 type)
2234  * 	Description
2235  * 		Change the packet type for the packet associated to *skb*. This
2236  * 		comes down to setting *skb*\ **->pkt_type** to *type*, except
2237  * 		the eBPF program does not have a write access to *skb*\
2238  * 		**->pkt_type** beside this helper. Using a helper here allows
2239  * 		for graceful handling of errors.
2240  *
2241  * 		The major use case is to change incoming *skb*s to
2242  * 		**PACKET_HOST** in a programmatic way instead of having to
2243  * 		recirculate via **redirect**\ (..., **BPF_F_INGRESS**), for
2244  * 		example.
2245  *
2246  * 		Note that *type* only allows certain values. At this time, they
2247  * 		are:
2248  *
2249  * 		**PACKET_HOST**
2250  * 			Packet is for us.
2251  * 		**PACKET_BROADCAST**
2252  * 			Send packet to all.
2253  * 		**PACKET_MULTICAST**
2254  * 			Send packet to group.
2255  * 		**PACKET_OTHERHOST**
2256  * 			Send packet to someone else.
2257  * 	Return
2258  * 		0 on success, or a negative error in case of failure.
2259  *
2260  * long bpf_skb_under_cgroup(struct sk_buff *skb, struct bpf_map *map, u32 index)
2261  * 	Description
2262  * 		Check whether *skb* is a descendant of the cgroup2 held by
2263  * 		*map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
2264  * 	Return
2265  * 		The return value depends on the result of the test, and can be:
2266  *
2267  * 		* 0, if the *skb* failed the cgroup2 descendant test.
2268  * 		* 1, if the *skb* succeeded the cgroup2 descendant test.
2269  * 		* A negative error code, if an error occurred.
2270  *
2271  * u32 bpf_get_hash_recalc(struct sk_buff *skb)
2272  * 	Description
2273  * 		Retrieve the hash of the packet, *skb*\ **->hash**. If it is
2274  * 		not set, in particular if the hash was cleared due to mangling,
2275  * 		recompute this hash. Later accesses to the hash can be done
2276  * 		directly with *skb*\ **->hash**.
2277  *
2278  * 		Calling **bpf_set_hash_invalid**\ (), changing a packet
2279  * 		prototype with **bpf_skb_change_proto**\ (), or calling
2280  * 		**bpf_skb_store_bytes**\ () with the
2281  * 		**BPF_F_INVALIDATE_HASH** are actions susceptible to clear
2282  * 		the hash and to trigger a new computation for the next call to
2283  * 		**bpf_get_hash_recalc**\ ().
2284  * 	Return
2285  * 		The 32-bit hash.
2286  *
2287  * u64 bpf_get_current_task(void)
2288  * 	Description
2289  * 		Get the current task.
2290  * 	Return
2291  * 		A pointer to the current task struct.
2292  *
2293  * long bpf_probe_write_user(void *dst, const void *src, u32 len)
2294  * 	Description
2295  * 		Attempt in a safe way to write *len* bytes from the buffer
2296  * 		*src* to *dst* in memory. It only works for threads that are in
2297  * 		user context, and *dst* must be a valid user space address.
2298  *
2299  * 		This helper should not be used to implement any kind of
2300  * 		security mechanism because of TOC-TOU attacks, but rather to
2301  * 		debug, divert, and manipulate execution of semi-cooperative
2302  * 		processes.
2303  *
2304  * 		Keep in mind that this feature is meant for experiments, and it
2305  * 		has a risk of crashing the system and running programs.
2306  * 		Therefore, when an eBPF program using this helper is attached,
2307  * 		a warning including PID and process name is printed to kernel
2308  * 		logs.
2309  * 	Return
2310  * 		0 on success, or a negative error in case of failure.
2311  *
2312  * long bpf_current_task_under_cgroup(struct bpf_map *map, u32 index)
2313  * 	Description
2314  * 		Check whether the probe is being run is the context of a given
2315  * 		subset of the cgroup2 hierarchy. The cgroup2 to test is held by
2316  * 		*map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
2317  * 	Return
2318  * 		The return value depends on the result of the test, and can be:
2319  *
2320  *		* 1, if current task belongs to the cgroup2.
2321  *		* 0, if current task does not belong to the cgroup2.
2322  * 		* A negative error code, if an error occurred.
2323  *
2324  * long bpf_skb_change_tail(struct sk_buff *skb, u32 len, u64 flags)
2325  * 	Description
2326  * 		Resize (trim or grow) the packet associated to *skb* to the
2327  * 		new *len*. The *flags* are reserved for future usage, and must
2328  * 		be left at zero.
2329  *
2330  * 		The basic idea is that the helper performs the needed work to
2331  * 		change the size of the packet, then the eBPF program rewrites
2332  * 		the rest via helpers like **bpf_skb_store_bytes**\ (),
2333  * 		**bpf_l3_csum_replace**\ (), **bpf_l3_csum_replace**\ ()
2334  * 		and others. This helper is a slow path utility intended for
2335  * 		replies with control messages. And because it is targeted for
2336  * 		slow path, the helper itself can afford to be slow: it
2337  * 		implicitly linearizes, unclones and drops offloads from the
2338  * 		*skb*.
2339  *
2340  * 		A call to this helper is susceptible to change the underlying
2341  * 		packet buffer. Therefore, at load time, all checks on pointers
2342  * 		previously done by the verifier are invalidated and must be
2343  * 		performed again, if the helper is used in combination with
2344  * 		direct packet access.
2345  * 	Return
2346  * 		0 on success, or a negative error in case of failure.
2347  *
2348  * long bpf_skb_pull_data(struct sk_buff *skb, u32 len)
2349  * 	Description
2350  * 		Pull in non-linear data in case the *skb* is non-linear and not
2351  * 		all of *len* are part of the linear section. Make *len* bytes
2352  * 		from *skb* readable and writable. If a zero value is passed for
2353  * 		*len*, then the whole length of the *skb* is pulled.
2354  *
2355  * 		This helper is only needed for reading and writing with direct
2356  * 		packet access.
2357  *
2358  * 		For direct packet access, testing that offsets to access
2359  * 		are within packet boundaries (test on *skb*\ **->data_end**) is
2360  * 		susceptible to fail if offsets are invalid, or if the requested
2361  * 		data is in non-linear parts of the *skb*. On failure the
2362  * 		program can just bail out, or in the case of a non-linear
2363  * 		buffer, use a helper to make the data available. The
2364  * 		**bpf_skb_load_bytes**\ () helper is a first solution to access
2365  * 		the data. Another one consists in using **bpf_skb_pull_data**
2366  * 		to pull in once the non-linear parts, then retesting and
2367  * 		eventually access the data.
2368  *
2369  * 		At the same time, this also makes sure the *skb* is uncloned,
2370  * 		which is a necessary condition for direct write. As this needs
2371  * 		to be an invariant for the write part only, the verifier
2372  * 		detects writes and adds a prologue that is calling
2373  * 		**bpf_skb_pull_data()** to effectively unclone the *skb* from
2374  * 		the very beginning in case it is indeed cloned.
2375  *
2376  * 		A call to this helper is susceptible to change the underlying
2377  * 		packet buffer. Therefore, at load time, all checks on pointers
2378  * 		previously done by the verifier are invalidated and must be
2379  * 		performed again, if the helper is used in combination with
2380  * 		direct packet access.
2381  * 	Return
2382  * 		0 on success, or a negative error in case of failure.
2383  *
2384  * s64 bpf_csum_update(struct sk_buff *skb, __wsum csum)
2385  * 	Description
2386  * 		Add the checksum *csum* into *skb*\ **->csum** in case the
2387  * 		driver has supplied a checksum for the entire packet into that
2388  * 		field. Return an error otherwise. This helper is intended to be
2389  * 		used in combination with **bpf_csum_diff**\ (), in particular
2390  * 		when the checksum needs to be updated after data has been
2391  * 		written into the packet through direct packet access.
2392  * 	Return
2393  * 		The checksum on success, or a negative error code in case of
2394  * 		failure.
2395  *
2396  * void bpf_set_hash_invalid(struct sk_buff *skb)
2397  * 	Description
2398  * 		Invalidate the current *skb*\ **->hash**. It can be used after
2399  * 		mangling on headers through direct packet access, in order to
2400  * 		indicate that the hash is outdated and to trigger a
2401  * 		recalculation the next time the kernel tries to access this
2402  * 		hash or when the **bpf_get_hash_recalc**\ () helper is called.
2403  * 	Return
2404  * 		void.
2405  *
2406  * long bpf_get_numa_node_id(void)
2407  * 	Description
2408  * 		Return the id of the current NUMA node. The primary use case
2409  * 		for this helper is the selection of sockets for the local NUMA
2410  * 		node, when the program is attached to sockets using the
2411  * 		**SO_ATTACH_REUSEPORT_EBPF** option (see also **socket(7)**),
2412  * 		but the helper is also available to other eBPF program types,
2413  * 		similarly to **bpf_get_smp_processor_id**\ ().
2414  * 	Return
2415  * 		The id of current NUMA node.
2416  *
2417  * long bpf_skb_change_head(struct sk_buff *skb, u32 len, u64 flags)
2418  * 	Description
2419  * 		Grows headroom of packet associated to *skb* and adjusts the
2420  * 		offset of the MAC header accordingly, adding *len* bytes of
2421  * 		space. It automatically extends and reallocates memory as
2422  * 		required.
2423  *
2424  * 		This helper can be used on a layer 3 *skb* to push a MAC header
2425  * 		for redirection into a layer 2 device.
2426  *
2427  * 		All values for *flags* are reserved for future usage, and must
2428  * 		be left at zero.
2429  *
2430  * 		A call to this helper is susceptible to change the underlying
2431  * 		packet buffer. Therefore, at load time, all checks on pointers
2432  * 		previously done by the verifier are invalidated and must be
2433  * 		performed again, if the helper is used in combination with
2434  * 		direct packet access.
2435  * 	Return
2436  * 		0 on success, or a negative error in case of failure.
2437  *
2438  * long bpf_xdp_adjust_head(struct xdp_buff *xdp_md, int delta)
2439  * 	Description
2440  * 		Adjust (move) *xdp_md*\ **->data** by *delta* bytes. Note that
2441  * 		it is possible to use a negative value for *delta*. This helper
2442  * 		can be used to prepare the packet for pushing or popping
2443  * 		headers.
2444  *
2445  * 		A call to this helper is susceptible to change the underlying
2446  * 		packet buffer. Therefore, at load time, all checks on pointers
2447  * 		previously done by the verifier are invalidated and must be
2448  * 		performed again, if the helper is used in combination with
2449  * 		direct packet access.
2450  * 	Return
2451  * 		0 on success, or a negative error in case of failure.
2452  *
2453  * long bpf_probe_read_str(void *dst, u32 size, const void *unsafe_ptr)
2454  * 	Description
2455  * 		Copy a NUL terminated string from an unsafe kernel address
2456  * 		*unsafe_ptr* to *dst*. See **bpf_probe_read_kernel_str**\ () for
2457  * 		more details.
2458  *
2459  * 		Generally, use **bpf_probe_read_user_str**\ () or
2460  * 		**bpf_probe_read_kernel_str**\ () instead.
2461  * 	Return
2462  * 		On success, the strictly positive length of the string,
2463  * 		including the trailing NUL character. On error, a negative
2464  * 		value.
2465  *
2466  * u64 bpf_get_socket_cookie(struct sk_buff *skb)
2467  * 	Description
2468  * 		If the **struct sk_buff** pointed by *skb* has a known socket,
2469  * 		retrieve the cookie (generated by the kernel) of this socket.
2470  * 		If no cookie has been set yet, generate a new cookie. Once
2471  * 		generated, the socket cookie remains stable for the life of the
2472  * 		socket. This helper can be useful for monitoring per socket
2473  * 		networking traffic statistics as it provides a global socket
2474  * 		identifier that can be assumed unique.
2475  * 	Return
2476  * 		A 8-byte long unique number on success, or 0 if the socket
2477  * 		field is missing inside *skb*.
2478  *
2479  * u64 bpf_get_socket_cookie(struct bpf_sock_addr *ctx)
2480  * 	Description
2481  * 		Equivalent to bpf_get_socket_cookie() helper that accepts
2482  * 		*skb*, but gets socket from **struct bpf_sock_addr** context.
2483  * 	Return
2484  * 		A 8-byte long unique number.
2485  *
2486  * u64 bpf_get_socket_cookie(struct bpf_sock_ops *ctx)
2487  * 	Description
2488  * 		Equivalent to **bpf_get_socket_cookie**\ () helper that accepts
2489  * 		*skb*, but gets socket from **struct bpf_sock_ops** context.
2490  * 	Return
2491  * 		A 8-byte long unique number.
2492  *
2493  * u64 bpf_get_socket_cookie(struct sock *sk)
2494  * 	Description
2495  * 		Equivalent to **bpf_get_socket_cookie**\ () helper that accepts
2496  * 		*sk*, but gets socket from a BTF **struct sock**. This helper
2497  * 		also works for sleepable programs.
2498  * 	Return
2499  * 		A 8-byte long unique number or 0 if *sk* is NULL.
2500  *
2501  * u32 bpf_get_socket_uid(struct sk_buff *skb)
2502  * 	Description
2503  * 		Get the owner UID of the socked associated to *skb*.
2504  * 	Return
2505  * 		The owner UID of the socket associated to *skb*. If the socket
2506  * 		is **NULL**, or if it is not a full socket (i.e. if it is a
2507  * 		time-wait or a request socket instead), **overflowuid** value
2508  * 		is returned (note that **overflowuid** might also be the actual
2509  * 		UID value for the socket).
2510  *
2511  * long bpf_set_hash(struct sk_buff *skb, u32 hash)
2512  * 	Description
2513  * 		Set the full hash for *skb* (set the field *skb*\ **->hash**)
2514  * 		to value *hash*.
2515  * 	Return
2516  * 		0
2517  *
2518  * long bpf_setsockopt(void *bpf_socket, int level, int optname, void *optval, int optlen)
2519  * 	Description
2520  * 		Emulate a call to **setsockopt()** on the socket associated to
2521  * 		*bpf_socket*, which must be a full socket. The *level* at
2522  * 		which the option resides and the name *optname* of the option
2523  * 		must be specified, see **setsockopt(2)** for more information.
2524  * 		The option value of length *optlen* is pointed by *optval*.
2525  *
2526  * 		*bpf_socket* should be one of the following:
2527  *
2528  * 		* **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
2529  * 		* **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**
2530  * 		  and **BPF_CGROUP_INET6_CONNECT**.
2531  *
2532  * 		This helper actually implements a subset of **setsockopt()**.
2533  * 		It supports the following *level*\ s:
2534  *
2535  * 		* **SOL_SOCKET**, which supports the following *optname*\ s:
2536  * 		  **SO_RCVBUF**, **SO_SNDBUF**, **SO_MAX_PACING_RATE**,
2537  * 		  **SO_PRIORITY**, **SO_RCVLOWAT**, **SO_MARK**,
2538  * 		  **SO_BINDTODEVICE**, **SO_KEEPALIVE**.
2539  * 		* **IPPROTO_TCP**, which supports the following *optname*\ s:
2540  * 		  **TCP_CONGESTION**, **TCP_BPF_IW**,
2541  * 		  **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,
2542  * 		  **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,
2543  *		  **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**.
2544  * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
2545  * 		* **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
2546  * 	Return
2547  * 		0 on success, or a negative error in case of failure.
2548  *
2549  * long bpf_skb_adjust_room(struct sk_buff *skb, s32 len_diff, u32 mode, u64 flags)
2550  * 	Description
2551  * 		Grow or shrink the room for data in the packet associated to
2552  * 		*skb* by *len_diff*, and according to the selected *mode*.
2553  *
2554  * 		By default, the helper will reset any offloaded checksum
2555  * 		indicator of the skb to CHECKSUM_NONE. This can be avoided
2556  * 		by the following flag:
2557  *
2558  * 		* **BPF_F_ADJ_ROOM_NO_CSUM_RESET**: Do not reset offloaded
2559  * 		  checksum data of the skb to CHECKSUM_NONE.
2560  *
2561  *		There are two supported modes at this time:
2562  *
2563  *		* **BPF_ADJ_ROOM_MAC**: Adjust room at the mac layer
2564  *		  (room space is added or removed below the layer 2 header).
2565  *
2566  * 		* **BPF_ADJ_ROOM_NET**: Adjust room at the network layer
2567  * 		  (room space is added or removed below the layer 3 header).
2568  *
2569  *		The following flags are supported at this time:
2570  *
2571  *		* **BPF_F_ADJ_ROOM_FIXED_GSO**: Do not adjust gso_size.
2572  *		  Adjusting mss in this way is not allowed for datagrams.
2573  *
2574  *		* **BPF_F_ADJ_ROOM_ENCAP_L3_IPV4**,
2575  *		  **BPF_F_ADJ_ROOM_ENCAP_L3_IPV6**:
2576  *		  Any new space is reserved to hold a tunnel header.
2577  *		  Configure skb offsets and other fields accordingly.
2578  *
2579  *		* **BPF_F_ADJ_ROOM_ENCAP_L4_GRE**,
2580  *		  **BPF_F_ADJ_ROOM_ENCAP_L4_UDP**:
2581  *		  Use with ENCAP_L3 flags to further specify the tunnel type.
2582  *
2583  *		* **BPF_F_ADJ_ROOM_ENCAP_L2**\ (*len*):
2584  *		  Use with ENCAP_L3/L4 flags to further specify the tunnel
2585  *		  type; *len* is the length of the inner MAC header.
2586  *
2587  *		* **BPF_F_ADJ_ROOM_ENCAP_L2_ETH**:
2588  *		  Use with BPF_F_ADJ_ROOM_ENCAP_L2 flag to further specify the
2589  *		  L2 type as Ethernet.
2590  *
2591  * 		A call to this helper is susceptible to change the underlying
2592  * 		packet buffer. Therefore, at load time, all checks on pointers
2593  * 		previously done by the verifier are invalidated and must be
2594  * 		performed again, if the helper is used in combination with
2595  * 		direct packet access.
2596  * 	Return
2597  * 		0 on success, or a negative error in case of failure.
2598  *
2599  * long bpf_redirect_map(struct bpf_map *map, u32 key, u64 flags)
2600  * 	Description
2601  * 		Redirect the packet to the endpoint referenced by *map* at
2602  * 		index *key*. Depending on its type, this *map* can contain
2603  * 		references to net devices (for forwarding packets through other
2604  * 		ports), or to CPUs (for redirecting XDP frames to another CPU;
2605  * 		but this is only implemented for native XDP (with driver
2606  * 		support) as of this writing).
2607  *
2608  * 		The lower two bits of *flags* are used as the return code if
2609  * 		the map lookup fails. This is so that the return value can be
2610  * 		one of the XDP program return codes up to **XDP_TX**, as chosen
2611  * 		by the caller. The higher bits of *flags* can be set to
2612  * 		BPF_F_BROADCAST or BPF_F_EXCLUDE_INGRESS as defined below.
2613  *
2614  * 		With BPF_F_BROADCAST the packet will be broadcasted to all the
2615  * 		interfaces in the map, with BPF_F_EXCLUDE_INGRESS the ingress
2616  * 		interface will be excluded when do broadcasting.
2617  *
2618  * 		See also **bpf_redirect**\ (), which only supports redirecting
2619  * 		to an ifindex, but doesn't require a map to do so.
2620  * 	Return
2621  * 		**XDP_REDIRECT** on success, or the value of the two lower bits
2622  * 		of the *flags* argument on error.
2623  *
2624  * long bpf_sk_redirect_map(struct sk_buff *skb, struct bpf_map *map, u32 key, u64 flags)
2625  * 	Description
2626  * 		Redirect the packet to the socket referenced by *map* (of type
2627  * 		**BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
2628  * 		egress interfaces can be used for redirection. The
2629  * 		**BPF_F_INGRESS** value in *flags* is used to make the
2630  * 		distinction (ingress path is selected if the flag is present,
2631  * 		egress path otherwise). This is the only flag supported for now.
2632  * 	Return
2633  * 		**SK_PASS** on success, or **SK_DROP** on error.
2634  *
2635  * long bpf_sock_map_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
2636  * 	Description
2637  * 		Add an entry to, or update a *map* referencing sockets. The
2638  * 		*skops* is used as a new value for the entry associated to
2639  * 		*key*. *flags* is one of:
2640  *
2641  * 		**BPF_NOEXIST**
2642  * 			The entry for *key* must not exist in the map.
2643  * 		**BPF_EXIST**
2644  * 			The entry for *key* must already exist in the map.
2645  * 		**BPF_ANY**
2646  * 			No condition on the existence of the entry for *key*.
2647  *
2648  * 		If the *map* has eBPF programs (parser and verdict), those will
2649  * 		be inherited by the socket being added. If the socket is
2650  * 		already attached to eBPF programs, this results in an error.
2651  * 	Return
2652  * 		0 on success, or a negative error in case of failure.
2653  *
2654  * long bpf_xdp_adjust_meta(struct xdp_buff *xdp_md, int delta)
2655  * 	Description
2656  * 		Adjust the address pointed by *xdp_md*\ **->data_meta** by
2657  * 		*delta* (which can be positive or negative). Note that this
2658  * 		operation modifies the address stored in *xdp_md*\ **->data**,
2659  * 		so the latter must be loaded only after the helper has been
2660  * 		called.
2661  *
2662  * 		The use of *xdp_md*\ **->data_meta** is optional and programs
2663  * 		are not required to use it. The rationale is that when the
2664  * 		packet is processed with XDP (e.g. as DoS filter), it is
2665  * 		possible to push further meta data along with it before passing
2666  * 		to the stack, and to give the guarantee that an ingress eBPF
2667  * 		program attached as a TC classifier on the same device can pick
2668  * 		this up for further post-processing. Since TC works with socket
2669  * 		buffers, it remains possible to set from XDP the **mark** or
2670  * 		**priority** pointers, or other pointers for the socket buffer.
2671  * 		Having this scratch space generic and programmable allows for
2672  * 		more flexibility as the user is free to store whatever meta
2673  * 		data they need.
2674  *
2675  * 		A call to this helper is susceptible to change the underlying
2676  * 		packet buffer. Therefore, at load time, all checks on pointers
2677  * 		previously done by the verifier are invalidated and must be
2678  * 		performed again, if the helper is used in combination with
2679  * 		direct packet access.
2680  * 	Return
2681  * 		0 on success, or a negative error in case of failure.
2682  *
2683  * long bpf_perf_event_read_value(struct bpf_map *map, u64 flags, struct bpf_perf_event_value *buf, u32 buf_size)
2684  * 	Description
2685  * 		Read the value of a perf event counter, and store it into *buf*
2686  * 		of size *buf_size*. This helper relies on a *map* of type
2687  * 		**BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of the perf event
2688  * 		counter is selected when *map* is updated with perf event file
2689  * 		descriptors. The *map* is an array whose size is the number of
2690  * 		available CPUs, and each cell contains a value relative to one
2691  * 		CPU. The value to retrieve is indicated by *flags*, that
2692  * 		contains the index of the CPU to look up, masked with
2693  * 		**BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
2694  * 		**BPF_F_CURRENT_CPU** to indicate that the value for the
2695  * 		current CPU should be retrieved.
2696  *
2697  * 		This helper behaves in a way close to
2698  * 		**bpf_perf_event_read**\ () helper, save that instead of
2699  * 		just returning the value observed, it fills the *buf*
2700  * 		structure. This allows for additional data to be retrieved: in
2701  * 		particular, the enabled and running times (in *buf*\
2702  * 		**->enabled** and *buf*\ **->running**, respectively) are
2703  * 		copied. In general, **bpf_perf_event_read_value**\ () is
2704  * 		recommended over **bpf_perf_event_read**\ (), which has some
2705  * 		ABI issues and provides fewer functionalities.
2706  *
2707  * 		These values are interesting, because hardware PMU (Performance
2708  * 		Monitoring Unit) counters are limited resources. When there are
2709  * 		more PMU based perf events opened than available counters,
2710  * 		kernel will multiplex these events so each event gets certain
2711  * 		percentage (but not all) of the PMU time. In case that
2712  * 		multiplexing happens, the number of samples or counter value
2713  * 		will not reflect the case compared to when no multiplexing
2714  * 		occurs. This makes comparison between different runs difficult.
2715  * 		Typically, the counter value should be normalized before
2716  * 		comparing to other experiments. The usual normalization is done
2717  * 		as follows.
2718  *
2719  * 		::
2720  *
2721  * 			normalized_counter = counter * t_enabled / t_running
2722  *
2723  * 		Where t_enabled is the time enabled for event and t_running is
2724  * 		the time running for event since last normalization. The
2725  * 		enabled and running times are accumulated since the perf event
2726  * 		open. To achieve scaling factor between two invocations of an
2727  * 		eBPF program, users can use CPU id as the key (which is
2728  * 		typical for perf array usage model) to remember the previous
2729  * 		value and do the calculation inside the eBPF program.
2730  * 	Return
2731  * 		0 on success, or a negative error in case of failure.
2732  *
2733  * long bpf_perf_prog_read_value(struct bpf_perf_event_data *ctx, struct bpf_perf_event_value *buf, u32 buf_size)
2734  * 	Description
2735  * 		For en eBPF program attached to a perf event, retrieve the
2736  * 		value of the event counter associated to *ctx* and store it in
2737  * 		the structure pointed by *buf* and of size *buf_size*. Enabled
2738  * 		and running times are also stored in the structure (see
2739  * 		description of helper **bpf_perf_event_read_value**\ () for
2740  * 		more details).
2741  * 	Return
2742  * 		0 on success, or a negative error in case of failure.
2743  *
2744  * long bpf_getsockopt(void *bpf_socket, int level, int optname, void *optval, int optlen)
2745  * 	Description
2746  * 		Emulate a call to **getsockopt()** on the socket associated to
2747  * 		*bpf_socket*, which must be a full socket. The *level* at
2748  * 		which the option resides and the name *optname* of the option
2749  * 		must be specified, see **getsockopt(2)** for more information.
2750  * 		The retrieved value is stored in the structure pointed by
2751  * 		*opval* and of length *optlen*.
2752  *
2753  * 		*bpf_socket* should be one of the following:
2754  *
2755  * 		* **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
2756  * 		* **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**
2757  * 		  and **BPF_CGROUP_INET6_CONNECT**.
2758  *
2759  * 		This helper actually implements a subset of **getsockopt()**.
2760  * 		It supports the following *level*\ s:
2761  *
2762  * 		* **IPPROTO_TCP**, which supports *optname*
2763  * 		  **TCP_CONGESTION**.
2764  * 		* **IPPROTO_IP**, which supports *optname* **IP_TOS**.
2765  * 		* **IPPROTO_IPV6**, which supports *optname* **IPV6_TCLASS**.
2766  * 	Return
2767  * 		0 on success, or a negative error in case of failure.
2768  *
2769  * long bpf_override_return(struct pt_regs *regs, u64 rc)
2770  * 	Description
2771  * 		Used for error injection, this helper uses kprobes to override
2772  * 		the return value of the probed function, and to set it to *rc*.
2773  * 		The first argument is the context *regs* on which the kprobe
2774  * 		works.
2775  *
2776  * 		This helper works by setting the PC (program counter)
2777  * 		to an override function which is run in place of the original
2778  * 		probed function. This means the probed function is not run at
2779  * 		all. The replacement function just returns with the required
2780  * 		value.
2781  *
2782  * 		This helper has security implications, and thus is subject to
2783  * 		restrictions. It is only available if the kernel was compiled
2784  * 		with the **CONFIG_BPF_KPROBE_OVERRIDE** configuration
2785  * 		option, and in this case it only works on functions tagged with
2786  * 		**ALLOW_ERROR_INJECTION** in the kernel code.
2787  *
2788  * 		Also, the helper is only available for the architectures having
2789  * 		the CONFIG_FUNCTION_ERROR_INJECTION option. As of this writing,
2790  * 		x86 architecture is the only one to support this feature.
2791  * 	Return
2792  * 		0
2793  *
2794  * long bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *bpf_sock, int argval)
2795  * 	Description
2796  * 		Attempt to set the value of the **bpf_sock_ops_cb_flags** field
2797  * 		for the full TCP socket associated to *bpf_sock_ops* to
2798  * 		*argval*.
2799  *
2800  * 		The primary use of this field is to determine if there should
2801  * 		be calls to eBPF programs of type
2802  * 		**BPF_PROG_TYPE_SOCK_OPS** at various points in the TCP
2803  * 		code. A program of the same type can change its value, per
2804  * 		connection and as necessary, when the connection is
2805  * 		established. This field is directly accessible for reading, but
2806  * 		this helper must be used for updates in order to return an
2807  * 		error if an eBPF program tries to set a callback that is not
2808  * 		supported in the current kernel.
2809  *
2810  * 		*argval* is a flag array which can combine these flags:
2811  *
2812  * 		* **BPF_SOCK_OPS_RTO_CB_FLAG** (retransmission time out)
2813  * 		* **BPF_SOCK_OPS_RETRANS_CB_FLAG** (retransmission)
2814  * 		* **BPF_SOCK_OPS_STATE_CB_FLAG** (TCP state change)
2815  * 		* **BPF_SOCK_OPS_RTT_CB_FLAG** (every RTT)
2816  *
2817  * 		Therefore, this function can be used to clear a callback flag by
2818  * 		setting the appropriate bit to zero. e.g. to disable the RTO
2819  * 		callback:
2820  *
2821  * 		**bpf_sock_ops_cb_flags_set(bpf_sock,**
2822  * 			**bpf_sock->bpf_sock_ops_cb_flags & ~BPF_SOCK_OPS_RTO_CB_FLAG)**
2823  *
2824  * 		Here are some examples of where one could call such eBPF
2825  * 		program:
2826  *
2827  * 		* When RTO fires.
2828  * 		* When a packet is retransmitted.
2829  * 		* When the connection terminates.
2830  * 		* When a packet is sent.
2831  * 		* When a packet is received.
2832  * 	Return
2833  * 		Code **-EINVAL** if the socket is not a full TCP socket;
2834  * 		otherwise, a positive number containing the bits that could not
2835  * 		be set is returned (which comes down to 0 if all bits were set
2836  * 		as required).
2837  *
2838  * long bpf_msg_redirect_map(struct sk_msg_buff *msg, struct bpf_map *map, u32 key, u64 flags)
2839  * 	Description
2840  * 		This helper is used in programs implementing policies at the
2841  * 		socket level. If the message *msg* is allowed to pass (i.e. if
2842  * 		the verdict eBPF program returns **SK_PASS**), redirect it to
2843  * 		the socket referenced by *map* (of type
2844  * 		**BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
2845  * 		egress interfaces can be used for redirection. The
2846  * 		**BPF_F_INGRESS** value in *flags* is used to make the
2847  * 		distinction (ingress path is selected if the flag is present,
2848  * 		egress path otherwise). This is the only flag supported for now.
2849  * 	Return
2850  * 		**SK_PASS** on success, or **SK_DROP** on error.
2851  *
2852  * long bpf_msg_apply_bytes(struct sk_msg_buff *msg, u32 bytes)
2853  * 	Description
2854  * 		For socket policies, apply the verdict of the eBPF program to
2855  * 		the next *bytes* (number of bytes) of message *msg*.
2856  *
2857  * 		For example, this helper can be used in the following cases:
2858  *
2859  * 		* A single **sendmsg**\ () or **sendfile**\ () system call
2860  * 		  contains multiple logical messages that the eBPF program is
2861  * 		  supposed to read and for which it should apply a verdict.
2862  * 		* An eBPF program only cares to read the first *bytes* of a
2863  * 		  *msg*. If the message has a large payload, then setting up
2864  * 		  and calling the eBPF program repeatedly for all bytes, even
2865  * 		  though the verdict is already known, would create unnecessary
2866  * 		  overhead.
2867  *
2868  * 		When called from within an eBPF program, the helper sets a
2869  * 		counter internal to the BPF infrastructure, that is used to
2870  * 		apply the last verdict to the next *bytes*. If *bytes* is
2871  * 		smaller than the current data being processed from a
2872  * 		**sendmsg**\ () or **sendfile**\ () system call, the first
2873  * 		*bytes* will be sent and the eBPF program will be re-run with
2874  * 		the pointer for start of data pointing to byte number *bytes*
2875  * 		**+ 1**. If *bytes* is larger than the current data being
2876  * 		processed, then the eBPF verdict will be applied to multiple
2877  * 		**sendmsg**\ () or **sendfile**\ () calls until *bytes* are
2878  * 		consumed.
2879  *
2880  * 		Note that if a socket closes with the internal counter holding
2881  * 		a non-zero value, this is not a problem because data is not
2882  * 		being buffered for *bytes* and is sent as it is received.
2883  * 	Return
2884  * 		0
2885  *
2886  * long bpf_msg_cork_bytes(struct sk_msg_buff *msg, u32 bytes)
2887  * 	Description
2888  * 		For socket policies, prevent the execution of the verdict eBPF
2889  * 		program for message *msg* until *bytes* (byte number) have been
2890  * 		accumulated.
2891  *
2892  * 		This can be used when one needs a specific number of bytes
2893  * 		before a verdict can be assigned, even if the data spans
2894  * 		multiple **sendmsg**\ () or **sendfile**\ () calls. The extreme
2895  * 		case would be a user calling **sendmsg**\ () repeatedly with
2896  * 		1-byte long message segments. Obviously, this is bad for
2897  * 		performance, but it is still valid. If the eBPF program needs
2898  * 		*bytes* bytes to validate a header, this helper can be used to
2899  * 		prevent the eBPF program to be called again until *bytes* have
2900  * 		been accumulated.
2901  * 	Return
2902  * 		0
2903  *
2904  * long bpf_msg_pull_data(struct sk_msg_buff *msg, u32 start, u32 end, u64 flags)
2905  * 	Description
2906  * 		For socket policies, pull in non-linear data from user space
2907  * 		for *msg* and set pointers *msg*\ **->data** and *msg*\
2908  * 		**->data_end** to *start* and *end* bytes offsets into *msg*,
2909  * 		respectively.
2910  *
2911  * 		If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
2912  * 		*msg* it can only parse data that the (**data**, **data_end**)
2913  * 		pointers have already consumed. For **sendmsg**\ () hooks this
2914  * 		is likely the first scatterlist element. But for calls relying
2915  * 		on the **sendpage** handler (e.g. **sendfile**\ ()) this will
2916  * 		be the range (**0**, **0**) because the data is shared with
2917  * 		user space and by default the objective is to avoid allowing
2918  * 		user space to modify data while (or after) eBPF verdict is
2919  * 		being decided. This helper can be used to pull in data and to
2920  * 		set the start and end pointer to given values. Data will be
2921  * 		copied if necessary (i.e. if data was not linear and if start
2922  * 		and end pointers do not point to the same chunk).
2923  *
2924  * 		A call to this helper is susceptible to change the underlying
2925  * 		packet buffer. Therefore, at load time, all checks on pointers
2926  * 		previously done by the verifier are invalidated and must be
2927  * 		performed again, if the helper is used in combination with
2928  * 		direct packet access.
2929  *
2930  * 		All values for *flags* are reserved for future usage, and must
2931  * 		be left at zero.
2932  * 	Return
2933  * 		0 on success, or a negative error in case of failure.
2934  *
2935  * long bpf_bind(struct bpf_sock_addr *ctx, struct sockaddr *addr, int addr_len)
2936  * 	Description
2937  * 		Bind the socket associated to *ctx* to the address pointed by
2938  * 		*addr*, of length *addr_len*. This allows for making outgoing
2939  * 		connection from the desired IP address, which can be useful for
2940  * 		example when all processes inside a cgroup should use one
2941  * 		single IP address on a host that has multiple IP configured.
2942  *
2943  * 		This helper works for IPv4 and IPv6, TCP and UDP sockets. The
2944  * 		domain (*addr*\ **->sa_family**) must be **AF_INET** (or
2945  * 		**AF_INET6**). It's advised to pass zero port (**sin_port**
2946  * 		or **sin6_port**) which triggers IP_BIND_ADDRESS_NO_PORT-like
2947  * 		behavior and lets the kernel efficiently pick up an unused
2948  * 		port as long as 4-tuple is unique. Passing non-zero port might
2949  * 		lead to degraded performance.
2950  * 	Return
2951  * 		0 on success, or a negative error in case of failure.
2952  *
2953  * long bpf_xdp_adjust_tail(struct xdp_buff *xdp_md, int delta)
2954  * 	Description
2955  * 		Adjust (move) *xdp_md*\ **->data_end** by *delta* bytes. It is
2956  * 		possible to both shrink and grow the packet tail.
2957  * 		Shrink done via *delta* being a negative integer.
2958  *
2959  * 		A call to this helper is susceptible to change the underlying
2960  * 		packet buffer. Therefore, at load time, all checks on pointers
2961  * 		previously done by the verifier are invalidated and must be
2962  * 		performed again, if the helper is used in combination with
2963  * 		direct packet access.
2964  * 	Return
2965  * 		0 on success, or a negative error in case of failure.
2966  *
2967  * long bpf_skb_get_xfrm_state(struct sk_buff *skb, u32 index, struct bpf_xfrm_state *xfrm_state, u32 size, u64 flags)
2968  * 	Description
2969  * 		Retrieve the XFRM state (IP transform framework, see also
2970  * 		**ip-xfrm(8)**) at *index* in XFRM "security path" for *skb*.
2971  *
2972  * 		The retrieved value is stored in the **struct bpf_xfrm_state**
2973  * 		pointed by *xfrm_state* and of length *size*.
2974  *
2975  * 		All values for *flags* are reserved for future usage, and must
2976  * 		be left at zero.
2977  *
2978  * 		This helper is available only if the kernel was compiled with
2979  * 		**CONFIG_XFRM** configuration option.
2980  * 	Return
2981  * 		0 on success, or a negative error in case of failure.
2982  *
2983  * long bpf_get_stack(void *ctx, void *buf, u32 size, u64 flags)
2984  * 	Description
2985  * 		Return a user or a kernel stack in bpf program provided buffer.
2986  * 		To achieve this, the helper needs *ctx*, which is a pointer
2987  * 		to the context on which the tracing program is executed.
2988  * 		To store the stacktrace, the bpf program provides *buf* with
2989  * 		a nonnegative *size*.
2990  *
2991  * 		The last argument, *flags*, holds the number of stack frames to
2992  * 		skip (from 0 to 255), masked with
2993  * 		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
2994  * 		the following flags:
2995  *
2996  * 		**BPF_F_USER_STACK**
2997  * 			Collect a user space stack instead of a kernel stack.
2998  * 		**BPF_F_USER_BUILD_ID**
2999  * 			Collect buildid+offset instead of ips for user stack,
3000  * 			only valid if **BPF_F_USER_STACK** is also specified.
3001  *
3002  * 		**bpf_get_stack**\ () can collect up to
3003  * 		**PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
3004  * 		to sufficient large buffer size. Note that
3005  * 		this limit can be controlled with the **sysctl** program, and
3006  * 		that it should be manually increased in order to profile long
3007  * 		user stacks (such as stacks for Java programs). To do so, use:
3008  *
3009  * 		::
3010  *
3011  * 			# sysctl kernel.perf_event_max_stack=<new value>
3012  * 	Return
3013  * 		A non-negative value equal to or less than *size* on success,
3014  * 		or a negative error in case of failure.
3015  *
3016  * long bpf_skb_load_bytes_relative(const void *skb, u32 offset, void *to, u32 len, u32 start_header)
3017  * 	Description
3018  * 		This helper is similar to **bpf_skb_load_bytes**\ () in that
3019  * 		it provides an easy way to load *len* bytes from *offset*
3020  * 		from the packet associated to *skb*, into the buffer pointed
3021  * 		by *to*. The difference to **bpf_skb_load_bytes**\ () is that
3022  * 		a fifth argument *start_header* exists in order to select a
3023  * 		base offset to start from. *start_header* can be one of:
3024  *
3025  * 		**BPF_HDR_START_MAC**
3026  * 			Base offset to load data from is *skb*'s mac header.
3027  * 		**BPF_HDR_START_NET**
3028  * 			Base offset to load data from is *skb*'s network header.
3029  *
3030  * 		In general, "direct packet access" is the preferred method to
3031  * 		access packet data, however, this helper is in particular useful
3032  * 		in socket filters where *skb*\ **->data** does not always point
3033  * 		to the start of the mac header and where "direct packet access"
3034  * 		is not available.
3035  * 	Return
3036  * 		0 on success, or a negative error in case of failure.
3037  *
3038  * long bpf_fib_lookup(void *ctx, struct bpf_fib_lookup *params, int plen, u32 flags)
3039  *	Description
3040  *		Do FIB lookup in kernel tables using parameters in *params*.
3041  *		If lookup is successful and result shows packet is to be
3042  *		forwarded, the neighbor tables are searched for the nexthop.
3043  *		If successful (ie., FIB lookup shows forwarding and nexthop
3044  *		is resolved), the nexthop address is returned in ipv4_dst
3045  *		or ipv6_dst based on family, smac is set to mac address of
3046  *		egress device, dmac is set to nexthop mac address, rt_metric
3047  *		is set to metric from route (IPv4/IPv6 only), and ifindex
3048  *		is set to the device index of the nexthop from the FIB lookup.
3049  *
3050  *		*plen* argument is the size of the passed in struct.
3051  *		*flags* argument can be a combination of one or more of the
3052  *		following values:
3053  *
3054  *		**BPF_FIB_LOOKUP_DIRECT**
3055  *			Do a direct table lookup vs full lookup using FIB
3056  *			rules.
3057  *		**BPF_FIB_LOOKUP_OUTPUT**
3058  *			Perform lookup from an egress perspective (default is
3059  *			ingress).
3060  *
3061  *		*ctx* is either **struct xdp_md** for XDP programs or
3062  *		**struct sk_buff** tc cls_act programs.
3063  *	Return
3064  *		* < 0 if any input argument is invalid
3065  *		*   0 on success (packet is forwarded, nexthop neighbor exists)
3066  *		* > 0 one of **BPF_FIB_LKUP_RET_** codes explaining why the
3067  *		  packet is not forwarded or needs assist from full stack
3068  *
3069  *		If lookup fails with BPF_FIB_LKUP_RET_FRAG_NEEDED, then the MTU
3070  *		was exceeded and output params->mtu_result contains the MTU.
3071  *
3072  * long bpf_sock_hash_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
3073  *	Description
3074  *		Add an entry to, or update a sockhash *map* referencing sockets.
3075  *		The *skops* is used as a new value for the entry associated to
3076  *		*key*. *flags* is one of:
3077  *
3078  *		**BPF_NOEXIST**
3079  *			The entry for *key* must not exist in the map.
3080  *		**BPF_EXIST**
3081  *			The entry for *key* must already exist in the map.
3082  *		**BPF_ANY**
3083  *			No condition on the existence of the entry for *key*.
3084  *
3085  *		If the *map* has eBPF programs (parser and verdict), those will
3086  *		be inherited by the socket being added. If the socket is
3087  *		already attached to eBPF programs, this results in an error.
3088  *	Return
3089  *		0 on success, or a negative error in case of failure.
3090  *
3091  * long bpf_msg_redirect_hash(struct sk_msg_buff *msg, struct bpf_map *map, void *key, u64 flags)
3092  *	Description
3093  *		This helper is used in programs implementing policies at the
3094  *		socket level. If the message *msg* is allowed to pass (i.e. if
3095  *		the verdict eBPF program returns **SK_PASS**), redirect it to
3096  *		the socket referenced by *map* (of type
3097  *		**BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
3098  *		egress interfaces can be used for redirection. The
3099  *		**BPF_F_INGRESS** value in *flags* is used to make the
3100  *		distinction (ingress path is selected if the flag is present,
3101  *		egress path otherwise). This is the only flag supported for now.
3102  *	Return
3103  *		**SK_PASS** on success, or **SK_DROP** on error.
3104  *
3105  * long bpf_sk_redirect_hash(struct sk_buff *skb, struct bpf_map *map, void *key, u64 flags)
3106  *	Description
3107  *		This helper is used in programs implementing policies at the
3108  *		skb socket level. If the sk_buff *skb* is allowed to pass (i.e.
3109  *		if the verdict eBPF program returns **SK_PASS**), redirect it
3110  *		to the socket referenced by *map* (of type
3111  *		**BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
3112  *		egress interfaces can be used for redirection. The
3113  *		**BPF_F_INGRESS** value in *flags* is used to make the
3114  *		distinction (ingress path is selected if the flag is present,
3115  *		egress otherwise). This is the only flag supported for now.
3116  *	Return
3117  *		**SK_PASS** on success, or **SK_DROP** on error.
3118  *
3119  * long bpf_lwt_push_encap(struct sk_buff *skb, u32 type, void *hdr, u32 len)
3120  *	Description
3121  *		Encapsulate the packet associated to *skb* within a Layer 3
3122  *		protocol header. This header is provided in the buffer at
3123  *		address *hdr*, with *len* its size in bytes. *type* indicates
3124  *		the protocol of the header and can be one of:
3125  *
3126  *		**BPF_LWT_ENCAP_SEG6**
3127  *			IPv6 encapsulation with Segment Routing Header
3128  *			(**struct ipv6_sr_hdr**). *hdr* only contains the SRH,
3129  *			the IPv6 header is computed by the kernel.
3130  *		**BPF_LWT_ENCAP_SEG6_INLINE**
3131  *			Only works if *skb* contains an IPv6 packet. Insert a
3132  *			Segment Routing Header (**struct ipv6_sr_hdr**) inside
3133  *			the IPv6 header.
3134  *		**BPF_LWT_ENCAP_IP**
3135  *			IP encapsulation (GRE/GUE/IPIP/etc). The outer header
3136  *			must be IPv4 or IPv6, followed by zero or more
3137  *			additional headers, up to **LWT_BPF_MAX_HEADROOM**
3138  *			total bytes in all prepended headers. Please note that
3139  *			if **skb_is_gso**\ (*skb*) is true, no more than two
3140  *			headers can be prepended, and the inner header, if
3141  *			present, should be either GRE or UDP/GUE.
3142  *
3143  *		**BPF_LWT_ENCAP_SEG6**\ \* types can be called by BPF programs
3144  *		of type **BPF_PROG_TYPE_LWT_IN**; **BPF_LWT_ENCAP_IP** type can
3145  *		be called by bpf programs of types **BPF_PROG_TYPE_LWT_IN** and
3146  *		**BPF_PROG_TYPE_LWT_XMIT**.
3147  *
3148  * 		A call to this helper is susceptible to change the underlying
3149  * 		packet buffer. Therefore, at load time, all checks on pointers
3150  * 		previously done by the verifier are invalidated and must be
3151  * 		performed again, if the helper is used in combination with
3152  * 		direct packet access.
3153  *	Return
3154  * 		0 on success, or a negative error in case of failure.
3155  *
3156  * long bpf_lwt_seg6_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len)
3157  *	Description
3158  *		Store *len* bytes from address *from* into the packet
3159  *		associated to *skb*, at *offset*. Only the flags, tag and TLVs
3160  *		inside the outermost IPv6 Segment Routing Header can be
3161  *		modified through this helper.
3162  *
3163  * 		A call to this helper is susceptible to change the underlying
3164  * 		packet buffer. Therefore, at load time, all checks on pointers
3165  * 		previously done by the verifier are invalidated and must be
3166  * 		performed again, if the helper is used in combination with
3167  * 		direct packet access.
3168  *	Return
3169  * 		0 on success, or a negative error in case of failure.
3170  *
3171  * long bpf_lwt_seg6_adjust_srh(struct sk_buff *skb, u32 offset, s32 delta)
3172  *	Description
3173  *		Adjust the size allocated to TLVs in the outermost IPv6
3174  *		Segment Routing Header contained in the packet associated to
3175  *		*skb*, at position *offset* by *delta* bytes. Only offsets
3176  *		after the segments are accepted. *delta* can be as well
3177  *		positive (growing) as negative (shrinking).
3178  *
3179  * 		A call to this helper is susceptible to change the underlying
3180  * 		packet buffer. Therefore, at load time, all checks on pointers
3181  * 		previously done by the verifier are invalidated and must be
3182  * 		performed again, if the helper is used in combination with
3183  * 		direct packet access.
3184  *	Return
3185  * 		0 on success, or a negative error in case of failure.
3186  *
3187  * long bpf_lwt_seg6_action(struct sk_buff *skb, u32 action, void *param, u32 param_len)
3188  *	Description
3189  *		Apply an IPv6 Segment Routing action of type *action* to the
3190  *		packet associated to *skb*. Each action takes a parameter
3191  *		contained at address *param*, and of length *param_len* bytes.
3192  *		*action* can be one of:
3193  *
3194  *		**SEG6_LOCAL_ACTION_END_X**
3195  *			End.X action: Endpoint with Layer-3 cross-connect.
3196  *			Type of *param*: **struct in6_addr**.
3197  *		**SEG6_LOCAL_ACTION_END_T**
3198  *			End.T action: Endpoint with specific IPv6 table lookup.
3199  *			Type of *param*: **int**.
3200  *		**SEG6_LOCAL_ACTION_END_B6**
3201  *			End.B6 action: Endpoint bound to an SRv6 policy.
3202  *			Type of *param*: **struct ipv6_sr_hdr**.
3203  *		**SEG6_LOCAL_ACTION_END_B6_ENCAP**
3204  *			End.B6.Encap action: Endpoint bound to an SRv6
3205  *			encapsulation policy.
3206  *			Type of *param*: **struct ipv6_sr_hdr**.
3207  *
3208  * 		A call to this helper is susceptible to change the underlying
3209  * 		packet buffer. Therefore, at load time, all checks on pointers
3210  * 		previously done by the verifier are invalidated and must be
3211  * 		performed again, if the helper is used in combination with
3212  * 		direct packet access.
3213  *	Return
3214  * 		0 on success, or a negative error in case of failure.
3215  *
3216  * long bpf_rc_repeat(void *ctx)
3217  *	Description
3218  *		This helper is used in programs implementing IR decoding, to
3219  *		report a successfully decoded repeat key message. This delays
3220  *		the generation of a key up event for previously generated
3221  *		key down event.
3222  *
3223  *		Some IR protocols like NEC have a special IR message for
3224  *		repeating last button, for when a button is held down.
3225  *
3226  *		The *ctx* should point to the lirc sample as passed into
3227  *		the program.
3228  *
3229  *		This helper is only available is the kernel was compiled with
3230  *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
3231  *		"**y**".
3232  *	Return
3233  *		0
3234  *
3235  * long bpf_rc_keydown(void *ctx, u32 protocol, u64 scancode, u32 toggle)
3236  *	Description
3237  *		This helper is used in programs implementing IR decoding, to
3238  *		report a successfully decoded key press with *scancode*,
3239  *		*toggle* value in the given *protocol*. The scancode will be
3240  *		translated to a keycode using the rc keymap, and reported as
3241  *		an input key down event. After a period a key up event is
3242  *		generated. This period can be extended by calling either
3243  *		**bpf_rc_keydown**\ () again with the same values, or calling
3244  *		**bpf_rc_repeat**\ ().
3245  *
3246  *		Some protocols include a toggle bit, in case the button was
3247  *		released and pressed again between consecutive scancodes.
3248  *
3249  *		The *ctx* should point to the lirc sample as passed into
3250  *		the program.
3251  *
3252  *		The *protocol* is the decoded protocol number (see
3253  *		**enum rc_proto** for some predefined values).
3254  *
3255  *		This helper is only available is the kernel was compiled with
3256  *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
3257  *		"**y**".
3258  *	Return
3259  *		0
3260  *
3261  * u64 bpf_skb_cgroup_id(struct sk_buff *skb)
3262  * 	Description
3263  * 		Return the cgroup v2 id of the socket associated with the *skb*.
3264  * 		This is roughly similar to the **bpf_get_cgroup_classid**\ ()
3265  * 		helper for cgroup v1 by providing a tag resp. identifier that
3266  * 		can be matched on or used for map lookups e.g. to implement
3267  * 		policy. The cgroup v2 id of a given path in the hierarchy is
3268  * 		exposed in user space through the f_handle API in order to get
3269  * 		to the same 64-bit id.
3270  *
3271  * 		This helper can be used on TC egress path, but not on ingress,
3272  * 		and is available only if the kernel was compiled with the
3273  * 		**CONFIG_SOCK_CGROUP_DATA** configuration option.
3274  * 	Return
3275  * 		The id is returned or 0 in case the id could not be retrieved.
3276  *
3277  * u64 bpf_get_current_cgroup_id(void)
3278  * 	Description
3279  * 		Get the current cgroup id based on the cgroup within which
3280  * 		the current task is running.
3281  * 	Return
3282  * 		A 64-bit integer containing the current cgroup id based
3283  * 		on the cgroup within which the current task is running.
3284  *
3285  * void *bpf_get_local_storage(void *map, u64 flags)
3286  *	Description
3287  *		Get the pointer to the local storage area.
3288  *		The type and the size of the local storage is defined
3289  *		by the *map* argument.
3290  *		The *flags* meaning is specific for each map type,
3291  *		and has to be 0 for cgroup local storage.
3292  *
3293  *		Depending on the BPF program type, a local storage area
3294  *		can be shared between multiple instances of the BPF program,
3295  *		running simultaneously.
3296  *
3297  *		A user should care about the synchronization by himself.
3298  *		For example, by using the **BPF_ATOMIC** instructions to alter
3299  *		the shared data.
3300  *	Return
3301  *		A pointer to the local storage area.
3302  *
3303  * long bpf_sk_select_reuseport(struct sk_reuseport_md *reuse, struct bpf_map *map, void *key, u64 flags)
3304  *	Description
3305  *		Select a **SO_REUSEPORT** socket from a
3306  *		**BPF_MAP_TYPE_REUSEPORT_SOCKARRAY** *map*.
3307  *		It checks the selected socket is matching the incoming
3308  *		request in the socket buffer.
3309  *	Return
3310  *		0 on success, or a negative error in case of failure.
3311  *
3312  * u64 bpf_skb_ancestor_cgroup_id(struct sk_buff *skb, int ancestor_level)
3313  *	Description
3314  *		Return id of cgroup v2 that is ancestor of cgroup associated
3315  *		with the *skb* at the *ancestor_level*.  The root cgroup is at
3316  *		*ancestor_level* zero and each step down the hierarchy
3317  *		increments the level. If *ancestor_level* == level of cgroup
3318  *		associated with *skb*, then return value will be same as that
3319  *		of **bpf_skb_cgroup_id**\ ().
3320  *
3321  *		The helper is useful to implement policies based on cgroups
3322  *		that are upper in hierarchy than immediate cgroup associated
3323  *		with *skb*.
3324  *
3325  *		The format of returned id and helper limitations are same as in
3326  *		**bpf_skb_cgroup_id**\ ().
3327  *	Return
3328  *		The id is returned or 0 in case the id could not be retrieved.
3329  *
3330  * struct bpf_sock *bpf_sk_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
3331  *	Description
3332  *		Look for TCP socket matching *tuple*, optionally in a child
3333  *		network namespace *netns*. The return value must be checked,
3334  *		and if non-**NULL**, released via **bpf_sk_release**\ ().
3335  *
3336  *		The *ctx* should point to the context of the program, such as
3337  *		the skb or socket (depending on the hook in use). This is used
3338  *		to determine the base network namespace for the lookup.
3339  *
3340  *		*tuple_size* must be one of:
3341  *
3342  *		**sizeof**\ (*tuple*\ **->ipv4**)
3343  *			Look for an IPv4 socket.
3344  *		**sizeof**\ (*tuple*\ **->ipv6**)
3345  *			Look for an IPv6 socket.
3346  *
3347  *		If the *netns* is a negative signed 32-bit integer, then the
3348  *		socket lookup table in the netns associated with the *ctx*
3349  *		will be used. For the TC hooks, this is the netns of the device
3350  *		in the skb. For socket hooks, this is the netns of the socket.
3351  *		If *netns* is any other signed 32-bit value greater than or
3352  *		equal to zero then it specifies the ID of the netns relative to
3353  *		the netns associated with the *ctx*. *netns* values beyond the
3354  *		range of 32-bit integers are reserved for future use.
3355  *
3356  *		All values for *flags* are reserved for future usage, and must
3357  *		be left at zero.
3358  *
3359  *		This helper is available only if the kernel was compiled with
3360  *		**CONFIG_NET** configuration option.
3361  *	Return
3362  *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
3363  *		For sockets with reuseport option, the **struct bpf_sock**
3364  *		result is from *reuse*\ **->socks**\ [] using the hash of the
3365  *		tuple.
3366  *
3367  * struct bpf_sock *bpf_sk_lookup_udp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
3368  *	Description
3369  *		Look for UDP socket matching *tuple*, optionally in a child
3370  *		network namespace *netns*. The return value must be checked,
3371  *		and if non-**NULL**, released via **bpf_sk_release**\ ().
3372  *
3373  *		The *ctx* should point to the context of the program, such as
3374  *		the skb or socket (depending on the hook in use). This is used
3375  *		to determine the base network namespace for the lookup.
3376  *
3377  *		*tuple_size* must be one of:
3378  *
3379  *		**sizeof**\ (*tuple*\ **->ipv4**)
3380  *			Look for an IPv4 socket.
3381  *		**sizeof**\ (*tuple*\ **->ipv6**)
3382  *			Look for an IPv6 socket.
3383  *
3384  *		If the *netns* is a negative signed 32-bit integer, then the
3385  *		socket lookup table in the netns associated with the *ctx*
3386  *		will be used. For the TC hooks, this is the netns of the device
3387  *		in the skb. For socket hooks, this is the netns of the socket.
3388  *		If *netns* is any other signed 32-bit value greater than or
3389  *		equal to zero then it specifies the ID of the netns relative to
3390  *		the netns associated with the *ctx*. *netns* values beyond the
3391  *		range of 32-bit integers are reserved for future use.
3392  *
3393  *		All values for *flags* are reserved for future usage, and must
3394  *		be left at zero.
3395  *
3396  *		This helper is available only if the kernel was compiled with
3397  *		**CONFIG_NET** configuration option.
3398  *	Return
3399  *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
3400  *		For sockets with reuseport option, the **struct bpf_sock**
3401  *		result is from *reuse*\ **->socks**\ [] using the hash of the
3402  *		tuple.
3403  *
3404  * long bpf_sk_release(void *sock)
3405  *	Description
3406  *		Release the reference held by *sock*. *sock* must be a
3407  *		non-**NULL** pointer that was returned from
3408  *		**bpf_sk_lookup_xxx**\ ().
3409  *	Return
3410  *		0 on success, or a negative error in case of failure.
3411  *
3412  * long bpf_map_push_elem(struct bpf_map *map, const void *value, u64 flags)
3413  * 	Description
3414  * 		Push an element *value* in *map*. *flags* is one of:
3415  *
3416  * 		**BPF_EXIST**
3417  * 			If the queue/stack is full, the oldest element is
3418  * 			removed to make room for this.
3419  * 	Return
3420  * 		0 on success, or a negative error in case of failure.
3421  *
3422  * long bpf_map_pop_elem(struct bpf_map *map, void *value)
3423  * 	Description
3424  * 		Pop an element from *map*.
3425  * 	Return
3426  * 		0 on success, or a negative error in case of failure.
3427  *
3428  * long bpf_map_peek_elem(struct bpf_map *map, void *value)
3429  * 	Description
3430  * 		Get an element from *map* without removing it.
3431  * 	Return
3432  * 		0 on success, or a negative error in case of failure.
3433  *
3434  * long bpf_msg_push_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)
3435  *	Description
3436  *		For socket policies, insert *len* bytes into *msg* at offset
3437  *		*start*.
3438  *
3439  *		If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
3440  *		*msg* it may want to insert metadata or options into the *msg*.
3441  *		This can later be read and used by any of the lower layer BPF
3442  *		hooks.
3443  *
3444  *		This helper may fail if under memory pressure (a malloc
3445  *		fails) in these cases BPF programs will get an appropriate
3446  *		error and BPF programs will need to handle them.
3447  *	Return
3448  *		0 on success, or a negative error in case of failure.
3449  *
3450  * long bpf_msg_pop_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)
3451  *	Description
3452  *		Will remove *len* bytes from a *msg* starting at byte *start*.
3453  *		This may result in **ENOMEM** errors under certain situations if
3454  *		an allocation and copy are required due to a full ring buffer.
3455  *		However, the helper will try to avoid doing the allocation
3456  *		if possible. Other errors can occur if input parameters are
3457  *		invalid either due to *start* byte not being valid part of *msg*
3458  *		payload and/or *pop* value being to large.
3459  *	Return
3460  *		0 on success, or a negative error in case of failure.
3461  *
3462  * long bpf_rc_pointer_rel(void *ctx, s32 rel_x, s32 rel_y)
3463  *	Description
3464  *		This helper is used in programs implementing IR decoding, to
3465  *		report a successfully decoded pointer movement.
3466  *
3467  *		The *ctx* should point to the lirc sample as passed into
3468  *		the program.
3469  *
3470  *		This helper is only available is the kernel was compiled with
3471  *		the **CONFIG_BPF_LIRC_MODE2** configuration option set to
3472  *		"**y**".
3473  *	Return
3474  *		0
3475  *
3476  * long bpf_spin_lock(struct bpf_spin_lock *lock)
3477  *	Description
3478  *		Acquire a spinlock represented by the pointer *lock*, which is
3479  *		stored as part of a value of a map. Taking the lock allows to
3480  *		safely update the rest of the fields in that value. The
3481  *		spinlock can (and must) later be released with a call to
3482  *		**bpf_spin_unlock**\ (\ *lock*\ ).
3483  *
3484  *		Spinlocks in BPF programs come with a number of restrictions
3485  *		and constraints:
3486  *
3487  *		* **bpf_spin_lock** objects are only allowed inside maps of
3488  *		  types **BPF_MAP_TYPE_HASH** and **BPF_MAP_TYPE_ARRAY** (this
3489  *		  list could be extended in the future).
3490  *		* BTF description of the map is mandatory.
3491  *		* The BPF program can take ONE lock at a time, since taking two
3492  *		  or more could cause dead locks.
3493  *		* Only one **struct bpf_spin_lock** is allowed per map element.
3494  *		* When the lock is taken, calls (either BPF to BPF or helpers)
3495  *		  are not allowed.
3496  *		* The **BPF_LD_ABS** and **BPF_LD_IND** instructions are not
3497  *		  allowed inside a spinlock-ed region.
3498  *		* The BPF program MUST call **bpf_spin_unlock**\ () to release
3499  *		  the lock, on all execution paths, before it returns.
3500  *		* The BPF program can access **struct bpf_spin_lock** only via
3501  *		  the **bpf_spin_lock**\ () and **bpf_spin_unlock**\ ()
3502  *		  helpers. Loading or storing data into the **struct
3503  *		  bpf_spin_lock** *lock*\ **;** field of a map is not allowed.
3504  *		* To use the **bpf_spin_lock**\ () helper, the BTF description
3505  *		  of the map value must be a struct and have **struct
3506  *		  bpf_spin_lock** *anyname*\ **;** field at the top level.
3507  *		  Nested lock inside another struct is not allowed.
3508  *		* The **struct bpf_spin_lock** *lock* field in a map value must
3509  *		  be aligned on a multiple of 4 bytes in that value.
3510  *		* Syscall with command **BPF_MAP_LOOKUP_ELEM** does not copy
3511  *		  the **bpf_spin_lock** field to user space.
3512  *		* Syscall with command **BPF_MAP_UPDATE_ELEM**, or update from
3513  *		  a BPF program, do not update the **bpf_spin_lock** field.
3514  *		* **bpf_spin_lock** cannot be on the stack or inside a
3515  *		  networking packet (it can only be inside of a map values).
3516  *		* **bpf_spin_lock** is available to root only.
3517  *		* Tracing programs and socket filter programs cannot use
3518  *		  **bpf_spin_lock**\ () due to insufficient preemption checks
3519  *		  (but this may change in the future).
3520  *		* **bpf_spin_lock** is not allowed in inner maps of map-in-map.
3521  *	Return
3522  *		0
3523  *
3524  * long bpf_spin_unlock(struct bpf_spin_lock *lock)
3525  *	Description
3526  *		Release the *lock* previously locked by a call to
3527  *		**bpf_spin_lock**\ (\ *lock*\ ).
3528  *	Return
3529  *		0
3530  *
3531  * struct bpf_sock *bpf_sk_fullsock(struct bpf_sock *sk)
3532  *	Description
3533  *		This helper gets a **struct bpf_sock** pointer such
3534  *		that all the fields in this **bpf_sock** can be accessed.
3535  *	Return
3536  *		A **struct bpf_sock** pointer on success, or **NULL** in
3537  *		case of failure.
3538  *
3539  * struct bpf_tcp_sock *bpf_tcp_sock(struct bpf_sock *sk)
3540  *	Description
3541  *		This helper gets a **struct bpf_tcp_sock** pointer from a
3542  *		**struct bpf_sock** pointer.
3543  *	Return
3544  *		A **struct bpf_tcp_sock** pointer on success, or **NULL** in
3545  *		case of failure.
3546  *
3547  * long bpf_skb_ecn_set_ce(struct sk_buff *skb)
3548  *	Description
3549  *		Set ECN (Explicit Congestion Notification) field of IP header
3550  *		to **CE** (Congestion Encountered) if current value is **ECT**
3551  *		(ECN Capable Transport). Otherwise, do nothing. Works with IPv6
3552  *		and IPv4.
3553  *	Return
3554  *		1 if the **CE** flag is set (either by the current helper call
3555  *		or because it was already present), 0 if it is not set.
3556  *
3557  * struct bpf_sock *bpf_get_listener_sock(struct bpf_sock *sk)
3558  *	Description
3559  *		Return a **struct bpf_sock** pointer in **TCP_LISTEN** state.
3560  *		**bpf_sk_release**\ () is unnecessary and not allowed.
3561  *	Return
3562  *		A **struct bpf_sock** pointer on success, or **NULL** in
3563  *		case of failure.
3564  *
3565  * struct bpf_sock *bpf_skc_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
3566  *	Description
3567  *		Look for TCP socket matching *tuple*, optionally in a child
3568  *		network namespace *netns*. The return value must be checked,
3569  *		and if non-**NULL**, released via **bpf_sk_release**\ ().
3570  *
3571  *		This function is identical to **bpf_sk_lookup_tcp**\ (), except
3572  *		that it also returns timewait or request sockets. Use
3573  *		**bpf_sk_fullsock**\ () or **bpf_tcp_sock**\ () to access the
3574  *		full structure.
3575  *
3576  *		This helper is available only if the kernel was compiled with
3577  *		**CONFIG_NET** configuration option.
3578  *	Return
3579  *		Pointer to **struct bpf_sock**, or **NULL** in case of failure.
3580  *		For sockets with reuseport option, the **struct bpf_sock**
3581  *		result is from *reuse*\ **->socks**\ [] using the hash of the
3582  *		tuple.
3583  *
3584  * long bpf_tcp_check_syncookie(void *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
3585  * 	Description
3586  * 		Check whether *iph* and *th* contain a valid SYN cookie ACK for
3587  * 		the listening socket in *sk*.
3588  *
3589  * 		*iph* points to the start of the IPv4 or IPv6 header, while
3590  * 		*iph_len* contains **sizeof**\ (**struct iphdr**) or
3591  * 		**sizeof**\ (**struct ip6hdr**).
3592  *
3593  * 		*th* points to the start of the TCP header, while *th_len*
3594  * 		contains **sizeof**\ (**struct tcphdr**).
3595  * 	Return
3596  * 		0 if *iph* and *th* are a valid SYN cookie ACK, or a negative
3597  * 		error otherwise.
3598  *
3599  * long bpf_sysctl_get_name(struct bpf_sysctl *ctx, char *buf, size_t buf_len, u64 flags)
3600  *	Description
3601  *		Get name of sysctl in /proc/sys/ and copy it into provided by
3602  *		program buffer *buf* of size *buf_len*.
3603  *
3604  *		The buffer is always NUL terminated, unless it's zero-sized.
3605  *
3606  *		If *flags* is zero, full name (e.g. "net/ipv4/tcp_mem") is
3607  *		copied. Use **BPF_F_SYSCTL_BASE_NAME** flag to copy base name
3608  *		only (e.g. "tcp_mem").
3609  *	Return
3610  *		Number of character copied (not including the trailing NUL).
3611  *
3612  *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
3613  *		truncated name in this case).
3614  *
3615  * long bpf_sysctl_get_current_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)
3616  *	Description
3617  *		Get current value of sysctl as it is presented in /proc/sys
3618  *		(incl. newline, etc), and copy it as a string into provided
3619  *		by program buffer *buf* of size *buf_len*.
3620  *
3621  *		The whole value is copied, no matter what file position user
3622  *		space issued e.g. sys_read at.
3623  *
3624  *		The buffer is always NUL terminated, unless it's zero-sized.
3625  *	Return
3626  *		Number of character copied (not including the trailing NUL).
3627  *
3628  *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
3629  *		truncated name in this case).
3630  *
3631  *		**-EINVAL** if current value was unavailable, e.g. because
3632  *		sysctl is uninitialized and read returns -EIO for it.
3633  *
3634  * long bpf_sysctl_get_new_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)
3635  *	Description
3636  *		Get new value being written by user space to sysctl (before
3637  *		the actual write happens) and copy it as a string into
3638  *		provided by program buffer *buf* of size *buf_len*.
3639  *
3640  *		User space may write new value at file position > 0.
3641  *
3642  *		The buffer is always NUL terminated, unless it's zero-sized.
3643  *	Return
3644  *		Number of character copied (not including the trailing NUL).
3645  *
3646  *		**-E2BIG** if the buffer wasn't big enough (*buf* will contain
3647  *		truncated name in this case).
3648  *
3649  *		**-EINVAL** if sysctl is being read.
3650  *
3651  * long bpf_sysctl_set_new_value(struct bpf_sysctl *ctx, const char *buf, size_t buf_len)
3652  *	Description
3653  *		Override new value being written by user space to sysctl with
3654  *		value provided by program in buffer *buf* of size *buf_len*.
3655  *
3656  *		*buf* should contain a string in same form as provided by user
3657  *		space on sysctl write.
3658  *
3659  *		User space may write new value at file position > 0. To override
3660  *		the whole sysctl value file position should be set to zero.
3661  *	Return
3662  *		0 on success.
3663  *
3664  *		**-E2BIG** if the *buf_len* is too big.
3665  *
3666  *		**-EINVAL** if sysctl is being read.
3667  *
3668  * long bpf_strtol(const char *buf, size_t buf_len, u64 flags, long *res)
3669  *	Description
3670  *		Convert the initial part of the string from buffer *buf* of
3671  *		size *buf_len* to a long integer according to the given base
3672  *		and save the result in *res*.
3673  *
3674  *		The string may begin with an arbitrary amount of white space
3675  *		(as determined by **isspace**\ (3)) followed by a single
3676  *		optional '**-**' sign.
3677  *
3678  *		Five least significant bits of *flags* encode base, other bits
3679  *		are currently unused.
3680  *
3681  *		Base must be either 8, 10, 16 or 0 to detect it automatically
3682  *		similar to user space **strtol**\ (3).
3683  *	Return
3684  *		Number of characters consumed on success. Must be positive but
3685  *		no more than *buf_len*.
3686  *
3687  *		**-EINVAL** if no valid digits were found or unsupported base
3688  *		was provided.
3689  *
3690  *		**-ERANGE** if resulting value was out of range.
3691  *
3692  * long bpf_strtoul(const char *buf, size_t buf_len, u64 flags, unsigned long *res)
3693  *	Description
3694  *		Convert the initial part of the string from buffer *buf* of
3695  *		size *buf_len* to an unsigned long integer according to the
3696  *		given base and save the result in *res*.
3697  *
3698  *		The string may begin with an arbitrary amount of white space
3699  *		(as determined by **isspace**\ (3)).
3700  *
3701  *		Five least significant bits of *flags* encode base, other bits
3702  *		are currently unused.
3703  *
3704  *		Base must be either 8, 10, 16 or 0 to detect it automatically
3705  *		similar to user space **strtoul**\ (3).
3706  *	Return
3707  *		Number of characters consumed on success. Must be positive but
3708  *		no more than *buf_len*.
3709  *
3710  *		**-EINVAL** if no valid digits were found or unsupported base
3711  *		was provided.
3712  *
3713  *		**-ERANGE** if resulting value was out of range.
3714  *
3715  * void *bpf_sk_storage_get(struct bpf_map *map, void *sk, void *value, u64 flags)
3716  *	Description
3717  *		Get a bpf-local-storage from a *sk*.
3718  *
3719  *		Logically, it could be thought of getting the value from
3720  *		a *map* with *sk* as the **key**.  From this
3721  *		perspective,  the usage is not much different from
3722  *		**bpf_map_lookup_elem**\ (*map*, **&**\ *sk*) except this
3723  *		helper enforces the key must be a full socket and the map must
3724  *		be a **BPF_MAP_TYPE_SK_STORAGE** also.
3725  *
3726  *		Underneath, the value is stored locally at *sk* instead of
3727  *		the *map*.  The *map* is used as the bpf-local-storage
3728  *		"type". The bpf-local-storage "type" (i.e. the *map*) is
3729  *		searched against all bpf-local-storages residing at *sk*.
3730  *
3731  *		*sk* is a kernel **struct sock** pointer for LSM program.
3732  *		*sk* is a **struct bpf_sock** pointer for other program types.
3733  *
3734  *		An optional *flags* (**BPF_SK_STORAGE_GET_F_CREATE**) can be
3735  *		used such that a new bpf-local-storage will be
3736  *		created if one does not exist.  *value* can be used
3737  *		together with **BPF_SK_STORAGE_GET_F_CREATE** to specify
3738  *		the initial value of a bpf-local-storage.  If *value* is
3739  *		**NULL**, the new bpf-local-storage will be zero initialized.
3740  *	Return
3741  *		A bpf-local-storage pointer is returned on success.
3742  *
3743  *		**NULL** if not found or there was an error in adding
3744  *		a new bpf-local-storage.
3745  *
3746  * long bpf_sk_storage_delete(struct bpf_map *map, void *sk)
3747  *	Description
3748  *		Delete a bpf-local-storage from a *sk*.
3749  *	Return
3750  *		0 on success.
3751  *
3752  *		**-ENOENT** if the bpf-local-storage cannot be found.
3753  *		**-EINVAL** if sk is not a fullsock (e.g. a request_sock).
3754  *
3755  * long bpf_send_signal(u32 sig)
3756  *	Description
3757  *		Send signal *sig* to the process of the current task.
3758  *		The signal may be delivered to any of this process's threads.
3759  *	Return
3760  *		0 on success or successfully queued.
3761  *
3762  *		**-EBUSY** if work queue under nmi is full.
3763  *
3764  *		**-EINVAL** if *sig* is invalid.
3765  *
3766  *		**-EPERM** if no permission to send the *sig*.
3767  *
3768  *		**-EAGAIN** if bpf program can try again.
3769  *
3770  * s64 bpf_tcp_gen_syncookie(void *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
3771  *	Description
3772  *		Try to issue a SYN cookie for the packet with corresponding
3773  *		IP/TCP headers, *iph* and *th*, on the listening socket in *sk*.
3774  *
3775  *		*iph* points to the start of the IPv4 or IPv6 header, while
3776  *		*iph_len* contains **sizeof**\ (**struct iphdr**) or
3777  *		**sizeof**\ (**struct ip6hdr**).
3778  *
3779  *		*th* points to the start of the TCP header, while *th_len*
3780  *		contains the length of the TCP header.
3781  *	Return
3782  *		On success, lower 32 bits hold the generated SYN cookie in
3783  *		followed by 16 bits which hold the MSS value for that cookie,
3784  *		and the top 16 bits are unused.
3785  *
3786  *		On failure, the returned value is one of the following:
3787  *
3788  *		**-EINVAL** SYN cookie cannot be issued due to error
3789  *
3790  *		**-ENOENT** SYN cookie should not be issued (no SYN flood)
3791  *
3792  *		**-EOPNOTSUPP** kernel configuration does not enable SYN cookies
3793  *
3794  *		**-EPROTONOSUPPORT** IP packet version is not 4 or 6
3795  *
3796  * long bpf_skb_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
3797  * 	Description
3798  * 		Write raw *data* blob into a special BPF perf event held by
3799  * 		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
3800  * 		event must have the following attributes: **PERF_SAMPLE_RAW**
3801  * 		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
3802  * 		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
3803  *
3804  * 		The *flags* are used to indicate the index in *map* for which
3805  * 		the value must be put, masked with **BPF_F_INDEX_MASK**.
3806  * 		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
3807  * 		to indicate that the index of the current CPU core should be
3808  * 		used.
3809  *
3810  * 		The value to write, of *size*, is passed through eBPF stack and
3811  * 		pointed by *data*.
3812  *
3813  * 		*ctx* is a pointer to in-kernel struct sk_buff.
3814  *
3815  * 		This helper is similar to **bpf_perf_event_output**\ () but
3816  * 		restricted to raw_tracepoint bpf programs.
3817  * 	Return
3818  * 		0 on success, or a negative error in case of failure.
3819  *
3820  * long bpf_probe_read_user(void *dst, u32 size, const void *unsafe_ptr)
3821  * 	Description
3822  * 		Safely attempt to read *size* bytes from user space address
3823  * 		*unsafe_ptr* and store the data in *dst*.
3824  * 	Return
3825  * 		0 on success, or a negative error in case of failure.
3826  *
3827  * long bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
3828  * 	Description
3829  * 		Safely attempt to read *size* bytes from kernel space address
3830  * 		*unsafe_ptr* and store the data in *dst*.
3831  * 	Return
3832  * 		0 on success, or a negative error in case of failure.
3833  *
3834  * long bpf_probe_read_user_str(void *dst, u32 size, const void *unsafe_ptr)
3835  * 	Description
3836  * 		Copy a NUL terminated string from an unsafe user address
3837  * 		*unsafe_ptr* to *dst*. The *size* should include the
3838  * 		terminating NUL byte. In case the string length is smaller than
3839  * 		*size*, the target is not padded with further NUL bytes. If the
3840  * 		string length is larger than *size*, just *size*-1 bytes are
3841  * 		copied and the last byte is set to NUL.
3842  *
3843  * 		On success, returns the number of bytes that were written,
3844  * 		including the terminal NUL. This makes this helper useful in
3845  * 		tracing programs for reading strings, and more importantly to
3846  * 		get its length at runtime. See the following snippet:
3847  *
3848  * 		::
3849  *
3850  * 			SEC("kprobe/sys_open")
3851  * 			void bpf_sys_open(struct pt_regs *ctx)
3852  * 			{
3853  * 			        char buf[PATHLEN]; // PATHLEN is defined to 256
3854  * 			        int res = bpf_probe_read_user_str(buf, sizeof(buf),
3855  * 				                                  ctx->di);
3856  *
3857  * 				// Consume buf, for example push it to
3858  * 				// userspace via bpf_perf_event_output(); we
3859  * 				// can use res (the string length) as event
3860  * 				// size, after checking its boundaries.
3861  * 			}
3862  *
3863  * 		In comparison, using **bpf_probe_read_user**\ () helper here
3864  * 		instead to read the string would require to estimate the length
3865  * 		at compile time, and would often result in copying more memory
3866  * 		than necessary.
3867  *
3868  * 		Another useful use case is when parsing individual process
3869  * 		arguments or individual environment variables navigating
3870  * 		*current*\ **->mm->arg_start** and *current*\
3871  * 		**->mm->env_start**: using this helper and the return value,
3872  * 		one can quickly iterate at the right offset of the memory area.
3873  * 	Return
3874  * 		On success, the strictly positive length of the output string,
3875  * 		including the trailing NUL character. On error, a negative
3876  * 		value.
3877  *
3878  * long bpf_probe_read_kernel_str(void *dst, u32 size, const void *unsafe_ptr)
3879  * 	Description
3880  * 		Copy a NUL terminated string from an unsafe kernel address *unsafe_ptr*
3881  * 		to *dst*. Same semantics as with **bpf_probe_read_user_str**\ () apply.
3882  * 	Return
3883  * 		On success, the strictly positive length of the string, including
3884  * 		the trailing NUL character. On error, a negative value.
3885  *
3886  * long bpf_tcp_send_ack(void *tp, u32 rcv_nxt)
3887  *	Description
3888  *		Send out a tcp-ack. *tp* is the in-kernel struct **tcp_sock**.
3889  *		*rcv_nxt* is the ack_seq to be sent out.
3890  *	Return
3891  *		0 on success, or a negative error in case of failure.
3892  *
3893  * long bpf_send_signal_thread(u32 sig)
3894  *	Description
3895  *		Send signal *sig* to the thread corresponding to the current task.
3896  *	Return
3897  *		0 on success or successfully queued.
3898  *
3899  *		**-EBUSY** if work queue under nmi is full.
3900  *
3901  *		**-EINVAL** if *sig* is invalid.
3902  *
3903  *		**-EPERM** if no permission to send the *sig*.
3904  *
3905  *		**-EAGAIN** if bpf program can try again.
3906  *
3907  * u64 bpf_jiffies64(void)
3908  *	Description
3909  *		Obtain the 64bit jiffies
3910  *	Return
3911  *		The 64 bit jiffies
3912  *
3913  * long bpf_read_branch_records(struct bpf_perf_event_data *ctx, void *buf, u32 size, u64 flags)
3914  *	Description
3915  *		For an eBPF program attached to a perf event, retrieve the
3916  *		branch records (**struct perf_branch_entry**) associated to *ctx*
3917  *		and store it in the buffer pointed by *buf* up to size
3918  *		*size* bytes.
3919  *	Return
3920  *		On success, number of bytes written to *buf*. On error, a
3921  *		negative value.
3922  *
3923  *		The *flags* can be set to **BPF_F_GET_BRANCH_RECORDS_SIZE** to
3924  *		instead return the number of bytes required to store all the
3925  *		branch entries. If this flag is set, *buf* may be NULL.
3926  *
3927  *		**-EINVAL** if arguments invalid or **size** not a multiple
3928  *		of **sizeof**\ (**struct perf_branch_entry**\ ).
3929  *
3930  *		**-ENOENT** if architecture does not support branch records.
3931  *
3932  * long bpf_get_ns_current_pid_tgid(u64 dev, u64 ino, struct bpf_pidns_info *nsdata, u32 size)
3933  *	Description
3934  *		Returns 0 on success, values for *pid* and *tgid* as seen from the current
3935  *		*namespace* will be returned in *nsdata*.
3936  *	Return
3937  *		0 on success, or one of the following in case of failure:
3938  *
3939  *		**-EINVAL** if dev and inum supplied don't match dev_t and inode number
3940  *              with nsfs of current task, or if dev conversion to dev_t lost high bits.
3941  *
3942  *		**-ENOENT** if pidns does not exists for the current task.
3943  *
3944  * long bpf_xdp_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
3945  *	Description
3946  *		Write raw *data* blob into a special BPF perf event held by
3947  *		*map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
3948  *		event must have the following attributes: **PERF_SAMPLE_RAW**
3949  *		as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
3950  *		**PERF_COUNT_SW_BPF_OUTPUT** as **config**.
3951  *
3952  *		The *flags* are used to indicate the index in *map* for which
3953  *		the value must be put, masked with **BPF_F_INDEX_MASK**.
3954  *		Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
3955  *		to indicate that the index of the current CPU core should be
3956  *		used.
3957  *
3958  *		The value to write, of *size*, is passed through eBPF stack and
3959  *		pointed by *data*.
3960  *
3961  *		*ctx* is a pointer to in-kernel struct xdp_buff.
3962  *
3963  *		This helper is similar to **bpf_perf_eventoutput**\ () but
3964  *		restricted to raw_tracepoint bpf programs.
3965  *	Return
3966  *		0 on success, or a negative error in case of failure.
3967  *
3968  * u64 bpf_get_netns_cookie(void *ctx)
3969  * 	Description
3970  * 		Retrieve the cookie (generated by the kernel) of the network
3971  * 		namespace the input *ctx* is associated with. The network
3972  * 		namespace cookie remains stable for its lifetime and provides
3973  * 		a global identifier that can be assumed unique. If *ctx* is
3974  * 		NULL, then the helper returns the cookie for the initial
3975  * 		network namespace. The cookie itself is very similar to that
3976  * 		of **bpf_get_socket_cookie**\ () helper, but for network
3977  * 		namespaces instead of sockets.
3978  * 	Return
3979  * 		A 8-byte long opaque number.
3980  *
3981  * u64 bpf_get_current_ancestor_cgroup_id(int ancestor_level)
3982  * 	Description
3983  * 		Return id of cgroup v2 that is ancestor of the cgroup associated
3984  * 		with the current task at the *ancestor_level*. The root cgroup
3985  * 		is at *ancestor_level* zero and each step down the hierarchy
3986  * 		increments the level. If *ancestor_level* == level of cgroup
3987  * 		associated with the current task, then return value will be the
3988  * 		same as that of **bpf_get_current_cgroup_id**\ ().
3989  *
3990  * 		The helper is useful to implement policies based on cgroups
3991  * 		that are upper in hierarchy than immediate cgroup associated
3992  * 		with the current task.
3993  *
3994  * 		The format of returned id and helper limitations are same as in
3995  * 		**bpf_get_current_cgroup_id**\ ().
3996  * 	Return
3997  * 		The id is returned or 0 in case the id could not be retrieved.
3998  *
3999  * long bpf_sk_assign(struct sk_buff *skb, void *sk, u64 flags)
4000  *	Description
4001  *		Helper is overloaded depending on BPF program type. This
4002  *		description applies to **BPF_PROG_TYPE_SCHED_CLS** and
4003  *		**BPF_PROG_TYPE_SCHED_ACT** programs.
4004  *
4005  *		Assign the *sk* to the *skb*. When combined with appropriate
4006  *		routing configuration to receive the packet towards the socket,
4007  *		will cause *skb* to be delivered to the specified socket.
4008  *		Subsequent redirection of *skb* via  **bpf_redirect**\ (),
4009  *		**bpf_clone_redirect**\ () or other methods outside of BPF may
4010  *		interfere with successful delivery to the socket.
4011  *
4012  *		This operation is only valid from TC ingress path.
4013  *
4014  *		The *flags* argument must be zero.
4015  *	Return
4016  *		0 on success, or a negative error in case of failure:
4017  *
4018  *		**-EINVAL** if specified *flags* are not supported.
4019  *
4020  *		**-ENOENT** if the socket is unavailable for assignment.
4021  *
4022  *		**-ENETUNREACH** if the socket is unreachable (wrong netns).
4023  *
4024  *		**-EOPNOTSUPP** if the operation is not supported, for example
4025  *		a call from outside of TC ingress.
4026  *
4027  *		**-ESOCKTNOSUPPORT** if the socket type is not supported
4028  *		(reuseport).
4029  *
4030  * long bpf_sk_assign(struct bpf_sk_lookup *ctx, struct bpf_sock *sk, u64 flags)
4031  *	Description
4032  *		Helper is overloaded depending on BPF program type. This
4033  *		description applies to **BPF_PROG_TYPE_SK_LOOKUP** programs.
4034  *
4035  *		Select the *sk* as a result of a socket lookup.
4036  *
4037  *		For the operation to succeed passed socket must be compatible
4038  *		with the packet description provided by the *ctx* object.
4039  *
4040  *		L4 protocol (**IPPROTO_TCP** or **IPPROTO_UDP**) must
4041  *		be an exact match. While IP family (**AF_INET** or
4042  *		**AF_INET6**) must be compatible, that is IPv6 sockets
4043  *		that are not v6-only can be selected for IPv4 packets.
4044  *
4045  *		Only TCP listeners and UDP unconnected sockets can be
4046  *		selected. *sk* can also be NULL to reset any previous
4047  *		selection.
4048  *
4049  *		*flags* argument can combination of following values:
4050  *
4051  *		* **BPF_SK_LOOKUP_F_REPLACE** to override the previous
4052  *		  socket selection, potentially done by a BPF program
4053  *		  that ran before us.
4054  *
4055  *		* **BPF_SK_LOOKUP_F_NO_REUSEPORT** to skip
4056  *		  load-balancing within reuseport group for the socket
4057  *		  being selected.
4058  *
4059  *		On success *ctx->sk* will point to the selected socket.
4060  *
4061  *	Return
4062  *		0 on success, or a negative errno in case of failure.
4063  *
4064  *		* **-EAFNOSUPPORT** if socket family (*sk->family*) is
4065  *		  not compatible with packet family (*ctx->family*).
4066  *
4067  *		* **-EEXIST** if socket has been already selected,
4068  *		  potentially by another program, and
4069  *		  **BPF_SK_LOOKUP_F_REPLACE** flag was not specified.
4070  *
4071  *		* **-EINVAL** if unsupported flags were specified.
4072  *
4073  *		* **-EPROTOTYPE** if socket L4 protocol
4074  *		  (*sk->protocol*) doesn't match packet protocol
4075  *		  (*ctx->protocol*).
4076  *
4077  *		* **-ESOCKTNOSUPPORT** if socket is not in allowed
4078  *		  state (TCP listening or UDP unconnected).
4079  *
4080  * u64 bpf_ktime_get_boot_ns(void)
4081  * 	Description
4082  * 		Return the time elapsed since system boot, in nanoseconds.
4083  * 		Does include the time the system was suspended.
4084  * 		See: **clock_gettime**\ (**CLOCK_BOOTTIME**)
4085  * 	Return
4086  * 		Current *ktime*.
4087  *
4088  * long bpf_seq_printf(struct seq_file *m, const char *fmt, u32 fmt_size, const void *data, u32 data_len)
4089  * 	Description
4090  * 		**bpf_seq_printf**\ () uses seq_file **seq_printf**\ () to print
4091  * 		out the format string.
4092  * 		The *m* represents the seq_file. The *fmt* and *fmt_size* are for
4093  * 		the format string itself. The *data* and *data_len* are format string
4094  * 		arguments. The *data* are a **u64** array and corresponding format string
4095  * 		values are stored in the array. For strings and pointers where pointees
4096  * 		are accessed, only the pointer values are stored in the *data* array.
4097  * 		The *data_len* is the size of *data* in bytes - must be a multiple of 8.
4098  *
4099  *		Formats **%s**, **%p{i,I}{4,6}** requires to read kernel memory.
4100  *		Reading kernel memory may fail due to either invalid address or
4101  *		valid address but requiring a major memory fault. If reading kernel memory
4102  *		fails, the string for **%s** will be an empty string, and the ip
4103  *		address for **%p{i,I}{4,6}** will be 0. Not returning error to
4104  *		bpf program is consistent with what **bpf_trace_printk**\ () does for now.
4105  * 	Return
4106  * 		0 on success, or a negative error in case of failure:
4107  *
4108  *		**-EBUSY** if per-CPU memory copy buffer is busy, can try again
4109  *		by returning 1 from bpf program.
4110  *
4111  *		**-EINVAL** if arguments are invalid, or if *fmt* is invalid/unsupported.
4112  *
4113  *		**-E2BIG** if *fmt* contains too many format specifiers.
4114  *
4115  *		**-EOVERFLOW** if an overflow happened: The same object will be tried again.
4116  *
4117  * long bpf_seq_write(struct seq_file *m, const void *data, u32 len)
4118  * 	Description
4119  * 		**bpf_seq_write**\ () uses seq_file **seq_write**\ () to write the data.
4120  * 		The *m* represents the seq_file. The *data* and *len* represent the
4121  * 		data to write in bytes.
4122  * 	Return
4123  * 		0 on success, or a negative error in case of failure:
4124  *
4125  *		**-EOVERFLOW** if an overflow happened: The same object will be tried again.
4126  *
4127  * u64 bpf_sk_cgroup_id(void *sk)
4128  *	Description
4129  *		Return the cgroup v2 id of the socket *sk*.
4130  *
4131  *		*sk* must be a non-**NULL** pointer to a socket, e.g. one
4132  *		returned from **bpf_sk_lookup_xxx**\ (),
4133  *		**bpf_sk_fullsock**\ (), etc. The format of returned id is
4134  *		same as in **bpf_skb_cgroup_id**\ ().
4135  *
4136  *		This helper is available only if the kernel was compiled with
4137  *		the **CONFIG_SOCK_CGROUP_DATA** configuration option.
4138  *	Return
4139  *		The id is returned or 0 in case the id could not be retrieved.
4140  *
4141  * u64 bpf_sk_ancestor_cgroup_id(void *sk, int ancestor_level)
4142  *	Description
4143  *		Return id of cgroup v2 that is ancestor of cgroup associated
4144  *		with the *sk* at the *ancestor_level*.  The root cgroup is at
4145  *		*ancestor_level* zero and each step down the hierarchy
4146  *		increments the level. If *ancestor_level* == level of cgroup
4147  *		associated with *sk*, then return value will be same as that
4148  *		of **bpf_sk_cgroup_id**\ ().
4149  *
4150  *		The helper is useful to implement policies based on cgroups
4151  *		that are upper in hierarchy than immediate cgroup associated
4152  *		with *sk*.
4153  *
4154  *		The format of returned id and helper limitations are same as in
4155  *		**bpf_sk_cgroup_id**\ ().
4156  *	Return
4157  *		The id is returned or 0 in case the id could not be retrieved.
4158  *
4159  * long bpf_ringbuf_output(void *ringbuf, void *data, u64 size, u64 flags)
4160  * 	Description
4161  * 		Copy *size* bytes from *data* into a ring buffer *ringbuf*.
4162  * 		If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
4163  * 		of new data availability is sent.
4164  * 		If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
4165  * 		of new data availability is sent unconditionally.
4166  * 		If **0** is specified in *flags*, an adaptive notification
4167  * 		of new data availability is sent.
4168  *
4169  * 		An adaptive notification is a notification sent whenever the user-space
4170  * 		process has caught up and consumed all available payloads. In case the user-space
4171  * 		process is still processing a previous payload, then no notification is needed
4172  * 		as it will process the newly added payload automatically.
4173  * 	Return
4174  * 		0 on success, or a negative error in case of failure.
4175  *
4176  * void *bpf_ringbuf_reserve(void *ringbuf, u64 size, u64 flags)
4177  * 	Description
4178  * 		Reserve *size* bytes of payload in a ring buffer *ringbuf*.
4179  * 		*flags* must be 0.
4180  * 	Return
4181  * 		Valid pointer with *size* bytes of memory available; NULL,
4182  * 		otherwise.
4183  *
4184  * void bpf_ringbuf_submit(void *data, u64 flags)
4185  * 	Description
4186  * 		Submit reserved ring buffer sample, pointed to by *data*.
4187  * 		If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
4188  * 		of new data availability is sent.
4189  * 		If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
4190  * 		of new data availability is sent unconditionally.
4191  * 		If **0** is specified in *flags*, an adaptive notification
4192  * 		of new data availability is sent.
4193  *
4194  * 		See 'bpf_ringbuf_output()' for the definition of adaptive notification.
4195  * 	Return
4196  * 		Nothing. Always succeeds.
4197  *
4198  * void bpf_ringbuf_discard(void *data, u64 flags)
4199  * 	Description
4200  * 		Discard reserved ring buffer sample, pointed to by *data*.
4201  * 		If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
4202  * 		of new data availability is sent.
4203  * 		If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
4204  * 		of new data availability is sent unconditionally.
4205  * 		If **0** is specified in *flags*, an adaptive notification
4206  * 		of new data availability is sent.
4207  *
4208  * 		See 'bpf_ringbuf_output()' for the definition of adaptive notification.
4209  * 	Return
4210  * 		Nothing. Always succeeds.
4211  *
4212  * u64 bpf_ringbuf_query(void *ringbuf, u64 flags)
4213  *	Description
4214  *		Query various characteristics of provided ring buffer. What
4215  *		exactly is queries is determined by *flags*:
4216  *
4217  *		* **BPF_RB_AVAIL_DATA**: Amount of data not yet consumed.
4218  *		* **BPF_RB_RING_SIZE**: The size of ring buffer.
4219  *		* **BPF_RB_CONS_POS**: Consumer position (can wrap around).
4220  *		* **BPF_RB_PROD_POS**: Producer(s) position (can wrap around).
4221  *
4222  *		Data returned is just a momentary snapshot of actual values
4223  *		and could be inaccurate, so this facility should be used to
4224  *		power heuristics and for reporting, not to make 100% correct
4225  *		calculation.
4226  *	Return
4227  *		Requested value, or 0, if *flags* are not recognized.
4228  *
4229  * long bpf_csum_level(struct sk_buff *skb, u64 level)
4230  * 	Description
4231  * 		Change the skbs checksum level by one layer up or down, or
4232  * 		reset it entirely to none in order to have the stack perform
4233  * 		checksum validation. The level is applicable to the following
4234  * 		protocols: TCP, UDP, GRE, SCTP, FCOE. For example, a decap of
4235  * 		| ETH | IP | UDP | GUE | IP | TCP | into | ETH | IP | TCP |
4236  * 		through **bpf_skb_adjust_room**\ () helper with passing in
4237  * 		**BPF_F_ADJ_ROOM_NO_CSUM_RESET** flag would require one	call
4238  * 		to **bpf_csum_level**\ () with **BPF_CSUM_LEVEL_DEC** since
4239  * 		the UDP header is removed. Similarly, an encap of the latter
4240  * 		into the former could be accompanied by a helper call to
4241  * 		**bpf_csum_level**\ () with **BPF_CSUM_LEVEL_INC** if the
4242  * 		skb is still intended to be processed in higher layers of the
4243  * 		stack instead of just egressing at tc.
4244  *
4245  * 		There are three supported level settings at this time:
4246  *
4247  * 		* **BPF_CSUM_LEVEL_INC**: Increases skb->csum_level for skbs
4248  * 		  with CHECKSUM_UNNECESSARY.
4249  * 		* **BPF_CSUM_LEVEL_DEC**: Decreases skb->csum_level for skbs
4250  * 		  with CHECKSUM_UNNECESSARY.
4251  * 		* **BPF_CSUM_LEVEL_RESET**: Resets skb->csum_level to 0 and
4252  * 		  sets CHECKSUM_NONE to force checksum validation by the stack.
4253  * 		* **BPF_CSUM_LEVEL_QUERY**: No-op, returns the current
4254  * 		  skb->csum_level.
4255  * 	Return
4256  * 		0 on success, or a negative error in case of failure. In the
4257  * 		case of **BPF_CSUM_LEVEL_QUERY**, the current skb->csum_level
4258  * 		is returned or the error code -EACCES in case the skb is not
4259  * 		subject to CHECKSUM_UNNECESSARY.
4260  *
4261  * struct tcp6_sock *bpf_skc_to_tcp6_sock(void *sk)
4262  *	Description
4263  *		Dynamically cast a *sk* pointer to a *tcp6_sock* pointer.
4264  *	Return
4265  *		*sk* if casting is valid, or **NULL** otherwise.
4266  *
4267  * struct tcp_sock *bpf_skc_to_tcp_sock(void *sk)
4268  *	Description
4269  *		Dynamically cast a *sk* pointer to a *tcp_sock* pointer.
4270  *	Return
4271  *		*sk* if casting is valid, or **NULL** otherwise.
4272  *
4273  * struct tcp_timewait_sock *bpf_skc_to_tcp_timewait_sock(void *sk)
4274  * 	Description
4275  *		Dynamically cast a *sk* pointer to a *tcp_timewait_sock* pointer.
4276  *	Return
4277  *		*sk* if casting is valid, or **NULL** otherwise.
4278  *
4279  * struct tcp_request_sock *bpf_skc_to_tcp_request_sock(void *sk)
4280  * 	Description
4281  *		Dynamically cast a *sk* pointer to a *tcp_request_sock* pointer.
4282  *	Return
4283  *		*sk* if casting is valid, or **NULL** otherwise.
4284  *
4285  * struct udp6_sock *bpf_skc_to_udp6_sock(void *sk)
4286  * 	Description
4287  *		Dynamically cast a *sk* pointer to a *udp6_sock* pointer.
4288  *	Return
4289  *		*sk* if casting is valid, or **NULL** otherwise.
4290  *
4291  * long bpf_get_task_stack(struct task_struct *task, void *buf, u32 size, u64 flags)
4292  *	Description
4293  *		Return a user or a kernel stack in bpf program provided buffer.
4294  *		To achieve this, the helper needs *task*, which is a valid
4295  *		pointer to **struct task_struct**. To store the stacktrace, the
4296  *		bpf program provides *buf* with a nonnegative *size*.
4297  *
4298  *		The last argument, *flags*, holds the number of stack frames to
4299  *		skip (from 0 to 255), masked with
4300  *		**BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
4301  *		the following flags:
4302  *
4303  *		**BPF_F_USER_STACK**
4304  *			Collect a user space stack instead of a kernel stack.
4305  *		**BPF_F_USER_BUILD_ID**
4306  *			Collect buildid+offset instead of ips for user stack,
4307  *			only valid if **BPF_F_USER_STACK** is also specified.
4308  *
4309  *		**bpf_get_task_stack**\ () can collect up to
4310  *		**PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
4311  *		to sufficient large buffer size. Note that
4312  *		this limit can be controlled with the **sysctl** program, and
4313  *		that it should be manually increased in order to profile long
4314  *		user stacks (such as stacks for Java programs). To do so, use:
4315  *
4316  *		::
4317  *
4318  *			# sysctl kernel.perf_event_max_stack=<new value>
4319  *	Return
4320  *		A non-negative value equal to or less than *size* on success,
4321  *		or a negative error in case of failure.
4322  *
4323  * long bpf_load_hdr_opt(struct bpf_sock_ops *skops, void *searchby_res, u32 len, u64 flags)
4324  *	Description
4325  *		Load header option.  Support reading a particular TCP header
4326  *		option for bpf program (**BPF_PROG_TYPE_SOCK_OPS**).
4327  *
4328  *		If *flags* is 0, it will search the option from the
4329  *		*skops*\ **->skb_data**.  The comment in **struct bpf_sock_ops**
4330  *		has details on what skb_data contains under different
4331  *		*skops*\ **->op**.
4332  *
4333  *		The first byte of the *searchby_res* specifies the
4334  *		kind that it wants to search.
4335  *
4336  *		If the searching kind is an experimental kind
4337  *		(i.e. 253 or 254 according to RFC6994).  It also
4338  *		needs to specify the "magic" which is either
4339  *		2 bytes or 4 bytes.  It then also needs to
4340  *		specify the size of the magic by using
4341  *		the 2nd byte which is "kind-length" of a TCP
4342  *		header option and the "kind-length" also
4343  *		includes the first 2 bytes "kind" and "kind-length"
4344  *		itself as a normal TCP header option also does.
4345  *
4346  *		For example, to search experimental kind 254 with
4347  *		2 byte magic 0xeB9F, the searchby_res should be
4348  *		[ 254, 4, 0xeB, 0x9F, 0, 0, .... 0 ].
4349  *
4350  *		To search for the standard window scale option (3),
4351  *		the *searchby_res* should be [ 3, 0, 0, .... 0 ].
4352  *		Note, kind-length must be 0 for regular option.
4353  *
4354  *		Searching for No-Op (0) and End-of-Option-List (1) are
4355  *		not supported.
4356  *
4357  *		*len* must be at least 2 bytes which is the minimal size
4358  *		of a header option.
4359  *
4360  *		Supported flags:
4361  *
4362  *		* **BPF_LOAD_HDR_OPT_TCP_SYN** to search from the
4363  *		  saved_syn packet or the just-received syn packet.
4364  *
4365  *	Return
4366  *		> 0 when found, the header option is copied to *searchby_res*.
4367  *		The return value is the total length copied. On failure, a
4368  *		negative error code is returned:
4369  *
4370  *		**-EINVAL** if a parameter is invalid.
4371  *
4372  *		**-ENOMSG** if the option is not found.
4373  *
4374  *		**-ENOENT** if no syn packet is available when
4375  *		**BPF_LOAD_HDR_OPT_TCP_SYN** is used.
4376  *
4377  *		**-ENOSPC** if there is not enough space.  Only *len* number of
4378  *		bytes are copied.
4379  *
4380  *		**-EFAULT** on failure to parse the header options in the
4381  *		packet.
4382  *
4383  *		**-EPERM** if the helper cannot be used under the current
4384  *		*skops*\ **->op**.
4385  *
4386  * long bpf_store_hdr_opt(struct bpf_sock_ops *skops, const void *from, u32 len, u64 flags)
4387  *	Description
4388  *		Store header option.  The data will be copied
4389  *		from buffer *from* with length *len* to the TCP header.
4390  *
4391  *		The buffer *from* should have the whole option that
4392  *		includes the kind, kind-length, and the actual
4393  *		option data.  The *len* must be at least kind-length
4394  *		long.  The kind-length does not have to be 4 byte
4395  *		aligned.  The kernel will take care of the padding
4396  *		and setting the 4 bytes aligned value to th->doff.
4397  *
4398  *		This helper will check for duplicated option
4399  *		by searching the same option in the outgoing skb.
4400  *
4401  *		This helper can only be called during
4402  *		**BPF_SOCK_OPS_WRITE_HDR_OPT_CB**.
4403  *
4404  *	Return
4405  *		0 on success, or negative error in case of failure:
4406  *
4407  *		**-EINVAL** If param is invalid.
4408  *
4409  *		**-ENOSPC** if there is not enough space in the header.
4410  *		Nothing has been written
4411  *
4412  *		**-EEXIST** if the option already exists.
4413  *
4414  *		**-EFAULT** on failrue to parse the existing header options.
4415  *
4416  *		**-EPERM** if the helper cannot be used under the current
4417  *		*skops*\ **->op**.
4418  *
4419  * long bpf_reserve_hdr_opt(struct bpf_sock_ops *skops, u32 len, u64 flags)
4420  *	Description
4421  *		Reserve *len* bytes for the bpf header option.  The
4422  *		space will be used by **bpf_store_hdr_opt**\ () later in
4423  *		**BPF_SOCK_OPS_WRITE_HDR_OPT_CB**.
4424  *
4425  *		If **bpf_reserve_hdr_opt**\ () is called multiple times,
4426  *		the total number of bytes will be reserved.
4427  *
4428  *		This helper can only be called during
4429  *		**BPF_SOCK_OPS_HDR_OPT_LEN_CB**.
4430  *
4431  *	Return
4432  *		0 on success, or negative error in case of failure:
4433  *
4434  *		**-EINVAL** if a parameter is invalid.
4435  *
4436  *		**-ENOSPC** if there is not enough space in the header.
4437  *
4438  *		**-EPERM** if the helper cannot be used under the current
4439  *		*skops*\ **->op**.
4440  *
4441  * void *bpf_inode_storage_get(struct bpf_map *map, void *inode, void *value, u64 flags)
4442  *	Description
4443  *		Get a bpf_local_storage from an *inode*.
4444  *
4445  *		Logically, it could be thought of as getting the value from
4446  *		a *map* with *inode* as the **key**.  From this
4447  *		perspective,  the usage is not much different from
4448  *		**bpf_map_lookup_elem**\ (*map*, **&**\ *inode*) except this
4449  *		helper enforces the key must be an inode and the map must also
4450  *		be a **BPF_MAP_TYPE_INODE_STORAGE**.
4451  *
4452  *		Underneath, the value is stored locally at *inode* instead of
4453  *		the *map*.  The *map* is used as the bpf-local-storage
4454  *		"type". The bpf-local-storage "type" (i.e. the *map*) is
4455  *		searched against all bpf_local_storage residing at *inode*.
4456  *
4457  *		An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
4458  *		used such that a new bpf_local_storage will be
4459  *		created if one does not exist.  *value* can be used
4460  *		together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
4461  *		the initial value of a bpf_local_storage.  If *value* is
4462  *		**NULL**, the new bpf_local_storage will be zero initialized.
4463  *	Return
4464  *		A bpf_local_storage pointer is returned on success.
4465  *
4466  *		**NULL** if not found or there was an error in adding
4467  *		a new bpf_local_storage.
4468  *
4469  * int bpf_inode_storage_delete(struct bpf_map *map, void *inode)
4470  *	Description
4471  *		Delete a bpf_local_storage from an *inode*.
4472  *	Return
4473  *		0 on success.
4474  *
4475  *		**-ENOENT** if the bpf_local_storage cannot be found.
4476  *
4477  * long bpf_d_path(struct path *path, char *buf, u32 sz)
4478  *	Description
4479  *		Return full path for given **struct path** object, which
4480  *		needs to be the kernel BTF *path* object. The path is
4481  *		returned in the provided buffer *buf* of size *sz* and
4482  *		is zero terminated.
4483  *
4484  *	Return
4485  *		On success, the strictly positive length of the string,
4486  *		including the trailing NUL character. On error, a negative
4487  *		value.
4488  *
4489  * long bpf_copy_from_user(void *dst, u32 size, const void *user_ptr)
4490  * 	Description
4491  * 		Read *size* bytes from user space address *user_ptr* and store
4492  * 		the data in *dst*. This is a wrapper of **copy_from_user**\ ().
4493  * 	Return
4494  * 		0 on success, or a negative error in case of failure.
4495  *
4496  * long bpf_snprintf_btf(char *str, u32 str_size, struct btf_ptr *ptr, u32 btf_ptr_size, u64 flags)
4497  *	Description
4498  *		Use BTF to store a string representation of *ptr*->ptr in *str*,
4499  *		using *ptr*->type_id.  This value should specify the type
4500  *		that *ptr*->ptr points to. LLVM __builtin_btf_type_id(type, 1)
4501  *		can be used to look up vmlinux BTF type ids. Traversing the
4502  *		data structure using BTF, the type information and values are
4503  *		stored in the first *str_size* - 1 bytes of *str*.  Safe copy of
4504  *		the pointer data is carried out to avoid kernel crashes during
4505  *		operation.  Smaller types can use string space on the stack;
4506  *		larger programs can use map data to store the string
4507  *		representation.
4508  *
4509  *		The string can be subsequently shared with userspace via
4510  *		bpf_perf_event_output() or ring buffer interfaces.
4511  *		bpf_trace_printk() is to be avoided as it places too small
4512  *		a limit on string size to be useful.
4513  *
4514  *		*flags* is a combination of
4515  *
4516  *		**BTF_F_COMPACT**
4517  *			no formatting around type information
4518  *		**BTF_F_NONAME**
4519  *			no struct/union member names/types
4520  *		**BTF_F_PTR_RAW**
4521  *			show raw (unobfuscated) pointer values;
4522  *			equivalent to printk specifier %px.
4523  *		**BTF_F_ZERO**
4524  *			show zero-valued struct/union members; they
4525  *			are not displayed by default
4526  *
4527  *	Return
4528  *		The number of bytes that were written (or would have been
4529  *		written if output had to be truncated due to string size),
4530  *		or a negative error in cases of failure.
4531  *
4532  * long bpf_seq_printf_btf(struct seq_file *m, struct btf_ptr *ptr, u32 ptr_size, u64 flags)
4533  *	Description
4534  *		Use BTF to write to seq_write a string representation of
4535  *		*ptr*->ptr, using *ptr*->type_id as per bpf_snprintf_btf().
4536  *		*flags* are identical to those used for bpf_snprintf_btf.
4537  *	Return
4538  *		0 on success or a negative error in case of failure.
4539  *
4540  * u64 bpf_skb_cgroup_classid(struct sk_buff *skb)
4541  * 	Description
4542  * 		See **bpf_get_cgroup_classid**\ () for the main description.
4543  * 		This helper differs from **bpf_get_cgroup_classid**\ () in that
4544  * 		the cgroup v1 net_cls class is retrieved only from the *skb*'s
4545  * 		associated socket instead of the current process.
4546  * 	Return
4547  * 		The id is returned or 0 in case the id could not be retrieved.
4548  *
4549  * long bpf_redirect_neigh(u32 ifindex, struct bpf_redir_neigh *params, int plen, u64 flags)
4550  * 	Description
4551  * 		Redirect the packet to another net device of index *ifindex*
4552  * 		and fill in L2 addresses from neighboring subsystem. This helper
4553  * 		is somewhat similar to **bpf_redirect**\ (), except that it
4554  * 		populates L2 addresses as well, meaning, internally, the helper
4555  * 		relies on the neighbor lookup for the L2 address of the nexthop.
4556  *
4557  * 		The helper will perform a FIB lookup based on the skb's
4558  * 		networking header to get the address of the next hop, unless
4559  * 		this is supplied by the caller in the *params* argument. The
4560  * 		*plen* argument indicates the len of *params* and should be set
4561  * 		to 0 if *params* is NULL.
4562  *
4563  * 		The *flags* argument is reserved and must be 0. The helper is
4564  * 		currently only supported for tc BPF program types, and enabled
4565  * 		for IPv4 and IPv6 protocols.
4566  * 	Return
4567  * 		The helper returns **TC_ACT_REDIRECT** on success or
4568  * 		**TC_ACT_SHOT** on error.
4569  *
4570  * void *bpf_per_cpu_ptr(const void *percpu_ptr, u32 cpu)
4571  *     Description
4572  *             Take a pointer to a percpu ksym, *percpu_ptr*, and return a
4573  *             pointer to the percpu kernel variable on *cpu*. A ksym is an
4574  *             extern variable decorated with '__ksym'. For ksym, there is a
4575  *             global var (either static or global) defined of the same name
4576  *             in the kernel. The ksym is percpu if the global var is percpu.
4577  *             The returned pointer points to the global percpu var on *cpu*.
4578  *
4579  *             bpf_per_cpu_ptr() has the same semantic as per_cpu_ptr() in the
4580  *             kernel, except that bpf_per_cpu_ptr() may return NULL. This
4581  *             happens if *cpu* is larger than nr_cpu_ids. The caller of
4582  *             bpf_per_cpu_ptr() must check the returned value.
4583  *     Return
4584  *             A pointer pointing to the kernel percpu variable on *cpu*, or
4585  *             NULL, if *cpu* is invalid.
4586  *
4587  * void *bpf_this_cpu_ptr(const void *percpu_ptr)
4588  *	Description
4589  *		Take a pointer to a percpu ksym, *percpu_ptr*, and return a
4590  *		pointer to the percpu kernel variable on this cpu. See the
4591  *		description of 'ksym' in **bpf_per_cpu_ptr**\ ().
4592  *
4593  *		bpf_this_cpu_ptr() has the same semantic as this_cpu_ptr() in
4594  *		the kernel. Different from **bpf_per_cpu_ptr**\ (), it would
4595  *		never return NULL.
4596  *	Return
4597  *		A pointer pointing to the kernel percpu variable on this cpu.
4598  *
4599  * long bpf_redirect_peer(u32 ifindex, u64 flags)
4600  * 	Description
4601  * 		Redirect the packet to another net device of index *ifindex*.
4602  * 		This helper is somewhat similar to **bpf_redirect**\ (), except
4603  * 		that the redirection happens to the *ifindex*' peer device and
4604  * 		the netns switch takes place from ingress to ingress without
4605  * 		going through the CPU's backlog queue.
4606  *
4607  * 		The *flags* argument is reserved and must be 0. The helper is
4608  * 		currently only supported for tc BPF program types at the ingress
4609  * 		hook and for veth device types. The peer device must reside in a
4610  * 		different network namespace.
4611  * 	Return
4612  * 		The helper returns **TC_ACT_REDIRECT** on success or
4613  * 		**TC_ACT_SHOT** on error.
4614  *
4615  * void *bpf_task_storage_get(struct bpf_map *map, struct task_struct *task, void *value, u64 flags)
4616  *	Description
4617  *		Get a bpf_local_storage from the *task*.
4618  *
4619  *		Logically, it could be thought of as getting the value from
4620  *		a *map* with *task* as the **key**.  From this
4621  *		perspective,  the usage is not much different from
4622  *		**bpf_map_lookup_elem**\ (*map*, **&**\ *task*) except this
4623  *		helper enforces the key must be an task_struct and the map must also
4624  *		be a **BPF_MAP_TYPE_TASK_STORAGE**.
4625  *
4626  *		Underneath, the value is stored locally at *task* instead of
4627  *		the *map*.  The *map* is used as the bpf-local-storage
4628  *		"type". The bpf-local-storage "type" (i.e. the *map*) is
4629  *		searched against all bpf_local_storage residing at *task*.
4630  *
4631  *		An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
4632  *		used such that a new bpf_local_storage will be
4633  *		created if one does not exist.  *value* can be used
4634  *		together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
4635  *		the initial value of a bpf_local_storage.  If *value* is
4636  *		**NULL**, the new bpf_local_storage will be zero initialized.
4637  *	Return
4638  *		A bpf_local_storage pointer is returned on success.
4639  *
4640  *		**NULL** if not found or there was an error in adding
4641  *		a new bpf_local_storage.
4642  *
4643  * long bpf_task_storage_delete(struct bpf_map *map, struct task_struct *task)
4644  *	Description
4645  *		Delete a bpf_local_storage from a *task*.
4646  *	Return
4647  *		0 on success.
4648  *
4649  *		**-ENOENT** if the bpf_local_storage cannot be found.
4650  *
4651  * struct task_struct *bpf_get_current_task_btf(void)
4652  *	Description
4653  *		Return a BTF pointer to the "current" task.
4654  *		This pointer can also be used in helpers that accept an
4655  *		*ARG_PTR_TO_BTF_ID* of type *task_struct*.
4656  *	Return
4657  *		Pointer to the current task.
4658  *
4659  * long bpf_bprm_opts_set(struct linux_binprm *bprm, u64 flags)
4660  *	Description
4661  *		Set or clear certain options on *bprm*:
4662  *
4663  *		**BPF_F_BPRM_SECUREEXEC** Set the secureexec bit
4664  *		which sets the **AT_SECURE** auxv for glibc. The bit
4665  *		is cleared if the flag is not specified.
4666  *	Return
4667  *		**-EINVAL** if invalid *flags* are passed, zero otherwise.
4668  *
4669  * u64 bpf_ktime_get_coarse_ns(void)
4670  * 	Description
4671  * 		Return a coarse-grained version of the time elapsed since
4672  * 		system boot, in nanoseconds. Does not include time the system
4673  * 		was suspended.
4674  *
4675  * 		See: **clock_gettime**\ (**CLOCK_MONOTONIC_COARSE**)
4676  * 	Return
4677  * 		Current *ktime*.
4678  *
4679  * long bpf_ima_inode_hash(struct inode *inode, void *dst, u32 size)
4680  *	Description
4681  *		Returns the stored IMA hash of the *inode* (if it's avaialable).
4682  *		If the hash is larger than *size*, then only *size*
4683  *		bytes will be copied to *dst*
4684  *	Return
4685  *		The **hash_algo** is returned on success,
4686  *		**-EOPNOTSUP** if IMA is disabled or **-EINVAL** if
4687  *		invalid arguments are passed.
4688  *
4689  * struct socket *bpf_sock_from_file(struct file *file)
4690  *	Description
4691  *		If the given file represents a socket, returns the associated
4692  *		socket.
4693  *	Return
4694  *		A pointer to a struct socket on success or NULL if the file is
4695  *		not a socket.
4696  *
4697  * long bpf_check_mtu(void *ctx, u32 ifindex, u32 *mtu_len, s32 len_diff, u64 flags)
4698  *	Description
4699  *		Check packet size against exceeding MTU of net device (based
4700  *		on *ifindex*).  This helper will likely be used in combination
4701  *		with helpers that adjust/change the packet size.
4702  *
4703  *		The argument *len_diff* can be used for querying with a planned
4704  *		size change. This allows to check MTU prior to changing packet
4705  *		ctx. Providing an *len_diff* adjustment that is larger than the
4706  *		actual packet size (resulting in negative packet size) will in
4707  *		principle not exceed the MTU, why it is not considered a
4708  *		failure.  Other BPF-helpers are needed for performing the
4709  *		planned size change, why the responsability for catch a negative
4710  *		packet size belong in those helpers.
4711  *
4712  *		Specifying *ifindex* zero means the MTU check is performed
4713  *		against the current net device.  This is practical if this isn't
4714  *		used prior to redirect.
4715  *
4716  *		On input *mtu_len* must be a valid pointer, else verifier will
4717  *		reject BPF program.  If the value *mtu_len* is initialized to
4718  *		zero then the ctx packet size is use.  When value *mtu_len* is
4719  *		provided as input this specify the L3 length that the MTU check
4720  *		is done against. Remember XDP and TC length operate at L2, but
4721  *		this value is L3 as this correlate to MTU and IP-header tot_len
4722  *		values which are L3 (similar behavior as bpf_fib_lookup).
4723  *
4724  *		The Linux kernel route table can configure MTUs on a more
4725  *		specific per route level, which is not provided by this helper.
4726  *		For route level MTU checks use the **bpf_fib_lookup**\ ()
4727  *		helper.
4728  *
4729  *		*ctx* is either **struct xdp_md** for XDP programs or
4730  *		**struct sk_buff** for tc cls_act programs.
4731  *
4732  *		The *flags* argument can be a combination of one or more of the
4733  *		following values:
4734  *
4735  *		**BPF_MTU_CHK_SEGS**
4736  *			This flag will only works for *ctx* **struct sk_buff**.
4737  *			If packet context contains extra packet segment buffers
4738  *			(often knows as GSO skb), then MTU check is harder to
4739  *			check at this point, because in transmit path it is
4740  *			possible for the skb packet to get re-segmented
4741  *			(depending on net device features).  This could still be
4742  *			a MTU violation, so this flag enables performing MTU
4743  *			check against segments, with a different violation
4744  *			return code to tell it apart. Check cannot use len_diff.
4745  *
4746  *		On return *mtu_len* pointer contains the MTU value of the net
4747  *		device.  Remember the net device configured MTU is the L3 size,
4748  *		which is returned here and XDP and TC length operate at L2.
4749  *		Helper take this into account for you, but remember when using
4750  *		MTU value in your BPF-code.
4751  *
4752  *	Return
4753  *		* 0 on success, and populate MTU value in *mtu_len* pointer.
4754  *
4755  *		* < 0 if any input argument is invalid (*mtu_len* not updated)
4756  *
4757  *		MTU violations return positive values, but also populate MTU
4758  *		value in *mtu_len* pointer, as this can be needed for
4759  *		implementing PMTU handing:
4760  *
4761  *		* **BPF_MTU_CHK_RET_FRAG_NEEDED**
4762  *		* **BPF_MTU_CHK_RET_SEGS_TOOBIG**
4763  *
4764  * long bpf_for_each_map_elem(struct bpf_map *map, void *callback_fn, void *callback_ctx, u64 flags)
4765  *	Description
4766  *		For each element in **map**, call **callback_fn** function with
4767  *		**map**, **callback_ctx** and other map-specific parameters.
4768  *		The **callback_fn** should be a static function and
4769  *		the **callback_ctx** should be a pointer to the stack.
4770  *		The **flags** is used to control certain aspects of the helper.
4771  *		Currently, the **flags** must be 0.
4772  *
4773  *		The following are a list of supported map types and their
4774  *		respective expected callback signatures:
4775  *
4776  *		BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_PERCPU_HASH,
4777  *		BPF_MAP_TYPE_LRU_HASH, BPF_MAP_TYPE_LRU_PERCPU_HASH,
4778  *		BPF_MAP_TYPE_ARRAY, BPF_MAP_TYPE_PERCPU_ARRAY
4779  *
4780  *		long (\*callback_fn)(struct bpf_map \*map, const void \*key, void \*value, void \*ctx);
4781  *
4782  *		For per_cpu maps, the map_value is the value on the cpu where the
4783  *		bpf_prog is running.
4784  *
4785  *		If **callback_fn** return 0, the helper will continue to the next
4786  *		element. If return value is 1, the helper will skip the rest of
4787  *		elements and return. Other return values are not used now.
4788  *
4789  *	Return
4790  *		The number of traversed map elements for success, **-EINVAL** for
4791  *		invalid **flags**.
4792  *
4793  * long bpf_snprintf(char *str, u32 str_size, const char *fmt, u64 *data, u32 data_len)
4794  *	Description
4795  *		Outputs a string into the **str** buffer of size **str_size**
4796  *		based on a format string stored in a read-only map pointed by
4797  *		**fmt**.
4798  *
4799  *		Each format specifier in **fmt** corresponds to one u64 element
4800  *		in the **data** array. For strings and pointers where pointees
4801  *		are accessed, only the pointer values are stored in the *data*
4802  *		array. The *data_len* is the size of *data* in bytes - must be
4803  *		a multiple of 8.
4804  *
4805  *		Formats **%s** and **%p{i,I}{4,6}** require to read kernel
4806  *		memory. Reading kernel memory may fail due to either invalid
4807  *		address or valid address but requiring a major memory fault. If
4808  *		reading kernel memory fails, the string for **%s** will be an
4809  *		empty string, and the ip address for **%p{i,I}{4,6}** will be 0.
4810  *		Not returning error to bpf program is consistent with what
4811  *		**bpf_trace_printk**\ () does for now.
4812  *
4813  *	Return
4814  *		The strictly positive length of the formatted string, including
4815  *		the trailing zero character. If the return value is greater than
4816  *		**str_size**, **str** contains a truncated string, guaranteed to
4817  *		be zero-terminated except when **str_size** is 0.
4818  *
4819  *		Or **-EBUSY** if the per-CPU memory copy buffer is busy.
4820  *
4821  * long bpf_sys_bpf(u32 cmd, void *attr, u32 attr_size)
4822  * 	Description
4823  * 		Execute bpf syscall with given arguments.
4824  * 	Return
4825  * 		A syscall result.
4826  *
4827  * long bpf_btf_find_by_name_kind(char *name, int name_sz, u32 kind, int flags)
4828  * 	Description
4829  * 		Find BTF type with given name and kind in vmlinux BTF or in module's BTFs.
4830  * 	Return
4831  * 		Returns btf_id and btf_obj_fd in lower and upper 32 bits.
4832  *
4833  * long bpf_sys_close(u32 fd)
4834  * 	Description
4835  * 		Execute close syscall for given FD.
4836  * 	Return
4837  * 		A syscall result.
4838  *
4839  * long bpf_timer_init(struct bpf_timer *timer, struct bpf_map *map, u64 flags)
4840  *	Description
4841  *		Initialize the timer.
4842  *		First 4 bits of *flags* specify clockid.
4843  *		Only CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_BOOTTIME are allowed.
4844  *		All other bits of *flags* are reserved.
4845  *		The verifier will reject the program if *timer* is not from
4846  *		the same *map*.
4847  *	Return
4848  *		0 on success.
4849  *		**-EBUSY** if *timer* is already initialized.
4850  *		**-EINVAL** if invalid *flags* are passed.
4851  *		**-EPERM** if *timer* is in a map that doesn't have any user references.
4852  *		The user space should either hold a file descriptor to a map with timers
4853  *		or pin such map in bpffs. When map is unpinned or file descriptor is
4854  *		closed all timers in the map will be cancelled and freed.
4855  *
4856  * long bpf_timer_set_callback(struct bpf_timer *timer, void *callback_fn)
4857  *	Description
4858  *		Configure the timer to call *callback_fn* static function.
4859  *	Return
4860  *		0 on success.
4861  *		**-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier.
4862  *		**-EPERM** if *timer* is in a map that doesn't have any user references.
4863  *		The user space should either hold a file descriptor to a map with timers
4864  *		or pin such map in bpffs. When map is unpinned or file descriptor is
4865  *		closed all timers in the map will be cancelled and freed.
4866  *
4867  * long bpf_timer_start(struct bpf_timer *timer, u64 nsecs, u64 flags)
4868  *	Description
4869  *		Set timer expiration N nanoseconds from the current time. The
4870  *		configured callback will be invoked in soft irq context on some cpu
4871  *		and will not repeat unless another bpf_timer_start() is made.
4872  *		In such case the next invocation can migrate to a different cpu.
4873  *		Since struct bpf_timer is a field inside map element the map
4874  *		owns the timer. The bpf_timer_set_callback() will increment refcnt
4875  *		of BPF program to make sure that callback_fn code stays valid.
4876  *		When user space reference to a map reaches zero all timers
4877  *		in a map are cancelled and corresponding program's refcnts are
4878  *		decremented. This is done to make sure that Ctrl-C of a user
4879  *		process doesn't leave any timers running. If map is pinned in
4880  *		bpffs the callback_fn can re-arm itself indefinitely.
4881  *		bpf_map_update/delete_elem() helpers and user space sys_bpf commands
4882  *		cancel and free the timer in the given map element.
4883  *		The map can contain timers that invoke callback_fn-s from different
4884  *		programs. The same callback_fn can serve different timers from
4885  *		different maps if key/value layout matches across maps.
4886  *		Every bpf_timer_set_callback() can have different callback_fn.
4887  *
4888  *	Return
4889  *		0 on success.
4890  *		**-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier
4891  *		or invalid *flags* are passed.
4892  *
4893  * long bpf_timer_cancel(struct bpf_timer *timer)
4894  *	Description
4895  *		Cancel the timer and wait for callback_fn to finish if it was running.
4896  *	Return
4897  *		0 if the timer was not active.
4898  *		1 if the timer was active.
4899  *		**-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier.
4900  *		**-EDEADLK** if callback_fn tried to call bpf_timer_cancel() on its
4901  *		own timer which would have led to a deadlock otherwise.
4902  *
4903  * u64 bpf_get_func_ip(void *ctx)
4904  * 	Description
4905  * 		Get address of the traced function (for tracing and kprobe programs).
4906  * 	Return
4907  * 		Address of the traced function.
4908  *
4909  * u64 bpf_get_attach_cookie(void *ctx)
4910  * 	Description
4911  * 		Get bpf_cookie value provided (optionally) during the program
4912  * 		attachment. It might be different for each individual
4913  * 		attachment, even if BPF program itself is the same.
4914  * 		Expects BPF program context *ctx* as a first argument.
4915  *
4916  * 		Supported for the following program types:
4917  *			- kprobe/uprobe;
4918  *			- tracepoint;
4919  *			- perf_event.
4920  * 	Return
4921  *		Value specified by user at BPF link creation/attachment time
4922  *		or 0, if it was not specified.
4923  *
4924  * long bpf_task_pt_regs(struct task_struct *task)
4925  *	Description
4926  *		Get the struct pt_regs associated with **task**.
4927  *	Return
4928  *		A pointer to struct pt_regs.
4929  *
4930  * long bpf_get_branch_snapshot(void *entries, u32 size, u64 flags)
4931  *	Description
4932  *		Get branch trace from hardware engines like Intel LBR. The
4933  *		hardware engine is stopped shortly after the helper is
4934  *		called. Therefore, the user need to filter branch entries
4935  *		based on the actual use case. To capture branch trace
4936  *		before the trigger point of the BPF program, the helper
4937  *		should be called at the beginning of the BPF program.
4938  *
4939  *		The data is stored as struct perf_branch_entry into output
4940  *		buffer *entries*. *size* is the size of *entries* in bytes.
4941  *		*flags* is reserved for now and must be zero.
4942  *
4943  *	Return
4944  *		On success, number of bytes written to *buf*. On error, a
4945  *		negative value.
4946  *
4947  *		**-EINVAL** if *flags* is not zero.
4948  *
4949  *		**-ENOENT** if architecture does not support branch records.
4950  *
4951  * long bpf_trace_vprintk(const char *fmt, u32 fmt_size, const void *data, u32 data_len)
4952  *	Description
4953  *		Behaves like **bpf_trace_printk**\ () helper, but takes an array of u64
4954  *		to format and can handle more format args as a result.
4955  *
4956  *		Arguments are to be used as in **bpf_seq_printf**\ () helper.
4957  *	Return
4958  *		The number of bytes written to the buffer, or a negative error
4959  *		in case of failure.
4960  *
4961  * struct unix_sock *bpf_skc_to_unix_sock(void *sk)
4962  * 	Description
4963  *		Dynamically cast a *sk* pointer to a *unix_sock* pointer.
4964  *	Return
4965  *		*sk* if casting is valid, or **NULL** otherwise.
4966  *
4967  * long bpf_kallsyms_lookup_name(const char *name, int name_sz, int flags, u64 *res)
4968  *	Description
4969  *		Get the address of a kernel symbol, returned in *res*. *res* is
4970  *		set to 0 if the symbol is not found.
4971  *	Return
4972  *		On success, zero. On error, a negative value.
4973  *
4974  *		**-EINVAL** if *flags* is not zero.
4975  *
4976  *		**-EINVAL** if string *name* is not the same size as *name_sz*.
4977  *
4978  *		**-ENOENT** if symbol is not found.
4979  *
4980  *		**-EPERM** if caller does not have permission to obtain kernel address.
4981  *
4982  * long bpf_find_vma(struct task_struct *task, u64 addr, void *callback_fn, void *callback_ctx, u64 flags)
4983  *	Description
4984  *		Find vma of *task* that contains *addr*, call *callback_fn*
4985  *		function with *task*, *vma*, and *callback_ctx*.
4986  *		The *callback_fn* should be a static function and
4987  *		the *callback_ctx* should be a pointer to the stack.
4988  *		The *flags* is used to control certain aspects of the helper.
4989  *		Currently, the *flags* must be 0.
4990  *
4991  *		The expected callback signature is
4992  *
4993  *		long (\*callback_fn)(struct task_struct \*task, struct vm_area_struct \*vma, void \*callback_ctx);
4994  *
4995  *	Return
4996  *		0 on success.
4997  *		**-ENOENT** if *task->mm* is NULL, or no vma contains *addr*.
4998  *		**-EBUSY** if failed to try lock mmap_lock.
4999  *		**-EINVAL** for invalid **flags**.
5000  *
5001  * long bpf_loop(u32 nr_loops, void *callback_fn, void *callback_ctx, u64 flags)
5002  *	Description
5003  *		For **nr_loops**, call **callback_fn** function
5004  *		with **callback_ctx** as the context parameter.
5005  *		The **callback_fn** should be a static function and
5006  *		the **callback_ctx** should be a pointer to the stack.
5007  *		The **flags** is used to control certain aspects of the helper.
5008  *		Currently, the **flags** must be 0. Currently, nr_loops is
5009  *		limited to 1 << 23 (~8 million) loops.
5010  *
5011  *		long (\*callback_fn)(u32 index, void \*ctx);
5012  *
5013  *		where **index** is the current index in the loop. The index
5014  *		is zero-indexed.
5015  *
5016  *		If **callback_fn** returns 0, the helper will continue to the next
5017  *		loop. If return value is 1, the helper will skip the rest of
5018  *		the loops and return. Other return values are not used now,
5019  *		and will be rejected by the verifier.
5020  *
5021  *	Return
5022  *		The number of loops performed, **-EINVAL** for invalid **flags**,
5023  *		**-E2BIG** if **nr_loops** exceeds the maximum number of loops.
5024  *
5025  * long bpf_strncmp(const char *s1, u32 s1_sz, const char *s2)
5026  *	Description
5027  *		Do strncmp() between **s1** and **s2**. **s1** doesn't need
5028  *		to be null-terminated and **s1_sz** is the maximum storage
5029  *		size of **s1**. **s2** must be a read-only string.
5030  *	Return
5031  *		An integer less than, equal to, or greater than zero
5032  *		if the first **s1_sz** bytes of **s1** is found to be
5033  *		less than, to match, or be greater than **s2**.
5034  *
5035  * long bpf_get_func_arg(void *ctx, u32 n, u64 *value)
5036  *	Description
5037  *		Get **n**-th argument (zero based) of the traced function (for tracing programs)
5038  *		returned in **value**.
5039  *
5040  *	Return
5041  *		0 on success.
5042  *		**-EINVAL** if n >= arguments count of traced function.
5043  *
5044  * long bpf_get_func_ret(void *ctx, u64 *value)
5045  *	Description
5046  *		Get return value of the traced function (for tracing programs)
5047  *		in **value**.
5048  *
5049  *	Return
5050  *		0 on success.
5051  *		**-EOPNOTSUPP** for tracing programs other than BPF_TRACE_FEXIT or BPF_MODIFY_RETURN.
5052  *
5053  * long bpf_get_func_arg_cnt(void *ctx)
5054  *	Description
5055  *		Get number of arguments of the traced function (for tracing programs).
5056  *
5057  *	Return
5058  *		The number of arguments of the traced function.
5059  *
5060  * int bpf_get_retval(void)
5061  *	Description
5062  *		Get the syscall's return value that will be returned to userspace.
5063  *
5064  *		This helper is currently supported by cgroup programs only.
5065  *	Return
5066  *		The syscall's return value.
5067  *
5068  * int bpf_set_retval(int retval)
5069  *	Description
5070  *		Set the syscall's return value that will be returned to userspace.
5071  *
5072  *		This helper is currently supported by cgroup programs only.
5073  *	Return
5074  *		0 on success, or a negative error in case of failure.
5075  *
5076  * u64 bpf_xdp_get_buff_len(struct xdp_buff *xdp_md)
5077  *	Description
5078  *		Get the total size of a given xdp buff (linear and paged area)
5079  *	Return
5080  *		The total size of a given xdp buffer.
5081  *
5082  * long bpf_xdp_load_bytes(struct xdp_buff *xdp_md, u32 offset, void *buf, u32 len)
5083  *	Description
5084  *		This helper is provided as an easy way to load data from a
5085  *		xdp buffer. It can be used to load *len* bytes from *offset* from
5086  *		the frame associated to *xdp_md*, into the buffer pointed by
5087  *		*buf*.
5088  *	Return
5089  *		0 on success, or a negative error in case of failure.
5090  *
5091  * long bpf_xdp_store_bytes(struct xdp_buff *xdp_md, u32 offset, void *buf, u32 len)
5092  *	Description
5093  *		Store *len* bytes from buffer *buf* into the frame
5094  *		associated to *xdp_md*, at *offset*.
5095  *	Return
5096  *		0 on success, or a negative error in case of failure.
5097  *
5098  * long bpf_copy_from_user_task(void *dst, u32 size, const void *user_ptr, struct task_struct *tsk, u64 flags)
5099  *	Description
5100  *		Read *size* bytes from user space address *user_ptr* in *tsk*'s
5101  *		address space, and stores the data in *dst*. *flags* is not
5102  *		used yet and is provided for future extensibility. This helper
5103  *		can only be used by sleepable programs.
5104  *	Return
5105  *		0 on success, or a negative error in case of failure. On error
5106  *		*dst* buffer is zeroed out.
5107  *
5108  * long bpf_skb_set_tstamp(struct sk_buff *skb, u64 tstamp, u32 tstamp_type)
5109  *	Description
5110  *		Change the __sk_buff->tstamp_type to *tstamp_type*
5111  *		and set *tstamp* to the __sk_buff->tstamp together.
5112  *
5113  *		If there is no need to change the __sk_buff->tstamp_type,
5114  *		the tstamp value can be directly written to __sk_buff->tstamp
5115  *		instead.
5116  *
5117  *		BPF_SKB_TSTAMP_DELIVERY_MONO is the only tstamp that
5118  *		will be kept during bpf_redirect_*().  A non zero
5119  *		*tstamp* must be used with the BPF_SKB_TSTAMP_DELIVERY_MONO
5120  *		*tstamp_type*.
5121  *
5122  *		A BPF_SKB_TSTAMP_UNSPEC *tstamp_type* can only be used
5123  *		with a zero *tstamp*.
5124  *
5125  *		Only IPv4 and IPv6 skb->protocol are supported.
5126  *
5127  *		This function is most useful when it needs to set a
5128  *		mono delivery time to __sk_buff->tstamp and then
5129  *		bpf_redirect_*() to the egress of an iface.  For example,
5130  *		changing the (rcv) timestamp in __sk_buff->tstamp at
5131  *		ingress to a mono delivery time and then bpf_redirect_*()
5132  *		to sch_fq@phy-dev.
5133  *	Return
5134  *		0 on success.
5135  *		**-EINVAL** for invalid input
5136  *		**-EOPNOTSUPP** for unsupported protocol
5137  *
5138  * long bpf_ima_file_hash(struct file *file, void *dst, u32 size)
5139  *	Description
5140  *		Returns a calculated IMA hash of the *file*.
5141  *		If the hash is larger than *size*, then only *size*
5142  *		bytes will be copied to *dst*
5143  *	Return
5144  *		The **hash_algo** is returned on success,
5145  *		**-EOPNOTSUP** if the hash calculation failed or **-EINVAL** if
5146  *		invalid arguments are passed.
5147  */
5148 #define __BPF_FUNC_MAPPER(FN)		\
5149 	FN(unspec),			\
5150 	FN(map_lookup_elem),		\
5151 	FN(map_update_elem),		\
5152 	FN(map_delete_elem),		\
5153 	FN(probe_read),			\
5154 	FN(ktime_get_ns),		\
5155 	FN(trace_printk),		\
5156 	FN(get_prandom_u32),		\
5157 	FN(get_smp_processor_id),	\
5158 	FN(skb_store_bytes),		\
5159 	FN(l3_csum_replace),		\
5160 	FN(l4_csum_replace),		\
5161 	FN(tail_call),			\
5162 	FN(clone_redirect),		\
5163 	FN(get_current_pid_tgid),	\
5164 	FN(get_current_uid_gid),	\
5165 	FN(get_current_comm),		\
5166 	FN(get_cgroup_classid),		\
5167 	FN(skb_vlan_push),		\
5168 	FN(skb_vlan_pop),		\
5169 	FN(skb_get_tunnel_key),		\
5170 	FN(skb_set_tunnel_key),		\
5171 	FN(perf_event_read),		\
5172 	FN(redirect),			\
5173 	FN(get_route_realm),		\
5174 	FN(perf_event_output),		\
5175 	FN(skb_load_bytes),		\
5176 	FN(get_stackid),		\
5177 	FN(csum_diff),			\
5178 	FN(skb_get_tunnel_opt),		\
5179 	FN(skb_set_tunnel_opt),		\
5180 	FN(skb_change_proto),		\
5181 	FN(skb_change_type),		\
5182 	FN(skb_under_cgroup),		\
5183 	FN(get_hash_recalc),		\
5184 	FN(get_current_task),		\
5185 	FN(probe_write_user),		\
5186 	FN(current_task_under_cgroup),	\
5187 	FN(skb_change_tail),		\
5188 	FN(skb_pull_data),		\
5189 	FN(csum_update),		\
5190 	FN(set_hash_invalid),		\
5191 	FN(get_numa_node_id),		\
5192 	FN(skb_change_head),		\
5193 	FN(xdp_adjust_head),		\
5194 	FN(probe_read_str),		\
5195 	FN(get_socket_cookie),		\
5196 	FN(get_socket_uid),		\
5197 	FN(set_hash),			\
5198 	FN(setsockopt),			\
5199 	FN(skb_adjust_room),		\
5200 	FN(redirect_map),		\
5201 	FN(sk_redirect_map),		\
5202 	FN(sock_map_update),		\
5203 	FN(xdp_adjust_meta),		\
5204 	FN(perf_event_read_value),	\
5205 	FN(perf_prog_read_value),	\
5206 	FN(getsockopt),			\
5207 	FN(override_return),		\
5208 	FN(sock_ops_cb_flags_set),	\
5209 	FN(msg_redirect_map),		\
5210 	FN(msg_apply_bytes),		\
5211 	FN(msg_cork_bytes),		\
5212 	FN(msg_pull_data),		\
5213 	FN(bind),			\
5214 	FN(xdp_adjust_tail),		\
5215 	FN(skb_get_xfrm_state),		\
5216 	FN(get_stack),			\
5217 	FN(skb_load_bytes_relative),	\
5218 	FN(fib_lookup),			\
5219 	FN(sock_hash_update),		\
5220 	FN(msg_redirect_hash),		\
5221 	FN(sk_redirect_hash),		\
5222 	FN(lwt_push_encap),		\
5223 	FN(lwt_seg6_store_bytes),	\
5224 	FN(lwt_seg6_adjust_srh),	\
5225 	FN(lwt_seg6_action),		\
5226 	FN(rc_repeat),			\
5227 	FN(rc_keydown),			\
5228 	FN(skb_cgroup_id),		\
5229 	FN(get_current_cgroup_id),	\
5230 	FN(get_local_storage),		\
5231 	FN(sk_select_reuseport),	\
5232 	FN(skb_ancestor_cgroup_id),	\
5233 	FN(sk_lookup_tcp),		\
5234 	FN(sk_lookup_udp),		\
5235 	FN(sk_release),			\
5236 	FN(map_push_elem),		\
5237 	FN(map_pop_elem),		\
5238 	FN(map_peek_elem),		\
5239 	FN(msg_push_data),		\
5240 	FN(msg_pop_data),		\
5241 	FN(rc_pointer_rel),		\
5242 	FN(spin_lock),			\
5243 	FN(spin_unlock),		\
5244 	FN(sk_fullsock),		\
5245 	FN(tcp_sock),			\
5246 	FN(skb_ecn_set_ce),		\
5247 	FN(get_listener_sock),		\
5248 	FN(skc_lookup_tcp),		\
5249 	FN(tcp_check_syncookie),	\
5250 	FN(sysctl_get_name),		\
5251 	FN(sysctl_get_current_value),	\
5252 	FN(sysctl_get_new_value),	\
5253 	FN(sysctl_set_new_value),	\
5254 	FN(strtol),			\
5255 	FN(strtoul),			\
5256 	FN(sk_storage_get),		\
5257 	FN(sk_storage_delete),		\
5258 	FN(send_signal),		\
5259 	FN(tcp_gen_syncookie),		\
5260 	FN(skb_output),			\
5261 	FN(probe_read_user),		\
5262 	FN(probe_read_kernel),		\
5263 	FN(probe_read_user_str),	\
5264 	FN(probe_read_kernel_str),	\
5265 	FN(tcp_send_ack),		\
5266 	FN(send_signal_thread),		\
5267 	FN(jiffies64),			\
5268 	FN(read_branch_records),	\
5269 	FN(get_ns_current_pid_tgid),	\
5270 	FN(xdp_output),			\
5271 	FN(get_netns_cookie),		\
5272 	FN(get_current_ancestor_cgroup_id),	\
5273 	FN(sk_assign),			\
5274 	FN(ktime_get_boot_ns),		\
5275 	FN(seq_printf),			\
5276 	FN(seq_write),			\
5277 	FN(sk_cgroup_id),		\
5278 	FN(sk_ancestor_cgroup_id),	\
5279 	FN(ringbuf_output),		\
5280 	FN(ringbuf_reserve),		\
5281 	FN(ringbuf_submit),		\
5282 	FN(ringbuf_discard),		\
5283 	FN(ringbuf_query),		\
5284 	FN(csum_level),			\
5285 	FN(skc_to_tcp6_sock),		\
5286 	FN(skc_to_tcp_sock),		\
5287 	FN(skc_to_tcp_timewait_sock),	\
5288 	FN(skc_to_tcp_request_sock),	\
5289 	FN(skc_to_udp6_sock),		\
5290 	FN(get_task_stack),		\
5291 	FN(load_hdr_opt),		\
5292 	FN(store_hdr_opt),		\
5293 	FN(reserve_hdr_opt),		\
5294 	FN(inode_storage_get),		\
5295 	FN(inode_storage_delete),	\
5296 	FN(d_path),			\
5297 	FN(copy_from_user),		\
5298 	FN(snprintf_btf),		\
5299 	FN(seq_printf_btf),		\
5300 	FN(skb_cgroup_classid),		\
5301 	FN(redirect_neigh),		\
5302 	FN(per_cpu_ptr),		\
5303 	FN(this_cpu_ptr),		\
5304 	FN(redirect_peer),		\
5305 	FN(task_storage_get),		\
5306 	FN(task_storage_delete),	\
5307 	FN(get_current_task_btf),	\
5308 	FN(bprm_opts_set),		\
5309 	FN(ktime_get_coarse_ns),	\
5310 	FN(ima_inode_hash),		\
5311 	FN(sock_from_file),		\
5312 	FN(check_mtu),			\
5313 	FN(for_each_map_elem),		\
5314 	FN(snprintf),			\
5315 	FN(sys_bpf),			\
5316 	FN(btf_find_by_name_kind),	\
5317 	FN(sys_close),			\
5318 	FN(timer_init),			\
5319 	FN(timer_set_callback),		\
5320 	FN(timer_start),		\
5321 	FN(timer_cancel),		\
5322 	FN(get_func_ip),		\
5323 	FN(get_attach_cookie),		\
5324 	FN(task_pt_regs),		\
5325 	FN(get_branch_snapshot),	\
5326 	FN(trace_vprintk),		\
5327 	FN(skc_to_unix_sock),		\
5328 	FN(kallsyms_lookup_name),	\
5329 	FN(find_vma),			\
5330 	FN(loop),			\
5331 	FN(strncmp),			\
5332 	FN(get_func_arg),		\
5333 	FN(get_func_ret),		\
5334 	FN(get_func_arg_cnt),		\
5335 	FN(get_retval),			\
5336 	FN(set_retval),			\
5337 	FN(xdp_get_buff_len),		\
5338 	FN(xdp_load_bytes),		\
5339 	FN(xdp_store_bytes),		\
5340 	FN(copy_from_user_task),	\
5341 	FN(skb_set_tstamp),		\
5342 	FN(ima_file_hash),		\
5343 	/* */
5344 
5345 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
5346  * function eBPF program intends to call
5347  */
5348 #define __BPF_ENUM_FN(x) BPF_FUNC_ ## x
5349 enum bpf_func_id {
5350 	__BPF_FUNC_MAPPER(__BPF_ENUM_FN)
5351 	__BPF_FUNC_MAX_ID,
5352 };
5353 #undef __BPF_ENUM_FN
5354 
5355 /* All flags used by eBPF helper functions, placed here. */
5356 
5357 /* BPF_FUNC_skb_store_bytes flags. */
5358 enum {
5359 	BPF_F_RECOMPUTE_CSUM		= (1ULL << 0),
5360 	BPF_F_INVALIDATE_HASH		= (1ULL << 1),
5361 };
5362 
5363 /* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
5364  * First 4 bits are for passing the header field size.
5365  */
5366 enum {
5367 	BPF_F_HDR_FIELD_MASK		= 0xfULL,
5368 };
5369 
5370 /* BPF_FUNC_l4_csum_replace flags. */
5371 enum {
5372 	BPF_F_PSEUDO_HDR		= (1ULL << 4),
5373 	BPF_F_MARK_MANGLED_0		= (1ULL << 5),
5374 	BPF_F_MARK_ENFORCE		= (1ULL << 6),
5375 };
5376 
5377 /* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */
5378 enum {
5379 	BPF_F_INGRESS			= (1ULL << 0),
5380 };
5381 
5382 /* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */
5383 enum {
5384 	BPF_F_TUNINFO_IPV6		= (1ULL << 0),
5385 };
5386 
5387 /* flags for both BPF_FUNC_get_stackid and BPF_FUNC_get_stack. */
5388 enum {
5389 	BPF_F_SKIP_FIELD_MASK		= 0xffULL,
5390 	BPF_F_USER_STACK		= (1ULL << 8),
5391 /* flags used by BPF_FUNC_get_stackid only. */
5392 	BPF_F_FAST_STACK_CMP		= (1ULL << 9),
5393 	BPF_F_REUSE_STACKID		= (1ULL << 10),
5394 /* flags used by BPF_FUNC_get_stack only. */
5395 	BPF_F_USER_BUILD_ID		= (1ULL << 11),
5396 };
5397 
5398 /* BPF_FUNC_skb_set_tunnel_key flags. */
5399 enum {
5400 	BPF_F_ZERO_CSUM_TX		= (1ULL << 1),
5401 	BPF_F_DONT_FRAGMENT		= (1ULL << 2),
5402 	BPF_F_SEQ_NUMBER		= (1ULL << 3),
5403 };
5404 
5405 /* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
5406  * BPF_FUNC_perf_event_read_value flags.
5407  */
5408 enum {
5409 	BPF_F_INDEX_MASK		= 0xffffffffULL,
5410 	BPF_F_CURRENT_CPU		= BPF_F_INDEX_MASK,
5411 /* BPF_FUNC_perf_event_output for sk_buff input context. */
5412 	BPF_F_CTXLEN_MASK		= (0xfffffULL << 32),
5413 };
5414 
5415 /* Current network namespace */
5416 enum {
5417 	BPF_F_CURRENT_NETNS		= (-1L),
5418 };
5419 
5420 /* BPF_FUNC_csum_level level values. */
5421 enum {
5422 	BPF_CSUM_LEVEL_QUERY,
5423 	BPF_CSUM_LEVEL_INC,
5424 	BPF_CSUM_LEVEL_DEC,
5425 	BPF_CSUM_LEVEL_RESET,
5426 };
5427 
5428 /* BPF_FUNC_skb_adjust_room flags. */
5429 enum {
5430 	BPF_F_ADJ_ROOM_FIXED_GSO	= (1ULL << 0),
5431 	BPF_F_ADJ_ROOM_ENCAP_L3_IPV4	= (1ULL << 1),
5432 	BPF_F_ADJ_ROOM_ENCAP_L3_IPV6	= (1ULL << 2),
5433 	BPF_F_ADJ_ROOM_ENCAP_L4_GRE	= (1ULL << 3),
5434 	BPF_F_ADJ_ROOM_ENCAP_L4_UDP	= (1ULL << 4),
5435 	BPF_F_ADJ_ROOM_NO_CSUM_RESET	= (1ULL << 5),
5436 	BPF_F_ADJ_ROOM_ENCAP_L2_ETH	= (1ULL << 6),
5437 };
5438 
5439 enum {
5440 	BPF_ADJ_ROOM_ENCAP_L2_MASK	= 0xff,
5441 	BPF_ADJ_ROOM_ENCAP_L2_SHIFT	= 56,
5442 };
5443 
5444 #define BPF_F_ADJ_ROOM_ENCAP_L2(len)	(((__u64)len & \
5445 					  BPF_ADJ_ROOM_ENCAP_L2_MASK) \
5446 					 << BPF_ADJ_ROOM_ENCAP_L2_SHIFT)
5447 
5448 /* BPF_FUNC_sysctl_get_name flags. */
5449 enum {
5450 	BPF_F_SYSCTL_BASE_NAME		= (1ULL << 0),
5451 };
5452 
5453 /* BPF_FUNC_<kernel_obj>_storage_get flags */
5454 enum {
5455 	BPF_LOCAL_STORAGE_GET_F_CREATE	= (1ULL << 0),
5456 	/* BPF_SK_STORAGE_GET_F_CREATE is only kept for backward compatibility
5457 	 * and BPF_LOCAL_STORAGE_GET_F_CREATE must be used instead.
5458 	 */
5459 	BPF_SK_STORAGE_GET_F_CREATE  = BPF_LOCAL_STORAGE_GET_F_CREATE,
5460 };
5461 
5462 /* BPF_FUNC_read_branch_records flags. */
5463 enum {
5464 	BPF_F_GET_BRANCH_RECORDS_SIZE	= (1ULL << 0),
5465 };
5466 
5467 /* BPF_FUNC_bpf_ringbuf_commit, BPF_FUNC_bpf_ringbuf_discard, and
5468  * BPF_FUNC_bpf_ringbuf_output flags.
5469  */
5470 enum {
5471 	BPF_RB_NO_WAKEUP		= (1ULL << 0),
5472 	BPF_RB_FORCE_WAKEUP		= (1ULL << 1),
5473 };
5474 
5475 /* BPF_FUNC_bpf_ringbuf_query flags */
5476 enum {
5477 	BPF_RB_AVAIL_DATA = 0,
5478 	BPF_RB_RING_SIZE = 1,
5479 	BPF_RB_CONS_POS = 2,
5480 	BPF_RB_PROD_POS = 3,
5481 };
5482 
5483 /* BPF ring buffer constants */
5484 enum {
5485 	BPF_RINGBUF_BUSY_BIT		= (1U << 31),
5486 	BPF_RINGBUF_DISCARD_BIT		= (1U << 30),
5487 	BPF_RINGBUF_HDR_SZ		= 8,
5488 };
5489 
5490 /* BPF_FUNC_sk_assign flags in bpf_sk_lookup context. */
5491 enum {
5492 	BPF_SK_LOOKUP_F_REPLACE		= (1ULL << 0),
5493 	BPF_SK_LOOKUP_F_NO_REUSEPORT	= (1ULL << 1),
5494 };
5495 
5496 /* Mode for BPF_FUNC_skb_adjust_room helper. */
5497 enum bpf_adj_room_mode {
5498 	BPF_ADJ_ROOM_NET,
5499 	BPF_ADJ_ROOM_MAC,
5500 };
5501 
5502 /* Mode for BPF_FUNC_skb_load_bytes_relative helper. */
5503 enum bpf_hdr_start_off {
5504 	BPF_HDR_START_MAC,
5505 	BPF_HDR_START_NET,
5506 };
5507 
5508 /* Encapsulation type for BPF_FUNC_lwt_push_encap helper. */
5509 enum bpf_lwt_encap_mode {
5510 	BPF_LWT_ENCAP_SEG6,
5511 	BPF_LWT_ENCAP_SEG6_INLINE,
5512 	BPF_LWT_ENCAP_IP,
5513 };
5514 
5515 /* Flags for bpf_bprm_opts_set helper */
5516 enum {
5517 	BPF_F_BPRM_SECUREEXEC	= (1ULL << 0),
5518 };
5519 
5520 /* Flags for bpf_redirect_map helper */
5521 enum {
5522 	BPF_F_BROADCAST		= (1ULL << 3),
5523 	BPF_F_EXCLUDE_INGRESS	= (1ULL << 4),
5524 };
5525 
5526 #define __bpf_md_ptr(type, name)	\
5527 union {					\
5528 	type name;			\
5529 	__u64 :64;			\
5530 } __attribute__((aligned(8)))
5531 
5532 enum {
5533 	BPF_SKB_TSTAMP_UNSPEC,
5534 	BPF_SKB_TSTAMP_DELIVERY_MONO,	/* tstamp has mono delivery time */
5535 	/* For any BPF_SKB_TSTAMP_* that the bpf prog cannot handle,
5536 	 * the bpf prog should handle it like BPF_SKB_TSTAMP_UNSPEC
5537 	 * and try to deduce it by ingress, egress or skb->sk->sk_clockid.
5538 	 */
5539 };
5540 
5541 /* user accessible mirror of in-kernel sk_buff.
5542  * new fields can only be added to the end of this structure
5543  */
5544 struct __sk_buff {
5545 	__u32 len;
5546 	__u32 pkt_type;
5547 	__u32 mark;
5548 	__u32 queue_mapping;
5549 	__u32 protocol;
5550 	__u32 vlan_present;
5551 	__u32 vlan_tci;
5552 	__u32 vlan_proto;
5553 	__u32 priority;
5554 	__u32 ingress_ifindex;
5555 	__u32 ifindex;
5556 	__u32 tc_index;
5557 	__u32 cb[5];
5558 	__u32 hash;
5559 	__u32 tc_classid;
5560 	__u32 data;
5561 	__u32 data_end;
5562 	__u32 napi_id;
5563 
5564 	/* Accessed by BPF_PROG_TYPE_sk_skb types from here to ... */
5565 	__u32 family;
5566 	__u32 remote_ip4;	/* Stored in network byte order */
5567 	__u32 local_ip4;	/* Stored in network byte order */
5568 	__u32 remote_ip6[4];	/* Stored in network byte order */
5569 	__u32 local_ip6[4];	/* Stored in network byte order */
5570 	__u32 remote_port;	/* Stored in network byte order */
5571 	__u32 local_port;	/* stored in host byte order */
5572 	/* ... here. */
5573 
5574 	__u32 data_meta;
5575 	__bpf_md_ptr(struct bpf_flow_keys *, flow_keys);
5576 	__u64 tstamp;
5577 	__u32 wire_len;
5578 	__u32 gso_segs;
5579 	__bpf_md_ptr(struct bpf_sock *, sk);
5580 	__u32 gso_size;
5581 	__u8  tstamp_type;
5582 	__u32 :24;		/* Padding, future use. */
5583 	__u64 hwtstamp;
5584 };
5585 
5586 struct bpf_tunnel_key {
5587 	__u32 tunnel_id;
5588 	union {
5589 		__u32 remote_ipv4;
5590 		__u32 remote_ipv6[4];
5591 	};
5592 	__u8 tunnel_tos;
5593 	__u8 tunnel_ttl;
5594 	__u16 tunnel_ext;	/* Padding, future use. */
5595 	__u32 tunnel_label;
5596 };
5597 
5598 /* user accessible mirror of in-kernel xfrm_state.
5599  * new fields can only be added to the end of this structure
5600  */
5601 struct bpf_xfrm_state {
5602 	__u32 reqid;
5603 	__u32 spi;	/* Stored in network byte order */
5604 	__u16 family;
5605 	__u16 ext;	/* Padding, future use. */
5606 	union {
5607 		__u32 remote_ipv4;	/* Stored in network byte order */
5608 		__u32 remote_ipv6[4];	/* Stored in network byte order */
5609 	};
5610 };
5611 
5612 /* Generic BPF return codes which all BPF program types may support.
5613  * The values are binary compatible with their TC_ACT_* counter-part to
5614  * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT
5615  * programs.
5616  *
5617  * XDP is handled seprately, see XDP_*.
5618  */
5619 enum bpf_ret_code {
5620 	BPF_OK = 0,
5621 	/* 1 reserved */
5622 	BPF_DROP = 2,
5623 	/* 3-6 reserved */
5624 	BPF_REDIRECT = 7,
5625 	/* >127 are reserved for prog type specific return codes.
5626 	 *
5627 	 * BPF_LWT_REROUTE: used by BPF_PROG_TYPE_LWT_IN and
5628 	 *    BPF_PROG_TYPE_LWT_XMIT to indicate that skb had been
5629 	 *    changed and should be routed based on its new L3 header.
5630 	 *    (This is an L3 redirect, as opposed to L2 redirect
5631 	 *    represented by BPF_REDIRECT above).
5632 	 */
5633 	BPF_LWT_REROUTE = 128,
5634 };
5635 
5636 struct bpf_sock {
5637 	__u32 bound_dev_if;
5638 	__u32 family;
5639 	__u32 type;
5640 	__u32 protocol;
5641 	__u32 mark;
5642 	__u32 priority;
5643 	/* IP address also allows 1 and 2 bytes access */
5644 	__u32 src_ip4;
5645 	__u32 src_ip6[4];
5646 	__u32 src_port;		/* host byte order */
5647 	__be16 dst_port;	/* network byte order */
5648 	__u16 :16;		/* zero padding */
5649 	__u32 dst_ip4;
5650 	__u32 dst_ip6[4];
5651 	__u32 state;
5652 	__s32 rx_queue_mapping;
5653 };
5654 
5655 struct bpf_tcp_sock {
5656 	__u32 snd_cwnd;		/* Sending congestion window		*/
5657 	__u32 srtt_us;		/* smoothed round trip time << 3 in usecs */
5658 	__u32 rtt_min;
5659 	__u32 snd_ssthresh;	/* Slow start size threshold		*/
5660 	__u32 rcv_nxt;		/* What we want to receive next		*/
5661 	__u32 snd_nxt;		/* Next sequence we send		*/
5662 	__u32 snd_una;		/* First byte we want an ack for	*/
5663 	__u32 mss_cache;	/* Cached effective mss, not including SACKS */
5664 	__u32 ecn_flags;	/* ECN status bits.			*/
5665 	__u32 rate_delivered;	/* saved rate sample: packets delivered */
5666 	__u32 rate_interval_us;	/* saved rate sample: time elapsed */
5667 	__u32 packets_out;	/* Packets which are "in flight"	*/
5668 	__u32 retrans_out;	/* Retransmitted packets out		*/
5669 	__u32 total_retrans;	/* Total retransmits for entire connection */
5670 	__u32 segs_in;		/* RFC4898 tcpEStatsPerfSegsIn
5671 				 * total number of segments in.
5672 				 */
5673 	__u32 data_segs_in;	/* RFC4898 tcpEStatsPerfDataSegsIn
5674 				 * total number of data segments in.
5675 				 */
5676 	__u32 segs_out;		/* RFC4898 tcpEStatsPerfSegsOut
5677 				 * The total number of segments sent.
5678 				 */
5679 	__u32 data_segs_out;	/* RFC4898 tcpEStatsPerfDataSegsOut
5680 				 * total number of data segments sent.
5681 				 */
5682 	__u32 lost_out;		/* Lost packets			*/
5683 	__u32 sacked_out;	/* SACK'd packets			*/
5684 	__u64 bytes_received;	/* RFC4898 tcpEStatsAppHCThruOctetsReceived
5685 				 * sum(delta(rcv_nxt)), or how many bytes
5686 				 * were acked.
5687 				 */
5688 	__u64 bytes_acked;	/* RFC4898 tcpEStatsAppHCThruOctetsAcked
5689 				 * sum(delta(snd_una)), or how many bytes
5690 				 * were acked.
5691 				 */
5692 	__u32 dsack_dups;	/* RFC4898 tcpEStatsStackDSACKDups
5693 				 * total number of DSACK blocks received
5694 				 */
5695 	__u32 delivered;	/* Total data packets delivered incl. rexmits */
5696 	__u32 delivered_ce;	/* Like the above but only ECE marked packets */
5697 	__u32 icsk_retransmits;	/* Number of unrecovered [RTO] timeouts */
5698 };
5699 
5700 struct bpf_sock_tuple {
5701 	union {
5702 		struct {
5703 			__be32 saddr;
5704 			__be32 daddr;
5705 			__be16 sport;
5706 			__be16 dport;
5707 		} ipv4;
5708 		struct {
5709 			__be32 saddr[4];
5710 			__be32 daddr[4];
5711 			__be16 sport;
5712 			__be16 dport;
5713 		} ipv6;
5714 	};
5715 };
5716 
5717 struct bpf_xdp_sock {
5718 	__u32 queue_id;
5719 };
5720 
5721 #define XDP_PACKET_HEADROOM 256
5722 
5723 /* User return codes for XDP prog type.
5724  * A valid XDP program must return one of these defined values. All other
5725  * return codes are reserved for future use. Unknown return codes will
5726  * result in packet drops and a warning via bpf_warn_invalid_xdp_action().
5727  */
5728 enum xdp_action {
5729 	XDP_ABORTED = 0,
5730 	XDP_DROP,
5731 	XDP_PASS,
5732 	XDP_TX,
5733 	XDP_REDIRECT,
5734 };
5735 
5736 /* user accessible metadata for XDP packet hook
5737  * new fields must be added to the end of this structure
5738  */
5739 struct xdp_md {
5740 	__u32 data;
5741 	__u32 data_end;
5742 	__u32 data_meta;
5743 	/* Below access go through struct xdp_rxq_info */
5744 	__u32 ingress_ifindex; /* rxq->dev->ifindex */
5745 	__u32 rx_queue_index;  /* rxq->queue_index  */
5746 
5747 	__u32 egress_ifindex;  /* txq->dev->ifindex */
5748 };
5749 
5750 /* DEVMAP map-value layout
5751  *
5752  * The struct data-layout of map-value is a configuration interface.
5753  * New members can only be added to the end of this structure.
5754  */
5755 struct bpf_devmap_val {
5756 	__u32 ifindex;   /* device index */
5757 	union {
5758 		int   fd;  /* prog fd on map write */
5759 		__u32 id;  /* prog id on map read */
5760 	} bpf_prog;
5761 };
5762 
5763 /* CPUMAP map-value layout
5764  *
5765  * The struct data-layout of map-value is a configuration interface.
5766  * New members can only be added to the end of this structure.
5767  */
5768 struct bpf_cpumap_val {
5769 	__u32 qsize;	/* queue size to remote target CPU */
5770 	union {
5771 		int   fd;	/* prog fd on map write */
5772 		__u32 id;	/* prog id on map read */
5773 	} bpf_prog;
5774 };
5775 
5776 enum sk_action {
5777 	SK_DROP = 0,
5778 	SK_PASS,
5779 };
5780 
5781 /* user accessible metadata for SK_MSG packet hook, new fields must
5782  * be added to the end of this structure
5783  */
5784 struct sk_msg_md {
5785 	__bpf_md_ptr(void *, data);
5786 	__bpf_md_ptr(void *, data_end);
5787 
5788 	__u32 family;
5789 	__u32 remote_ip4;	/* Stored in network byte order */
5790 	__u32 local_ip4;	/* Stored in network byte order */
5791 	__u32 remote_ip6[4];	/* Stored in network byte order */
5792 	__u32 local_ip6[4];	/* Stored in network byte order */
5793 	__u32 remote_port;	/* Stored in network byte order */
5794 	__u32 local_port;	/* stored in host byte order */
5795 	__u32 size;		/* Total size of sk_msg */
5796 
5797 	__bpf_md_ptr(struct bpf_sock *, sk); /* current socket */
5798 };
5799 
5800 struct sk_reuseport_md {
5801 	/*
5802 	 * Start of directly accessible data. It begins from
5803 	 * the tcp/udp header.
5804 	 */
5805 	__bpf_md_ptr(void *, data);
5806 	/* End of directly accessible data */
5807 	__bpf_md_ptr(void *, data_end);
5808 	/*
5809 	 * Total length of packet (starting from the tcp/udp header).
5810 	 * Note that the directly accessible bytes (data_end - data)
5811 	 * could be less than this "len".  Those bytes could be
5812 	 * indirectly read by a helper "bpf_skb_load_bytes()".
5813 	 */
5814 	__u32 len;
5815 	/*
5816 	 * Eth protocol in the mac header (network byte order). e.g.
5817 	 * ETH_P_IP(0x0800) and ETH_P_IPV6(0x86DD)
5818 	 */
5819 	__u32 eth_protocol;
5820 	__u32 ip_protocol;	/* IP protocol. e.g. IPPROTO_TCP, IPPROTO_UDP */
5821 	__u32 bind_inany;	/* Is sock bound to an INANY address? */
5822 	__u32 hash;		/* A hash of the packet 4 tuples */
5823 	/* When reuse->migrating_sk is NULL, it is selecting a sk for the
5824 	 * new incoming connection request (e.g. selecting a listen sk for
5825 	 * the received SYN in the TCP case).  reuse->sk is one of the sk
5826 	 * in the reuseport group. The bpf prog can use reuse->sk to learn
5827 	 * the local listening ip/port without looking into the skb.
5828 	 *
5829 	 * When reuse->migrating_sk is not NULL, reuse->sk is closed and
5830 	 * reuse->migrating_sk is the socket that needs to be migrated
5831 	 * to another listening socket.  migrating_sk could be a fullsock
5832 	 * sk that is fully established or a reqsk that is in-the-middle
5833 	 * of 3-way handshake.
5834 	 */
5835 	__bpf_md_ptr(struct bpf_sock *, sk);
5836 	__bpf_md_ptr(struct bpf_sock *, migrating_sk);
5837 };
5838 
5839 #define BPF_TAG_SIZE	8
5840 
5841 struct bpf_prog_info {
5842 	__u32 type;
5843 	__u32 id;
5844 	__u8  tag[BPF_TAG_SIZE];
5845 	__u32 jited_prog_len;
5846 	__u32 xlated_prog_len;
5847 	__aligned_u64 jited_prog_insns;
5848 	__aligned_u64 xlated_prog_insns;
5849 	__u64 load_time;	/* ns since boottime */
5850 	__u32 created_by_uid;
5851 	__u32 nr_map_ids;
5852 	__aligned_u64 map_ids;
5853 	char name[BPF_OBJ_NAME_LEN];
5854 	__u32 ifindex;
5855 	__u32 gpl_compatible:1;
5856 	__u32 :31; /* alignment pad */
5857 	__u64 netns_dev;
5858 	__u64 netns_ino;
5859 	__u32 nr_jited_ksyms;
5860 	__u32 nr_jited_func_lens;
5861 	__aligned_u64 jited_ksyms;
5862 	__aligned_u64 jited_func_lens;
5863 	__u32 btf_id;
5864 	__u32 func_info_rec_size;
5865 	__aligned_u64 func_info;
5866 	__u32 nr_func_info;
5867 	__u32 nr_line_info;
5868 	__aligned_u64 line_info;
5869 	__aligned_u64 jited_line_info;
5870 	__u32 nr_jited_line_info;
5871 	__u32 line_info_rec_size;
5872 	__u32 jited_line_info_rec_size;
5873 	__u32 nr_prog_tags;
5874 	__aligned_u64 prog_tags;
5875 	__u64 run_time_ns;
5876 	__u64 run_cnt;
5877 	__u64 recursion_misses;
5878 	__u32 verified_insns;
5879 } __attribute__((aligned(8)));
5880 
5881 struct bpf_map_info {
5882 	__u32 type;
5883 	__u32 id;
5884 	__u32 key_size;
5885 	__u32 value_size;
5886 	__u32 max_entries;
5887 	__u32 map_flags;
5888 	char  name[BPF_OBJ_NAME_LEN];
5889 	__u32 ifindex;
5890 	__u32 btf_vmlinux_value_type_id;
5891 	__u64 netns_dev;
5892 	__u64 netns_ino;
5893 	__u32 btf_id;
5894 	__u32 btf_key_type_id;
5895 	__u32 btf_value_type_id;
5896 	__u32 :32;	/* alignment pad */
5897 	__u64 map_extra;
5898 } __attribute__((aligned(8)));
5899 
5900 struct bpf_btf_info {
5901 	__aligned_u64 btf;
5902 	__u32 btf_size;
5903 	__u32 id;
5904 	__aligned_u64 name;
5905 	__u32 name_len;
5906 	__u32 kernel_btf;
5907 } __attribute__((aligned(8)));
5908 
5909 struct bpf_link_info {
5910 	__u32 type;
5911 	__u32 id;
5912 	__u32 prog_id;
5913 	union {
5914 		struct {
5915 			__aligned_u64 tp_name; /* in/out: tp_name buffer ptr */
5916 			__u32 tp_name_len;     /* in/out: tp_name buffer len */
5917 		} raw_tracepoint;
5918 		struct {
5919 			__u32 attach_type;
5920 			__u32 target_obj_id; /* prog_id for PROG_EXT, otherwise btf object id */
5921 			__u32 target_btf_id; /* BTF type id inside the object */
5922 		} tracing;
5923 		struct {
5924 			__u64 cgroup_id;
5925 			__u32 attach_type;
5926 		} cgroup;
5927 		struct {
5928 			__aligned_u64 target_name; /* in/out: target_name buffer ptr */
5929 			__u32 target_name_len;	   /* in/out: target_name buffer len */
5930 			union {
5931 				struct {
5932 					__u32 map_id;
5933 				} map;
5934 			};
5935 		} iter;
5936 		struct  {
5937 			__u32 netns_ino;
5938 			__u32 attach_type;
5939 		} netns;
5940 		struct {
5941 			__u32 ifindex;
5942 		} xdp;
5943 	};
5944 } __attribute__((aligned(8)));
5945 
5946 /* User bpf_sock_addr struct to access socket fields and sockaddr struct passed
5947  * by user and intended to be used by socket (e.g. to bind to, depends on
5948  * attach type).
5949  */
5950 struct bpf_sock_addr {
5951 	__u32 user_family;	/* Allows 4-byte read, but no write. */
5952 	__u32 user_ip4;		/* Allows 1,2,4-byte read and 4-byte write.
5953 				 * Stored in network byte order.
5954 				 */
5955 	__u32 user_ip6[4];	/* Allows 1,2,4,8-byte read and 4,8-byte write.
5956 				 * Stored in network byte order.
5957 				 */
5958 	__u32 user_port;	/* Allows 1,2,4-byte read and 4-byte write.
5959 				 * Stored in network byte order
5960 				 */
5961 	__u32 family;		/* Allows 4-byte read, but no write */
5962 	__u32 type;		/* Allows 4-byte read, but no write */
5963 	__u32 protocol;		/* Allows 4-byte read, but no write */
5964 	__u32 msg_src_ip4;	/* Allows 1,2,4-byte read and 4-byte write.
5965 				 * Stored in network byte order.
5966 				 */
5967 	__u32 msg_src_ip6[4];	/* Allows 1,2,4,8-byte read and 4,8-byte write.
5968 				 * Stored in network byte order.
5969 				 */
5970 	__bpf_md_ptr(struct bpf_sock *, sk);
5971 };
5972 
5973 /* User bpf_sock_ops struct to access socket values and specify request ops
5974  * and their replies.
5975  * Some of this fields are in network (bigendian) byte order and may need
5976  * to be converted before use (bpf_ntohl() defined in samples/bpf/bpf_endian.h).
5977  * New fields can only be added at the end of this structure
5978  */
5979 struct bpf_sock_ops {
5980 	__u32 op;
5981 	union {
5982 		__u32 args[4];		/* Optionally passed to bpf program */
5983 		__u32 reply;		/* Returned by bpf program	    */
5984 		__u32 replylong[4];	/* Optionally returned by bpf prog  */
5985 	};
5986 	__u32 family;
5987 	__u32 remote_ip4;	/* Stored in network byte order */
5988 	__u32 local_ip4;	/* Stored in network byte order */
5989 	__u32 remote_ip6[4];	/* Stored in network byte order */
5990 	__u32 local_ip6[4];	/* Stored in network byte order */
5991 	__u32 remote_port;	/* Stored in network byte order */
5992 	__u32 local_port;	/* stored in host byte order */
5993 	__u32 is_fullsock;	/* Some TCP fields are only valid if
5994 				 * there is a full socket. If not, the
5995 				 * fields read as zero.
5996 				 */
5997 	__u32 snd_cwnd;
5998 	__u32 srtt_us;		/* Averaged RTT << 3 in usecs */
5999 	__u32 bpf_sock_ops_cb_flags; /* flags defined in uapi/linux/tcp.h */
6000 	__u32 state;
6001 	__u32 rtt_min;
6002 	__u32 snd_ssthresh;
6003 	__u32 rcv_nxt;
6004 	__u32 snd_nxt;
6005 	__u32 snd_una;
6006 	__u32 mss_cache;
6007 	__u32 ecn_flags;
6008 	__u32 rate_delivered;
6009 	__u32 rate_interval_us;
6010 	__u32 packets_out;
6011 	__u32 retrans_out;
6012 	__u32 total_retrans;
6013 	__u32 segs_in;
6014 	__u32 data_segs_in;
6015 	__u32 segs_out;
6016 	__u32 data_segs_out;
6017 	__u32 lost_out;
6018 	__u32 sacked_out;
6019 	__u32 sk_txhash;
6020 	__u64 bytes_received;
6021 	__u64 bytes_acked;
6022 	__bpf_md_ptr(struct bpf_sock *, sk);
6023 	/* [skb_data, skb_data_end) covers the whole TCP header.
6024 	 *
6025 	 * BPF_SOCK_OPS_PARSE_HDR_OPT_CB: The packet received
6026 	 * BPF_SOCK_OPS_HDR_OPT_LEN_CB:   Not useful because the
6027 	 *                                header has not been written.
6028 	 * BPF_SOCK_OPS_WRITE_HDR_OPT_CB: The header and options have
6029 	 *				  been written so far.
6030 	 * BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB:  The SYNACK that concludes
6031 	 *					the 3WHS.
6032 	 * BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB: The ACK that concludes
6033 	 *					the 3WHS.
6034 	 *
6035 	 * bpf_load_hdr_opt() can also be used to read a particular option.
6036 	 */
6037 	__bpf_md_ptr(void *, skb_data);
6038 	__bpf_md_ptr(void *, skb_data_end);
6039 	__u32 skb_len;		/* The total length of a packet.
6040 				 * It includes the header, options,
6041 				 * and payload.
6042 				 */
6043 	__u32 skb_tcp_flags;	/* tcp_flags of the header.  It provides
6044 				 * an easy way to check for tcp_flags
6045 				 * without parsing skb_data.
6046 				 *
6047 				 * In particular, the skb_tcp_flags
6048 				 * will still be available in
6049 				 * BPF_SOCK_OPS_HDR_OPT_LEN even though
6050 				 * the outgoing header has not
6051 				 * been written yet.
6052 				 */
6053 };
6054 
6055 /* Definitions for bpf_sock_ops_cb_flags */
6056 enum {
6057 	BPF_SOCK_OPS_RTO_CB_FLAG	= (1<<0),
6058 	BPF_SOCK_OPS_RETRANS_CB_FLAG	= (1<<1),
6059 	BPF_SOCK_OPS_STATE_CB_FLAG	= (1<<2),
6060 	BPF_SOCK_OPS_RTT_CB_FLAG	= (1<<3),
6061 	/* Call bpf for all received TCP headers.  The bpf prog will be
6062 	 * called under sock_ops->op == BPF_SOCK_OPS_PARSE_HDR_OPT_CB
6063 	 *
6064 	 * Please refer to the comment in BPF_SOCK_OPS_PARSE_HDR_OPT_CB
6065 	 * for the header option related helpers that will be useful
6066 	 * to the bpf programs.
6067 	 *
6068 	 * It could be used at the client/active side (i.e. connect() side)
6069 	 * when the server told it that the server was in syncookie
6070 	 * mode and required the active side to resend the bpf-written
6071 	 * options.  The active side can keep writing the bpf-options until
6072 	 * it received a valid packet from the server side to confirm
6073 	 * the earlier packet (and options) has been received.  The later
6074 	 * example patch is using it like this at the active side when the
6075 	 * server is in syncookie mode.
6076 	 *
6077 	 * The bpf prog will usually turn this off in the common cases.
6078 	 */
6079 	BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG	= (1<<4),
6080 	/* Call bpf when kernel has received a header option that
6081 	 * the kernel cannot handle.  The bpf prog will be called under
6082 	 * sock_ops->op == BPF_SOCK_OPS_PARSE_HDR_OPT_CB.
6083 	 *
6084 	 * Please refer to the comment in BPF_SOCK_OPS_PARSE_HDR_OPT_CB
6085 	 * for the header option related helpers that will be useful
6086 	 * to the bpf programs.
6087 	 */
6088 	BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG = (1<<5),
6089 	/* Call bpf when the kernel is writing header options for the
6090 	 * outgoing packet.  The bpf prog will first be called
6091 	 * to reserve space in a skb under
6092 	 * sock_ops->op == BPF_SOCK_OPS_HDR_OPT_LEN_CB.  Then
6093 	 * the bpf prog will be called to write the header option(s)
6094 	 * under sock_ops->op == BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
6095 	 *
6096 	 * Please refer to the comment in BPF_SOCK_OPS_HDR_OPT_LEN_CB
6097 	 * and BPF_SOCK_OPS_WRITE_HDR_OPT_CB for the header option
6098 	 * related helpers that will be useful to the bpf programs.
6099 	 *
6100 	 * The kernel gets its chance to reserve space and write
6101 	 * options first before the BPF program does.
6102 	 */
6103 	BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG = (1<<6),
6104 /* Mask of all currently supported cb flags */
6105 	BPF_SOCK_OPS_ALL_CB_FLAGS       = 0x7F,
6106 };
6107 
6108 /* List of known BPF sock_ops operators.
6109  * New entries can only be added at the end
6110  */
6111 enum {
6112 	BPF_SOCK_OPS_VOID,
6113 	BPF_SOCK_OPS_TIMEOUT_INIT,	/* Should return SYN-RTO value to use or
6114 					 * -1 if default value should be used
6115 					 */
6116 	BPF_SOCK_OPS_RWND_INIT,		/* Should return initial advertized
6117 					 * window (in packets) or -1 if default
6118 					 * value should be used
6119 					 */
6120 	BPF_SOCK_OPS_TCP_CONNECT_CB,	/* Calls BPF program right before an
6121 					 * active connection is initialized
6122 					 */
6123 	BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB,	/* Calls BPF program when an
6124 						 * active connection is
6125 						 * established
6126 						 */
6127 	BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB,	/* Calls BPF program when a
6128 						 * passive connection is
6129 						 * established
6130 						 */
6131 	BPF_SOCK_OPS_NEEDS_ECN,		/* If connection's congestion control
6132 					 * needs ECN
6133 					 */
6134 	BPF_SOCK_OPS_BASE_RTT,		/* Get base RTT. The correct value is
6135 					 * based on the path and may be
6136 					 * dependent on the congestion control
6137 					 * algorithm. In general it indicates
6138 					 * a congestion threshold. RTTs above
6139 					 * this indicate congestion
6140 					 */
6141 	BPF_SOCK_OPS_RTO_CB,		/* Called when an RTO has triggered.
6142 					 * Arg1: value of icsk_retransmits
6143 					 * Arg2: value of icsk_rto
6144 					 * Arg3: whether RTO has expired
6145 					 */
6146 	BPF_SOCK_OPS_RETRANS_CB,	/* Called when skb is retransmitted.
6147 					 * Arg1: sequence number of 1st byte
6148 					 * Arg2: # segments
6149 					 * Arg3: return value of
6150 					 *       tcp_transmit_skb (0 => success)
6151 					 */
6152 	BPF_SOCK_OPS_STATE_CB,		/* Called when TCP changes state.
6153 					 * Arg1: old_state
6154 					 * Arg2: new_state
6155 					 */
6156 	BPF_SOCK_OPS_TCP_LISTEN_CB,	/* Called on listen(2), right after
6157 					 * socket transition to LISTEN state.
6158 					 */
6159 	BPF_SOCK_OPS_RTT_CB,		/* Called on every RTT.
6160 					 */
6161 	BPF_SOCK_OPS_PARSE_HDR_OPT_CB,	/* Parse the header option.
6162 					 * It will be called to handle
6163 					 * the packets received at
6164 					 * an already established
6165 					 * connection.
6166 					 *
6167 					 * sock_ops->skb_data:
6168 					 * Referring to the received skb.
6169 					 * It covers the TCP header only.
6170 					 *
6171 					 * bpf_load_hdr_opt() can also
6172 					 * be used to search for a
6173 					 * particular option.
6174 					 */
6175 	BPF_SOCK_OPS_HDR_OPT_LEN_CB,	/* Reserve space for writing the
6176 					 * header option later in
6177 					 * BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
6178 					 * Arg1: bool want_cookie. (in
6179 					 *       writing SYNACK only)
6180 					 *
6181 					 * sock_ops->skb_data:
6182 					 * Not available because no header has
6183 					 * been	written yet.
6184 					 *
6185 					 * sock_ops->skb_tcp_flags:
6186 					 * The tcp_flags of the
6187 					 * outgoing skb. (e.g. SYN, ACK, FIN).
6188 					 *
6189 					 * bpf_reserve_hdr_opt() should
6190 					 * be used to reserve space.
6191 					 */
6192 	BPF_SOCK_OPS_WRITE_HDR_OPT_CB,	/* Write the header options
6193 					 * Arg1: bool want_cookie. (in
6194 					 *       writing SYNACK only)
6195 					 *
6196 					 * sock_ops->skb_data:
6197 					 * Referring to the outgoing skb.
6198 					 * It covers the TCP header
6199 					 * that has already been written
6200 					 * by the kernel and the
6201 					 * earlier bpf-progs.
6202 					 *
6203 					 * sock_ops->skb_tcp_flags:
6204 					 * The tcp_flags of the outgoing
6205 					 * skb. (e.g. SYN, ACK, FIN).
6206 					 *
6207 					 * bpf_store_hdr_opt() should
6208 					 * be used to write the
6209 					 * option.
6210 					 *
6211 					 * bpf_load_hdr_opt() can also
6212 					 * be used to search for a
6213 					 * particular option that
6214 					 * has already been written
6215 					 * by the kernel or the
6216 					 * earlier bpf-progs.
6217 					 */
6218 };
6219 
6220 /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
6221  * changes between the TCP and BPF versions. Ideally this should never happen.
6222  * If it does, we need to add code to convert them before calling
6223  * the BPF sock_ops function.
6224  */
6225 enum {
6226 	BPF_TCP_ESTABLISHED = 1,
6227 	BPF_TCP_SYN_SENT,
6228 	BPF_TCP_SYN_RECV,
6229 	BPF_TCP_FIN_WAIT1,
6230 	BPF_TCP_FIN_WAIT2,
6231 	BPF_TCP_TIME_WAIT,
6232 	BPF_TCP_CLOSE,
6233 	BPF_TCP_CLOSE_WAIT,
6234 	BPF_TCP_LAST_ACK,
6235 	BPF_TCP_LISTEN,
6236 	BPF_TCP_CLOSING,	/* Now a valid state */
6237 	BPF_TCP_NEW_SYN_RECV,
6238 
6239 	BPF_TCP_MAX_STATES	/* Leave at the end! */
6240 };
6241 
6242 enum {
6243 	TCP_BPF_IW		= 1001,	/* Set TCP initial congestion window */
6244 	TCP_BPF_SNDCWND_CLAMP	= 1002,	/* Set sndcwnd_clamp */
6245 	TCP_BPF_DELACK_MAX	= 1003, /* Max delay ack in usecs */
6246 	TCP_BPF_RTO_MIN		= 1004, /* Min delay ack in usecs */
6247 	/* Copy the SYN pkt to optval
6248 	 *
6249 	 * BPF_PROG_TYPE_SOCK_OPS only.  It is similar to the
6250 	 * bpf_getsockopt(TCP_SAVED_SYN) but it does not limit
6251 	 * to only getting from the saved_syn.  It can either get the
6252 	 * syn packet from:
6253 	 *
6254 	 * 1. the just-received SYN packet (only available when writing the
6255 	 *    SYNACK).  It will be useful when it is not necessary to
6256 	 *    save the SYN packet for latter use.  It is also the only way
6257 	 *    to get the SYN during syncookie mode because the syn
6258 	 *    packet cannot be saved during syncookie.
6259 	 *
6260 	 * OR
6261 	 *
6262 	 * 2. the earlier saved syn which was done by
6263 	 *    bpf_setsockopt(TCP_SAVE_SYN).
6264 	 *
6265 	 * The bpf_getsockopt(TCP_BPF_SYN*) option will hide where the
6266 	 * SYN packet is obtained.
6267 	 *
6268 	 * If the bpf-prog does not need the IP[46] header,  the
6269 	 * bpf-prog can avoid parsing the IP header by using
6270 	 * TCP_BPF_SYN.  Otherwise, the bpf-prog can get both
6271 	 * IP[46] and TCP header by using TCP_BPF_SYN_IP.
6272 	 *
6273 	 *      >0: Total number of bytes copied
6274 	 * -ENOSPC: Not enough space in optval. Only optlen number of
6275 	 *          bytes is copied.
6276 	 * -ENOENT: The SYN skb is not available now and the earlier SYN pkt
6277 	 *	    is not saved by setsockopt(TCP_SAVE_SYN).
6278 	 */
6279 	TCP_BPF_SYN		= 1005, /* Copy the TCP header */
6280 	TCP_BPF_SYN_IP		= 1006, /* Copy the IP[46] and TCP header */
6281 	TCP_BPF_SYN_MAC         = 1007, /* Copy the MAC, IP[46], and TCP header */
6282 };
6283 
6284 enum {
6285 	BPF_LOAD_HDR_OPT_TCP_SYN = (1ULL << 0),
6286 };
6287 
6288 /* args[0] value during BPF_SOCK_OPS_HDR_OPT_LEN_CB and
6289  * BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
6290  */
6291 enum {
6292 	BPF_WRITE_HDR_TCP_CURRENT_MSS = 1,	/* Kernel is finding the
6293 						 * total option spaces
6294 						 * required for an established
6295 						 * sk in order to calculate the
6296 						 * MSS.  No skb is actually
6297 						 * sent.
6298 						 */
6299 	BPF_WRITE_HDR_TCP_SYNACK_COOKIE = 2,	/* Kernel is in syncookie mode
6300 						 * when sending a SYN.
6301 						 */
6302 };
6303 
6304 struct bpf_perf_event_value {
6305 	__u64 counter;
6306 	__u64 enabled;
6307 	__u64 running;
6308 };
6309 
6310 enum {
6311 	BPF_DEVCG_ACC_MKNOD	= (1ULL << 0),
6312 	BPF_DEVCG_ACC_READ	= (1ULL << 1),
6313 	BPF_DEVCG_ACC_WRITE	= (1ULL << 2),
6314 };
6315 
6316 enum {
6317 	BPF_DEVCG_DEV_BLOCK	= (1ULL << 0),
6318 	BPF_DEVCG_DEV_CHAR	= (1ULL << 1),
6319 };
6320 
6321 struct bpf_cgroup_dev_ctx {
6322 	/* access_type encoded as (BPF_DEVCG_ACC_* << 16) | BPF_DEVCG_DEV_* */
6323 	__u32 access_type;
6324 	__u32 major;
6325 	__u32 minor;
6326 };
6327 
6328 struct bpf_raw_tracepoint_args {
6329 	__u64 args[0];
6330 };
6331 
6332 /* DIRECT:  Skip the FIB rules and go to FIB table associated with device
6333  * OUTPUT:  Do lookup from egress perspective; default is ingress
6334  */
6335 enum {
6336 	BPF_FIB_LOOKUP_DIRECT  = (1U << 0),
6337 	BPF_FIB_LOOKUP_OUTPUT  = (1U << 1),
6338 };
6339 
6340 enum {
6341 	BPF_FIB_LKUP_RET_SUCCESS,      /* lookup successful */
6342 	BPF_FIB_LKUP_RET_BLACKHOLE,    /* dest is blackholed; can be dropped */
6343 	BPF_FIB_LKUP_RET_UNREACHABLE,  /* dest is unreachable; can be dropped */
6344 	BPF_FIB_LKUP_RET_PROHIBIT,     /* dest not allowed; can be dropped */
6345 	BPF_FIB_LKUP_RET_NOT_FWDED,    /* packet is not forwarded */
6346 	BPF_FIB_LKUP_RET_FWD_DISABLED, /* fwding is not enabled on ingress */
6347 	BPF_FIB_LKUP_RET_UNSUPP_LWT,   /* fwd requires encapsulation */
6348 	BPF_FIB_LKUP_RET_NO_NEIGH,     /* no neighbor entry for nh */
6349 	BPF_FIB_LKUP_RET_FRAG_NEEDED,  /* fragmentation required to fwd */
6350 };
6351 
6352 struct bpf_fib_lookup {
6353 	/* input:  network family for lookup (AF_INET, AF_INET6)
6354 	 * output: network family of egress nexthop
6355 	 */
6356 	__u8	family;
6357 
6358 	/* set if lookup is to consider L4 data - e.g., FIB rules */
6359 	__u8	l4_protocol;
6360 	__be16	sport;
6361 	__be16	dport;
6362 
6363 	union {	/* used for MTU check */
6364 		/* input to lookup */
6365 		__u16	tot_len; /* L3 length from network hdr (iph->tot_len) */
6366 
6367 		/* output: MTU value */
6368 		__u16	mtu_result;
6369 	};
6370 	/* input: L3 device index for lookup
6371 	 * output: device index from FIB lookup
6372 	 */
6373 	__u32	ifindex;
6374 
6375 	union {
6376 		/* inputs to lookup */
6377 		__u8	tos;		/* AF_INET  */
6378 		__be32	flowinfo;	/* AF_INET6, flow_label + priority */
6379 
6380 		/* output: metric of fib result (IPv4/IPv6 only) */
6381 		__u32	rt_metric;
6382 	};
6383 
6384 	union {
6385 		__be32		ipv4_src;
6386 		__u32		ipv6_src[4];  /* in6_addr; network order */
6387 	};
6388 
6389 	/* input to bpf_fib_lookup, ipv{4,6}_dst is destination address in
6390 	 * network header. output: bpf_fib_lookup sets to gateway address
6391 	 * if FIB lookup returns gateway route
6392 	 */
6393 	union {
6394 		__be32		ipv4_dst;
6395 		__u32		ipv6_dst[4];  /* in6_addr; network order */
6396 	};
6397 
6398 	/* output */
6399 	__be16	h_vlan_proto;
6400 	__be16	h_vlan_TCI;
6401 	__u8	smac[6];     /* ETH_ALEN */
6402 	__u8	dmac[6];     /* ETH_ALEN */
6403 };
6404 
6405 struct bpf_redir_neigh {
6406 	/* network family for lookup (AF_INET, AF_INET6) */
6407 	__u32 nh_family;
6408 	/* network address of nexthop; skips fib lookup to find gateway */
6409 	union {
6410 		__be32		ipv4_nh;
6411 		__u32		ipv6_nh[4];  /* in6_addr; network order */
6412 	};
6413 };
6414 
6415 /* bpf_check_mtu flags*/
6416 enum  bpf_check_mtu_flags {
6417 	BPF_MTU_CHK_SEGS  = (1U << 0),
6418 };
6419 
6420 enum bpf_check_mtu_ret {
6421 	BPF_MTU_CHK_RET_SUCCESS,      /* check and lookup successful */
6422 	BPF_MTU_CHK_RET_FRAG_NEEDED,  /* fragmentation required to fwd */
6423 	BPF_MTU_CHK_RET_SEGS_TOOBIG,  /* GSO re-segmentation needed to fwd */
6424 };
6425 
6426 enum bpf_task_fd_type {
6427 	BPF_FD_TYPE_RAW_TRACEPOINT,	/* tp name */
6428 	BPF_FD_TYPE_TRACEPOINT,		/* tp name */
6429 	BPF_FD_TYPE_KPROBE,		/* (symbol + offset) or addr */
6430 	BPF_FD_TYPE_KRETPROBE,		/* (symbol + offset) or addr */
6431 	BPF_FD_TYPE_UPROBE,		/* filename + offset */
6432 	BPF_FD_TYPE_URETPROBE,		/* filename + offset */
6433 };
6434 
6435 enum {
6436 	BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG		= (1U << 0),
6437 	BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL		= (1U << 1),
6438 	BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP		= (1U << 2),
6439 };
6440 
6441 struct bpf_flow_keys {
6442 	__u16	nhoff;
6443 	__u16	thoff;
6444 	__u16	addr_proto;			/* ETH_P_* of valid addrs */
6445 	__u8	is_frag;
6446 	__u8	is_first_frag;
6447 	__u8	is_encap;
6448 	__u8	ip_proto;
6449 	__be16	n_proto;
6450 	__be16	sport;
6451 	__be16	dport;
6452 	union {
6453 		struct {
6454 			__be32	ipv4_src;
6455 			__be32	ipv4_dst;
6456 		};
6457 		struct {
6458 			__u32	ipv6_src[4];	/* in6_addr; network order */
6459 			__u32	ipv6_dst[4];	/* in6_addr; network order */
6460 		};
6461 	};
6462 	__u32	flags;
6463 	__be32	flow_label;
6464 };
6465 
6466 struct bpf_func_info {
6467 	__u32	insn_off;
6468 	__u32	type_id;
6469 };
6470 
6471 #define BPF_LINE_INFO_LINE_NUM(line_col)	((line_col) >> 10)
6472 #define BPF_LINE_INFO_LINE_COL(line_col)	((line_col) & 0x3ff)
6473 
6474 struct bpf_line_info {
6475 	__u32	insn_off;
6476 	__u32	file_name_off;
6477 	__u32	line_off;
6478 	__u32	line_col;
6479 };
6480 
6481 struct bpf_spin_lock {
6482 	__u32	val;
6483 };
6484 
6485 struct bpf_timer {
6486 	__u64 :64;
6487 	__u64 :64;
6488 } __attribute__((aligned(8)));
6489 
6490 struct bpf_sysctl {
6491 	__u32	write;		/* Sysctl is being read (= 0) or written (= 1).
6492 				 * Allows 1,2,4-byte read, but no write.
6493 				 */
6494 	__u32	file_pos;	/* Sysctl file position to read from, write to.
6495 				 * Allows 1,2,4-byte read an 4-byte write.
6496 				 */
6497 };
6498 
6499 struct bpf_sockopt {
6500 	__bpf_md_ptr(struct bpf_sock *, sk);
6501 	__bpf_md_ptr(void *, optval);
6502 	__bpf_md_ptr(void *, optval_end);
6503 
6504 	__s32	level;
6505 	__s32	optname;
6506 	__s32	optlen;
6507 	__s32	retval;
6508 };
6509 
6510 struct bpf_pidns_info {
6511 	__u32 pid;
6512 	__u32 tgid;
6513 };
6514 
6515 /* User accessible data for SK_LOOKUP programs. Add new fields at the end. */
6516 struct bpf_sk_lookup {
6517 	union {
6518 		__bpf_md_ptr(struct bpf_sock *, sk); /* Selected socket */
6519 		__u64 cookie; /* Non-zero if socket was selected in PROG_TEST_RUN */
6520 	};
6521 
6522 	__u32 family;		/* Protocol family (AF_INET, AF_INET6) */
6523 	__u32 protocol;		/* IP protocol (IPPROTO_TCP, IPPROTO_UDP) */
6524 	__u32 remote_ip4;	/* Network byte order */
6525 	__u32 remote_ip6[4];	/* Network byte order */
6526 	__be16 remote_port;	/* Network byte order */
6527 	__u16 :16;		/* Zero padding */
6528 	__u32 local_ip4;	/* Network byte order */
6529 	__u32 local_ip6[4];	/* Network byte order */
6530 	__u32 local_port;	/* Host byte order */
6531 	__u32 ingress_ifindex;		/* The arriving interface. Determined by inet_iif. */
6532 };
6533 
6534 /*
6535  * struct btf_ptr is used for typed pointer representation; the
6536  * type id is used to render the pointer data as the appropriate type
6537  * via the bpf_snprintf_btf() helper described above.  A flags field -
6538  * potentially to specify additional details about the BTF pointer
6539  * (rather than its mode of display) - is included for future use.
6540  * Display flags - BTF_F_* - are passed to bpf_snprintf_btf separately.
6541  */
6542 struct btf_ptr {
6543 	void *ptr;
6544 	__u32 type_id;
6545 	__u32 flags;		/* BTF ptr flags; unused at present. */
6546 };
6547 
6548 /*
6549  * Flags to control bpf_snprintf_btf() behaviour.
6550  *     - BTF_F_COMPACT: no formatting around type information
6551  *     - BTF_F_NONAME: no struct/union member names/types
6552  *     - BTF_F_PTR_RAW: show raw (unobfuscated) pointer values;
6553  *       equivalent to %px.
6554  *     - BTF_F_ZERO: show zero-valued struct/union members; they
6555  *       are not displayed by default
6556  */
6557 enum {
6558 	BTF_F_COMPACT	=	(1ULL << 0),
6559 	BTF_F_NONAME	=	(1ULL << 1),
6560 	BTF_F_PTR_RAW	=	(1ULL << 2),
6561 	BTF_F_ZERO	=	(1ULL << 3),
6562 };
6563 
6564 /* bpf_core_relo_kind encodes which aspect of captured field/type/enum value
6565  * has to be adjusted by relocations. It is emitted by llvm and passed to
6566  * libbpf and later to the kernel.
6567  */
6568 enum bpf_core_relo_kind {
6569 	BPF_CORE_FIELD_BYTE_OFFSET = 0,      /* field byte offset */
6570 	BPF_CORE_FIELD_BYTE_SIZE = 1,        /* field size in bytes */
6571 	BPF_CORE_FIELD_EXISTS = 2,           /* field existence in target kernel */
6572 	BPF_CORE_FIELD_SIGNED = 3,           /* field signedness (0 - unsigned, 1 - signed) */
6573 	BPF_CORE_FIELD_LSHIFT_U64 = 4,       /* bitfield-specific left bitshift */
6574 	BPF_CORE_FIELD_RSHIFT_U64 = 5,       /* bitfield-specific right bitshift */
6575 	BPF_CORE_TYPE_ID_LOCAL = 6,          /* type ID in local BPF object */
6576 	BPF_CORE_TYPE_ID_TARGET = 7,         /* type ID in target kernel */
6577 	BPF_CORE_TYPE_EXISTS = 8,            /* type existence in target kernel */
6578 	BPF_CORE_TYPE_SIZE = 9,              /* type size in bytes */
6579 	BPF_CORE_ENUMVAL_EXISTS = 10,        /* enum value existence in target kernel */
6580 	BPF_CORE_ENUMVAL_VALUE = 11,         /* enum value integer value */
6581 };
6582 
6583 /*
6584  * "struct bpf_core_relo" is used to pass relocation data form LLVM to libbpf
6585  * and from libbpf to the kernel.
6586  *
6587  * CO-RE relocation captures the following data:
6588  * - insn_off - instruction offset (in bytes) within a BPF program that needs
6589  *   its insn->imm field to be relocated with actual field info;
6590  * - type_id - BTF type ID of the "root" (containing) entity of a relocatable
6591  *   type or field;
6592  * - access_str_off - offset into corresponding .BTF string section. String
6593  *   interpretation depends on specific relocation kind:
6594  *     - for field-based relocations, string encodes an accessed field using
6595  *       a sequence of field and array indices, separated by colon (:). It's
6596  *       conceptually very close to LLVM's getelementptr ([0]) instruction's
6597  *       arguments for identifying offset to a field.
6598  *     - for type-based relocations, strings is expected to be just "0";
6599  *     - for enum value-based relocations, string contains an index of enum
6600  *       value within its enum type;
6601  * - kind - one of enum bpf_core_relo_kind;
6602  *
6603  * Example:
6604  *   struct sample {
6605  *       int a;
6606  *       struct {
6607  *           int b[10];
6608  *       };
6609  *   };
6610  *
6611  *   struct sample *s = ...;
6612  *   int *x = &s->a;     // encoded as "0:0" (a is field #0)
6613  *   int *y = &s->b[5];  // encoded as "0:1:0:5" (anon struct is field #1,
6614  *                       // b is field #0 inside anon struct, accessing elem #5)
6615  *   int *z = &s[10]->b; // encoded as "10:1" (ptr is used as an array)
6616  *
6617  * type_id for all relocs in this example will capture BTF type id of
6618  * `struct sample`.
6619  *
6620  * Such relocation is emitted when using __builtin_preserve_access_index()
6621  * Clang built-in, passing expression that captures field address, e.g.:
6622  *
6623  * bpf_probe_read(&dst, sizeof(dst),
6624  *		  __builtin_preserve_access_index(&src->a.b.c));
6625  *
6626  * In this case Clang will emit field relocation recording necessary data to
6627  * be able to find offset of embedded `a.b.c` field within `src` struct.
6628  *
6629  * [0] https://llvm.org/docs/LangRef.html#getelementptr-instruction
6630  */
6631 struct bpf_core_relo {
6632 	__u32 insn_off;
6633 	__u32 type_id;
6634 	__u32 access_str_off;
6635 	enum bpf_core_relo_kind kind;
6636 };
6637 
6638 #endif /* _UAPI__LINUX_BPF_H__ */
6639 )********"
6640