11bc38b8fSAlexei Starovoitov /* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */ 26061a3d6SEric Leblond 3e3ed2fefSWang Nan /* 4e3ed2fefSWang Nan * common eBPF 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 38992c4225SAndrii Nakryiko struct bpf_map_create_opts { 39992c4225SAndrii Nakryiko size_t sz; /* size of this struct for forward/backward compatibility */ 40992c4225SAndrii Nakryiko 41992c4225SAndrii Nakryiko __u32 btf_fd; 42992c4225SAndrii Nakryiko __u32 btf_key_type_id; 43992c4225SAndrii Nakryiko __u32 btf_value_type_id; 44992c4225SAndrii Nakryiko __u32 btf_vmlinux_value_type_id; 45992c4225SAndrii Nakryiko 46*74d98070SAndrii Nakryiko __u32 inner_map_fd; 47*74d98070SAndrii Nakryiko __u32 map_flags; 48992c4225SAndrii Nakryiko __u64 map_extra; 49992c4225SAndrii Nakryiko 50*74d98070SAndrii Nakryiko __u32 numa_node; 51*74d98070SAndrii Nakryiko __u32 map_ifindex; 52992c4225SAndrii Nakryiko }; 53992c4225SAndrii Nakryiko #define bpf_map_create_opts__last_field map_ifindex 54992c4225SAndrii Nakryiko 55992c4225SAndrii Nakryiko LIBBPF_API int bpf_map_create(enum bpf_map_type map_type, 56992c4225SAndrii Nakryiko const char *map_name, 57992c4225SAndrii Nakryiko __u32 key_size, 58992c4225SAndrii Nakryiko __u32 value_size, 59992c4225SAndrii Nakryiko __u32 max_entries, 60992c4225SAndrii Nakryiko const struct bpf_map_create_opts *opts); 61992c4225SAndrii Nakryiko 628a138aedSMartin KaFai Lau struct bpf_create_map_attr { 638a138aedSMartin KaFai Lau const char *name; 648a138aedSMartin KaFai Lau enum bpf_map_type map_type; 658a138aedSMartin KaFai Lau __u32 map_flags; 668a138aedSMartin KaFai Lau __u32 key_size; 678a138aedSMartin KaFai Lau __u32 value_size; 688a138aedSMartin KaFai Lau __u32 max_entries; 698a138aedSMartin KaFai Lau __u32 numa_node; 708a138aedSMartin KaFai Lau __u32 btf_fd; 7161746dbeSMartin KaFai Lau __u32 btf_key_type_id; 7261746dbeSMartin KaFai Lau __u32 btf_value_type_id; 73f0307a7eSDavid Beckett __u32 map_ifindex; 74590a0088SMartin KaFai Lau union { 7591134d84SMartin KaFai Lau __u32 inner_map_fd; 76590a0088SMartin KaFai Lau __u32 btf_vmlinux_value_type_id; 77590a0088SMartin KaFai Lau }; 788a138aedSMartin KaFai Lau }; 798a138aedSMartin KaFai Lau 80992c4225SAndrii Nakryiko LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_map_create() instead") 81992c4225SAndrii Nakryiko LIBBPF_API int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr); 82992c4225SAndrii Nakryiko LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_map_create() instead") 83ab9e0848SAndrey Ignatov LIBBPF_API int bpf_create_map_node(enum bpf_map_type map_type, const char *name, 84ab9e0848SAndrey Ignatov int key_size, int value_size, 85ab9e0848SAndrey Ignatov int max_entries, __u32 map_flags, int node); 86992c4225SAndrii Nakryiko LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_map_create() instead") 87ab9e0848SAndrey Ignatov LIBBPF_API int bpf_create_map_name(enum bpf_map_type map_type, const char *name, 88ab9e0848SAndrey Ignatov int key_size, int value_size, 89a5580c7fSJoe Stringer int max_entries, __u32 map_flags); 90992c4225SAndrii Nakryiko LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_map_create() instead") 91ab9e0848SAndrey Ignatov LIBBPF_API int bpf_create_map(enum bpf_map_type map_type, int key_size, 92ab9e0848SAndrey Ignatov int value_size, int max_entries, __u32 map_flags); 93992c4225SAndrii Nakryiko LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_map_create() instead") 94ab9e0848SAndrey Ignatov LIBBPF_API int bpf_create_map_in_map_node(enum bpf_map_type map_type, 95ab9e0848SAndrey Ignatov const char *name, int key_size, 96ab9e0848SAndrey Ignatov int inner_map_fd, int max_entries, 97ad17d0e6SMartin KaFai Lau __u32 map_flags, int node); 98992c4225SAndrii Nakryiko LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_map_create() instead") 99ab9e0848SAndrey Ignatov LIBBPF_API int bpf_create_map_in_map(enum bpf_map_type map_type, 100ab9e0848SAndrey Ignatov const char *name, int key_size, 101ab9e0848SAndrey Ignatov int inner_map_fd, int max_entries, 10288cda1c9SMartin KaFai Lau __u32 map_flags); 103e3ed2fefSWang Nan 104d10ef2b8SAndrii Nakryiko struct bpf_prog_load_opts { 105d10ef2b8SAndrii Nakryiko size_t sz; /* size of this struct for forward/backward compatibility */ 106d10ef2b8SAndrii Nakryiko 107d10ef2b8SAndrii Nakryiko /* libbpf can retry BPF_PROG_LOAD command if bpf() syscall returns 108d10ef2b8SAndrii Nakryiko * -EAGAIN. This field determines how many attempts libbpf has to 109d10ef2b8SAndrii Nakryiko * make. If not specified, libbpf will use default value of 5. 110d10ef2b8SAndrii Nakryiko */ 111d10ef2b8SAndrii Nakryiko int attempts; 112d10ef2b8SAndrii Nakryiko 113d10ef2b8SAndrii Nakryiko enum bpf_attach_type expected_attach_type; 114d10ef2b8SAndrii Nakryiko __u32 prog_btf_fd; 115d10ef2b8SAndrii Nakryiko __u32 prog_flags; 116d10ef2b8SAndrii Nakryiko __u32 prog_ifindex; 117d10ef2b8SAndrii Nakryiko __u32 kern_version; 118d10ef2b8SAndrii Nakryiko 119d10ef2b8SAndrii Nakryiko __u32 attach_btf_id; 120d10ef2b8SAndrii Nakryiko __u32 attach_prog_fd; 121d10ef2b8SAndrii Nakryiko __u32 attach_btf_obj_fd; 122d10ef2b8SAndrii Nakryiko 123d10ef2b8SAndrii Nakryiko const int *fd_array; 124d10ef2b8SAndrii Nakryiko 125d10ef2b8SAndrii Nakryiko /* .BTF.ext func info data */ 126d10ef2b8SAndrii Nakryiko const void *func_info; 127d10ef2b8SAndrii Nakryiko __u32 func_info_cnt; 128d10ef2b8SAndrii Nakryiko __u32 func_info_rec_size; 129d10ef2b8SAndrii Nakryiko 130d10ef2b8SAndrii Nakryiko /* .BTF.ext line info data */ 131d10ef2b8SAndrii Nakryiko const void *line_info; 132d10ef2b8SAndrii Nakryiko __u32 line_info_cnt; 133d10ef2b8SAndrii Nakryiko __u32 line_info_rec_size; 134d10ef2b8SAndrii Nakryiko 135d10ef2b8SAndrii Nakryiko /* verifier log options */ 136d10ef2b8SAndrii Nakryiko __u32 log_level; 137d10ef2b8SAndrii Nakryiko __u32 log_size; 138d10ef2b8SAndrii Nakryiko char *log_buf; 139d10ef2b8SAndrii Nakryiko }; 140d10ef2b8SAndrii Nakryiko #define bpf_prog_load_opts__last_field log_buf 141d10ef2b8SAndrii Nakryiko 142d10ef2b8SAndrii Nakryiko LIBBPF_API int bpf_prog_load(enum bpf_prog_type prog_type, 143d10ef2b8SAndrii Nakryiko const char *prog_name, const char *license, 144d10ef2b8SAndrii Nakryiko const struct bpf_insn *insns, size_t insn_cnt, 145d10ef2b8SAndrii Nakryiko const struct bpf_prog_load_opts *opts); 146d10ef2b8SAndrii Nakryiko /* this "specialization" should go away in libbpf 1.0 */ 147d10ef2b8SAndrii Nakryiko LIBBPF_API int bpf_prog_load_v0_6_0(enum bpf_prog_type prog_type, 148d10ef2b8SAndrii Nakryiko const char *prog_name, const char *license, 149d10ef2b8SAndrii Nakryiko const struct bpf_insn *insns, size_t insn_cnt, 150d10ef2b8SAndrii Nakryiko const struct bpf_prog_load_opts *opts); 151d10ef2b8SAndrii Nakryiko 152d10ef2b8SAndrii Nakryiko /* This is an elaborate way to not conflict with deprecated bpf_prog_load() 153d10ef2b8SAndrii Nakryiko * API, defined in libbpf.h. Once we hit libbpf 1.0, all this will be gone. 154d10ef2b8SAndrii Nakryiko * With this approach, if someone is calling bpf_prog_load() with 155d10ef2b8SAndrii Nakryiko * 4 arguments, they will use the deprecated API, which keeps backwards 156d10ef2b8SAndrii Nakryiko * compatibility (both source code and binary). If bpf_prog_load() is called 157d10ef2b8SAndrii Nakryiko * with 6 arguments, though, it gets redirected to __bpf_prog_load. 158d10ef2b8SAndrii Nakryiko * So looking forward to libbpf 1.0 when this hack will be gone and 159d10ef2b8SAndrii Nakryiko * __bpf_prog_load() will be called just bpf_prog_load(). 160d10ef2b8SAndrii Nakryiko */ 161d10ef2b8SAndrii Nakryiko #ifndef bpf_prog_load 162d10ef2b8SAndrii Nakryiko #define bpf_prog_load(...) ___libbpf_overload(___bpf_prog_load, __VA_ARGS__) 163d10ef2b8SAndrii Nakryiko #define ___bpf_prog_load4(file, type, pobj, prog_fd) \ 164d10ef2b8SAndrii Nakryiko bpf_prog_load_deprecated(file, type, pobj, prog_fd) 165d10ef2b8SAndrii Nakryiko #define ___bpf_prog_load6(prog_type, prog_name, license, insns, insn_cnt, opts) \ 166d10ef2b8SAndrii Nakryiko bpf_prog_load(prog_type, prog_name, license, insns, insn_cnt, opts) 167d10ef2b8SAndrii Nakryiko #endif /* bpf_prog_load */ 168d10ef2b8SAndrii Nakryiko 169d7be143bSAndrey Ignatov struct bpf_load_program_attr { 170d7be143bSAndrey Ignatov enum bpf_prog_type prog_type; 171d7be143bSAndrey Ignatov enum bpf_attach_type expected_attach_type; 172d7be143bSAndrey Ignatov const char *name; 173d7be143bSAndrey Ignatov const struct bpf_insn *insns; 174d7be143bSAndrey Ignatov size_t insns_cnt; 175d7be143bSAndrey Ignatov const char *license; 176e7bf94dbSAlexei Starovoitov union { 177d7be143bSAndrey Ignatov __u32 kern_version; 178e7bf94dbSAlexei Starovoitov __u32 attach_prog_fd; 179e7bf94dbSAlexei Starovoitov }; 18012a8654bSAlexei Starovoitov union { 181f0307a7eSDavid Beckett __u32 prog_ifindex; 18212a8654bSAlexei Starovoitov __u32 attach_btf_id; 18312a8654bSAlexei Starovoitov }; 1847e0d0fb5SYonghong Song __u32 prog_btf_fd; 1857e0d0fb5SYonghong Song __u32 func_info_rec_size; 1867e0d0fb5SYonghong Song const void *func_info; 1877e0d0fb5SYonghong Song __u32 func_info_cnt; 1883d650141SMartin KaFai Lau __u32 line_info_rec_size; 1893d650141SMartin KaFai Lau const void *line_info; 1903d650141SMartin KaFai Lau __u32 line_info_cnt; 191a4021a35SYonghong Song __u32 log_level; 19204656198SJiong Wang __u32 prog_flags; 193d7be143bSAndrey Ignatov }; 194d7be143bSAndrey Ignatov 195c034a177SJohn Fastabend /* Flags to direct loading requirements */ 196c034a177SJohn Fastabend #define MAPS_RELAX_COMPAT 0x01 197c034a177SJohn Fastabend 1987bf98369SWang Nan /* Recommend log buffer size */ 1994519efa6SMcCabe, Robert J #define BPF_LOG_BUF_SIZE (UINT32_MAX >> 8) /* verifier maximum in kernels <= 5.1 */ 200d10ef2b8SAndrii Nakryiko LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_load() instead") 201d10ef2b8SAndrii Nakryiko LIBBPF_API int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr, 202d7be143bSAndrey Ignatov char *log_buf, size_t log_buf_sz); 203d10ef2b8SAndrii Nakryiko LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_load() instead") 204ab9e0848SAndrey Ignatov LIBBPF_API int bpf_load_program(enum bpf_prog_type type, 205ab9e0848SAndrey Ignatov const struct bpf_insn *insns, size_t insns_cnt, 206ab9e0848SAndrey Ignatov const char *license, __u32 kern_version, 207ab9e0848SAndrey Ignatov char *log_buf, size_t log_buf_sz); 208d10ef2b8SAndrii Nakryiko LIBBPF_DEPRECATED_SINCE(0, 7, "use bpf_prog_load() instead") 209ab9e0848SAndrey Ignatov LIBBPF_API int bpf_verify_program(enum bpf_prog_type type, 210ab9e0848SAndrey Ignatov const struct bpf_insn *insns, 211e9ee9efcSDavid Miller size_t insns_cnt, __u32 prog_flags, 21291045f5eSDavid S. Miller const char *license, __u32 kern_version, 213ab9e0848SAndrey Ignatov char *log_buf, size_t log_buf_sz, 214ab9e0848SAndrey Ignatov int log_level); 2157bf98369SWang Nan 216ab9e0848SAndrey Ignatov LIBBPF_API int bpf_map_update_elem(int fd, const void *key, const void *value, 21783d994d0SJoe Stringer __u64 flags); 2189742da01SWang Nan 219ab9e0848SAndrey Ignatov LIBBPF_API int bpf_map_lookup_elem(int fd, const void *key, void *value); 220df5d22faSAlexei Starovoitov LIBBPF_API int bpf_map_lookup_elem_flags(int fd, const void *key, void *value, 221df5d22faSAlexei Starovoitov __u64 flags); 22243b987d2SMauricio Vasquez B LIBBPF_API int bpf_map_lookup_and_delete_elem(int fd, const void *key, 22343b987d2SMauricio Vasquez B void *value); 224d59b9f2dSDenis Salopek LIBBPF_API int bpf_map_lookup_and_delete_elem_flags(int fd, const void *key, 225d59b9f2dSDenis Salopek void *value, __u64 flags); 226ab9e0848SAndrey Ignatov LIBBPF_API int bpf_map_delete_elem(int fd, const void *key); 227ab9e0848SAndrey Ignatov LIBBPF_API int bpf_map_get_next_key(int fd, const void *key, void *next_key); 228d859900cSDaniel Borkmann LIBBPF_API int bpf_map_freeze(int fd); 2292ab3d86eSYonghong Song 2302ab3d86eSYonghong Song struct bpf_map_batch_opts { 2312ab3d86eSYonghong Song size_t sz; /* size of this struct for forward/backward compatibility */ 2322ab3d86eSYonghong Song __u64 elem_flags; 2332ab3d86eSYonghong Song __u64 flags; 2342ab3d86eSYonghong Song }; 2352ab3d86eSYonghong Song #define bpf_map_batch_opts__last_field flags 2362ab3d86eSYonghong Song 2372ab3d86eSYonghong Song LIBBPF_API int bpf_map_delete_batch(int fd, void *keys, 2382ab3d86eSYonghong Song __u32 *count, 2392ab3d86eSYonghong Song const struct bpf_map_batch_opts *opts); 2402ab3d86eSYonghong Song LIBBPF_API int bpf_map_lookup_batch(int fd, void *in_batch, void *out_batch, 2412ab3d86eSYonghong Song void *keys, void *values, __u32 *count, 2422ab3d86eSYonghong Song const struct bpf_map_batch_opts *opts); 2432ab3d86eSYonghong Song LIBBPF_API int bpf_map_lookup_and_delete_batch(int fd, void *in_batch, 2442ab3d86eSYonghong Song void *out_batch, void *keys, 2452ab3d86eSYonghong Song void *values, __u32 *count, 2462ab3d86eSYonghong Song const struct bpf_map_batch_opts *opts); 2472ab3d86eSYonghong Song LIBBPF_API int bpf_map_update_batch(int fd, void *keys, void *values, 2482ab3d86eSYonghong Song __u32 *count, 2492ab3d86eSYonghong Song const struct bpf_map_batch_opts *opts); 2502ab3d86eSYonghong Song 251ab9e0848SAndrey Ignatov LIBBPF_API int bpf_obj_pin(int fd, const char *pathname); 252ab9e0848SAndrey Ignatov LIBBPF_API int bpf_obj_get(const char *pathname); 253cdbee383SAndrey Ignatov 254cdbee383SAndrey Ignatov struct bpf_prog_attach_opts { 255cdbee383SAndrey Ignatov size_t sz; /* size of this struct for forward/backward compatibility */ 256cdbee383SAndrey Ignatov unsigned int flags; 257cdbee383SAndrey Ignatov int replace_prog_fd; 258cdbee383SAndrey Ignatov }; 259cdbee383SAndrey Ignatov #define bpf_prog_attach_opts__last_field replace_prog_fd 260cdbee383SAndrey Ignatov 261ab9e0848SAndrey Ignatov LIBBPF_API int bpf_prog_attach(int prog_fd, int attachable_fd, 262ab9e0848SAndrey Ignatov enum bpf_attach_type type, unsigned int flags); 263cdbee383SAndrey Ignatov LIBBPF_API int bpf_prog_attach_xattr(int prog_fd, int attachable_fd, 264cdbee383SAndrey Ignatov enum bpf_attach_type type, 265cdbee383SAndrey Ignatov const struct bpf_prog_attach_opts *opts); 266ab9e0848SAndrey Ignatov LIBBPF_API int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type); 267ab9e0848SAndrey Ignatov LIBBPF_API int bpf_prog_detach2(int prog_fd, int attachable_fd, 268ab9e0848SAndrey Ignatov enum bpf_attach_type type); 26964a97591SLorenz Bauer 27074fc097dSYonghong Song union bpf_iter_link_info; /* defined in up-to-date linux/bpf.h */ 271cc4f864bSAndrii Nakryiko struct bpf_link_create_opts { 272cc4f864bSAndrii Nakryiko size_t sz; /* size of this struct for forward/backward compatibility */ 273cd31039aSYonghong Song __u32 flags; 27474fc097dSYonghong Song union bpf_iter_link_info *iter_info; 27574fc097dSYonghong Song __u32 iter_info_len; 276a5359091SToke Høiland-Jørgensen __u32 target_btf_id; 2773ec84f4bSAndrii Nakryiko union { 2783ec84f4bSAndrii Nakryiko struct { 2793ec84f4bSAndrii Nakryiko __u64 bpf_cookie; 2803ec84f4bSAndrii Nakryiko } perf_event; 281cc4f864bSAndrii Nakryiko }; 2823ec84f4bSAndrii Nakryiko size_t :0; 2833ec84f4bSAndrii Nakryiko }; 2843ec84f4bSAndrii Nakryiko #define bpf_link_create_opts__last_field perf_event 285cc4f864bSAndrii Nakryiko 286cc4f864bSAndrii Nakryiko LIBBPF_API int bpf_link_create(int prog_fd, int target_fd, 287cc4f864bSAndrii Nakryiko enum bpf_attach_type attach_type, 288cc4f864bSAndrii Nakryiko const struct bpf_link_create_opts *opts); 289cc4f864bSAndrii Nakryiko 2902e49527eSAndrii Nakryiko LIBBPF_API int bpf_link_detach(int link_fd); 2912e49527eSAndrii Nakryiko 292cc4f864bSAndrii Nakryiko struct bpf_link_update_opts { 293cc4f864bSAndrii Nakryiko size_t sz; /* size of this struct for forward/backward compatibility */ 294cc4f864bSAndrii Nakryiko __u32 flags; /* extra flags */ 295cc4f864bSAndrii Nakryiko __u32 old_prog_fd; /* expected old program FD */ 296cc4f864bSAndrii Nakryiko }; 297cc4f864bSAndrii Nakryiko #define bpf_link_update_opts__last_field old_prog_fd 298cc4f864bSAndrii Nakryiko 299cc4f864bSAndrii Nakryiko LIBBPF_API int bpf_link_update(int link_fd, int new_prog_fd, 300cc4f864bSAndrii Nakryiko const struct bpf_link_update_opts *opts); 301cc4f864bSAndrii Nakryiko 302c09add2fSYonghong Song LIBBPF_API int bpf_iter_create(int link_fd); 303c09add2fSYonghong Song 30464a97591SLorenz Bauer struct bpf_prog_test_run_attr { 30564a97591SLorenz Bauer int prog_fd; 30664a97591SLorenz Bauer int repeat; 30764a97591SLorenz Bauer const void *data_in; 30864a97591SLorenz Bauer __u32 data_size_in; 30964a97591SLorenz Bauer void *data_out; /* optional */ 31064a97591SLorenz Bauer __u32 data_size_out; /* in: max length of data_out 31164a97591SLorenz Bauer * out: length of data_out */ 31264a97591SLorenz Bauer __u32 retval; /* out: return code of the BPF program */ 31364a97591SLorenz Bauer __u32 duration; /* out: average per repetition in ns */ 3145e903c65SStanislav Fomichev const void *ctx_in; /* optional */ 3155e903c65SStanislav Fomichev __u32 ctx_size_in; 3165e903c65SStanislav Fomichev void *ctx_out; /* optional */ 3175e903c65SStanislav Fomichev __u32 ctx_size_out; /* in: max length of ctx_out 3185e903c65SStanislav Fomichev * out: length of cxt_out */ 31964a97591SLorenz Bauer }; 32064a97591SLorenz Bauer 32164a97591SLorenz Bauer LIBBPF_API int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr); 32264a97591SLorenz Bauer 32364a97591SLorenz Bauer /* 32464a97591SLorenz Bauer * bpf_prog_test_run does not check that data_out is large enough. Consider 32564a97591SLorenz Bauer * using bpf_prog_test_run_xattr instead. 32664a97591SLorenz Bauer */ 327ab9e0848SAndrey Ignatov LIBBPF_API int bpf_prog_test_run(int prog_fd, int repeat, void *data, 328ab9e0848SAndrey Ignatov __u32 size, void *data_out, __u32 *size_out, 329ab9e0848SAndrey Ignatov __u32 *retval, __u32 *duration); 330ab9e0848SAndrey Ignatov LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id); 331ab9e0848SAndrey Ignatov LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id); 33209d7c2e3SQuentin Monnet LIBBPF_API int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id); 3330dbc8668SAndrii Nakryiko LIBBPF_API int bpf_link_get_next_id(__u32 start_id, __u32 *next_id); 334ab9e0848SAndrey Ignatov LIBBPF_API int bpf_prog_get_fd_by_id(__u32 id); 335ab9e0848SAndrey Ignatov LIBBPF_API int bpf_map_get_fd_by_id(__u32 id); 336ab9e0848SAndrey Ignatov LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id); 3370dbc8668SAndrii Nakryiko LIBBPF_API int bpf_link_get_fd_by_id(__u32 id); 3380dbc8668SAndrii Nakryiko LIBBPF_API int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len); 339ab9e0848SAndrey Ignatov LIBBPF_API int bpf_prog_query(int target_fd, enum bpf_attach_type type, 340ab9e0848SAndrey Ignatov __u32 query_flags, __u32 *attach_flags, 341ab9e0848SAndrey Ignatov __u32 *prog_ids, __u32 *prog_cnt); 342ab9e0848SAndrey Ignatov LIBBPF_API int bpf_raw_tracepoint_open(const char *name, int prog_fd); 343b8604247SAndrii Nakryiko LIBBPF_API int bpf_load_btf(const void *btf, __u32 btf_size, char *log_buf, 344ab9e0848SAndrey Ignatov __u32 log_buf_size, bool do_log); 345ab9e0848SAndrey Ignatov LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, 346ab9e0848SAndrey Ignatov __u32 *buf_len, __u32 *prog_id, __u32 *fd_type, 347ab9e0848SAndrey Ignatov __u64 *probe_offset, __u64 *probe_addr); 3484e15507fSAndrii Nakryiko 3494e15507fSAndrii Nakryiko enum bpf_stats_type; /* defined in up-to-date linux/bpf.h */ 3500bee1067SSong Liu LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type); 3518c4905b9SStanislav Fomichev 3525d23328dSYiFei Zhu struct bpf_prog_bind_opts { 3535d23328dSYiFei Zhu size_t sz; /* size of this struct for forward/backward compatibility */ 3545d23328dSYiFei Zhu __u32 flags; 3555d23328dSYiFei Zhu }; 3565d23328dSYiFei Zhu #define bpf_prog_bind_opts__last_field flags 3575d23328dSYiFei Zhu 3585d23328dSYiFei Zhu LIBBPF_API int bpf_prog_bind_map(int prog_fd, int map_fd, 3595d23328dSYiFei Zhu const struct bpf_prog_bind_opts *opts); 36088f7fe72SSong Liu 36188f7fe72SSong Liu struct bpf_test_run_opts { 36288f7fe72SSong Liu size_t sz; /* size of this struct for forward/backward compatibility */ 36388f7fe72SSong Liu const void *data_in; /* optional */ 36488f7fe72SSong Liu void *data_out; /* optional */ 36588f7fe72SSong Liu __u32 data_size_in; 36688f7fe72SSong Liu __u32 data_size_out; /* in: max length of data_out 36788f7fe72SSong Liu * out: length of data_out 36888f7fe72SSong Liu */ 36988f7fe72SSong Liu const void *ctx_in; /* optional */ 37088f7fe72SSong Liu void *ctx_out; /* optional */ 37188f7fe72SSong Liu __u32 ctx_size_in; 37288f7fe72SSong Liu __u32 ctx_size_out; /* in: max length of ctx_out 37388f7fe72SSong Liu * out: length of cxt_out 37488f7fe72SSong Liu */ 37588f7fe72SSong Liu __u32 retval; /* out: return code of the BPF program */ 37688f7fe72SSong Liu int repeat; 37788f7fe72SSong Liu __u32 duration; /* out: average per repetition in ns */ 37888f7fe72SSong Liu __u32 flags; 37988f7fe72SSong Liu __u32 cpu; 38088f7fe72SSong Liu }; 38188f7fe72SSong Liu #define bpf_test_run_opts__last_field cpu 38288f7fe72SSong Liu 38388f7fe72SSong Liu LIBBPF_API int bpf_prog_test_run_opts(int prog_fd, 38488f7fe72SSong Liu struct bpf_test_run_opts *opts); 38588f7fe72SSong Liu 3868c4905b9SStanislav Fomichev #ifdef __cplusplus 3878c4905b9SStanislav Fomichev } /* extern "C" */ 3888c4905b9SStanislav Fomichev #endif 3898c4905b9SStanislav Fomichev 390eff81908SAndrey Ignatov #endif /* __LIBBPF_BPF_H */ 391