0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #ifndef __LIBBPF_BPF_H
0024 #define __LIBBPF_BPF_H
0025
0026 #include <linux/bpf.h>
0027 #include <stdbool.h>
0028 #include <stddef.h>
0029 #include <stdint.h>
0030
0031 #include "libbpf_common.h"
0032 #include "libbpf_legacy.h"
0033
0034 #ifdef __cplusplus
0035 extern "C" {
0036 #endif
0037
0038 int libbpf_set_memlock_rlim(size_t memlock_bytes);
0039
0040 struct bpf_map_create_opts {
0041 size_t sz;
0042
0043 __u32 btf_fd;
0044 __u32 btf_key_type_id;
0045 __u32 btf_value_type_id;
0046 __u32 btf_vmlinux_value_type_id;
0047
0048 __u32 inner_map_fd;
0049 __u32 map_flags;
0050 __u64 map_extra;
0051
0052 __u32 numa_node;
0053 __u32 map_ifindex;
0054 };
0055 #define bpf_map_create_opts__last_field map_ifindex
0056
0057 LIBBPF_API int bpf_map_create(enum bpf_map_type map_type,
0058 const char *map_name,
0059 __u32 key_size,
0060 __u32 value_size,
0061 __u32 max_entries,
0062 const struct bpf_map_create_opts *opts);
0063
0064 struct bpf_prog_load_opts {
0065 size_t sz;
0066
0067
0068
0069
0070
0071 int attempts;
0072
0073 enum bpf_attach_type expected_attach_type;
0074 __u32 prog_btf_fd;
0075 __u32 prog_flags;
0076 __u32 prog_ifindex;
0077 __u32 kern_version;
0078
0079 __u32 attach_btf_id;
0080 __u32 attach_prog_fd;
0081 __u32 attach_btf_obj_fd;
0082
0083 const int *fd_array;
0084
0085
0086 const void *func_info;
0087 __u32 func_info_cnt;
0088 __u32 func_info_rec_size;
0089
0090
0091 const void *line_info;
0092 __u32 line_info_cnt;
0093 __u32 line_info_rec_size;
0094
0095
0096 __u32 log_level;
0097 __u32 log_size;
0098 char *log_buf;
0099 };
0100 #define bpf_prog_load_opts__last_field log_buf
0101
0102 LIBBPF_API int bpf_prog_load(enum bpf_prog_type prog_type,
0103 const char *prog_name, const char *license,
0104 const struct bpf_insn *insns, size_t insn_cnt,
0105 const struct bpf_prog_load_opts *opts);
0106
0107
0108 #define MAPS_RELAX_COMPAT 0x01
0109
0110
0111 #define BPF_LOG_BUF_SIZE (UINT32_MAX >> 8)
0112
0113 struct bpf_btf_load_opts {
0114 size_t sz;
0115
0116
0117 char *log_buf;
0118 __u32 log_level;
0119 __u32 log_size;
0120 };
0121 #define bpf_btf_load_opts__last_field log_size
0122
0123 LIBBPF_API int bpf_btf_load(const void *btf_data, size_t btf_size,
0124 const struct bpf_btf_load_opts *opts);
0125
0126 LIBBPF_API int bpf_map_update_elem(int fd, const void *key, const void *value,
0127 __u64 flags);
0128
0129 LIBBPF_API int bpf_map_lookup_elem(int fd, const void *key, void *value);
0130 LIBBPF_API int bpf_map_lookup_elem_flags(int fd, const void *key, void *value,
0131 __u64 flags);
0132 LIBBPF_API int bpf_map_lookup_and_delete_elem(int fd, const void *key,
0133 void *value);
0134 LIBBPF_API int bpf_map_lookup_and_delete_elem_flags(int fd, const void *key,
0135 void *value, __u64 flags);
0136 LIBBPF_API int bpf_map_delete_elem(int fd, const void *key);
0137 LIBBPF_API int bpf_map_delete_elem_flags(int fd, const void *key, __u64 flags);
0138 LIBBPF_API int bpf_map_get_next_key(int fd, const void *key, void *next_key);
0139 LIBBPF_API int bpf_map_freeze(int fd);
0140
0141 struct bpf_map_batch_opts {
0142 size_t sz;
0143 __u64 elem_flags;
0144 __u64 flags;
0145 };
0146 #define bpf_map_batch_opts__last_field flags
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163
0164 LIBBPF_API int bpf_map_delete_batch(int fd, const void *keys,
0165 __u32 *count,
0166 const struct bpf_map_batch_opts *opts);
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197 LIBBPF_API int bpf_map_lookup_batch(int fd, void *in_batch, void *out_batch,
0198 void *keys, void *values, __u32 *count,
0199 const struct bpf_map_batch_opts *opts);
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223 LIBBPF_API int bpf_map_lookup_and_delete_batch(int fd, void *in_batch,
0224 void *out_batch, void *keys,
0225 void *values, __u32 *count,
0226 const struct bpf_map_batch_opts *opts);
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269 LIBBPF_API int bpf_map_update_batch(int fd, const void *keys, const void *values,
0270 __u32 *count,
0271 const struct bpf_map_batch_opts *opts);
0272
0273 struct bpf_obj_get_opts {
0274 size_t sz;
0275
0276 __u32 file_flags;
0277
0278 size_t :0;
0279 };
0280 #define bpf_obj_get_opts__last_field file_flags
0281
0282 LIBBPF_API int bpf_obj_pin(int fd, const char *pathname);
0283 LIBBPF_API int bpf_obj_get(const char *pathname);
0284 LIBBPF_API int bpf_obj_get_opts(const char *pathname,
0285 const struct bpf_obj_get_opts *opts);
0286
0287 struct bpf_prog_attach_opts {
0288 size_t sz;
0289 unsigned int flags;
0290 int replace_prog_fd;
0291 };
0292 #define bpf_prog_attach_opts__last_field replace_prog_fd
0293
0294 LIBBPF_API int bpf_prog_attach(int prog_fd, int attachable_fd,
0295 enum bpf_attach_type type, unsigned int flags);
0296 LIBBPF_API int bpf_prog_attach_opts(int prog_fd, int attachable_fd,
0297 enum bpf_attach_type type,
0298 const struct bpf_prog_attach_opts *opts);
0299 LIBBPF_API int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type);
0300 LIBBPF_API int bpf_prog_detach2(int prog_fd, int attachable_fd,
0301 enum bpf_attach_type type);
0302
0303 union bpf_iter_link_info;
0304 struct bpf_link_create_opts {
0305 size_t sz;
0306 __u32 flags;
0307 union bpf_iter_link_info *iter_info;
0308 __u32 iter_info_len;
0309 __u32 target_btf_id;
0310 union {
0311 struct {
0312 __u64 bpf_cookie;
0313 } perf_event;
0314 struct {
0315 __u32 flags;
0316 __u32 cnt;
0317 const char **syms;
0318 const unsigned long *addrs;
0319 const __u64 *cookies;
0320 } kprobe_multi;
0321 struct {
0322 __u64 cookie;
0323 } tracing;
0324 };
0325 size_t :0;
0326 };
0327 #define bpf_link_create_opts__last_field kprobe_multi.cookies
0328
0329 LIBBPF_API int bpf_link_create(int prog_fd, int target_fd,
0330 enum bpf_attach_type attach_type,
0331 const struct bpf_link_create_opts *opts);
0332
0333 LIBBPF_API int bpf_link_detach(int link_fd);
0334
0335 struct bpf_link_update_opts {
0336 size_t sz;
0337 __u32 flags;
0338 __u32 old_prog_fd;
0339 };
0340 #define bpf_link_update_opts__last_field old_prog_fd
0341
0342 LIBBPF_API int bpf_link_update(int link_fd, int new_prog_fd,
0343 const struct bpf_link_update_opts *opts);
0344
0345 LIBBPF_API int bpf_iter_create(int link_fd);
0346
0347 struct bpf_prog_test_run_attr {
0348 int prog_fd;
0349 int repeat;
0350 const void *data_in;
0351 __u32 data_size_in;
0352 void *data_out;
0353 __u32 data_size_out;
0354
0355 __u32 retval;
0356 __u32 duration;
0357 const void *ctx_in;
0358 __u32 ctx_size_in;
0359 void *ctx_out;
0360 __u32 ctx_size_out;
0361
0362 };
0363
0364 LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id);
0365 LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id);
0366 LIBBPF_API int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id);
0367 LIBBPF_API int bpf_link_get_next_id(__u32 start_id, __u32 *next_id);
0368 LIBBPF_API int bpf_prog_get_fd_by_id(__u32 id);
0369 LIBBPF_API int bpf_map_get_fd_by_id(__u32 id);
0370 LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id);
0371 LIBBPF_API int bpf_link_get_fd_by_id(__u32 id);
0372 LIBBPF_API int bpf_obj_get_info_by_fd(int bpf_fd, void *info, __u32 *info_len);
0373
0374 struct bpf_prog_query_opts {
0375 size_t sz;
0376 __u32 query_flags;
0377 __u32 attach_flags;
0378 __u32 *prog_ids;
0379 __u32 prog_cnt;
0380 __u32 *prog_attach_flags;
0381 };
0382 #define bpf_prog_query_opts__last_field prog_attach_flags
0383
0384 LIBBPF_API int bpf_prog_query_opts(int target_fd,
0385 enum bpf_attach_type type,
0386 struct bpf_prog_query_opts *opts);
0387 LIBBPF_API int bpf_prog_query(int target_fd, enum bpf_attach_type type,
0388 __u32 query_flags, __u32 *attach_flags,
0389 __u32 *prog_ids, __u32 *prog_cnt);
0390
0391 LIBBPF_API int bpf_raw_tracepoint_open(const char *name, int prog_fd);
0392 LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf,
0393 __u32 *buf_len, __u32 *prog_id, __u32 *fd_type,
0394 __u64 *probe_offset, __u64 *probe_addr);
0395
0396 enum bpf_stats_type;
0397 LIBBPF_API int bpf_enable_stats(enum bpf_stats_type type);
0398
0399 struct bpf_prog_bind_opts {
0400 size_t sz;
0401 __u32 flags;
0402 };
0403 #define bpf_prog_bind_opts__last_field flags
0404
0405 LIBBPF_API int bpf_prog_bind_map(int prog_fd, int map_fd,
0406 const struct bpf_prog_bind_opts *opts);
0407
0408 struct bpf_test_run_opts {
0409 size_t sz;
0410 const void *data_in;
0411 void *data_out;
0412 __u32 data_size_in;
0413 __u32 data_size_out;
0414
0415
0416 const void *ctx_in;
0417 void *ctx_out;
0418 __u32 ctx_size_in;
0419 __u32 ctx_size_out;
0420
0421
0422 __u32 retval;
0423 int repeat;
0424 __u32 duration;
0425 __u32 flags;
0426 __u32 cpu;
0427 __u32 batch_size;
0428 };
0429 #define bpf_test_run_opts__last_field batch_size
0430
0431 LIBBPF_API int bpf_prog_test_run_opts(int prog_fd,
0432 struct bpf_test_run_opts *opts);
0433
0434 #ifdef __cplusplus
0435 }
0436 #endif
0437
0438 #endif