xref: /linux/tools/lib/bpf/bpf.h (revision 1159d27852207e8efb8d6ef2dae5aaa87ec4e225)
11bc38b8fSAlexei Starovoitov /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
26061a3d6SEric Leblond 
3e3ed2fefSWang Nan /*
40a504fa1SIlya Leoshkevich  * Common BPF ELF operations.
5e3ed2fefSWang Nan  *
6e3ed2fefSWang Nan  * Copyright (C) 2013-2015 Alexei Starovoitov <ast@kernel.org>
7e3ed2fefSWang Nan  * Copyright (C) 2015 Wang Nan <wangnan0@huawei.com>
8e3ed2fefSWang Nan  * Copyright (C) 2015 Huawei Inc.
9203d1cacSWang Nan  *
10203d1cacSWang Nan  * This program is free software; you can redistribute it and/or
11203d1cacSWang Nan  * modify it under the terms of the GNU Lesser General Public
12203d1cacSWang Nan  * License as published by the Free Software Foundation;
13203d1cacSWang Nan  * version 2.1 of the License (not later!)
14203d1cacSWang Nan  *
15203d1cacSWang Nan  * This program is distributed in the hope that it will be useful,
16203d1cacSWang Nan  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17203d1cacSWang Nan  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18203d1cacSWang Nan  * GNU Lesser General Public License for more details.
19203d1cacSWang Nan  *
20203d1cacSWang Nan  * You should have received a copy of the GNU Lesser General Public
21203d1cacSWang Nan  * License along with this program; if not,  see <http://www.gnu.org/licenses>
22e3ed2fefSWang Nan  */
23eff81908SAndrey Ignatov #ifndef __LIBBPF_BPF_H
24eff81908SAndrey Ignatov #define __LIBBPF_BPF_H
25e3ed2fefSWang Nan 
26e3ed2fefSWang Nan #include <linux/bpf.h>
27878a4d32SBjörn Töpel #include <stdbool.h>
287a5980f9SMickaël Salaün #include <stddef.h>
2932e621e5SDaniel T. Lee #include <stdint.h>
30e3ed2fefSWang Nan 
31544402d4SAndrii Nakryiko #include "libbpf_common.h"
32be80e9cdSAndrii Nakryiko #include "libbpf_legacy.h"
33544402d4SAndrii Nakryiko 
348c4905b9SStanislav Fomichev #ifdef __cplusplus
358c4905b9SStanislav Fomichev extern "C" {
368c4905b9SStanislav Fomichev #endif
378c4905b9SStanislav Fomichev 
3893ee1eb8SAndrii Nakryiko LIBBPF_API int libbpf_set_memlock_rlim(size_t memlock_bytes);
39e542f2c4SAndrii Nakryiko 
40992c4225SAndrii Nakryiko struct bpf_map_create_opts {
41992c4225SAndrii Nakryiko 	size_t sz; /* size of this struct for forward/backward compatibility */
42992c4225SAndrii Nakryiko 
43992c4225SAndrii Nakryiko 	__u32 btf_fd;
44992c4225SAndrii Nakryiko 	__u32 btf_key_type_id;
45992c4225SAndrii Nakryiko 	__u32 btf_value_type_id;
46992c4225SAndrii Nakryiko 	__u32 btf_vmlinux_value_type_id;
47992c4225SAndrii Nakryiko 
4874d98070SAndrii Nakryiko 	__u32 inner_map_fd;
4974d98070SAndrii Nakryiko 	__u32 map_flags;
50992c4225SAndrii Nakryiko 	__u64 map_extra;
51992c4225SAndrii Nakryiko 
5274d98070SAndrii Nakryiko 	__u32 numa_node;
5374d98070SAndrii Nakryiko 	__u32 map_ifindex;
549e926acdSKui-Feng Lee 	__s32 value_type_btf_obj_fd;
55364f8483SAndrii Nakryiko 
56364f8483SAndrii Nakryiko 	__u32 token_fd;
579e926acdSKui-Feng Lee 	size_t :0;
58992c4225SAndrii Nakryiko };
59364f8483SAndrii Nakryiko #define bpf_map_create_opts__last_field token_fd
60992c4225SAndrii Nakryiko 
61992c4225SAndrii Nakryiko LIBBPF_API int bpf_map_create(enum bpf_map_type map_type,
62992c4225SAndrii Nakryiko 			      const char *map_name,
63992c4225SAndrii Nakryiko 			      __u32 key_size,
64992c4225SAndrii Nakryiko 			      __u32 value_size,
65992c4225SAndrii Nakryiko 			      __u32 max_entries,
66992c4225SAndrii Nakryiko 			      const struct bpf_map_create_opts *opts);
67992c4225SAndrii Nakryiko 
68d10ef2b8SAndrii Nakryiko struct bpf_prog_load_opts {
69d10ef2b8SAndrii Nakryiko 	size_t sz; /* size of this struct for forward/backward compatibility */
70d10ef2b8SAndrii Nakryiko 
71d10ef2b8SAndrii Nakryiko 	/* libbpf can retry BPF_PROG_LOAD command if bpf() syscall returns
72d10ef2b8SAndrii Nakryiko 	 * -EAGAIN. This field determines how many attempts libbpf has to
73d10ef2b8SAndrii Nakryiko 	 *  make. If not specified, libbpf will use default value of 5.
74d10ef2b8SAndrii Nakryiko 	 */
75d10ef2b8SAndrii Nakryiko 	int attempts;
76d10ef2b8SAndrii Nakryiko 
77d10ef2b8SAndrii Nakryiko 	enum bpf_attach_type expected_attach_type;
78d10ef2b8SAndrii Nakryiko 	__u32 prog_btf_fd;
79d10ef2b8SAndrii Nakryiko 	__u32 prog_flags;
80d10ef2b8SAndrii Nakryiko 	__u32 prog_ifindex;
81d10ef2b8SAndrii Nakryiko 	__u32 kern_version;
82d10ef2b8SAndrii Nakryiko 
83d10ef2b8SAndrii Nakryiko 	__u32 attach_btf_id;
84d10ef2b8SAndrii Nakryiko 	__u32 attach_prog_fd;
85d10ef2b8SAndrii Nakryiko 	__u32 attach_btf_obj_fd;
86d10ef2b8SAndrii Nakryiko 
87d10ef2b8SAndrii Nakryiko 	const int *fd_array;
88d10ef2b8SAndrii Nakryiko 
89d10ef2b8SAndrii Nakryiko 	/* .BTF.ext func info data */
90d10ef2b8SAndrii Nakryiko 	const void *func_info;
91d10ef2b8SAndrii Nakryiko 	__u32 func_info_cnt;
92d10ef2b8SAndrii Nakryiko 	__u32 func_info_rec_size;
93d10ef2b8SAndrii Nakryiko 
94d10ef2b8SAndrii Nakryiko 	/* .BTF.ext line info data */
95d10ef2b8SAndrii Nakryiko 	const void *line_info;
96d10ef2b8SAndrii Nakryiko 	__u32 line_info_cnt;
97d10ef2b8SAndrii Nakryiko 	__u32 line_info_rec_size;
98d10ef2b8SAndrii Nakryiko 
99d10ef2b8SAndrii Nakryiko 	/* verifier log options */
100d10ef2b8SAndrii Nakryiko 	__u32 log_level;
101d10ef2b8SAndrii Nakryiko 	__u32 log_size;
102d10ef2b8SAndrii Nakryiko 	char *log_buf;
10394e55c0fSAndrii Nakryiko 	/* output: actual total log contents size (including termintaing zero).
10494e55c0fSAndrii Nakryiko 	 * It could be both larger than original log_size (if log was
10594e55c0fSAndrii Nakryiko 	 * truncated), or smaller (if log buffer wasn't filled completely).
10694e55c0fSAndrii Nakryiko 	 * If kernel doesn't support this feature, log_size is left unchanged.
10794e55c0fSAndrii Nakryiko 	 */
10894e55c0fSAndrii Nakryiko 	__u32 log_true_size;
109404cbc14SAndrii Nakryiko 	__u32 token_fd;
11094e55c0fSAndrii Nakryiko 	size_t :0;
111d10ef2b8SAndrii Nakryiko };
112404cbc14SAndrii Nakryiko #define bpf_prog_load_opts__last_field token_fd
113d10ef2b8SAndrii Nakryiko 
114d10ef2b8SAndrii Nakryiko LIBBPF_API int bpf_prog_load(enum bpf_prog_type prog_type,
115d10ef2b8SAndrii Nakryiko 			     const char *prog_name, const char *license,
116d10ef2b8SAndrii Nakryiko 			     const struct bpf_insn *insns, size_t insn_cnt,
11794e55c0fSAndrii Nakryiko 			     struct bpf_prog_load_opts *opts);
118d7be143bSAndrey Ignatov 
119c034a177SJohn Fastabend /* Flags to direct loading requirements */
120c034a177SJohn Fastabend #define MAPS_RELAX_COMPAT	0x01
121c034a177SJohn Fastabend 
122e0e3ea88SAndrii Nakryiko /* Recommended log buffer size */
1234519efa6SMcCabe, Robert J #define BPF_LOG_BUF_SIZE (UINT32_MAX >> 8) /* verifier maximum in kernels <= 5.1 */
124e0e3ea88SAndrii Nakryiko 
1250ed08d67SAndrii Nakryiko struct bpf_btf_load_opts {
1260ed08d67SAndrii Nakryiko 	size_t sz; /* size of this struct for forward/backward compatibility */
1270ed08d67SAndrii Nakryiko 
1280ed08d67SAndrii Nakryiko 	/* kernel log options */
1290ed08d67SAndrii Nakryiko 	char *log_buf;
1300ed08d67SAndrii Nakryiko 	__u32 log_level;
1310ed08d67SAndrii Nakryiko 	__u32 log_size;
132097d8002SAndrii Nakryiko 	/* output: actual total log contents size (including termintaing zero).
133097d8002SAndrii Nakryiko 	 * It could be both larger than original log_size (if log was
134097d8002SAndrii Nakryiko 	 * truncated), or smaller (if log buffer wasn't filled completely).
135097d8002SAndrii Nakryiko 	 * If kernel doesn't support this feature, log_size is left unchanged.
136097d8002SAndrii Nakryiko 	 */
137097d8002SAndrii Nakryiko 	__u32 log_true_size;
138a3d63e85SAndrii Nakryiko 
139a3d63e85SAndrii Nakryiko 	__u32 btf_flags;
140a3d63e85SAndrii Nakryiko 	__u32 token_fd;
141097d8002SAndrii Nakryiko 	size_t :0;
1420ed08d67SAndrii Nakryiko };
143a3d63e85SAndrii Nakryiko #define bpf_btf_load_opts__last_field token_fd
1440ed08d67SAndrii Nakryiko 
1450ed08d67SAndrii Nakryiko LIBBPF_API int bpf_btf_load(const void *btf_data, size_t btf_size,
146097d8002SAndrii Nakryiko 			    struct bpf_btf_load_opts *opts);
1470ed08d67SAndrii Nakryiko 
148ab9e0848SAndrey Ignatov LIBBPF_API int bpf_map_update_elem(int fd, const void *key, const void *value,
14983d994d0SJoe Stringer 				   __u64 flags);
1509742da01SWang Nan 
151ab9e0848SAndrey Ignatov LIBBPF_API int bpf_map_lookup_elem(int fd, const void *key, void *value);
152df5d22faSAlexei Starovoitov LIBBPF_API int bpf_map_lookup_elem_flags(int fd, const void *key, void *value,
153df5d22faSAlexei Starovoitov 					 __u64 flags);
15443b987d2SMauricio Vasquez B LIBBPF_API int bpf_map_lookup_and_delete_elem(int fd, const void *key,
15543b987d2SMauricio Vasquez B 					      void *value);
156d59b9f2dSDenis Salopek LIBBPF_API int bpf_map_lookup_and_delete_elem_flags(int fd, const void *key,
157d59b9f2dSDenis Salopek 						    void *value, __u64 flags);
158ab9e0848SAndrey Ignatov LIBBPF_API int bpf_map_delete_elem(int fd, const void *key);
159737d0646SAndrii Nakryiko LIBBPF_API int bpf_map_delete_elem_flags(int fd, const void *key, __u64 flags);
160ab9e0848SAndrey Ignatov LIBBPF_API int bpf_map_get_next_key(int fd, const void *key, void *next_key);
161d859900cSDaniel Borkmann LIBBPF_API int bpf_map_freeze(int fd);
1622ab3d86eSYonghong Song 
1632ab3d86eSYonghong Song struct bpf_map_batch_opts {
1642ab3d86eSYonghong Song 	size_t sz; /* size of this struct for forward/backward compatibility */
1652ab3d86eSYonghong Song 	__u64 elem_flags;
1662ab3d86eSYonghong Song 	__u64 flags;
1672ab3d86eSYonghong Song };
1682ab3d86eSYonghong Song #define bpf_map_batch_opts__last_field flags
1692ab3d86eSYonghong Song 
170e59618f0SGrant Seltzer 
171e59618f0SGrant Seltzer /**
172e59618f0SGrant Seltzer  * @brief **bpf_map_delete_batch()** allows for batch deletion of multiple
173e59618f0SGrant Seltzer  * elements in a BPF map.
174e59618f0SGrant Seltzer  *
175e59618f0SGrant Seltzer  * @param fd BPF map file descriptor
176e59618f0SGrant Seltzer  * @param keys pointer to an array of *count* keys
177e59618f0SGrant Seltzer  * @param count input and output parameter; on input **count** represents the
178e59618f0SGrant Seltzer  * number of  elements in the map to delete in batch;
179e59618f0SGrant Seltzer  * on output if a non-EFAULT error is returned, **count** represents the number of deleted
180e59618f0SGrant Seltzer  * elements if the output **count** value is not equal to the input **count** value
181e59618f0SGrant Seltzer  * If EFAULT is returned, **count** should not be trusted to be correct.
182e59618f0SGrant Seltzer  * @param opts options for configuring the way the batch deletion works
183e59618f0SGrant Seltzer  * @return 0, on success; negative error code, otherwise (errno is also set to
184e59618f0SGrant Seltzer  * the error code)
185e59618f0SGrant Seltzer  */
186e59618f0SGrant Seltzer LIBBPF_API int bpf_map_delete_batch(int fd, const void *keys,
1872ab3d86eSYonghong Song 				    __u32 *count,
1882ab3d86eSYonghong Song 				    const struct bpf_map_batch_opts *opts);
189e59618f0SGrant Seltzer 
190e59618f0SGrant Seltzer /**
191e59618f0SGrant Seltzer  * @brief **bpf_map_lookup_batch()** allows for batch lookup of BPF map elements.
192e59618f0SGrant Seltzer  *
193e59618f0SGrant Seltzer  * The parameter *in_batch* is the address of the first element in the batch to read.
194e59618f0SGrant Seltzer  * *out_batch* is an output parameter that should be passed as *in_batch* to subsequent
195e59618f0SGrant Seltzer  * calls to **bpf_map_lookup_batch()**. NULL can be passed for *in_batch* to indicate
196e59618f0SGrant Seltzer  * that the batched lookup starts from the beginning of the map.
197e59618f0SGrant Seltzer  *
198e59618f0SGrant Seltzer  * The *keys* and *values* are output parameters which must point to memory large enough to
199e59618f0SGrant Seltzer  * hold *count* items based on the key and value size of the map *map_fd*. The *keys*
200e59618f0SGrant Seltzer  * buffer must be of *key_size* * *count*. The *values* buffer must be of
201e59618f0SGrant Seltzer  * *value_size* * *count*.
202e59618f0SGrant Seltzer  *
203e59618f0SGrant Seltzer  * @param fd BPF map file descriptor
204e59618f0SGrant Seltzer  * @param in_batch address of the first element in batch to read, can pass NULL to
205e59618f0SGrant Seltzer  * indicate that the batched lookup starts from the beginning of the map.
206e59618f0SGrant Seltzer  * @param out_batch output parameter that should be passed to next call as *in_batch*
207e59618f0SGrant Seltzer  * @param keys pointer to an array large enough for *count* keys
208e59618f0SGrant Seltzer  * @param values pointer to an array large enough for *count* values
209e59618f0SGrant Seltzer  * @param count input and output parameter; on input it's the number of elements
210e59618f0SGrant Seltzer  * in the map to read in batch; on output it's the number of elements that were
211e59618f0SGrant Seltzer  * successfully read.
212e59618f0SGrant Seltzer  * If a non-EFAULT error is returned, count will be set as the number of elements
213e59618f0SGrant Seltzer  * that were read before the error occurred.
214e59618f0SGrant Seltzer  * If EFAULT is returned, **count** should not be trusted to be correct.
215e59618f0SGrant Seltzer  * @param opts options for configuring the way the batch lookup works
216e59618f0SGrant Seltzer  * @return 0, on success; negative error code, otherwise (errno is also set to
217e59618f0SGrant Seltzer  * the error code)
218e59618f0SGrant Seltzer  */
2192ab3d86eSYonghong Song LIBBPF_API int bpf_map_lookup_batch(int fd, void *in_batch, void *out_batch,
2202ab3d86eSYonghong Song 				    void *keys, void *values, __u32 *count,
2212ab3d86eSYonghong Song 				    const struct bpf_map_batch_opts *opts);
222e59618f0SGrant Seltzer 
223e59618f0SGrant Seltzer /**
224e59618f0SGrant Seltzer  * @brief **bpf_map_lookup_and_delete_batch()** allows for batch lookup and deletion
225e59618f0SGrant Seltzer  * of BPF map elements where each element is deleted after being retrieved.
226e59618f0SGrant Seltzer  *
227e59618f0SGrant Seltzer  * @param fd BPF map file descriptor
228e59618f0SGrant Seltzer  * @param in_batch address of the first element in batch to read, can pass NULL to
229e59618f0SGrant Seltzer  * get address of the first element in *out_batch*
230e59618f0SGrant Seltzer  * @param out_batch output parameter that should be passed to next call as *in_batch*
231e59618f0SGrant Seltzer  * @param keys pointer to an array of *count* keys
232e59618f0SGrant Seltzer  * @param values pointer to an array large enough for *count* values
233e59618f0SGrant Seltzer  * @param count input and output parameter; on input it's the number of elements
234e59618f0SGrant Seltzer  * in the map to read and delete in batch; on output it represents the number of
235e59618f0SGrant Seltzer  * elements that were successfully read and deleted
236e59618f0SGrant Seltzer  * If a non-**EFAULT** error code is returned and if the output **count** value
237e59618f0SGrant Seltzer  * is not equal to the input **count** value, up to **count** elements may
238e59618f0SGrant Seltzer  * have been deleted.
239e59618f0SGrant Seltzer  * if **EFAULT** is returned up to *count* elements may have been deleted without
240e59618f0SGrant Seltzer  * being returned via the *keys* and *values* output parameters.
241e59618f0SGrant Seltzer  * @param opts options for configuring the way the batch lookup and delete works
242e59618f0SGrant Seltzer  * @return 0, on success; negative error code, otherwise (errno is also set to
243e59618f0SGrant Seltzer  * the error code)
244e59618f0SGrant Seltzer  */
2452ab3d86eSYonghong Song LIBBPF_API int bpf_map_lookup_and_delete_batch(int fd, void *in_batch,
2462ab3d86eSYonghong Song 					void *out_batch, void *keys,
2472ab3d86eSYonghong Song 					void *values, __u32 *count,
2482ab3d86eSYonghong Song 					const struct bpf_map_batch_opts *opts);
249e59618f0SGrant Seltzer 
250e59618f0SGrant Seltzer /**
251e59618f0SGrant Seltzer  * @brief **bpf_map_update_batch()** updates multiple elements in a map
252e59618f0SGrant Seltzer  * by specifying keys and their corresponding values.
253e59618f0SGrant Seltzer  *
254e59618f0SGrant Seltzer  * The *keys* and *values* parameters must point to memory large enough
255e59618f0SGrant Seltzer  * to hold *count* items based on the key and value size of the map.
256e59618f0SGrant Seltzer  *
257e59618f0SGrant Seltzer  * The *opts* parameter can be used to control how *bpf_map_update_batch()*
258e59618f0SGrant Seltzer  * should handle keys that either do or do not already exist in the map.
259e59618f0SGrant Seltzer  * In particular the *flags* parameter of *bpf_map_batch_opts* can be
260e59618f0SGrant Seltzer  * one of the following:
261e59618f0SGrant Seltzer  *
262e59618f0SGrant Seltzer  * Note that *count* is an input and output parameter, where on output it
263e59618f0SGrant Seltzer  * represents how many elements were successfully updated. Also note that if
264e59618f0SGrant Seltzer  * **EFAULT** then *count* should not be trusted to be correct.
265e59618f0SGrant Seltzer  *
266e59618f0SGrant Seltzer  * **BPF_ANY**
267e59618f0SGrant Seltzer  *    Create new elements or update existing.
268e59618f0SGrant Seltzer  *
269e59618f0SGrant Seltzer  * **BPF_NOEXIST**
270e59618f0SGrant Seltzer  *    Create new elements only if they do not exist.
271e59618f0SGrant Seltzer  *
272e59618f0SGrant Seltzer  * **BPF_EXIST**
273e59618f0SGrant Seltzer  *    Update existing elements.
274e59618f0SGrant Seltzer  *
275e59618f0SGrant Seltzer  * **BPF_F_LOCK**
276e59618f0SGrant Seltzer  *    Update spin_lock-ed map elements. This must be
277e59618f0SGrant Seltzer  *    specified if the map value contains a spinlock.
278e59618f0SGrant Seltzer  *
279e59618f0SGrant Seltzer  * @param fd BPF map file descriptor
280e59618f0SGrant Seltzer  * @param keys pointer to an array of *count* keys
281e59618f0SGrant Seltzer  * @param values pointer to an array of *count* values
282e59618f0SGrant Seltzer  * @param count input and output parameter; on input it's the number of elements
283e59618f0SGrant Seltzer  * in the map to update in batch; on output if a non-EFAULT error is returned,
284e59618f0SGrant Seltzer  * **count** represents the number of updated elements if the output **count**
285e59618f0SGrant Seltzer  * value is not equal to the input **count** value.
286e59618f0SGrant Seltzer  * If EFAULT is returned, **count** should not be trusted to be correct.
287e59618f0SGrant Seltzer  * @param opts options for configuring the way the batch update works
288e59618f0SGrant Seltzer  * @return 0, on success; negative error code, otherwise (errno is also set to
289e59618f0SGrant Seltzer  * the error code)
290e59618f0SGrant Seltzer  */
291e59618f0SGrant Seltzer LIBBPF_API int bpf_map_update_batch(int fd, const void *keys, const void *values,
2922ab3d86eSYonghong Song 				    __u32 *count,
2932ab3d86eSYonghong Song 				    const struct bpf_map_batch_opts *opts);
2942ab3d86eSYonghong Song 
295f1674dc7SAndrii Nakryiko struct bpf_obj_pin_opts {
296f1674dc7SAndrii Nakryiko 	size_t sz; /* size of this struct for forward/backward compatibility */
297f1674dc7SAndrii Nakryiko 
298f1674dc7SAndrii Nakryiko 	__u32 file_flags;
299f1674dc7SAndrii Nakryiko 	int path_fd;
300f1674dc7SAndrii Nakryiko 
301f1674dc7SAndrii Nakryiko 	size_t :0;
302f1674dc7SAndrii Nakryiko };
303f1674dc7SAndrii Nakryiko #define bpf_obj_pin_opts__last_field path_fd
304f1674dc7SAndrii Nakryiko 
305f1674dc7SAndrii Nakryiko LIBBPF_API int bpf_obj_pin(int fd, const char *pathname);
306f1674dc7SAndrii Nakryiko LIBBPF_API int bpf_obj_pin_opts(int fd, const char *pathname,
307f1674dc7SAndrii Nakryiko 				const struct bpf_obj_pin_opts *opts);
308f1674dc7SAndrii Nakryiko 
309395fc4faSJoe Burton struct bpf_obj_get_opts {
310395fc4faSJoe Burton 	size_t sz; /* size of this struct for forward/backward compatibility */
311395fc4faSJoe Burton 
312395fc4faSJoe Burton 	__u32 file_flags;
313f1674dc7SAndrii Nakryiko 	int path_fd;
314395fc4faSJoe Burton 
315395fc4faSJoe Burton 	size_t :0;
316395fc4faSJoe Burton };
317f1674dc7SAndrii Nakryiko #define bpf_obj_get_opts__last_field path_fd
318395fc4faSJoe Burton 
319ab9e0848SAndrey Ignatov LIBBPF_API int bpf_obj_get(const char *pathname);
320395fc4faSJoe Burton LIBBPF_API int bpf_obj_get_opts(const char *pathname,
321395fc4faSJoe Burton 				const struct bpf_obj_get_opts *opts);
322cdbee383SAndrey Ignatov 
323ab9e0848SAndrey Ignatov LIBBPF_API int bpf_prog_attach(int prog_fd, int attachable_fd,
324ab9e0848SAndrey Ignatov 			       enum bpf_attach_type type, unsigned int flags);
325ab9e0848SAndrey Ignatov LIBBPF_API int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type);
326ab9e0848SAndrey Ignatov LIBBPF_API int bpf_prog_detach2(int prog_fd, int attachable_fd,
327ab9e0848SAndrey Ignatov 				enum bpf_attach_type type);
32864a97591SLorenz Bauer 
329fe20ce3aSDaniel Borkmann struct bpf_prog_attach_opts {
330fe20ce3aSDaniel Borkmann 	size_t sz; /* size of this struct for forward/backward compatibility */
331fe20ce3aSDaniel Borkmann 	__u32 flags;
332fe20ce3aSDaniel Borkmann 	union {
333fe20ce3aSDaniel Borkmann 		int replace_prog_fd;
334fe20ce3aSDaniel Borkmann 		int replace_fd;
335fe20ce3aSDaniel Borkmann 	};
336fe20ce3aSDaniel Borkmann 	int relative_fd;
337fe20ce3aSDaniel Borkmann 	__u32 relative_id;
338fe20ce3aSDaniel Borkmann 	__u64 expected_revision;
339fe20ce3aSDaniel Borkmann 	size_t :0;
340fe20ce3aSDaniel Borkmann };
341fe20ce3aSDaniel Borkmann #define bpf_prog_attach_opts__last_field expected_revision
342fe20ce3aSDaniel Borkmann 
343fe20ce3aSDaniel Borkmann struct bpf_prog_detach_opts {
344fe20ce3aSDaniel Borkmann 	size_t sz; /* size of this struct for forward/backward compatibility */
345fe20ce3aSDaniel Borkmann 	__u32 flags;
346fe20ce3aSDaniel Borkmann 	int relative_fd;
347fe20ce3aSDaniel Borkmann 	__u32 relative_id;
348fe20ce3aSDaniel Borkmann 	__u64 expected_revision;
349fe20ce3aSDaniel Borkmann 	size_t :0;
350fe20ce3aSDaniel Borkmann };
351fe20ce3aSDaniel Borkmann #define bpf_prog_detach_opts__last_field expected_revision
352fe20ce3aSDaniel Borkmann 
353fe20ce3aSDaniel Borkmann /**
354fe20ce3aSDaniel Borkmann  * @brief **bpf_prog_attach_opts()** attaches the BPF program corresponding to
355fe20ce3aSDaniel Borkmann  * *prog_fd* to a *target* which can represent a file descriptor or netdevice
356fe20ce3aSDaniel Borkmann  * ifindex.
357fe20ce3aSDaniel Borkmann  *
358fe20ce3aSDaniel Borkmann  * @param prog_fd BPF program file descriptor
359fe20ce3aSDaniel Borkmann  * @param target attach location file descriptor or ifindex
360fe20ce3aSDaniel Borkmann  * @param type attach type for the BPF program
361fe20ce3aSDaniel Borkmann  * @param opts options for configuring the attachment
362fe20ce3aSDaniel Borkmann  * @return 0, on success; negative error code, otherwise (errno is also set to
363fe20ce3aSDaniel Borkmann  * the error code)
364fe20ce3aSDaniel Borkmann  */
365fe20ce3aSDaniel Borkmann LIBBPF_API int bpf_prog_attach_opts(int prog_fd, int target,
366fe20ce3aSDaniel Borkmann 				    enum bpf_attach_type type,
367fe20ce3aSDaniel Borkmann 				    const struct bpf_prog_attach_opts *opts);
368fe20ce3aSDaniel Borkmann 
369fe20ce3aSDaniel Borkmann /**
370fe20ce3aSDaniel Borkmann  * @brief **bpf_prog_detach_opts()** detaches the BPF program corresponding to
371fe20ce3aSDaniel Borkmann  * *prog_fd* from a *target* which can represent a file descriptor or netdevice
372fe20ce3aSDaniel Borkmann  * ifindex.
373fe20ce3aSDaniel Borkmann  *
374fe20ce3aSDaniel Borkmann  * @param prog_fd BPF program file descriptor
375fe20ce3aSDaniel Borkmann  * @param target detach location file descriptor or ifindex
376fe20ce3aSDaniel Borkmann  * @param type detach type for the BPF program
377fe20ce3aSDaniel Borkmann  * @param opts options for configuring the detachment
378fe20ce3aSDaniel Borkmann  * @return 0, on success; negative error code, otherwise (errno is also set to
379fe20ce3aSDaniel Borkmann  * the error code)
380fe20ce3aSDaniel Borkmann  */
381fe20ce3aSDaniel Borkmann LIBBPF_API int bpf_prog_detach_opts(int prog_fd, int target,
382fe20ce3aSDaniel Borkmann 				    enum bpf_attach_type type,
383fe20ce3aSDaniel Borkmann 				    const struct bpf_prog_detach_opts *opts);
384fe20ce3aSDaniel Borkmann 
38574fc097dSYonghong Song union bpf_iter_link_info; /* defined in up-to-date linux/bpf.h */
386cc4f864bSAndrii Nakryiko struct bpf_link_create_opts {
387cc4f864bSAndrii Nakryiko 	size_t sz; /* size of this struct for forward/backward compatibility */
388cd31039aSYonghong Song 	__u32 flags;
38974fc097dSYonghong Song 	union bpf_iter_link_info *iter_info;
39074fc097dSYonghong Song 	__u32 iter_info_len;
391a5359091SToke Høiland-Jørgensen 	__u32 target_btf_id;
3923ec84f4bSAndrii Nakryiko 	union {
3933ec84f4bSAndrii Nakryiko 		struct {
3943ec84f4bSAndrii Nakryiko 			__u64 bpf_cookie;
3953ec84f4bSAndrii Nakryiko 		} perf_event;
3965117c26eSJiri Olsa 		struct {
3975117c26eSJiri Olsa 			__u32 flags;
3985117c26eSJiri Olsa 			__u32 cnt;
3995117c26eSJiri Olsa 			const char **syms;
4005117c26eSJiri Olsa 			const unsigned long *addrs;
4015117c26eSJiri Olsa 			const __u64 *cookies;
4025117c26eSJiri Olsa 		} kprobe_multi;
403129b9c5eSKui-Feng Lee 		struct {
4045054a303SJiri Olsa 			__u32 flags;
4055054a303SJiri Olsa 			__u32 cnt;
4065054a303SJiri Olsa 			const char *path;
4075054a303SJiri Olsa 			const unsigned long *offsets;
4085054a303SJiri Olsa 			const unsigned long *ref_ctr_offsets;
4095054a303SJiri Olsa 			const __u64 *cookies;
4105054a303SJiri Olsa 			__u32 pid;
4115054a303SJiri Olsa 		} uprobe_multi;
4125054a303SJiri Olsa 		struct {
413129b9c5eSKui-Feng Lee 			__u64 cookie;
414129b9c5eSKui-Feng Lee 		} tracing;
41552364abbSFlorian Westphal 		struct {
41652364abbSFlorian Westphal 			__u32 pf;
41752364abbSFlorian Westphal 			__u32 hooknum;
41852364abbSFlorian Westphal 			__s32 priority;
41952364abbSFlorian Westphal 			__u32 flags;
42052364abbSFlorian Westphal 		} netfilter;
42155cc3768SDaniel Borkmann 		struct {
42255cc3768SDaniel Borkmann 			__u32 relative_fd;
42355cc3768SDaniel Borkmann 			__u32 relative_id;
42455cc3768SDaniel Borkmann 			__u64 expected_revision;
42555cc3768SDaniel Borkmann 		} tcx;
42605c31b4aSDaniel Borkmann 		struct {
42705c31b4aSDaniel Borkmann 			__u32 relative_fd;
42805c31b4aSDaniel Borkmann 			__u32 relative_id;
42905c31b4aSDaniel Borkmann 			__u64 expected_revision;
43005c31b4aSDaniel Borkmann 		} netkit;
431cc4f864bSAndrii Nakryiko 	};
4323ec84f4bSAndrii Nakryiko 	size_t :0;
4333ec84f4bSAndrii Nakryiko };
4345054a303SJiri Olsa #define bpf_link_create_opts__last_field uprobe_multi.pid
435cc4f864bSAndrii Nakryiko 
436cc4f864bSAndrii Nakryiko LIBBPF_API int bpf_link_create(int prog_fd, int target_fd,
437cc4f864bSAndrii Nakryiko 			       enum bpf_attach_type attach_type,
438cc4f864bSAndrii Nakryiko 			       const struct bpf_link_create_opts *opts);
439cc4f864bSAndrii Nakryiko 
4402e49527eSAndrii Nakryiko LIBBPF_API int bpf_link_detach(int link_fd);
4412e49527eSAndrii Nakryiko 
442cc4f864bSAndrii Nakryiko struct bpf_link_update_opts {
443cc4f864bSAndrii Nakryiko 	size_t sz; /* size of this struct for forward/backward compatibility */
444cc4f864bSAndrii Nakryiko 	__u32 flags;	   /* extra flags */
445cc4f864bSAndrii Nakryiko 	__u32 old_prog_fd; /* expected old program FD */
446912dd4b0SKui-Feng Lee 	__u32 old_map_fd;  /* expected old map FD */
447cc4f864bSAndrii Nakryiko };
448912dd4b0SKui-Feng Lee #define bpf_link_update_opts__last_field old_map_fd
449cc4f864bSAndrii Nakryiko 
450cc4f864bSAndrii Nakryiko LIBBPF_API int bpf_link_update(int link_fd, int new_prog_fd,
451cc4f864bSAndrii Nakryiko 			       const struct bpf_link_update_opts *opts);
452cc4f864bSAndrii Nakryiko 
453c09add2fSYonghong Song LIBBPF_API int bpf_iter_create(int link_fd);
454c09add2fSYonghong Song 
45564a97591SLorenz Bauer struct bpf_prog_test_run_attr {
45664a97591SLorenz Bauer 	int prog_fd;
45764a97591SLorenz Bauer 	int repeat;
45864a97591SLorenz Bauer 	const void *data_in;
45964a97591SLorenz Bauer 	__u32 data_size_in;
46064a97591SLorenz Bauer 	void *data_out;      /* optional */
46164a97591SLorenz Bauer 	__u32 data_size_out; /* in: max length of data_out
46264a97591SLorenz Bauer 			      * out: length of data_out */
46364a97591SLorenz Bauer 	__u32 retval;        /* out: return code of the BPF program */
46464a97591SLorenz Bauer 	__u32 duration;      /* out: average per repetition in ns */
4655e903c65SStanislav Fomichev 	const void *ctx_in; /* optional */
4665e903c65SStanislav Fomichev 	__u32 ctx_size_in;
4675e903c65SStanislav Fomichev 	void *ctx_out;      /* optional */
4685e903c65SStanislav Fomichev 	__u32 ctx_size_out; /* in: max length of ctx_out
4695e903c65SStanislav Fomichev 			     * out: length of cxt_out */
47064a97591SLorenz Bauer };
47164a97591SLorenz Bauer 
472ab9e0848SAndrey Ignatov LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id);
473ab9e0848SAndrey Ignatov LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id);
47409d7c2e3SQuentin Monnet LIBBPF_API int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id);
4750dbc8668SAndrii Nakryiko LIBBPF_API int bpf_link_get_next_id(__u32 start_id, __u32 *next_id);
476243e3005SRoberto Sassu 
477243e3005SRoberto Sassu struct bpf_get_fd_by_id_opts {
478243e3005SRoberto Sassu 	size_t sz; /* size of this struct for forward/backward compatibility */
479243e3005SRoberto Sassu 	__u32 open_flags; /* permissions requested for the operation on fd */
480243e3005SRoberto Sassu 	size_t :0;
481243e3005SRoberto Sassu };
482243e3005SRoberto Sassu #define bpf_get_fd_by_id_opts__last_field open_flags
483243e3005SRoberto Sassu 
484ab9e0848SAndrey Ignatov LIBBPF_API int bpf_prog_get_fd_by_id(__u32 id);
4858f13f168SRoberto Sassu LIBBPF_API int bpf_prog_get_fd_by_id_opts(__u32 id,
4868f13f168SRoberto Sassu 				const struct bpf_get_fd_by_id_opts *opts);
487ab9e0848SAndrey Ignatov LIBBPF_API int bpf_map_get_fd_by_id(__u32 id);
488243e3005SRoberto Sassu LIBBPF_API int bpf_map_get_fd_by_id_opts(__u32 id,
489243e3005SRoberto Sassu 				const struct bpf_get_fd_by_id_opts *opts);
490ab9e0848SAndrey Ignatov LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id);
4912ce7cbf2SRoberto Sassu LIBBPF_API int bpf_btf_get_fd_by_id_opts(__u32 id,
4922ce7cbf2SRoberto Sassu 				const struct bpf_get_fd_by_id_opts *opts);
4930dbc8668SAndrii Nakryiko LIBBPF_API int bpf_link_get_fd_by_id(__u32 id);
49497c8f9ddSRoberto Sassu LIBBPF_API int bpf_link_get_fd_by_id_opts(__u32 id,
49597c8f9ddSRoberto Sassu 				const struct bpf_get_fd_by_id_opts *opts);
4960dbc8668SAndrii Nakryiko LIBBPF_API int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len);
4970a504fa1SIlya Leoshkevich 
4980a504fa1SIlya Leoshkevich /**
4990a504fa1SIlya Leoshkevich  * @brief **bpf_prog_get_info_by_fd()** obtains information about the BPF
5000a504fa1SIlya Leoshkevich  * program corresponding to *prog_fd*.
5010a504fa1SIlya Leoshkevich  *
5020a504fa1SIlya Leoshkevich  * Populates up to *info_len* bytes of *info* and updates *info_len* with the
503*1159d278SMatt Bobrowski  * actual number of bytes written to *info*. Note that *info* should be
504*1159d278SMatt Bobrowski  * zero-initialized or initialized as expected by the requested *info*
505*1159d278SMatt Bobrowski  * type. Failing to (zero-)initialize *info* under certain circumstances can
506*1159d278SMatt Bobrowski  * result in this helper returning an error.
5070a504fa1SIlya Leoshkevich  *
5080a504fa1SIlya Leoshkevich  * @param prog_fd BPF program file descriptor
5090a504fa1SIlya Leoshkevich  * @param info pointer to **struct bpf_prog_info** that will be populated with
5100a504fa1SIlya Leoshkevich  * BPF program information
5110a504fa1SIlya Leoshkevich  * @param info_len pointer to the size of *info*; on success updated with the
5120a504fa1SIlya Leoshkevich  * number of bytes written to *info*
5130a504fa1SIlya Leoshkevich  * @return 0, on success; negative error code, otherwise (errno is also set to
5140a504fa1SIlya Leoshkevich  * the error code)
51555a9ed0eSIlya Leoshkevich  */
51655a9ed0eSIlya Leoshkevich LIBBPF_API int bpf_prog_get_info_by_fd(int prog_fd, struct bpf_prog_info *info, __u32 *info_len);
5170a504fa1SIlya Leoshkevich 
5180a504fa1SIlya Leoshkevich /**
5190a504fa1SIlya Leoshkevich  * @brief **bpf_map_get_info_by_fd()** obtains information about the BPF
5200a504fa1SIlya Leoshkevich  * map corresponding to *map_fd*.
5210a504fa1SIlya Leoshkevich  *
5220a504fa1SIlya Leoshkevich  * Populates up to *info_len* bytes of *info* and updates *info_len* with the
523*1159d278SMatt Bobrowski  * actual number of bytes written to *info*. Note that *info* should be
524*1159d278SMatt Bobrowski  * zero-initialized or initialized as expected by the requested *info*
525*1159d278SMatt Bobrowski  * type. Failing to (zero-)initialize *info* under certain circumstances can
526*1159d278SMatt Bobrowski  * result in this helper returning an error.
5270a504fa1SIlya Leoshkevich  *
5280a504fa1SIlya Leoshkevich  * @param map_fd BPF map file descriptor
5290a504fa1SIlya Leoshkevich  * @param info pointer to **struct bpf_map_info** that will be populated with
5300a504fa1SIlya Leoshkevich  * BPF map information
5310a504fa1SIlya Leoshkevich  * @param info_len pointer to the size of *info*; on success updated with the
5320a504fa1SIlya Leoshkevich  * number of bytes written to *info*
5330a504fa1SIlya Leoshkevich  * @return 0, on success; negative error code, otherwise (errno is also set to
5340a504fa1SIlya Leoshkevich  * the error code)
5350a504fa1SIlya Leoshkevich  */
53655a9ed0eSIlya Leoshkevich LIBBPF_API int bpf_map_get_info_by_fd(int map_fd, struct bpf_map_info *info, __u32 *info_len);
5370a504fa1SIlya Leoshkevich 
5380a504fa1SIlya Leoshkevich /**
5390a504fa1SIlya Leoshkevich  * @brief **bpf_btf_get_info_by_fd()** obtains information about the
5400a504fa1SIlya Leoshkevich  * BTF object corresponding to *btf_fd*.
5410a504fa1SIlya Leoshkevich  *
5420a504fa1SIlya Leoshkevich  * Populates up to *info_len* bytes of *info* and updates *info_len* with the
543*1159d278SMatt Bobrowski  * actual number of bytes written to *info*. Note that *info* should be
544*1159d278SMatt Bobrowski  * zero-initialized or initialized as expected by the requested *info*
545*1159d278SMatt Bobrowski  * type. Failing to (zero-)initialize *info* under certain circumstances can
546*1159d278SMatt Bobrowski  * result in this helper returning an error.
5470a504fa1SIlya Leoshkevich  *
5480a504fa1SIlya Leoshkevich  * @param btf_fd BTF object file descriptor
5490a504fa1SIlya Leoshkevich  * @param info pointer to **struct bpf_btf_info** that will be populated with
5500a504fa1SIlya Leoshkevich  * BTF object information
5510a504fa1SIlya Leoshkevich  * @param info_len pointer to the size of *info*; on success updated with the
5520a504fa1SIlya Leoshkevich  * number of bytes written to *info*
5530a504fa1SIlya Leoshkevich  * @return 0, on success; negative error code, otherwise (errno is also set to
5540a504fa1SIlya Leoshkevich  * the error code)
5550a504fa1SIlya Leoshkevich  */
55655a9ed0eSIlya Leoshkevich LIBBPF_API int bpf_btf_get_info_by_fd(int btf_fd, struct bpf_btf_info *info, __u32 *info_len);
5570a504fa1SIlya Leoshkevich 
5580a504fa1SIlya Leoshkevich /**
5590a504fa1SIlya Leoshkevich  * @brief **bpf_btf_get_info_by_fd()** obtains information about the BPF
5600a504fa1SIlya Leoshkevich  * link corresponding to *link_fd*.
5610a504fa1SIlya Leoshkevich  *
5620a504fa1SIlya Leoshkevich  * Populates up to *info_len* bytes of *info* and updates *info_len* with the
563*1159d278SMatt Bobrowski  * actual number of bytes written to *info*. Note that *info* should be
564*1159d278SMatt Bobrowski  * zero-initialized or initialized as expected by the requested *info*
565*1159d278SMatt Bobrowski  * type. Failing to (zero-)initialize *info* under certain circumstances can
566*1159d278SMatt Bobrowski  * result in this helper returning an error.
5670a504fa1SIlya Leoshkevich  *
5680a504fa1SIlya Leoshkevich  * @param link_fd BPF link file descriptor
5690a504fa1SIlya Leoshkevich  * @param info pointer to **struct bpf_link_info** that will be populated with
5700a504fa1SIlya Leoshkevich  * BPF link information
5710a504fa1SIlya Leoshkevich  * @param info_len pointer to the size of *info*; on success updated with the
5720a504fa1SIlya Leoshkevich  * number of bytes written to *info*
5730a504fa1SIlya Leoshkevich  * @return 0, on success; negative error code, otherwise (errno is also set to
5740a504fa1SIlya Leoshkevich  * the error code)
5750a504fa1SIlya Leoshkevich  */
57655a9ed0eSIlya Leoshkevich LIBBPF_API int bpf_link_get_info_by_fd(int link_fd, struct bpf_link_info *info, __u32 *info_len);
577a4b2f3cfSStanislav Fomichev 
578a4b2f3cfSStanislav Fomichev struct bpf_prog_query_opts {
579a4b2f3cfSStanislav Fomichev 	size_t sz; /* size of this struct for forward/backward compatibility */
580a4b2f3cfSStanislav Fomichev 	__u32 query_flags;
581a4b2f3cfSStanislav Fomichev 	__u32 attach_flags; /* output argument */
582a4b2f3cfSStanislav Fomichev 	__u32 *prog_ids;
583fe20ce3aSDaniel Borkmann 	union {
584fe20ce3aSDaniel Borkmann 		/* input+output argument */
585fe20ce3aSDaniel Borkmann 		__u32 prog_cnt;
586fe20ce3aSDaniel Borkmann 		__u32 count;
587a4b2f3cfSStanislav Fomichev 	};
588fe20ce3aSDaniel Borkmann 	__u32 *prog_attach_flags;
589fe20ce3aSDaniel Borkmann 	__u32 *link_ids;
590fe20ce3aSDaniel Borkmann 	__u32 *link_attach_flags;
591fe20ce3aSDaniel Borkmann 	__u64 revision;
592fe20ce3aSDaniel Borkmann 	size_t :0;
593fe20ce3aSDaniel Borkmann };
594fe20ce3aSDaniel Borkmann #define bpf_prog_query_opts__last_field revision
595a4b2f3cfSStanislav Fomichev 
596fe20ce3aSDaniel Borkmann /**
597fe20ce3aSDaniel Borkmann  * @brief **bpf_prog_query_opts()** queries the BPF programs and BPF links
598fe20ce3aSDaniel Borkmann  * which are attached to *target* which can represent a file descriptor or
599fe20ce3aSDaniel Borkmann  * netdevice ifindex.
600fe20ce3aSDaniel Borkmann  *
601fe20ce3aSDaniel Borkmann  * @param target query location file descriptor or ifindex
602fe20ce3aSDaniel Borkmann  * @param type attach type for the BPF program
603fe20ce3aSDaniel Borkmann  * @param opts options for configuring the query
604fe20ce3aSDaniel Borkmann  * @return 0, on success; negative error code, otherwise (errno is also set to
605fe20ce3aSDaniel Borkmann  * the error code)
606fe20ce3aSDaniel Borkmann  */
607fe20ce3aSDaniel Borkmann LIBBPF_API int bpf_prog_query_opts(int target, enum bpf_attach_type type,
608a4b2f3cfSStanislav Fomichev 				   struct bpf_prog_query_opts *opts);
609ab9e0848SAndrey Ignatov LIBBPF_API int bpf_prog_query(int target_fd, enum bpf_attach_type type,
610ab9e0848SAndrey Ignatov 			      __u32 query_flags, __u32 *attach_flags,
611ab9e0848SAndrey Ignatov 			      __u32 *prog_ids, __u32 *prog_cnt);
612a4b2f3cfSStanislav Fomichev 
613ab9e0848SAndrey Ignatov LIBBPF_API int bpf_raw_tracepoint_open(const char *name, int prog_fd);
614ab9e0848SAndrey Ignatov LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf,
615ab9e0848SAndrey Ignatov 				 __u32 *buf_len, __u32 *prog_id, __u32 *fd_type,
616ab9e0848SAndrey Ignatov 				 __u64 *probe_offset, __u64 *probe_addr);
6174e15507fSAndrii Nakryiko 
618b4269341SAndrii Nakryiko #ifdef __cplusplus
619b4269341SAndrii Nakryiko /* forward-declaring enums in C++ isn't compatible with pure C enums, so
620b4269341SAndrii Nakryiko  * instead define bpf_enable_stats() as accepting int as an input
621b4269341SAndrii Nakryiko  */
622b4269341SAndrii Nakryiko LIBBPF_API int bpf_enable_stats(int type);
623b4269341SAndrii Nakryiko #else
6244e15507fSAndrii Nakryiko enum bpf_stats_type; /* defined in up-to-date linux/bpf.h */
6250bee1067SSong Liu LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type);
626b4269341SAndrii Nakryiko #endif
6278c4905b9SStanislav Fomichev 
6285d23328dSYiFei Zhu struct bpf_prog_bind_opts {
6295d23328dSYiFei Zhu 	size_t sz; /* size of this struct for forward/backward compatibility */
6305d23328dSYiFei Zhu 	__u32 flags;
6315d23328dSYiFei Zhu };
6325d23328dSYiFei Zhu #define bpf_prog_bind_opts__last_field flags
6335d23328dSYiFei Zhu 
6345d23328dSYiFei Zhu LIBBPF_API int bpf_prog_bind_map(int prog_fd, int map_fd,
6355d23328dSYiFei Zhu 				 const struct bpf_prog_bind_opts *opts);
63688f7fe72SSong Liu 
63788f7fe72SSong Liu struct bpf_test_run_opts {
63888f7fe72SSong Liu 	size_t sz; /* size of this struct for forward/backward compatibility */
63988f7fe72SSong Liu 	const void *data_in; /* optional */
64088f7fe72SSong Liu 	void *data_out;      /* optional */
64188f7fe72SSong Liu 	__u32 data_size_in;
64288f7fe72SSong Liu 	__u32 data_size_out; /* in: max length of data_out
64388f7fe72SSong Liu 			      * out: length of data_out
64488f7fe72SSong Liu 			      */
64588f7fe72SSong Liu 	const void *ctx_in; /* optional */
64688f7fe72SSong Liu 	void *ctx_out;      /* optional */
64788f7fe72SSong Liu 	__u32 ctx_size_in;
64888f7fe72SSong Liu 	__u32 ctx_size_out; /* in: max length of ctx_out
64988f7fe72SSong Liu 			     * out: length of cxt_out
65088f7fe72SSong Liu 			     */
65188f7fe72SSong Liu 	__u32 retval;        /* out: return code of the BPF program */
65288f7fe72SSong Liu 	int repeat;
65388f7fe72SSong Liu 	__u32 duration;      /* out: average per repetition in ns */
65488f7fe72SSong Liu 	__u32 flags;
65588f7fe72SSong Liu 	__u32 cpu;
65624592ad1SToke Høiland-Jørgensen 	__u32 batch_size;
65788f7fe72SSong Liu };
65824592ad1SToke Høiland-Jørgensen #define bpf_test_run_opts__last_field batch_size
65988f7fe72SSong Liu 
66088f7fe72SSong Liu LIBBPF_API int bpf_prog_test_run_opts(int prog_fd,
66188f7fe72SSong Liu 				      struct bpf_test_run_opts *opts);
66288f7fe72SSong Liu 
663639ecd7dSAndrii Nakryiko struct bpf_token_create_opts {
664639ecd7dSAndrii Nakryiko 	size_t sz; /* size of this struct for forward/backward compatibility */
665639ecd7dSAndrii Nakryiko 	__u32 flags;
666639ecd7dSAndrii Nakryiko 	size_t :0;
667639ecd7dSAndrii Nakryiko };
668639ecd7dSAndrii Nakryiko #define bpf_token_create_opts__last_field flags
669639ecd7dSAndrii Nakryiko 
670639ecd7dSAndrii Nakryiko /**
671639ecd7dSAndrii Nakryiko  * @brief **bpf_token_create()** creates a new instance of BPF token derived
672639ecd7dSAndrii Nakryiko  * from specified BPF FS mount point.
673639ecd7dSAndrii Nakryiko  *
674639ecd7dSAndrii Nakryiko  * BPF token created with this API can be passed to bpf() syscall for
675639ecd7dSAndrii Nakryiko  * commands like BPF_PROG_LOAD, BPF_MAP_CREATE, etc.
676639ecd7dSAndrii Nakryiko  *
677639ecd7dSAndrii Nakryiko  * @param bpffs_fd FD for BPF FS instance from which to derive a BPF token
678639ecd7dSAndrii Nakryiko  * instance.
679639ecd7dSAndrii Nakryiko  * @param opts optional BPF token creation options, can be NULL
680639ecd7dSAndrii Nakryiko  *
681639ecd7dSAndrii Nakryiko  * @return BPF token FD > 0, on success; negative error code, otherwise (errno
682639ecd7dSAndrii Nakryiko  * is also set to the error code)
683639ecd7dSAndrii Nakryiko  */
684639ecd7dSAndrii Nakryiko LIBBPF_API int bpf_token_create(int bpffs_fd,
685639ecd7dSAndrii Nakryiko 				struct bpf_token_create_opts *opts);
686639ecd7dSAndrii Nakryiko 
6878c4905b9SStanislav Fomichev #ifdef __cplusplus
6888c4905b9SStanislav Fomichev } /* extern "C" */
6898c4905b9SStanislav Fomichev #endif
6908c4905b9SStanislav Fomichev 
691eff81908SAndrey Ignatov #endif /* __LIBBPF_BPF_H */
692