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