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