7527 lines · c
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */2/* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com3 *4 * This program is free software; you can redistribute it and/or5 * modify it under the terms of version 2 of the GNU General Public6 * 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_MEMSX 0x80 /* load with sign extension */23#define BPF_ATOMIC 0xc0 /* atomic memory ops - op type in immediate */24#define BPF_XADD 0xc0 /* exclusive add - legacy name */25 26/* alu/jmp fields */27#define BPF_MOV 0xb0 /* mov reg to reg */28#define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */29 30/* change endianness of a register */31#define BPF_END 0xd0 /* flags for endianness conversion: */32#define BPF_TO_LE 0x00 /* convert to little-endian */33#define BPF_TO_BE 0x08 /* convert to big-endian */34#define BPF_FROM_LE BPF_TO_LE35#define BPF_FROM_BE BPF_TO_BE36 37/* jmp encodings */38#define BPF_JNE 0x50 /* jump != */39#define BPF_JLT 0xa0 /* LT is unsigned, '<' */40#define BPF_JLE 0xb0 /* LE is unsigned, '<=' */41#define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */42#define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */43#define BPF_JSLT 0xc0 /* SLT is signed, '<' */44#define BPF_JSLE 0xd0 /* SLE is signed, '<=' */45#define BPF_JCOND 0xe0 /* conditional pseudo jumps: may_goto, goto_or_nop */46#define BPF_CALL 0x80 /* function call */47#define BPF_EXIT 0x90 /* function return */48 49/* atomic op type fields (stored in immediate) */50#define BPF_FETCH 0x01 /* not an opcode on its own, used to build others */51#define BPF_XCHG (0xe0 | BPF_FETCH) /* atomic exchange */52#define BPF_CMPXCHG (0xf0 | BPF_FETCH) /* atomic compare-and-write */53 54enum bpf_cond_pseudo_jmp {55 BPF_MAY_GOTO = 0,56};57 58/* Register numbers */59enum {60 BPF_REG_0 = 0,61 BPF_REG_1,62 BPF_REG_2,63 BPF_REG_3,64 BPF_REG_4,65 BPF_REG_5,66 BPF_REG_6,67 BPF_REG_7,68 BPF_REG_8,69 BPF_REG_9,70 BPF_REG_10,71 __MAX_BPF_REG,72};73 74/* BPF has 10 general purpose 64-bit registers and stack frame. */75#define MAX_BPF_REG __MAX_BPF_REG76 77struct bpf_insn {78 __u8 code; /* opcode */79 __u8 dst_reg:4; /* dest register */80 __u8 src_reg:4; /* source register */81 __s16 off; /* signed offset */82 __s32 imm; /* signed immediate constant */83};84 85/* Deprecated: use struct bpf_lpm_trie_key_u8 (when the "data" member is needed for86 * byte access) or struct bpf_lpm_trie_key_hdr (when using an alternative type for87 * the trailing flexible array member) instead.88 */89struct bpf_lpm_trie_key {90 __u32 prefixlen; /* up to 32 for AF_INET, 128 for AF_INET6 */91 __u8 data[0]; /* Arbitrary size */92};93 94/* Header for bpf_lpm_trie_key structs */95struct bpf_lpm_trie_key_hdr {96 __u32 prefixlen;97};98 99/* Key of an a BPF_MAP_TYPE_LPM_TRIE entry, with trailing byte array. */100struct bpf_lpm_trie_key_u8 {101 union {102 struct bpf_lpm_trie_key_hdr hdr;103 __u32 prefixlen;104 };105 __u8 data[]; /* Arbitrary size */106};107 108struct bpf_cgroup_storage_key {109 __u64 cgroup_inode_id; /* cgroup inode id */110 __u32 attach_type; /* program attach type (enum bpf_attach_type) */111};112 113enum bpf_cgroup_iter_order {114 BPF_CGROUP_ITER_ORDER_UNSPEC = 0,115 BPF_CGROUP_ITER_SELF_ONLY, /* process only a single object. */116 BPF_CGROUP_ITER_DESCENDANTS_PRE, /* walk descendants in pre-order. */117 BPF_CGROUP_ITER_DESCENDANTS_POST, /* walk descendants in post-order. */118 BPF_CGROUP_ITER_ANCESTORS_UP, /* walk ancestors upward. */119};120 121union bpf_iter_link_info {122 struct {123 __u32 map_fd;124 } map;125 struct {126 enum bpf_cgroup_iter_order order;127 128 /* At most one of cgroup_fd and cgroup_id can be non-zero. If129 * both are zero, the walk starts from the default cgroup v2130 * root. For walking v1 hierarchy, one should always explicitly131 * specify cgroup_fd.132 */133 __u32 cgroup_fd;134 __u64 cgroup_id;135 } cgroup;136 /* Parameters of task iterators. */137 struct {138 __u32 tid;139 __u32 pid;140 __u32 pid_fd;141 } task;142};143 144/* BPF syscall commands, see bpf(2) man-page for more details. */145/**146 * DOC: eBPF Syscall Preamble147 *148 * The operation to be performed by the **bpf**\ () system call is determined149 * by the *cmd* argument. Each operation takes an accompanying argument,150 * provided via *attr*, which is a pointer to a union of type *bpf_attr* (see151 * below). The size argument is the size of the union pointed to by *attr*.152 */153/**154 * DOC: eBPF Syscall Commands155 *156 * BPF_MAP_CREATE157 * Description158 * Create a map and return a file descriptor that refers to the159 * map. The close-on-exec file descriptor flag (see **fcntl**\ (2))160 * is automatically enabled for the new file descriptor.161 *162 * Applying **close**\ (2) to the file descriptor returned by163 * **BPF_MAP_CREATE** will delete the map (but see NOTES).164 *165 * Return166 * A new file descriptor (a nonnegative integer), or -1 if an167 * error occurred (in which case, *errno* is set appropriately).168 *169 * BPF_MAP_LOOKUP_ELEM170 * Description171 * Look up an element with a given *key* in the map referred to172 * by the file descriptor *map_fd*.173 *174 * The *flags* argument may be specified as one of the175 * following:176 *177 * **BPF_F_LOCK**178 * Look up the value of a spin-locked map without179 * returning the lock. This must be specified if the180 * elements contain a spinlock.181 *182 * Return183 * Returns zero on success. On error, -1 is returned and *errno*184 * is set appropriately.185 *186 * BPF_MAP_UPDATE_ELEM187 * Description188 * Create or update an element (key/value pair) in a specified map.189 *190 * The *flags* argument should be specified as one of the191 * following:192 *193 * **BPF_ANY**194 * Create a new element or update an existing element.195 * **BPF_NOEXIST**196 * Create a new element only if it did not exist.197 * **BPF_EXIST**198 * Update an existing element.199 * **BPF_F_LOCK**200 * Update a spin_lock-ed map element.201 *202 * Return203 * Returns zero on success. On error, -1 is returned and *errno*204 * is set appropriately.205 *206 * May set *errno* to **EINVAL**, **EPERM**, **ENOMEM**,207 * **E2BIG**, **EEXIST**, or **ENOENT**.208 *209 * **E2BIG**210 * The number of elements in the map reached the211 * *max_entries* limit specified at map creation time.212 * **EEXIST**213 * If *flags* specifies **BPF_NOEXIST** and the element214 * with *key* already exists in the map.215 * **ENOENT**216 * If *flags* specifies **BPF_EXIST** and the element with217 * *key* does not exist in the map.218 *219 * BPF_MAP_DELETE_ELEM220 * Description221 * Look up and delete an element by key in a specified map.222 *223 * Return224 * Returns zero on success. On error, -1 is returned and *errno*225 * is set appropriately.226 *227 * BPF_MAP_GET_NEXT_KEY228 * Description229 * Look up an element by key in a specified map and return the key230 * of the next element. Can be used to iterate over all elements231 * in the map.232 *233 * Return234 * Returns zero on success. On error, -1 is returned and *errno*235 * is set appropriately.236 *237 * The following cases can be used to iterate over all elements of238 * the map:239 *240 * * If *key* is not found, the operation returns zero and sets241 * the *next_key* pointer to the key of the first element.242 * * If *key* is found, the operation returns zero and sets the243 * *next_key* pointer to the key of the next element.244 * * If *key* is the last element, returns -1 and *errno* is set245 * to **ENOENT**.246 *247 * May set *errno* to **ENOMEM**, **EFAULT**, **EPERM**, or248 * **EINVAL** on error.249 *250 * BPF_PROG_LOAD251 * Description252 * Verify and load an eBPF program, returning a new file253 * descriptor associated with the program.254 *255 * Applying **close**\ (2) to the file descriptor returned by256 * **BPF_PROG_LOAD** will unload the eBPF program (but see NOTES).257 *258 * The close-on-exec file descriptor flag (see **fcntl**\ (2)) is259 * automatically enabled for the new file descriptor.260 *261 * Return262 * A new file descriptor (a nonnegative integer), or -1 if an263 * error occurred (in which case, *errno* is set appropriately).264 *265 * BPF_OBJ_PIN266 * Description267 * Pin an eBPF program or map referred by the specified *bpf_fd*268 * to the provided *pathname* on the filesystem.269 *270 * The *pathname* argument must not contain a dot (".").271 *272 * On success, *pathname* retains a reference to the eBPF object,273 * preventing deallocation of the object when the original274 * *bpf_fd* is closed. This allow the eBPF object to live beyond275 * **close**\ (\ *bpf_fd*\ ), and hence the lifetime of the parent276 * process.277 *278 * Applying **unlink**\ (2) or similar calls to the *pathname*279 * unpins the object from the filesystem, removing the reference.280 * If no other file descriptors or filesystem nodes refer to the281 * same object, it will be deallocated (see NOTES).282 *283 * The filesystem type for the parent directory of *pathname* must284 * be **BPF_FS_MAGIC**.285 *286 * Return287 * Returns zero on success. On error, -1 is returned and *errno*288 * is set appropriately.289 *290 * BPF_OBJ_GET291 * Description292 * Open a file descriptor for the eBPF object pinned to the293 * specified *pathname*.294 *295 * Return296 * A new file descriptor (a nonnegative integer), or -1 if an297 * error occurred (in which case, *errno* is set appropriately).298 *299 * BPF_PROG_ATTACH300 * Description301 * Attach an eBPF program to a *target_fd* at the specified302 * *attach_type* hook.303 *304 * The *attach_type* specifies the eBPF attachment point to305 * attach the program to, and must be one of *bpf_attach_type*306 * (see below).307 *308 * The *attach_bpf_fd* must be a valid file descriptor for a309 * loaded eBPF program of a cgroup, flow dissector, LIRC, sockmap310 * or sock_ops type corresponding to the specified *attach_type*.311 *312 * The *target_fd* must be a valid file descriptor for a kernel313 * object which depends on the attach type of *attach_bpf_fd*:314 *315 * **BPF_PROG_TYPE_CGROUP_DEVICE**,316 * **BPF_PROG_TYPE_CGROUP_SKB**,317 * **BPF_PROG_TYPE_CGROUP_SOCK**,318 * **BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,319 * **BPF_PROG_TYPE_CGROUP_SOCKOPT**,320 * **BPF_PROG_TYPE_CGROUP_SYSCTL**,321 * **BPF_PROG_TYPE_SOCK_OPS**322 *323 * Control Group v2 hierarchy with the eBPF controller324 * enabled. Requires the kernel to be compiled with325 * **CONFIG_CGROUP_BPF**.326 *327 * **BPF_PROG_TYPE_FLOW_DISSECTOR**328 *329 * Network namespace (eg /proc/self/ns/net).330 *331 * **BPF_PROG_TYPE_LIRC_MODE2**332 *333 * LIRC device path (eg /dev/lircN). Requires the kernel334 * to be compiled with **CONFIG_BPF_LIRC_MODE2**.335 *336 * **BPF_PROG_TYPE_SK_SKB**,337 * **BPF_PROG_TYPE_SK_MSG**338 *339 * eBPF map of socket type (eg **BPF_MAP_TYPE_SOCKHASH**).340 *341 * Return342 * Returns zero on success. On error, -1 is returned and *errno*343 * is set appropriately.344 *345 * BPF_PROG_DETACH346 * Description347 * Detach the eBPF program associated with the *target_fd* at the348 * hook specified by *attach_type*. The program must have been349 * previously attached using **BPF_PROG_ATTACH**.350 *351 * Return352 * Returns zero on success. On error, -1 is returned and *errno*353 * is set appropriately.354 *355 * BPF_PROG_TEST_RUN356 * Description357 * Run the eBPF program associated with the *prog_fd* a *repeat*358 * number of times against a provided program context *ctx_in* and359 * data *data_in*, and return the modified program context360 * *ctx_out*, *data_out* (for example, packet data), result of the361 * execution *retval*, and *duration* of the test run.362 *363 * The sizes of the buffers provided as input and output364 * parameters *ctx_in*, *ctx_out*, *data_in*, and *data_out* must365 * be provided in the corresponding variables *ctx_size_in*,366 * *ctx_size_out*, *data_size_in*, and/or *data_size_out*. If any367 * of these parameters are not provided (ie set to NULL), the368 * corresponding size field must be zero.369 *370 * Some program types have particular requirements:371 *372 * **BPF_PROG_TYPE_SK_LOOKUP**373 * *data_in* and *data_out* must be NULL.374 *375 * **BPF_PROG_TYPE_RAW_TRACEPOINT**,376 * **BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE**377 *378 * *ctx_out*, *data_in* and *data_out* must be NULL.379 * *repeat* must be zero.380 *381 * BPF_PROG_RUN is an alias for BPF_PROG_TEST_RUN.382 *383 * Return384 * Returns zero on success. On error, -1 is returned and *errno*385 * is set appropriately.386 *387 * **ENOSPC**388 * Either *data_size_out* or *ctx_size_out* is too small.389 * **ENOTSUPP**390 * This command is not supported by the program type of391 * the program referred to by *prog_fd*.392 *393 * BPF_PROG_GET_NEXT_ID394 * Description395 * Fetch the next eBPF program currently loaded into the kernel.396 *397 * Looks for the eBPF program with an id greater than *start_id*398 * and updates *next_id* on success. If no other eBPF programs399 * remain with ids higher than *start_id*, returns -1 and sets400 * *errno* to **ENOENT**.401 *402 * Return403 * Returns zero on success. On error, or when no id remains, -1404 * is returned and *errno* is set appropriately.405 *406 * BPF_MAP_GET_NEXT_ID407 * Description408 * Fetch the next eBPF map currently loaded into the kernel.409 *410 * Looks for the eBPF map with an id greater than *start_id*411 * and updates *next_id* on success. If no other eBPF maps412 * remain with ids higher than *start_id*, returns -1 and sets413 * *errno* to **ENOENT**.414 *415 * Return416 * Returns zero on success. On error, or when no id remains, -1417 * is returned and *errno* is set appropriately.418 *419 * BPF_PROG_GET_FD_BY_ID420 * Description421 * Open a file descriptor for the eBPF program corresponding to422 * *prog_id*.423 *424 * Return425 * A new file descriptor (a nonnegative integer), or -1 if an426 * error occurred (in which case, *errno* is set appropriately).427 *428 * BPF_MAP_GET_FD_BY_ID429 * Description430 * Open a file descriptor for the eBPF map corresponding to431 * *map_id*.432 *433 * Return434 * A new file descriptor (a nonnegative integer), or -1 if an435 * error occurred (in which case, *errno* is set appropriately).436 *437 * BPF_OBJ_GET_INFO_BY_FD438 * Description439 * Obtain information about the eBPF object corresponding to440 * *bpf_fd*.441 *442 * Populates up to *info_len* bytes of *info*, which will be in443 * one of the following formats depending on the eBPF object type444 * of *bpf_fd*:445 *446 * * **struct bpf_prog_info**447 * * **struct bpf_map_info**448 * * **struct bpf_btf_info**449 * * **struct bpf_link_info**450 *451 * Return452 * Returns zero on success. On error, -1 is returned and *errno*453 * is set appropriately.454 *455 * BPF_PROG_QUERY456 * Description457 * Obtain information about eBPF programs associated with the458 * specified *attach_type* hook.459 *460 * The *target_fd* must be a valid file descriptor for a kernel461 * object which depends on the attach type of *attach_bpf_fd*:462 *463 * **BPF_PROG_TYPE_CGROUP_DEVICE**,464 * **BPF_PROG_TYPE_CGROUP_SKB**,465 * **BPF_PROG_TYPE_CGROUP_SOCK**,466 * **BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,467 * **BPF_PROG_TYPE_CGROUP_SOCKOPT**,468 * **BPF_PROG_TYPE_CGROUP_SYSCTL**,469 * **BPF_PROG_TYPE_SOCK_OPS**470 *471 * Control Group v2 hierarchy with the eBPF controller472 * enabled. Requires the kernel to be compiled with473 * **CONFIG_CGROUP_BPF**.474 *475 * **BPF_PROG_TYPE_FLOW_DISSECTOR**476 *477 * Network namespace (eg /proc/self/ns/net).478 *479 * **BPF_PROG_TYPE_LIRC_MODE2**480 *481 * LIRC device path (eg /dev/lircN). Requires the kernel482 * to be compiled with **CONFIG_BPF_LIRC_MODE2**.483 *484 * **BPF_PROG_QUERY** always fetches the number of programs485 * attached and the *attach_flags* which were used to attach those486 * programs. Additionally, if *prog_ids* is nonzero and the number487 * of attached programs is less than *prog_cnt*, populates488 * *prog_ids* with the eBPF program ids of the programs attached489 * at *target_fd*.490 *491 * The following flags may alter the result:492 *493 * **BPF_F_QUERY_EFFECTIVE**494 * Only return information regarding programs which are495 * currently effective at the specified *target_fd*.496 *497 * Return498 * Returns zero on success. On error, -1 is returned and *errno*499 * is set appropriately.500 *501 * BPF_RAW_TRACEPOINT_OPEN502 * Description503 * Attach an eBPF program to a tracepoint *name* to access kernel504 * internal arguments of the tracepoint in their raw form.505 *506 * The *prog_fd* must be a valid file descriptor associated with507 * a loaded eBPF program of type **BPF_PROG_TYPE_RAW_TRACEPOINT**.508 *509 * No ABI guarantees are made about the content of tracepoint510 * arguments exposed to the corresponding eBPF program.511 *512 * Applying **close**\ (2) to the file descriptor returned by513 * **BPF_RAW_TRACEPOINT_OPEN** will delete the map (but see NOTES).514 *515 * Return516 * A new file descriptor (a nonnegative integer), or -1 if an517 * error occurred (in which case, *errno* is set appropriately).518 *519 * BPF_BTF_LOAD520 * Description521 * Verify and load BPF Type Format (BTF) metadata into the kernel,522 * returning a new file descriptor associated with the metadata.523 * BTF is described in more detail at524 * https://www.kernel.org/doc/html/latest/bpf/btf.html.525 *526 * The *btf* parameter must point to valid memory providing527 * *btf_size* bytes of BTF binary metadata.528 *529 * The returned file descriptor can be passed to other **bpf**\ ()530 * subcommands such as **BPF_PROG_LOAD** or **BPF_MAP_CREATE** to531 * associate the BTF with those objects.532 *533 * Similar to **BPF_PROG_LOAD**, **BPF_BTF_LOAD** has optional534 * parameters to specify a *btf_log_buf*, *btf_log_size* and535 * *btf_log_level* which allow the kernel to return freeform log536 * output regarding the BTF verification process.537 *538 * Return539 * A new file descriptor (a nonnegative integer), or -1 if an540 * error occurred (in which case, *errno* is set appropriately).541 *542 * BPF_BTF_GET_FD_BY_ID543 * Description544 * Open a file descriptor for the BPF Type Format (BTF)545 * corresponding to *btf_id*.546 *547 * Return548 * A new file descriptor (a nonnegative integer), or -1 if an549 * error occurred (in which case, *errno* is set appropriately).550 *551 * BPF_TASK_FD_QUERY552 * Description553 * Obtain information about eBPF programs associated with the554 * target process identified by *pid* and *fd*.555 *556 * If the *pid* and *fd* are associated with a tracepoint, kprobe557 * or uprobe perf event, then the *prog_id* and *fd_type* will558 * be populated with the eBPF program id and file descriptor type559 * of type **bpf_task_fd_type**. If associated with a kprobe or560 * uprobe, the *probe_offset* and *probe_addr* will also be561 * populated. Optionally, if *buf* is provided, then up to562 * *buf_len* bytes of *buf* will be populated with the name of563 * the tracepoint, kprobe or uprobe.564 *565 * The resulting *prog_id* may be introspected in deeper detail566 * using **BPF_PROG_GET_FD_BY_ID** and **BPF_OBJ_GET_INFO_BY_FD**.567 *568 * Return569 * Returns zero on success. On error, -1 is returned and *errno*570 * is set appropriately.571 *572 * BPF_MAP_LOOKUP_AND_DELETE_ELEM573 * Description574 * Look up an element with the given *key* in the map referred to575 * by the file descriptor *fd*, and if found, delete the element.576 *577 * For **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map578 * types, the *flags* argument needs to be set to 0, but for other579 * map types, it may be specified as:580 *581 * **BPF_F_LOCK**582 * Look up and delete the value of a spin-locked map583 * without returning the lock. This must be specified if584 * the elements contain a spinlock.585 *586 * The **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map types587 * implement this command as a "pop" operation, deleting the top588 * element rather than one corresponding to *key*.589 * The *key* and *key_len* parameters should be zeroed when590 * issuing this operation for these map types.591 *592 * This command is only valid for the following map types:593 * * **BPF_MAP_TYPE_QUEUE**594 * * **BPF_MAP_TYPE_STACK**595 * * **BPF_MAP_TYPE_HASH**596 * * **BPF_MAP_TYPE_PERCPU_HASH**597 * * **BPF_MAP_TYPE_LRU_HASH**598 * * **BPF_MAP_TYPE_LRU_PERCPU_HASH**599 *600 * Return601 * Returns zero on success. On error, -1 is returned and *errno*602 * is set appropriately.603 *604 * BPF_MAP_FREEZE605 * Description606 * Freeze the permissions of the specified map.607 *608 * Write permissions may be frozen by passing zero *flags*.609 * Upon success, no future syscall invocations may alter the610 * map state of *map_fd*. Write operations from eBPF programs611 * are still possible for a frozen map.612 *613 * Not supported for maps of type **BPF_MAP_TYPE_STRUCT_OPS**.614 *615 * Return616 * Returns zero on success. On error, -1 is returned and *errno*617 * is set appropriately.618 *619 * BPF_BTF_GET_NEXT_ID620 * Description621 * Fetch the next BPF Type Format (BTF) object currently loaded622 * into the kernel.623 *624 * Looks for the BTF object with an id greater than *start_id*625 * and updates *next_id* on success. If no other BTF objects626 * remain with ids higher than *start_id*, returns -1 and sets627 * *errno* to **ENOENT**.628 *629 * Return630 * Returns zero on success. On error, or when no id remains, -1631 * is returned and *errno* is set appropriately.632 *633 * BPF_MAP_LOOKUP_BATCH634 * Description635 * Iterate and fetch multiple elements in a map.636 *637 * Two opaque values are used to manage batch operations,638 * *in_batch* and *out_batch*. Initially, *in_batch* must be set639 * to NULL to begin the batched operation. After each subsequent640 * **BPF_MAP_LOOKUP_BATCH**, the caller should pass the resultant641 * *out_batch* as the *in_batch* for the next operation to642 * continue iteration from the current point. Both *in_batch* and643 * *out_batch* must point to memory large enough to hold a key,644 * except for maps of type **BPF_MAP_TYPE_{HASH, PERCPU_HASH,645 * LRU_HASH, LRU_PERCPU_HASH}**, for which batch parameters646 * must be at least 4 bytes wide regardless of key size.647 *648 * The *keys* and *values* are output parameters which must point649 * to memory large enough to hold *count* items based on the key650 * and value size of the map *map_fd*. The *keys* buffer must be651 * of *key_size* * *count*. The *values* buffer must be of652 * *value_size* * *count*.653 *654 * The *elem_flags* argument may be specified as one of the655 * following:656 *657 * **BPF_F_LOCK**658 * Look up the value of a spin-locked map without659 * returning the lock. This must be specified if the660 * elements contain a spinlock.661 *662 * On success, *count* elements from the map are copied into the663 * user buffer, with the keys copied into *keys* and the values664 * copied into the corresponding indices in *values*.665 *666 * If an error is returned and *errno* is not **EFAULT**, *count*667 * is set to the number of successfully processed elements.668 *669 * Return670 * Returns zero on success. On error, -1 is returned and *errno*671 * is set appropriately.672 *673 * May set *errno* to **ENOSPC** to indicate that *keys* or674 * *values* is too small to dump an entire bucket during675 * iteration of a hash-based map type.676 *677 * BPF_MAP_LOOKUP_AND_DELETE_BATCH678 * Description679 * Iterate and delete all elements in a map.680 *681 * This operation has the same behavior as682 * **BPF_MAP_LOOKUP_BATCH** with two exceptions:683 *684 * * Every element that is successfully returned is also deleted685 * from the map. This is at least *count* elements. Note that686 * *count* is both an input and an output parameter.687 * * Upon returning with *errno* set to **EFAULT**, up to688 * *count* elements may be deleted without returning the keys689 * and values of the deleted elements.690 *691 * Return692 * Returns zero on success. On error, -1 is returned and *errno*693 * is set appropriately.694 *695 * BPF_MAP_UPDATE_BATCH696 * Description697 * Update multiple elements in a map by *key*.698 *699 * The *keys* and *values* are input parameters which must point700 * to memory large enough to hold *count* items based on the key701 * and value size of the map *map_fd*. The *keys* buffer must be702 * of *key_size* * *count*. The *values* buffer must be of703 * *value_size* * *count*.704 *705 * Each element specified in *keys* is sequentially updated to the706 * value in the corresponding index in *values*. The *in_batch*707 * and *out_batch* parameters are ignored and should be zeroed.708 *709 * The *elem_flags* argument should be specified as one of the710 * following:711 *712 * **BPF_ANY**713 * Create new elements or update a existing elements.714 * **BPF_NOEXIST**715 * Create new elements only if they do not exist.716 * **BPF_EXIST**717 * Update existing elements.718 * **BPF_F_LOCK**719 * Update spin_lock-ed map elements. This must be720 * specified if the map value contains a spinlock.721 *722 * On success, *count* elements from the map are updated.723 *724 * If an error is returned and *errno* is not **EFAULT**, *count*725 * is set to the number of successfully processed elements.726 *727 * Return728 * Returns zero on success. On error, -1 is returned and *errno*729 * is set appropriately.730 *731 * May set *errno* to **EINVAL**, **EPERM**, **ENOMEM**, or732 * **E2BIG**. **E2BIG** indicates that the number of elements in733 * the map reached the *max_entries* limit specified at map734 * creation time.735 *736 * May set *errno* to one of the following error codes under737 * specific circumstances:738 *739 * **EEXIST**740 * If *flags* specifies **BPF_NOEXIST** and the element741 * with *key* already exists in the map.742 * **ENOENT**743 * If *flags* specifies **BPF_EXIST** and the element with744 * *key* does not exist in the map.745 *746 * BPF_MAP_DELETE_BATCH747 * Description748 * Delete multiple elements in a map by *key*.749 *750 * The *keys* parameter is an input parameter which must point751 * to memory large enough to hold *count* items based on the key752 * size of the map *map_fd*, that is, *key_size* * *count*.753 *754 * Each element specified in *keys* is sequentially deleted. The755 * *in_batch*, *out_batch*, and *values* parameters are ignored756 * and should be zeroed.757 *758 * The *elem_flags* argument may be specified as one of the759 * following:760 *761 * **BPF_F_LOCK**762 * Look up the value of a spin-locked map without763 * returning the lock. This must be specified if the764 * elements contain a spinlock.765 *766 * On success, *count* elements from the map are updated.767 *768 * If an error is returned and *errno* is not **EFAULT**, *count*769 * is set to the number of successfully processed elements. If770 * *errno* is **EFAULT**, up to *count* elements may be been771 * deleted.772 *773 * Return774 * Returns zero on success. On error, -1 is returned and *errno*775 * is set appropriately.776 *777 * BPF_LINK_CREATE778 * Description779 * Attach an eBPF program to a *target_fd* at the specified780 * *attach_type* hook and return a file descriptor handle for781 * managing the link.782 *783 * Return784 * A new file descriptor (a nonnegative integer), or -1 if an785 * error occurred (in which case, *errno* is set appropriately).786 *787 * BPF_LINK_UPDATE788 * Description789 * Update the eBPF program in the specified *link_fd* to790 * *new_prog_fd*.791 *792 * Return793 * Returns zero on success. On error, -1 is returned and *errno*794 * is set appropriately.795 *796 * BPF_LINK_GET_FD_BY_ID797 * Description798 * Open a file descriptor for the eBPF Link corresponding to799 * *link_id*.800 *801 * Return802 * A new file descriptor (a nonnegative integer), or -1 if an803 * error occurred (in which case, *errno* is set appropriately).804 *805 * BPF_LINK_GET_NEXT_ID806 * Description807 * Fetch the next eBPF link currently loaded into the kernel.808 *809 * Looks for the eBPF link with an id greater than *start_id*810 * and updates *next_id* on success. If no other eBPF links811 * remain with ids higher than *start_id*, returns -1 and sets812 * *errno* to **ENOENT**.813 *814 * Return815 * Returns zero on success. On error, or when no id remains, -1816 * is returned and *errno* is set appropriately.817 *818 * BPF_ENABLE_STATS819 * Description820 * Enable eBPF runtime statistics gathering.821 *822 * Runtime statistics gathering for the eBPF runtime is disabled823 * by default to minimize the corresponding performance overhead.824 * This command enables statistics globally.825 *826 * Multiple programs may independently enable statistics.827 * After gathering the desired statistics, eBPF runtime statistics828 * may be disabled again by calling **close**\ (2) for the file829 * descriptor returned by this function. Statistics will only be830 * disabled system-wide when all outstanding file descriptors831 * returned by prior calls for this subcommand are closed.832 *833 * Return834 * A new file descriptor (a nonnegative integer), or -1 if an835 * error occurred (in which case, *errno* is set appropriately).836 *837 * BPF_ITER_CREATE838 * Description839 * Create an iterator on top of the specified *link_fd* (as840 * previously created using **BPF_LINK_CREATE**) and return a841 * file descriptor that can be used to trigger the iteration.842 *843 * If the resulting file descriptor is pinned to the filesystem844 * using **BPF_OBJ_PIN**, then subsequent **read**\ (2) syscalls845 * for that path will trigger the iterator to read kernel state846 * using the eBPF program attached to *link_fd*.847 *848 * Return849 * A new file descriptor (a nonnegative integer), or -1 if an850 * error occurred (in which case, *errno* is set appropriately).851 *852 * BPF_LINK_DETACH853 * Description854 * Forcefully detach the specified *link_fd* from its855 * corresponding attachment point.856 *857 * Return858 * Returns zero on success. On error, -1 is returned and *errno*859 * is set appropriately.860 *861 * BPF_PROG_BIND_MAP862 * Description863 * Bind a map to the lifetime of an eBPF program.864 *865 * The map identified by *map_fd* is bound to the program866 * identified by *prog_fd* and only released when *prog_fd* is867 * released. This may be used in cases where metadata should be868 * associated with a program which otherwise does not contain any869 * references to the map (for example, embedded in the eBPF870 * program instructions).871 *872 * Return873 * Returns zero on success. On error, -1 is returned and *errno*874 * is set appropriately.875 *876 * BPF_TOKEN_CREATE877 * Description878 * Create BPF token with embedded information about what879 * BPF-related functionality it allows:880 * - a set of allowed bpf() syscall commands;881 * - a set of allowed BPF map types to be created with882 * BPF_MAP_CREATE command, if BPF_MAP_CREATE itself is allowed;883 * - a set of allowed BPF program types and BPF program attach884 * types to be loaded with BPF_PROG_LOAD command, if885 * BPF_PROG_LOAD itself is allowed.886 *887 * BPF token is created (derived) from an instance of BPF FS,888 * assuming it has necessary delegation mount options specified.889 * This BPF token can be passed as an extra parameter to various890 * bpf() syscall commands to grant BPF subsystem functionality to891 * unprivileged processes.892 *893 * When created, BPF token is "associated" with the owning894 * user namespace of BPF FS instance (super block) that it was895 * derived from, and subsequent BPF operations performed with896 * BPF token would be performing capabilities checks (i.e.,897 * CAP_BPF, CAP_PERFMON, CAP_NET_ADMIN, CAP_SYS_ADMIN) within898 * that user namespace. Without BPF token, such capabilities899 * have to be granted in init user namespace, making bpf()900 * syscall incompatible with user namespace, for the most part.901 *902 * Return903 * A new file descriptor (a nonnegative integer), or -1 if an904 * error occurred (in which case, *errno* is set appropriately).905 *906 * NOTES907 * eBPF objects (maps and programs) can be shared between processes.908 *909 * * After **fork**\ (2), the child inherits file descriptors910 * referring to the same eBPF objects.911 * * File descriptors referring to eBPF objects can be transferred over912 * **unix**\ (7) domain sockets.913 * * File descriptors referring to eBPF objects can be duplicated in the914 * usual way, using **dup**\ (2) and similar calls.915 * * File descriptors referring to eBPF objects can be pinned to the916 * filesystem using the **BPF_OBJ_PIN** command of **bpf**\ (2).917 *918 * An eBPF object is deallocated only after all file descriptors referring919 * to the object have been closed and no references remain pinned to the920 * filesystem or attached (for example, bound to a program or device).921 */922enum bpf_cmd {923 BPF_MAP_CREATE,924 BPF_MAP_LOOKUP_ELEM,925 BPF_MAP_UPDATE_ELEM,926 BPF_MAP_DELETE_ELEM,927 BPF_MAP_GET_NEXT_KEY,928 BPF_PROG_LOAD,929 BPF_OBJ_PIN,930 BPF_OBJ_GET,931 BPF_PROG_ATTACH,932 BPF_PROG_DETACH,933 BPF_PROG_TEST_RUN,934 BPF_PROG_RUN = BPF_PROG_TEST_RUN,935 BPF_PROG_GET_NEXT_ID,936 BPF_MAP_GET_NEXT_ID,937 BPF_PROG_GET_FD_BY_ID,938 BPF_MAP_GET_FD_BY_ID,939 BPF_OBJ_GET_INFO_BY_FD,940 BPF_PROG_QUERY,941 BPF_RAW_TRACEPOINT_OPEN,942 BPF_BTF_LOAD,943 BPF_BTF_GET_FD_BY_ID,944 BPF_TASK_FD_QUERY,945 BPF_MAP_LOOKUP_AND_DELETE_ELEM,946 BPF_MAP_FREEZE,947 BPF_BTF_GET_NEXT_ID,948 BPF_MAP_LOOKUP_BATCH,949 BPF_MAP_LOOKUP_AND_DELETE_BATCH,950 BPF_MAP_UPDATE_BATCH,951 BPF_MAP_DELETE_BATCH,952 BPF_LINK_CREATE,953 BPF_LINK_UPDATE,954 BPF_LINK_GET_FD_BY_ID,955 BPF_LINK_GET_NEXT_ID,956 BPF_ENABLE_STATS,957 BPF_ITER_CREATE,958 BPF_LINK_DETACH,959 BPF_PROG_BIND_MAP,960 BPF_TOKEN_CREATE,961 __MAX_BPF_CMD,962};963 964enum bpf_map_type {965 BPF_MAP_TYPE_UNSPEC,966 BPF_MAP_TYPE_HASH,967 BPF_MAP_TYPE_ARRAY,968 BPF_MAP_TYPE_PROG_ARRAY,969 BPF_MAP_TYPE_PERF_EVENT_ARRAY,970 BPF_MAP_TYPE_PERCPU_HASH,971 BPF_MAP_TYPE_PERCPU_ARRAY,972 BPF_MAP_TYPE_STACK_TRACE,973 BPF_MAP_TYPE_CGROUP_ARRAY,974 BPF_MAP_TYPE_LRU_HASH,975 BPF_MAP_TYPE_LRU_PERCPU_HASH,976 BPF_MAP_TYPE_LPM_TRIE,977 BPF_MAP_TYPE_ARRAY_OF_MAPS,978 BPF_MAP_TYPE_HASH_OF_MAPS,979 BPF_MAP_TYPE_DEVMAP,980 BPF_MAP_TYPE_SOCKMAP,981 BPF_MAP_TYPE_CPUMAP,982 BPF_MAP_TYPE_XSKMAP,983 BPF_MAP_TYPE_SOCKHASH,984 BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED,985 /* BPF_MAP_TYPE_CGROUP_STORAGE is available to bpf programs attaching986 * to a cgroup. The newer BPF_MAP_TYPE_CGRP_STORAGE is available to987 * both cgroup-attached and other progs and supports all functionality988 * provided by BPF_MAP_TYPE_CGROUP_STORAGE. So mark989 * BPF_MAP_TYPE_CGROUP_STORAGE deprecated.990 */991 BPF_MAP_TYPE_CGROUP_STORAGE = BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED,992 BPF_MAP_TYPE_REUSEPORT_SOCKARRAY,993 BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE_DEPRECATED,994 /* BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE is available to bpf programs995 * attaching to a cgroup. The new mechanism (BPF_MAP_TYPE_CGRP_STORAGE +996 * local percpu kptr) supports all BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE997 * functionality and more. So mark * BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE998 * deprecated.999 */1000 BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE = BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE_DEPRECATED,1001 BPF_MAP_TYPE_QUEUE,1002 BPF_MAP_TYPE_STACK,1003 BPF_MAP_TYPE_SK_STORAGE,1004 BPF_MAP_TYPE_DEVMAP_HASH,1005 BPF_MAP_TYPE_STRUCT_OPS,1006 BPF_MAP_TYPE_RINGBUF,1007 BPF_MAP_TYPE_INODE_STORAGE,1008 BPF_MAP_TYPE_TASK_STORAGE,1009 BPF_MAP_TYPE_BLOOM_FILTER,1010 BPF_MAP_TYPE_USER_RINGBUF,1011 BPF_MAP_TYPE_CGRP_STORAGE,1012 BPF_MAP_TYPE_ARENA,1013 __MAX_BPF_MAP_TYPE1014};1015 1016/* Note that tracing related programs such as1017 * BPF_PROG_TYPE_{KPROBE,TRACEPOINT,PERF_EVENT,RAW_TRACEPOINT}1018 * are not subject to a stable API since kernel internal data1019 * structures can change from release to release and may1020 * therefore break existing tracing BPF programs. Tracing BPF1021 * programs correspond to /a/ specific kernel which is to be1022 * analyzed, and not /a/ specific kernel /and/ all future ones.1023 */1024enum bpf_prog_type {1025 BPF_PROG_TYPE_UNSPEC,1026 BPF_PROG_TYPE_SOCKET_FILTER,1027 BPF_PROG_TYPE_KPROBE,1028 BPF_PROG_TYPE_SCHED_CLS,1029 BPF_PROG_TYPE_SCHED_ACT,1030 BPF_PROG_TYPE_TRACEPOINT,1031 BPF_PROG_TYPE_XDP,1032 BPF_PROG_TYPE_PERF_EVENT,1033 BPF_PROG_TYPE_CGROUP_SKB,1034 BPF_PROG_TYPE_CGROUP_SOCK,1035 BPF_PROG_TYPE_LWT_IN,1036 BPF_PROG_TYPE_LWT_OUT,1037 BPF_PROG_TYPE_LWT_XMIT,1038 BPF_PROG_TYPE_SOCK_OPS,1039 BPF_PROG_TYPE_SK_SKB,1040 BPF_PROG_TYPE_CGROUP_DEVICE,1041 BPF_PROG_TYPE_SK_MSG,1042 BPF_PROG_TYPE_RAW_TRACEPOINT,1043 BPF_PROG_TYPE_CGROUP_SOCK_ADDR,1044 BPF_PROG_TYPE_LWT_SEG6LOCAL,1045 BPF_PROG_TYPE_LIRC_MODE2,1046 BPF_PROG_TYPE_SK_REUSEPORT,1047 BPF_PROG_TYPE_FLOW_DISSECTOR,1048 BPF_PROG_TYPE_CGROUP_SYSCTL,1049 BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,1050 BPF_PROG_TYPE_CGROUP_SOCKOPT,1051 BPF_PROG_TYPE_TRACING,1052 BPF_PROG_TYPE_STRUCT_OPS,1053 BPF_PROG_TYPE_EXT,1054 BPF_PROG_TYPE_LSM,1055 BPF_PROG_TYPE_SK_LOOKUP,1056 BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */1057 BPF_PROG_TYPE_NETFILTER,1058 __MAX_BPF_PROG_TYPE1059};1060 1061enum bpf_attach_type {1062 BPF_CGROUP_INET_INGRESS,1063 BPF_CGROUP_INET_EGRESS,1064 BPF_CGROUP_INET_SOCK_CREATE,1065 BPF_CGROUP_SOCK_OPS,1066 BPF_SK_SKB_STREAM_PARSER,1067 BPF_SK_SKB_STREAM_VERDICT,1068 BPF_CGROUP_DEVICE,1069 BPF_SK_MSG_VERDICT,1070 BPF_CGROUP_INET4_BIND,1071 BPF_CGROUP_INET6_BIND,1072 BPF_CGROUP_INET4_CONNECT,1073 BPF_CGROUP_INET6_CONNECT,1074 BPF_CGROUP_INET4_POST_BIND,1075 BPF_CGROUP_INET6_POST_BIND,1076 BPF_CGROUP_UDP4_SENDMSG,1077 BPF_CGROUP_UDP6_SENDMSG,1078 BPF_LIRC_MODE2,1079 BPF_FLOW_DISSECTOR,1080 BPF_CGROUP_SYSCTL,1081 BPF_CGROUP_UDP4_RECVMSG,1082 BPF_CGROUP_UDP6_RECVMSG,1083 BPF_CGROUP_GETSOCKOPT,1084 BPF_CGROUP_SETSOCKOPT,1085 BPF_TRACE_RAW_TP,1086 BPF_TRACE_FENTRY,1087 BPF_TRACE_FEXIT,1088 BPF_MODIFY_RETURN,1089 BPF_LSM_MAC,1090 BPF_TRACE_ITER,1091 BPF_CGROUP_INET4_GETPEERNAME,1092 BPF_CGROUP_INET6_GETPEERNAME,1093 BPF_CGROUP_INET4_GETSOCKNAME,1094 BPF_CGROUP_INET6_GETSOCKNAME,1095 BPF_XDP_DEVMAP,1096 BPF_CGROUP_INET_SOCK_RELEASE,1097 BPF_XDP_CPUMAP,1098 BPF_SK_LOOKUP,1099 BPF_XDP,1100 BPF_SK_SKB_VERDICT,1101 BPF_SK_REUSEPORT_SELECT,1102 BPF_SK_REUSEPORT_SELECT_OR_MIGRATE,1103 BPF_PERF_EVENT,1104 BPF_TRACE_KPROBE_MULTI,1105 BPF_LSM_CGROUP,1106 BPF_STRUCT_OPS,1107 BPF_NETFILTER,1108 BPF_TCX_INGRESS,1109 BPF_TCX_EGRESS,1110 BPF_TRACE_UPROBE_MULTI,1111 BPF_CGROUP_UNIX_CONNECT,1112 BPF_CGROUP_UNIX_SENDMSG,1113 BPF_CGROUP_UNIX_RECVMSG,1114 BPF_CGROUP_UNIX_GETPEERNAME,1115 BPF_CGROUP_UNIX_GETSOCKNAME,1116 BPF_NETKIT_PRIMARY,1117 BPF_NETKIT_PEER,1118 BPF_TRACE_KPROBE_SESSION,1119 __MAX_BPF_ATTACH_TYPE1120};1121 1122#define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE1123 1124/* Add BPF_LINK_TYPE(type, name) in bpf_types.h to keep bpf_link_type_strs[]1125 * in sync with the definitions below.1126 */1127enum bpf_link_type {1128 BPF_LINK_TYPE_UNSPEC = 0,1129 BPF_LINK_TYPE_RAW_TRACEPOINT = 1,1130 BPF_LINK_TYPE_TRACING = 2,1131 BPF_LINK_TYPE_CGROUP = 3,1132 BPF_LINK_TYPE_ITER = 4,1133 BPF_LINK_TYPE_NETNS = 5,1134 BPF_LINK_TYPE_XDP = 6,1135 BPF_LINK_TYPE_PERF_EVENT = 7,1136 BPF_LINK_TYPE_KPROBE_MULTI = 8,1137 BPF_LINK_TYPE_STRUCT_OPS = 9,1138 BPF_LINK_TYPE_NETFILTER = 10,1139 BPF_LINK_TYPE_TCX = 11,1140 BPF_LINK_TYPE_UPROBE_MULTI = 12,1141 BPF_LINK_TYPE_NETKIT = 13,1142 BPF_LINK_TYPE_SOCKMAP = 14,1143 __MAX_BPF_LINK_TYPE,1144};1145 1146#define MAX_BPF_LINK_TYPE __MAX_BPF_LINK_TYPE1147 1148enum bpf_perf_event_type {1149 BPF_PERF_EVENT_UNSPEC = 0,1150 BPF_PERF_EVENT_UPROBE = 1,1151 BPF_PERF_EVENT_URETPROBE = 2,1152 BPF_PERF_EVENT_KPROBE = 3,1153 BPF_PERF_EVENT_KRETPROBE = 4,1154 BPF_PERF_EVENT_TRACEPOINT = 5,1155 BPF_PERF_EVENT_EVENT = 6,1156};1157 1158/* cgroup-bpf attach flags used in BPF_PROG_ATTACH command1159 *1160 * NONE(default): No further bpf programs allowed in the subtree.1161 *1162 * BPF_F_ALLOW_OVERRIDE: If a sub-cgroup installs some bpf program,1163 * the program in this cgroup yields to sub-cgroup program.1164 *1165 * BPF_F_ALLOW_MULTI: If a sub-cgroup installs some bpf program,1166 * that cgroup program gets run in addition to the program in this cgroup.1167 *1168 * Only one program is allowed to be attached to a cgroup with1169 * NONE or BPF_F_ALLOW_OVERRIDE flag.1170 * Attaching another program on top of NONE or BPF_F_ALLOW_OVERRIDE will1171 * release old program and attach the new one. Attach flags has to match.1172 *1173 * Multiple programs are allowed to be attached to a cgroup with1174 * BPF_F_ALLOW_MULTI flag. They are executed in FIFO order1175 * (those that were attached first, run first)1176 * The programs of sub-cgroup are executed first, then programs of1177 * this cgroup and then programs of parent cgroup.1178 * When children program makes decision (like picking TCP CA or sock bind)1179 * parent program has a chance to override it.1180 *1181 * With BPF_F_ALLOW_MULTI a new program is added to the end of the list of1182 * programs for a cgroup. Though it's possible to replace an old program at1183 * any position by also specifying BPF_F_REPLACE flag and position itself in1184 * replace_bpf_fd attribute. Old program at this position will be released.1185 *1186 * A cgroup with MULTI or OVERRIDE flag allows any attach flags in sub-cgroups.1187 * A cgroup with NONE doesn't allow any programs in sub-cgroups.1188 * Ex1:1189 * cgrp1 (MULTI progs A, B) ->1190 * cgrp2 (OVERRIDE prog C) ->1191 * cgrp3 (MULTI prog D) ->1192 * cgrp4 (OVERRIDE prog E) ->1193 * cgrp5 (NONE prog F)1194 * the event in cgrp5 triggers execution of F,D,A,B in that order.1195 * if prog F is detached, the execution is E,D,A,B1196 * if prog F and D are detached, the execution is E,A,B1197 * if prog F, E and D are detached, the execution is C,A,B1198 *1199 * All eligible programs are executed regardless of return code from1200 * earlier programs.1201 */1202#define BPF_F_ALLOW_OVERRIDE (1U << 0)1203#define BPF_F_ALLOW_MULTI (1U << 1)1204/* Generic attachment flags. */1205#define BPF_F_REPLACE (1U << 2)1206#define BPF_F_BEFORE (1U << 3)1207#define BPF_F_AFTER (1U << 4)1208#define BPF_F_ID (1U << 5)1209#define BPF_F_LINK BPF_F_LINK /* 1 << 13 */1210 1211/* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the1212 * verifier will perform strict alignment checking as if the kernel1213 * has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set,1214 * and NET_IP_ALIGN defined to 2.1215 */1216#define BPF_F_STRICT_ALIGNMENT (1U << 0)1217 1218/* If BPF_F_ANY_ALIGNMENT is used in BPF_PROG_LOAD command, the1219 * verifier will allow any alignment whatsoever. On platforms1220 * with strict alignment requirements for loads ands stores (such1221 * as sparc and mips) the verifier validates that all loads and1222 * stores provably follow this requirement. This flag turns that1223 * checking and enforcement off.1224 *1225 * It is mostly used for testing when we want to validate the1226 * context and memory access aspects of the verifier, but because1227 * of an unaligned access the alignment check would trigger before1228 * the one we are interested in.1229 */1230#define BPF_F_ANY_ALIGNMENT (1U << 1)1231 1232/* BPF_F_TEST_RND_HI32 is used in BPF_PROG_LOAD command for testing purpose.1233 * Verifier does sub-register def/use analysis and identifies instructions whose1234 * def only matters for low 32-bit, high 32-bit is never referenced later1235 * through implicit zero extension. Therefore verifier notifies JIT back-ends1236 * that it is safe to ignore clearing high 32-bit for these instructions. This1237 * saves some back-ends a lot of code-gen. However such optimization is not1238 * necessary on some arches, for example x86_64, arm64 etc, whose JIT back-ends1239 * hence hasn't used verifier's analysis result. But, we really want to have a1240 * way to be able to verify the correctness of the described optimization on1241 * x86_64 on which testsuites are frequently exercised.1242 *1243 * So, this flag is introduced. Once it is set, verifier will randomize high1244 * 32-bit for those instructions who has been identified as safe to ignore them.1245 * Then, if verifier is not doing correct analysis, such randomization will1246 * regress tests to expose bugs.1247 */1248#define BPF_F_TEST_RND_HI32 (1U << 2)1249 1250/* The verifier internal test flag. Behavior is undefined */1251#define BPF_F_TEST_STATE_FREQ (1U << 3)1252 1253/* If BPF_F_SLEEPABLE is used in BPF_PROG_LOAD command, the verifier will1254 * restrict map and helper usage for such programs. Sleepable BPF programs can1255 * only be attached to hooks where kernel execution context allows sleeping.1256 * Such programs are allowed to use helpers that may sleep like1257 * bpf_copy_from_user().1258 */1259#define BPF_F_SLEEPABLE (1U << 4)1260 1261/* If BPF_F_XDP_HAS_FRAGS is used in BPF_PROG_LOAD command, the loaded program1262 * fully support xdp frags.1263 */1264#define BPF_F_XDP_HAS_FRAGS (1U << 5)1265 1266/* If BPF_F_XDP_DEV_BOUND_ONLY is used in BPF_PROG_LOAD command, the loaded1267 * program becomes device-bound but can access XDP metadata.1268 */1269#define BPF_F_XDP_DEV_BOUND_ONLY (1U << 6)1270 1271/* The verifier internal test flag. Behavior is undefined */1272#define BPF_F_TEST_REG_INVARIANTS (1U << 7)1273 1274/* link_create.kprobe_multi.flags used in LINK_CREATE command for1275 * BPF_TRACE_KPROBE_MULTI attach type to create return probe.1276 */1277enum {1278 BPF_F_KPROBE_MULTI_RETURN = (1U << 0)1279};1280 1281/* link_create.uprobe_multi.flags used in LINK_CREATE command for1282 * BPF_TRACE_UPROBE_MULTI attach type to create return probe.1283 */1284enum {1285 BPF_F_UPROBE_MULTI_RETURN = (1U << 0)1286};1287 1288/* link_create.netfilter.flags used in LINK_CREATE command for1289 * BPF_PROG_TYPE_NETFILTER to enable IP packet defragmentation.1290 */1291#define BPF_F_NETFILTER_IP_DEFRAG (1U << 0)1292 1293/* When BPF ldimm64's insn[0].src_reg != 0 then this can have1294 * the following extensions:1295 *1296 * insn[0].src_reg: BPF_PSEUDO_MAP_[FD|IDX]1297 * insn[0].imm: map fd or fd_idx1298 * insn[1].imm: 01299 * insn[0].off: 01300 * insn[1].off: 01301 * ldimm64 rewrite: address of map1302 * verifier type: CONST_PTR_TO_MAP1303 */1304#define BPF_PSEUDO_MAP_FD 11305#define BPF_PSEUDO_MAP_IDX 51306 1307/* insn[0].src_reg: BPF_PSEUDO_MAP_[IDX_]VALUE1308 * insn[0].imm: map fd or fd_idx1309 * insn[1].imm: offset into value1310 * insn[0].off: 01311 * insn[1].off: 01312 * ldimm64 rewrite: address of map[0]+offset1313 * verifier type: PTR_TO_MAP_VALUE1314 */1315#define BPF_PSEUDO_MAP_VALUE 21316#define BPF_PSEUDO_MAP_IDX_VALUE 61317 1318/* insn[0].src_reg: BPF_PSEUDO_BTF_ID1319 * insn[0].imm: kernel btd id of VAR1320 * insn[1].imm: 01321 * insn[0].off: 01322 * insn[1].off: 01323 * ldimm64 rewrite: address of the kernel variable1324 * verifier type: PTR_TO_BTF_ID or PTR_TO_MEM, depending on whether the var1325 * is struct/union.1326 */1327#define BPF_PSEUDO_BTF_ID 31328/* insn[0].src_reg: BPF_PSEUDO_FUNC1329 * insn[0].imm: insn offset to the func1330 * insn[1].imm: 01331 * insn[0].off: 01332 * insn[1].off: 01333 * ldimm64 rewrite: address of the function1334 * verifier type: PTR_TO_FUNC.1335 */1336#define BPF_PSEUDO_FUNC 41337 1338/* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative1339 * offset to another bpf function1340 */1341#define BPF_PSEUDO_CALL 11342/* when bpf_call->src_reg == BPF_PSEUDO_KFUNC_CALL,1343 * bpf_call->imm == btf_id of a BTF_KIND_FUNC in the running kernel1344 */1345#define BPF_PSEUDO_KFUNC_CALL 21346 1347enum bpf_addr_space_cast {1348 BPF_ADDR_SPACE_CAST = 1,1349};1350 1351/* flags for BPF_MAP_UPDATE_ELEM command */1352enum {1353 BPF_ANY = 0, /* create new element or update existing */1354 BPF_NOEXIST = 1, /* create new element if it didn't exist */1355 BPF_EXIST = 2, /* update existing element */1356 BPF_F_LOCK = 4, /* spin_lock-ed map_lookup/map_update */1357};1358 1359/* flags for BPF_MAP_CREATE command */1360enum {1361 BPF_F_NO_PREALLOC = (1U << 0),1362/* Instead of having one common LRU list in the1363 * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list1364 * which can scale and perform better.1365 * Note, the LRU nodes (including free nodes) cannot be moved1366 * across different LRU lists.1367 */1368 BPF_F_NO_COMMON_LRU = (1U << 1),1369/* Specify numa node during map creation */1370 BPF_F_NUMA_NODE = (1U << 2),1371 1372/* Flags for accessing BPF object from syscall side. */1373 BPF_F_RDONLY = (1U << 3),1374 BPF_F_WRONLY = (1U << 4),1375 1376/* Flag for stack_map, store build_id+offset instead of pointer */1377 BPF_F_STACK_BUILD_ID = (1U << 5),1378 1379/* Zero-initialize hash function seed. This should only be used for testing. */1380 BPF_F_ZERO_SEED = (1U << 6),1381 1382/* Flags for accessing BPF object from program side. */1383 BPF_F_RDONLY_PROG = (1U << 7),1384 BPF_F_WRONLY_PROG = (1U << 8),1385 1386/* Clone map from listener for newly accepted socket */1387 BPF_F_CLONE = (1U << 9),1388 1389/* Enable memory-mapping BPF map */1390 BPF_F_MMAPABLE = (1U << 10),1391 1392/* Share perf_event among processes */1393 BPF_F_PRESERVE_ELEMS = (1U << 11),1394 1395/* Create a map that is suitable to be an inner map with dynamic max entries */1396 BPF_F_INNER_MAP = (1U << 12),1397 1398/* Create a map that will be registered/unregesitered by the backed bpf_link */1399 BPF_F_LINK = (1U << 13),1400 1401/* Get path from provided FD in BPF_OBJ_PIN/BPF_OBJ_GET commands */1402 BPF_F_PATH_FD = (1U << 14),1403 1404/* Flag for value_type_btf_obj_fd, the fd is available */1405 BPF_F_VTYPE_BTF_OBJ_FD = (1U << 15),1406 1407/* BPF token FD is passed in a corresponding command's token_fd field */1408 BPF_F_TOKEN_FD = (1U << 16),1409 1410/* When user space page faults in bpf_arena send SIGSEGV instead of inserting new page */1411 BPF_F_SEGV_ON_FAULT = (1U << 17),1412 1413/* Do not translate kernel bpf_arena pointers to user pointers */1414 BPF_F_NO_USER_CONV = (1U << 18),1415};1416 1417/* Flags for BPF_PROG_QUERY. */1418 1419/* Query effective (directly attached + inherited from ancestor cgroups)1420 * programs that will be executed for events within a cgroup.1421 * attach_flags with this flag are always returned 0.1422 */1423#define BPF_F_QUERY_EFFECTIVE (1U << 0)1424 1425/* Flags for BPF_PROG_TEST_RUN */1426 1427/* If set, run the test on the cpu specified by bpf_attr.test.cpu */1428#define BPF_F_TEST_RUN_ON_CPU (1U << 0)1429/* If set, XDP frames will be transmitted after processing */1430#define BPF_F_TEST_XDP_LIVE_FRAMES (1U << 1)1431/* If set, apply CHECKSUM_COMPLETE to skb and validate the checksum */1432#define BPF_F_TEST_SKB_CHECKSUM_COMPLETE (1U << 2)1433 1434/* type for BPF_ENABLE_STATS */1435enum bpf_stats_type {1436 /* enabled run_time_ns and run_cnt */1437 BPF_STATS_RUN_TIME = 0,1438};1439 1440enum bpf_stack_build_id_status {1441 /* user space need an empty entry to identify end of a trace */1442 BPF_STACK_BUILD_ID_EMPTY = 0,1443 /* with valid build_id and offset */1444 BPF_STACK_BUILD_ID_VALID = 1,1445 /* couldn't get build_id, fallback to ip */1446 BPF_STACK_BUILD_ID_IP = 2,1447};1448 1449#define BPF_BUILD_ID_SIZE 201450struct bpf_stack_build_id {1451 __s32 status;1452 unsigned char build_id[BPF_BUILD_ID_SIZE];1453 union {1454 __u64 offset;1455 __u64 ip;1456 };1457};1458 1459#define BPF_OBJ_NAME_LEN 16U1460 1461union bpf_attr {1462 struct { /* anonymous struct used by BPF_MAP_CREATE command */1463 __u32 map_type; /* one of enum bpf_map_type */1464 __u32 key_size; /* size of key in bytes */1465 __u32 value_size; /* size of value in bytes */1466 __u32 max_entries; /* max number of entries in a map */1467 __u32 map_flags; /* BPF_MAP_CREATE related1468 * flags defined above.1469 */1470 __u32 inner_map_fd; /* fd pointing to the inner map */1471 __u32 numa_node; /* numa node (effective only if1472 * BPF_F_NUMA_NODE is set).1473 */1474 char map_name[BPF_OBJ_NAME_LEN];1475 __u32 map_ifindex; /* ifindex of netdev to create on */1476 __u32 btf_fd; /* fd pointing to a BTF type data */1477 __u32 btf_key_type_id; /* BTF type_id of the key */1478 __u32 btf_value_type_id; /* BTF type_id of the value */1479 __u32 btf_vmlinux_value_type_id;/* BTF type_id of a kernel-1480 * struct stored as the1481 * map value1482 */1483 /* Any per-map-type extra fields1484 *1485 * BPF_MAP_TYPE_BLOOM_FILTER - the lowest 4 bits indicate the1486 * number of hash functions (if 0, the bloom filter will default1487 * to using 5 hash functions).1488 *1489 * BPF_MAP_TYPE_ARENA - contains the address where user space1490 * is going to mmap() the arena. It has to be page aligned.1491 */1492 __u64 map_extra;1493 1494 __s32 value_type_btf_obj_fd; /* fd pointing to a BTF1495 * type data for1496 * btf_vmlinux_value_type_id.1497 */1498 /* BPF token FD to use with BPF_MAP_CREATE operation.1499 * If provided, map_flags should have BPF_F_TOKEN_FD flag set.1500 */1501 __s32 map_token_fd;1502 };1503 1504 struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */1505 __u32 map_fd;1506 __aligned_u64 key;1507 union {1508 __aligned_u64 value;1509 __aligned_u64 next_key;1510 };1511 __u64 flags;1512 };1513 1514 struct { /* struct used by BPF_MAP_*_BATCH commands */1515 __aligned_u64 in_batch; /* start batch,1516 * NULL to start from beginning1517 */1518 __aligned_u64 out_batch; /* output: next start batch */1519 __aligned_u64 keys;1520 __aligned_u64 values;1521 __u32 count; /* input/output:1522 * input: # of key/value1523 * elements1524 * output: # of filled elements1525 */1526 __u32 map_fd;1527 __u64 elem_flags;1528 __u64 flags;1529 } batch;1530 1531 struct { /* anonymous struct used by BPF_PROG_LOAD command */1532 __u32 prog_type; /* one of enum bpf_prog_type */1533 __u32 insn_cnt;1534 __aligned_u64 insns;1535 __aligned_u64 license;1536 __u32 log_level; /* verbosity level of verifier */1537 __u32 log_size; /* size of user buffer */1538 __aligned_u64 log_buf; /* user supplied buffer */1539 __u32 kern_version; /* not used */1540 __u32 prog_flags;1541 char prog_name[BPF_OBJ_NAME_LEN];1542 __u32 prog_ifindex; /* ifindex of netdev to prep for */1543 /* For some prog types expected attach type must be known at1544 * load time to verify attach type specific parts of prog1545 * (context accesses, allowed helpers, etc).1546 */1547 __u32 expected_attach_type;1548 __u32 prog_btf_fd; /* fd pointing to BTF type data */1549 __u32 func_info_rec_size; /* userspace bpf_func_info size */1550 __aligned_u64 func_info; /* func info */1551 __u32 func_info_cnt; /* number of bpf_func_info records */1552 __u32 line_info_rec_size; /* userspace bpf_line_info size */1553 __aligned_u64 line_info; /* line info */1554 __u32 line_info_cnt; /* number of bpf_line_info records */1555 __u32 attach_btf_id; /* in-kernel BTF type id to attach to */1556 union {1557 /* valid prog_fd to attach to bpf prog */1558 __u32 attach_prog_fd;1559 /* or valid module BTF object fd or 0 to attach to vmlinux */1560 __u32 attach_btf_obj_fd;1561 };1562 __u32 core_relo_cnt; /* number of bpf_core_relo */1563 __aligned_u64 fd_array; /* array of FDs */1564 __aligned_u64 core_relos;1565 __u32 core_relo_rec_size; /* sizeof(struct bpf_core_relo) */1566 /* output: actual total log contents size (including termintaing zero).1567 * It could be both larger than original log_size (if log was1568 * truncated), or smaller (if log buffer wasn't filled completely).1569 */1570 __u32 log_true_size;1571 /* BPF token FD to use with BPF_PROG_LOAD operation.1572 * If provided, prog_flags should have BPF_F_TOKEN_FD flag set.1573 */1574 __s32 prog_token_fd;1575 };1576 1577 struct { /* anonymous struct used by BPF_OBJ_* commands */1578 __aligned_u64 pathname;1579 __u32 bpf_fd;1580 __u32 file_flags;1581 /* Same as dirfd in openat() syscall; see openat(2)1582 * manpage for details of path FD and pathname semantics;1583 * path_fd should accompanied by BPF_F_PATH_FD flag set in1584 * file_flags field, otherwise it should be set to zero;1585 * if BPF_F_PATH_FD flag is not set, AT_FDCWD is assumed.1586 */1587 __s32 path_fd;1588 };1589 1590 struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */1591 union {1592 __u32 target_fd; /* target object to attach to or ... */1593 __u32 target_ifindex; /* target ifindex */1594 };1595 __u32 attach_bpf_fd;1596 __u32 attach_type;1597 __u32 attach_flags;1598 __u32 replace_bpf_fd;1599 union {1600 __u32 relative_fd;1601 __u32 relative_id;1602 };1603 __u64 expected_revision;1604 };1605 1606 struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */1607 __u32 prog_fd;1608 __u32 retval;1609 __u32 data_size_in; /* input: len of data_in */1610 __u32 data_size_out; /* input/output: len of data_out1611 * returns ENOSPC if data_out1612 * is too small.1613 */1614 __aligned_u64 data_in;1615 __aligned_u64 data_out;1616 __u32 repeat;1617 __u32 duration;1618 __u32 ctx_size_in; /* input: len of ctx_in */1619 __u32 ctx_size_out; /* input/output: len of ctx_out1620 * returns ENOSPC if ctx_out1621 * is too small.1622 */1623 __aligned_u64 ctx_in;1624 __aligned_u64 ctx_out;1625 __u32 flags;1626 __u32 cpu;1627 __u32 batch_size;1628 } test;1629 1630 struct { /* anonymous struct used by BPF_*_GET_*_ID */1631 union {1632 __u32 start_id;1633 __u32 prog_id;1634 __u32 map_id;1635 __u32 btf_id;1636 __u32 link_id;1637 };1638 __u32 next_id;1639 __u32 open_flags;1640 };1641 1642 struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */1643 __u32 bpf_fd;1644 __u32 info_len;1645 __aligned_u64 info;1646 } info;1647 1648 struct { /* anonymous struct used by BPF_PROG_QUERY command */1649 union {1650 __u32 target_fd; /* target object to query or ... */1651 __u32 target_ifindex; /* target ifindex */1652 };1653 __u32 attach_type;1654 __u32 query_flags;1655 __u32 attach_flags;1656 __aligned_u64 prog_ids;1657 union {1658 __u32 prog_cnt;1659 __u32 count;1660 };1661 __u32 :32;1662 /* output: per-program attach_flags.1663 * not allowed to be set during effective query.1664 */1665 __aligned_u64 prog_attach_flags;1666 __aligned_u64 link_ids;1667 __aligned_u64 link_attach_flags;1668 __u64 revision;1669 } query;1670 1671 struct { /* anonymous struct used by BPF_RAW_TRACEPOINT_OPEN command */1672 __u64 name;1673 __u32 prog_fd;1674 __u32 :32;1675 __aligned_u64 cookie;1676 } raw_tracepoint;1677 1678 struct { /* anonymous struct for BPF_BTF_LOAD */1679 __aligned_u64 btf;1680 __aligned_u64 btf_log_buf;1681 __u32 btf_size;1682 __u32 btf_log_size;1683 __u32 btf_log_level;1684 /* output: actual total log contents size (including termintaing zero).1685 * It could be both larger than original log_size (if log was1686 * truncated), or smaller (if log buffer wasn't filled completely).1687 */1688 __u32 btf_log_true_size;1689 __u32 btf_flags;1690 /* BPF token FD to use with BPF_BTF_LOAD operation.1691 * If provided, btf_flags should have BPF_F_TOKEN_FD flag set.1692 */1693 __s32 btf_token_fd;1694 };1695 1696 struct {1697 __u32 pid; /* input: pid */1698 __u32 fd; /* input: fd */1699 __u32 flags; /* input: flags */1700 __u32 buf_len; /* input/output: buf len */1701 __aligned_u64 buf; /* input/output:1702 * tp_name for tracepoint1703 * symbol for kprobe1704 * filename for uprobe1705 */1706 __u32 prog_id; /* output: prod_id */1707 __u32 fd_type; /* output: BPF_FD_TYPE_* */1708 __u64 probe_offset; /* output: probe_offset */1709 __u64 probe_addr; /* output: probe_addr */1710 } task_fd_query;1711 1712 struct { /* struct used by BPF_LINK_CREATE command */1713 union {1714 __u32 prog_fd; /* eBPF program to attach */1715 __u32 map_fd; /* struct_ops to attach */1716 };1717 union {1718 __u32 target_fd; /* target object to attach to or ... */1719 __u32 target_ifindex; /* target ifindex */1720 };1721 __u32 attach_type; /* attach type */1722 __u32 flags; /* extra flags */1723 union {1724 __u32 target_btf_id; /* btf_id of target to attach to */1725 struct {1726 __aligned_u64 iter_info; /* extra bpf_iter_link_info */1727 __u32 iter_info_len; /* iter_info length */1728 };1729 struct {1730 /* black box user-provided value passed through1731 * to BPF program at the execution time and1732 * accessible through bpf_get_attach_cookie() BPF helper1733 */1734 __u64 bpf_cookie;1735 } perf_event;1736 struct {1737 __u32 flags;1738 __u32 cnt;1739 __aligned_u64 syms;1740 __aligned_u64 addrs;1741 __aligned_u64 cookies;1742 } kprobe_multi;1743 struct {1744 /* this is overlaid with the target_btf_id above. */1745 __u32 target_btf_id;1746 /* black box user-provided value passed through1747 * to BPF program at the execution time and1748 * accessible through bpf_get_attach_cookie() BPF helper1749 */1750 __u64 cookie;1751 } tracing;1752 struct {1753 __u32 pf;1754 __u32 hooknum;1755 __s32 priority;1756 __u32 flags;1757 } netfilter;1758 struct {1759 union {1760 __u32 relative_fd;1761 __u32 relative_id;1762 };1763 __u64 expected_revision;1764 } tcx;1765 struct {1766 __aligned_u64 path;1767 __aligned_u64 offsets;1768 __aligned_u64 ref_ctr_offsets;1769 __aligned_u64 cookies;1770 __u32 cnt;1771 __u32 flags;1772 __u32 pid;1773 } uprobe_multi;1774 struct {1775 union {1776 __u32 relative_fd;1777 __u32 relative_id;1778 };1779 __u64 expected_revision;1780 } netkit;1781 };1782 } link_create;1783 1784 struct { /* struct used by BPF_LINK_UPDATE command */1785 __u32 link_fd; /* link fd */1786 union {1787 /* new program fd to update link with */1788 __u32 new_prog_fd;1789 /* new struct_ops map fd to update link with */1790 __u32 new_map_fd;1791 };1792 __u32 flags; /* extra flags */1793 union {1794 /* expected link's program fd; is specified only if1795 * BPF_F_REPLACE flag is set in flags.1796 */1797 __u32 old_prog_fd;1798 /* expected link's map fd; is specified only1799 * if BPF_F_REPLACE flag is set.1800 */1801 __u32 old_map_fd;1802 };1803 } link_update;1804 1805 struct {1806 __u32 link_fd;1807 } link_detach;1808 1809 struct { /* struct used by BPF_ENABLE_STATS command */1810 __u32 type;1811 } enable_stats;1812 1813 struct { /* struct used by BPF_ITER_CREATE command */1814 __u32 link_fd;1815 __u32 flags;1816 } iter_create;1817 1818 struct { /* struct used by BPF_PROG_BIND_MAP command */1819 __u32 prog_fd;1820 __u32 map_fd;1821 __u32 flags; /* extra flags */1822 } prog_bind_map;1823 1824 struct { /* struct used by BPF_TOKEN_CREATE command */1825 __u32 flags;1826 __u32 bpffs_fd;1827 } token_create;1828 1829} __attribute__((aligned(8)));1830 1831/* The description below is an attempt at providing documentation to eBPF1832 * developers about the multiple available eBPF helper functions. It can be1833 * parsed and used to produce a manual page. The workflow is the following,1834 * and requires the rst2man utility:1835 *1836 * $ ./scripts/bpf_doc.py \1837 * --filename include/uapi/linux/bpf.h > /tmp/bpf-helpers.rst1838 * $ rst2man /tmp/bpf-helpers.rst > /tmp/bpf-helpers.71839 * $ man /tmp/bpf-helpers.71840 *1841 * Note that in order to produce this external documentation, some RST1842 * formatting is used in the descriptions to get "bold" and "italics" in1843 * manual pages. Also note that the few trailing white spaces are1844 * intentional, removing them would break paragraphs for rst2man.1845 *1846 * Start of BPF helper function descriptions:1847 *1848 * void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)1849 * Description1850 * Perform a lookup in *map* for an entry associated to *key*.1851 * Return1852 * Map value associated to *key*, or **NULL** if no entry was1853 * found.1854 *1855 * long bpf_map_update_elem(struct bpf_map *map, const void *key, const void *value, u64 flags)1856 * Description1857 * Add or update the value of the entry associated to *key* in1858 * *map* with *value*. *flags* is one of:1859 *1860 * **BPF_NOEXIST**1861 * The entry for *key* must not exist in the map.1862 * **BPF_EXIST**1863 * The entry for *key* must already exist in the map.1864 * **BPF_ANY**1865 * No condition on the existence of the entry for *key*.1866 *1867 * Flag value **BPF_NOEXIST** cannot be used for maps of types1868 * **BPF_MAP_TYPE_ARRAY** or **BPF_MAP_TYPE_PERCPU_ARRAY** (all1869 * elements always exist), the helper would return an error.1870 * Return1871 * 0 on success, or a negative error in case of failure.1872 *1873 * long bpf_map_delete_elem(struct bpf_map *map, const void *key)1874 * Description1875 * Delete entry with *key* from *map*.1876 * Return1877 * 0 on success, or a negative error in case of failure.1878 *1879 * long bpf_probe_read(void *dst, u32 size, const void *unsafe_ptr)1880 * Description1881 * For tracing programs, safely attempt to read *size* bytes from1882 * kernel space address *unsafe_ptr* and store the data in *dst*.1883 *1884 * Generally, use **bpf_probe_read_user**\ () or1885 * **bpf_probe_read_kernel**\ () instead.1886 * Return1887 * 0 on success, or a negative error in case of failure.1888 *1889 * u64 bpf_ktime_get_ns(void)1890 * Description1891 * Return the time elapsed since system boot, in nanoseconds.1892 * Does not include time the system was suspended.1893 * See: **clock_gettime**\ (**CLOCK_MONOTONIC**)1894 * Return1895 * Current *ktime*.1896 *1897 * long bpf_trace_printk(const char *fmt, u32 fmt_size, ...)1898 * Description1899 * This helper is a "printk()-like" facility for debugging. It1900 * prints a message defined by format *fmt* (of size *fmt_size*)1901 * to file *\/sys/kernel/tracing/trace* from TraceFS, if1902 * available. It can take up to three additional **u64**1903 * arguments (as an eBPF helpers, the total number of arguments is1904 * limited to five).1905 *1906 * Each time the helper is called, it appends a line to the trace.1907 * Lines are discarded while *\/sys/kernel/tracing/trace* is1908 * open, use *\/sys/kernel/tracing/trace_pipe* to avoid this.1909 * The format of the trace is customizable, and the exact output1910 * one will get depends on the options set in1911 * *\/sys/kernel/tracing/trace_options* (see also the1912 * *README* file under the same directory). However, it usually1913 * defaults to something like:1914 *1915 * ::1916 *1917 * telnet-470 [001] .N.. 419421.045894: 0x00000001: <formatted msg>1918 *1919 * In the above:1920 *1921 * * ``telnet`` is the name of the current task.1922 * * ``470`` is the PID of the current task.1923 * * ``001`` is the CPU number on which the task is1924 * running.1925 * * In ``.N..``, each character refers to a set of1926 * options (whether irqs are enabled, scheduling1927 * options, whether hard/softirqs are running, level of1928 * preempt_disabled respectively). **N** means that1929 * **TIF_NEED_RESCHED** and **PREEMPT_NEED_RESCHED**1930 * are set.1931 * * ``419421.045894`` is a timestamp.1932 * * ``0x00000001`` is a fake value used by BPF for the1933 * instruction pointer register.1934 * * ``<formatted msg>`` is the message formatted with1935 * *fmt*.1936 *1937 * The conversion specifiers supported by *fmt* are similar, but1938 * more limited than for printk(). They are **%d**, **%i**,1939 * **%u**, **%x**, **%ld**, **%li**, **%lu**, **%lx**, **%lld**,1940 * **%lli**, **%llu**, **%llx**, **%p**, **%s**. No modifier (size1941 * of field, padding with zeroes, etc.) is available, and the1942 * helper will return **-EINVAL** (but print nothing) if it1943 * encounters an unknown specifier.1944 *1945 * Also, note that **bpf_trace_printk**\ () is slow, and should1946 * only be used for debugging purposes. For this reason, a notice1947 * block (spanning several lines) is printed to kernel logs and1948 * states that the helper should not be used "for production use"1949 * the first time this helper is used (or more precisely, when1950 * **trace_printk**\ () buffers are allocated). For passing values1951 * to user space, perf events should be preferred.1952 * Return1953 * The number of bytes written to the buffer, or a negative error1954 * in case of failure.1955 *1956 * u32 bpf_get_prandom_u32(void)1957 * Description1958 * Get a pseudo-random number.1959 *1960 * From a security point of view, this helper uses its own1961 * pseudo-random internal state, and cannot be used to infer the1962 * seed of other random functions in the kernel. However, it is1963 * essential to note that the generator used by the helper is not1964 * cryptographically secure.1965 * Return1966 * A random 32-bit unsigned value.1967 *1968 * u32 bpf_get_smp_processor_id(void)1969 * Description1970 * Get the SMP (symmetric multiprocessing) processor id. Note that1971 * all programs run with migration disabled, which means that the1972 * SMP processor id is stable during all the execution of the1973 * program.1974 * Return1975 * The SMP id of the processor running the program.1976 *1977 * long bpf_skb_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len, u64 flags)1978 * Description1979 * Store *len* bytes from address *from* into the packet1980 * associated to *skb*, at *offset*. *flags* are a combination of1981 * **BPF_F_RECOMPUTE_CSUM** (automatically recompute the1982 * checksum for the packet after storing the bytes) and1983 * **BPF_F_INVALIDATE_HASH** (set *skb*\ **->hash**, *skb*\1984 * **->swhash** and *skb*\ **->l4hash** to 0).1985 *1986 * A call to this helper is susceptible to change the underlying1987 * packet buffer. Therefore, at load time, all checks on pointers1988 * previously done by the verifier are invalidated and must be1989 * performed again, if the helper is used in combination with1990 * direct packet access.1991 * Return1992 * 0 on success, or a negative error in case of failure.1993 *1994 * long bpf_l3_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 size)1995 * Description1996 * Recompute the layer 3 (e.g. IP) checksum for the packet1997 * associated to *skb*. Computation is incremental, so the helper1998 * must know the former value of the header field that was1999 * modified (*from*), the new value of this field (*to*), and the2000 * number of bytes (2 or 4) for this field, stored in *size*.2001 * Alternatively, it is possible to store the difference between2002 * the previous and the new values of the header field in *to*, by2003 * setting *from* and *size* to 0. For both methods, *offset*2004 * indicates the location of the IP checksum within the packet.2005 *2006 * This helper works in combination with **bpf_csum_diff**\ (),2007 * which does not update the checksum in-place, but offers more2008 * flexibility and can handle sizes larger than 2 or 4 for the2009 * checksum to update.2010 *2011 * A call to this helper is susceptible to change the underlying2012 * packet buffer. Therefore, at load time, all checks on pointers2013 * previously done by the verifier are invalidated and must be2014 * performed again, if the helper is used in combination with2015 * direct packet access.2016 * Return2017 * 0 on success, or a negative error in case of failure.2018 *2019 * long bpf_l4_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 flags)2020 * Description2021 * Recompute the layer 4 (e.g. TCP, UDP or ICMP) checksum for the2022 * packet associated to *skb*. Computation is incremental, so the2023 * helper must know the former value of the header field that was2024 * modified (*from*), the new value of this field (*to*), and the2025 * number of bytes (2 or 4) for this field, stored on the lowest2026 * four bits of *flags*. Alternatively, it is possible to store2027 * the difference between the previous and the new values of the2028 * header field in *to*, by setting *from* and the four lowest2029 * bits of *flags* to 0. For both methods, *offset* indicates the2030 * location of the IP checksum within the packet. In addition to2031 * the size of the field, *flags* can be added (bitwise OR) actual2032 * flags. With **BPF_F_MARK_MANGLED_0**, a null checksum is left2033 * untouched (unless **BPF_F_MARK_ENFORCE** is added as well), and2034 * for updates resulting in a null checksum the value is set to2035 * **CSUM_MANGLED_0** instead. Flag **BPF_F_PSEUDO_HDR** indicates2036 * the checksum is to be computed against a pseudo-header.2037 *2038 * This helper works in combination with **bpf_csum_diff**\ (),2039 * which does not update the checksum in-place, but offers more2040 * flexibility and can handle sizes larger than 2 or 4 for the2041 * checksum to update.2042 *2043 * A call to this helper is susceptible to change the underlying2044 * packet buffer. Therefore, at load time, all checks on pointers2045 * previously done by the verifier are invalidated and must be2046 * performed again, if the helper is used in combination with2047 * direct packet access.2048 * Return2049 * 0 on success, or a negative error in case of failure.2050 *2051 * long bpf_tail_call(void *ctx, struct bpf_map *prog_array_map, u32 index)2052 * Description2053 * This special helper is used to trigger a "tail call", or in2054 * other words, to jump into another eBPF program. The same stack2055 * frame is used (but values on stack and in registers for the2056 * caller are not accessible to the callee). This mechanism allows2057 * for program chaining, either for raising the maximum number of2058 * available eBPF instructions, or to execute given programs in2059 * conditional blocks. For security reasons, there is an upper2060 * limit to the number of successive tail calls that can be2061 * performed.2062 *2063 * Upon call of this helper, the program attempts to jump into a2064 * program referenced at index *index* in *prog_array_map*, a2065 * special map of type **BPF_MAP_TYPE_PROG_ARRAY**, and passes2066 * *ctx*, a pointer to the context.2067 *2068 * If the call succeeds, the kernel immediately runs the first2069 * instruction of the new program. This is not a function call,2070 * and it never returns to the previous program. If the call2071 * fails, then the helper has no effect, and the caller continues2072 * to run its subsequent instructions. A call can fail if the2073 * destination program for the jump does not exist (i.e. *index*2074 * is superior to the number of entries in *prog_array_map*), or2075 * if the maximum number of tail calls has been reached for this2076 * chain of programs. This limit is defined in the kernel by the2077 * macro **MAX_TAIL_CALL_CNT** (not accessible to user space),2078 * which is currently set to 33.2079 * Return2080 * 0 on success, or a negative error in case of failure.2081 *2082 * long bpf_clone_redirect(struct sk_buff *skb, u32 ifindex, u64 flags)2083 * Description2084 * Clone and redirect the packet associated to *skb* to another2085 * net device of index *ifindex*. Both ingress and egress2086 * interfaces can be used for redirection. The **BPF_F_INGRESS**2087 * value in *flags* is used to make the distinction (ingress path2088 * is selected if the flag is present, egress path otherwise).2089 * This is the only flag supported for now.2090 *2091 * In comparison with **bpf_redirect**\ () helper,2092 * **bpf_clone_redirect**\ () has the associated cost of2093 * duplicating the packet buffer, but this can be executed out of2094 * the eBPF program. Conversely, **bpf_redirect**\ () is more2095 * efficient, but it is handled through an action code where the2096 * redirection happens only after the eBPF program has returned.2097 *2098 * A call to this helper is susceptible to change the underlying2099 * packet buffer. Therefore, at load time, all checks on pointers2100 * previously done by the verifier are invalidated and must be2101 * performed again, if the helper is used in combination with2102 * direct packet access.2103 * Return2104 * 0 on success, or a negative error in case of failure. Positive2105 * error indicates a potential drop or congestion in the target2106 * device. The particular positive error codes are not defined.2107 *2108 * u64 bpf_get_current_pid_tgid(void)2109 * Description2110 * Get the current pid and tgid.2111 * Return2112 * A 64-bit integer containing the current tgid and pid, and2113 * created as such:2114 * *current_task*\ **->tgid << 32 \|**2115 * *current_task*\ **->pid**.2116 *2117 * u64 bpf_get_current_uid_gid(void)2118 * Description2119 * Get the current uid and gid.2120 * Return2121 * A 64-bit integer containing the current GID and UID, and2122 * created as such: *current_gid* **<< 32 \|** *current_uid*.2123 *2124 * long bpf_get_current_comm(void *buf, u32 size_of_buf)2125 * Description2126 * Copy the **comm** attribute of the current task into *buf* of2127 * *size_of_buf*. The **comm** attribute contains the name of2128 * the executable (excluding the path) for the current task. The2129 * *size_of_buf* must be strictly positive. On success, the2130 * helper makes sure that the *buf* is NUL-terminated. On failure,2131 * it is filled with zeroes.2132 * Return2133 * 0 on success, or a negative error in case of failure.2134 *2135 * u32 bpf_get_cgroup_classid(struct sk_buff *skb)2136 * Description2137 * Retrieve the classid for the current task, i.e. for the net_cls2138 * cgroup to which *skb* belongs.2139 *2140 * This helper can be used on TC egress path, but not on ingress.2141 *2142 * The net_cls cgroup provides an interface to tag network packets2143 * based on a user-provided identifier for all traffic coming from2144 * the tasks belonging to the related cgroup. See also the related2145 * kernel documentation, available from the Linux sources in file2146 * *Documentation/admin-guide/cgroup-v1/net_cls.rst*.2147 *2148 * The Linux kernel has two versions for cgroups: there are2149 * cgroups v1 and cgroups v2. Both are available to users, who can2150 * use a mixture of them, but note that the net_cls cgroup is for2151 * cgroup v1 only. This makes it incompatible with BPF programs2152 * run on cgroups, which is a cgroup-v2-only feature (a socket can2153 * only hold data for one version of cgroups at a time).2154 *2155 * This helper is only available is the kernel was compiled with2156 * the **CONFIG_CGROUP_NET_CLASSID** configuration option set to2157 * "**y**" or to "**m**".2158 * Return2159 * The classid, or 0 for the default unconfigured classid.2160 *2161 * long bpf_skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)2162 * Description2163 * Push a *vlan_tci* (VLAN tag control information) of protocol2164 * *vlan_proto* to the packet associated to *skb*, then update2165 * the checksum. Note that if *vlan_proto* is different from2166 * **ETH_P_8021Q** and **ETH_P_8021AD**, it is considered to2167 * be **ETH_P_8021Q**.2168 *2169 * A call to this helper is susceptible to change the underlying2170 * packet buffer. Therefore, at load time, all checks on pointers2171 * previously done by the verifier are invalidated and must be2172 * performed again, if the helper is used in combination with2173 * direct packet access.2174 * Return2175 * 0 on success, or a negative error in case of failure.2176 *2177 * long bpf_skb_vlan_pop(struct sk_buff *skb)2178 * Description2179 * Pop a VLAN header from the packet associated to *skb*.2180 *2181 * A call to this helper is susceptible to change the underlying2182 * packet buffer. Therefore, at load time, all checks on pointers2183 * previously done by the verifier are invalidated and must be2184 * performed again, if the helper is used in combination with2185 * direct packet access.2186 * Return2187 * 0 on success, or a negative error in case of failure.2188 *2189 * long bpf_skb_get_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)2190 * Description2191 * Get tunnel metadata. This helper takes a pointer *key* to an2192 * empty **struct bpf_tunnel_key** of **size**, that will be2193 * filled with tunnel metadata for the packet associated to *skb*.2194 * The *flags* can be set to **BPF_F_TUNINFO_IPV6**, which2195 * indicates that the tunnel is based on IPv6 protocol instead of2196 * IPv4.2197 *2198 * The **struct bpf_tunnel_key** is an object that generalizes the2199 * principal parameters used by various tunneling protocols into a2200 * single struct. This way, it can be used to easily make a2201 * decision based on the contents of the encapsulation header,2202 * "summarized" in this struct. In particular, it holds the IP2203 * address of the remote end (IPv4 or IPv6, depending on the case)2204 * in *key*\ **->remote_ipv4** or *key*\ **->remote_ipv6**. Also,2205 * this struct exposes the *key*\ **->tunnel_id**, which is2206 * generally mapped to a VNI (Virtual Network Identifier), making2207 * it programmable together with the **bpf_skb_set_tunnel_key**\2208 * () helper.2209 *2210 * Let's imagine that the following code is part of a program2211 * attached to the TC ingress interface, on one end of a GRE2212 * tunnel, and is supposed to filter out all messages coming from2213 * remote ends with IPv4 address other than 10.0.0.1:2214 *2215 * ::2216 *2217 * int ret;2218 * struct bpf_tunnel_key key = {};2219 *2220 * ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);2221 * if (ret < 0)2222 * return TC_ACT_SHOT; // drop packet2223 *2224 * if (key.remote_ipv4 != 0x0a000001)2225 * return TC_ACT_SHOT; // drop packet2226 *2227 * return TC_ACT_OK; // accept packet2228 *2229 * This interface can also be used with all encapsulation devices2230 * that can operate in "collect metadata" mode: instead of having2231 * one network device per specific configuration, the "collect2232 * metadata" mode only requires a single device where the2233 * configuration can be extracted from this helper.2234 *2235 * This can be used together with various tunnels such as VXLan,2236 * Geneve, GRE or IP in IP (IPIP).2237 * Return2238 * 0 on success, or a negative error in case of failure.2239 *2240 * long bpf_skb_set_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)2241 * Description2242 * Populate tunnel metadata for packet associated to *skb.* The2243 * tunnel metadata is set to the contents of *key*, of *size*. The2244 * *flags* can be set to a combination of the following values:2245 *2246 * **BPF_F_TUNINFO_IPV6**2247 * Indicate that the tunnel is based on IPv6 protocol2248 * instead of IPv4.2249 * **BPF_F_ZERO_CSUM_TX**2250 * For IPv4 packets, add a flag to tunnel metadata2251 * indicating that checksum computation should be skipped2252 * and checksum set to zeroes.2253 * **BPF_F_DONT_FRAGMENT**2254 * Add a flag to tunnel metadata indicating that the2255 * packet should not be fragmented.2256 * **BPF_F_SEQ_NUMBER**2257 * Add a flag to tunnel metadata indicating that a2258 * sequence number should be added to tunnel header before2259 * sending the packet. This flag was added for GRE2260 * encapsulation, but might be used with other protocols2261 * as well in the future.2262 * **BPF_F_NO_TUNNEL_KEY**2263 * Add a flag to tunnel metadata indicating that no tunnel2264 * key should be set in the resulting tunnel header.2265 *2266 * Here is a typical usage on the transmit path:2267 *2268 * ::2269 *2270 * struct bpf_tunnel_key key;2271 * populate key ...2272 * bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0);2273 * bpf_clone_redirect(skb, vxlan_dev_ifindex, 0);2274 *2275 * See also the description of the **bpf_skb_get_tunnel_key**\ ()2276 * helper for additional information.2277 * Return2278 * 0 on success, or a negative error in case of failure.2279 *2280 * u64 bpf_perf_event_read(struct bpf_map *map, u64 flags)2281 * Description2282 * Read the value of a perf event counter. This helper relies on a2283 * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of2284 * the perf event counter is selected when *map* is updated with2285 * perf event file descriptors. The *map* is an array whose size2286 * is the number of available CPUs, and each cell contains a value2287 * relative to one CPU. The value to retrieve is indicated by2288 * *flags*, that contains the index of the CPU to look up, masked2289 * with **BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to2290 * **BPF_F_CURRENT_CPU** to indicate that the value for the2291 * current CPU should be retrieved.2292 *2293 * Note that before Linux 4.13, only hardware perf event can be2294 * retrieved.2295 *2296 * Also, be aware that the newer helper2297 * **bpf_perf_event_read_value**\ () is recommended over2298 * **bpf_perf_event_read**\ () in general. The latter has some ABI2299 * quirks where error and counter value are used as a return code2300 * (which is wrong to do since ranges may overlap). This issue is2301 * fixed with **bpf_perf_event_read_value**\ (), which at the same2302 * time provides more features over the **bpf_perf_event_read**\2303 * () interface. Please refer to the description of2304 * **bpf_perf_event_read_value**\ () for details.2305 * Return2306 * The value of the perf event counter read from the map, or a2307 * negative error code in case of failure.2308 *2309 * long bpf_redirect(u32 ifindex, u64 flags)2310 * Description2311 * Redirect the packet to another net device of index *ifindex*.2312 * This helper is somewhat similar to **bpf_clone_redirect**\2313 * (), except that the packet is not cloned, which provides2314 * increased performance.2315 *2316 * Except for XDP, both ingress and egress interfaces can be used2317 * for redirection. The **BPF_F_INGRESS** value in *flags* is used2318 * to make the distinction (ingress path is selected if the flag2319 * is present, egress path otherwise). Currently, XDP only2320 * supports redirection to the egress interface, and accepts no2321 * flag at all.2322 *2323 * The same effect can also be attained with the more generic2324 * **bpf_redirect_map**\ (), which uses a BPF map to store the2325 * redirect target instead of providing it directly to the helper.2326 * Return2327 * For XDP, the helper returns **XDP_REDIRECT** on success or2328 * **XDP_ABORTED** on error. For other program types, the values2329 * are **TC_ACT_REDIRECT** on success or **TC_ACT_SHOT** on2330 * error.2331 *2332 * u32 bpf_get_route_realm(struct sk_buff *skb)2333 * Description2334 * Retrieve the realm or the route, that is to say the2335 * **tclassid** field of the destination for the *skb*. The2336 * identifier retrieved is a user-provided tag, similar to the2337 * one used with the net_cls cgroup (see description for2338 * **bpf_get_cgroup_classid**\ () helper), but here this tag is2339 * held by a route (a destination entry), not by a task.2340 *2341 * Retrieving this identifier works with the clsact TC egress hook2342 * (see also **tc-bpf(8)**), or alternatively on conventional2343 * classful egress qdiscs, but not on TC ingress path. In case of2344 * clsact TC egress hook, this has the advantage that, internally,2345 * the destination entry has not been dropped yet in the transmit2346 * path. Therefore, the destination entry does not need to be2347 * artificially held via **netif_keep_dst**\ () for a classful2348 * qdisc until the *skb* is freed.2349 *2350 * This helper is available only if the kernel was compiled with2351 * **CONFIG_IP_ROUTE_CLASSID** configuration option.2352 * Return2353 * The realm of the route for the packet associated to *skb*, or 02354 * if none was found.2355 *2356 * long bpf_perf_event_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)2357 * Description2358 * Write raw *data* blob into a special BPF perf event held by2359 * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf2360 * event must have the following attributes: **PERF_SAMPLE_RAW**2361 * as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and2362 * **PERF_COUNT_SW_BPF_OUTPUT** as **config**.2363 *2364 * The *flags* are used to indicate the index in *map* for which2365 * the value must be put, masked with **BPF_F_INDEX_MASK**.2366 * Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**2367 * to indicate that the index of the current CPU core should be2368 * used.2369 *2370 * The value to write, of *size*, is passed through eBPF stack and2371 * pointed by *data*.2372 *2373 * The context of the program *ctx* needs also be passed to the2374 * helper.2375 *2376 * On user space, a program willing to read the values needs to2377 * call **perf_event_open**\ () on the perf event (either for2378 * one or for all CPUs) and to store the file descriptor into the2379 * *map*. This must be done before the eBPF program can send data2380 * into it. An example is available in file2381 * *samples/bpf/trace_output_user.c* in the Linux kernel source2382 * tree (the eBPF program counterpart is in2383 * *samples/bpf/trace_output_kern.c*).2384 *2385 * **bpf_perf_event_output**\ () achieves better performance2386 * than **bpf_trace_printk**\ () for sharing data with user2387 * space, and is much better suitable for streaming data from eBPF2388 * programs.2389 *2390 * Note that this helper is not restricted to tracing use cases2391 * and can be used with programs attached to TC or XDP as well,2392 * where it allows for passing data to user space listeners. Data2393 * can be:2394 *2395 * * Only custom structs,2396 * * Only the packet payload, or2397 * * A combination of both.2398 * Return2399 * 0 on success, or a negative error in case of failure.2400 *2401 * long bpf_skb_load_bytes(const void *skb, u32 offset, void *to, u32 len)2402 * Description2403 * This helper was provided as an easy way to load data from a2404 * packet. It can be used to load *len* bytes from *offset* from2405 * the packet associated to *skb*, into the buffer pointed by2406 * *to*.2407 *2408 * Since Linux 4.7, usage of this helper has mostly been replaced2409 * by "direct packet access", enabling packet data to be2410 * manipulated with *skb*\ **->data** and *skb*\ **->data_end**2411 * pointing respectively to the first byte of packet data and to2412 * the byte after the last byte of packet data. However, it2413 * remains useful if one wishes to read large quantities of data2414 * at once from a packet into the eBPF stack.2415 * Return2416 * 0 on success, or a negative error in case of failure.2417 *2418 * long bpf_get_stackid(void *ctx, struct bpf_map *map, u64 flags)2419 * Description2420 * Walk a user or a kernel stack and return its id. To achieve2421 * this, the helper needs *ctx*, which is a pointer to the context2422 * on which the tracing program is executed, and a pointer to a2423 * *map* of type **BPF_MAP_TYPE_STACK_TRACE**.2424 *2425 * The last argument, *flags*, holds the number of stack frames to2426 * skip (from 0 to 255), masked with2427 * **BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set2428 * a combination of the following flags:2429 *2430 * **BPF_F_USER_STACK**2431 * Collect a user space stack instead of a kernel stack.2432 * **BPF_F_FAST_STACK_CMP**2433 * Compare stacks by hash only.2434 * **BPF_F_REUSE_STACKID**2435 * If two different stacks hash into the same *stackid*,2436 * discard the old one.2437 *2438 * The stack id retrieved is a 32 bit long integer handle which2439 * can be further combined with other data (including other stack2440 * ids) and used as a key into maps. This can be useful for2441 * generating a variety of graphs (such as flame graphs or off-cpu2442 * graphs).2443 *2444 * For walking a stack, this helper is an improvement over2445 * **bpf_probe_read**\ (), which can be used with unrolled loops2446 * but is not efficient and consumes a lot of eBPF instructions.2447 * Instead, **bpf_get_stackid**\ () can collect up to2448 * **PERF_MAX_STACK_DEPTH** both kernel and user frames. Note that2449 * this limit can be controlled with the **sysctl** program, and2450 * that it should be manually increased in order to profile long2451 * user stacks (such as stacks for Java programs). To do so, use:2452 *2453 * ::2454 *2455 * # sysctl kernel.perf_event_max_stack=<new value>2456 * Return2457 * The positive or null stack id on success, or a negative error2458 * in case of failure.2459 *2460 * s64 bpf_csum_diff(__be32 *from, u32 from_size, __be32 *to, u32 to_size, __wsum seed)2461 * Description2462 * Compute a checksum difference, from the raw buffer pointed by2463 * *from*, of length *from_size* (that must be a multiple of 4),2464 * towards the raw buffer pointed by *to*, of size *to_size*2465 * (same remark). An optional *seed* can be added to the value2466 * (this can be cascaded, the seed may come from a previous call2467 * to the helper).2468 *2469 * This is flexible enough to be used in several ways:2470 *2471 * * With *from_size* == 0, *to_size* > 0 and *seed* set to2472 * checksum, it can be used when pushing new data.2473 * * With *from_size* > 0, *to_size* == 0 and *seed* set to2474 * checksum, it can be used when removing data from a packet.2475 * * With *from_size* > 0, *to_size* > 0 and *seed* set to 0, it2476 * can be used to compute a diff. Note that *from_size* and2477 * *to_size* do not need to be equal.2478 *2479 * This helper can be used in combination with2480 * **bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\ (), to2481 * which one can feed in the difference computed with2482 * **bpf_csum_diff**\ ().2483 * Return2484 * The checksum result, or a negative error code in case of2485 * failure.2486 *2487 * long bpf_skb_get_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)2488 * Description2489 * Retrieve tunnel options metadata for the packet associated to2490 * *skb*, and store the raw tunnel option data to the buffer *opt*2491 * of *size*.2492 *2493 * This helper can be used with encapsulation devices that can2494 * operate in "collect metadata" mode (please refer to the related2495 * note in the description of **bpf_skb_get_tunnel_key**\ () for2496 * more details). A particular example where this can be used is2497 * in combination with the Geneve encapsulation protocol, where it2498 * allows for pushing (with **bpf_skb_get_tunnel_opt**\ () helper)2499 * and retrieving arbitrary TLVs (Type-Length-Value headers) from2500 * the eBPF program. This allows for full customization of these2501 * headers.2502 * Return2503 * The size of the option data retrieved.2504 *2505 * long bpf_skb_set_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)2506 * Description2507 * Set tunnel options metadata for the packet associated to *skb*2508 * to the option data contained in the raw buffer *opt* of *size*.2509 *2510 * See also the description of the **bpf_skb_get_tunnel_opt**\ ()2511 * helper for additional information.2512 * Return2513 * 0 on success, or a negative error in case of failure.2514 *2515 * long bpf_skb_change_proto(struct sk_buff *skb, __be16 proto, u64 flags)2516 * Description2517 * Change the protocol of the *skb* to *proto*. Currently2518 * supported are transition from IPv4 to IPv6, and from IPv6 to2519 * IPv4. The helper takes care of the groundwork for the2520 * transition, including resizing the socket buffer. The eBPF2521 * program is expected to fill the new headers, if any, via2522 * **skb_store_bytes**\ () and to recompute the checksums with2523 * **bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\2524 * (). The main case for this helper is to perform NAT642525 * operations out of an eBPF program.2526 *2527 * Internally, the GSO type is marked as dodgy so that headers are2528 * checked and segments are recalculated by the GSO/GRO engine.2529 * The size for GSO target is adapted as well.2530 *2531 * All values for *flags* are reserved for future usage, and must2532 * be left at zero.2533 *2534 * A call to this helper is susceptible to change the underlying2535 * packet buffer. Therefore, at load time, all checks on pointers2536 * previously done by the verifier are invalidated and must be2537 * performed again, if the helper is used in combination with2538 * direct packet access.2539 * Return2540 * 0 on success, or a negative error in case of failure.2541 *2542 * long bpf_skb_change_type(struct sk_buff *skb, u32 type)2543 * Description2544 * Change the packet type for the packet associated to *skb*. This2545 * comes down to setting *skb*\ **->pkt_type** to *type*, except2546 * the eBPF program does not have a write access to *skb*\2547 * **->pkt_type** beside this helper. Using a helper here allows2548 * for graceful handling of errors.2549 *2550 * The major use case is to change incoming *skb*s to2551 * **PACKET_HOST** in a programmatic way instead of having to2552 * recirculate via **redirect**\ (..., **BPF_F_INGRESS**), for2553 * example.2554 *2555 * Note that *type* only allows certain values. At this time, they2556 * are:2557 *2558 * **PACKET_HOST**2559 * Packet is for us.2560 * **PACKET_BROADCAST**2561 * Send packet to all.2562 * **PACKET_MULTICAST**2563 * Send packet to group.2564 * **PACKET_OTHERHOST**2565 * Send packet to someone else.2566 * Return2567 * 0 on success, or a negative error in case of failure.2568 *2569 * long bpf_skb_under_cgroup(struct sk_buff *skb, struct bpf_map *map, u32 index)2570 * Description2571 * Check whether *skb* is a descendant of the cgroup2 held by2572 * *map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.2573 * Return2574 * The return value depends on the result of the test, and can be:2575 *2576 * * 0, if the *skb* failed the cgroup2 descendant test.2577 * * 1, if the *skb* succeeded the cgroup2 descendant test.2578 * * A negative error code, if an error occurred.2579 *2580 * u32 bpf_get_hash_recalc(struct sk_buff *skb)2581 * Description2582 * Retrieve the hash of the packet, *skb*\ **->hash**. If it is2583 * not set, in particular if the hash was cleared due to mangling,2584 * recompute this hash. Later accesses to the hash can be done2585 * directly with *skb*\ **->hash**.2586 *2587 * Calling **bpf_set_hash_invalid**\ (), changing a packet2588 * prototype with **bpf_skb_change_proto**\ (), or calling2589 * **bpf_skb_store_bytes**\ () with the2590 * **BPF_F_INVALIDATE_HASH** are actions susceptible to clear2591 * the hash and to trigger a new computation for the next call to2592 * **bpf_get_hash_recalc**\ ().2593 * Return2594 * The 32-bit hash.2595 *2596 * u64 bpf_get_current_task(void)2597 * Description2598 * Get the current task.2599 * Return2600 * A pointer to the current task struct.2601 *2602 * long bpf_probe_write_user(void *dst, const void *src, u32 len)2603 * Description2604 * Attempt in a safe way to write *len* bytes from the buffer2605 * *src* to *dst* in memory. It only works for threads that are in2606 * user context, and *dst* must be a valid user space address.2607 *2608 * This helper should not be used to implement any kind of2609 * security mechanism because of TOC-TOU attacks, but rather to2610 * debug, divert, and manipulate execution of semi-cooperative2611 * processes.2612 *2613 * Keep in mind that this feature is meant for experiments, and it2614 * has a risk of crashing the system and running programs.2615 * Therefore, when an eBPF program using this helper is attached,2616 * a warning including PID and process name is printed to kernel2617 * logs.2618 * Return2619 * 0 on success, or a negative error in case of failure.2620 *2621 * long bpf_current_task_under_cgroup(struct bpf_map *map, u32 index)2622 * Description2623 * Check whether the probe is being run is the context of a given2624 * subset of the cgroup2 hierarchy. The cgroup2 to test is held by2625 * *map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.2626 * Return2627 * The return value depends on the result of the test, and can be:2628 *2629 * * 1, if current task belongs to the cgroup2.2630 * * 0, if current task does not belong to the cgroup2.2631 * * A negative error code, if an error occurred.2632 *2633 * long bpf_skb_change_tail(struct sk_buff *skb, u32 len, u64 flags)2634 * Description2635 * Resize (trim or grow) the packet associated to *skb* to the2636 * new *len*. The *flags* are reserved for future usage, and must2637 * be left at zero.2638 *2639 * The basic idea is that the helper performs the needed work to2640 * change the size of the packet, then the eBPF program rewrites2641 * the rest via helpers like **bpf_skb_store_bytes**\ (),2642 * **bpf_l3_csum_replace**\ (), **bpf_l3_csum_replace**\ ()2643 * and others. This helper is a slow path utility intended for2644 * replies with control messages. And because it is targeted for2645 * slow path, the helper itself can afford to be slow: it2646 * implicitly linearizes, unclones and drops offloads from the2647 * *skb*.2648 *2649 * A call to this helper is susceptible to change the underlying2650 * packet buffer. Therefore, at load time, all checks on pointers2651 * previously done by the verifier are invalidated and must be2652 * performed again, if the helper is used in combination with2653 * direct packet access.2654 * Return2655 * 0 on success, or a negative error in case of failure.2656 *2657 * long bpf_skb_pull_data(struct sk_buff *skb, u32 len)2658 * Description2659 * Pull in non-linear data in case the *skb* is non-linear and not2660 * all of *len* are part of the linear section. Make *len* bytes2661 * from *skb* readable and writable. If a zero value is passed for2662 * *len*, then all bytes in the linear part of *skb* will be made2663 * readable and writable.2664 *2665 * This helper is only needed for reading and writing with direct2666 * packet access.2667 *2668 * For direct packet access, testing that offsets to access2669 * are within packet boundaries (test on *skb*\ **->data_end**) is2670 * susceptible to fail if offsets are invalid, or if the requested2671 * data is in non-linear parts of the *skb*. On failure the2672 * program can just bail out, or in the case of a non-linear2673 * buffer, use a helper to make the data available. The2674 * **bpf_skb_load_bytes**\ () helper is a first solution to access2675 * the data. Another one consists in using **bpf_skb_pull_data**2676 * to pull in once the non-linear parts, then retesting and2677 * eventually access the data.2678 *2679 * At the same time, this also makes sure the *skb* is uncloned,2680 * which is a necessary condition for direct write. As this needs2681 * to be an invariant for the write part only, the verifier2682 * detects writes and adds a prologue that is calling2683 * **bpf_skb_pull_data()** to effectively unclone the *skb* from2684 * the very beginning in case it is indeed cloned.2685 *2686 * A call to this helper is susceptible to change the underlying2687 * packet buffer. Therefore, at load time, all checks on pointers2688 * previously done by the verifier are invalidated and must be2689 * performed again, if the helper is used in combination with2690 * direct packet access.2691 * Return2692 * 0 on success, or a negative error in case of failure.2693 *2694 * s64 bpf_csum_update(struct sk_buff *skb, __wsum csum)2695 * Description2696 * Add the checksum *csum* into *skb*\ **->csum** in case the2697 * driver has supplied a checksum for the entire packet into that2698 * field. Return an error otherwise. This helper is intended to be2699 * used in combination with **bpf_csum_diff**\ (), in particular2700 * when the checksum needs to be updated after data has been2701 * written into the packet through direct packet access.2702 * Return2703 * The checksum on success, or a negative error code in case of2704 * failure.2705 *2706 * void bpf_set_hash_invalid(struct sk_buff *skb)2707 * Description2708 * Invalidate the current *skb*\ **->hash**. It can be used after2709 * mangling on headers through direct packet access, in order to2710 * indicate that the hash is outdated and to trigger a2711 * recalculation the next time the kernel tries to access this2712 * hash or when the **bpf_get_hash_recalc**\ () helper is called.2713 * Return2714 * void.2715 *2716 * long bpf_get_numa_node_id(void)2717 * Description2718 * Return the id of the current NUMA node. The primary use case2719 * for this helper is the selection of sockets for the local NUMA2720 * node, when the program is attached to sockets using the2721 * **SO_ATTACH_REUSEPORT_EBPF** option (see also **socket(7)**),2722 * but the helper is also available to other eBPF program types,2723 * similarly to **bpf_get_smp_processor_id**\ ().2724 * Return2725 * The id of current NUMA node.2726 *2727 * long bpf_skb_change_head(struct sk_buff *skb, u32 len, u64 flags)2728 * Description2729 * Grows headroom of packet associated to *skb* and adjusts the2730 * offset of the MAC header accordingly, adding *len* bytes of2731 * space. It automatically extends and reallocates memory as2732 * required.2733 *2734 * This helper can be used on a layer 3 *skb* to push a MAC header2735 * for redirection into a layer 2 device.2736 *2737 * All values for *flags* are reserved for future usage, and must2738 * be left at zero.2739 *2740 * A call to this helper is susceptible to change the underlying2741 * packet buffer. Therefore, at load time, all checks on pointers2742 * previously done by the verifier are invalidated and must be2743 * performed again, if the helper is used in combination with2744 * direct packet access.2745 * Return2746 * 0 on success, or a negative error in case of failure.2747 *2748 * long bpf_xdp_adjust_head(struct xdp_buff *xdp_md, int delta)2749 * Description2750 * Adjust (move) *xdp_md*\ **->data** by *delta* bytes. Note that2751 * it is possible to use a negative value for *delta*. This helper2752 * can be used to prepare the packet for pushing or popping2753 * headers.2754 *2755 * A call to this helper is susceptible to change the underlying2756 * packet buffer. Therefore, at load time, all checks on pointers2757 * previously done by the verifier are invalidated and must be2758 * performed again, if the helper is used in combination with2759 * direct packet access.2760 * Return2761 * 0 on success, or a negative error in case of failure.2762 *2763 * long bpf_probe_read_str(void *dst, u32 size, const void *unsafe_ptr)2764 * Description2765 * Copy a NUL terminated string from an unsafe kernel address2766 * *unsafe_ptr* to *dst*. See **bpf_probe_read_kernel_str**\ () for2767 * more details.2768 *2769 * Generally, use **bpf_probe_read_user_str**\ () or2770 * **bpf_probe_read_kernel_str**\ () instead.2771 * Return2772 * On success, the strictly positive length of the string,2773 * including the trailing NUL character. On error, a negative2774 * value.2775 *2776 * u64 bpf_get_socket_cookie(struct sk_buff *skb)2777 * Description2778 * If the **struct sk_buff** pointed by *skb* has a known socket,2779 * retrieve the cookie (generated by the kernel) of this socket.2780 * If no cookie has been set yet, generate a new cookie. Once2781 * generated, the socket cookie remains stable for the life of the2782 * socket. This helper can be useful for monitoring per socket2783 * networking traffic statistics as it provides a global socket2784 * identifier that can be assumed unique.2785 * Return2786 * A 8-byte long unique number on success, or 0 if the socket2787 * field is missing inside *skb*.2788 *2789 * u64 bpf_get_socket_cookie(struct bpf_sock_addr *ctx)2790 * Description2791 * Equivalent to bpf_get_socket_cookie() helper that accepts2792 * *skb*, but gets socket from **struct bpf_sock_addr** context.2793 * Return2794 * A 8-byte long unique number.2795 *2796 * u64 bpf_get_socket_cookie(struct bpf_sock_ops *ctx)2797 * Description2798 * Equivalent to **bpf_get_socket_cookie**\ () helper that accepts2799 * *skb*, but gets socket from **struct bpf_sock_ops** context.2800 * Return2801 * A 8-byte long unique number.2802 *2803 * u64 bpf_get_socket_cookie(struct sock *sk)2804 * Description2805 * Equivalent to **bpf_get_socket_cookie**\ () helper that accepts2806 * *sk*, but gets socket from a BTF **struct sock**. This helper2807 * also works for sleepable programs.2808 * Return2809 * A 8-byte long unique number or 0 if *sk* is NULL.2810 *2811 * u32 bpf_get_socket_uid(struct sk_buff *skb)2812 * Description2813 * Get the owner UID of the socked associated to *skb*.2814 * Return2815 * The owner UID of the socket associated to *skb*. If the socket2816 * is **NULL**, or if it is not a full socket (i.e. if it is a2817 * time-wait or a request socket instead), **overflowuid** value2818 * is returned (note that **overflowuid** might also be the actual2819 * UID value for the socket).2820 *2821 * long bpf_set_hash(struct sk_buff *skb, u32 hash)2822 * Description2823 * Set the full hash for *skb* (set the field *skb*\ **->hash**)2824 * to value *hash*.2825 * Return2826 * 02827 *2828 * long bpf_setsockopt(void *bpf_socket, int level, int optname, void *optval, int optlen)2829 * Description2830 * Emulate a call to **setsockopt()** on the socket associated to2831 * *bpf_socket*, which must be a full socket. The *level* at2832 * which the option resides and the name *optname* of the option2833 * must be specified, see **setsockopt(2)** for more information.2834 * The option value of length *optlen* is pointed by *optval*.2835 *2836 * *bpf_socket* should be one of the following:2837 *2838 * * **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.2839 * * **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**,2840 * **BPF_CGROUP_INET6_CONNECT** and **BPF_CGROUP_UNIX_CONNECT**.2841 *2842 * This helper actually implements a subset of **setsockopt()**.2843 * It supports the following *level*\ s:2844 *2845 * * **SOL_SOCKET**, which supports the following *optname*\ s:2846 * **SO_RCVBUF**, **SO_SNDBUF**, **SO_MAX_PACING_RATE**,2847 * **SO_PRIORITY**, **SO_RCVLOWAT**, **SO_MARK**,2848 * **SO_BINDTODEVICE**, **SO_KEEPALIVE**, **SO_REUSEADDR**,2849 * **SO_REUSEPORT**, **SO_BINDTOIFINDEX**, **SO_TXREHASH**.2850 * * **IPPROTO_TCP**, which supports the following *optname*\ s:2851 * **TCP_CONGESTION**, **TCP_BPF_IW**,2852 * **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,2853 * **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,2854 * **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**,2855 * **TCP_NODELAY**, **TCP_MAXSEG**, **TCP_WINDOW_CLAMP**,2856 * **TCP_THIN_LINEAR_TIMEOUTS**, **TCP_BPF_DELACK_MAX**,2857 * **TCP_BPF_RTO_MIN**, **TCP_BPF_SOCK_OPS_CB_FLAGS**.2858 * * **IPPROTO_IP**, which supports *optname* **IP_TOS**.2859 * * **IPPROTO_IPV6**, which supports the following *optname*\ s:2860 * **IPV6_TCLASS**, **IPV6_AUTOFLOWLABEL**.2861 * Return2862 * 0 on success, or a negative error in case of failure.2863 *2864 * long bpf_skb_adjust_room(struct sk_buff *skb, s32 len_diff, u32 mode, u64 flags)2865 * Description2866 * Grow or shrink the room for data in the packet associated to2867 * *skb* by *len_diff*, and according to the selected *mode*.2868 *2869 * By default, the helper will reset any offloaded checksum2870 * indicator of the skb to CHECKSUM_NONE. This can be avoided2871 * by the following flag:2872 *2873 * * **BPF_F_ADJ_ROOM_NO_CSUM_RESET**: Do not reset offloaded2874 * checksum data of the skb to CHECKSUM_NONE.2875 *2876 * There are two supported modes at this time:2877 *2878 * * **BPF_ADJ_ROOM_MAC**: Adjust room at the mac layer2879 * (room space is added or removed between the layer 2 and2880 * layer 3 headers).2881 *2882 * * **BPF_ADJ_ROOM_NET**: Adjust room at the network layer2883 * (room space is added or removed between the layer 3 and2884 * layer 4 headers).2885 *2886 * The following flags are supported at this time:2887 *2888 * * **BPF_F_ADJ_ROOM_FIXED_GSO**: Do not adjust gso_size.2889 * Adjusting mss in this way is not allowed for datagrams.2890 *2891 * * **BPF_F_ADJ_ROOM_ENCAP_L3_IPV4**,2892 * **BPF_F_ADJ_ROOM_ENCAP_L3_IPV6**:2893 * Any new space is reserved to hold a tunnel header.2894 * Configure skb offsets and other fields accordingly.2895 *2896 * * **BPF_F_ADJ_ROOM_ENCAP_L4_GRE**,2897 * **BPF_F_ADJ_ROOM_ENCAP_L4_UDP**:2898 * Use with ENCAP_L3 flags to further specify the tunnel type.2899 *2900 * * **BPF_F_ADJ_ROOM_ENCAP_L2**\ (*len*):2901 * Use with ENCAP_L3/L4 flags to further specify the tunnel2902 * type; *len* is the length of the inner MAC header.2903 *2904 * * **BPF_F_ADJ_ROOM_ENCAP_L2_ETH**:2905 * Use with BPF_F_ADJ_ROOM_ENCAP_L2 flag to further specify the2906 * L2 type as Ethernet.2907 *2908 * * **BPF_F_ADJ_ROOM_DECAP_L3_IPV4**,2909 * **BPF_F_ADJ_ROOM_DECAP_L3_IPV6**:2910 * Indicate the new IP header version after decapsulating the outer2911 * IP header. Used when the inner and outer IP versions are different.2912 *2913 * A call to this helper is susceptible to change the underlying2914 * packet buffer. Therefore, at load time, all checks on pointers2915 * previously done by the verifier are invalidated and must be2916 * performed again, if the helper is used in combination with2917 * direct packet access.2918 * Return2919 * 0 on success, or a negative error in case of failure.2920 *2921 * long bpf_redirect_map(struct bpf_map *map, u64 key, u64 flags)2922 * Description2923 * Redirect the packet to the endpoint referenced by *map* at2924 * index *key*. Depending on its type, this *map* can contain2925 * references to net devices (for forwarding packets through other2926 * ports), or to CPUs (for redirecting XDP frames to another CPU;2927 * but this is only implemented for native XDP (with driver2928 * support) as of this writing).2929 *2930 * The lower two bits of *flags* are used as the return code if2931 * the map lookup fails. This is so that the return value can be2932 * one of the XDP program return codes up to **XDP_TX**, as chosen2933 * by the caller. The higher bits of *flags* can be set to2934 * BPF_F_BROADCAST or BPF_F_EXCLUDE_INGRESS as defined below.2935 *2936 * With BPF_F_BROADCAST the packet will be broadcasted to all the2937 * interfaces in the map, with BPF_F_EXCLUDE_INGRESS the ingress2938 * interface will be excluded when do broadcasting.2939 *2940 * See also **bpf_redirect**\ (), which only supports redirecting2941 * to an ifindex, but doesn't require a map to do so.2942 * Return2943 * **XDP_REDIRECT** on success, or the value of the two lower bits2944 * of the *flags* argument on error.2945 *2946 * long bpf_sk_redirect_map(struct sk_buff *skb, struct bpf_map *map, u32 key, u64 flags)2947 * Description2948 * Redirect the packet to the socket referenced by *map* (of type2949 * **BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and2950 * egress interfaces can be used for redirection. The2951 * **BPF_F_INGRESS** value in *flags* is used to make the2952 * distinction (ingress path is selected if the flag is present,2953 * egress path otherwise). This is the only flag supported for now.2954 * Return2955 * **SK_PASS** on success, or **SK_DROP** on error.2956 *2957 * long bpf_sock_map_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)2958 * Description2959 * Add an entry to, or update a *map* referencing sockets. The2960 * *skops* is used as a new value for the entry associated to2961 * *key*. *flags* is one of:2962 *2963 * **BPF_NOEXIST**2964 * The entry for *key* must not exist in the map.2965 * **BPF_EXIST**2966 * The entry for *key* must already exist in the map.2967 * **BPF_ANY**2968 * No condition on the existence of the entry for *key*.2969 *2970 * If the *map* has eBPF programs (parser and verdict), those will2971 * be inherited by the socket being added. If the socket is2972 * already attached to eBPF programs, this results in an error.2973 * Return2974 * 0 on success, or a negative error in case of failure.2975 *2976 * long bpf_xdp_adjust_meta(struct xdp_buff *xdp_md, int delta)2977 * Description2978 * Adjust the address pointed by *xdp_md*\ **->data_meta** by2979 * *delta* (which can be positive or negative). Note that this2980 * operation modifies the address stored in *xdp_md*\ **->data**,2981 * so the latter must be loaded only after the helper has been2982 * called.2983 *2984 * The use of *xdp_md*\ **->data_meta** is optional and programs2985 * are not required to use it. The rationale is that when the2986 * packet is processed with XDP (e.g. as DoS filter), it is2987 * possible to push further meta data along with it before passing2988 * to the stack, and to give the guarantee that an ingress eBPF2989 * program attached as a TC classifier on the same device can pick2990 * this up for further post-processing. Since TC works with socket2991 * buffers, it remains possible to set from XDP the **mark** or2992 * **priority** pointers, or other pointers for the socket buffer.2993 * Having this scratch space generic and programmable allows for2994 * more flexibility as the user is free to store whatever meta2995 * data they need.2996 *2997 * A call to this helper is susceptible to change the underlying2998 * packet buffer. Therefore, at load time, all checks on pointers2999 * previously done by the verifier are invalidated and must be3000 * performed again, if the helper is used in combination with3001 * direct packet access.3002 * Return3003 * 0 on success, or a negative error in case of failure.3004 *3005 * long bpf_perf_event_read_value(struct bpf_map *map, u64 flags, struct bpf_perf_event_value *buf, u32 buf_size)3006 * Description3007 * Read the value of a perf event counter, and store it into *buf*3008 * of size *buf_size*. This helper relies on a *map* of type3009 * **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of the perf event3010 * counter is selected when *map* is updated with perf event file3011 * descriptors. The *map* is an array whose size is the number of3012 * available CPUs, and each cell contains a value relative to one3013 * CPU. The value to retrieve is indicated by *flags*, that3014 * contains the index of the CPU to look up, masked with3015 * **BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to3016 * **BPF_F_CURRENT_CPU** to indicate that the value for the3017 * current CPU should be retrieved.3018 *3019 * This helper behaves in a way close to3020 * **bpf_perf_event_read**\ () helper, save that instead of3021 * just returning the value observed, it fills the *buf*3022 * structure. This allows for additional data to be retrieved: in3023 * particular, the enabled and running times (in *buf*\3024 * **->enabled** and *buf*\ **->running**, respectively) are3025 * copied. In general, **bpf_perf_event_read_value**\ () is3026 * recommended over **bpf_perf_event_read**\ (), which has some3027 * ABI issues and provides fewer functionalities.3028 *3029 * These values are interesting, because hardware PMU (Performance3030 * Monitoring Unit) counters are limited resources. When there are3031 * more PMU based perf events opened than available counters,3032 * kernel will multiplex these events so each event gets certain3033 * percentage (but not all) of the PMU time. In case that3034 * multiplexing happens, the number of samples or counter value3035 * will not reflect the case compared to when no multiplexing3036 * occurs. This makes comparison between different runs difficult.3037 * Typically, the counter value should be normalized before3038 * comparing to other experiments. The usual normalization is done3039 * as follows.3040 *3041 * ::3042 *3043 * normalized_counter = counter * t_enabled / t_running3044 *3045 * Where t_enabled is the time enabled for event and t_running is3046 * the time running for event since last normalization. The3047 * enabled and running times are accumulated since the perf event3048 * open. To achieve scaling factor between two invocations of an3049 * eBPF program, users can use CPU id as the key (which is3050 * typical for perf array usage model) to remember the previous3051 * value and do the calculation inside the eBPF program.3052 * Return3053 * 0 on success, or a negative error in case of failure.3054 *3055 * long bpf_perf_prog_read_value(struct bpf_perf_event_data *ctx, struct bpf_perf_event_value *buf, u32 buf_size)3056 * Description3057 * For an eBPF program attached to a perf event, retrieve the3058 * value of the event counter associated to *ctx* and store it in3059 * the structure pointed by *buf* and of size *buf_size*. Enabled3060 * and running times are also stored in the structure (see3061 * description of helper **bpf_perf_event_read_value**\ () for3062 * more details).3063 * Return3064 * 0 on success, or a negative error in case of failure.3065 *3066 * long bpf_getsockopt(void *bpf_socket, int level, int optname, void *optval, int optlen)3067 * Description3068 * Emulate a call to **getsockopt()** on the socket associated to3069 * *bpf_socket*, which must be a full socket. The *level* at3070 * which the option resides and the name *optname* of the option3071 * must be specified, see **getsockopt(2)** for more information.3072 * The retrieved value is stored in the structure pointed by3073 * *opval* and of length *optlen*.3074 *3075 * *bpf_socket* should be one of the following:3076 *3077 * * **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.3078 * * **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**,3079 * **BPF_CGROUP_INET6_CONNECT** and **BPF_CGROUP_UNIX_CONNECT**.3080 *3081 * This helper actually implements a subset of **getsockopt()**.3082 * It supports the same set of *optname*\ s that is supported by3083 * the **bpf_setsockopt**\ () helper. The exceptions are3084 * **TCP_BPF_*** is **bpf_setsockopt**\ () only and3085 * **TCP_SAVED_SYN** is **bpf_getsockopt**\ () only.3086 * Return3087 * 0 on success, or a negative error in case of failure.3088 *3089 * long bpf_override_return(struct pt_regs *regs, u64 rc)3090 * Description3091 * Used for error injection, this helper uses kprobes to override3092 * the return value of the probed function, and to set it to *rc*.3093 * The first argument is the context *regs* on which the kprobe3094 * works.3095 *3096 * This helper works by setting the PC (program counter)3097 * to an override function which is run in place of the original3098 * probed function. This means the probed function is not run at3099 * all. The replacement function just returns with the required3100 * value.3101 *3102 * This helper has security implications, and thus is subject to3103 * restrictions. It is only available if the kernel was compiled3104 * with the **CONFIG_BPF_KPROBE_OVERRIDE** configuration3105 * option, and in this case it only works on functions tagged with3106 * **ALLOW_ERROR_INJECTION** in the kernel code.3107 *3108 * Also, the helper is only available for the architectures having3109 * the CONFIG_FUNCTION_ERROR_INJECTION option. As of this writing,3110 * x86 architecture is the only one to support this feature.3111 * Return3112 * 03113 *3114 * long bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *bpf_sock, int argval)3115 * Description3116 * Attempt to set the value of the **bpf_sock_ops_cb_flags** field3117 * for the full TCP socket associated to *bpf_sock_ops* to3118 * *argval*.3119 *3120 * The primary use of this field is to determine if there should3121 * be calls to eBPF programs of type3122 * **BPF_PROG_TYPE_SOCK_OPS** at various points in the TCP3123 * code. A program of the same type can change its value, per3124 * connection and as necessary, when the connection is3125 * established. This field is directly accessible for reading, but3126 * this helper must be used for updates in order to return an3127 * error if an eBPF program tries to set a callback that is not3128 * supported in the current kernel.3129 *3130 * *argval* is a flag array which can combine these flags:3131 *3132 * * **BPF_SOCK_OPS_RTO_CB_FLAG** (retransmission time out)3133 * * **BPF_SOCK_OPS_RETRANS_CB_FLAG** (retransmission)3134 * * **BPF_SOCK_OPS_STATE_CB_FLAG** (TCP state change)3135 * * **BPF_SOCK_OPS_RTT_CB_FLAG** (every RTT)3136 *3137 * Therefore, this function can be used to clear a callback flag by3138 * setting the appropriate bit to zero. e.g. to disable the RTO3139 * callback:3140 *3141 * **bpf_sock_ops_cb_flags_set(bpf_sock,**3142 * **bpf_sock->bpf_sock_ops_cb_flags & ~BPF_SOCK_OPS_RTO_CB_FLAG)**3143 *3144 * Here are some examples of where one could call such eBPF3145 * program:3146 *3147 * * When RTO fires.3148 * * When a packet is retransmitted.3149 * * When the connection terminates.3150 * * When a packet is sent.3151 * * When a packet is received.3152 * Return3153 * Code **-EINVAL** if the socket is not a full TCP socket;3154 * otherwise, a positive number containing the bits that could not3155 * be set is returned (which comes down to 0 if all bits were set3156 * as required).3157 *3158 * long bpf_msg_redirect_map(struct sk_msg_buff *msg, struct bpf_map *map, u32 key, u64 flags)3159 * Description3160 * This helper is used in programs implementing policies at the3161 * socket level. If the message *msg* is allowed to pass (i.e. if3162 * the verdict eBPF program returns **SK_PASS**), redirect it to3163 * the socket referenced by *map* (of type3164 * **BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and3165 * egress interfaces can be used for redirection. The3166 * **BPF_F_INGRESS** value in *flags* is used to make the3167 * distinction (ingress path is selected if the flag is present,3168 * egress path otherwise). This is the only flag supported for now.3169 * Return3170 * **SK_PASS** on success, or **SK_DROP** on error.3171 *3172 * long bpf_msg_apply_bytes(struct sk_msg_buff *msg, u32 bytes)3173 * Description3174 * For socket policies, apply the verdict of the eBPF program to3175 * the next *bytes* (number of bytes) of message *msg*.3176 *3177 * For example, this helper can be used in the following cases:3178 *3179 * * A single **sendmsg**\ () or **sendfile**\ () system call3180 * contains multiple logical messages that the eBPF program is3181 * supposed to read and for which it should apply a verdict.3182 * * An eBPF program only cares to read the first *bytes* of a3183 * *msg*. If the message has a large payload, then setting up3184 * and calling the eBPF program repeatedly for all bytes, even3185 * though the verdict is already known, would create unnecessary3186 * overhead.3187 *3188 * When called from within an eBPF program, the helper sets a3189 * counter internal to the BPF infrastructure, that is used to3190 * apply the last verdict to the next *bytes*. If *bytes* is3191 * smaller than the current data being processed from a3192 * **sendmsg**\ () or **sendfile**\ () system call, the first3193 * *bytes* will be sent and the eBPF program will be re-run with3194 * the pointer for start of data pointing to byte number *bytes*3195 * **+ 1**. If *bytes* is larger than the current data being3196 * processed, then the eBPF verdict will be applied to multiple3197 * **sendmsg**\ () or **sendfile**\ () calls until *bytes* are3198 * consumed.3199 *3200 * Note that if a socket closes with the internal counter holding3201 * a non-zero value, this is not a problem because data is not3202 * being buffered for *bytes* and is sent as it is received.3203 * Return3204 * 03205 *3206 * long bpf_msg_cork_bytes(struct sk_msg_buff *msg, u32 bytes)3207 * Description3208 * For socket policies, prevent the execution of the verdict eBPF3209 * program for message *msg* until *bytes* (byte number) have been3210 * accumulated.3211 *3212 * This can be used when one needs a specific number of bytes3213 * before a verdict can be assigned, even if the data spans3214 * multiple **sendmsg**\ () or **sendfile**\ () calls. The extreme3215 * case would be a user calling **sendmsg**\ () repeatedly with3216 * 1-byte long message segments. Obviously, this is bad for3217 * performance, but it is still valid. If the eBPF program needs3218 * *bytes* bytes to validate a header, this helper can be used to3219 * prevent the eBPF program to be called again until *bytes* have3220 * been accumulated.3221 * Return3222 * 03223 *3224 * long bpf_msg_pull_data(struct sk_msg_buff *msg, u32 start, u32 end, u64 flags)3225 * Description3226 * For socket policies, pull in non-linear data from user space3227 * for *msg* and set pointers *msg*\ **->data** and *msg*\3228 * **->data_end** to *start* and *end* bytes offsets into *msg*,3229 * respectively.3230 *3231 * If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a3232 * *msg* it can only parse data that the (**data**, **data_end**)3233 * pointers have already consumed. For **sendmsg**\ () hooks this3234 * is likely the first scatterlist element. But for calls relying3235 * on the **sendpage** handler (e.g. **sendfile**\ ()) this will3236 * be the range (**0**, **0**) because the data is shared with3237 * user space and by default the objective is to avoid allowing3238 * user space to modify data while (or after) eBPF verdict is3239 * being decided. This helper can be used to pull in data and to3240 * set the start and end pointer to given values. Data will be3241 * copied if necessary (i.e. if data was not linear and if start3242 * and end pointers do not point to the same chunk).3243 *3244 * A call to this helper is susceptible to change the underlying3245 * packet buffer. Therefore, at load time, all checks on pointers3246 * previously done by the verifier are invalidated and must be3247 * performed again, if the helper is used in combination with3248 * direct packet access.3249 *3250 * All values for *flags* are reserved for future usage, and must3251 * be left at zero.3252 * Return3253 * 0 on success, or a negative error in case of failure.3254 *3255 * long bpf_bind(struct bpf_sock_addr *ctx, struct sockaddr *addr, int addr_len)3256 * Description3257 * Bind the socket associated to *ctx* to the address pointed by3258 * *addr*, of length *addr_len*. This allows for making outgoing3259 * connection from the desired IP address, which can be useful for3260 * example when all processes inside a cgroup should use one3261 * single IP address on a host that has multiple IP configured.3262 *3263 * This helper works for IPv4 and IPv6, TCP and UDP sockets. The3264 * domain (*addr*\ **->sa_family**) must be **AF_INET** (or3265 * **AF_INET6**). It's advised to pass zero port (**sin_port**3266 * or **sin6_port**) which triggers IP_BIND_ADDRESS_NO_PORT-like3267 * behavior and lets the kernel efficiently pick up an unused3268 * port as long as 4-tuple is unique. Passing non-zero port might3269 * lead to degraded performance.3270 * Return3271 * 0 on success, or a negative error in case of failure.3272 *3273 * long bpf_xdp_adjust_tail(struct xdp_buff *xdp_md, int delta)3274 * Description3275 * Adjust (move) *xdp_md*\ **->data_end** by *delta* bytes. It is3276 * possible to both shrink and grow the packet tail.3277 * Shrink done via *delta* being a negative integer.3278 *3279 * A call to this helper is susceptible to change the underlying3280 * packet buffer. Therefore, at load time, all checks on pointers3281 * previously done by the verifier are invalidated and must be3282 * performed again, if the helper is used in combination with3283 * direct packet access.3284 * Return3285 * 0 on success, or a negative error in case of failure.3286 *3287 * long bpf_skb_get_xfrm_state(struct sk_buff *skb, u32 index, struct bpf_xfrm_state *xfrm_state, u32 size, u64 flags)3288 * Description3289 * Retrieve the XFRM state (IP transform framework, see also3290 * **ip-xfrm(8)**) at *index* in XFRM "security path" for *skb*.3291 *3292 * The retrieved value is stored in the **struct bpf_xfrm_state**3293 * pointed by *xfrm_state* and of length *size*.3294 *3295 * All values for *flags* are reserved for future usage, and must3296 * be left at zero.3297 *3298 * This helper is available only if the kernel was compiled with3299 * **CONFIG_XFRM** configuration option.3300 * Return3301 * 0 on success, or a negative error in case of failure.3302 *3303 * long bpf_get_stack(void *ctx, void *buf, u32 size, u64 flags)3304 * Description3305 * Return a user or a kernel stack in bpf program provided buffer.3306 * To achieve this, the helper needs *ctx*, which is a pointer3307 * to the context on which the tracing program is executed.3308 * To store the stacktrace, the bpf program provides *buf* with3309 * a nonnegative *size*.3310 *3311 * The last argument, *flags*, holds the number of stack frames to3312 * skip (from 0 to 255), masked with3313 * **BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set3314 * the following flags:3315 *3316 * **BPF_F_USER_STACK**3317 * Collect a user space stack instead of a kernel stack.3318 * **BPF_F_USER_BUILD_ID**3319 * Collect (build_id, file_offset) instead of ips for user3320 * stack, only valid if **BPF_F_USER_STACK** is also3321 * specified.3322 *3323 * *file_offset* is an offset relative to the beginning3324 * of the executable or shared object file backing the vma3325 * which the *ip* falls in. It is *not* an offset relative3326 * to that object's base address. Accordingly, it must be3327 * adjusted by adding (sh_addr - sh_offset), where3328 * sh_{addr,offset} correspond to the executable section3329 * containing *file_offset* in the object, for comparisons3330 * to symbols' st_value to be valid.3331 *3332 * **bpf_get_stack**\ () can collect up to3333 * **PERF_MAX_STACK_DEPTH** both kernel and user frames, subject3334 * to sufficient large buffer size. Note that3335 * this limit can be controlled with the **sysctl** program, and3336 * that it should be manually increased in order to profile long3337 * user stacks (such as stacks for Java programs). To do so, use:3338 *3339 * ::3340 *3341 * # sysctl kernel.perf_event_max_stack=<new value>3342 * Return3343 * The non-negative copied *buf* length equal to or less than3344 * *size* on success, or a negative error in case of failure.3345 *3346 * long bpf_skb_load_bytes_relative(const void *skb, u32 offset, void *to, u32 len, u32 start_header)3347 * Description3348 * This helper is similar to **bpf_skb_load_bytes**\ () in that3349 * it provides an easy way to load *len* bytes from *offset*3350 * from the packet associated to *skb*, into the buffer pointed3351 * by *to*. The difference to **bpf_skb_load_bytes**\ () is that3352 * a fifth argument *start_header* exists in order to select a3353 * base offset to start from. *start_header* can be one of:3354 *3355 * **BPF_HDR_START_MAC**3356 * Base offset to load data from is *skb*'s mac header.3357 * **BPF_HDR_START_NET**3358 * Base offset to load data from is *skb*'s network header.3359 *3360 * In general, "direct packet access" is the preferred method to3361 * access packet data, however, this helper is in particular useful3362 * in socket filters where *skb*\ **->data** does not always point3363 * to the start of the mac header and where "direct packet access"3364 * is not available.3365 * Return3366 * 0 on success, or a negative error in case of failure.3367 *3368 * long bpf_fib_lookup(void *ctx, struct bpf_fib_lookup *params, int plen, u32 flags)3369 * Description3370 * Do FIB lookup in kernel tables using parameters in *params*.3371 * If lookup is successful and result shows packet is to be3372 * forwarded, the neighbor tables are searched for the nexthop.3373 * If successful (ie., FIB lookup shows forwarding and nexthop3374 * is resolved), the nexthop address is returned in ipv4_dst3375 * or ipv6_dst based on family, smac is set to mac address of3376 * egress device, dmac is set to nexthop mac address, rt_metric3377 * is set to metric from route (IPv4/IPv6 only), and ifindex3378 * is set to the device index of the nexthop from the FIB lookup.3379 *3380 * *plen* argument is the size of the passed in struct.3381 * *flags* argument can be a combination of one or more of the3382 * following values:3383 *3384 * **BPF_FIB_LOOKUP_DIRECT**3385 * Do a direct table lookup vs full lookup using FIB3386 * rules.3387 * **BPF_FIB_LOOKUP_TBID**3388 * Used with BPF_FIB_LOOKUP_DIRECT.3389 * Use the routing table ID present in *params*->tbid3390 * for the fib lookup.3391 * **BPF_FIB_LOOKUP_OUTPUT**3392 * Perform lookup from an egress perspective (default is3393 * ingress).3394 * **BPF_FIB_LOOKUP_SKIP_NEIGH**3395 * Skip the neighbour table lookup. *params*->dmac3396 * and *params*->smac will not be set as output. A common3397 * use case is to call **bpf_redirect_neigh**\ () after3398 * doing **bpf_fib_lookup**\ ().3399 * **BPF_FIB_LOOKUP_SRC**3400 * Derive and set source IP addr in *params*->ipv{4,6}_src3401 * for the nexthop. If the src addr cannot be derived,3402 * **BPF_FIB_LKUP_RET_NO_SRC_ADDR** is returned. In this3403 * case, *params*->dmac and *params*->smac are not set either.3404 * **BPF_FIB_LOOKUP_MARK**3405 * Use the mark present in *params*->mark for the fib lookup.3406 * This option should not be used with BPF_FIB_LOOKUP_DIRECT,3407 * as it only has meaning for full lookups.3408 *3409 * *ctx* is either **struct xdp_md** for XDP programs or3410 * **struct sk_buff** tc cls_act programs.3411 * Return3412 * * < 0 if any input argument is invalid3413 * * 0 on success (packet is forwarded, nexthop neighbor exists)3414 * * > 0 one of **BPF_FIB_LKUP_RET_** codes explaining why the3415 * packet is not forwarded or needs assist from full stack3416 *3417 * If lookup fails with BPF_FIB_LKUP_RET_FRAG_NEEDED, then the MTU3418 * was exceeded and output params->mtu_result contains the MTU.3419 *3420 * long bpf_sock_hash_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)3421 * Description3422 * Add an entry to, or update a sockhash *map* referencing sockets.3423 * The *skops* is used as a new value for the entry associated to3424 * *key*. *flags* is one of:3425 *3426 * **BPF_NOEXIST**3427 * The entry for *key* must not exist in the map.3428 * **BPF_EXIST**3429 * The entry for *key* must already exist in the map.3430 * **BPF_ANY**3431 * No condition on the existence of the entry for *key*.3432 *3433 * If the *map* has eBPF programs (parser and verdict), those will3434 * be inherited by the socket being added. If the socket is3435 * already attached to eBPF programs, this results in an error.3436 * Return3437 * 0 on success, or a negative error in case of failure.3438 *3439 * long bpf_msg_redirect_hash(struct sk_msg_buff *msg, struct bpf_map *map, void *key, u64 flags)3440 * Description3441 * This helper is used in programs implementing policies at the3442 * socket level. If the message *msg* is allowed to pass (i.e. if3443 * the verdict eBPF program returns **SK_PASS**), redirect it to3444 * the socket referenced by *map* (of type3445 * **BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and3446 * egress interfaces can be used for redirection. The3447 * **BPF_F_INGRESS** value in *flags* is used to make the3448 * distinction (ingress path is selected if the flag is present,3449 * egress path otherwise). This is the only flag supported for now.3450 * Return3451 * **SK_PASS** on success, or **SK_DROP** on error.3452 *3453 * long bpf_sk_redirect_hash(struct sk_buff *skb, struct bpf_map *map, void *key, u64 flags)3454 * Description3455 * This helper is used in programs implementing policies at the3456 * skb socket level. If the sk_buff *skb* is allowed to pass (i.e.3457 * if the verdict eBPF program returns **SK_PASS**), redirect it3458 * to the socket referenced by *map* (of type3459 * **BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and3460 * egress interfaces can be used for redirection. The3461 * **BPF_F_INGRESS** value in *flags* is used to make the3462 * distinction (ingress path is selected if the flag is present,3463 * egress otherwise). This is the only flag supported for now.3464 * Return3465 * **SK_PASS** on success, or **SK_DROP** on error.3466 *3467 * long bpf_lwt_push_encap(struct sk_buff *skb, u32 type, void *hdr, u32 len)3468 * Description3469 * Encapsulate the packet associated to *skb* within a Layer 33470 * protocol header. This header is provided in the buffer at3471 * address *hdr*, with *len* its size in bytes. *type* indicates3472 * the protocol of the header and can be one of:3473 *3474 * **BPF_LWT_ENCAP_SEG6**3475 * IPv6 encapsulation with Segment Routing Header3476 * (**struct ipv6_sr_hdr**). *hdr* only contains the SRH,3477 * the IPv6 header is computed by the kernel.3478 * **BPF_LWT_ENCAP_SEG6_INLINE**3479 * Only works if *skb* contains an IPv6 packet. Insert a3480 * Segment Routing Header (**struct ipv6_sr_hdr**) inside3481 * the IPv6 header.3482 * **BPF_LWT_ENCAP_IP**3483 * IP encapsulation (GRE/GUE/IPIP/etc). The outer header3484 * must be IPv4 or IPv6, followed by zero or more3485 * additional headers, up to **LWT_BPF_MAX_HEADROOM**3486 * total bytes in all prepended headers. Please note that3487 * if **skb_is_gso**\ (*skb*) is true, no more than two3488 * headers can be prepended, and the inner header, if3489 * present, should be either GRE or UDP/GUE.3490 *3491 * **BPF_LWT_ENCAP_SEG6**\ \* types can be called by BPF programs3492 * of type **BPF_PROG_TYPE_LWT_IN**; **BPF_LWT_ENCAP_IP** type can3493 * be called by bpf programs of types **BPF_PROG_TYPE_LWT_IN** and3494 * **BPF_PROG_TYPE_LWT_XMIT**.3495 *3496 * A call to this helper is susceptible to change the underlying3497 * packet buffer. Therefore, at load time, all checks on pointers3498 * previously done by the verifier are invalidated and must be3499 * performed again, if the helper is used in combination with3500 * direct packet access.3501 * Return3502 * 0 on success, or a negative error in case of failure.3503 *3504 * long bpf_lwt_seg6_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len)3505 * Description3506 * Store *len* bytes from address *from* into the packet3507 * associated to *skb*, at *offset*. Only the flags, tag and TLVs3508 * inside the outermost IPv6 Segment Routing Header can be3509 * modified through this helper.3510 *3511 * A call to this helper is susceptible to change the underlying3512 * packet buffer. Therefore, at load time, all checks on pointers3513 * previously done by the verifier are invalidated and must be3514 * performed again, if the helper is used in combination with3515 * direct packet access.3516 * Return3517 * 0 on success, or a negative error in case of failure.3518 *3519 * long bpf_lwt_seg6_adjust_srh(struct sk_buff *skb, u32 offset, s32 delta)3520 * Description3521 * Adjust the size allocated to TLVs in the outermost IPv63522 * Segment Routing Header contained in the packet associated to3523 * *skb*, at position *offset* by *delta* bytes. Only offsets3524 * after the segments are accepted. *delta* can be as well3525 * positive (growing) as negative (shrinking).3526 *3527 * A call to this helper is susceptible to change the underlying3528 * packet buffer. Therefore, at load time, all checks on pointers3529 * previously done by the verifier are invalidated and must be3530 * performed again, if the helper is used in combination with3531 * direct packet access.3532 * Return3533 * 0 on success, or a negative error in case of failure.3534 *3535 * long bpf_lwt_seg6_action(struct sk_buff *skb, u32 action, void *param, u32 param_len)3536 * Description3537 * Apply an IPv6 Segment Routing action of type *action* to the3538 * packet associated to *skb*. Each action takes a parameter3539 * contained at address *param*, and of length *param_len* bytes.3540 * *action* can be one of:3541 *3542 * **SEG6_LOCAL_ACTION_END_X**3543 * End.X action: Endpoint with Layer-3 cross-connect.3544 * Type of *param*: **struct in6_addr**.3545 * **SEG6_LOCAL_ACTION_END_T**3546 * End.T action: Endpoint with specific IPv6 table lookup.3547 * Type of *param*: **int**.3548 * **SEG6_LOCAL_ACTION_END_B6**3549 * End.B6 action: Endpoint bound to an SRv6 policy.3550 * Type of *param*: **struct ipv6_sr_hdr**.3551 * **SEG6_LOCAL_ACTION_END_B6_ENCAP**3552 * End.B6.Encap action: Endpoint bound to an SRv63553 * encapsulation policy.3554 * Type of *param*: **struct ipv6_sr_hdr**.3555 *3556 * A call to this helper is susceptible to change the underlying3557 * packet buffer. Therefore, at load time, all checks on pointers3558 * previously done by the verifier are invalidated and must be3559 * performed again, if the helper is used in combination with3560 * direct packet access.3561 * Return3562 * 0 on success, or a negative error in case of failure.3563 *3564 * long bpf_rc_repeat(void *ctx)3565 * Description3566 * This helper is used in programs implementing IR decoding, to3567 * report a successfully decoded repeat key message. This delays3568 * the generation of a key up event for previously generated3569 * key down event.3570 *3571 * Some IR protocols like NEC have a special IR message for3572 * repeating last button, for when a button is held down.3573 *3574 * The *ctx* should point to the lirc sample as passed into3575 * the program.3576 *3577 * This helper is only available is the kernel was compiled with3578 * the **CONFIG_BPF_LIRC_MODE2** configuration option set to3579 * "**y**".3580 * Return3581 * 03582 *3583 * long bpf_rc_keydown(void *ctx, u32 protocol, u64 scancode, u32 toggle)3584 * Description3585 * This helper is used in programs implementing IR decoding, to3586 * report a successfully decoded key press with *scancode*,3587 * *toggle* value in the given *protocol*. The scancode will be3588 * translated to a keycode using the rc keymap, and reported as3589 * an input key down event. After a period a key up event is3590 * generated. This period can be extended by calling either3591 * **bpf_rc_keydown**\ () again with the same values, or calling3592 * **bpf_rc_repeat**\ ().3593 *3594 * Some protocols include a toggle bit, in case the button was3595 * released and pressed again between consecutive scancodes.3596 *3597 * The *ctx* should point to the lirc sample as passed into3598 * the program.3599 *3600 * The *protocol* is the decoded protocol number (see3601 * **enum rc_proto** for some predefined values).3602 *3603 * This helper is only available is the kernel was compiled with3604 * the **CONFIG_BPF_LIRC_MODE2** configuration option set to3605 * "**y**".3606 * Return3607 * 03608 *3609 * u64 bpf_skb_cgroup_id(struct sk_buff *skb)3610 * Description3611 * Return the cgroup v2 id of the socket associated with the *skb*.3612 * This is roughly similar to the **bpf_get_cgroup_classid**\ ()3613 * helper for cgroup v1 by providing a tag resp. identifier that3614 * can be matched on or used for map lookups e.g. to implement3615 * policy. The cgroup v2 id of a given path in the hierarchy is3616 * exposed in user space through the f_handle API in order to get3617 * to the same 64-bit id.3618 *3619 * This helper can be used on TC egress path, but not on ingress,3620 * and is available only if the kernel was compiled with the3621 * **CONFIG_SOCK_CGROUP_DATA** configuration option.3622 * Return3623 * The id is returned or 0 in case the id could not be retrieved.3624 *3625 * u64 bpf_get_current_cgroup_id(void)3626 * Description3627 * Get the current cgroup id based on the cgroup within which3628 * the current task is running.3629 * Return3630 * A 64-bit integer containing the current cgroup id based3631 * on the cgroup within which the current task is running.3632 *3633 * void *bpf_get_local_storage(void *map, u64 flags)3634 * Description3635 * Get the pointer to the local storage area.3636 * The type and the size of the local storage is defined3637 * by the *map* argument.3638 * The *flags* meaning is specific for each map type,3639 * and has to be 0 for cgroup local storage.3640 *3641 * Depending on the BPF program type, a local storage area3642 * can be shared between multiple instances of the BPF program,3643 * running simultaneously.3644 *3645 * A user should care about the synchronization by himself.3646 * For example, by using the **BPF_ATOMIC** instructions to alter3647 * the shared data.3648 * Return3649 * A pointer to the local storage area.3650 *3651 * long bpf_sk_select_reuseport(struct sk_reuseport_md *reuse, struct bpf_map *map, void *key, u64 flags)3652 * Description3653 * Select a **SO_REUSEPORT** socket from a3654 * **BPF_MAP_TYPE_REUSEPORT_SOCKARRAY** *map*.3655 * It checks the selected socket is matching the incoming3656 * request in the socket buffer.3657 * Return3658 * 0 on success, or a negative error in case of failure.3659 *3660 * u64 bpf_skb_ancestor_cgroup_id(struct sk_buff *skb, int ancestor_level)3661 * Description3662 * Return id of cgroup v2 that is ancestor of cgroup associated3663 * with the *skb* at the *ancestor_level*. The root cgroup is at3664 * *ancestor_level* zero and each step down the hierarchy3665 * increments the level. If *ancestor_level* == level of cgroup3666 * associated with *skb*, then return value will be same as that3667 * of **bpf_skb_cgroup_id**\ ().3668 *3669 * The helper is useful to implement policies based on cgroups3670 * that are upper in hierarchy than immediate cgroup associated3671 * with *skb*.3672 *3673 * The format of returned id and helper limitations are same as in3674 * **bpf_skb_cgroup_id**\ ().3675 * Return3676 * The id is returned or 0 in case the id could not be retrieved.3677 *3678 * struct bpf_sock *bpf_sk_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)3679 * Description3680 * Look for TCP socket matching *tuple*, optionally in a child3681 * network namespace *netns*. The return value must be checked,3682 * and if non-**NULL**, released via **bpf_sk_release**\ ().3683 *3684 * The *ctx* should point to the context of the program, such as3685 * the skb or socket (depending on the hook in use). This is used3686 * to determine the base network namespace for the lookup.3687 *3688 * *tuple_size* must be one of:3689 *3690 * **sizeof**\ (*tuple*\ **->ipv4**)3691 * Look for an IPv4 socket.3692 * **sizeof**\ (*tuple*\ **->ipv6**)3693 * Look for an IPv6 socket.3694 *3695 * If the *netns* is a negative signed 32-bit integer, then the3696 * socket lookup table in the netns associated with the *ctx*3697 * will be used. For the TC hooks, this is the netns of the device3698 * in the skb. For socket hooks, this is the netns of the socket.3699 * If *netns* is any other signed 32-bit value greater than or3700 * equal to zero then it specifies the ID of the netns relative to3701 * the netns associated with the *ctx*. *netns* values beyond the3702 * range of 32-bit integers are reserved for future use.3703 *3704 * All values for *flags* are reserved for future usage, and must3705 * be left at zero.3706 *3707 * This helper is available only if the kernel was compiled with3708 * **CONFIG_NET** configuration option.3709 * Return3710 * Pointer to **struct bpf_sock**, or **NULL** in case of failure.3711 * For sockets with reuseport option, the **struct bpf_sock**3712 * result is from *reuse*\ **->socks**\ [] using the hash of the3713 * tuple.3714 *3715 * struct bpf_sock *bpf_sk_lookup_udp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)3716 * Description3717 * Look for UDP socket matching *tuple*, optionally in a child3718 * network namespace *netns*. The return value must be checked,3719 * and if non-**NULL**, released via **bpf_sk_release**\ ().3720 *3721 * The *ctx* should point to the context of the program, such as3722 * the skb or socket (depending on the hook in use). This is used3723 * to determine the base network namespace for the lookup.3724 *3725 * *tuple_size* must be one of:3726 *3727 * **sizeof**\ (*tuple*\ **->ipv4**)3728 * Look for an IPv4 socket.3729 * **sizeof**\ (*tuple*\ **->ipv6**)3730 * Look for an IPv6 socket.3731 *3732 * If the *netns* is a negative signed 32-bit integer, then the3733 * socket lookup table in the netns associated with the *ctx*3734 * will be used. For the TC hooks, this is the netns of the device3735 * in the skb. For socket hooks, this is the netns of the socket.3736 * If *netns* is any other signed 32-bit value greater than or3737 * equal to zero then it specifies the ID of the netns relative to3738 * the netns associated with the *ctx*. *netns* values beyond the3739 * range of 32-bit integers are reserved for future use.3740 *3741 * All values for *flags* are reserved for future usage, and must3742 * be left at zero.3743 *3744 * This helper is available only if the kernel was compiled with3745 * **CONFIG_NET** configuration option.3746 * Return3747 * Pointer to **struct bpf_sock**, or **NULL** in case of failure.3748 * For sockets with reuseport option, the **struct bpf_sock**3749 * result is from *reuse*\ **->socks**\ [] using the hash of the3750 * tuple.3751 *3752 * long bpf_sk_release(void *sock)3753 * Description3754 * Release the reference held by *sock*. *sock* must be a3755 * non-**NULL** pointer that was returned from3756 * **bpf_sk_lookup_xxx**\ ().3757 * Return3758 * 0 on success, or a negative error in case of failure.3759 *3760 * long bpf_map_push_elem(struct bpf_map *map, const void *value, u64 flags)3761 * Description3762 * Push an element *value* in *map*. *flags* is one of:3763 *3764 * **BPF_EXIST**3765 * If the queue/stack is full, the oldest element is3766 * removed to make room for this.3767 * Return3768 * 0 on success, or a negative error in case of failure.3769 *3770 * long bpf_map_pop_elem(struct bpf_map *map, void *value)3771 * Description3772 * Pop an element from *map*.3773 * Return3774 * 0 on success, or a negative error in case of failure.3775 *3776 * long bpf_map_peek_elem(struct bpf_map *map, void *value)3777 * Description3778 * Get an element from *map* without removing it.3779 * Return3780 * 0 on success, or a negative error in case of failure.3781 *3782 * long bpf_msg_push_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)3783 * Description3784 * For socket policies, insert *len* bytes into *msg* at offset3785 * *start*.3786 *3787 * If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a3788 * *msg* it may want to insert metadata or options into the *msg*.3789 * This can later be read and used by any of the lower layer BPF3790 * hooks.3791 *3792 * This helper may fail if under memory pressure (a malloc3793 * fails) in these cases BPF programs will get an appropriate3794 * error and BPF programs will need to handle them.3795 * Return3796 * 0 on success, or a negative error in case of failure.3797 *3798 * long bpf_msg_pop_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)3799 * Description3800 * Will remove *len* bytes from a *msg* starting at byte *start*.3801 * This may result in **ENOMEM** errors under certain situations if3802 * an allocation and copy are required due to a full ring buffer.3803 * However, the helper will try to avoid doing the allocation3804 * if possible. Other errors can occur if input parameters are3805 * invalid either due to *start* byte not being valid part of *msg*3806 * payload and/or *pop* value being to large.3807 * Return3808 * 0 on success, or a negative error in case of failure.3809 *3810 * long bpf_rc_pointer_rel(void *ctx, s32 rel_x, s32 rel_y)3811 * Description3812 * This helper is used in programs implementing IR decoding, to3813 * report a successfully decoded pointer movement.3814 *3815 * The *ctx* should point to the lirc sample as passed into3816 * the program.3817 *3818 * This helper is only available is the kernel was compiled with3819 * the **CONFIG_BPF_LIRC_MODE2** configuration option set to3820 * "**y**".3821 * Return3822 * 03823 *3824 * long bpf_spin_lock(struct bpf_spin_lock *lock)3825 * Description3826 * Acquire a spinlock represented by the pointer *lock*, which is3827 * stored as part of a value of a map. Taking the lock allows to3828 * safely update the rest of the fields in that value. The3829 * spinlock can (and must) later be released with a call to3830 * **bpf_spin_unlock**\ (\ *lock*\ ).3831 *3832 * Spinlocks in BPF programs come with a number of restrictions3833 * and constraints:3834 *3835 * * **bpf_spin_lock** objects are only allowed inside maps of3836 * types **BPF_MAP_TYPE_HASH** and **BPF_MAP_TYPE_ARRAY** (this3837 * list could be extended in the future).3838 * * BTF description of the map is mandatory.3839 * * The BPF program can take ONE lock at a time, since taking two3840 * or more could cause dead locks.3841 * * Only one **struct bpf_spin_lock** is allowed per map element.3842 * * When the lock is taken, calls (either BPF to BPF or helpers)3843 * are not allowed.3844 * * The **BPF_LD_ABS** and **BPF_LD_IND** instructions are not3845 * allowed inside a spinlock-ed region.3846 * * The BPF program MUST call **bpf_spin_unlock**\ () to release3847 * the lock, on all execution paths, before it returns.3848 * * The BPF program can access **struct bpf_spin_lock** only via3849 * the **bpf_spin_lock**\ () and **bpf_spin_unlock**\ ()3850 * helpers. Loading or storing data into the **struct3851 * bpf_spin_lock** *lock*\ **;** field of a map is not allowed.3852 * * To use the **bpf_spin_lock**\ () helper, the BTF description3853 * of the map value must be a struct and have **struct3854 * bpf_spin_lock** *anyname*\ **;** field at the top level.3855 * Nested lock inside another struct is not allowed.3856 * * The **struct bpf_spin_lock** *lock* field in a map value must3857 * be aligned on a multiple of 4 bytes in that value.3858 * * Syscall with command **BPF_MAP_LOOKUP_ELEM** does not copy3859 * the **bpf_spin_lock** field to user space.3860 * * Syscall with command **BPF_MAP_UPDATE_ELEM**, or update from3861 * a BPF program, do not update the **bpf_spin_lock** field.3862 * * **bpf_spin_lock** cannot be on the stack or inside a3863 * networking packet (it can only be inside of a map values).3864 * * **bpf_spin_lock** is available to root only.3865 * * Tracing programs and socket filter programs cannot use3866 * **bpf_spin_lock**\ () due to insufficient preemption checks3867 * (but this may change in the future).3868 * * **bpf_spin_lock** is not allowed in inner maps of map-in-map.3869 * Return3870 * 03871 *3872 * long bpf_spin_unlock(struct bpf_spin_lock *lock)3873 * Description3874 * Release the *lock* previously locked by a call to3875 * **bpf_spin_lock**\ (\ *lock*\ ).3876 * Return3877 * 03878 *3879 * struct bpf_sock *bpf_sk_fullsock(struct bpf_sock *sk)3880 * Description3881 * This helper gets a **struct bpf_sock** pointer such3882 * that all the fields in this **bpf_sock** can be accessed.3883 * Return3884 * A **struct bpf_sock** pointer on success, or **NULL** in3885 * case of failure.3886 *3887 * struct bpf_tcp_sock *bpf_tcp_sock(struct bpf_sock *sk)3888 * Description3889 * This helper gets a **struct bpf_tcp_sock** pointer from a3890 * **struct bpf_sock** pointer.3891 * Return3892 * A **struct bpf_tcp_sock** pointer on success, or **NULL** in3893 * case of failure.3894 *3895 * long bpf_skb_ecn_set_ce(struct sk_buff *skb)3896 * Description3897 * Set ECN (Explicit Congestion Notification) field of IP header3898 * to **CE** (Congestion Encountered) if current value is **ECT**3899 * (ECN Capable Transport). Otherwise, do nothing. Works with IPv63900 * and IPv4.3901 * Return3902 * 1 if the **CE** flag is set (either by the current helper call3903 * or because it was already present), 0 if it is not set.3904 *3905 * struct bpf_sock *bpf_get_listener_sock(struct bpf_sock *sk)3906 * Description3907 * Return a **struct bpf_sock** pointer in **TCP_LISTEN** state.3908 * **bpf_sk_release**\ () is unnecessary and not allowed.3909 * Return3910 * A **struct bpf_sock** pointer on success, or **NULL** in3911 * case of failure.3912 *3913 * struct bpf_sock *bpf_skc_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)3914 * Description3915 * Look for TCP socket matching *tuple*, optionally in a child3916 * network namespace *netns*. The return value must be checked,3917 * and if non-**NULL**, released via **bpf_sk_release**\ ().3918 *3919 * This function is identical to **bpf_sk_lookup_tcp**\ (), except3920 * that it also returns timewait or request sockets. Use3921 * **bpf_sk_fullsock**\ () or **bpf_tcp_sock**\ () to access the3922 * full structure.3923 *3924 * This helper is available only if the kernel was compiled with3925 * **CONFIG_NET** configuration option.3926 * Return3927 * Pointer to **struct bpf_sock**, or **NULL** in case of failure.3928 * For sockets with reuseport option, the **struct bpf_sock**3929 * result is from *reuse*\ **->socks**\ [] using the hash of the3930 * tuple.3931 *3932 * long bpf_tcp_check_syncookie(void *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)3933 * Description3934 * Check whether *iph* and *th* contain a valid SYN cookie ACK for3935 * the listening socket in *sk*.3936 *3937 * *iph* points to the start of the IPv4 or IPv6 header, while3938 * *iph_len* contains **sizeof**\ (**struct iphdr**) or3939 * **sizeof**\ (**struct ipv6hdr**).3940 *3941 * *th* points to the start of the TCP header, while *th_len*3942 * contains the length of the TCP header (at least3943 * **sizeof**\ (**struct tcphdr**)).3944 * Return3945 * 0 if *iph* and *th* are a valid SYN cookie ACK, or a negative3946 * error otherwise.3947 *3948 * long bpf_sysctl_get_name(struct bpf_sysctl *ctx, char *buf, size_t buf_len, u64 flags)3949 * Description3950 * Get name of sysctl in /proc/sys/ and copy it into provided by3951 * program buffer *buf* of size *buf_len*.3952 *3953 * The buffer is always NUL terminated, unless it's zero-sized.3954 *3955 * If *flags* is zero, full name (e.g. "net/ipv4/tcp_mem") is3956 * copied. Use **BPF_F_SYSCTL_BASE_NAME** flag to copy base name3957 * only (e.g. "tcp_mem").3958 * Return3959 * Number of character copied (not including the trailing NUL).3960 *3961 * **-E2BIG** if the buffer wasn't big enough (*buf* will contain3962 * truncated name in this case).3963 *3964 * long bpf_sysctl_get_current_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)3965 * Description3966 * Get current value of sysctl as it is presented in /proc/sys3967 * (incl. newline, etc), and copy it as a string into provided3968 * by program buffer *buf* of size *buf_len*.3969 *3970 * The whole value is copied, no matter what file position user3971 * space issued e.g. sys_read at.3972 *3973 * The buffer is always NUL terminated, unless it's zero-sized.3974 * Return3975 * Number of character copied (not including the trailing NUL).3976 *3977 * **-E2BIG** if the buffer wasn't big enough (*buf* will contain3978 * truncated name in this case).3979 *3980 * **-EINVAL** if current value was unavailable, e.g. because3981 * sysctl is uninitialized and read returns -EIO for it.3982 *3983 * long bpf_sysctl_get_new_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)3984 * Description3985 * Get new value being written by user space to sysctl (before3986 * the actual write happens) and copy it as a string into3987 * provided by program buffer *buf* of size *buf_len*.3988 *3989 * User space may write new value at file position > 0.3990 *3991 * The buffer is always NUL terminated, unless it's zero-sized.3992 * Return3993 * Number of character copied (not including the trailing NUL).3994 *3995 * **-E2BIG** if the buffer wasn't big enough (*buf* will contain3996 * truncated name in this case).3997 *3998 * **-EINVAL** if sysctl is being read.3999 *4000 * long bpf_sysctl_set_new_value(struct bpf_sysctl *ctx, const char *buf, size_t buf_len)4001 * Description4002 * Override new value being written by user space to sysctl with4003 * value provided by program in buffer *buf* of size *buf_len*.4004 *4005 * *buf* should contain a string in same form as provided by user4006 * space on sysctl write.4007 *4008 * User space may write new value at file position > 0. To override4009 * the whole sysctl value file position should be set to zero.4010 * Return4011 * 0 on success.4012 *4013 * **-E2BIG** if the *buf_len* is too big.4014 *4015 * **-EINVAL** if sysctl is being read.4016 *4017 * long bpf_strtol(const char *buf, size_t buf_len, u64 flags, long *res)4018 * Description4019 * Convert the initial part of the string from buffer *buf* of4020 * size *buf_len* to a long integer according to the given base4021 * and save the result in *res*.4022 *4023 * The string may begin with an arbitrary amount of white space4024 * (as determined by **isspace**\ (3)) followed by a single4025 * optional '**-**' sign.4026 *4027 * Five least significant bits of *flags* encode base, other bits4028 * are currently unused.4029 *4030 * Base must be either 8, 10, 16 or 0 to detect it automatically4031 * similar to user space **strtol**\ (3).4032 * Return4033 * Number of characters consumed on success. Must be positive but4034 * no more than *buf_len*.4035 *4036 * **-EINVAL** if no valid digits were found or unsupported base4037 * was provided.4038 *4039 * **-ERANGE** if resulting value was out of range.4040 *4041 * long bpf_strtoul(const char *buf, size_t buf_len, u64 flags, unsigned long *res)4042 * Description4043 * Convert the initial part of the string from buffer *buf* of4044 * size *buf_len* to an unsigned long integer according to the4045 * given base and save the result in *res*.4046 *4047 * The string may begin with an arbitrary amount of white space4048 * (as determined by **isspace**\ (3)).4049 *4050 * Five least significant bits of *flags* encode base, other bits4051 * are currently unused.4052 *4053 * Base must be either 8, 10, 16 or 0 to detect it automatically4054 * similar to user space **strtoul**\ (3).4055 * Return4056 * Number of characters consumed on success. Must be positive but4057 * no more than *buf_len*.4058 *4059 * **-EINVAL** if no valid digits were found or unsupported base4060 * was provided.4061 *4062 * **-ERANGE** if resulting value was out of range.4063 *4064 * void *bpf_sk_storage_get(struct bpf_map *map, void *sk, void *value, u64 flags)4065 * Description4066 * Get a bpf-local-storage from a *sk*.4067 *4068 * Logically, it could be thought of getting the value from4069 * a *map* with *sk* as the **key**. From this4070 * perspective, the usage is not much different from4071 * **bpf_map_lookup_elem**\ (*map*, **&**\ *sk*) except this4072 * helper enforces the key must be a full socket and the map must4073 * be a **BPF_MAP_TYPE_SK_STORAGE** also.4074 *4075 * Underneath, the value is stored locally at *sk* instead of4076 * the *map*. The *map* is used as the bpf-local-storage4077 * "type". The bpf-local-storage "type" (i.e. the *map*) is4078 * searched against all bpf-local-storages residing at *sk*.4079 *4080 * *sk* is a kernel **struct sock** pointer for LSM program.4081 * *sk* is a **struct bpf_sock** pointer for other program types.4082 *4083 * An optional *flags* (**BPF_SK_STORAGE_GET_F_CREATE**) can be4084 * used such that a new bpf-local-storage will be4085 * created if one does not exist. *value* can be used4086 * together with **BPF_SK_STORAGE_GET_F_CREATE** to specify4087 * the initial value of a bpf-local-storage. If *value* is4088 * **NULL**, the new bpf-local-storage will be zero initialized.4089 * Return4090 * A bpf-local-storage pointer is returned on success.4091 *4092 * **NULL** if not found or there was an error in adding4093 * a new bpf-local-storage.4094 *4095 * long bpf_sk_storage_delete(struct bpf_map *map, void *sk)4096 * Description4097 * Delete a bpf-local-storage from a *sk*.4098 * Return4099 * 0 on success.4100 *4101 * **-ENOENT** if the bpf-local-storage cannot be found.4102 * **-EINVAL** if sk is not a fullsock (e.g. a request_sock).4103 *4104 * long bpf_send_signal(u32 sig)4105 * Description4106 * Send signal *sig* to the process of the current task.4107 * The signal may be delivered to any of this process's threads.4108 * Return4109 * 0 on success or successfully queued.4110 *4111 * **-EBUSY** if work queue under nmi is full.4112 *4113 * **-EINVAL** if *sig* is invalid.4114 *4115 * **-EPERM** if no permission to send the *sig*.4116 *4117 * **-EAGAIN** if bpf program can try again.4118 *4119 * s64 bpf_tcp_gen_syncookie(void *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)4120 * Description4121 * Try to issue a SYN cookie for the packet with corresponding4122 * IP/TCP headers, *iph* and *th*, on the listening socket in *sk*.4123 *4124 * *iph* points to the start of the IPv4 or IPv6 header, while4125 * *iph_len* contains **sizeof**\ (**struct iphdr**) or4126 * **sizeof**\ (**struct ipv6hdr**).4127 *4128 * *th* points to the start of the TCP header, while *th_len*4129 * contains the length of the TCP header with options (at least4130 * **sizeof**\ (**struct tcphdr**)).4131 * Return4132 * On success, lower 32 bits hold the generated SYN cookie in4133 * followed by 16 bits which hold the MSS value for that cookie,4134 * and the top 16 bits are unused.4135 *4136 * On failure, the returned value is one of the following:4137 *4138 * **-EINVAL** SYN cookie cannot be issued due to error4139 *4140 * **-ENOENT** SYN cookie should not be issued (no SYN flood)4141 *4142 * **-EOPNOTSUPP** kernel configuration does not enable SYN cookies4143 *4144 * **-EPROTONOSUPPORT** IP packet version is not 4 or 64145 *4146 * long bpf_skb_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)4147 * Description4148 * Write raw *data* blob into a special BPF perf event held by4149 * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf4150 * event must have the following attributes: **PERF_SAMPLE_RAW**4151 * as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and4152 * **PERF_COUNT_SW_BPF_OUTPUT** as **config**.4153 *4154 * The *flags* are used to indicate the index in *map* for which4155 * the value must be put, masked with **BPF_F_INDEX_MASK**.4156 * Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**4157 * to indicate that the index of the current CPU core should be4158 * used.4159 *4160 * The value to write, of *size*, is passed through eBPF stack and4161 * pointed by *data*.4162 *4163 * *ctx* is a pointer to in-kernel struct sk_buff.4164 *4165 * This helper is similar to **bpf_perf_event_output**\ () but4166 * restricted to raw_tracepoint bpf programs.4167 * Return4168 * 0 on success, or a negative error in case of failure.4169 *4170 * long bpf_probe_read_user(void *dst, u32 size, const void *unsafe_ptr)4171 * Description4172 * Safely attempt to read *size* bytes from user space address4173 * *unsafe_ptr* and store the data in *dst*.4174 * Return4175 * 0 on success, or a negative error in case of failure.4176 *4177 * long bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)4178 * Description4179 * Safely attempt to read *size* bytes from kernel space address4180 * *unsafe_ptr* and store the data in *dst*.4181 * Return4182 * 0 on success, or a negative error in case of failure.4183 *4184 * long bpf_probe_read_user_str(void *dst, u32 size, const void *unsafe_ptr)4185 * Description4186 * Copy a NUL terminated string from an unsafe user address4187 * *unsafe_ptr* to *dst*. The *size* should include the4188 * terminating NUL byte. In case the string length is smaller than4189 * *size*, the target is not padded with further NUL bytes. If the4190 * string length is larger than *size*, just *size*-1 bytes are4191 * copied and the last byte is set to NUL.4192 *4193 * On success, returns the number of bytes that were written,4194 * including the terminal NUL. This makes this helper useful in4195 * tracing programs for reading strings, and more importantly to4196 * get its length at runtime. See the following snippet:4197 *4198 * ::4199 *4200 * SEC("kprobe/sys_open")4201 * void bpf_sys_open(struct pt_regs *ctx)4202 * {4203 * char buf[PATHLEN]; // PATHLEN is defined to 2564204 * int res = bpf_probe_read_user_str(buf, sizeof(buf),4205 * ctx->di);4206 *4207 * // Consume buf, for example push it to4208 * // userspace via bpf_perf_event_output(); we4209 * // can use res (the string length) as event4210 * // size, after checking its boundaries.4211 * }4212 *4213 * In comparison, using **bpf_probe_read_user**\ () helper here4214 * instead to read the string would require to estimate the length4215 * at compile time, and would often result in copying more memory4216 * than necessary.4217 *4218 * Another useful use case is when parsing individual process4219 * arguments or individual environment variables navigating4220 * *current*\ **->mm->arg_start** and *current*\4221 * **->mm->env_start**: using this helper and the return value,4222 * one can quickly iterate at the right offset of the memory area.4223 * Return4224 * On success, the strictly positive length of the output string,4225 * including the trailing NUL character. On error, a negative4226 * value.4227 *4228 * long bpf_probe_read_kernel_str(void *dst, u32 size, const void *unsafe_ptr)4229 * Description4230 * Copy a NUL terminated string from an unsafe kernel address *unsafe_ptr*4231 * to *dst*. Same semantics as with **bpf_probe_read_user_str**\ () apply.4232 * Return4233 * On success, the strictly positive length of the string, including4234 * the trailing NUL character. On error, a negative value.4235 *4236 * long bpf_tcp_send_ack(void *tp, u32 rcv_nxt)4237 * Description4238 * Send out a tcp-ack. *tp* is the in-kernel struct **tcp_sock**.4239 * *rcv_nxt* is the ack_seq to be sent out.4240 * Return4241 * 0 on success, or a negative error in case of failure.4242 *4243 * long bpf_send_signal_thread(u32 sig)4244 * Description4245 * Send signal *sig* to the thread corresponding to the current task.4246 * Return4247 * 0 on success or successfully queued.4248 *4249 * **-EBUSY** if work queue under nmi is full.4250 *4251 * **-EINVAL** if *sig* is invalid.4252 *4253 * **-EPERM** if no permission to send the *sig*.4254 *4255 * **-EAGAIN** if bpf program can try again.4256 *4257 * u64 bpf_jiffies64(void)4258 * Description4259 * Obtain the 64bit jiffies4260 * Return4261 * The 64 bit jiffies4262 *4263 * long bpf_read_branch_records(struct bpf_perf_event_data *ctx, void *buf, u32 size, u64 flags)4264 * Description4265 * For an eBPF program attached to a perf event, retrieve the4266 * branch records (**struct perf_branch_entry**) associated to *ctx*4267 * and store it in the buffer pointed by *buf* up to size4268 * *size* bytes.4269 * Return4270 * On success, number of bytes written to *buf*. On error, a4271 * negative value.4272 *4273 * The *flags* can be set to **BPF_F_GET_BRANCH_RECORDS_SIZE** to4274 * instead return the number of bytes required to store all the4275 * branch entries. If this flag is set, *buf* may be NULL.4276 *4277 * **-EINVAL** if arguments invalid or **size** not a multiple4278 * of **sizeof**\ (**struct perf_branch_entry**\ ).4279 *4280 * **-ENOENT** if architecture does not support branch records.4281 *4282 * long bpf_get_ns_current_pid_tgid(u64 dev, u64 ino, struct bpf_pidns_info *nsdata, u32 size)4283 * Description4284 * Returns 0 on success, values for *pid* and *tgid* as seen from the current4285 * *namespace* will be returned in *nsdata*.4286 * Return4287 * 0 on success, or one of the following in case of failure:4288 *4289 * **-EINVAL** if dev and inum supplied don't match dev_t and inode number4290 * with nsfs of current task, or if dev conversion to dev_t lost high bits.4291 *4292 * **-ENOENT** if pidns does not exists for the current task.4293 *4294 * long bpf_xdp_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)4295 * Description4296 * Write raw *data* blob into a special BPF perf event held by4297 * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf4298 * event must have the following attributes: **PERF_SAMPLE_RAW**4299 * as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and4300 * **PERF_COUNT_SW_BPF_OUTPUT** as **config**.4301 *4302 * The *flags* are used to indicate the index in *map* for which4303 * the value must be put, masked with **BPF_F_INDEX_MASK**.4304 * Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**4305 * to indicate that the index of the current CPU core should be4306 * used.4307 *4308 * The value to write, of *size*, is passed through eBPF stack and4309 * pointed by *data*.4310 *4311 * *ctx* is a pointer to in-kernel struct xdp_buff.4312 *4313 * This helper is similar to **bpf_perf_eventoutput**\ () but4314 * restricted to raw_tracepoint bpf programs.4315 * Return4316 * 0 on success, or a negative error in case of failure.4317 *4318 * u64 bpf_get_netns_cookie(void *ctx)4319 * Description4320 * Retrieve the cookie (generated by the kernel) of the network4321 * namespace the input *ctx* is associated with. The network4322 * namespace cookie remains stable for its lifetime and provides4323 * a global identifier that can be assumed unique. If *ctx* is4324 * NULL, then the helper returns the cookie for the initial4325 * network namespace. The cookie itself is very similar to that4326 * of **bpf_get_socket_cookie**\ () helper, but for network4327 * namespaces instead of sockets.4328 * Return4329 * A 8-byte long opaque number.4330 *4331 * u64 bpf_get_current_ancestor_cgroup_id(int ancestor_level)4332 * Description4333 * Return id of cgroup v2 that is ancestor of the cgroup associated4334 * with the current task at the *ancestor_level*. The root cgroup4335 * is at *ancestor_level* zero and each step down the hierarchy4336 * increments the level. If *ancestor_level* == level of cgroup4337 * associated with the current task, then return value will be the4338 * same as that of **bpf_get_current_cgroup_id**\ ().4339 *4340 * The helper is useful to implement policies based on cgroups4341 * that are upper in hierarchy than immediate cgroup associated4342 * with the current task.4343 *4344 * The format of returned id and helper limitations are same as in4345 * **bpf_get_current_cgroup_id**\ ().4346 * Return4347 * The id is returned or 0 in case the id could not be retrieved.4348 *4349 * long bpf_sk_assign(struct sk_buff *skb, void *sk, u64 flags)4350 * Description4351 * Helper is overloaded depending on BPF program type. This4352 * description applies to **BPF_PROG_TYPE_SCHED_CLS** and4353 * **BPF_PROG_TYPE_SCHED_ACT** programs.4354 *4355 * Assign the *sk* to the *skb*. When combined with appropriate4356 * routing configuration to receive the packet towards the socket,4357 * will cause *skb* to be delivered to the specified socket.4358 * Subsequent redirection of *skb* via **bpf_redirect**\ (),4359 * **bpf_clone_redirect**\ () or other methods outside of BPF may4360 * interfere with successful delivery to the socket.4361 *4362 * This operation is only valid from TC ingress path.4363 *4364 * The *flags* argument must be zero.4365 * Return4366 * 0 on success, or a negative error in case of failure:4367 *4368 * **-EINVAL** if specified *flags* are not supported.4369 *4370 * **-ENOENT** if the socket is unavailable for assignment.4371 *4372 * **-ENETUNREACH** if the socket is unreachable (wrong netns).4373 *4374 * **-EOPNOTSUPP** if the operation is not supported, for example4375 * a call from outside of TC ingress.4376 *4377 * long bpf_sk_assign(struct bpf_sk_lookup *ctx, struct bpf_sock *sk, u64 flags)4378 * Description4379 * Helper is overloaded depending on BPF program type. This4380 * description applies to **BPF_PROG_TYPE_SK_LOOKUP** programs.4381 *4382 * Select the *sk* as a result of a socket lookup.4383 *4384 * For the operation to succeed passed socket must be compatible4385 * with the packet description provided by the *ctx* object.4386 *4387 * L4 protocol (**IPPROTO_TCP** or **IPPROTO_UDP**) must4388 * be an exact match. While IP family (**AF_INET** or4389 * **AF_INET6**) must be compatible, that is IPv6 sockets4390 * that are not v6-only can be selected for IPv4 packets.4391 *4392 * Only TCP listeners and UDP unconnected sockets can be4393 * selected. *sk* can also be NULL to reset any previous4394 * selection.4395 *4396 * *flags* argument can combination of following values:4397 *4398 * * **BPF_SK_LOOKUP_F_REPLACE** to override the previous4399 * socket selection, potentially done by a BPF program4400 * that ran before us.4401 *4402 * * **BPF_SK_LOOKUP_F_NO_REUSEPORT** to skip4403 * load-balancing within reuseport group for the socket4404 * being selected.4405 *4406 * On success *ctx->sk* will point to the selected socket.4407 *4408 * Return4409 * 0 on success, or a negative errno in case of failure.4410 *4411 * * **-EAFNOSUPPORT** if socket family (*sk->family*) is4412 * not compatible with packet family (*ctx->family*).4413 *4414 * * **-EEXIST** if socket has been already selected,4415 * potentially by another program, and4416 * **BPF_SK_LOOKUP_F_REPLACE** flag was not specified.4417 *4418 * * **-EINVAL** if unsupported flags were specified.4419 *4420 * * **-EPROTOTYPE** if socket L4 protocol4421 * (*sk->protocol*) doesn't match packet protocol4422 * (*ctx->protocol*).4423 *4424 * * **-ESOCKTNOSUPPORT** if socket is not in allowed4425 * state (TCP listening or UDP unconnected).4426 *4427 * u64 bpf_ktime_get_boot_ns(void)4428 * Description4429 * Return the time elapsed since system boot, in nanoseconds.4430 * Does include the time the system was suspended.4431 * See: **clock_gettime**\ (**CLOCK_BOOTTIME**)4432 * Return4433 * Current *ktime*.4434 *4435 * long bpf_seq_printf(struct seq_file *m, const char *fmt, u32 fmt_size, const void *data, u32 data_len)4436 * Description4437 * **bpf_seq_printf**\ () uses seq_file **seq_printf**\ () to print4438 * out the format string.4439 * The *m* represents the seq_file. The *fmt* and *fmt_size* are for4440 * the format string itself. The *data* and *data_len* are format string4441 * arguments. The *data* are a **u64** array and corresponding format string4442 * values are stored in the array. For strings and pointers where pointees4443 * are accessed, only the pointer values are stored in the *data* array.4444 * The *data_len* is the size of *data* in bytes - must be a multiple of 8.4445 *4446 * Formats **%s**, **%p{i,I}{4,6}** requires to read kernel memory.4447 * Reading kernel memory may fail due to either invalid address or4448 * valid address but requiring a major memory fault. If reading kernel memory4449 * fails, the string for **%s** will be an empty string, and the ip4450 * address for **%p{i,I}{4,6}** will be 0. Not returning error to4451 * bpf program is consistent with what **bpf_trace_printk**\ () does for now.4452 * Return4453 * 0 on success, or a negative error in case of failure:4454 *4455 * **-EBUSY** if per-CPU memory copy buffer is busy, can try again4456 * by returning 1 from bpf program.4457 *4458 * **-EINVAL** if arguments are invalid, or if *fmt* is invalid/unsupported.4459 *4460 * **-E2BIG** if *fmt* contains too many format specifiers.4461 *4462 * **-EOVERFLOW** if an overflow happened: The same object will be tried again.4463 *4464 * long bpf_seq_write(struct seq_file *m, const void *data, u32 len)4465 * Description4466 * **bpf_seq_write**\ () uses seq_file **seq_write**\ () to write the data.4467 * The *m* represents the seq_file. The *data* and *len* represent the4468 * data to write in bytes.4469 * Return4470 * 0 on success, or a negative error in case of failure:4471 *4472 * **-EOVERFLOW** if an overflow happened: The same object will be tried again.4473 *4474 * u64 bpf_sk_cgroup_id(void *sk)4475 * Description4476 * Return the cgroup v2 id of the socket *sk*.4477 *4478 * *sk* must be a non-**NULL** pointer to a socket, e.g. one4479 * returned from **bpf_sk_lookup_xxx**\ (),4480 * **bpf_sk_fullsock**\ (), etc. The format of returned id is4481 * same as in **bpf_skb_cgroup_id**\ ().4482 *4483 * This helper is available only if the kernel was compiled with4484 * the **CONFIG_SOCK_CGROUP_DATA** configuration option.4485 * Return4486 * The id is returned or 0 in case the id could not be retrieved.4487 *4488 * u64 bpf_sk_ancestor_cgroup_id(void *sk, int ancestor_level)4489 * Description4490 * Return id of cgroup v2 that is ancestor of cgroup associated4491 * with the *sk* at the *ancestor_level*. The root cgroup is at4492 * *ancestor_level* zero and each step down the hierarchy4493 * increments the level. If *ancestor_level* == level of cgroup4494 * associated with *sk*, then return value will be same as that4495 * of **bpf_sk_cgroup_id**\ ().4496 *4497 * The helper is useful to implement policies based on cgroups4498 * that are upper in hierarchy than immediate cgroup associated4499 * with *sk*.4500 *4501 * The format of returned id and helper limitations are same as in4502 * **bpf_sk_cgroup_id**\ ().4503 * Return4504 * The id is returned or 0 in case the id could not be retrieved.4505 *4506 * long bpf_ringbuf_output(void *ringbuf, void *data, u64 size, u64 flags)4507 * Description4508 * Copy *size* bytes from *data* into a ring buffer *ringbuf*.4509 * If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification4510 * of new data availability is sent.4511 * If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification4512 * of new data availability is sent unconditionally.4513 * If **0** is specified in *flags*, an adaptive notification4514 * of new data availability is sent.4515 *4516 * An adaptive notification is a notification sent whenever the user-space4517 * process has caught up and consumed all available payloads. In case the user-space4518 * process is still processing a previous payload, then no notification is needed4519 * as it will process the newly added payload automatically.4520 * Return4521 * 0 on success, or a negative error in case of failure.4522 *4523 * void *bpf_ringbuf_reserve(void *ringbuf, u64 size, u64 flags)4524 * Description4525 * Reserve *size* bytes of payload in a ring buffer *ringbuf*.4526 * *flags* must be 0.4527 * Return4528 * Valid pointer with *size* bytes of memory available; NULL,4529 * otherwise.4530 *4531 * void bpf_ringbuf_submit(void *data, u64 flags)4532 * Description4533 * Submit reserved ring buffer sample, pointed to by *data*.4534 * If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification4535 * of new data availability is sent.4536 * If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification4537 * of new data availability is sent unconditionally.4538 * If **0** is specified in *flags*, an adaptive notification4539 * of new data availability is sent.4540 *4541 * See 'bpf_ringbuf_output()' for the definition of adaptive notification.4542 * Return4543 * Nothing. Always succeeds.4544 *4545 * void bpf_ringbuf_discard(void *data, u64 flags)4546 * Description4547 * Discard reserved ring buffer sample, pointed to by *data*.4548 * If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification4549 * of new data availability is sent.4550 * If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification4551 * of new data availability is sent unconditionally.4552 * If **0** is specified in *flags*, an adaptive notification4553 * of new data availability is sent.4554 *4555 * See 'bpf_ringbuf_output()' for the definition of adaptive notification.4556 * Return4557 * Nothing. Always succeeds.4558 *4559 * u64 bpf_ringbuf_query(void *ringbuf, u64 flags)4560 * Description4561 * Query various characteristics of provided ring buffer. What4562 * exactly is queries is determined by *flags*:4563 *4564 * * **BPF_RB_AVAIL_DATA**: Amount of data not yet consumed.4565 * * **BPF_RB_RING_SIZE**: The size of ring buffer.4566 * * **BPF_RB_CONS_POS**: Consumer position (can wrap around).4567 * * **BPF_RB_PROD_POS**: Producer(s) position (can wrap around).4568 *4569 * Data returned is just a momentary snapshot of actual values4570 * and could be inaccurate, so this facility should be used to4571 * power heuristics and for reporting, not to make 100% correct4572 * calculation.4573 * Return4574 * Requested value, or 0, if *flags* are not recognized.4575 *4576 * long bpf_csum_level(struct sk_buff *skb, u64 level)4577 * Description4578 * Change the skbs checksum level by one layer up or down, or4579 * reset it entirely to none in order to have the stack perform4580 * checksum validation. The level is applicable to the following4581 * protocols: TCP, UDP, GRE, SCTP, FCOE. For example, a decap of4582 * | ETH | IP | UDP | GUE | IP | TCP | into | ETH | IP | TCP |4583 * through **bpf_skb_adjust_room**\ () helper with passing in4584 * **BPF_F_ADJ_ROOM_NO_CSUM_RESET** flag would require one call4585 * to **bpf_csum_level**\ () with **BPF_CSUM_LEVEL_DEC** since4586 * the UDP header is removed. Similarly, an encap of the latter4587 * into the former could be accompanied by a helper call to4588 * **bpf_csum_level**\ () with **BPF_CSUM_LEVEL_INC** if the4589 * skb is still intended to be processed in higher layers of the4590 * stack instead of just egressing at tc.4591 *4592 * There are three supported level settings at this time:4593 *4594 * * **BPF_CSUM_LEVEL_INC**: Increases skb->csum_level for skbs4595 * with CHECKSUM_UNNECESSARY.4596 * * **BPF_CSUM_LEVEL_DEC**: Decreases skb->csum_level for skbs4597 * with CHECKSUM_UNNECESSARY.4598 * * **BPF_CSUM_LEVEL_RESET**: Resets skb->csum_level to 0 and4599 * sets CHECKSUM_NONE to force checksum validation by the stack.4600 * * **BPF_CSUM_LEVEL_QUERY**: No-op, returns the current4601 * skb->csum_level.4602 * Return4603 * 0 on success, or a negative error in case of failure. In the4604 * case of **BPF_CSUM_LEVEL_QUERY**, the current skb->csum_level4605 * is returned or the error code -EACCES in case the skb is not4606 * subject to CHECKSUM_UNNECESSARY.4607 *4608 * struct tcp6_sock *bpf_skc_to_tcp6_sock(void *sk)4609 * Description4610 * Dynamically cast a *sk* pointer to a *tcp6_sock* pointer.4611 * Return4612 * *sk* if casting is valid, or **NULL** otherwise.4613 *4614 * struct tcp_sock *bpf_skc_to_tcp_sock(void *sk)4615 * Description4616 * Dynamically cast a *sk* pointer to a *tcp_sock* pointer.4617 * Return4618 * *sk* if casting is valid, or **NULL** otherwise.4619 *4620 * struct tcp_timewait_sock *bpf_skc_to_tcp_timewait_sock(void *sk)4621 * Description4622 * Dynamically cast a *sk* pointer to a *tcp_timewait_sock* pointer.4623 * Return4624 * *sk* if casting is valid, or **NULL** otherwise.4625 *4626 * struct tcp_request_sock *bpf_skc_to_tcp_request_sock(void *sk)4627 * Description4628 * Dynamically cast a *sk* pointer to a *tcp_request_sock* pointer.4629 * Return4630 * *sk* if casting is valid, or **NULL** otherwise.4631 *4632 * struct udp6_sock *bpf_skc_to_udp6_sock(void *sk)4633 * Description4634 * Dynamically cast a *sk* pointer to a *udp6_sock* pointer.4635 * Return4636 * *sk* if casting is valid, or **NULL** otherwise.4637 *4638 * long bpf_get_task_stack(struct task_struct *task, void *buf, u32 size, u64 flags)4639 * Description4640 * Return a user or a kernel stack in bpf program provided buffer.4641 * Note: the user stack will only be populated if the *task* is4642 * the current task; all other tasks will return -EOPNOTSUPP.4643 * To achieve this, the helper needs *task*, which is a valid4644 * pointer to **struct task_struct**. To store the stacktrace, the4645 * bpf program provides *buf* with a nonnegative *size*.4646 *4647 * The last argument, *flags*, holds the number of stack frames to4648 * skip (from 0 to 255), masked with4649 * **BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set4650 * the following flags:4651 *4652 * **BPF_F_USER_STACK**4653 * Collect a user space stack instead of a kernel stack.4654 * The *task* must be the current task.4655 * **BPF_F_USER_BUILD_ID**4656 * Collect buildid+offset instead of ips for user stack,4657 * only valid if **BPF_F_USER_STACK** is also specified.4658 *4659 * **bpf_get_task_stack**\ () can collect up to4660 * **PERF_MAX_STACK_DEPTH** both kernel and user frames, subject4661 * to sufficient large buffer size. Note that4662 * this limit can be controlled with the **sysctl** program, and4663 * that it should be manually increased in order to profile long4664 * user stacks (such as stacks for Java programs). To do so, use:4665 *4666 * ::4667 *4668 * # sysctl kernel.perf_event_max_stack=<new value>4669 * Return4670 * The non-negative copied *buf* length equal to or less than4671 * *size* on success, or a negative error in case of failure.4672 *4673 * long bpf_load_hdr_opt(struct bpf_sock_ops *skops, void *searchby_res, u32 len, u64 flags)4674 * Description4675 * Load header option. Support reading a particular TCP header4676 * option for bpf program (**BPF_PROG_TYPE_SOCK_OPS**).4677 *4678 * If *flags* is 0, it will search the option from the4679 * *skops*\ **->skb_data**. The comment in **struct bpf_sock_ops**4680 * has details on what skb_data contains under different4681 * *skops*\ **->op**.4682 *4683 * The first byte of the *searchby_res* specifies the4684 * kind that it wants to search.4685 *4686 * If the searching kind is an experimental kind4687 * (i.e. 253 or 254 according to RFC6994). It also4688 * needs to specify the "magic" which is either4689 * 2 bytes or 4 bytes. It then also needs to4690 * specify the size of the magic by using4691 * the 2nd byte which is "kind-length" of a TCP4692 * header option and the "kind-length" also4693 * includes the first 2 bytes "kind" and "kind-length"4694 * itself as a normal TCP header option also does.4695 *4696 * For example, to search experimental kind 254 with4697 * 2 byte magic 0xeB9F, the searchby_res should be4698 * [ 254, 4, 0xeB, 0x9F, 0, 0, .... 0 ].4699 *4700 * To search for the standard window scale option (3),4701 * the *searchby_res* should be [ 3, 0, 0, .... 0 ].4702 * Note, kind-length must be 0 for regular option.4703 *4704 * Searching for No-Op (0) and End-of-Option-List (1) are4705 * not supported.4706 *4707 * *len* must be at least 2 bytes which is the minimal size4708 * of a header option.4709 *4710 * Supported flags:4711 *4712 * * **BPF_LOAD_HDR_OPT_TCP_SYN** to search from the4713 * saved_syn packet or the just-received syn packet.4714 *4715 * Return4716 * > 0 when found, the header option is copied to *searchby_res*.4717 * The return value is the total length copied. On failure, a4718 * negative error code is returned:4719 *4720 * **-EINVAL** if a parameter is invalid.4721 *4722 * **-ENOMSG** if the option is not found.4723 *4724 * **-ENOENT** if no syn packet is available when4725 * **BPF_LOAD_HDR_OPT_TCP_SYN** is used.4726 *4727 * **-ENOSPC** if there is not enough space. Only *len* number of4728 * bytes are copied.4729 *4730 * **-EFAULT** on failure to parse the header options in the4731 * packet.4732 *4733 * **-EPERM** if the helper cannot be used under the current4734 * *skops*\ **->op**.4735 *4736 * long bpf_store_hdr_opt(struct bpf_sock_ops *skops, const void *from, u32 len, u64 flags)4737 * Description4738 * Store header option. The data will be copied4739 * from buffer *from* with length *len* to the TCP header.4740 *4741 * The buffer *from* should have the whole option that4742 * includes the kind, kind-length, and the actual4743 * option data. The *len* must be at least kind-length4744 * long. The kind-length does not have to be 4 byte4745 * aligned. The kernel will take care of the padding4746 * and setting the 4 bytes aligned value to th->doff.4747 *4748 * This helper will check for duplicated option4749 * by searching the same option in the outgoing skb.4750 *4751 * This helper can only be called during4752 * **BPF_SOCK_OPS_WRITE_HDR_OPT_CB**.4753 *4754 * Return4755 * 0 on success, or negative error in case of failure:4756 *4757 * **-EINVAL** If param is invalid.4758 *4759 * **-ENOSPC** if there is not enough space in the header.4760 * Nothing has been written4761 *4762 * **-EEXIST** if the option already exists.4763 *4764 * **-EFAULT** on failure to parse the existing header options.4765 *4766 * **-EPERM** if the helper cannot be used under the current4767 * *skops*\ **->op**.4768 *4769 * long bpf_reserve_hdr_opt(struct bpf_sock_ops *skops, u32 len, u64 flags)4770 * Description4771 * Reserve *len* bytes for the bpf header option. The4772 * space will be used by **bpf_store_hdr_opt**\ () later in4773 * **BPF_SOCK_OPS_WRITE_HDR_OPT_CB**.4774 *4775 * If **bpf_reserve_hdr_opt**\ () is called multiple times,4776 * the total number of bytes will be reserved.4777 *4778 * This helper can only be called during4779 * **BPF_SOCK_OPS_HDR_OPT_LEN_CB**.4780 *4781 * Return4782 * 0 on success, or negative error in case of failure:4783 *4784 * **-EINVAL** if a parameter is invalid.4785 *4786 * **-ENOSPC** if there is not enough space in the header.4787 *4788 * **-EPERM** if the helper cannot be used under the current4789 * *skops*\ **->op**.4790 *4791 * void *bpf_inode_storage_get(struct bpf_map *map, void *inode, void *value, u64 flags)4792 * Description4793 * Get a bpf_local_storage from an *inode*.4794 *4795 * Logically, it could be thought of as getting the value from4796 * a *map* with *inode* as the **key**. From this4797 * perspective, the usage is not much different from4798 * **bpf_map_lookup_elem**\ (*map*, **&**\ *inode*) except this4799 * helper enforces the key must be an inode and the map must also4800 * be a **BPF_MAP_TYPE_INODE_STORAGE**.4801 *4802 * Underneath, the value is stored locally at *inode* instead of4803 * the *map*. The *map* is used as the bpf-local-storage4804 * "type". The bpf-local-storage "type" (i.e. the *map*) is4805 * searched against all bpf_local_storage residing at *inode*.4806 *4807 * An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be4808 * used such that a new bpf_local_storage will be4809 * created if one does not exist. *value* can be used4810 * together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify4811 * the initial value of a bpf_local_storage. If *value* is4812 * **NULL**, the new bpf_local_storage will be zero initialized.4813 * Return4814 * A bpf_local_storage pointer is returned on success.4815 *4816 * **NULL** if not found or there was an error in adding4817 * a new bpf_local_storage.4818 *4819 * int bpf_inode_storage_delete(struct bpf_map *map, void *inode)4820 * Description4821 * Delete a bpf_local_storage from an *inode*.4822 * Return4823 * 0 on success.4824 *4825 * **-ENOENT** if the bpf_local_storage cannot be found.4826 *4827 * long bpf_d_path(struct path *path, char *buf, u32 sz)4828 * Description4829 * Return full path for given **struct path** object, which4830 * needs to be the kernel BTF *path* object. The path is4831 * returned in the provided buffer *buf* of size *sz* and4832 * is zero terminated.4833 *4834 * Return4835 * On success, the strictly positive length of the string,4836 * including the trailing NUL character. On error, a negative4837 * value.4838 *4839 * long bpf_copy_from_user(void *dst, u32 size, const void *user_ptr)4840 * Description4841 * Read *size* bytes from user space address *user_ptr* and store4842 * the data in *dst*. This is a wrapper of **copy_from_user**\ ().4843 * Return4844 * 0 on success, or a negative error in case of failure.4845 *4846 * long bpf_snprintf_btf(char *str, u32 str_size, struct btf_ptr *ptr, u32 btf_ptr_size, u64 flags)4847 * Description4848 * Use BTF to store a string representation of *ptr*->ptr in *str*,4849 * using *ptr*->type_id. This value should specify the type4850 * that *ptr*->ptr points to. LLVM __builtin_btf_type_id(type, 1)4851 * can be used to look up vmlinux BTF type ids. Traversing the4852 * data structure using BTF, the type information and values are4853 * stored in the first *str_size* - 1 bytes of *str*. Safe copy of4854 * the pointer data is carried out to avoid kernel crashes during4855 * operation. Smaller types can use string space on the stack;4856 * larger programs can use map data to store the string4857 * representation.4858 *4859 * The string can be subsequently shared with userspace via4860 * bpf_perf_event_output() or ring buffer interfaces.4861 * bpf_trace_printk() is to be avoided as it places too small4862 * a limit on string size to be useful.4863 *4864 * *flags* is a combination of4865 *4866 * **BTF_F_COMPACT**4867 * no formatting around type information4868 * **BTF_F_NONAME**4869 * no struct/union member names/types4870 * **BTF_F_PTR_RAW**4871 * show raw (unobfuscated) pointer values;4872 * equivalent to printk specifier %px.4873 * **BTF_F_ZERO**4874 * show zero-valued struct/union members; they4875 * are not displayed by default4876 *4877 * Return4878 * The number of bytes that were written (or would have been4879 * written if output had to be truncated due to string size),4880 * or a negative error in cases of failure.4881 *4882 * long bpf_seq_printf_btf(struct seq_file *m, struct btf_ptr *ptr, u32 ptr_size, u64 flags)4883 * Description4884 * Use BTF to write to seq_write a string representation of4885 * *ptr*->ptr, using *ptr*->type_id as per bpf_snprintf_btf().4886 * *flags* are identical to those used for bpf_snprintf_btf.4887 * Return4888 * 0 on success or a negative error in case of failure.4889 *4890 * u64 bpf_skb_cgroup_classid(struct sk_buff *skb)4891 * Description4892 * See **bpf_get_cgroup_classid**\ () for the main description.4893 * This helper differs from **bpf_get_cgroup_classid**\ () in that4894 * the cgroup v1 net_cls class is retrieved only from the *skb*'s4895 * associated socket instead of the current process.4896 * Return4897 * The id is returned or 0 in case the id could not be retrieved.4898 *4899 * long bpf_redirect_neigh(u32 ifindex, struct bpf_redir_neigh *params, int plen, u64 flags)4900 * Description4901 * Redirect the packet to another net device of index *ifindex*4902 * and fill in L2 addresses from neighboring subsystem. This helper4903 * is somewhat similar to **bpf_redirect**\ (), except that it4904 * populates L2 addresses as well, meaning, internally, the helper4905 * relies on the neighbor lookup for the L2 address of the nexthop.4906 *4907 * The helper will perform a FIB lookup based on the skb's4908 * networking header to get the address of the next hop, unless4909 * this is supplied by the caller in the *params* argument. The4910 * *plen* argument indicates the len of *params* and should be set4911 * to 0 if *params* is NULL.4912 *4913 * The *flags* argument is reserved and must be 0. The helper is4914 * currently only supported for tc BPF program types, and enabled4915 * for IPv4 and IPv6 protocols.4916 * Return4917 * The helper returns **TC_ACT_REDIRECT** on success or4918 * **TC_ACT_SHOT** on error.4919 *4920 * void *bpf_per_cpu_ptr(const void *percpu_ptr, u32 cpu)4921 * Description4922 * Take a pointer to a percpu ksym, *percpu_ptr*, and return a4923 * pointer to the percpu kernel variable on *cpu*. A ksym is an4924 * extern variable decorated with '__ksym'. For ksym, there is a4925 * global var (either static or global) defined of the same name4926 * in the kernel. The ksym is percpu if the global var is percpu.4927 * The returned pointer points to the global percpu var on *cpu*.4928 *4929 * bpf_per_cpu_ptr() has the same semantic as per_cpu_ptr() in the4930 * kernel, except that bpf_per_cpu_ptr() may return NULL. This4931 * happens if *cpu* is larger than nr_cpu_ids. The caller of4932 * bpf_per_cpu_ptr() must check the returned value.4933 * Return4934 * A pointer pointing to the kernel percpu variable on *cpu*, or4935 * NULL, if *cpu* is invalid.4936 *4937 * void *bpf_this_cpu_ptr(const void *percpu_ptr)4938 * Description4939 * Take a pointer to a percpu ksym, *percpu_ptr*, and return a4940 * pointer to the percpu kernel variable on this cpu. See the4941 * description of 'ksym' in **bpf_per_cpu_ptr**\ ().4942 *4943 * bpf_this_cpu_ptr() has the same semantic as this_cpu_ptr() in4944 * the kernel. Different from **bpf_per_cpu_ptr**\ (), it would4945 * never return NULL.4946 * Return4947 * A pointer pointing to the kernel percpu variable on this cpu.4948 *4949 * long bpf_redirect_peer(u32 ifindex, u64 flags)4950 * Description4951 * Redirect the packet to another net device of index *ifindex*.4952 * This helper is somewhat similar to **bpf_redirect**\ (), except4953 * that the redirection happens to the *ifindex*' peer device and4954 * the netns switch takes place from ingress to ingress without4955 * going through the CPU's backlog queue.4956 *4957 * The *flags* argument is reserved and must be 0. The helper is4958 * currently only supported for tc BPF program types at the4959 * ingress hook and for veth and netkit target device types. The4960 * peer device must reside in a different network namespace.4961 * Return4962 * The helper returns **TC_ACT_REDIRECT** on success or4963 * **TC_ACT_SHOT** on error.4964 *4965 * void *bpf_task_storage_get(struct bpf_map *map, struct task_struct *task, void *value, u64 flags)4966 * Description4967 * Get a bpf_local_storage from the *task*.4968 *4969 * Logically, it could be thought of as getting the value from4970 * a *map* with *task* as the **key**. From this4971 * perspective, the usage is not much different from4972 * **bpf_map_lookup_elem**\ (*map*, **&**\ *task*) except this4973 * helper enforces the key must be a task_struct and the map must also4974 * be a **BPF_MAP_TYPE_TASK_STORAGE**.4975 *4976 * Underneath, the value is stored locally at *task* instead of4977 * the *map*. The *map* is used as the bpf-local-storage4978 * "type". The bpf-local-storage "type" (i.e. the *map*) is4979 * searched against all bpf_local_storage residing at *task*.4980 *4981 * An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be4982 * used such that a new bpf_local_storage will be4983 * created if one does not exist. *value* can be used4984 * together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify4985 * the initial value of a bpf_local_storage. If *value* is4986 * **NULL**, the new bpf_local_storage will be zero initialized.4987 * Return4988 * A bpf_local_storage pointer is returned on success.4989 *4990 * **NULL** if not found or there was an error in adding4991 * a new bpf_local_storage.4992 *4993 * long bpf_task_storage_delete(struct bpf_map *map, struct task_struct *task)4994 * Description4995 * Delete a bpf_local_storage from a *task*.4996 * Return4997 * 0 on success.4998 *4999 * **-ENOENT** if the bpf_local_storage cannot be found.5000 *5001 * struct task_struct *bpf_get_current_task_btf(void)5002 * Description5003 * Return a BTF pointer to the "current" task.5004 * This pointer can also be used in helpers that accept an5005 * *ARG_PTR_TO_BTF_ID* of type *task_struct*.5006 * Return5007 * Pointer to the current task.5008 *5009 * long bpf_bprm_opts_set(struct linux_binprm *bprm, u64 flags)5010 * Description5011 * Set or clear certain options on *bprm*:5012 *5013 * **BPF_F_BPRM_SECUREEXEC** Set the secureexec bit5014 * which sets the **AT_SECURE** auxv for glibc. The bit5015 * is cleared if the flag is not specified.5016 * Return5017 * **-EINVAL** if invalid *flags* are passed, zero otherwise.5018 *5019 * u64 bpf_ktime_get_coarse_ns(void)5020 * Description5021 * Return a coarse-grained version of the time elapsed since5022 * system boot, in nanoseconds. Does not include time the system5023 * was suspended.5024 *5025 * See: **clock_gettime**\ (**CLOCK_MONOTONIC_COARSE**)5026 * Return5027 * Current *ktime*.5028 *5029 * long bpf_ima_inode_hash(struct inode *inode, void *dst, u32 size)5030 * Description5031 * Returns the stored IMA hash of the *inode* (if it's available).5032 * If the hash is larger than *size*, then only *size*5033 * bytes will be copied to *dst*5034 * Return5035 * The **hash_algo** is returned on success,5036 * **-EOPNOTSUPP** if IMA is disabled or **-EINVAL** if5037 * invalid arguments are passed.5038 *5039 * struct socket *bpf_sock_from_file(struct file *file)5040 * Description5041 * If the given file represents a socket, returns the associated5042 * socket.5043 * Return5044 * A pointer to a struct socket on success or NULL if the file is5045 * not a socket.5046 *5047 * long bpf_check_mtu(void *ctx, u32 ifindex, u32 *mtu_len, s32 len_diff, u64 flags)5048 * Description5049 * Check packet size against exceeding MTU of net device (based5050 * on *ifindex*). This helper will likely be used in combination5051 * with helpers that adjust/change the packet size.5052 *5053 * The argument *len_diff* can be used for querying with a planned5054 * size change. This allows to check MTU prior to changing packet5055 * ctx. Providing a *len_diff* adjustment that is larger than the5056 * actual packet size (resulting in negative packet size) will in5057 * principle not exceed the MTU, which is why it is not considered5058 * a failure. Other BPF helpers are needed for performing the5059 * planned size change; therefore the responsibility for catching5060 * a negative packet size belongs in those helpers.5061 *5062 * Specifying *ifindex* zero means the MTU check is performed5063 * against the current net device. This is practical if this isn't5064 * used prior to redirect.5065 *5066 * On input *mtu_len* must be a valid pointer, else verifier will5067 * reject BPF program. If the value *mtu_len* is initialized to5068 * zero then the ctx packet size is use. When value *mtu_len* is5069 * provided as input this specify the L3 length that the MTU check5070 * is done against. Remember XDP and TC length operate at L2, but5071 * this value is L3 as this correlate to MTU and IP-header tot_len5072 * values which are L3 (similar behavior as bpf_fib_lookup).5073 *5074 * The Linux kernel route table can configure MTUs on a more5075 * specific per route level, which is not provided by this helper.5076 * For route level MTU checks use the **bpf_fib_lookup**\ ()5077 * helper.5078 *5079 * *ctx* is either **struct xdp_md** for XDP programs or5080 * **struct sk_buff** for tc cls_act programs.5081 *5082 * The *flags* argument can be a combination of one or more of the5083 * following values:5084 *5085 * **BPF_MTU_CHK_SEGS**5086 * This flag will only works for *ctx* **struct sk_buff**.5087 * If packet context contains extra packet segment buffers5088 * (often knows as GSO skb), then MTU check is harder to5089 * check at this point, because in transmit path it is5090 * possible for the skb packet to get re-segmented5091 * (depending on net device features). This could still be5092 * a MTU violation, so this flag enables performing MTU5093 * check against segments, with a different violation5094 * return code to tell it apart. Check cannot use len_diff.5095 *5096 * On return *mtu_len* pointer contains the MTU value of the net5097 * device. Remember the net device configured MTU is the L3 size,5098 * which is returned here and XDP and TC length operate at L2.5099 * Helper take this into account for you, but remember when using5100 * MTU value in your BPF-code.5101 *5102 * Return5103 * * 0 on success, and populate MTU value in *mtu_len* pointer.5104 *5105 * * < 0 if any input argument is invalid (*mtu_len* not updated)5106 *5107 * MTU violations return positive values, but also populate MTU5108 * value in *mtu_len* pointer, as this can be needed for5109 * implementing PMTU handing:5110 *5111 * * **BPF_MTU_CHK_RET_FRAG_NEEDED**5112 * * **BPF_MTU_CHK_RET_SEGS_TOOBIG**5113 *5114 * long bpf_for_each_map_elem(struct bpf_map *map, void *callback_fn, void *callback_ctx, u64 flags)5115 * Description5116 * For each element in **map**, call **callback_fn** function with5117 * **map**, **callback_ctx** and other map-specific parameters.5118 * The **callback_fn** should be a static function and5119 * the **callback_ctx** should be a pointer to the stack.5120 * The **flags** is used to control certain aspects of the helper.5121 * Currently, the **flags** must be 0.5122 *5123 * The following are a list of supported map types and their5124 * respective expected callback signatures:5125 *5126 * BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_PERCPU_HASH,5127 * BPF_MAP_TYPE_LRU_HASH, BPF_MAP_TYPE_LRU_PERCPU_HASH,5128 * BPF_MAP_TYPE_ARRAY, BPF_MAP_TYPE_PERCPU_ARRAY5129 *5130 * long (\*callback_fn)(struct bpf_map \*map, const void \*key, void \*value, void \*ctx);5131 *5132 * For per_cpu maps, the map_value is the value on the cpu where the5133 * bpf_prog is running.5134 *5135 * If **callback_fn** return 0, the helper will continue to the next5136 * element. If return value is 1, the helper will skip the rest of5137 * elements and return. Other return values are not used now.5138 *5139 * Return5140 * The number of traversed map elements for success, **-EINVAL** for5141 * invalid **flags**.5142 *5143 * long bpf_snprintf(char *str, u32 str_size, const char *fmt, u64 *data, u32 data_len)5144 * Description5145 * Outputs a string into the **str** buffer of size **str_size**5146 * based on a format string stored in a read-only map pointed by5147 * **fmt**.5148 *5149 * Each format specifier in **fmt** corresponds to one u64 element5150 * in the **data** array. For strings and pointers where pointees5151 * are accessed, only the pointer values are stored in the *data*5152 * array. The *data_len* is the size of *data* in bytes - must be5153 * a multiple of 8.5154 *5155 * Formats **%s** and **%p{i,I}{4,6}** require to read kernel5156 * memory. Reading kernel memory may fail due to either invalid5157 * address or valid address but requiring a major memory fault. If5158 * reading kernel memory fails, the string for **%s** will be an5159 * empty string, and the ip address for **%p{i,I}{4,6}** will be 0.5160 * Not returning error to bpf program is consistent with what5161 * **bpf_trace_printk**\ () does for now.5162 *5163 * Return5164 * The strictly positive length of the formatted string, including5165 * the trailing zero character. If the return value is greater than5166 * **str_size**, **str** contains a truncated string, guaranteed to5167 * be zero-terminated except when **str_size** is 0.5168 *5169 * Or **-EBUSY** if the per-CPU memory copy buffer is busy.5170 *5171 * long bpf_sys_bpf(u32 cmd, void *attr, u32 attr_size)5172 * Description5173 * Execute bpf syscall with given arguments.5174 * Return5175 * A syscall result.5176 *5177 * long bpf_btf_find_by_name_kind(char *name, int name_sz, u32 kind, int flags)5178 * Description5179 * Find BTF type with given name and kind in vmlinux BTF or in module's BTFs.5180 * Return5181 * Returns btf_id and btf_obj_fd in lower and upper 32 bits.5182 *5183 * long bpf_sys_close(u32 fd)5184 * Description5185 * Execute close syscall for given FD.5186 * Return5187 * A syscall result.5188 *5189 * long bpf_timer_init(struct bpf_timer *timer, struct bpf_map *map, u64 flags)5190 * Description5191 * Initialize the timer.5192 * First 4 bits of *flags* specify clockid.5193 * Only CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_BOOTTIME are allowed.5194 * All other bits of *flags* are reserved.5195 * The verifier will reject the program if *timer* is not from5196 * the same *map*.5197 * Return5198 * 0 on success.5199 * **-EBUSY** if *timer* is already initialized.5200 * **-EINVAL** if invalid *flags* are passed.5201 * **-EPERM** if *timer* is in a map that doesn't have any user references.5202 * The user space should either hold a file descriptor to a map with timers5203 * or pin such map in bpffs. When map is unpinned or file descriptor is5204 * closed all timers in the map will be cancelled and freed.5205 *5206 * long bpf_timer_set_callback(struct bpf_timer *timer, void *callback_fn)5207 * Description5208 * Configure the timer to call *callback_fn* static function.5209 * Return5210 * 0 on success.5211 * **-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier.5212 * **-EPERM** if *timer* is in a map that doesn't have any user references.5213 * The user space should either hold a file descriptor to a map with timers5214 * or pin such map in bpffs. When map is unpinned or file descriptor is5215 * closed all timers in the map will be cancelled and freed.5216 *5217 * long bpf_timer_start(struct bpf_timer *timer, u64 nsecs, u64 flags)5218 * Description5219 * Set timer expiration N nanoseconds from the current time. The5220 * configured callback will be invoked in soft irq context on some cpu5221 * and will not repeat unless another bpf_timer_start() is made.5222 * In such case the next invocation can migrate to a different cpu.5223 * Since struct bpf_timer is a field inside map element the map5224 * owns the timer. The bpf_timer_set_callback() will increment refcnt5225 * of BPF program to make sure that callback_fn code stays valid.5226 * When user space reference to a map reaches zero all timers5227 * in a map are cancelled and corresponding program's refcnts are5228 * decremented. This is done to make sure that Ctrl-C of a user5229 * process doesn't leave any timers running. If map is pinned in5230 * bpffs the callback_fn can re-arm itself indefinitely.5231 * bpf_map_update/delete_elem() helpers and user space sys_bpf commands5232 * cancel and free the timer in the given map element.5233 * The map can contain timers that invoke callback_fn-s from different5234 * programs. The same callback_fn can serve different timers from5235 * different maps if key/value layout matches across maps.5236 * Every bpf_timer_set_callback() can have different callback_fn.5237 *5238 * *flags* can be one of:5239 *5240 * **BPF_F_TIMER_ABS**5241 * Start the timer in absolute expire value instead of the5242 * default relative one.5243 * **BPF_F_TIMER_CPU_PIN**5244 * Timer will be pinned to the CPU of the caller.5245 *5246 * Return5247 * 0 on success.5248 * **-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier5249 * or invalid *flags* are passed.5250 *5251 * long bpf_timer_cancel(struct bpf_timer *timer)5252 * Description5253 * Cancel the timer and wait for callback_fn to finish if it was running.5254 * Return5255 * 0 if the timer was not active.5256 * 1 if the timer was active.5257 * **-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier.5258 * **-EDEADLK** if callback_fn tried to call bpf_timer_cancel() on its5259 * own timer which would have led to a deadlock otherwise.5260 *5261 * u64 bpf_get_func_ip(void *ctx)5262 * Description5263 * Get address of the traced function (for tracing and kprobe programs).5264 *5265 * When called for kprobe program attached as uprobe it returns5266 * probe address for both entry and return uprobe.5267 *5268 * Return5269 * Address of the traced function for kprobe.5270 * 0 for kprobes placed within the function (not at the entry).5271 * Address of the probe for uprobe and return uprobe.5272 *5273 * u64 bpf_get_attach_cookie(void *ctx)5274 * Description5275 * Get bpf_cookie value provided (optionally) during the program5276 * attachment. It might be different for each individual5277 * attachment, even if BPF program itself is the same.5278 * Expects BPF program context *ctx* as a first argument.5279 *5280 * Supported for the following program types:5281 * - kprobe/uprobe;5282 * - tracepoint;5283 * - perf_event.5284 * Return5285 * Value specified by user at BPF link creation/attachment time5286 * or 0, if it was not specified.5287 *5288 * long bpf_task_pt_regs(struct task_struct *task)5289 * Description5290 * Get the struct pt_regs associated with **task**.5291 * Return5292 * A pointer to struct pt_regs.5293 *5294 * long bpf_get_branch_snapshot(void *entries, u32 size, u64 flags)5295 * Description5296 * Get branch trace from hardware engines like Intel LBR. The5297 * hardware engine is stopped shortly after the helper is5298 * called. Therefore, the user need to filter branch entries5299 * based on the actual use case. To capture branch trace5300 * before the trigger point of the BPF program, the helper5301 * should be called at the beginning of the BPF program.5302 *5303 * The data is stored as struct perf_branch_entry into output5304 * buffer *entries*. *size* is the size of *entries* in bytes.5305 * *flags* is reserved for now and must be zero.5306 *5307 * Return5308 * On success, number of bytes written to *buf*. On error, a5309 * negative value.5310 *5311 * **-EINVAL** if *flags* is not zero.5312 *5313 * **-ENOENT** if architecture does not support branch records.5314 *5315 * long bpf_trace_vprintk(const char *fmt, u32 fmt_size, const void *data, u32 data_len)5316 * Description5317 * Behaves like **bpf_trace_printk**\ () helper, but takes an array of u645318 * to format and can handle more format args as a result.5319 *5320 * Arguments are to be used as in **bpf_seq_printf**\ () helper.5321 * Return5322 * The number of bytes written to the buffer, or a negative error5323 * in case of failure.5324 *5325 * struct unix_sock *bpf_skc_to_unix_sock(void *sk)5326 * Description5327 * Dynamically cast a *sk* pointer to a *unix_sock* pointer.5328 * Return5329 * *sk* if casting is valid, or **NULL** otherwise.5330 *5331 * long bpf_kallsyms_lookup_name(const char *name, int name_sz, int flags, u64 *res)5332 * Description5333 * Get the address of a kernel symbol, returned in *res*. *res* is5334 * set to 0 if the symbol is not found.5335 * Return5336 * On success, zero. On error, a negative value.5337 *5338 * **-EINVAL** if *flags* is not zero.5339 *5340 * **-EINVAL** if string *name* is not the same size as *name_sz*.5341 *5342 * **-ENOENT** if symbol is not found.5343 *5344 * **-EPERM** if caller does not have permission to obtain kernel address.5345 *5346 * long bpf_find_vma(struct task_struct *task, u64 addr, void *callback_fn, void *callback_ctx, u64 flags)5347 * Description5348 * Find vma of *task* that contains *addr*, call *callback_fn*5349 * function with *task*, *vma*, and *callback_ctx*.5350 * The *callback_fn* should be a static function and5351 * the *callback_ctx* should be a pointer to the stack.5352 * The *flags* is used to control certain aspects of the helper.5353 * Currently, the *flags* must be 0.5354 *5355 * The expected callback signature is5356 *5357 * long (\*callback_fn)(struct task_struct \*task, struct vm_area_struct \*vma, void \*callback_ctx);5358 *5359 * Return5360 * 0 on success.5361 * **-ENOENT** if *task->mm* is NULL, or no vma contains *addr*.5362 * **-EBUSY** if failed to try lock mmap_lock.5363 * **-EINVAL** for invalid **flags**.5364 *5365 * long bpf_loop(u32 nr_loops, void *callback_fn, void *callback_ctx, u64 flags)5366 * Description5367 * For **nr_loops**, call **callback_fn** function5368 * with **callback_ctx** as the context parameter.5369 * The **callback_fn** should be a static function and5370 * the **callback_ctx** should be a pointer to the stack.5371 * The **flags** is used to control certain aspects of the helper.5372 * Currently, the **flags** must be 0. Currently, nr_loops is5373 * limited to 1 << 23 (~8 million) loops.5374 *5375 * long (\*callback_fn)(u32 index, void \*ctx);5376 *5377 * where **index** is the current index in the loop. The index5378 * is zero-indexed.5379 *5380 * If **callback_fn** returns 0, the helper will continue to the next5381 * loop. If return value is 1, the helper will skip the rest of5382 * the loops and return. Other return values are not used now,5383 * and will be rejected by the verifier.5384 *5385 * Return5386 * The number of loops performed, **-EINVAL** for invalid **flags**,5387 * **-E2BIG** if **nr_loops** exceeds the maximum number of loops.5388 *5389 * long bpf_strncmp(const char *s1, u32 s1_sz, const char *s2)5390 * Description5391 * Do strncmp() between **s1** and **s2**. **s1** doesn't need5392 * to be null-terminated and **s1_sz** is the maximum storage5393 * size of **s1**. **s2** must be a read-only string.5394 * Return5395 * An integer less than, equal to, or greater than zero5396 * if the first **s1_sz** bytes of **s1** is found to be5397 * less than, to match, or be greater than **s2**.5398 *5399 * long bpf_get_func_arg(void *ctx, u32 n, u64 *value)5400 * Description5401 * Get **n**-th argument register (zero based) of the traced function (for tracing programs)5402 * returned in **value**.5403 *5404 * Return5405 * 0 on success.5406 * **-EINVAL** if n >= argument register count of traced function.5407 *5408 * long bpf_get_func_ret(void *ctx, u64 *value)5409 * Description5410 * Get return value of the traced function (for tracing programs)5411 * in **value**.5412 *5413 * Return5414 * 0 on success.5415 * **-EOPNOTSUPP** for tracing programs other than BPF_TRACE_FEXIT or BPF_MODIFY_RETURN.5416 *5417 * long bpf_get_func_arg_cnt(void *ctx)5418 * Description5419 * Get number of registers of the traced function (for tracing programs) where5420 * function arguments are stored in these registers.5421 *5422 * Return5423 * The number of argument registers of the traced function.5424 *5425 * int bpf_get_retval(void)5426 * Description5427 * Get the BPF program's return value that will be returned to the upper layers.5428 *5429 * This helper is currently supported by cgroup programs and only by the hooks5430 * where BPF program's return value is returned to the userspace via errno.5431 * Return5432 * The BPF program's return value.5433 *5434 * int bpf_set_retval(int retval)5435 * Description5436 * Set the BPF program's return value that will be returned to the upper layers.5437 *5438 * This helper is currently supported by cgroup programs and only by the hooks5439 * where BPF program's return value is returned to the userspace via errno.5440 *5441 * Note that there is the following corner case where the program exports an error5442 * via bpf_set_retval but signals success via 'return 1':5443 *5444 * bpf_set_retval(-EPERM);5445 * return 1;5446 *5447 * In this case, the BPF program's return value will use helper's -EPERM. This5448 * still holds true for cgroup/bind{4,6} which supports extra 'return 3' success case.5449 *5450 * Return5451 * 0 on success, or a negative error in case of failure.5452 *5453 * u64 bpf_xdp_get_buff_len(struct xdp_buff *xdp_md)5454 * Description5455 * Get the total size of a given xdp buff (linear and paged area)5456 * Return5457 * The total size of a given xdp buffer.5458 *5459 * long bpf_xdp_load_bytes(struct xdp_buff *xdp_md, u32 offset, void *buf, u32 len)5460 * Description5461 * This helper is provided as an easy way to load data from a5462 * xdp buffer. It can be used to load *len* bytes from *offset* from5463 * the frame associated to *xdp_md*, into the buffer pointed by5464 * *buf*.5465 * Return5466 * 0 on success, or a negative error in case of failure.5467 *5468 * long bpf_xdp_store_bytes(struct xdp_buff *xdp_md, u32 offset, void *buf, u32 len)5469 * Description5470 * Store *len* bytes from buffer *buf* into the frame5471 * associated to *xdp_md*, at *offset*.5472 * Return5473 * 0 on success, or a negative error in case of failure.5474 *5475 * long bpf_copy_from_user_task(void *dst, u32 size, const void *user_ptr, struct task_struct *tsk, u64 flags)5476 * Description5477 * Read *size* bytes from user space address *user_ptr* in *tsk*'s5478 * address space, and stores the data in *dst*. *flags* is not5479 * used yet and is provided for future extensibility. This helper5480 * can only be used by sleepable programs.5481 * Return5482 * 0 on success, or a negative error in case of failure. On error5483 * *dst* buffer is zeroed out.5484 *5485 * long bpf_skb_set_tstamp(struct sk_buff *skb, u64 tstamp, u32 tstamp_type)5486 * Description5487 * Change the __sk_buff->tstamp_type to *tstamp_type*5488 * and set *tstamp* to the __sk_buff->tstamp together.5489 *5490 * If there is no need to change the __sk_buff->tstamp_type,5491 * the tstamp value can be directly written to __sk_buff->tstamp5492 * instead.5493 *5494 * BPF_SKB_TSTAMP_DELIVERY_MONO is the only tstamp that5495 * will be kept during bpf_redirect_*(). A non zero5496 * *tstamp* must be used with the BPF_SKB_TSTAMP_DELIVERY_MONO5497 * *tstamp_type*.5498 *5499 * A BPF_SKB_TSTAMP_UNSPEC *tstamp_type* can only be used5500 * with a zero *tstamp*.5501 *5502 * Only IPv4 and IPv6 skb->protocol are supported.5503 *5504 * This function is most useful when it needs to set a5505 * mono delivery time to __sk_buff->tstamp and then5506 * bpf_redirect_*() to the egress of an iface. For example,5507 * changing the (rcv) timestamp in __sk_buff->tstamp at5508 * ingress to a mono delivery time and then bpf_redirect_*()5509 * to sch_fq@phy-dev.5510 * Return5511 * 0 on success.5512 * **-EINVAL** for invalid input5513 * **-EOPNOTSUPP** for unsupported protocol5514 *5515 * long bpf_ima_file_hash(struct file *file, void *dst, u32 size)5516 * Description5517 * Returns a calculated IMA hash of the *file*.5518 * If the hash is larger than *size*, then only *size*5519 * bytes will be copied to *dst*5520 * Return5521 * The **hash_algo** is returned on success,5522 * **-EOPNOTSUPP** if the hash calculation failed or **-EINVAL** if5523 * invalid arguments are passed.5524 *5525 * void *bpf_kptr_xchg(void *dst, void *ptr)5526 * Description5527 * Exchange kptr at pointer *dst* with *ptr*, and return the old value.5528 * *dst* can be map value or local kptr. *ptr* can be NULL, otherwise5529 * it must be a referenced pointer which will be released when this helper5530 * is called.5531 * Return5532 * The old value of kptr (which can be NULL). The returned pointer5533 * if not NULL, is a reference which must be released using its5534 * corresponding release function, or moved into a BPF map before5535 * program exit.5536 *5537 * void *bpf_map_lookup_percpu_elem(struct bpf_map *map, const void *key, u32 cpu)5538 * Description5539 * Perform a lookup in *percpu map* for an entry associated to5540 * *key* on *cpu*.5541 * Return5542 * Map value associated to *key* on *cpu*, or **NULL** if no entry5543 * was found or *cpu* is invalid.5544 *5545 * struct mptcp_sock *bpf_skc_to_mptcp_sock(void *sk)5546 * Description5547 * Dynamically cast a *sk* pointer to a *mptcp_sock* pointer.5548 * Return5549 * *sk* if casting is valid, or **NULL** otherwise.5550 *5551 * long bpf_dynptr_from_mem(void *data, u32 size, u64 flags, struct bpf_dynptr *ptr)5552 * Description5553 * Get a dynptr to local memory *data*.5554 *5555 * *data* must be a ptr to a map value.5556 * The maximum *size* supported is DYNPTR_MAX_SIZE.5557 * *flags* is currently unused.5558 * Return5559 * 0 on success, -E2BIG if the size exceeds DYNPTR_MAX_SIZE,5560 * -EINVAL if flags is not 0.5561 *5562 * long bpf_ringbuf_reserve_dynptr(void *ringbuf, u32 size, u64 flags, struct bpf_dynptr *ptr)5563 * Description5564 * Reserve *size* bytes of payload in a ring buffer *ringbuf*5565 * through the dynptr interface. *flags* must be 0.5566 *5567 * Please note that a corresponding bpf_ringbuf_submit_dynptr or5568 * bpf_ringbuf_discard_dynptr must be called on *ptr*, even if the5569 * reservation fails. This is enforced by the verifier.5570 * Return5571 * 0 on success, or a negative error in case of failure.5572 *5573 * void bpf_ringbuf_submit_dynptr(struct bpf_dynptr *ptr, u64 flags)5574 * Description5575 * Submit reserved ring buffer sample, pointed to by *data*,5576 * through the dynptr interface. This is a no-op if the dynptr is5577 * invalid/null.5578 *5579 * For more information on *flags*, please see5580 * 'bpf_ringbuf_submit'.5581 * Return5582 * Nothing. Always succeeds.5583 *5584 * void bpf_ringbuf_discard_dynptr(struct bpf_dynptr *ptr, u64 flags)5585 * Description5586 * Discard reserved ring buffer sample through the dynptr5587 * interface. This is a no-op if the dynptr is invalid/null.5588 *5589 * For more information on *flags*, please see5590 * 'bpf_ringbuf_discard'.5591 * Return5592 * Nothing. Always succeeds.5593 *5594 * long bpf_dynptr_read(void *dst, u32 len, const struct bpf_dynptr *src, u32 offset, u64 flags)5595 * Description5596 * Read *len* bytes from *src* into *dst*, starting from *offset*5597 * into *src*.5598 * *flags* is currently unused.5599 * Return5600 * 0 on success, -E2BIG if *offset* + *len* exceeds the length5601 * of *src*'s data, -EINVAL if *src* is an invalid dynptr or if5602 * *flags* is not 0.5603 *5604 * long bpf_dynptr_write(const struct bpf_dynptr *dst, u32 offset, void *src, u32 len, u64 flags)5605 * Description5606 * Write *len* bytes from *src* into *dst*, starting from *offset*5607 * into *dst*.5608 *5609 * *flags* must be 0 except for skb-type dynptrs.5610 *5611 * For skb-type dynptrs:5612 * * All data slices of the dynptr are automatically5613 * invalidated after **bpf_dynptr_write**\ (). This is5614 * because writing may pull the skb and change the5615 * underlying packet buffer.5616 *5617 * * For *flags*, please see the flags accepted by5618 * **bpf_skb_store_bytes**\ ().5619 * Return5620 * 0 on success, -E2BIG if *offset* + *len* exceeds the length5621 * of *dst*'s data, -EINVAL if *dst* is an invalid dynptr or if *dst*5622 * is a read-only dynptr or if *flags* is not correct. For skb-type dynptrs,5623 * other errors correspond to errors returned by **bpf_skb_store_bytes**\ ().5624 *5625 * void *bpf_dynptr_data(const struct bpf_dynptr *ptr, u32 offset, u32 len)5626 * Description5627 * Get a pointer to the underlying dynptr data.5628 *5629 * *len* must be a statically known value. The returned data slice5630 * is invalidated whenever the dynptr is invalidated.5631 *5632 * skb and xdp type dynptrs may not use bpf_dynptr_data. They should5633 * instead use bpf_dynptr_slice and bpf_dynptr_slice_rdwr.5634 * Return5635 * Pointer to the underlying dynptr data, NULL if the dynptr is5636 * read-only, if the dynptr is invalid, or if the offset and length5637 * is out of bounds.5638 *5639 * s64 bpf_tcp_raw_gen_syncookie_ipv4(struct iphdr *iph, struct tcphdr *th, u32 th_len)5640 * Description5641 * Try to issue a SYN cookie for the packet with corresponding5642 * IPv4/TCP headers, *iph* and *th*, without depending on a5643 * listening socket.5644 *5645 * *iph* points to the IPv4 header.5646 *5647 * *th* points to the start of the TCP header, while *th_len*5648 * contains the length of the TCP header (at least5649 * **sizeof**\ (**struct tcphdr**)).5650 * Return5651 * On success, lower 32 bits hold the generated SYN cookie in5652 * followed by 16 bits which hold the MSS value for that cookie,5653 * and the top 16 bits are unused.5654 *5655 * On failure, the returned value is one of the following:5656 *5657 * **-EINVAL** if *th_len* is invalid.5658 *5659 * s64 bpf_tcp_raw_gen_syncookie_ipv6(struct ipv6hdr *iph, struct tcphdr *th, u32 th_len)5660 * Description5661 * Try to issue a SYN cookie for the packet with corresponding5662 * IPv6/TCP headers, *iph* and *th*, without depending on a5663 * listening socket.5664 *5665 * *iph* points to the IPv6 header.5666 *5667 * *th* points to the start of the TCP header, while *th_len*5668 * contains the length of the TCP header (at least5669 * **sizeof**\ (**struct tcphdr**)).5670 * Return5671 * On success, lower 32 bits hold the generated SYN cookie in5672 * followed by 16 bits which hold the MSS value for that cookie,5673 * and the top 16 bits are unused.5674 *5675 * On failure, the returned value is one of the following:5676 *5677 * **-EINVAL** if *th_len* is invalid.5678 *5679 * **-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.5680 *5681 * long bpf_tcp_raw_check_syncookie_ipv4(struct iphdr *iph, struct tcphdr *th)5682 * Description5683 * Check whether *iph* and *th* contain a valid SYN cookie ACK5684 * without depending on a listening socket.5685 *5686 * *iph* points to the IPv4 header.5687 *5688 * *th* points to the TCP header.5689 * Return5690 * 0 if *iph* and *th* are a valid SYN cookie ACK.5691 *5692 * On failure, the returned value is one of the following:5693 *5694 * **-EACCES** if the SYN cookie is not valid.5695 *5696 * long bpf_tcp_raw_check_syncookie_ipv6(struct ipv6hdr *iph, struct tcphdr *th)5697 * Description5698 * Check whether *iph* and *th* contain a valid SYN cookie ACK5699 * without depending on a listening socket.5700 *5701 * *iph* points to the IPv6 header.5702 *5703 * *th* points to the TCP header.5704 * Return5705 * 0 if *iph* and *th* are a valid SYN cookie ACK.5706 *5707 * On failure, the returned value is one of the following:5708 *5709 * **-EACCES** if the SYN cookie is not valid.5710 *5711 * **-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.5712 *5713 * u64 bpf_ktime_get_tai_ns(void)5714 * Description5715 * A nonsettable system-wide clock derived from wall-clock time but5716 * ignoring leap seconds. This clock does not experience5717 * discontinuities and backwards jumps caused by NTP inserting leap5718 * seconds as CLOCK_REALTIME does.5719 *5720 * See: **clock_gettime**\ (**CLOCK_TAI**)5721 * Return5722 * Current *ktime*.5723 *5724 * long bpf_user_ringbuf_drain(struct bpf_map *map, void *callback_fn, void *ctx, u64 flags)5725 * Description5726 * Drain samples from the specified user ring buffer, and invoke5727 * the provided callback for each such sample:5728 *5729 * long (\*callback_fn)(const struct bpf_dynptr \*dynptr, void \*ctx);5730 *5731 * If **callback_fn** returns 0, the helper will continue to try5732 * and drain the next sample, up to a maximum of5733 * BPF_MAX_USER_RINGBUF_SAMPLES samples. If the return value is 1,5734 * the helper will skip the rest of the samples and return. Other5735 * return values are not used now, and will be rejected by the5736 * verifier.5737 * Return5738 * The number of drained samples if no error was encountered while5739 * draining samples, or 0 if no samples were present in the ring5740 * buffer. If a user-space producer was epoll-waiting on this map,5741 * and at least one sample was drained, they will receive an event5742 * notification notifying them of available space in the ring5743 * buffer. If the BPF_RB_NO_WAKEUP flag is passed to this5744 * function, no wakeup notification will be sent. If the5745 * BPF_RB_FORCE_WAKEUP flag is passed, a wakeup notification will5746 * be sent even if no sample was drained.5747 *5748 * On failure, the returned value is one of the following:5749 *5750 * **-EBUSY** if the ring buffer is contended, and another calling5751 * context was concurrently draining the ring buffer.5752 *5753 * **-EINVAL** if user-space is not properly tracking the ring5754 * buffer due to the producer position not being aligned to 85755 * bytes, a sample not being aligned to 8 bytes, or the producer5756 * position not matching the advertised length of a sample.5757 *5758 * **-E2BIG** if user-space has tried to publish a sample which is5759 * larger than the size of the ring buffer, or which cannot fit5760 * within a struct bpf_dynptr.5761 *5762 * void *bpf_cgrp_storage_get(struct bpf_map *map, struct cgroup *cgroup, void *value, u64 flags)5763 * Description5764 * Get a bpf_local_storage from the *cgroup*.5765 *5766 * Logically, it could be thought of as getting the value from5767 * a *map* with *cgroup* as the **key**. From this5768 * perspective, the usage is not much different from5769 * **bpf_map_lookup_elem**\ (*map*, **&**\ *cgroup*) except this5770 * helper enforces the key must be a cgroup struct and the map must also5771 * be a **BPF_MAP_TYPE_CGRP_STORAGE**.5772 *5773 * In reality, the local-storage value is embedded directly inside of the5774 * *cgroup* object itself, rather than being located in the5775 * **BPF_MAP_TYPE_CGRP_STORAGE** map. When the local-storage value is5776 * queried for some *map* on a *cgroup* object, the kernel will perform an5777 * O(n) iteration over all of the live local-storage values for that5778 * *cgroup* object until the local-storage value for the *map* is found.5779 *5780 * An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be5781 * used such that a new bpf_local_storage will be5782 * created if one does not exist. *value* can be used5783 * together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify5784 * the initial value of a bpf_local_storage. If *value* is5785 * **NULL**, the new bpf_local_storage will be zero initialized.5786 * Return5787 * A bpf_local_storage pointer is returned on success.5788 *5789 * **NULL** if not found or there was an error in adding5790 * a new bpf_local_storage.5791 *5792 * long bpf_cgrp_storage_delete(struct bpf_map *map, struct cgroup *cgroup)5793 * Description5794 * Delete a bpf_local_storage from a *cgroup*.5795 * Return5796 * 0 on success.5797 *5798 * **-ENOENT** if the bpf_local_storage cannot be found.5799 */5800#define ___BPF_FUNC_MAPPER(FN, ctx...) \5801 FN(unspec, 0, ##ctx) \5802 FN(map_lookup_elem, 1, ##ctx) \5803 FN(map_update_elem, 2, ##ctx) \5804 FN(map_delete_elem, 3, ##ctx) \5805 FN(probe_read, 4, ##ctx) \5806 FN(ktime_get_ns, 5, ##ctx) \5807 FN(trace_printk, 6, ##ctx) \5808 FN(get_prandom_u32, 7, ##ctx) \5809 FN(get_smp_processor_id, 8, ##ctx) \5810 FN(skb_store_bytes, 9, ##ctx) \5811 FN(l3_csum_replace, 10, ##ctx) \5812 FN(l4_csum_replace, 11, ##ctx) \5813 FN(tail_call, 12, ##ctx) \5814 FN(clone_redirect, 13, ##ctx) \5815 FN(get_current_pid_tgid, 14, ##ctx) \5816 FN(get_current_uid_gid, 15, ##ctx) \5817 FN(get_current_comm, 16, ##ctx) \5818 FN(get_cgroup_classid, 17, ##ctx) \5819 FN(skb_vlan_push, 18, ##ctx) \5820 FN(skb_vlan_pop, 19, ##ctx) \5821 FN(skb_get_tunnel_key, 20, ##ctx) \5822 FN(skb_set_tunnel_key, 21, ##ctx) \5823 FN(perf_event_read, 22, ##ctx) \5824 FN(redirect, 23, ##ctx) \5825 FN(get_route_realm, 24, ##ctx) \5826 FN(perf_event_output, 25, ##ctx) \5827 FN(skb_load_bytes, 26, ##ctx) \5828 FN(get_stackid, 27, ##ctx) \5829 FN(csum_diff, 28, ##ctx) \5830 FN(skb_get_tunnel_opt, 29, ##ctx) \5831 FN(skb_set_tunnel_opt, 30, ##ctx) \5832 FN(skb_change_proto, 31, ##ctx) \5833 FN(skb_change_type, 32, ##ctx) \5834 FN(skb_under_cgroup, 33, ##ctx) \5835 FN(get_hash_recalc, 34, ##ctx) \5836 FN(get_current_task, 35, ##ctx) \5837 FN(probe_write_user, 36, ##ctx) \5838 FN(current_task_under_cgroup, 37, ##ctx) \5839 FN(skb_change_tail, 38, ##ctx) \5840 FN(skb_pull_data, 39, ##ctx) \5841 FN(csum_update, 40, ##ctx) \5842 FN(set_hash_invalid, 41, ##ctx) \5843 FN(get_numa_node_id, 42, ##ctx) \5844 FN(skb_change_head, 43, ##ctx) \5845 FN(xdp_adjust_head, 44, ##ctx) \5846 FN(probe_read_str, 45, ##ctx) \5847 FN(get_socket_cookie, 46, ##ctx) \5848 FN(get_socket_uid, 47, ##ctx) \5849 FN(set_hash, 48, ##ctx) \5850 FN(setsockopt, 49, ##ctx) \5851 FN(skb_adjust_room, 50, ##ctx) \5852 FN(redirect_map, 51, ##ctx) \5853 FN(sk_redirect_map, 52, ##ctx) \5854 FN(sock_map_update, 53, ##ctx) \5855 FN(xdp_adjust_meta, 54, ##ctx) \5856 FN(perf_event_read_value, 55, ##ctx) \5857 FN(perf_prog_read_value, 56, ##ctx) \5858 FN(getsockopt, 57, ##ctx) \5859 FN(override_return, 58, ##ctx) \5860 FN(sock_ops_cb_flags_set, 59, ##ctx) \5861 FN(msg_redirect_map, 60, ##ctx) \5862 FN(msg_apply_bytes, 61, ##ctx) \5863 FN(msg_cork_bytes, 62, ##ctx) \5864 FN(msg_pull_data, 63, ##ctx) \5865 FN(bind, 64, ##ctx) \5866 FN(xdp_adjust_tail, 65, ##ctx) \5867 FN(skb_get_xfrm_state, 66, ##ctx) \5868 FN(get_stack, 67, ##ctx) \5869 FN(skb_load_bytes_relative, 68, ##ctx) \5870 FN(fib_lookup, 69, ##ctx) \5871 FN(sock_hash_update, 70, ##ctx) \5872 FN(msg_redirect_hash, 71, ##ctx) \5873 FN(sk_redirect_hash, 72, ##ctx) \5874 FN(lwt_push_encap, 73, ##ctx) \5875 FN(lwt_seg6_store_bytes, 74, ##ctx) \5876 FN(lwt_seg6_adjust_srh, 75, ##ctx) \5877 FN(lwt_seg6_action, 76, ##ctx) \5878 FN(rc_repeat, 77, ##ctx) \5879 FN(rc_keydown, 78, ##ctx) \5880 FN(skb_cgroup_id, 79, ##ctx) \5881 FN(get_current_cgroup_id, 80, ##ctx) \5882 FN(get_local_storage, 81, ##ctx) \5883 FN(sk_select_reuseport, 82, ##ctx) \5884 FN(skb_ancestor_cgroup_id, 83, ##ctx) \5885 FN(sk_lookup_tcp, 84, ##ctx) \5886 FN(sk_lookup_udp, 85, ##ctx) \5887 FN(sk_release, 86, ##ctx) \5888 FN(map_push_elem, 87, ##ctx) \5889 FN(map_pop_elem, 88, ##ctx) \5890 FN(map_peek_elem, 89, ##ctx) \5891 FN(msg_push_data, 90, ##ctx) \5892 FN(msg_pop_data, 91, ##ctx) \5893 FN(rc_pointer_rel, 92, ##ctx) \5894 FN(spin_lock, 93, ##ctx) \5895 FN(spin_unlock, 94, ##ctx) \5896 FN(sk_fullsock, 95, ##ctx) \5897 FN(tcp_sock, 96, ##ctx) \5898 FN(skb_ecn_set_ce, 97, ##ctx) \5899 FN(get_listener_sock, 98, ##ctx) \5900 FN(skc_lookup_tcp, 99, ##ctx) \5901 FN(tcp_check_syncookie, 100, ##ctx) \5902 FN(sysctl_get_name, 101, ##ctx) \5903 FN(sysctl_get_current_value, 102, ##ctx) \5904 FN(sysctl_get_new_value, 103, ##ctx) \5905 FN(sysctl_set_new_value, 104, ##ctx) \5906 FN(strtol, 105, ##ctx) \5907 FN(strtoul, 106, ##ctx) \5908 FN(sk_storage_get, 107, ##ctx) \5909 FN(sk_storage_delete, 108, ##ctx) \5910 FN(send_signal, 109, ##ctx) \5911 FN(tcp_gen_syncookie, 110, ##ctx) \5912 FN(skb_output, 111, ##ctx) \5913 FN(probe_read_user, 112, ##ctx) \5914 FN(probe_read_kernel, 113, ##ctx) \5915 FN(probe_read_user_str, 114, ##ctx) \5916 FN(probe_read_kernel_str, 115, ##ctx) \5917 FN(tcp_send_ack, 116, ##ctx) \5918 FN(send_signal_thread, 117, ##ctx) \5919 FN(jiffies64, 118, ##ctx) \5920 FN(read_branch_records, 119, ##ctx) \5921 FN(get_ns_current_pid_tgid, 120, ##ctx) \5922 FN(xdp_output, 121, ##ctx) \5923 FN(get_netns_cookie, 122, ##ctx) \5924 FN(get_current_ancestor_cgroup_id, 123, ##ctx) \5925 FN(sk_assign, 124, ##ctx) \5926 FN(ktime_get_boot_ns, 125, ##ctx) \5927 FN(seq_printf, 126, ##ctx) \5928 FN(seq_write, 127, ##ctx) \5929 FN(sk_cgroup_id, 128, ##ctx) \5930 FN(sk_ancestor_cgroup_id, 129, ##ctx) \5931 FN(ringbuf_output, 130, ##ctx) \5932 FN(ringbuf_reserve, 131, ##ctx) \5933 FN(ringbuf_submit, 132, ##ctx) \5934 FN(ringbuf_discard, 133, ##ctx) \5935 FN(ringbuf_query, 134, ##ctx) \5936 FN(csum_level, 135, ##ctx) \5937 FN(skc_to_tcp6_sock, 136, ##ctx) \5938 FN(skc_to_tcp_sock, 137, ##ctx) \5939 FN(skc_to_tcp_timewait_sock, 138, ##ctx) \5940 FN(skc_to_tcp_request_sock, 139, ##ctx) \5941 FN(skc_to_udp6_sock, 140, ##ctx) \5942 FN(get_task_stack, 141, ##ctx) \5943 FN(load_hdr_opt, 142, ##ctx) \5944 FN(store_hdr_opt, 143, ##ctx) \5945 FN(reserve_hdr_opt, 144, ##ctx) \5946 FN(inode_storage_get, 145, ##ctx) \5947 FN(inode_storage_delete, 146, ##ctx) \5948 FN(d_path, 147, ##ctx) \5949 FN(copy_from_user, 148, ##ctx) \5950 FN(snprintf_btf, 149, ##ctx) \5951 FN(seq_printf_btf, 150, ##ctx) \5952 FN(skb_cgroup_classid, 151, ##ctx) \5953 FN(redirect_neigh, 152, ##ctx) \5954 FN(per_cpu_ptr, 153, ##ctx) \5955 FN(this_cpu_ptr, 154, ##ctx) \5956 FN(redirect_peer, 155, ##ctx) \5957 FN(task_storage_get, 156, ##ctx) \5958 FN(task_storage_delete, 157, ##ctx) \5959 FN(get_current_task_btf, 158, ##ctx) \5960 FN(bprm_opts_set, 159, ##ctx) \5961 FN(ktime_get_coarse_ns, 160, ##ctx) \5962 FN(ima_inode_hash, 161, ##ctx) \5963 FN(sock_from_file, 162, ##ctx) \5964 FN(check_mtu, 163, ##ctx) \5965 FN(for_each_map_elem, 164, ##ctx) \5966 FN(snprintf, 165, ##ctx) \5967 FN(sys_bpf, 166, ##ctx) \5968 FN(btf_find_by_name_kind, 167, ##ctx) \5969 FN(sys_close, 168, ##ctx) \5970 FN(timer_init, 169, ##ctx) \5971 FN(timer_set_callback, 170, ##ctx) \5972 FN(timer_start, 171, ##ctx) \5973 FN(timer_cancel, 172, ##ctx) \5974 FN(get_func_ip, 173, ##ctx) \5975 FN(get_attach_cookie, 174, ##ctx) \5976 FN(task_pt_regs, 175, ##ctx) \5977 FN(get_branch_snapshot, 176, ##ctx) \5978 FN(trace_vprintk, 177, ##ctx) \5979 FN(skc_to_unix_sock, 178, ##ctx) \5980 FN(kallsyms_lookup_name, 179, ##ctx) \5981 FN(find_vma, 180, ##ctx) \5982 FN(loop, 181, ##ctx) \5983 FN(strncmp, 182, ##ctx) \5984 FN(get_func_arg, 183, ##ctx) \5985 FN(get_func_ret, 184, ##ctx) \5986 FN(get_func_arg_cnt, 185, ##ctx) \5987 FN(get_retval, 186, ##ctx) \5988 FN(set_retval, 187, ##ctx) \5989 FN(xdp_get_buff_len, 188, ##ctx) \5990 FN(xdp_load_bytes, 189, ##ctx) \5991 FN(xdp_store_bytes, 190, ##ctx) \5992 FN(copy_from_user_task, 191, ##ctx) \5993 FN(skb_set_tstamp, 192, ##ctx) \5994 FN(ima_file_hash, 193, ##ctx) \5995 FN(kptr_xchg, 194, ##ctx) \5996 FN(map_lookup_percpu_elem, 195, ##ctx) \5997 FN(skc_to_mptcp_sock, 196, ##ctx) \5998 FN(dynptr_from_mem, 197, ##ctx) \5999 FN(ringbuf_reserve_dynptr, 198, ##ctx) \6000 FN(ringbuf_submit_dynptr, 199, ##ctx) \6001 FN(ringbuf_discard_dynptr, 200, ##ctx) \6002 FN(dynptr_read, 201, ##ctx) \6003 FN(dynptr_write, 202, ##ctx) \6004 FN(dynptr_data, 203, ##ctx) \6005 FN(tcp_raw_gen_syncookie_ipv4, 204, ##ctx) \6006 FN(tcp_raw_gen_syncookie_ipv6, 205, ##ctx) \6007 FN(tcp_raw_check_syncookie_ipv4, 206, ##ctx) \6008 FN(tcp_raw_check_syncookie_ipv6, 207, ##ctx) \6009 FN(ktime_get_tai_ns, 208, ##ctx) \6010 FN(user_ringbuf_drain, 209, ##ctx) \6011 FN(cgrp_storage_get, 210, ##ctx) \6012 FN(cgrp_storage_delete, 211, ##ctx) \6013 /* */6014 6015/* backwards-compatibility macros for users of __BPF_FUNC_MAPPER that don't6016 * know or care about integer value that is now passed as second argument6017 */6018#define __BPF_FUNC_MAPPER_APPLY(name, value, FN) FN(name),6019#define __BPF_FUNC_MAPPER(FN) ___BPF_FUNC_MAPPER(__BPF_FUNC_MAPPER_APPLY, FN)6020 6021/* integer value in 'imm' field of BPF_CALL instruction selects which helper6022 * function eBPF program intends to call6023 */6024#define __BPF_ENUM_FN(x, y) BPF_FUNC_ ## x = y,6025enum bpf_func_id {6026 ___BPF_FUNC_MAPPER(__BPF_ENUM_FN)6027 __BPF_FUNC_MAX_ID,6028};6029#undef __BPF_ENUM_FN6030 6031/* All flags used by eBPF helper functions, placed here. */6032 6033/* BPF_FUNC_skb_store_bytes flags. */6034enum {6035 BPF_F_RECOMPUTE_CSUM = (1ULL << 0),6036 BPF_F_INVALIDATE_HASH = (1ULL << 1),6037};6038 6039/* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.6040 * First 4 bits are for passing the header field size.6041 */6042enum {6043 BPF_F_HDR_FIELD_MASK = 0xfULL,6044};6045 6046/* BPF_FUNC_l4_csum_replace flags. */6047enum {6048 BPF_F_PSEUDO_HDR = (1ULL << 4),6049 BPF_F_MARK_MANGLED_0 = (1ULL << 5),6050 BPF_F_MARK_ENFORCE = (1ULL << 6),6051};6052 6053/* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */6054enum {6055 BPF_F_TUNINFO_IPV6 = (1ULL << 0),6056};6057 6058/* flags for both BPF_FUNC_get_stackid and BPF_FUNC_get_stack. */6059enum {6060 BPF_F_SKIP_FIELD_MASK = 0xffULL,6061 BPF_F_USER_STACK = (1ULL << 8),6062/* flags used by BPF_FUNC_get_stackid only. */6063 BPF_F_FAST_STACK_CMP = (1ULL << 9),6064 BPF_F_REUSE_STACKID = (1ULL << 10),6065/* flags used by BPF_FUNC_get_stack only. */6066 BPF_F_USER_BUILD_ID = (1ULL << 11),6067};6068 6069/* BPF_FUNC_skb_set_tunnel_key flags. */6070enum {6071 BPF_F_ZERO_CSUM_TX = (1ULL << 1),6072 BPF_F_DONT_FRAGMENT = (1ULL << 2),6073 BPF_F_SEQ_NUMBER = (1ULL << 3),6074 BPF_F_NO_TUNNEL_KEY = (1ULL << 4),6075};6076 6077/* BPF_FUNC_skb_get_tunnel_key flags. */6078enum {6079 BPF_F_TUNINFO_FLAGS = (1ULL << 4),6080};6081 6082/* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and6083 * BPF_FUNC_perf_event_read_value flags.6084 */6085enum {6086 BPF_F_INDEX_MASK = 0xffffffffULL,6087 BPF_F_CURRENT_CPU = BPF_F_INDEX_MASK,6088/* BPF_FUNC_perf_event_output for sk_buff input context. */6089 BPF_F_CTXLEN_MASK = (0xfffffULL << 32),6090};6091 6092/* Current network namespace */6093enum {6094 BPF_F_CURRENT_NETNS = (-1L),6095};6096 6097/* BPF_FUNC_csum_level level values. */6098enum {6099 BPF_CSUM_LEVEL_QUERY,6100 BPF_CSUM_LEVEL_INC,6101 BPF_CSUM_LEVEL_DEC,6102 BPF_CSUM_LEVEL_RESET,6103};6104 6105/* BPF_FUNC_skb_adjust_room flags. */6106enum {6107 BPF_F_ADJ_ROOM_FIXED_GSO = (1ULL << 0),6108 BPF_F_ADJ_ROOM_ENCAP_L3_IPV4 = (1ULL << 1),6109 BPF_F_ADJ_ROOM_ENCAP_L3_IPV6 = (1ULL << 2),6110 BPF_F_ADJ_ROOM_ENCAP_L4_GRE = (1ULL << 3),6111 BPF_F_ADJ_ROOM_ENCAP_L4_UDP = (1ULL << 4),6112 BPF_F_ADJ_ROOM_NO_CSUM_RESET = (1ULL << 5),6113 BPF_F_ADJ_ROOM_ENCAP_L2_ETH = (1ULL << 6),6114 BPF_F_ADJ_ROOM_DECAP_L3_IPV4 = (1ULL << 7),6115 BPF_F_ADJ_ROOM_DECAP_L3_IPV6 = (1ULL << 8),6116};6117 6118enum {6119 BPF_ADJ_ROOM_ENCAP_L2_MASK = 0xff,6120 BPF_ADJ_ROOM_ENCAP_L2_SHIFT = 56,6121};6122 6123#define BPF_F_ADJ_ROOM_ENCAP_L2(len) (((__u64)len & \6124 BPF_ADJ_ROOM_ENCAP_L2_MASK) \6125 << BPF_ADJ_ROOM_ENCAP_L2_SHIFT)6126 6127/* BPF_FUNC_sysctl_get_name flags. */6128enum {6129 BPF_F_SYSCTL_BASE_NAME = (1ULL << 0),6130};6131 6132/* BPF_FUNC_<kernel_obj>_storage_get flags */6133enum {6134 BPF_LOCAL_STORAGE_GET_F_CREATE = (1ULL << 0),6135 /* BPF_SK_STORAGE_GET_F_CREATE is only kept for backward compatibility6136 * and BPF_LOCAL_STORAGE_GET_F_CREATE must be used instead.6137 */6138 BPF_SK_STORAGE_GET_F_CREATE = BPF_LOCAL_STORAGE_GET_F_CREATE,6139};6140 6141/* BPF_FUNC_read_branch_records flags. */6142enum {6143 BPF_F_GET_BRANCH_RECORDS_SIZE = (1ULL << 0),6144};6145 6146/* BPF_FUNC_bpf_ringbuf_commit, BPF_FUNC_bpf_ringbuf_discard, and6147 * BPF_FUNC_bpf_ringbuf_output flags.6148 */6149enum {6150 BPF_RB_NO_WAKEUP = (1ULL << 0),6151 BPF_RB_FORCE_WAKEUP = (1ULL << 1),6152};6153 6154/* BPF_FUNC_bpf_ringbuf_query flags */6155enum {6156 BPF_RB_AVAIL_DATA = 0,6157 BPF_RB_RING_SIZE = 1,6158 BPF_RB_CONS_POS = 2,6159 BPF_RB_PROD_POS = 3,6160};6161 6162/* BPF ring buffer constants */6163enum {6164 BPF_RINGBUF_BUSY_BIT = (1U << 31),6165 BPF_RINGBUF_DISCARD_BIT = (1U << 30),6166 BPF_RINGBUF_HDR_SZ = 8,6167};6168 6169/* BPF_FUNC_sk_assign flags in bpf_sk_lookup context. */6170enum {6171 BPF_SK_LOOKUP_F_REPLACE = (1ULL << 0),6172 BPF_SK_LOOKUP_F_NO_REUSEPORT = (1ULL << 1),6173};6174 6175/* Mode for BPF_FUNC_skb_adjust_room helper. */6176enum bpf_adj_room_mode {6177 BPF_ADJ_ROOM_NET,6178 BPF_ADJ_ROOM_MAC,6179};6180 6181/* Mode for BPF_FUNC_skb_load_bytes_relative helper. */6182enum bpf_hdr_start_off {6183 BPF_HDR_START_MAC,6184 BPF_HDR_START_NET,6185};6186 6187/* Encapsulation type for BPF_FUNC_lwt_push_encap helper. */6188enum bpf_lwt_encap_mode {6189 BPF_LWT_ENCAP_SEG6,6190 BPF_LWT_ENCAP_SEG6_INLINE,6191 BPF_LWT_ENCAP_IP,6192};6193 6194/* Flags for bpf_bprm_opts_set helper */6195enum {6196 BPF_F_BPRM_SECUREEXEC = (1ULL << 0),6197};6198 6199/* Flags for bpf_redirect and bpf_redirect_map helpers */6200enum {6201 BPF_F_INGRESS = (1ULL << 0), /* used for skb path */6202 BPF_F_BROADCAST = (1ULL << 3), /* used for XDP path */6203 BPF_F_EXCLUDE_INGRESS = (1ULL << 4), /* used for XDP path */6204#define BPF_F_REDIRECT_FLAGS (BPF_F_INGRESS | BPF_F_BROADCAST | BPF_F_EXCLUDE_INGRESS)6205};6206 6207#define __bpf_md_ptr(type, name) \6208union { \6209 type name; \6210 __u64 :64; \6211} __attribute__((aligned(8)))6212 6213/* The enum used in skb->tstamp_type. It specifies the clock type6214 * of the time stored in the skb->tstamp.6215 */6216enum {6217 BPF_SKB_TSTAMP_UNSPEC = 0, /* DEPRECATED */6218 BPF_SKB_TSTAMP_DELIVERY_MONO = 1, /* DEPRECATED */6219 BPF_SKB_CLOCK_REALTIME = 0,6220 BPF_SKB_CLOCK_MONOTONIC = 1,6221 BPF_SKB_CLOCK_TAI = 2,6222 /* For any future BPF_SKB_CLOCK_* that the bpf prog cannot handle,6223 * the bpf prog can try to deduce it by ingress/egress/skb->sk->sk_clockid.6224 */6225};6226 6227/* user accessible mirror of in-kernel sk_buff.6228 * new fields can only be added to the end of this structure6229 */6230struct __sk_buff {6231 __u32 len;6232 __u32 pkt_type;6233 __u32 mark;6234 __u32 queue_mapping;6235 __u32 protocol;6236 __u32 vlan_present;6237 __u32 vlan_tci;6238 __u32 vlan_proto;6239 __u32 priority;6240 __u32 ingress_ifindex;6241 __u32 ifindex;6242 __u32 tc_index;6243 __u32 cb[5];6244 __u32 hash;6245 __u32 tc_classid;6246 __u32 data;6247 __u32 data_end;6248 __u32 napi_id;6249 6250 /* Accessed by BPF_PROG_TYPE_sk_skb types from here to ... */6251 __u32 family;6252 __u32 remote_ip4; /* Stored in network byte order */6253 __u32 local_ip4; /* Stored in network byte order */6254 __u32 remote_ip6[4]; /* Stored in network byte order */6255 __u32 local_ip6[4]; /* Stored in network byte order */6256 __u32 remote_port; /* Stored in network byte order */6257 __u32 local_port; /* stored in host byte order */6258 /* ... here. */6259 6260 __u32 data_meta;6261 __bpf_md_ptr(struct bpf_flow_keys *, flow_keys);6262 __u64 tstamp;6263 __u32 wire_len;6264 __u32 gso_segs;6265 __bpf_md_ptr(struct bpf_sock *, sk);6266 __u32 gso_size;6267 __u8 tstamp_type;6268 __u32 :24; /* Padding, future use. */6269 __u64 hwtstamp;6270};6271 6272struct bpf_tunnel_key {6273 __u32 tunnel_id;6274 union {6275 __u32 remote_ipv4;6276 __u32 remote_ipv6[4];6277 };6278 __u8 tunnel_tos;6279 __u8 tunnel_ttl;6280 union {6281 __u16 tunnel_ext; /* compat */6282 __be16 tunnel_flags;6283 };6284 __u32 tunnel_label;6285 union {6286 __u32 local_ipv4;6287 __u32 local_ipv6[4];6288 };6289};6290 6291/* user accessible mirror of in-kernel xfrm_state.6292 * new fields can only be added to the end of this structure6293 */6294struct bpf_xfrm_state {6295 __u32 reqid;6296 __u32 spi; /* Stored in network byte order */6297 __u16 family;6298 __u16 ext; /* Padding, future use. */6299 union {6300 __u32 remote_ipv4; /* Stored in network byte order */6301 __u32 remote_ipv6[4]; /* Stored in network byte order */6302 };6303};6304 6305/* Generic BPF return codes which all BPF program types may support.6306 * The values are binary compatible with their TC_ACT_* counter-part to6307 * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT6308 * programs.6309 *6310 * XDP is handled seprately, see XDP_*.6311 */6312enum bpf_ret_code {6313 BPF_OK = 0,6314 /* 1 reserved */6315 BPF_DROP = 2,6316 /* 3-6 reserved */6317 BPF_REDIRECT = 7,6318 /* >127 are reserved for prog type specific return codes.6319 *6320 * BPF_LWT_REROUTE: used by BPF_PROG_TYPE_LWT_IN and6321 * BPF_PROG_TYPE_LWT_XMIT to indicate that skb had been6322 * changed and should be routed based on its new L3 header.6323 * (This is an L3 redirect, as opposed to L2 redirect6324 * represented by BPF_REDIRECT above).6325 */6326 BPF_LWT_REROUTE = 128,6327 /* BPF_FLOW_DISSECTOR_CONTINUE: used by BPF_PROG_TYPE_FLOW_DISSECTOR6328 * to indicate that no custom dissection was performed, and6329 * fallback to standard dissector is requested.6330 */6331 BPF_FLOW_DISSECTOR_CONTINUE = 129,6332};6333 6334struct bpf_sock {6335 __u32 bound_dev_if;6336 __u32 family;6337 __u32 type;6338 __u32 protocol;6339 __u32 mark;6340 __u32 priority;6341 /* IP address also allows 1 and 2 bytes access */6342 __u32 src_ip4;6343 __u32 src_ip6[4];6344 __u32 src_port; /* host byte order */6345 __be16 dst_port; /* network byte order */6346 __u16 :16; /* zero padding */6347 __u32 dst_ip4;6348 __u32 dst_ip6[4];6349 __u32 state;6350 __s32 rx_queue_mapping;6351};6352 6353struct bpf_tcp_sock {6354 __u32 snd_cwnd; /* Sending congestion window */6355 __u32 srtt_us; /* smoothed round trip time << 3 in usecs */6356 __u32 rtt_min;6357 __u32 snd_ssthresh; /* Slow start size threshold */6358 __u32 rcv_nxt; /* What we want to receive next */6359 __u32 snd_nxt; /* Next sequence we send */6360 __u32 snd_una; /* First byte we want an ack for */6361 __u32 mss_cache; /* Cached effective mss, not including SACKS */6362 __u32 ecn_flags; /* ECN status bits. */6363 __u32 rate_delivered; /* saved rate sample: packets delivered */6364 __u32 rate_interval_us; /* saved rate sample: time elapsed */6365 __u32 packets_out; /* Packets which are "in flight" */6366 __u32 retrans_out; /* Retransmitted packets out */6367 __u32 total_retrans; /* Total retransmits for entire connection */6368 __u32 segs_in; /* RFC4898 tcpEStatsPerfSegsIn6369 * total number of segments in.6370 */6371 __u32 data_segs_in; /* RFC4898 tcpEStatsPerfDataSegsIn6372 * total number of data segments in.6373 */6374 __u32 segs_out; /* RFC4898 tcpEStatsPerfSegsOut6375 * The total number of segments sent.6376 */6377 __u32 data_segs_out; /* RFC4898 tcpEStatsPerfDataSegsOut6378 * total number of data segments sent.6379 */6380 __u32 lost_out; /* Lost packets */6381 __u32 sacked_out; /* SACK'd packets */6382 __u64 bytes_received; /* RFC4898 tcpEStatsAppHCThruOctetsReceived6383 * sum(delta(rcv_nxt)), or how many bytes6384 * were acked.6385 */6386 __u64 bytes_acked; /* RFC4898 tcpEStatsAppHCThruOctetsAcked6387 * sum(delta(snd_una)), or how many bytes6388 * were acked.6389 */6390 __u32 dsack_dups; /* RFC4898 tcpEStatsStackDSACKDups6391 * total number of DSACK blocks received6392 */6393 __u32 delivered; /* Total data packets delivered incl. rexmits */6394 __u32 delivered_ce; /* Like the above but only ECE marked packets */6395 __u32 icsk_retransmits; /* Number of unrecovered [RTO] timeouts */6396};6397 6398struct bpf_sock_tuple {6399 union {6400 struct {6401 __be32 saddr;6402 __be32 daddr;6403 __be16 sport;6404 __be16 dport;6405 } ipv4;6406 struct {6407 __be32 saddr[4];6408 __be32 daddr[4];6409 __be16 sport;6410 __be16 dport;6411 } ipv6;6412 };6413};6414 6415/* (Simplified) user return codes for tcx prog type.6416 * A valid tcx program must return one of these defined values. All other6417 * return codes are reserved for future use. Must remain compatible with6418 * their TC_ACT_* counter-parts. For compatibility in behavior, unknown6419 * return codes are mapped to TCX_NEXT.6420 */6421enum tcx_action_base {6422 TCX_NEXT = -1,6423 TCX_PASS = 0,6424 TCX_DROP = 2,6425 TCX_REDIRECT = 7,6426};6427 6428struct bpf_xdp_sock {6429 __u32 queue_id;6430};6431 6432#define XDP_PACKET_HEADROOM 2566433 6434/* User return codes for XDP prog type.6435 * A valid XDP program must return one of these defined values. All other6436 * return codes are reserved for future use. Unknown return codes will6437 * result in packet drops and a warning via bpf_warn_invalid_xdp_action().6438 */6439enum xdp_action {6440 XDP_ABORTED = 0,6441 XDP_DROP,6442 XDP_PASS,6443 XDP_TX,6444 XDP_REDIRECT,6445};6446 6447/* user accessible metadata for XDP packet hook6448 * new fields must be added to the end of this structure6449 */6450struct xdp_md {6451 __u32 data;6452 __u32 data_end;6453 __u32 data_meta;6454 /* Below access go through struct xdp_rxq_info */6455 __u32 ingress_ifindex; /* rxq->dev->ifindex */6456 __u32 rx_queue_index; /* rxq->queue_index */6457 6458 __u32 egress_ifindex; /* txq->dev->ifindex */6459};6460 6461/* DEVMAP map-value layout6462 *6463 * The struct data-layout of map-value is a configuration interface.6464 * New members can only be added to the end of this structure.6465 */6466struct bpf_devmap_val {6467 __u32 ifindex; /* device index */6468 union {6469 int fd; /* prog fd on map write */6470 __u32 id; /* prog id on map read */6471 } bpf_prog;6472};6473 6474/* CPUMAP map-value layout6475 *6476 * The struct data-layout of map-value is a configuration interface.6477 * New members can only be added to the end of this structure.6478 */6479struct bpf_cpumap_val {6480 __u32 qsize; /* queue size to remote target CPU */6481 union {6482 int fd; /* prog fd on map write */6483 __u32 id; /* prog id on map read */6484 } bpf_prog;6485};6486 6487enum sk_action {6488 SK_DROP = 0,6489 SK_PASS,6490};6491 6492/* user accessible metadata for SK_MSG packet hook, new fields must6493 * be added to the end of this structure6494 */6495struct sk_msg_md {6496 __bpf_md_ptr(void *, data);6497 __bpf_md_ptr(void *, data_end);6498 6499 __u32 family;6500 __u32 remote_ip4; /* Stored in network byte order */6501 __u32 local_ip4; /* Stored in network byte order */6502 __u32 remote_ip6[4]; /* Stored in network byte order */6503 __u32 local_ip6[4]; /* Stored in network byte order */6504 __u32 remote_port; /* Stored in network byte order */6505 __u32 local_port; /* stored in host byte order */6506 __u32 size; /* Total size of sk_msg */6507 6508 __bpf_md_ptr(struct bpf_sock *, sk); /* current socket */6509};6510 6511struct sk_reuseport_md {6512 /*6513 * Start of directly accessible data. It begins from6514 * the tcp/udp header.6515 */6516 __bpf_md_ptr(void *, data);6517 /* End of directly accessible data */6518 __bpf_md_ptr(void *, data_end);6519 /*6520 * Total length of packet (starting from the tcp/udp header).6521 * Note that the directly accessible bytes (data_end - data)6522 * could be less than this "len". Those bytes could be6523 * indirectly read by a helper "bpf_skb_load_bytes()".6524 */6525 __u32 len;6526 /*6527 * Eth protocol in the mac header (network byte order). e.g.6528 * ETH_P_IP(0x0800) and ETH_P_IPV6(0x86DD)6529 */6530 __u32 eth_protocol;6531 __u32 ip_protocol; /* IP protocol. e.g. IPPROTO_TCP, IPPROTO_UDP */6532 __u32 bind_inany; /* Is sock bound to an INANY address? */6533 __u32 hash; /* A hash of the packet 4 tuples */6534 /* When reuse->migrating_sk is NULL, it is selecting a sk for the6535 * new incoming connection request (e.g. selecting a listen sk for6536 * the received SYN in the TCP case). reuse->sk is one of the sk6537 * in the reuseport group. The bpf prog can use reuse->sk to learn6538 * the local listening ip/port without looking into the skb.6539 *6540 * When reuse->migrating_sk is not NULL, reuse->sk is closed and6541 * reuse->migrating_sk is the socket that needs to be migrated6542 * to another listening socket. migrating_sk could be a fullsock6543 * sk that is fully established or a reqsk that is in-the-middle6544 * of 3-way handshake.6545 */6546 __bpf_md_ptr(struct bpf_sock *, sk);6547 __bpf_md_ptr(struct bpf_sock *, migrating_sk);6548};6549 6550#define BPF_TAG_SIZE 86551 6552struct bpf_prog_info {6553 __u32 type;6554 __u32 id;6555 __u8 tag[BPF_TAG_SIZE];6556 __u32 jited_prog_len;6557 __u32 xlated_prog_len;6558 __aligned_u64 jited_prog_insns;6559 __aligned_u64 xlated_prog_insns;6560 __u64 load_time; /* ns since boottime */6561 __u32 created_by_uid;6562 __u32 nr_map_ids;6563 __aligned_u64 map_ids;6564 char name[BPF_OBJ_NAME_LEN];6565 __u32 ifindex;6566 __u32 gpl_compatible:1;6567 __u32 :31; /* alignment pad */6568 __u64 netns_dev;6569 __u64 netns_ino;6570 __u32 nr_jited_ksyms;6571 __u32 nr_jited_func_lens;6572 __aligned_u64 jited_ksyms;6573 __aligned_u64 jited_func_lens;6574 __u32 btf_id;6575 __u32 func_info_rec_size;6576 __aligned_u64 func_info;6577 __u32 nr_func_info;6578 __u32 nr_line_info;6579 __aligned_u64 line_info;6580 __aligned_u64 jited_line_info;6581 __u32 nr_jited_line_info;6582 __u32 line_info_rec_size;6583 __u32 jited_line_info_rec_size;6584 __u32 nr_prog_tags;6585 __aligned_u64 prog_tags;6586 __u64 run_time_ns;6587 __u64 run_cnt;6588 __u64 recursion_misses;6589 __u32 verified_insns;6590 __u32 attach_btf_obj_id;6591 __u32 attach_btf_id;6592} __attribute__((aligned(8)));6593 6594struct bpf_map_info {6595 __u32 type;6596 __u32 id;6597 __u32 key_size;6598 __u32 value_size;6599 __u32 max_entries;6600 __u32 map_flags;6601 char name[BPF_OBJ_NAME_LEN];6602 __u32 ifindex;6603 __u32 btf_vmlinux_value_type_id;6604 __u64 netns_dev;6605 __u64 netns_ino;6606 __u32 btf_id;6607 __u32 btf_key_type_id;6608 __u32 btf_value_type_id;6609 __u32 btf_vmlinux_id;6610 __u64 map_extra;6611} __attribute__((aligned(8)));6612 6613struct bpf_btf_info {6614 __aligned_u64 btf;6615 __u32 btf_size;6616 __u32 id;6617 __aligned_u64 name;6618 __u32 name_len;6619 __u32 kernel_btf;6620} __attribute__((aligned(8)));6621 6622struct bpf_link_info {6623 __u32 type;6624 __u32 id;6625 __u32 prog_id;6626 union {6627 struct {6628 __aligned_u64 tp_name; /* in/out: tp_name buffer ptr */6629 __u32 tp_name_len; /* in/out: tp_name buffer len */6630 } raw_tracepoint;6631 struct {6632 __u32 attach_type;6633 __u32 target_obj_id; /* prog_id for PROG_EXT, otherwise btf object id */6634 __u32 target_btf_id; /* BTF type id inside the object */6635 } tracing;6636 struct {6637 __u64 cgroup_id;6638 __u32 attach_type;6639 } cgroup;6640 struct {6641 __aligned_u64 target_name; /* in/out: target_name buffer ptr */6642 __u32 target_name_len; /* in/out: target_name buffer len */6643 6644 /* If the iter specific field is 32 bits, it can be put6645 * in the first or second union. Otherwise it should be6646 * put in the second union.6647 */6648 union {6649 struct {6650 __u32 map_id;6651 } map;6652 };6653 union {6654 struct {6655 __u64 cgroup_id;6656 __u32 order;6657 } cgroup;6658 struct {6659 __u32 tid;6660 __u32 pid;6661 } task;6662 };6663 } iter;6664 struct {6665 __u32 netns_ino;6666 __u32 attach_type;6667 } netns;6668 struct {6669 __u32 ifindex;6670 } xdp;6671 struct {6672 __u32 map_id;6673 } struct_ops;6674 struct {6675 __u32 pf;6676 __u32 hooknum;6677 __s32 priority;6678 __u32 flags;6679 } netfilter;6680 struct {6681 __aligned_u64 addrs;6682 __u32 count; /* in/out: kprobe_multi function count */6683 __u32 flags;6684 __u64 missed;6685 __aligned_u64 cookies;6686 } kprobe_multi;6687 struct {6688 __aligned_u64 path;6689 __aligned_u64 offsets;6690 __aligned_u64 ref_ctr_offsets;6691 __aligned_u64 cookies;6692 __u32 path_size; /* in/out: real path size on success, including zero byte */6693 __u32 count; /* in/out: uprobe_multi offsets/ref_ctr_offsets/cookies count */6694 __u32 flags;6695 __u32 pid;6696 } uprobe_multi;6697 struct {6698 __u32 type; /* enum bpf_perf_event_type */6699 __u32 :32;6700 union {6701 struct {6702 __aligned_u64 file_name; /* in/out */6703 __u32 name_len;6704 __u32 offset; /* offset from file_name */6705 __u64 cookie;6706 } uprobe; /* BPF_PERF_EVENT_UPROBE, BPF_PERF_EVENT_URETPROBE */6707 struct {6708 __aligned_u64 func_name; /* in/out */6709 __u32 name_len;6710 __u32 offset; /* offset from func_name */6711 __u64 addr;6712 __u64 missed;6713 __u64 cookie;6714 } kprobe; /* BPF_PERF_EVENT_KPROBE, BPF_PERF_EVENT_KRETPROBE */6715 struct {6716 __aligned_u64 tp_name; /* in/out */6717 __u32 name_len;6718 __u32 :32;6719 __u64 cookie;6720 } tracepoint; /* BPF_PERF_EVENT_TRACEPOINT */6721 struct {6722 __u64 config;6723 __u32 type;6724 __u32 :32;6725 __u64 cookie;6726 } event; /* BPF_PERF_EVENT_EVENT */6727 };6728 } perf_event;6729 struct {6730 __u32 ifindex;6731 __u32 attach_type;6732 } tcx;6733 struct {6734 __u32 ifindex;6735 __u32 attach_type;6736 } netkit;6737 struct {6738 __u32 map_id;6739 __u32 attach_type;6740 } sockmap;6741 };6742} __attribute__((aligned(8)));6743 6744/* User bpf_sock_addr struct to access socket fields and sockaddr struct passed6745 * by user and intended to be used by socket (e.g. to bind to, depends on6746 * attach type).6747 */6748struct bpf_sock_addr {6749 __u32 user_family; /* Allows 4-byte read, but no write. */6750 __u32 user_ip4; /* Allows 1,2,4-byte read and 4-byte write.6751 * Stored in network byte order.6752 */6753 __u32 user_ip6[4]; /* Allows 1,2,4,8-byte read and 4,8-byte write.6754 * Stored in network byte order.6755 */6756 __u32 user_port; /* Allows 1,2,4-byte read and 4-byte write.6757 * Stored in network byte order6758 */6759 __u32 family; /* Allows 4-byte read, but no write */6760 __u32 type; /* Allows 4-byte read, but no write */6761 __u32 protocol; /* Allows 4-byte read, but no write */6762 __u32 msg_src_ip4; /* Allows 1,2,4-byte read and 4-byte write.6763 * Stored in network byte order.6764 */6765 __u32 msg_src_ip6[4]; /* Allows 1,2,4,8-byte read and 4,8-byte write.6766 * Stored in network byte order.6767 */6768 __bpf_md_ptr(struct bpf_sock *, sk);6769};6770 6771/* User bpf_sock_ops struct to access socket values and specify request ops6772 * and their replies.6773 * Some of this fields are in network (bigendian) byte order and may need6774 * to be converted before use (bpf_ntohl() defined in samples/bpf/bpf_endian.h).6775 * New fields can only be added at the end of this structure6776 */6777struct bpf_sock_ops {6778 __u32 op;6779 union {6780 __u32 args[4]; /* Optionally passed to bpf program */6781 __u32 reply; /* Returned by bpf program */6782 __u32 replylong[4]; /* Optionally returned by bpf prog */6783 };6784 __u32 family;6785 __u32 remote_ip4; /* Stored in network byte order */6786 __u32 local_ip4; /* Stored in network byte order */6787 __u32 remote_ip6[4]; /* Stored in network byte order */6788 __u32 local_ip6[4]; /* Stored in network byte order */6789 __u32 remote_port; /* Stored in network byte order */6790 __u32 local_port; /* stored in host byte order */6791 __u32 is_fullsock; /* Some TCP fields are only valid if6792 * there is a full socket. If not, the6793 * fields read as zero.6794 */6795 __u32 snd_cwnd;6796 __u32 srtt_us; /* Averaged RTT << 3 in usecs */6797 __u32 bpf_sock_ops_cb_flags; /* flags defined in uapi/linux/tcp.h */6798 __u32 state;6799 __u32 rtt_min;6800 __u32 snd_ssthresh;6801 __u32 rcv_nxt;6802 __u32 snd_nxt;6803 __u32 snd_una;6804 __u32 mss_cache;6805 __u32 ecn_flags;6806 __u32 rate_delivered;6807 __u32 rate_interval_us;6808 __u32 packets_out;6809 __u32 retrans_out;6810 __u32 total_retrans;6811 __u32 segs_in;6812 __u32 data_segs_in;6813 __u32 segs_out;6814 __u32 data_segs_out;6815 __u32 lost_out;6816 __u32 sacked_out;6817 __u32 sk_txhash;6818 __u64 bytes_received;6819 __u64 bytes_acked;6820 __bpf_md_ptr(struct bpf_sock *, sk);6821 /* [skb_data, skb_data_end) covers the whole TCP header.6822 *6823 * BPF_SOCK_OPS_PARSE_HDR_OPT_CB: The packet received6824 * BPF_SOCK_OPS_HDR_OPT_LEN_CB: Not useful because the6825 * header has not been written.6826 * BPF_SOCK_OPS_WRITE_HDR_OPT_CB: The header and options have6827 * been written so far.6828 * BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB: The SYNACK that concludes6829 * the 3WHS.6830 * BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB: The ACK that concludes6831 * the 3WHS.6832 *6833 * bpf_load_hdr_opt() can also be used to read a particular option.6834 */6835 __bpf_md_ptr(void *, skb_data);6836 __bpf_md_ptr(void *, skb_data_end);6837 __u32 skb_len; /* The total length of a packet.6838 * It includes the header, options,6839 * and payload.6840 */6841 __u32 skb_tcp_flags; /* tcp_flags of the header. It provides6842 * an easy way to check for tcp_flags6843 * without parsing skb_data.6844 *6845 * In particular, the skb_tcp_flags6846 * will still be available in6847 * BPF_SOCK_OPS_HDR_OPT_LEN even though6848 * the outgoing header has not6849 * been written yet.6850 */6851 __u64 skb_hwtstamp;6852};6853 6854/* Definitions for bpf_sock_ops_cb_flags */6855enum {6856 BPF_SOCK_OPS_RTO_CB_FLAG = (1<<0),6857 BPF_SOCK_OPS_RETRANS_CB_FLAG = (1<<1),6858 BPF_SOCK_OPS_STATE_CB_FLAG = (1<<2),6859 BPF_SOCK_OPS_RTT_CB_FLAG = (1<<3),6860 /* Call bpf for all received TCP headers. The bpf prog will be6861 * called under sock_ops->op == BPF_SOCK_OPS_PARSE_HDR_OPT_CB6862 *6863 * Please refer to the comment in BPF_SOCK_OPS_PARSE_HDR_OPT_CB6864 * for the header option related helpers that will be useful6865 * to the bpf programs.6866 *6867 * It could be used at the client/active side (i.e. connect() side)6868 * when the server told it that the server was in syncookie6869 * mode and required the active side to resend the bpf-written6870 * options. The active side can keep writing the bpf-options until6871 * it received a valid packet from the server side to confirm6872 * the earlier packet (and options) has been received. The later6873 * example patch is using it like this at the active side when the6874 * server is in syncookie mode.6875 *6876 * The bpf prog will usually turn this off in the common cases.6877 */6878 BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG = (1<<4),6879 /* Call bpf when kernel has received a header option that6880 * the kernel cannot handle. The bpf prog will be called under6881 * sock_ops->op == BPF_SOCK_OPS_PARSE_HDR_OPT_CB.6882 *6883 * Please refer to the comment in BPF_SOCK_OPS_PARSE_HDR_OPT_CB6884 * for the header option related helpers that will be useful6885 * to the bpf programs.6886 */6887 BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG = (1<<5),6888 /* Call bpf when the kernel is writing header options for the6889 * outgoing packet. The bpf prog will first be called6890 * to reserve space in a skb under6891 * sock_ops->op == BPF_SOCK_OPS_HDR_OPT_LEN_CB. Then6892 * the bpf prog will be called to write the header option(s)6893 * under sock_ops->op == BPF_SOCK_OPS_WRITE_HDR_OPT_CB.6894 *6895 * Please refer to the comment in BPF_SOCK_OPS_HDR_OPT_LEN_CB6896 * and BPF_SOCK_OPS_WRITE_HDR_OPT_CB for the header option6897 * related helpers that will be useful to the bpf programs.6898 *6899 * The kernel gets its chance to reserve space and write6900 * options first before the BPF program does.6901 */6902 BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG = (1<<6),6903/* Mask of all currently supported cb flags */6904 BPF_SOCK_OPS_ALL_CB_FLAGS = 0x7F,6905};6906 6907/* List of known BPF sock_ops operators.6908 * New entries can only be added at the end6909 */6910enum {6911 BPF_SOCK_OPS_VOID,6912 BPF_SOCK_OPS_TIMEOUT_INIT, /* Should return SYN-RTO value to use or6913 * -1 if default value should be used6914 */6915 BPF_SOCK_OPS_RWND_INIT, /* Should return initial advertized6916 * window (in packets) or -1 if default6917 * value should be used6918 */6919 BPF_SOCK_OPS_TCP_CONNECT_CB, /* Calls BPF program right before an6920 * active connection is initialized6921 */6922 BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB, /* Calls BPF program when an6923 * active connection is6924 * established6925 */6926 BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB, /* Calls BPF program when a6927 * passive connection is6928 * established6929 */6930 BPF_SOCK_OPS_NEEDS_ECN, /* If connection's congestion control6931 * needs ECN6932 */6933 BPF_SOCK_OPS_BASE_RTT, /* Get base RTT. The correct value is6934 * based on the path and may be6935 * dependent on the congestion control6936 * algorithm. In general it indicates6937 * a congestion threshold. RTTs above6938 * this indicate congestion6939 */6940 BPF_SOCK_OPS_RTO_CB, /* Called when an RTO has triggered.6941 * Arg1: value of icsk_retransmits6942 * Arg2: value of icsk_rto6943 * Arg3: whether RTO has expired6944 */6945 BPF_SOCK_OPS_RETRANS_CB, /* Called when skb is retransmitted.6946 * Arg1: sequence number of 1st byte6947 * Arg2: # segments6948 * Arg3: return value of6949 * tcp_transmit_skb (0 => success)6950 */6951 BPF_SOCK_OPS_STATE_CB, /* Called when TCP changes state.6952 * Arg1: old_state6953 * Arg2: new_state6954 */6955 BPF_SOCK_OPS_TCP_LISTEN_CB, /* Called on listen(2), right after6956 * socket transition to LISTEN state.6957 */6958 BPF_SOCK_OPS_RTT_CB, /* Called on every RTT.6959 * Arg1: measured RTT input (mrtt)6960 * Arg2: updated srtt6961 */6962 BPF_SOCK_OPS_PARSE_HDR_OPT_CB, /* Parse the header option.6963 * It will be called to handle6964 * the packets received at6965 * an already established6966 * connection.6967 *6968 * sock_ops->skb_data:6969 * Referring to the received skb.6970 * It covers the TCP header only.6971 *6972 * bpf_load_hdr_opt() can also6973 * be used to search for a6974 * particular option.6975 */6976 BPF_SOCK_OPS_HDR_OPT_LEN_CB, /* Reserve space for writing the6977 * header option later in6978 * BPF_SOCK_OPS_WRITE_HDR_OPT_CB.6979 * Arg1: bool want_cookie. (in6980 * writing SYNACK only)6981 *6982 * sock_ops->skb_data:6983 * Not available because no header has6984 * been written yet.6985 *6986 * sock_ops->skb_tcp_flags:6987 * The tcp_flags of the6988 * outgoing skb. (e.g. SYN, ACK, FIN).6989 *6990 * bpf_reserve_hdr_opt() should6991 * be used to reserve space.6992 */6993 BPF_SOCK_OPS_WRITE_HDR_OPT_CB, /* Write the header options6994 * Arg1: bool want_cookie. (in6995 * writing SYNACK only)6996 *6997 * sock_ops->skb_data:6998 * Referring to the outgoing skb.6999 * It covers the TCP header7000 * that has already been written7001 * by the kernel and the7002 * earlier bpf-progs.7003 *7004 * sock_ops->skb_tcp_flags:7005 * The tcp_flags of the outgoing7006 * skb. (e.g. SYN, ACK, FIN).7007 *7008 * bpf_store_hdr_opt() should7009 * be used to write the7010 * option.7011 *7012 * bpf_load_hdr_opt() can also7013 * be used to search for a7014 * particular option that7015 * has already been written7016 * by the kernel or the7017 * earlier bpf-progs.7018 */7019};7020 7021/* List of TCP states. There is a build check in net/ipv4/tcp.c to detect7022 * changes between the TCP and BPF versions. Ideally this should never happen.7023 * If it does, we need to add code to convert them before calling7024 * the BPF sock_ops function.7025 */7026enum {7027 BPF_TCP_ESTABLISHED = 1,7028 BPF_TCP_SYN_SENT,7029 BPF_TCP_SYN_RECV,7030 BPF_TCP_FIN_WAIT1,7031 BPF_TCP_FIN_WAIT2,7032 BPF_TCP_TIME_WAIT,7033 BPF_TCP_CLOSE,7034 BPF_TCP_CLOSE_WAIT,7035 BPF_TCP_LAST_ACK,7036 BPF_TCP_LISTEN,7037 BPF_TCP_CLOSING, /* Now a valid state */7038 BPF_TCP_NEW_SYN_RECV,7039 BPF_TCP_BOUND_INACTIVE,7040 7041 BPF_TCP_MAX_STATES /* Leave at the end! */7042};7043 7044enum {7045 TCP_BPF_IW = 1001, /* Set TCP initial congestion window */7046 TCP_BPF_SNDCWND_CLAMP = 1002, /* Set sndcwnd_clamp */7047 TCP_BPF_DELACK_MAX = 1003, /* Max delay ack in usecs */7048 TCP_BPF_RTO_MIN = 1004, /* Min delay ack in usecs */7049 /* Copy the SYN pkt to optval7050 *7051 * BPF_PROG_TYPE_SOCK_OPS only. It is similar to the7052 * bpf_getsockopt(TCP_SAVED_SYN) but it does not limit7053 * to only getting from the saved_syn. It can either get the7054 * syn packet from:7055 *7056 * 1. the just-received SYN packet (only available when writing the7057 * SYNACK). It will be useful when it is not necessary to7058 * save the SYN packet for latter use. It is also the only way7059 * to get the SYN during syncookie mode because the syn7060 * packet cannot be saved during syncookie.7061 *7062 * OR7063 *7064 * 2. the earlier saved syn which was done by7065 * bpf_setsockopt(TCP_SAVE_SYN).7066 *7067 * The bpf_getsockopt(TCP_BPF_SYN*) option will hide where the7068 * SYN packet is obtained.7069 *7070 * If the bpf-prog does not need the IP[46] header, the7071 * bpf-prog can avoid parsing the IP header by using7072 * TCP_BPF_SYN. Otherwise, the bpf-prog can get both7073 * IP[46] and TCP header by using TCP_BPF_SYN_IP.7074 *7075 * >0: Total number of bytes copied7076 * -ENOSPC: Not enough space in optval. Only optlen number of7077 * bytes is copied.7078 * -ENOENT: The SYN skb is not available now and the earlier SYN pkt7079 * is not saved by setsockopt(TCP_SAVE_SYN).7080 */7081 TCP_BPF_SYN = 1005, /* Copy the TCP header */7082 TCP_BPF_SYN_IP = 1006, /* Copy the IP[46] and TCP header */7083 TCP_BPF_SYN_MAC = 1007, /* Copy the MAC, IP[46], and TCP header */7084 TCP_BPF_SOCK_OPS_CB_FLAGS = 1008, /* Get or Set TCP sock ops flags */7085};7086 7087enum {7088 BPF_LOAD_HDR_OPT_TCP_SYN = (1ULL << 0),7089};7090 7091/* args[0] value during BPF_SOCK_OPS_HDR_OPT_LEN_CB and7092 * BPF_SOCK_OPS_WRITE_HDR_OPT_CB.7093 */7094enum {7095 BPF_WRITE_HDR_TCP_CURRENT_MSS = 1, /* Kernel is finding the7096 * total option spaces7097 * required for an established7098 * sk in order to calculate the7099 * MSS. No skb is actually7100 * sent.7101 */7102 BPF_WRITE_HDR_TCP_SYNACK_COOKIE = 2, /* Kernel is in syncookie mode7103 * when sending a SYN.7104 */7105};7106 7107struct bpf_perf_event_value {7108 __u64 counter;7109 __u64 enabled;7110 __u64 running;7111};7112 7113enum {7114 BPF_DEVCG_ACC_MKNOD = (1ULL << 0),7115 BPF_DEVCG_ACC_READ = (1ULL << 1),7116 BPF_DEVCG_ACC_WRITE = (1ULL << 2),7117};7118 7119enum {7120 BPF_DEVCG_DEV_BLOCK = (1ULL << 0),7121 BPF_DEVCG_DEV_CHAR = (1ULL << 1),7122};7123 7124struct bpf_cgroup_dev_ctx {7125 /* access_type encoded as (BPF_DEVCG_ACC_* << 16) | BPF_DEVCG_DEV_* */7126 __u32 access_type;7127 __u32 major;7128 __u32 minor;7129};7130 7131struct bpf_raw_tracepoint_args {7132 __u64 args[0];7133};7134 7135/* DIRECT: Skip the FIB rules and go to FIB table associated with device7136 * OUTPUT: Do lookup from egress perspective; default is ingress7137 */7138enum {7139 BPF_FIB_LOOKUP_DIRECT = (1U << 0),7140 BPF_FIB_LOOKUP_OUTPUT = (1U << 1),7141 BPF_FIB_LOOKUP_SKIP_NEIGH = (1U << 2),7142 BPF_FIB_LOOKUP_TBID = (1U << 3),7143 BPF_FIB_LOOKUP_SRC = (1U << 4),7144 BPF_FIB_LOOKUP_MARK = (1U << 5),7145};7146 7147enum {7148 BPF_FIB_LKUP_RET_SUCCESS, /* lookup successful */7149 BPF_FIB_LKUP_RET_BLACKHOLE, /* dest is blackholed; can be dropped */7150 BPF_FIB_LKUP_RET_UNREACHABLE, /* dest is unreachable; can be dropped */7151 BPF_FIB_LKUP_RET_PROHIBIT, /* dest not allowed; can be dropped */7152 BPF_FIB_LKUP_RET_NOT_FWDED, /* packet is not forwarded */7153 BPF_FIB_LKUP_RET_FWD_DISABLED, /* fwding is not enabled on ingress */7154 BPF_FIB_LKUP_RET_UNSUPP_LWT, /* fwd requires encapsulation */7155 BPF_FIB_LKUP_RET_NO_NEIGH, /* no neighbor entry for nh */7156 BPF_FIB_LKUP_RET_FRAG_NEEDED, /* fragmentation required to fwd */7157 BPF_FIB_LKUP_RET_NO_SRC_ADDR, /* failed to derive IP src addr */7158};7159 7160struct bpf_fib_lookup {7161 /* input: network family for lookup (AF_INET, AF_INET6)7162 * output: network family of egress nexthop7163 */7164 __u8 family;7165 7166 /* set if lookup is to consider L4 data - e.g., FIB rules */7167 __u8 l4_protocol;7168 __be16 sport;7169 __be16 dport;7170 7171 union { /* used for MTU check */7172 /* input to lookup */7173 __u16 tot_len; /* L3 length from network hdr (iph->tot_len) */7174 7175 /* output: MTU value */7176 __u16 mtu_result;7177 } __attribute__((packed, aligned(2)));7178 /* input: L3 device index for lookup7179 * output: device index from FIB lookup7180 */7181 __u32 ifindex;7182 7183 union {7184 /* inputs to lookup */7185 __u8 tos; /* AF_INET */7186 __be32 flowinfo; /* AF_INET6, flow_label + priority */7187 7188 /* output: metric of fib result (IPv4/IPv6 only) */7189 __u32 rt_metric;7190 };7191 7192 /* input: source address to consider for lookup7193 * output: source address result from lookup7194 */7195 union {7196 __be32 ipv4_src;7197 __u32 ipv6_src[4]; /* in6_addr; network order */7198 };7199 7200 /* input to bpf_fib_lookup, ipv{4,6}_dst is destination address in7201 * network header. output: bpf_fib_lookup sets to gateway address7202 * if FIB lookup returns gateway route7203 */7204 union {7205 __be32 ipv4_dst;7206 __u32 ipv6_dst[4]; /* in6_addr; network order */7207 };7208 7209 union {7210 struct {7211 /* output */7212 __be16 h_vlan_proto;7213 __be16 h_vlan_TCI;7214 };7215 /* input: when accompanied with the7216 * 'BPF_FIB_LOOKUP_DIRECT | BPF_FIB_LOOKUP_TBID` flags, a7217 * specific routing table to use for the fib lookup.7218 */7219 __u32 tbid;7220 };7221 7222 union {7223 /* input */7224 struct {7225 __u32 mark; /* policy routing */7226 /* 2 4-byte holes for input */7227 };7228 7229 /* output: source and dest mac */7230 struct {7231 __u8 smac[6]; /* ETH_ALEN */7232 __u8 dmac[6]; /* ETH_ALEN */7233 };7234 };7235};7236 7237struct bpf_redir_neigh {7238 /* network family for lookup (AF_INET, AF_INET6) */7239 __u32 nh_family;7240 /* network address of nexthop; skips fib lookup to find gateway */7241 union {7242 __be32 ipv4_nh;7243 __u32 ipv6_nh[4]; /* in6_addr; network order */7244 };7245};7246 7247/* bpf_check_mtu flags*/7248enum bpf_check_mtu_flags {7249 BPF_MTU_CHK_SEGS = (1U << 0),7250};7251 7252enum bpf_check_mtu_ret {7253 BPF_MTU_CHK_RET_SUCCESS, /* check and lookup successful */7254 BPF_MTU_CHK_RET_FRAG_NEEDED, /* fragmentation required to fwd */7255 BPF_MTU_CHK_RET_SEGS_TOOBIG, /* GSO re-segmentation needed to fwd */7256};7257 7258enum bpf_task_fd_type {7259 BPF_FD_TYPE_RAW_TRACEPOINT, /* tp name */7260 BPF_FD_TYPE_TRACEPOINT, /* tp name */7261 BPF_FD_TYPE_KPROBE, /* (symbol + offset) or addr */7262 BPF_FD_TYPE_KRETPROBE, /* (symbol + offset) or addr */7263 BPF_FD_TYPE_UPROBE, /* filename + offset */7264 BPF_FD_TYPE_URETPROBE, /* filename + offset */7265};7266 7267enum {7268 BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG = (1U << 0),7269 BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL = (1U << 1),7270 BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP = (1U << 2),7271};7272 7273struct bpf_flow_keys {7274 __u16 nhoff;7275 __u16 thoff;7276 __u16 addr_proto; /* ETH_P_* of valid addrs */7277 __u8 is_frag;7278 __u8 is_first_frag;7279 __u8 is_encap;7280 __u8 ip_proto;7281 __be16 n_proto;7282 __be16 sport;7283 __be16 dport;7284 union {7285 struct {7286 __be32 ipv4_src;7287 __be32 ipv4_dst;7288 };7289 struct {7290 __u32 ipv6_src[4]; /* in6_addr; network order */7291 __u32 ipv6_dst[4]; /* in6_addr; network order */7292 };7293 };7294 __u32 flags;7295 __be32 flow_label;7296};7297 7298struct bpf_func_info {7299 __u32 insn_off;7300 __u32 type_id;7301};7302 7303#define BPF_LINE_INFO_LINE_NUM(line_col) ((line_col) >> 10)7304#define BPF_LINE_INFO_LINE_COL(line_col) ((line_col) & 0x3ff)7305 7306struct bpf_line_info {7307 __u32 insn_off;7308 __u32 file_name_off;7309 __u32 line_off;7310 __u32 line_col;7311};7312 7313struct bpf_spin_lock {7314 __u32 val;7315};7316 7317struct bpf_timer {7318 __u64 __opaque[2];7319} __attribute__((aligned(8)));7320 7321struct bpf_wq {7322 __u64 __opaque[2];7323} __attribute__((aligned(8)));7324 7325struct bpf_dynptr {7326 __u64 __opaque[2];7327} __attribute__((aligned(8)));7328 7329struct bpf_list_head {7330 __u64 __opaque[2];7331} __attribute__((aligned(8)));7332 7333struct bpf_list_node {7334 __u64 __opaque[3];7335} __attribute__((aligned(8)));7336 7337struct bpf_rb_root {7338 __u64 __opaque[2];7339} __attribute__((aligned(8)));7340 7341struct bpf_rb_node {7342 __u64 __opaque[4];7343} __attribute__((aligned(8)));7344 7345struct bpf_refcount {7346 __u32 __opaque[1];7347} __attribute__((aligned(4)));7348 7349struct bpf_sysctl {7350 __u32 write; /* Sysctl is being read (= 0) or written (= 1).7351 * Allows 1,2,4-byte read, but no write.7352 */7353 __u32 file_pos; /* Sysctl file position to read from, write to.7354 * Allows 1,2,4-byte read an 4-byte write.7355 */7356};7357 7358struct bpf_sockopt {7359 __bpf_md_ptr(struct bpf_sock *, sk);7360 __bpf_md_ptr(void *, optval);7361 __bpf_md_ptr(void *, optval_end);7362 7363 __s32 level;7364 __s32 optname;7365 __s32 optlen;7366 __s32 retval;7367};7368 7369struct bpf_pidns_info {7370 __u32 pid;7371 __u32 tgid;7372};7373 7374/* User accessible data for SK_LOOKUP programs. Add new fields at the end. */7375struct bpf_sk_lookup {7376 union {7377 __bpf_md_ptr(struct bpf_sock *, sk); /* Selected socket */7378 __u64 cookie; /* Non-zero if socket was selected in PROG_TEST_RUN */7379 };7380 7381 __u32 family; /* Protocol family (AF_INET, AF_INET6) */7382 __u32 protocol; /* IP protocol (IPPROTO_TCP, IPPROTO_UDP) */7383 __u32 remote_ip4; /* Network byte order */7384 __u32 remote_ip6[4]; /* Network byte order */7385 __be16 remote_port; /* Network byte order */7386 __u16 :16; /* Zero padding */7387 __u32 local_ip4; /* Network byte order */7388 __u32 local_ip6[4]; /* Network byte order */7389 __u32 local_port; /* Host byte order */7390 __u32 ingress_ifindex; /* The arriving interface. Determined by inet_iif. */7391};7392 7393/*7394 * struct btf_ptr is used for typed pointer representation; the7395 * type id is used to render the pointer data as the appropriate type7396 * via the bpf_snprintf_btf() helper described above. A flags field -7397 * potentially to specify additional details about the BTF pointer7398 * (rather than its mode of display) - is included for future use.7399 * Display flags - BTF_F_* - are passed to bpf_snprintf_btf separately.7400 */7401struct btf_ptr {7402 void *ptr;7403 __u32 type_id;7404 __u32 flags; /* BTF ptr flags; unused at present. */7405};7406 7407/*7408 * Flags to control bpf_snprintf_btf() behaviour.7409 * - BTF_F_COMPACT: no formatting around type information7410 * - BTF_F_NONAME: no struct/union member names/types7411 * - BTF_F_PTR_RAW: show raw (unobfuscated) pointer values;7412 * equivalent to %px.7413 * - BTF_F_ZERO: show zero-valued struct/union members; they7414 * are not displayed by default7415 */7416enum {7417 BTF_F_COMPACT = (1ULL << 0),7418 BTF_F_NONAME = (1ULL << 1),7419 BTF_F_PTR_RAW = (1ULL << 2),7420 BTF_F_ZERO = (1ULL << 3),7421};7422 7423/* bpf_core_relo_kind encodes which aspect of captured field/type/enum value7424 * has to be adjusted by relocations. It is emitted by llvm and passed to7425 * libbpf and later to the kernel.7426 */7427enum bpf_core_relo_kind {7428 BPF_CORE_FIELD_BYTE_OFFSET = 0, /* field byte offset */7429 BPF_CORE_FIELD_BYTE_SIZE = 1, /* field size in bytes */7430 BPF_CORE_FIELD_EXISTS = 2, /* field existence in target kernel */7431 BPF_CORE_FIELD_SIGNED = 3, /* field signedness (0 - unsigned, 1 - signed) */7432 BPF_CORE_FIELD_LSHIFT_U64 = 4, /* bitfield-specific left bitshift */7433 BPF_CORE_FIELD_RSHIFT_U64 = 5, /* bitfield-specific right bitshift */7434 BPF_CORE_TYPE_ID_LOCAL = 6, /* type ID in local BPF object */7435 BPF_CORE_TYPE_ID_TARGET = 7, /* type ID in target kernel */7436 BPF_CORE_TYPE_EXISTS = 8, /* type existence in target kernel */7437 BPF_CORE_TYPE_SIZE = 9, /* type size in bytes */7438 BPF_CORE_ENUMVAL_EXISTS = 10, /* enum value existence in target kernel */7439 BPF_CORE_ENUMVAL_VALUE = 11, /* enum value integer value */7440 BPF_CORE_TYPE_MATCHES = 12, /* type match in target kernel */7441};7442 7443/*7444 * "struct bpf_core_relo" is used to pass relocation data form LLVM to libbpf7445 * and from libbpf to the kernel.7446 *7447 * CO-RE relocation captures the following data:7448 * - insn_off - instruction offset (in bytes) within a BPF program that needs7449 * its insn->imm field to be relocated with actual field info;7450 * - type_id - BTF type ID of the "root" (containing) entity of a relocatable7451 * type or field;7452 * - access_str_off - offset into corresponding .BTF string section. String7453 * interpretation depends on specific relocation kind:7454 * - for field-based relocations, string encodes an accessed field using7455 * a sequence of field and array indices, separated by colon (:). It's7456 * conceptually very close to LLVM's getelementptr ([0]) instruction's7457 * arguments for identifying offset to a field.7458 * - for type-based relocations, strings is expected to be just "0";7459 * - for enum value-based relocations, string contains an index of enum7460 * value within its enum type;7461 * - kind - one of enum bpf_core_relo_kind;7462 *7463 * Example:7464 * struct sample {7465 * int a;7466 * struct {7467 * int b[10];7468 * };7469 * };7470 *7471 * struct sample *s = ...;7472 * int *x = &s->a; // encoded as "0:0" (a is field #0)7473 * int *y = &s->b[5]; // encoded as "0:1:0:5" (anon struct is field #1,7474 * // b is field #0 inside anon struct, accessing elem #5)7475 * int *z = &s[10]->b; // encoded as "10:1" (ptr is used as an array)7476 *7477 * type_id for all relocs in this example will capture BTF type id of7478 * `struct sample`.7479 *7480 * Such relocation is emitted when using __builtin_preserve_access_index()7481 * Clang built-in, passing expression that captures field address, e.g.:7482 *7483 * bpf_probe_read(&dst, sizeof(dst),7484 * __builtin_preserve_access_index(&src->a.b.c));7485 *7486 * In this case Clang will emit field relocation recording necessary data to7487 * be able to find offset of embedded `a.b.c` field within `src` struct.7488 *7489 * [0] https://llvm.org/docs/LangRef.html#getelementptr-instruction7490 */7491struct bpf_core_relo {7492 __u32 insn_off;7493 __u32 type_id;7494 __u32 access_str_off;7495 enum bpf_core_relo_kind kind;7496};7497 7498/*7499 * Flags to control bpf_timer_start() behaviour.7500 * - BPF_F_TIMER_ABS: Timeout passed is absolute time, by default it is7501 * relative to current time.7502 * - BPF_F_TIMER_CPU_PIN: Timer will be pinned to the CPU of the caller.7503 */7504enum {7505 BPF_F_TIMER_ABS = (1ULL << 0),7506 BPF_F_TIMER_CPU_PIN = (1ULL << 1),7507};7508 7509/* BPF numbers iterator state */7510struct bpf_iter_num {7511 /* opaque iterator state; having __u64 here allows to preserve correct7512 * alignment requirements in vmlinux.h, generated from BTF7513 */7514 __u64 __opaque[1];7515} __attribute__((aligned(8)));7516 7517/*7518 * Flags to control BPF kfunc behaviour.7519 * - BPF_F_PAD_ZEROS: Pad destination buffer with zeros. (See the respective7520 * helper documentation for details.)7521 */7522enum bpf_kfunc_flags {7523 BPF_F_PAD_ZEROS = (1ULL << 0),7524};7525 7526#endif /* _UAPI__LINUX_BPF_H__ */7527