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