/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */12/*3* Common BPF ELF operations.4*5* Copyright (C) 2013-2015 Alexei Starovoitov <[email protected]>6* Copyright (C) 2015 Wang Nan <[email protected]>7* Copyright (C) 2015 Huawei Inc.8*9* This program is free software; you can redistribute it and/or10* modify it under the terms of the GNU Lesser General Public11* License as published by the Free Software Foundation;12* version 2.1 of the License (not later!)13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU Lesser General Public License for more details.18*19* You should have received a copy of the GNU Lesser General Public20* License along with this program; if not, see <http://www.gnu.org/licenses>21*/22#ifndef __LIBBPF_BPF_H23#define __LIBBPF_BPF_H2425#include <linux/bpf.h>26#include <stdbool.h>27#include <stddef.h>28#include <stdint.h>2930#include "libbpf_common.h"31#include "libbpf_legacy.h"3233#ifdef __cplusplus34extern "C" {35#endif3637LIBBPF_API int libbpf_set_memlock_rlim(size_t memlock_bytes);3839struct bpf_map_create_opts {40size_t sz; /* size of this struct for forward/backward compatibility */4142__u32 btf_fd;43__u32 btf_key_type_id;44__u32 btf_value_type_id;45__u32 btf_vmlinux_value_type_id;4647__u32 inner_map_fd;48__u32 map_flags;49__u64 map_extra;5051__u32 numa_node;52__u32 map_ifindex;53__s32 value_type_btf_obj_fd;5455__u32 token_fd;5657const void *excl_prog_hash;58__u32 excl_prog_hash_size;59size_t :0;60};61#define bpf_map_create_opts__last_field excl_prog_hash_size6263LIBBPF_API int bpf_map_create(enum bpf_map_type map_type,64const char *map_name,65__u32 key_size,66__u32 value_size,67__u32 max_entries,68const struct bpf_map_create_opts *opts);6970struct bpf_prog_load_opts {71size_t sz; /* size of this struct for forward/backward compatibility */7273/* libbpf can retry BPF_PROG_LOAD command if bpf() syscall returns74* -EAGAIN. This field determines how many attempts libbpf has to75* make. If not specified, libbpf will use default value of 5.76*/77int attempts;7879enum bpf_attach_type expected_attach_type;80__u32 prog_btf_fd;81__u32 prog_flags;82__u32 prog_ifindex;83__u32 kern_version;8485__u32 attach_btf_id;86__u32 attach_prog_fd;87__u32 attach_btf_obj_fd;8889const int *fd_array;9091/* .BTF.ext func info data */92const void *func_info;93__u32 func_info_cnt;94__u32 func_info_rec_size;9596/* .BTF.ext line info data */97const void *line_info;98__u32 line_info_cnt;99__u32 line_info_rec_size;100101/* verifier log options */102__u32 log_level;103__u32 log_size;104char *log_buf;105/* output: actual total log contents size (including terminating zero).106* It could be both larger than original log_size (if log was107* truncated), or smaller (if log buffer wasn't filled completely).108* If kernel doesn't support this feature, log_size is left unchanged.109*/110__u32 log_true_size;111__u32 token_fd;112113/* if set, provides the length of fd_array */114__u32 fd_array_cnt;115size_t :0;116};117#define bpf_prog_load_opts__last_field fd_array_cnt118119LIBBPF_API int bpf_prog_load(enum bpf_prog_type prog_type,120const char *prog_name, const char *license,121const struct bpf_insn *insns, size_t insn_cnt,122struct bpf_prog_load_opts *opts);123124/* Flags to direct loading requirements */125#define MAPS_RELAX_COMPAT 0x01126127/* Recommended log buffer size */128#define BPF_LOG_BUF_SIZE (UINT32_MAX >> 8) /* verifier maximum in kernels <= 5.1 */129130struct bpf_btf_load_opts {131size_t sz; /* size of this struct for forward/backward compatibility */132133/* kernel log options */134char *log_buf;135__u32 log_level;136__u32 log_size;137/* output: actual total log contents size (including terminating zero).138* It could be both larger than original log_size (if log was139* truncated), or smaller (if log buffer wasn't filled completely).140* If kernel doesn't support this feature, log_size is left unchanged.141*/142__u32 log_true_size;143144__u32 btf_flags;145__u32 token_fd;146size_t :0;147};148#define bpf_btf_load_opts__last_field token_fd149150LIBBPF_API int bpf_btf_load(const void *btf_data, size_t btf_size,151struct bpf_btf_load_opts *opts);152153LIBBPF_API int bpf_map_update_elem(int fd, const void *key, const void *value,154__u64 flags);155156LIBBPF_API int bpf_map_lookup_elem(int fd, const void *key, void *value);157LIBBPF_API int bpf_map_lookup_elem_flags(int fd, const void *key, void *value,158__u64 flags);159LIBBPF_API int bpf_map_lookup_and_delete_elem(int fd, const void *key,160void *value);161LIBBPF_API int bpf_map_lookup_and_delete_elem_flags(int fd, const void *key,162void *value, __u64 flags);163LIBBPF_API int bpf_map_delete_elem(int fd, const void *key);164LIBBPF_API int bpf_map_delete_elem_flags(int fd, const void *key, __u64 flags);165LIBBPF_API int bpf_map_get_next_key(int fd, const void *key, void *next_key);166LIBBPF_API int bpf_map_freeze(int fd);167168struct bpf_map_batch_opts {169size_t sz; /* size of this struct for forward/backward compatibility */170__u64 elem_flags;171__u64 flags;172};173#define bpf_map_batch_opts__last_field flags174175176/**177* @brief **bpf_map_delete_batch()** allows for batch deletion of multiple178* elements in a BPF map.179*180* @param fd BPF map file descriptor181* @param keys pointer to an array of *count* keys182* @param count input and output parameter; on input **count** represents the183* number of elements in the map to delete in batch;184* on output if a non-EFAULT error is returned, **count** represents the number of deleted185* elements if the output **count** value is not equal to the input **count** value186* If EFAULT is returned, **count** should not be trusted to be correct.187* @param opts options for configuring the way the batch deletion works188* @return 0, on success; negative error code, otherwise (errno is also set to189* the error code)190*/191LIBBPF_API int bpf_map_delete_batch(int fd, const void *keys,192__u32 *count,193const struct bpf_map_batch_opts *opts);194195/**196* @brief **bpf_map_lookup_batch()** allows for batch lookup of BPF map elements.197*198* The parameter *in_batch* is the address of the first element in the batch to199* read. *out_batch* is an output parameter that should be passed as *in_batch*200* to subsequent calls to **bpf_map_lookup_batch()**. NULL can be passed for201* *in_batch* to indicate that the batched lookup starts from the beginning of202* the map. Both *in_batch* and *out_batch* must point to memory large enough to203* hold a single key, except for maps of type **BPF_MAP_TYPE_{HASH, PERCPU_HASH,204* LRU_HASH, LRU_PERCPU_HASH}**, for which the memory size must be at205* least 4 bytes wide regardless of key size.206*207* The *keys* and *values* are output parameters which must point to memory large enough to208* hold *count* items based on the key and value size of the map *map_fd*. The *keys*209* buffer must be of *key_size* * *count*. The *values* buffer must be of210* *value_size* * *count*.211*212* @param fd BPF map file descriptor213* @param in_batch address of the first element in batch to read, can pass NULL to214* indicate that the batched lookup starts from the beginning of the map.215* @param out_batch output parameter that should be passed to next call as *in_batch*216* @param keys pointer to an array large enough for *count* keys217* @param values pointer to an array large enough for *count* values218* @param count input and output parameter; on input it's the number of elements219* in the map to read in batch; on output it's the number of elements that were220* successfully read.221* If a non-EFAULT error is returned, count will be set as the number of elements222* that were read before the error occurred.223* If EFAULT is returned, **count** should not be trusted to be correct.224* @param opts options for configuring the way the batch lookup works225* @return 0, on success; negative error code, otherwise (errno is also set to226* the error code)227*/228LIBBPF_API int bpf_map_lookup_batch(int fd, void *in_batch, void *out_batch,229void *keys, void *values, __u32 *count,230const struct bpf_map_batch_opts *opts);231232/**233* @brief **bpf_map_lookup_and_delete_batch()** allows for batch lookup and deletion234* of BPF map elements where each element is deleted after being retrieved.235*236* @param fd BPF map file descriptor237* @param in_batch address of the first element in batch to read, can pass NULL to238* get address of the first element in *out_batch*. If not NULL, must be large239* enough to hold a key. For **BPF_MAP_TYPE_{HASH, PERCPU_HASH, LRU_HASH,240* LRU_PERCPU_HASH}**, the memory size must be at least 4 bytes wide regardless241* of key size.242* @param out_batch output parameter that should be passed to next call as *in_batch*243* @param keys pointer to an array of *count* keys244* @param values pointer to an array large enough for *count* values245* @param count input and output parameter; on input it's the number of elements246* in the map to read and delete in batch; on output it represents the number of247* elements that were successfully read and deleted248* If a non-**EFAULT** error code is returned and if the output **count** value249* is not equal to the input **count** value, up to **count** elements may250* have been deleted.251* if **EFAULT** is returned up to *count* elements may have been deleted without252* being returned via the *keys* and *values* output parameters.253* @param opts options for configuring the way the batch lookup and delete works254* @return 0, on success; negative error code, otherwise (errno is also set to255* the error code)256*/257LIBBPF_API int bpf_map_lookup_and_delete_batch(int fd, void *in_batch,258void *out_batch, void *keys,259void *values, __u32 *count,260const struct bpf_map_batch_opts *opts);261262/**263* @brief **bpf_map_update_batch()** updates multiple elements in a map264* by specifying keys and their corresponding values.265*266* The *keys* and *values* parameters must point to memory large enough267* to hold *count* items based on the key and value size of the map.268*269* The *opts* parameter can be used to control how *bpf_map_update_batch()*270* should handle keys that either do or do not already exist in the map.271* In particular the *flags* parameter of *bpf_map_batch_opts* can be272* one of the following:273*274* Note that *count* is an input and output parameter, where on output it275* represents how many elements were successfully updated. Also note that if276* **EFAULT** then *count* should not be trusted to be correct.277*278* **BPF_ANY**279* Create new elements or update existing.280*281* **BPF_NOEXIST**282* Create new elements only if they do not exist.283*284* **BPF_EXIST**285* Update existing elements.286*287* **BPF_F_LOCK**288* Update spin_lock-ed map elements. This must be289* specified if the map value contains a spinlock.290*291* @param fd BPF map file descriptor292* @param keys pointer to an array of *count* keys293* @param values pointer to an array of *count* values294* @param count input and output parameter; on input it's the number of elements295* in the map to update in batch; on output if a non-EFAULT error is returned,296* **count** represents the number of updated elements if the output **count**297* value is not equal to the input **count** value.298* If EFAULT is returned, **count** should not be trusted to be correct.299* @param opts options for configuring the way the batch update works300* @return 0, on success; negative error code, otherwise (errno is also set to301* the error code)302*/303LIBBPF_API int bpf_map_update_batch(int fd, const void *keys, const void *values,304__u32 *count,305const struct bpf_map_batch_opts *opts);306307struct bpf_obj_pin_opts {308size_t sz; /* size of this struct for forward/backward compatibility */309310__u32 file_flags;311int path_fd;312313size_t :0;314};315#define bpf_obj_pin_opts__last_field path_fd316317LIBBPF_API int bpf_obj_pin(int fd, const char *pathname);318LIBBPF_API int bpf_obj_pin_opts(int fd, const char *pathname,319const struct bpf_obj_pin_opts *opts);320321struct bpf_obj_get_opts {322size_t sz; /* size of this struct for forward/backward compatibility */323324__u32 file_flags;325int path_fd;326327size_t :0;328};329#define bpf_obj_get_opts__last_field path_fd330331LIBBPF_API int bpf_obj_get(const char *pathname);332LIBBPF_API int bpf_obj_get_opts(const char *pathname,333const struct bpf_obj_get_opts *opts);334335LIBBPF_API int bpf_prog_attach(int prog_fd, int attachable_fd,336enum bpf_attach_type type, unsigned int flags);337LIBBPF_API int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type);338LIBBPF_API int bpf_prog_detach2(int prog_fd, int attachable_fd,339enum bpf_attach_type type);340341struct bpf_prog_attach_opts {342size_t sz; /* size of this struct for forward/backward compatibility */343__u32 flags;344union {345int replace_prog_fd;346int replace_fd;347};348int relative_fd;349__u32 relative_id;350__u64 expected_revision;351size_t :0;352};353#define bpf_prog_attach_opts__last_field expected_revision354355struct bpf_prog_detach_opts {356size_t sz; /* size of this struct for forward/backward compatibility */357__u32 flags;358int relative_fd;359__u32 relative_id;360__u64 expected_revision;361size_t :0;362};363#define bpf_prog_detach_opts__last_field expected_revision364365/**366* @brief **bpf_prog_attach_opts()** attaches the BPF program corresponding to367* *prog_fd* to a *target* which can represent a file descriptor or netdevice368* ifindex.369*370* @param prog_fd BPF program file descriptor371* @param target attach location file descriptor or ifindex372* @param type attach type for the BPF program373* @param opts options for configuring the attachment374* @return 0, on success; negative error code, otherwise (errno is also set to375* the error code)376*/377LIBBPF_API int bpf_prog_attach_opts(int prog_fd, int target,378enum bpf_attach_type type,379const struct bpf_prog_attach_opts *opts);380381/**382* @brief **bpf_prog_detach_opts()** detaches the BPF program corresponding to383* *prog_fd* from a *target* which can represent a file descriptor or netdevice384* ifindex.385*386* @param prog_fd BPF program file descriptor387* @param target detach location file descriptor or ifindex388* @param type detach type for the BPF program389* @param opts options for configuring the detachment390* @return 0, on success; negative error code, otherwise (errno is also set to391* the error code)392*/393LIBBPF_API int bpf_prog_detach_opts(int prog_fd, int target,394enum bpf_attach_type type,395const struct bpf_prog_detach_opts *opts);396397union bpf_iter_link_info; /* defined in up-to-date linux/bpf.h */398struct bpf_link_create_opts {399size_t sz; /* size of this struct for forward/backward compatibility */400__u32 flags;401union bpf_iter_link_info *iter_info;402__u32 iter_info_len;403__u32 target_btf_id;404union {405struct {406__u64 bpf_cookie;407} perf_event;408struct {409__u32 flags;410__u32 cnt;411const char **syms;412const unsigned long *addrs;413const __u64 *cookies;414} kprobe_multi;415struct {416__u32 flags;417__u32 cnt;418const char *path;419const unsigned long *offsets;420const unsigned long *ref_ctr_offsets;421const __u64 *cookies;422__u32 pid;423} uprobe_multi;424struct {425__u64 cookie;426} tracing;427struct {428__u32 pf;429__u32 hooknum;430__s32 priority;431__u32 flags;432} netfilter;433struct {434__u32 relative_fd;435__u32 relative_id;436__u64 expected_revision;437} tcx;438struct {439__u32 relative_fd;440__u32 relative_id;441__u64 expected_revision;442} netkit;443struct {444__u32 relative_fd;445__u32 relative_id;446__u64 expected_revision;447} cgroup;448};449size_t :0;450};451#define bpf_link_create_opts__last_field uprobe_multi.pid452453LIBBPF_API int bpf_link_create(int prog_fd, int target_fd,454enum bpf_attach_type attach_type,455const struct bpf_link_create_opts *opts);456457LIBBPF_API int bpf_link_detach(int link_fd);458459struct bpf_link_update_opts {460size_t sz; /* size of this struct for forward/backward compatibility */461__u32 flags; /* extra flags */462__u32 old_prog_fd; /* expected old program FD */463__u32 old_map_fd; /* expected old map FD */464};465#define bpf_link_update_opts__last_field old_map_fd466467LIBBPF_API int bpf_link_update(int link_fd, int new_prog_fd,468const struct bpf_link_update_opts *opts);469470LIBBPF_API int bpf_iter_create(int link_fd);471472struct bpf_prog_test_run_attr {473int prog_fd;474int repeat;475const void *data_in;476__u32 data_size_in;477void *data_out; /* optional */478__u32 data_size_out; /* in: max length of data_out479* out: length of data_out */480__u32 retval; /* out: return code of the BPF program */481__u32 duration; /* out: average per repetition in ns */482const void *ctx_in; /* optional */483__u32 ctx_size_in;484void *ctx_out; /* optional */485__u32 ctx_size_out; /* in: max length of ctx_out486* out: length of cxt_out */487};488489LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id);490LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id);491LIBBPF_API int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id);492LIBBPF_API int bpf_link_get_next_id(__u32 start_id, __u32 *next_id);493494struct bpf_get_fd_by_id_opts {495size_t sz; /* size of this struct for forward/backward compatibility */496__u32 open_flags; /* permissions requested for the operation on fd */497__u32 token_fd;498size_t :0;499};500#define bpf_get_fd_by_id_opts__last_field token_fd501502LIBBPF_API int bpf_prog_get_fd_by_id(__u32 id);503LIBBPF_API int bpf_prog_get_fd_by_id_opts(__u32 id,504const struct bpf_get_fd_by_id_opts *opts);505LIBBPF_API int bpf_map_get_fd_by_id(__u32 id);506LIBBPF_API int bpf_map_get_fd_by_id_opts(__u32 id,507const struct bpf_get_fd_by_id_opts *opts);508LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id);509LIBBPF_API int bpf_btf_get_fd_by_id_opts(__u32 id,510const struct bpf_get_fd_by_id_opts *opts);511LIBBPF_API int bpf_link_get_fd_by_id(__u32 id);512LIBBPF_API int bpf_link_get_fd_by_id_opts(__u32 id,513const struct bpf_get_fd_by_id_opts *opts);514LIBBPF_API int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len);515516/**517* @brief **bpf_prog_get_info_by_fd()** obtains information about the BPF518* program corresponding to *prog_fd*.519*520* Populates up to *info_len* bytes of *info* and updates *info_len* with the521* actual number of bytes written to *info*. Note that *info* should be522* zero-initialized or initialized as expected by the requested *info*523* type. Failing to (zero-)initialize *info* under certain circumstances can524* result in this helper returning an error.525*526* @param prog_fd BPF program file descriptor527* @param info pointer to **struct bpf_prog_info** that will be populated with528* BPF program information529* @param info_len pointer to the size of *info*; on success updated with the530* number of bytes written to *info*531* @return 0, on success; negative error code, otherwise (errno is also set to532* the error code)533*/534LIBBPF_API int bpf_prog_get_info_by_fd(int prog_fd, struct bpf_prog_info *info, __u32 *info_len);535536/**537* @brief **bpf_map_get_info_by_fd()** obtains information about the BPF538* map corresponding to *map_fd*.539*540* Populates up to *info_len* bytes of *info* and updates *info_len* with the541* actual number of bytes written to *info*. Note that *info* should be542* zero-initialized or initialized as expected by the requested *info*543* type. Failing to (zero-)initialize *info* under certain circumstances can544* result in this helper returning an error.545*546* @param map_fd BPF map file descriptor547* @param info pointer to **struct bpf_map_info** that will be populated with548* BPF map information549* @param info_len pointer to the size of *info*; on success updated with the550* number of bytes written to *info*551* @return 0, on success; negative error code, otherwise (errno is also set to552* the error code)553*/554LIBBPF_API int bpf_map_get_info_by_fd(int map_fd, struct bpf_map_info *info, __u32 *info_len);555556/**557* @brief **bpf_btf_get_info_by_fd()** obtains information about the558* BTF object corresponding to *btf_fd*.559*560* Populates up to *info_len* bytes of *info* and updates *info_len* with the561* actual number of bytes written to *info*. Note that *info* should be562* zero-initialized or initialized as expected by the requested *info*563* type. Failing to (zero-)initialize *info* under certain circumstances can564* result in this helper returning an error.565*566* @param btf_fd BTF object file descriptor567* @param info pointer to **struct bpf_btf_info** that will be populated with568* BTF object information569* @param info_len pointer to the size of *info*; on success updated with the570* number of bytes written to *info*571* @return 0, on success; negative error code, otherwise (errno is also set to572* the error code)573*/574LIBBPF_API int bpf_btf_get_info_by_fd(int btf_fd, struct bpf_btf_info *info, __u32 *info_len);575576/**577* @brief **bpf_btf_get_info_by_fd()** obtains information about the BPF578* link corresponding to *link_fd*.579*580* Populates up to *info_len* bytes of *info* and updates *info_len* with the581* actual number of bytes written to *info*. Note that *info* should be582* zero-initialized or initialized as expected by the requested *info*583* type. Failing to (zero-)initialize *info* under certain circumstances can584* result in this helper returning an error.585*586* @param link_fd BPF link file descriptor587* @param info pointer to **struct bpf_link_info** that will be populated with588* BPF link information589* @param info_len pointer to the size of *info*; on success updated with the590* number of bytes written to *info*591* @return 0, on success; negative error code, otherwise (errno is also set to592* the error code)593*/594LIBBPF_API int bpf_link_get_info_by_fd(int link_fd, struct bpf_link_info *info, __u32 *info_len);595596struct bpf_prog_query_opts {597size_t sz; /* size of this struct for forward/backward compatibility */598__u32 query_flags;599__u32 attach_flags; /* output argument */600__u32 *prog_ids;601union {602/* input+output argument */603__u32 prog_cnt;604__u32 count;605};606__u32 *prog_attach_flags;607__u32 *link_ids;608__u32 *link_attach_flags;609__u64 revision;610size_t :0;611};612#define bpf_prog_query_opts__last_field revision613614/**615* @brief **bpf_prog_query_opts()** queries the BPF programs and BPF links616* which are attached to *target* which can represent a file descriptor or617* netdevice ifindex.618*619* @param target query location file descriptor or ifindex620* @param type attach type for the BPF program621* @param opts options for configuring the query622* @return 0, on success; negative error code, otherwise (errno is also set to623* the error code)624*/625LIBBPF_API int bpf_prog_query_opts(int target, enum bpf_attach_type type,626struct bpf_prog_query_opts *opts);627LIBBPF_API int bpf_prog_query(int target_fd, enum bpf_attach_type type,628__u32 query_flags, __u32 *attach_flags,629__u32 *prog_ids, __u32 *prog_cnt);630631struct bpf_raw_tp_opts {632size_t sz; /* size of this struct for forward/backward compatibility */633const char *tp_name;634__u64 cookie;635size_t :0;636};637#define bpf_raw_tp_opts__last_field cookie638639LIBBPF_API int bpf_raw_tracepoint_open_opts(int prog_fd, struct bpf_raw_tp_opts *opts);640LIBBPF_API int bpf_raw_tracepoint_open(const char *name, int prog_fd);641LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf,642__u32 *buf_len, __u32 *prog_id, __u32 *fd_type,643__u64 *probe_offset, __u64 *probe_addr);644645#ifdef __cplusplus646/* forward-declaring enums in C++ isn't compatible with pure C enums, so647* instead define bpf_enable_stats() as accepting int as an input648*/649LIBBPF_API int bpf_enable_stats(int type);650#else651enum bpf_stats_type; /* defined in up-to-date linux/bpf.h */652LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type);653#endif654655struct bpf_prog_bind_opts {656size_t sz; /* size of this struct for forward/backward compatibility */657__u32 flags;658};659#define bpf_prog_bind_opts__last_field flags660661LIBBPF_API int bpf_prog_bind_map(int prog_fd, int map_fd,662const struct bpf_prog_bind_opts *opts);663664struct bpf_test_run_opts {665size_t sz; /* size of this struct for forward/backward compatibility */666const void *data_in; /* optional */667void *data_out; /* optional */668__u32 data_size_in;669__u32 data_size_out; /* in: max length of data_out670* out: length of data_out671*/672const void *ctx_in; /* optional */673void *ctx_out; /* optional */674__u32 ctx_size_in;675__u32 ctx_size_out; /* in: max length of ctx_out676* out: length of cxt_out677*/678__u32 retval; /* out: return code of the BPF program */679int repeat;680__u32 duration; /* out: average per repetition in ns */681__u32 flags;682__u32 cpu;683__u32 batch_size;684};685#define bpf_test_run_opts__last_field batch_size686687LIBBPF_API int bpf_prog_test_run_opts(int prog_fd,688struct bpf_test_run_opts *opts);689690struct bpf_token_create_opts {691size_t sz; /* size of this struct for forward/backward compatibility */692__u32 flags;693size_t :0;694};695#define bpf_token_create_opts__last_field flags696697/**698* @brief **bpf_token_create()** creates a new instance of BPF token derived699* from specified BPF FS mount point.700*701* BPF token created with this API can be passed to bpf() syscall for702* commands like BPF_PROG_LOAD, BPF_MAP_CREATE, etc.703*704* @param bpffs_fd FD for BPF FS instance from which to derive a BPF token705* instance.706* @param opts optional BPF token creation options, can be NULL707*708* @return BPF token FD > 0, on success; negative error code, otherwise (errno709* is also set to the error code)710*/711LIBBPF_API int bpf_token_create(int bpffs_fd,712struct bpf_token_create_opts *opts);713714struct bpf_prog_stream_read_opts {715size_t sz;716size_t :0;717};718#define bpf_prog_stream_read_opts__last_field sz719/**720* @brief **bpf_prog_stream_read** reads data from the BPF stream of a given BPF721* program.722*723* @param prog_fd FD for the BPF program whose BPF stream is to be read.724* @param stream_id ID of the BPF stream to be read.725* @param buf Buffer to read data into from the BPF stream.726* @param buf_len Maximum number of bytes to read from the BPF stream.727* @param opts optional options, can be NULL728*729* @return The number of bytes read, on success; negative error code, otherwise730* (errno is also set to the error code)731*/732LIBBPF_API int bpf_prog_stream_read(int prog_fd, __u32 stream_id, void *buf, __u32 buf_len,733struct bpf_prog_stream_read_opts *opts);734735#ifdef __cplusplus736} /* extern "C" */737#endif738739#endif /* __LIBBPF_BPF_H */740741742