1 /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 2 3 /* 4 * Common BPF ELF operations. 5 * 6 * Copyright (C) 2013-2015 Alexei Starovoitov <ast@kernel.org> 7 * Copyright (C) 2015 Wang Nan <wangnan0@huawei.com> 8 * Copyright (C) 2015 Huawei Inc. 9 * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Lesser General Public 12 * License as published by the Free Software Foundation; 13 * version 2.1 of the License (not later!) 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this program; if not, see <http://www.gnu.org/licenses> 22 */ 23 #ifndef __LIBBPF_BPF_H 24 #define __LIBBPF_BPF_H 25 26 #include <linux/bpf.h> 27 #include <stdbool.h> 28 #include <stddef.h> 29 #include <stdint.h> 30 31 #include "libbpf_common.h" 32 #include "libbpf_legacy.h" 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 int libbpf_set_memlock_rlim(size_t memlock_bytes); 39 40 struct bpf_map_create_opts { 41 size_t sz; /* size of this struct for forward/backward compatibility */ 42 43 __u32 btf_fd; 44 __u32 btf_key_type_id; 45 __u32 btf_value_type_id; 46 __u32 btf_vmlinux_value_type_id; 47 48 __u32 inner_map_fd; 49 __u32 map_flags; 50 __u64 map_extra; 51 52 __u32 numa_node; 53 __u32 map_ifindex; 54 55 __u32 token_fd; 56 size_t :0; 57 }; 58 #define bpf_map_create_opts__last_field token_fd 59 60 LIBBPF_API int bpf_map_create(enum bpf_map_type map_type, 61 const char *map_name, 62 __u32 key_size, 63 __u32 value_size, 64 __u32 max_entries, 65 const struct bpf_map_create_opts *opts); 66 67 struct bpf_prog_load_opts { 68 size_t sz; /* size of this struct for forward/backward compatibility */ 69 70 /* libbpf can retry BPF_PROG_LOAD command if bpf() syscall returns 71 * -EAGAIN. This field determines how many attempts libbpf has to 72 * make. If not specified, libbpf will use default value of 5. 73 */ 74 int attempts; 75 76 enum bpf_attach_type expected_attach_type; 77 __u32 prog_btf_fd; 78 __u32 prog_flags; 79 __u32 prog_ifindex; 80 __u32 kern_version; 81 82 __u32 attach_btf_id; 83 __u32 attach_prog_fd; 84 __u32 attach_btf_obj_fd; 85 86 const int *fd_array; 87 88 /* .BTF.ext func info data */ 89 const void *func_info; 90 __u32 func_info_cnt; 91 __u32 func_info_rec_size; 92 93 /* .BTF.ext line info data */ 94 const void *line_info; 95 __u32 line_info_cnt; 96 __u32 line_info_rec_size; 97 98 /* verifier log options */ 99 __u32 log_level; 100 __u32 log_size; 101 char *log_buf; 102 /* output: actual total log contents size (including termintaing zero). 103 * It could be both larger than original log_size (if log was 104 * truncated), or smaller (if log buffer wasn't filled completely). 105 * If kernel doesn't support this feature, log_size is left unchanged. 106 */ 107 __u32 log_true_size; 108 __u32 token_fd; 109 size_t :0; 110 }; 111 #define bpf_prog_load_opts__last_field token_fd 112 113 LIBBPF_API int bpf_prog_load(enum bpf_prog_type prog_type, 114 const char *prog_name, const char *license, 115 const struct bpf_insn *insns, size_t insn_cnt, 116 struct bpf_prog_load_opts *opts); 117 118 /* Flags to direct loading requirements */ 119 #define MAPS_RELAX_COMPAT 0x01 120 121 /* Recommended log buffer size */ 122 #define BPF_LOG_BUF_SIZE (UINT32_MAX >> 8) /* verifier maximum in kernels <= 5.1 */ 123 124 struct bpf_btf_load_opts { 125 size_t sz; /* size of this struct for forward/backward compatibility */ 126 127 /* kernel log options */ 128 char *log_buf; 129 __u32 log_level; 130 __u32 log_size; 131 /* output: actual total log contents size (including termintaing zero). 132 * It could be both larger than original log_size (if log was 133 * truncated), or smaller (if log buffer wasn't filled completely). 134 * If kernel doesn't support this feature, log_size is left unchanged. 135 */ 136 __u32 log_true_size; 137 __u32 token_fd; 138 size_t :0; 139 }; 140 #define bpf_btf_load_opts__last_field token_fd 141 142 LIBBPF_API int bpf_btf_load(const void *btf_data, size_t btf_size, 143 struct bpf_btf_load_opts *opts); 144 145 LIBBPF_API int bpf_map_update_elem(int fd, const void *key, const void *value, 146 __u64 flags); 147 148 LIBBPF_API int bpf_map_lookup_elem(int fd, const void *key, void *value); 149 LIBBPF_API int bpf_map_lookup_elem_flags(int fd, const void *key, void *value, 150 __u64 flags); 151 LIBBPF_API int bpf_map_lookup_and_delete_elem(int fd, const void *key, 152 void *value); 153 LIBBPF_API int bpf_map_lookup_and_delete_elem_flags(int fd, const void *key, 154 void *value, __u64 flags); 155 LIBBPF_API int bpf_map_delete_elem(int fd, const void *key); 156 LIBBPF_API int bpf_map_delete_elem_flags(int fd, const void *key, __u64 flags); 157 LIBBPF_API int bpf_map_get_next_key(int fd, const void *key, void *next_key); 158 LIBBPF_API int bpf_map_freeze(int fd); 159 160 struct bpf_map_batch_opts { 161 size_t sz; /* size of this struct for forward/backward compatibility */ 162 __u64 elem_flags; 163 __u64 flags; 164 }; 165 #define bpf_map_batch_opts__last_field flags 166 167 168 /** 169 * @brief **bpf_map_delete_batch()** allows for batch deletion of multiple 170 * elements in a BPF map. 171 * 172 * @param fd BPF map file descriptor 173 * @param keys pointer to an array of *count* keys 174 * @param count input and output parameter; on input **count** represents the 175 * number of elements in the map to delete in batch; 176 * on output if a non-EFAULT error is returned, **count** represents the number of deleted 177 * elements if the output **count** value is not equal to the input **count** value 178 * If EFAULT is returned, **count** should not be trusted to be correct. 179 * @param opts options for configuring the way the batch deletion works 180 * @return 0, on success; negative error code, otherwise (errno is also set to 181 * the error code) 182 */ 183 LIBBPF_API int bpf_map_delete_batch(int fd, const void *keys, 184 __u32 *count, 185 const struct bpf_map_batch_opts *opts); 186 187 /** 188 * @brief **bpf_map_lookup_batch()** allows for batch lookup of BPF map elements. 189 * 190 * The parameter *in_batch* is the address of the first element in the batch to read. 191 * *out_batch* is an output parameter that should be passed as *in_batch* to subsequent 192 * calls to **bpf_map_lookup_batch()**. NULL can be passed for *in_batch* to indicate 193 * that the batched lookup starts from the beginning of the map. 194 * 195 * The *keys* and *values* are output parameters which must point to memory large enough to 196 * hold *count* items based on the key and value size of the map *map_fd*. The *keys* 197 * buffer must be of *key_size* * *count*. The *values* buffer must be of 198 * *value_size* * *count*. 199 * 200 * @param fd BPF map file descriptor 201 * @param in_batch address of the first element in batch to read, can pass NULL to 202 * indicate that the batched lookup starts from the beginning of the map. 203 * @param out_batch output parameter that should be passed to next call as *in_batch* 204 * @param keys pointer to an array large enough for *count* keys 205 * @param values pointer to an array large enough for *count* values 206 * @param count input and output parameter; on input it's the number of elements 207 * in the map to read in batch; on output it's the number of elements that were 208 * successfully read. 209 * If a non-EFAULT error is returned, count will be set as the number of elements 210 * that were read before the error occurred. 211 * If EFAULT is returned, **count** should not be trusted to be correct. 212 * @param opts options for configuring the way the batch lookup works 213 * @return 0, on success; negative error code, otherwise (errno is also set to 214 * the error code) 215 */ 216 LIBBPF_API int bpf_map_lookup_batch(int fd, void *in_batch, void *out_batch, 217 void *keys, void *values, __u32 *count, 218 const struct bpf_map_batch_opts *opts); 219 220 /** 221 * @brief **bpf_map_lookup_and_delete_batch()** allows for batch lookup and deletion 222 * of BPF map elements where each element is deleted after being retrieved. 223 * 224 * @param fd BPF map file descriptor 225 * @param in_batch address of the first element in batch to read, can pass NULL to 226 * get address of the first element in *out_batch* 227 * @param out_batch output parameter that should be passed to next call as *in_batch* 228 * @param keys pointer to an array of *count* keys 229 * @param values pointer to an array large enough for *count* values 230 * @param count input and output parameter; on input it's the number of elements 231 * in the map to read and delete in batch; on output it represents the number of 232 * elements that were successfully read and deleted 233 * If a non-**EFAULT** error code is returned and if the output **count** value 234 * is not equal to the input **count** value, up to **count** elements may 235 * have been deleted. 236 * if **EFAULT** is returned up to *count* elements may have been deleted without 237 * being returned via the *keys* and *values* output parameters. 238 * @param opts options for configuring the way the batch lookup and delete works 239 * @return 0, on success; negative error code, otherwise (errno is also set to 240 * the error code) 241 */ 242 LIBBPF_API int bpf_map_lookup_and_delete_batch(int fd, void *in_batch, 243 void *out_batch, void *keys, 244 void *values, __u32 *count, 245 const struct bpf_map_batch_opts *opts); 246 247 /** 248 * @brief **bpf_map_update_batch()** updates multiple elements in a map 249 * by specifying keys and their corresponding values. 250 * 251 * The *keys* and *values* parameters must point to memory large enough 252 * to hold *count* items based on the key and value size of the map. 253 * 254 * The *opts* parameter can be used to control how *bpf_map_update_batch()* 255 * should handle keys that either do or do not already exist in the map. 256 * In particular the *flags* parameter of *bpf_map_batch_opts* can be 257 * one of the following: 258 * 259 * Note that *count* is an input and output parameter, where on output it 260 * represents how many elements were successfully updated. Also note that if 261 * **EFAULT** then *count* should not be trusted to be correct. 262 * 263 * **BPF_ANY** 264 * Create new elements or update existing. 265 * 266 * **BPF_NOEXIST** 267 * Create new elements only if they do not exist. 268 * 269 * **BPF_EXIST** 270 * Update existing elements. 271 * 272 * **BPF_F_LOCK** 273 * Update spin_lock-ed map elements. This must be 274 * specified if the map value contains a spinlock. 275 * 276 * @param fd BPF map file descriptor 277 * @param keys pointer to an array of *count* keys 278 * @param values pointer to an array of *count* values 279 * @param count input and output parameter; on input it's the number of elements 280 * in the map to update in batch; on output if a non-EFAULT error is returned, 281 * **count** represents the number of updated elements if the output **count** 282 * value is not equal to the input **count** value. 283 * If EFAULT is returned, **count** should not be trusted to be correct. 284 * @param opts options for configuring the way the batch update works 285 * @return 0, on success; negative error code, otherwise (errno is also set to 286 * the error code) 287 */ 288 LIBBPF_API int bpf_map_update_batch(int fd, const void *keys, const void *values, 289 __u32 *count, 290 const struct bpf_map_batch_opts *opts); 291 292 struct bpf_obj_pin_opts { 293 size_t sz; /* size of this struct for forward/backward compatibility */ 294 295 __u32 file_flags; 296 int path_fd; 297 298 size_t :0; 299 }; 300 #define bpf_obj_pin_opts__last_field path_fd 301 302 LIBBPF_API int bpf_obj_pin(int fd, const char *pathname); 303 LIBBPF_API int bpf_obj_pin_opts(int fd, const char *pathname, 304 const struct bpf_obj_pin_opts *opts); 305 306 struct bpf_obj_get_opts { 307 size_t sz; /* size of this struct for forward/backward compatibility */ 308 309 __u32 file_flags; 310 int path_fd; 311 312 size_t :0; 313 }; 314 #define bpf_obj_get_opts__last_field path_fd 315 316 LIBBPF_API int bpf_obj_get(const char *pathname); 317 LIBBPF_API int bpf_obj_get_opts(const char *pathname, 318 const struct bpf_obj_get_opts *opts); 319 320 LIBBPF_API int bpf_prog_attach(int prog_fd, int attachable_fd, 321 enum bpf_attach_type type, unsigned int flags); 322 LIBBPF_API int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type); 323 LIBBPF_API int bpf_prog_detach2(int prog_fd, int attachable_fd, 324 enum bpf_attach_type type); 325 326 struct bpf_prog_attach_opts { 327 size_t sz; /* size of this struct for forward/backward compatibility */ 328 __u32 flags; 329 union { 330 int replace_prog_fd; 331 int replace_fd; 332 }; 333 int relative_fd; 334 __u32 relative_id; 335 __u64 expected_revision; 336 size_t :0; 337 }; 338 #define bpf_prog_attach_opts__last_field expected_revision 339 340 struct bpf_prog_detach_opts { 341 size_t sz; /* size of this struct for forward/backward compatibility */ 342 __u32 flags; 343 int relative_fd; 344 __u32 relative_id; 345 __u64 expected_revision; 346 size_t :0; 347 }; 348 #define bpf_prog_detach_opts__last_field expected_revision 349 350 /** 351 * @brief **bpf_prog_attach_opts()** attaches the BPF program corresponding to 352 * *prog_fd* to a *target* which can represent a file descriptor or netdevice 353 * ifindex. 354 * 355 * @param prog_fd BPF program file descriptor 356 * @param target attach location file descriptor or ifindex 357 * @param type attach type for the BPF program 358 * @param opts options for configuring the attachment 359 * @return 0, on success; negative error code, otherwise (errno is also set to 360 * the error code) 361 */ 362 LIBBPF_API int bpf_prog_attach_opts(int prog_fd, int target, 363 enum bpf_attach_type type, 364 const struct bpf_prog_attach_opts *opts); 365 366 /** 367 * @brief **bpf_prog_detach_opts()** detaches the BPF program corresponding to 368 * *prog_fd* from a *target* which can represent a file descriptor or netdevice 369 * ifindex. 370 * 371 * @param prog_fd BPF program file descriptor 372 * @param target detach location file descriptor or ifindex 373 * @param type detach type for the BPF program 374 * @param opts options for configuring the detachment 375 * @return 0, on success; negative error code, otherwise (errno is also set to 376 * the error code) 377 */ 378 LIBBPF_API int bpf_prog_detach_opts(int prog_fd, int target, 379 enum bpf_attach_type type, 380 const struct bpf_prog_detach_opts *opts); 381 382 union bpf_iter_link_info; /* defined in up-to-date linux/bpf.h */ 383 struct bpf_link_create_opts { 384 size_t sz; /* size of this struct for forward/backward compatibility */ 385 __u32 flags; 386 union bpf_iter_link_info *iter_info; 387 __u32 iter_info_len; 388 __u32 target_btf_id; 389 union { 390 struct { 391 __u64 bpf_cookie; 392 } perf_event; 393 struct { 394 __u32 flags; 395 __u32 cnt; 396 const char **syms; 397 const unsigned long *addrs; 398 const __u64 *cookies; 399 } kprobe_multi; 400 struct { 401 __u32 flags; 402 __u32 cnt; 403 const char *path; 404 const unsigned long *offsets; 405 const unsigned long *ref_ctr_offsets; 406 const __u64 *cookies; 407 __u32 pid; 408 } uprobe_multi; 409 struct { 410 __u64 cookie; 411 } tracing; 412 struct { 413 __u32 pf; 414 __u32 hooknum; 415 __s32 priority; 416 __u32 flags; 417 } netfilter; 418 struct { 419 __u32 relative_fd; 420 __u32 relative_id; 421 __u64 expected_revision; 422 } tcx; 423 struct { 424 __u32 relative_fd; 425 __u32 relative_id; 426 __u64 expected_revision; 427 } netkit; 428 }; 429 size_t :0; 430 }; 431 #define bpf_link_create_opts__last_field uprobe_multi.pid 432 433 LIBBPF_API int bpf_link_create(int prog_fd, int target_fd, 434 enum bpf_attach_type attach_type, 435 const struct bpf_link_create_opts *opts); 436 437 LIBBPF_API int bpf_link_detach(int link_fd); 438 439 struct bpf_link_update_opts { 440 size_t sz; /* size of this struct for forward/backward compatibility */ 441 __u32 flags; /* extra flags */ 442 __u32 old_prog_fd; /* expected old program FD */ 443 __u32 old_map_fd; /* expected old map FD */ 444 }; 445 #define bpf_link_update_opts__last_field old_map_fd 446 447 LIBBPF_API int bpf_link_update(int link_fd, int new_prog_fd, 448 const struct bpf_link_update_opts *opts); 449 450 LIBBPF_API int bpf_iter_create(int link_fd); 451 452 struct bpf_prog_test_run_attr { 453 int prog_fd; 454 int repeat; 455 const void *data_in; 456 __u32 data_size_in; 457 void *data_out; /* optional */ 458 __u32 data_size_out; /* in: max length of data_out 459 * out: length of data_out */ 460 __u32 retval; /* out: return code of the BPF program */ 461 __u32 duration; /* out: average per repetition in ns */ 462 const void *ctx_in; /* optional */ 463 __u32 ctx_size_in; 464 void *ctx_out; /* optional */ 465 __u32 ctx_size_out; /* in: max length of ctx_out 466 * out: length of cxt_out */ 467 }; 468 469 LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id); 470 LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id); 471 LIBBPF_API int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id); 472 LIBBPF_API int bpf_link_get_next_id(__u32 start_id, __u32 *next_id); 473 474 struct bpf_get_fd_by_id_opts { 475 size_t sz; /* size of this struct for forward/backward compatibility */ 476 __u32 open_flags; /* permissions requested for the operation on fd */ 477 size_t :0; 478 }; 479 #define bpf_get_fd_by_id_opts__last_field open_flags 480 481 LIBBPF_API int bpf_prog_get_fd_by_id(__u32 id); 482 LIBBPF_API int bpf_prog_get_fd_by_id_opts(__u32 id, 483 const struct bpf_get_fd_by_id_opts *opts); 484 LIBBPF_API int bpf_map_get_fd_by_id(__u32 id); 485 LIBBPF_API int bpf_map_get_fd_by_id_opts(__u32 id, 486 const struct bpf_get_fd_by_id_opts *opts); 487 LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id); 488 LIBBPF_API int bpf_btf_get_fd_by_id_opts(__u32 id, 489 const struct bpf_get_fd_by_id_opts *opts); 490 LIBBPF_API int bpf_link_get_fd_by_id(__u32 id); 491 LIBBPF_API int bpf_link_get_fd_by_id_opts(__u32 id, 492 const struct bpf_get_fd_by_id_opts *opts); 493 LIBBPF_API int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len); 494 495 /** 496 * @brief **bpf_prog_get_info_by_fd()** obtains information about the BPF 497 * program corresponding to *prog_fd*. 498 * 499 * Populates up to *info_len* bytes of *info* and updates *info_len* with the 500 * actual number of bytes written to *info*. 501 * 502 * @param prog_fd BPF program file descriptor 503 * @param info pointer to **struct bpf_prog_info** that will be populated with 504 * BPF program information 505 * @param info_len pointer to the size of *info*; on success updated with the 506 * number of bytes written to *info* 507 * @return 0, on success; negative error code, otherwise (errno is also set to 508 * the error code) 509 */ 510 LIBBPF_API int bpf_prog_get_info_by_fd(int prog_fd, struct bpf_prog_info *info, __u32 *info_len); 511 512 /** 513 * @brief **bpf_map_get_info_by_fd()** obtains information about the BPF 514 * map corresponding to *map_fd*. 515 * 516 * Populates up to *info_len* bytes of *info* and updates *info_len* with the 517 * actual number of bytes written to *info*. 518 * 519 * @param map_fd BPF map file descriptor 520 * @param info pointer to **struct bpf_map_info** that will be populated with 521 * BPF map information 522 * @param info_len pointer to the size of *info*; on success updated with the 523 * number of bytes written to *info* 524 * @return 0, on success; negative error code, otherwise (errno is also set to 525 * the error code) 526 */ 527 LIBBPF_API int bpf_map_get_info_by_fd(int map_fd, struct bpf_map_info *info, __u32 *info_len); 528 529 /** 530 * @brief **bpf_btf_get_info_by_fd()** obtains information about the 531 * BTF object corresponding to *btf_fd*. 532 * 533 * Populates up to *info_len* bytes of *info* and updates *info_len* with the 534 * actual number of bytes written to *info*. 535 * 536 * @param btf_fd BTF object file descriptor 537 * @param info pointer to **struct bpf_btf_info** that will be populated with 538 * BTF object information 539 * @param info_len pointer to the size of *info*; on success updated with the 540 * number of bytes written to *info* 541 * @return 0, on success; negative error code, otherwise (errno is also set to 542 * the error code) 543 */ 544 LIBBPF_API int bpf_btf_get_info_by_fd(int btf_fd, struct bpf_btf_info *info, __u32 *info_len); 545 546 /** 547 * @brief **bpf_btf_get_info_by_fd()** obtains information about the BPF 548 * link corresponding to *link_fd*. 549 * 550 * Populates up to *info_len* bytes of *info* and updates *info_len* with the 551 * actual number of bytes written to *info*. 552 * 553 * @param link_fd BPF link file descriptor 554 * @param info pointer to **struct bpf_link_info** that will be populated with 555 * BPF link information 556 * @param info_len pointer to the size of *info*; on success updated with the 557 * number of bytes written to *info* 558 * @return 0, on success; negative error code, otherwise (errno is also set to 559 * the error code) 560 */ 561 LIBBPF_API int bpf_link_get_info_by_fd(int link_fd, struct bpf_link_info *info, __u32 *info_len); 562 563 struct bpf_prog_query_opts { 564 size_t sz; /* size of this struct for forward/backward compatibility */ 565 __u32 query_flags; 566 __u32 attach_flags; /* output argument */ 567 __u32 *prog_ids; 568 union { 569 /* input+output argument */ 570 __u32 prog_cnt; 571 __u32 count; 572 }; 573 __u32 *prog_attach_flags; 574 __u32 *link_ids; 575 __u32 *link_attach_flags; 576 __u64 revision; 577 size_t :0; 578 }; 579 #define bpf_prog_query_opts__last_field revision 580 581 /** 582 * @brief **bpf_prog_query_opts()** queries the BPF programs and BPF links 583 * which are attached to *target* which can represent a file descriptor or 584 * netdevice ifindex. 585 * 586 * @param target query location file descriptor or ifindex 587 * @param type attach type for the BPF program 588 * @param opts options for configuring the query 589 * @return 0, on success; negative error code, otherwise (errno is also set to 590 * the error code) 591 */ 592 LIBBPF_API int bpf_prog_query_opts(int target, enum bpf_attach_type type, 593 struct bpf_prog_query_opts *opts); 594 LIBBPF_API int bpf_prog_query(int target_fd, enum bpf_attach_type type, 595 __u32 query_flags, __u32 *attach_flags, 596 __u32 *prog_ids, __u32 *prog_cnt); 597 598 LIBBPF_API int bpf_raw_tracepoint_open(const char *name, int prog_fd); 599 LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, 600 __u32 *buf_len, __u32 *prog_id, __u32 *fd_type, 601 __u64 *probe_offset, __u64 *probe_addr); 602 603 #ifdef __cplusplus 604 /* forward-declaring enums in C++ isn't compatible with pure C enums, so 605 * instead define bpf_enable_stats() as accepting int as an input 606 */ 607 LIBBPF_API int bpf_enable_stats(int type); 608 #else 609 enum bpf_stats_type; /* defined in up-to-date linux/bpf.h */ 610 LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); 611 #endif 612 613 struct bpf_prog_bind_opts { 614 size_t sz; /* size of this struct for forward/backward compatibility */ 615 __u32 flags; 616 }; 617 #define bpf_prog_bind_opts__last_field flags 618 619 LIBBPF_API int bpf_prog_bind_map(int prog_fd, int map_fd, 620 const struct bpf_prog_bind_opts *opts); 621 622 struct bpf_test_run_opts { 623 size_t sz; /* size of this struct for forward/backward compatibility */ 624 const void *data_in; /* optional */ 625 void *data_out; /* optional */ 626 __u32 data_size_in; 627 __u32 data_size_out; /* in: max length of data_out 628 * out: length of data_out 629 */ 630 const void *ctx_in; /* optional */ 631 void *ctx_out; /* optional */ 632 __u32 ctx_size_in; 633 __u32 ctx_size_out; /* in: max length of ctx_out 634 * out: length of cxt_out 635 */ 636 __u32 retval; /* out: return code of the BPF program */ 637 int repeat; 638 __u32 duration; /* out: average per repetition in ns */ 639 __u32 flags; 640 __u32 cpu; 641 __u32 batch_size; 642 }; 643 #define bpf_test_run_opts__last_field batch_size 644 645 LIBBPF_API int bpf_prog_test_run_opts(int prog_fd, 646 struct bpf_test_run_opts *opts); 647 648 struct bpf_token_create_opts { 649 size_t sz; /* size of this struct for forward/backward compatibility */ 650 __u32 flags; 651 size_t :0; 652 }; 653 #define bpf_token_create_opts__last_field flags 654 655 /** 656 * @brief **bpf_token_create()** creates a new instance of BPF token derived 657 * from specified BPF FS mount point. 658 * 659 * BPF token created with this API can be passed to bpf() syscall for 660 * commands like BPF_PROG_LOAD, BPF_MAP_CREATE, etc. 661 * 662 * @param bpffs_fd FD for BPF FS instance from which to derive a BPF token 663 * instance. 664 * @param opts optional BPF token creation options, can be NULL 665 * 666 * @return BPF token FD > 0, on success; negative error code, otherwise (errno 667 * is also set to the error code) 668 */ 669 LIBBPF_API int bpf_token_create(int bpffs_fd, 670 struct bpf_token_create_opts *opts); 671 672 #ifdef __cplusplus 673 } /* extern "C" */ 674 #endif 675 676 #endif /* __LIBBPF_BPF_H */ 677