/* 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;56size_t :0;57};58#define bpf_map_create_opts__last_field token_fd5960LIBBPF_API int bpf_map_create(enum bpf_map_type map_type,61const char *map_name,62__u32 key_size,63__u32 value_size,64__u32 max_entries,65const struct bpf_map_create_opts *opts);6667struct bpf_prog_load_opts {68size_t sz; /* size of this struct for forward/backward compatibility */6970/* libbpf can retry BPF_PROG_LOAD command if bpf() syscall returns71* -EAGAIN. This field determines how many attempts libbpf has to72* make. If not specified, libbpf will use default value of 5.73*/74int attempts;7576enum bpf_attach_type expected_attach_type;77__u32 prog_btf_fd;78__u32 prog_flags;79__u32 prog_ifindex;80__u32 kern_version;8182__u32 attach_btf_id;83__u32 attach_prog_fd;84__u32 attach_btf_obj_fd;8586const int *fd_array;8788/* .BTF.ext func info data */89const void *func_info;90__u32 func_info_cnt;91__u32 func_info_rec_size;9293/* .BTF.ext line info data */94const void *line_info;95__u32 line_info_cnt;96__u32 line_info_rec_size;9798/* verifier log options */99__u32 log_level;100__u32 log_size;101char *log_buf;102/* output: actual total log contents size (including terminating zero).103* It could be both larger than original log_size (if log was104* 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;109110/* if set, provides the length of fd_array */111__u32 fd_array_cnt;112size_t :0;113};114#define bpf_prog_load_opts__last_field fd_array_cnt115116LIBBPF_API int bpf_prog_load(enum bpf_prog_type prog_type,117const char *prog_name, const char *license,118const struct bpf_insn *insns, size_t insn_cnt,119struct bpf_prog_load_opts *opts);120121/* Flags to direct loading requirements */122#define MAPS_RELAX_COMPAT 0x01123124/* Recommended log buffer size */125#define BPF_LOG_BUF_SIZE (UINT32_MAX >> 8) /* verifier maximum in kernels <= 5.1 */126127struct bpf_btf_load_opts {128size_t sz; /* size of this struct for forward/backward compatibility */129130/* kernel log options */131char *log_buf;132__u32 log_level;133__u32 log_size;134/* output: actual total log contents size (including terminating zero).135* It could be both larger than original log_size (if log was136* truncated), or smaller (if log buffer wasn't filled completely).137* If kernel doesn't support this feature, log_size is left unchanged.138*/139__u32 log_true_size;140141__u32 btf_flags;142__u32 token_fd;143size_t :0;144};145#define bpf_btf_load_opts__last_field token_fd146147LIBBPF_API int bpf_btf_load(const void *btf_data, size_t btf_size,148struct bpf_btf_load_opts *opts);149150LIBBPF_API int bpf_map_update_elem(int fd, const void *key, const void *value,151__u64 flags);152153LIBBPF_API int bpf_map_lookup_elem(int fd, const void *key, void *value);154LIBBPF_API int bpf_map_lookup_elem_flags(int fd, const void *key, void *value,155__u64 flags);156LIBBPF_API int bpf_map_lookup_and_delete_elem(int fd, const void *key,157void *value);158LIBBPF_API int bpf_map_lookup_and_delete_elem_flags(int fd, const void *key,159void *value, __u64 flags);160LIBBPF_API int bpf_map_delete_elem(int fd, const void *key);161LIBBPF_API int bpf_map_delete_elem_flags(int fd, const void *key, __u64 flags);162LIBBPF_API int bpf_map_get_next_key(int fd, const void *key, void *next_key);163LIBBPF_API int bpf_map_freeze(int fd);164165struct bpf_map_batch_opts {166size_t sz; /* size of this struct for forward/backward compatibility */167__u64 elem_flags;168__u64 flags;169};170#define bpf_map_batch_opts__last_field flags171172173/**174* @brief **bpf_map_delete_batch()** allows for batch deletion of multiple175* elements in a BPF map.176*177* @param fd BPF map file descriptor178* @param keys pointer to an array of *count* keys179* @param count input and output parameter; on input **count** represents the180* number of elements in the map to delete in batch;181* on output if a non-EFAULT error is returned, **count** represents the number of deleted182* elements if the output **count** value is not equal to the input **count** value183* If EFAULT is returned, **count** should not be trusted to be correct.184* @param opts options for configuring the way the batch deletion works185* @return 0, on success; negative error code, otherwise (errno is also set to186* the error code)187*/188LIBBPF_API int bpf_map_delete_batch(int fd, const void *keys,189__u32 *count,190const struct bpf_map_batch_opts *opts);191192/**193* @brief **bpf_map_lookup_batch()** allows for batch lookup of BPF map elements.194*195* The parameter *in_batch* is the address of the first element in the batch to196* read. *out_batch* is an output parameter that should be passed as *in_batch*197* to subsequent calls to **bpf_map_lookup_batch()**. NULL can be passed for198* *in_batch* to indicate that the batched lookup starts from the beginning of199* the map. Both *in_batch* and *out_batch* must point to memory large enough to200* hold a single key, except for maps of type **BPF_MAP_TYPE_{HASH, PERCPU_HASH,201* LRU_HASH, LRU_PERCPU_HASH}**, for which the memory size must be at202* least 4 bytes wide regardless of key size.203*204* The *keys* and *values* are output parameters which must point to memory large enough to205* hold *count* items based on the key and value size of the map *map_fd*. The *keys*206* buffer must be of *key_size* * *count*. The *values* buffer must be of207* *value_size* * *count*.208*209* @param fd BPF map file descriptor210* @param in_batch address of the first element in batch to read, can pass NULL to211* indicate that the batched lookup starts from the beginning of the map.212* @param out_batch output parameter that should be passed to next call as *in_batch*213* @param keys pointer to an array large enough for *count* keys214* @param values pointer to an array large enough for *count* values215* @param count input and output parameter; on input it's the number of elements216* in the map to read in batch; on output it's the number of elements that were217* successfully read.218* If a non-EFAULT error is returned, count will be set as the number of elements219* that were read before the error occurred.220* If EFAULT is returned, **count** should not be trusted to be correct.221* @param opts options for configuring the way the batch lookup works222* @return 0, on success; negative error code, otherwise (errno is also set to223* the error code)224*/225LIBBPF_API int bpf_map_lookup_batch(int fd, void *in_batch, void *out_batch,226void *keys, void *values, __u32 *count,227const struct bpf_map_batch_opts *opts);228229/**230* @brief **bpf_map_lookup_and_delete_batch()** allows for batch lookup and deletion231* of BPF map elements where each element is deleted after being retrieved.232*233* @param fd BPF map file descriptor234* @param in_batch address of the first element in batch to read, can pass NULL to235* get address of the first element in *out_batch*. If not NULL, must be large236* enough to hold a key. For **BPF_MAP_TYPE_{HASH, PERCPU_HASH, LRU_HASH,237* LRU_PERCPU_HASH}**, the memory size must be at least 4 bytes wide regardless238* of key size.239* @param out_batch output parameter that should be passed to next call as *in_batch*240* @param keys pointer to an array of *count* keys241* @param values pointer to an array large enough for *count* values242* @param count input and output parameter; on input it's the number of elements243* in the map to read and delete in batch; on output it represents the number of244* elements that were successfully read and deleted245* If a non-**EFAULT** error code is returned and if the output **count** value246* is not equal to the input **count** value, up to **count** elements may247* have been deleted.248* if **EFAULT** is returned up to *count* elements may have been deleted without249* being returned via the *keys* and *values* output parameters.250* @param opts options for configuring the way the batch lookup and delete works251* @return 0, on success; negative error code, otherwise (errno is also set to252* the error code)253*/254LIBBPF_API int bpf_map_lookup_and_delete_batch(int fd, void *in_batch,255void *out_batch, void *keys,256void *values, __u32 *count,257const struct bpf_map_batch_opts *opts);258259/**260* @brief **bpf_map_update_batch()** updates multiple elements in a map261* by specifying keys and their corresponding values.262*263* The *keys* and *values* parameters must point to memory large enough264* to hold *count* items based on the key and value size of the map.265*266* The *opts* parameter can be used to control how *bpf_map_update_batch()*267* should handle keys that either do or do not already exist in the map.268* In particular the *flags* parameter of *bpf_map_batch_opts* can be269* one of the following:270*271* Note that *count* is an input and output parameter, where on output it272* represents how many elements were successfully updated. Also note that if273* **EFAULT** then *count* should not be trusted to be correct.274*275* **BPF_ANY**276* Create new elements or update existing.277*278* **BPF_NOEXIST**279* Create new elements only if they do not exist.280*281* **BPF_EXIST**282* Update existing elements.283*284* **BPF_F_LOCK**285* Update spin_lock-ed map elements. This must be286* specified if the map value contains a spinlock.287*288* @param fd BPF map file descriptor289* @param keys pointer to an array of *count* keys290* @param values pointer to an array of *count* values291* @param count input and output parameter; on input it's the number of elements292* in the map to update in batch; on output if a non-EFAULT error is returned,293* **count** represents the number of updated elements if the output **count**294* value is not equal to the input **count** value.295* If EFAULT is returned, **count** should not be trusted to be correct.296* @param opts options for configuring the way the batch update works297* @return 0, on success; negative error code, otherwise (errno is also set to298* the error code)299*/300LIBBPF_API int bpf_map_update_batch(int fd, const void *keys, const void *values,301__u32 *count,302const struct bpf_map_batch_opts *opts);303304struct bpf_obj_pin_opts {305size_t sz; /* size of this struct for forward/backward compatibility */306307__u32 file_flags;308int path_fd;309310size_t :0;311};312#define bpf_obj_pin_opts__last_field path_fd313314LIBBPF_API int bpf_obj_pin(int fd, const char *pathname);315LIBBPF_API int bpf_obj_pin_opts(int fd, const char *pathname,316const struct bpf_obj_pin_opts *opts);317318struct bpf_obj_get_opts {319size_t sz; /* size of this struct for forward/backward compatibility */320321__u32 file_flags;322int path_fd;323324size_t :0;325};326#define bpf_obj_get_opts__last_field path_fd327328LIBBPF_API int bpf_obj_get(const char *pathname);329LIBBPF_API int bpf_obj_get_opts(const char *pathname,330const struct bpf_obj_get_opts *opts);331332LIBBPF_API int bpf_prog_attach(int prog_fd, int attachable_fd,333enum bpf_attach_type type, unsigned int flags);334LIBBPF_API int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type);335LIBBPF_API int bpf_prog_detach2(int prog_fd, int attachable_fd,336enum bpf_attach_type type);337338struct bpf_prog_attach_opts {339size_t sz; /* size of this struct for forward/backward compatibility */340__u32 flags;341union {342int replace_prog_fd;343int replace_fd;344};345int relative_fd;346__u32 relative_id;347__u64 expected_revision;348size_t :0;349};350#define bpf_prog_attach_opts__last_field expected_revision351352struct bpf_prog_detach_opts {353size_t sz; /* size of this struct for forward/backward compatibility */354__u32 flags;355int relative_fd;356__u32 relative_id;357__u64 expected_revision;358size_t :0;359};360#define bpf_prog_detach_opts__last_field expected_revision361362/**363* @brief **bpf_prog_attach_opts()** attaches the BPF program corresponding to364* *prog_fd* to a *target* which can represent a file descriptor or netdevice365* ifindex.366*367* @param prog_fd BPF program file descriptor368* @param target attach location file descriptor or ifindex369* @param type attach type for the BPF program370* @param opts options for configuring the attachment371* @return 0, on success; negative error code, otherwise (errno is also set to372* the error code)373*/374LIBBPF_API int bpf_prog_attach_opts(int prog_fd, int target,375enum bpf_attach_type type,376const struct bpf_prog_attach_opts *opts);377378/**379* @brief **bpf_prog_detach_opts()** detaches the BPF program corresponding to380* *prog_fd* from a *target* which can represent a file descriptor or netdevice381* ifindex.382*383* @param prog_fd BPF program file descriptor384* @param target detach location file descriptor or ifindex385* @param type detach type for the BPF program386* @param opts options for configuring the detachment387* @return 0, on success; negative error code, otherwise (errno is also set to388* the error code)389*/390LIBBPF_API int bpf_prog_detach_opts(int prog_fd, int target,391enum bpf_attach_type type,392const struct bpf_prog_detach_opts *opts);393394union bpf_iter_link_info; /* defined in up-to-date linux/bpf.h */395struct bpf_link_create_opts {396size_t sz; /* size of this struct for forward/backward compatibility */397__u32 flags;398union bpf_iter_link_info *iter_info;399__u32 iter_info_len;400__u32 target_btf_id;401union {402struct {403__u64 bpf_cookie;404} perf_event;405struct {406__u32 flags;407__u32 cnt;408const char **syms;409const unsigned long *addrs;410const __u64 *cookies;411} kprobe_multi;412struct {413__u32 flags;414__u32 cnt;415const char *path;416const unsigned long *offsets;417const unsigned long *ref_ctr_offsets;418const __u64 *cookies;419__u32 pid;420} uprobe_multi;421struct {422__u64 cookie;423} tracing;424struct {425__u32 pf;426__u32 hooknum;427__s32 priority;428__u32 flags;429} netfilter;430struct {431__u32 relative_fd;432__u32 relative_id;433__u64 expected_revision;434} tcx;435struct {436__u32 relative_fd;437__u32 relative_id;438__u64 expected_revision;439} netkit;440struct {441__u32 relative_fd;442__u32 relative_id;443__u64 expected_revision;444} cgroup;445};446size_t :0;447};448#define bpf_link_create_opts__last_field uprobe_multi.pid449450LIBBPF_API int bpf_link_create(int prog_fd, int target_fd,451enum bpf_attach_type attach_type,452const struct bpf_link_create_opts *opts);453454LIBBPF_API int bpf_link_detach(int link_fd);455456struct bpf_link_update_opts {457size_t sz; /* size of this struct for forward/backward compatibility */458__u32 flags; /* extra flags */459__u32 old_prog_fd; /* expected old program FD */460__u32 old_map_fd; /* expected old map FD */461};462#define bpf_link_update_opts__last_field old_map_fd463464LIBBPF_API int bpf_link_update(int link_fd, int new_prog_fd,465const struct bpf_link_update_opts *opts);466467LIBBPF_API int bpf_iter_create(int link_fd);468469struct bpf_prog_test_run_attr {470int prog_fd;471int repeat;472const void *data_in;473__u32 data_size_in;474void *data_out; /* optional */475__u32 data_size_out; /* in: max length of data_out476* out: length of data_out */477__u32 retval; /* out: return code of the BPF program */478__u32 duration; /* out: average per repetition in ns */479const void *ctx_in; /* optional */480__u32 ctx_size_in;481void *ctx_out; /* optional */482__u32 ctx_size_out; /* in: max length of ctx_out483* out: length of cxt_out */484};485486LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id);487LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id);488LIBBPF_API int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id);489LIBBPF_API int bpf_link_get_next_id(__u32 start_id, __u32 *next_id);490491struct bpf_get_fd_by_id_opts {492size_t sz; /* size of this struct for forward/backward compatibility */493__u32 open_flags; /* permissions requested for the operation on fd */494__u32 token_fd;495size_t :0;496};497#define bpf_get_fd_by_id_opts__last_field token_fd498499LIBBPF_API int bpf_prog_get_fd_by_id(__u32 id);500LIBBPF_API int bpf_prog_get_fd_by_id_opts(__u32 id,501const struct bpf_get_fd_by_id_opts *opts);502LIBBPF_API int bpf_map_get_fd_by_id(__u32 id);503LIBBPF_API int bpf_map_get_fd_by_id_opts(__u32 id,504const struct bpf_get_fd_by_id_opts *opts);505LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id);506LIBBPF_API int bpf_btf_get_fd_by_id_opts(__u32 id,507const struct bpf_get_fd_by_id_opts *opts);508LIBBPF_API int bpf_link_get_fd_by_id(__u32 id);509LIBBPF_API int bpf_link_get_fd_by_id_opts(__u32 id,510const struct bpf_get_fd_by_id_opts *opts);511LIBBPF_API int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len);512513/**514* @brief **bpf_prog_get_info_by_fd()** obtains information about the BPF515* program corresponding to *prog_fd*.516*517* Populates up to *info_len* bytes of *info* and updates *info_len* with the518* actual number of bytes written to *info*. Note that *info* should be519* zero-initialized or initialized as expected by the requested *info*520* type. Failing to (zero-)initialize *info* under certain circumstances can521* result in this helper returning an error.522*523* @param prog_fd BPF program file descriptor524* @param info pointer to **struct bpf_prog_info** that will be populated with525* BPF program information526* @param info_len pointer to the size of *info*; on success updated with the527* number of bytes written to *info*528* @return 0, on success; negative error code, otherwise (errno is also set to529* the error code)530*/531LIBBPF_API int bpf_prog_get_info_by_fd(int prog_fd, struct bpf_prog_info *info, __u32 *info_len);532533/**534* @brief **bpf_map_get_info_by_fd()** obtains information about the BPF535* map corresponding to *map_fd*.536*537* Populates up to *info_len* bytes of *info* and updates *info_len* with the538* actual number of bytes written to *info*. Note that *info* should be539* zero-initialized or initialized as expected by the requested *info*540* type. Failing to (zero-)initialize *info* under certain circumstances can541* result in this helper returning an error.542*543* @param map_fd BPF map file descriptor544* @param info pointer to **struct bpf_map_info** that will be populated with545* BPF map information546* @param info_len pointer to the size of *info*; on success updated with the547* number of bytes written to *info*548* @return 0, on success; negative error code, otherwise (errno is also set to549* the error code)550*/551LIBBPF_API int bpf_map_get_info_by_fd(int map_fd, struct bpf_map_info *info, __u32 *info_len);552553/**554* @brief **bpf_btf_get_info_by_fd()** obtains information about the555* BTF object corresponding to *btf_fd*.556*557* Populates up to *info_len* bytes of *info* and updates *info_len* with the558* actual number of bytes written to *info*. Note that *info* should be559* zero-initialized or initialized as expected by the requested *info*560* type. Failing to (zero-)initialize *info* under certain circumstances can561* result in this helper returning an error.562*563* @param btf_fd BTF object file descriptor564* @param info pointer to **struct bpf_btf_info** that will be populated with565* BTF object information566* @param info_len pointer to the size of *info*; on success updated with the567* number of bytes written to *info*568* @return 0, on success; negative error code, otherwise (errno is also set to569* the error code)570*/571LIBBPF_API int bpf_btf_get_info_by_fd(int btf_fd, struct bpf_btf_info *info, __u32 *info_len);572573/**574* @brief **bpf_btf_get_info_by_fd()** obtains information about the BPF575* link corresponding to *link_fd*.576*577* Populates up to *info_len* bytes of *info* and updates *info_len* with the578* actual number of bytes written to *info*. Note that *info* should be579* zero-initialized or initialized as expected by the requested *info*580* type. Failing to (zero-)initialize *info* under certain circumstances can581* result in this helper returning an error.582*583* @param link_fd BPF link file descriptor584* @param info pointer to **struct bpf_link_info** that will be populated with585* BPF link information586* @param info_len pointer to the size of *info*; on success updated with the587* number of bytes written to *info*588* @return 0, on success; negative error code, otherwise (errno is also set to589* the error code)590*/591LIBBPF_API int bpf_link_get_info_by_fd(int link_fd, struct bpf_link_info *info, __u32 *info_len);592593struct bpf_prog_query_opts {594size_t sz; /* size of this struct for forward/backward compatibility */595__u32 query_flags;596__u32 attach_flags; /* output argument */597__u32 *prog_ids;598union {599/* input+output argument */600__u32 prog_cnt;601__u32 count;602};603__u32 *prog_attach_flags;604__u32 *link_ids;605__u32 *link_attach_flags;606__u64 revision;607size_t :0;608};609#define bpf_prog_query_opts__last_field revision610611/**612* @brief **bpf_prog_query_opts()** queries the BPF programs and BPF links613* which are attached to *target* which can represent a file descriptor or614* netdevice ifindex.615*616* @param target query location file descriptor or ifindex617* @param type attach type for the BPF program618* @param opts options for configuring the query619* @return 0, on success; negative error code, otherwise (errno is also set to620* the error code)621*/622LIBBPF_API int bpf_prog_query_opts(int target, enum bpf_attach_type type,623struct bpf_prog_query_opts *opts);624LIBBPF_API int bpf_prog_query(int target_fd, enum bpf_attach_type type,625__u32 query_flags, __u32 *attach_flags,626__u32 *prog_ids, __u32 *prog_cnt);627628struct bpf_raw_tp_opts {629size_t sz; /* size of this struct for forward/backward compatibility */630const char *tp_name;631__u64 cookie;632size_t :0;633};634#define bpf_raw_tp_opts__last_field cookie635636LIBBPF_API int bpf_raw_tracepoint_open_opts(int prog_fd, struct bpf_raw_tp_opts *opts);637LIBBPF_API int bpf_raw_tracepoint_open(const char *name, int prog_fd);638LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf,639__u32 *buf_len, __u32 *prog_id, __u32 *fd_type,640__u64 *probe_offset, __u64 *probe_addr);641642#ifdef __cplusplus643/* forward-declaring enums in C++ isn't compatible with pure C enums, so644* instead define bpf_enable_stats() as accepting int as an input645*/646LIBBPF_API int bpf_enable_stats(int type);647#else648enum bpf_stats_type; /* defined in up-to-date linux/bpf.h */649LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type);650#endif651652struct bpf_prog_bind_opts {653size_t sz; /* size of this struct for forward/backward compatibility */654__u32 flags;655};656#define bpf_prog_bind_opts__last_field flags657658LIBBPF_API int bpf_prog_bind_map(int prog_fd, int map_fd,659const struct bpf_prog_bind_opts *opts);660661struct bpf_test_run_opts {662size_t sz; /* size of this struct for forward/backward compatibility */663const void *data_in; /* optional */664void *data_out; /* optional */665__u32 data_size_in;666__u32 data_size_out; /* in: max length of data_out667* out: length of data_out668*/669const void *ctx_in; /* optional */670void *ctx_out; /* optional */671__u32 ctx_size_in;672__u32 ctx_size_out; /* in: max length of ctx_out673* out: length of cxt_out674*/675__u32 retval; /* out: return code of the BPF program */676int repeat;677__u32 duration; /* out: average per repetition in ns */678__u32 flags;679__u32 cpu;680__u32 batch_size;681};682#define bpf_test_run_opts__last_field batch_size683684LIBBPF_API int bpf_prog_test_run_opts(int prog_fd,685struct bpf_test_run_opts *opts);686687struct bpf_token_create_opts {688size_t sz; /* size of this struct for forward/backward compatibility */689__u32 flags;690size_t :0;691};692#define bpf_token_create_opts__last_field flags693694/**695* @brief **bpf_token_create()** creates a new instance of BPF token derived696* from specified BPF FS mount point.697*698* BPF token created with this API can be passed to bpf() syscall for699* commands like BPF_PROG_LOAD, BPF_MAP_CREATE, etc.700*701* @param bpffs_fd FD for BPF FS instance from which to derive a BPF token702* instance.703* @param opts optional BPF token creation options, can be NULL704*705* @return BPF token FD > 0, on success; negative error code, otherwise (errno706* is also set to the error code)707*/708LIBBPF_API int bpf_token_create(int bpffs_fd,709struct bpf_token_create_opts *opts);710711struct bpf_prog_stream_read_opts {712size_t sz;713size_t :0;714};715#define bpf_prog_stream_read_opts__last_field sz716/**717* @brief **bpf_prog_stream_read** reads data from the BPF stream of a given BPF718* program.719*720* @param prog_fd FD for the BPF program whose BPF stream is to be read.721* @param stream_id ID of the BPF stream to be read.722* @param buf Buffer to read data into from the BPF stream.723* @param buf_len Maximum number of bytes to read from the BPF stream.724* @param opts optional options, can be NULL725*726* @return The number of bytes read, on success; negative error code, otherwise727* (errno is also set to the error code)728*/729LIBBPF_API int bpf_prog_stream_read(int prog_fd, __u32 stream_id, void *buf, __u32 buf_len,730struct bpf_prog_stream_read_opts *opts);731732#ifdef __cplusplus733} /* extern "C" */734#endif735736#endif /* __LIBBPF_BPF_H */737738739