1
2
3
4
5
6
7
8
9
10#ifndef __LIBBPF_LIBBPF_H
11#define __LIBBPF_LIBBPF_H
12
13#include <stdarg.h>
14#include <stdio.h>
15#include <stdint.h>
16#include <stdbool.h>
17#include <sys/types.h>
18#include <linux/bpf.h>
19
20#include "libbpf_common.h"
21#include "libbpf_legacy.h"
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27enum libbpf_errno {
28 __LIBBPF_ERRNO__START = 4000,
29
30
31 LIBBPF_ERRNO__LIBELF = __LIBBPF_ERRNO__START,
32 LIBBPF_ERRNO__FORMAT,
33 LIBBPF_ERRNO__KVERSION,
34 LIBBPF_ERRNO__ENDIAN,
35 LIBBPF_ERRNO__INTERNAL,
36 LIBBPF_ERRNO__RELOC,
37 LIBBPF_ERRNO__LOAD,
38 LIBBPF_ERRNO__VERIFY,
39 LIBBPF_ERRNO__PROG2BIG,
40 LIBBPF_ERRNO__KVER,
41 LIBBPF_ERRNO__PROGTYPE,
42 LIBBPF_ERRNO__WRNGPID,
43 LIBBPF_ERRNO__INVSEQ,
44 LIBBPF_ERRNO__NLPARSE,
45 __LIBBPF_ERRNO__END,
46};
47
48LIBBPF_API int libbpf_strerror(int err, char *buf, size_t size);
49
50enum libbpf_print_level {
51 LIBBPF_WARN,
52 LIBBPF_INFO,
53 LIBBPF_DEBUG,
54};
55
56typedef int (*libbpf_print_fn_t)(enum libbpf_print_level level,
57 const char *, va_list ap);
58
59LIBBPF_API libbpf_print_fn_t libbpf_set_print(libbpf_print_fn_t fn);
60
61
62struct bpf_object;
63
64struct bpf_object_open_attr {
65 const char *file;
66 enum bpf_prog_type prog_type;
67};
68
69struct bpf_object_open_opts {
70
71 size_t sz;
72
73
74
75
76
77
78 const char *object_name;
79
80 bool relaxed_maps;
81
82
83
84
85
86 bool relaxed_core_relocs;
87
88
89
90
91 const char *pin_root_path;
92 __u32 attach_prog_fd;
93
94
95
96 const char *kconfig;
97
98
99
100
101
102
103 const char *btf_custom_path;
104};
105#define bpf_object_open_opts__last_field btf_custom_path
106
107LIBBPF_API struct bpf_object *bpf_object__open(const char *path);
108LIBBPF_API struct bpf_object *
109bpf_object__open_file(const char *path, const struct bpf_object_open_opts *opts);
110LIBBPF_API struct bpf_object *
111bpf_object__open_mem(const void *obj_buf, size_t obj_buf_sz,
112 const struct bpf_object_open_opts *opts);
113
114
115LIBBPF_API struct bpf_object *
116bpf_object__open_buffer(const void *obj_buf, size_t obj_buf_sz,
117 const char *name);
118LIBBPF_API struct bpf_object *
119bpf_object__open_xattr(struct bpf_object_open_attr *attr);
120
121enum libbpf_pin_type {
122 LIBBPF_PIN_NONE,
123
124 LIBBPF_PIN_BY_NAME,
125};
126
127
128
129
130
131LIBBPF_API int bpf_object__pin_maps(struct bpf_object *obj, const char *path);
132LIBBPF_API int bpf_object__unpin_maps(struct bpf_object *obj,
133 const char *path);
134LIBBPF_API int bpf_object__pin_programs(struct bpf_object *obj,
135 const char *path);
136LIBBPF_API int bpf_object__unpin_programs(struct bpf_object *obj,
137 const char *path);
138LIBBPF_API int bpf_object__pin(struct bpf_object *object, const char *path);
139LIBBPF_API void bpf_object__close(struct bpf_object *object);
140
141struct bpf_object_load_attr {
142 struct bpf_object *obj;
143 int log_level;
144 const char *target_btf_path;
145};
146
147
148LIBBPF_API int bpf_object__load(struct bpf_object *obj);
149LIBBPF_API int bpf_object__load_xattr(struct bpf_object_load_attr *attr);
150LIBBPF_API int bpf_object__unload(struct bpf_object *obj);
151
152LIBBPF_API const char *bpf_object__name(const struct bpf_object *obj);
153LIBBPF_API unsigned int bpf_object__kversion(const struct bpf_object *obj);
154LIBBPF_API int bpf_object__set_kversion(struct bpf_object *obj, __u32 kern_version);
155
156struct btf;
157LIBBPF_API struct btf *bpf_object__btf(const struct bpf_object *obj);
158LIBBPF_API int bpf_object__btf_fd(const struct bpf_object *obj);
159
160LIBBPF_API struct bpf_program *
161bpf_object__find_program_by_title(const struct bpf_object *obj,
162 const char *title);
163LIBBPF_API struct bpf_program *
164bpf_object__find_program_by_name(const struct bpf_object *obj,
165 const char *name);
166
167LIBBPF_API struct bpf_object *bpf_object__next(struct bpf_object *prev);
168#define bpf_object__for_each_safe(pos, tmp) \
169 for ((pos) = bpf_object__next(NULL), \
170 (tmp) = bpf_object__next(pos); \
171 (pos) != NULL; \
172 (pos) = (tmp), (tmp) = bpf_object__next(tmp))
173
174typedef void (*bpf_object_clear_priv_t)(struct bpf_object *, void *);
175LIBBPF_API int bpf_object__set_priv(struct bpf_object *obj, void *priv,
176 bpf_object_clear_priv_t clear_priv);
177LIBBPF_API void *bpf_object__priv(const struct bpf_object *prog);
178
179LIBBPF_API int
180libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type,
181 enum bpf_attach_type *expected_attach_type);
182LIBBPF_API int libbpf_attach_type_by_name(const char *name,
183 enum bpf_attach_type *attach_type);
184LIBBPF_API int libbpf_find_vmlinux_btf_id(const char *name,
185 enum bpf_attach_type attach_type);
186
187
188struct bpf_program;
189LIBBPF_API struct bpf_program *bpf_program__next(struct bpf_program *prog,
190 const struct bpf_object *obj);
191
192#define bpf_object__for_each_program(pos, obj) \
193 for ((pos) = bpf_program__next(NULL, (obj)); \
194 (pos) != NULL; \
195 (pos) = bpf_program__next((pos), (obj)))
196
197LIBBPF_API struct bpf_program *bpf_program__prev(struct bpf_program *prog,
198 const struct bpf_object *obj);
199
200typedef void (*bpf_program_clear_priv_t)(struct bpf_program *, void *);
201
202LIBBPF_API int bpf_program__set_priv(struct bpf_program *prog, void *priv,
203 bpf_program_clear_priv_t clear_priv);
204
205LIBBPF_API void *bpf_program__priv(const struct bpf_program *prog);
206LIBBPF_API void bpf_program__set_ifindex(struct bpf_program *prog,
207 __u32 ifindex);
208
209LIBBPF_API const char *bpf_program__name(const struct bpf_program *prog);
210LIBBPF_API const char *bpf_program__section_name(const struct bpf_program *prog);
211LIBBPF_API LIBBPF_DEPRECATED("BPF program title is confusing term; please use bpf_program__section_name() instead")
212const char *bpf_program__title(const struct bpf_program *prog, bool needs_copy);
213LIBBPF_API bool bpf_program__autoload(const struct bpf_program *prog);
214LIBBPF_API int bpf_program__set_autoload(struct bpf_program *prog, bool autoload);
215
216
217LIBBPF_API size_t bpf_program__size(const struct bpf_program *prog);
218
219LIBBPF_API int bpf_program__load(struct bpf_program *prog, char *license,
220 __u32 kern_version);
221LIBBPF_API int bpf_program__fd(const struct bpf_program *prog);
222LIBBPF_API int bpf_program__pin_instance(struct bpf_program *prog,
223 const char *path,
224 int instance);
225LIBBPF_API int bpf_program__unpin_instance(struct bpf_program *prog,
226 const char *path,
227 int instance);
228LIBBPF_API int bpf_program__pin(struct bpf_program *prog, const char *path);
229LIBBPF_API int bpf_program__unpin(struct bpf_program *prog, const char *path);
230LIBBPF_API void bpf_program__unload(struct bpf_program *prog);
231
232struct bpf_link;
233
234LIBBPF_API struct bpf_link *bpf_link__open(const char *path);
235LIBBPF_API int bpf_link__fd(const struct bpf_link *link);
236LIBBPF_API const char *bpf_link__pin_path(const struct bpf_link *link);
237LIBBPF_API int bpf_link__pin(struct bpf_link *link, const char *path);
238LIBBPF_API int bpf_link__unpin(struct bpf_link *link);
239LIBBPF_API int bpf_link__update_program(struct bpf_link *link,
240 struct bpf_program *prog);
241LIBBPF_API void bpf_link__disconnect(struct bpf_link *link);
242LIBBPF_API int bpf_link__detach(struct bpf_link *link);
243LIBBPF_API int bpf_link__destroy(struct bpf_link *link);
244
245LIBBPF_API struct bpf_link *
246bpf_program__attach(struct bpf_program *prog);
247
248struct bpf_perf_event_opts {
249
250 size_t sz;
251
252 __u64 bpf_cookie;
253};
254#define bpf_perf_event_opts__last_field bpf_cookie
255
256LIBBPF_API struct bpf_link *
257bpf_program__attach_perf_event(struct bpf_program *prog, int pfd);
258
259LIBBPF_API struct bpf_link *
260bpf_program__attach_perf_event_opts(struct bpf_program *prog, int pfd,
261 const struct bpf_perf_event_opts *opts);
262
263struct bpf_kprobe_opts {
264
265 size_t sz;
266
267 __u64 bpf_cookie;
268
269 unsigned long offset;
270
271 bool retprobe;
272 size_t :0;
273};
274#define bpf_kprobe_opts__last_field retprobe
275
276LIBBPF_API struct bpf_link *
277bpf_program__attach_kprobe(struct bpf_program *prog, bool retprobe,
278 const char *func_name);
279LIBBPF_API struct bpf_link *
280bpf_program__attach_kprobe_opts(struct bpf_program *prog,
281 const char *func_name,
282 const struct bpf_kprobe_opts *opts);
283
284struct bpf_uprobe_opts {
285
286 size_t sz;
287
288
289
290 size_t ref_ctr_offset;
291
292 __u64 bpf_cookie;
293
294 bool retprobe;
295 size_t :0;
296};
297#define bpf_uprobe_opts__last_field retprobe
298
299LIBBPF_API struct bpf_link *
300bpf_program__attach_uprobe(struct bpf_program *prog, bool retprobe,
301 pid_t pid, const char *binary_path,
302 size_t func_offset);
303LIBBPF_API struct bpf_link *
304bpf_program__attach_uprobe_opts(struct bpf_program *prog, pid_t pid,
305 const char *binary_path, size_t func_offset,
306 const struct bpf_uprobe_opts *opts);
307
308struct bpf_tracepoint_opts {
309
310 size_t sz;
311
312 __u64 bpf_cookie;
313};
314#define bpf_tracepoint_opts__last_field bpf_cookie
315
316LIBBPF_API struct bpf_link *
317bpf_program__attach_tracepoint(struct bpf_program *prog,
318 const char *tp_category,
319 const char *tp_name);
320LIBBPF_API struct bpf_link *
321bpf_program__attach_tracepoint_opts(struct bpf_program *prog,
322 const char *tp_category,
323 const char *tp_name,
324 const struct bpf_tracepoint_opts *opts);
325
326LIBBPF_API struct bpf_link *
327bpf_program__attach_raw_tracepoint(struct bpf_program *prog,
328 const char *tp_name);
329LIBBPF_API struct bpf_link *
330bpf_program__attach_trace(struct bpf_program *prog);
331LIBBPF_API struct bpf_link *
332bpf_program__attach_lsm(struct bpf_program *prog);
333LIBBPF_API struct bpf_link *
334bpf_program__attach_cgroup(struct bpf_program *prog, int cgroup_fd);
335LIBBPF_API struct bpf_link *
336bpf_program__attach_netns(struct bpf_program *prog, int netns_fd);
337LIBBPF_API struct bpf_link *
338bpf_program__attach_xdp(struct bpf_program *prog, int ifindex);
339LIBBPF_API struct bpf_link *
340bpf_program__attach_freplace(struct bpf_program *prog,
341 int target_fd, const char *attach_func_name);
342
343struct bpf_map;
344
345LIBBPF_API struct bpf_link *bpf_map__attach_struct_ops(struct bpf_map *map);
346
347struct bpf_iter_attach_opts {
348 size_t sz;
349 union bpf_iter_link_info *link_info;
350 __u32 link_info_len;
351};
352#define bpf_iter_attach_opts__last_field link_info_len
353
354LIBBPF_API struct bpf_link *
355bpf_program__attach_iter(struct bpf_program *prog,
356 const struct bpf_iter_attach_opts *opts);
357
358struct bpf_insn;
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389struct bpf_prog_prep_result {
390
391
392
393
394 struct bpf_insn *new_insn_ptr;
395 int new_insn_cnt;
396
397
398 int *pfd;
399};
400
401
402
403
404
405
406
407
408
409
410
411
412
413typedef int (*bpf_program_prep_t)(struct bpf_program *prog, int n,
414 struct bpf_insn *insns, int insns_cnt,
415 struct bpf_prog_prep_result *res);
416
417LIBBPF_API int bpf_program__set_prep(struct bpf_program *prog, int nr_instance,
418 bpf_program_prep_t prep);
419
420LIBBPF_API int bpf_program__nth_fd(const struct bpf_program *prog, int n);
421
422
423
424
425LIBBPF_API int bpf_program__set_socket_filter(struct bpf_program *prog);
426LIBBPF_API int bpf_program__set_tracepoint(struct bpf_program *prog);
427LIBBPF_API int bpf_program__set_raw_tracepoint(struct bpf_program *prog);
428LIBBPF_API int bpf_program__set_kprobe(struct bpf_program *prog);
429LIBBPF_API int bpf_program__set_lsm(struct bpf_program *prog);
430LIBBPF_API int bpf_program__set_sched_cls(struct bpf_program *prog);
431LIBBPF_API int bpf_program__set_sched_act(struct bpf_program *prog);
432LIBBPF_API int bpf_program__set_xdp(struct bpf_program *prog);
433LIBBPF_API int bpf_program__set_perf_event(struct bpf_program *prog);
434LIBBPF_API int bpf_program__set_tracing(struct bpf_program *prog);
435LIBBPF_API int bpf_program__set_struct_ops(struct bpf_program *prog);
436LIBBPF_API int bpf_program__set_extension(struct bpf_program *prog);
437LIBBPF_API int bpf_program__set_sk_lookup(struct bpf_program *prog);
438
439LIBBPF_API enum bpf_prog_type bpf_program__get_type(const struct bpf_program *prog);
440LIBBPF_API void bpf_program__set_type(struct bpf_program *prog,
441 enum bpf_prog_type type);
442
443LIBBPF_API enum bpf_attach_type
444bpf_program__get_expected_attach_type(const struct bpf_program *prog);
445LIBBPF_API void
446bpf_program__set_expected_attach_type(struct bpf_program *prog,
447 enum bpf_attach_type type);
448
449LIBBPF_API int
450bpf_program__set_attach_target(struct bpf_program *prog, int attach_prog_fd,
451 const char *attach_func_name);
452
453LIBBPF_API bool bpf_program__is_socket_filter(const struct bpf_program *prog);
454LIBBPF_API bool bpf_program__is_tracepoint(const struct bpf_program *prog);
455LIBBPF_API bool bpf_program__is_raw_tracepoint(const struct bpf_program *prog);
456LIBBPF_API bool bpf_program__is_kprobe(const struct bpf_program *prog);
457LIBBPF_API bool bpf_program__is_lsm(const struct bpf_program *prog);
458LIBBPF_API bool bpf_program__is_sched_cls(const struct bpf_program *prog);
459LIBBPF_API bool bpf_program__is_sched_act(const struct bpf_program *prog);
460LIBBPF_API bool bpf_program__is_xdp(const struct bpf_program *prog);
461LIBBPF_API bool bpf_program__is_perf_event(const struct bpf_program *prog);
462LIBBPF_API bool bpf_program__is_tracing(const struct bpf_program *prog);
463LIBBPF_API bool bpf_program__is_struct_ops(const struct bpf_program *prog);
464LIBBPF_API bool bpf_program__is_extension(const struct bpf_program *prog);
465LIBBPF_API bool bpf_program__is_sk_lookup(const struct bpf_program *prog);
466
467
468
469
470
471
472
473struct bpf_map_def {
474 unsigned int type;
475 unsigned int key_size;
476 unsigned int value_size;
477 unsigned int max_entries;
478 unsigned int map_flags;
479};
480
481
482
483
484
485LIBBPF_API struct bpf_map *
486bpf_object__find_map_by_name(const struct bpf_object *obj, const char *name);
487
488LIBBPF_API int
489bpf_object__find_map_fd_by_name(const struct bpf_object *obj, const char *name);
490
491
492
493
494
495LIBBPF_API struct bpf_map *
496bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset);
497
498LIBBPF_API struct bpf_map *
499bpf_map__next(const struct bpf_map *map, const struct bpf_object *obj);
500#define bpf_object__for_each_map(pos, obj) \
501 for ((pos) = bpf_map__next(NULL, (obj)); \
502 (pos) != NULL; \
503 (pos) = bpf_map__next((pos), (obj)))
504#define bpf_map__for_each bpf_object__for_each_map
505
506LIBBPF_API struct bpf_map *
507bpf_map__prev(const struct bpf_map *map, const struct bpf_object *obj);
508
509
510LIBBPF_API int bpf_map__fd(const struct bpf_map *map);
511LIBBPF_API int bpf_map__reuse_fd(struct bpf_map *map, int fd);
512
513LIBBPF_API const struct bpf_map_def *bpf_map__def(const struct bpf_map *map);
514
515LIBBPF_API const char *bpf_map__name(const struct bpf_map *map);
516
517LIBBPF_API enum bpf_map_type bpf_map__type(const struct bpf_map *map);
518LIBBPF_API int bpf_map__set_type(struct bpf_map *map, enum bpf_map_type type);
519
520LIBBPF_API __u32 bpf_map__max_entries(const struct bpf_map *map);
521LIBBPF_API int bpf_map__set_max_entries(struct bpf_map *map, __u32 max_entries);
522LIBBPF_API int bpf_map__resize(struct bpf_map *map, __u32 max_entries);
523
524LIBBPF_API __u32 bpf_map__map_flags(const struct bpf_map *map);
525LIBBPF_API int bpf_map__set_map_flags(struct bpf_map *map, __u32 flags);
526
527LIBBPF_API __u32 bpf_map__numa_node(const struct bpf_map *map);
528LIBBPF_API int bpf_map__set_numa_node(struct bpf_map *map, __u32 numa_node);
529
530LIBBPF_API __u32 bpf_map__key_size(const struct bpf_map *map);
531LIBBPF_API int bpf_map__set_key_size(struct bpf_map *map, __u32 size);
532
533LIBBPF_API __u32 bpf_map__value_size(const struct bpf_map *map);
534LIBBPF_API int bpf_map__set_value_size(struct bpf_map *map, __u32 size);
535
536LIBBPF_API __u32 bpf_map__btf_key_type_id(const struct bpf_map *map);
537LIBBPF_API __u32 bpf_map__btf_value_type_id(const struct bpf_map *map);
538
539LIBBPF_API __u32 bpf_map__ifindex(const struct bpf_map *map);
540LIBBPF_API int bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex);
541
542typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *);
543LIBBPF_API int bpf_map__set_priv(struct bpf_map *map, void *priv,
544 bpf_map_clear_priv_t clear_priv);
545LIBBPF_API void *bpf_map__priv(const struct bpf_map *map);
546LIBBPF_API int bpf_map__set_initial_value(struct bpf_map *map,
547 const void *data, size_t size);
548LIBBPF_API const void *bpf_map__initial_value(struct bpf_map *map, size_t *psize);
549LIBBPF_API bool bpf_map__is_offload_neutral(const struct bpf_map *map);
550LIBBPF_API bool bpf_map__is_internal(const struct bpf_map *map);
551LIBBPF_API int bpf_map__set_pin_path(struct bpf_map *map, const char *path);
552LIBBPF_API const char *bpf_map__get_pin_path(const struct bpf_map *map);
553LIBBPF_API const char *bpf_map__pin_path(const struct bpf_map *map);
554LIBBPF_API bool bpf_map__is_pinned(const struct bpf_map *map);
555LIBBPF_API int bpf_map__pin(struct bpf_map *map, const char *path);
556LIBBPF_API int bpf_map__unpin(struct bpf_map *map, const char *path);
557
558LIBBPF_API int bpf_map__set_inner_map_fd(struct bpf_map *map, int fd);
559LIBBPF_API struct bpf_map *bpf_map__inner_map(struct bpf_map *map);
560
561LIBBPF_API long libbpf_get_error(const void *ptr);
562
563struct bpf_prog_load_attr {
564 const char *file;
565 enum bpf_prog_type prog_type;
566 enum bpf_attach_type expected_attach_type;
567 int ifindex;
568 int log_level;
569 int prog_flags;
570};
571
572LIBBPF_API int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr,
573 struct bpf_object **pobj, int *prog_fd);
574LIBBPF_API int bpf_prog_load(const char *file, enum bpf_prog_type type,
575 struct bpf_object **pobj, int *prog_fd);
576
577
578struct xdp_link_info {
579 __u32 prog_id;
580 __u32 drv_prog_id;
581 __u32 hw_prog_id;
582 __u32 skb_prog_id;
583 __u8 attach_mode;
584};
585
586struct bpf_xdp_set_link_opts {
587 size_t sz;
588 int old_fd;
589 size_t :0;
590};
591#define bpf_xdp_set_link_opts__last_field old_fd
592
593LIBBPF_API int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags);
594LIBBPF_API int bpf_set_link_xdp_fd_opts(int ifindex, int fd, __u32 flags,
595 const struct bpf_xdp_set_link_opts *opts);
596LIBBPF_API int bpf_get_link_xdp_id(int ifindex, __u32 *prog_id, __u32 flags);
597LIBBPF_API int bpf_get_link_xdp_info(int ifindex, struct xdp_link_info *info,
598 size_t info_size, __u32 flags);
599
600
601enum bpf_tc_attach_point {
602 BPF_TC_INGRESS = 1 << 0,
603 BPF_TC_EGRESS = 1 << 1,
604 BPF_TC_CUSTOM = 1 << 2,
605};
606
607#define BPF_TC_PARENT(a, b) \
608 ((((a) << 16) & 0xFFFF0000U) | ((b) & 0x0000FFFFU))
609
610enum bpf_tc_flags {
611 BPF_TC_F_REPLACE = 1 << 0,
612};
613
614struct bpf_tc_hook {
615 size_t sz;
616 int ifindex;
617 enum bpf_tc_attach_point attach_point;
618 __u32 parent;
619 size_t :0;
620};
621#define bpf_tc_hook__last_field parent
622
623struct bpf_tc_opts {
624 size_t sz;
625 int prog_fd;
626 __u32 flags;
627 __u32 prog_id;
628 __u32 handle;
629 __u32 priority;
630 size_t :0;
631};
632#define bpf_tc_opts__last_field priority
633
634LIBBPF_API int bpf_tc_hook_create(struct bpf_tc_hook *hook);
635LIBBPF_API int bpf_tc_hook_destroy(struct bpf_tc_hook *hook);
636LIBBPF_API int bpf_tc_attach(const struct bpf_tc_hook *hook,
637 struct bpf_tc_opts *opts);
638LIBBPF_API int bpf_tc_detach(const struct bpf_tc_hook *hook,
639 const struct bpf_tc_opts *opts);
640LIBBPF_API int bpf_tc_query(const struct bpf_tc_hook *hook,
641 struct bpf_tc_opts *opts);
642
643
644struct ring_buffer;
645
646typedef int (*ring_buffer_sample_fn)(void *ctx, void *data, size_t size);
647
648struct ring_buffer_opts {
649 size_t sz;
650};
651
652#define ring_buffer_opts__last_field sz
653
654LIBBPF_API struct ring_buffer *
655ring_buffer__new(int map_fd, ring_buffer_sample_fn sample_cb, void *ctx,
656 const struct ring_buffer_opts *opts);
657LIBBPF_API void ring_buffer__free(struct ring_buffer *rb);
658LIBBPF_API int ring_buffer__add(struct ring_buffer *rb, int map_fd,
659 ring_buffer_sample_fn sample_cb, void *ctx);
660LIBBPF_API int ring_buffer__poll(struct ring_buffer *rb, int timeout_ms);
661LIBBPF_API int ring_buffer__consume(struct ring_buffer *rb);
662LIBBPF_API int ring_buffer__epoll_fd(const struct ring_buffer *rb);
663
664
665struct perf_buffer;
666
667typedef void (*perf_buffer_sample_fn)(void *ctx, int cpu,
668 void *data, __u32 size);
669typedef void (*perf_buffer_lost_fn)(void *ctx, int cpu, __u64 cnt);
670
671
672struct perf_buffer_opts {
673
674 perf_buffer_sample_fn sample_cb;
675
676 perf_buffer_lost_fn lost_cb;
677
678 void *ctx;
679};
680
681LIBBPF_API struct perf_buffer *
682perf_buffer__new(int map_fd, size_t page_cnt,
683 const struct perf_buffer_opts *opts);
684
685enum bpf_perf_event_ret {
686 LIBBPF_PERF_EVENT_DONE = 0,
687 LIBBPF_PERF_EVENT_ERROR = -1,
688 LIBBPF_PERF_EVENT_CONT = -2,
689};
690
691struct perf_event_header;
692
693typedef enum bpf_perf_event_ret
694(*perf_buffer_event_fn)(void *ctx, int cpu, struct perf_event_header *event);
695
696
697struct perf_buffer_raw_opts {
698
699 struct perf_event_attr *attr;
700
701 perf_buffer_event_fn event_cb;
702
703 void *ctx;
704
705
706
707 int cpu_cnt;
708
709 int *cpus;
710
711 int *map_keys;
712};
713
714LIBBPF_API struct perf_buffer *
715perf_buffer__new_raw(int map_fd, size_t page_cnt,
716 const struct perf_buffer_raw_opts *opts);
717
718LIBBPF_API void perf_buffer__free(struct perf_buffer *pb);
719LIBBPF_API int perf_buffer__epoll_fd(const struct perf_buffer *pb);
720LIBBPF_API int perf_buffer__poll(struct perf_buffer *pb, int timeout_ms);
721LIBBPF_API int perf_buffer__consume(struct perf_buffer *pb);
722LIBBPF_API int perf_buffer__consume_buffer(struct perf_buffer *pb, size_t buf_idx);
723LIBBPF_API size_t perf_buffer__buffer_cnt(const struct perf_buffer *pb);
724LIBBPF_API int perf_buffer__buffer_fd(const struct perf_buffer *pb, size_t buf_idx);
725
726typedef enum bpf_perf_event_ret
727 (*bpf_perf_event_print_t)(struct perf_event_header *hdr,
728 void *private_data);
729LIBBPF_API enum bpf_perf_event_ret
730bpf_perf_event_read_simple(void *mmap_mem, size_t mmap_size, size_t page_size,
731 void **copy_mem, size_t *copy_size,
732 bpf_perf_event_print_t fn, void *private_data);
733
734struct bpf_prog_linfo;
735struct bpf_prog_info;
736
737LIBBPF_API void bpf_prog_linfo__free(struct bpf_prog_linfo *prog_linfo);
738LIBBPF_API struct bpf_prog_linfo *
739bpf_prog_linfo__new(const struct bpf_prog_info *info);
740LIBBPF_API const struct bpf_line_info *
741bpf_prog_linfo__lfind_addr_func(const struct bpf_prog_linfo *prog_linfo,
742 __u64 addr, __u32 func_idx, __u32 nr_skip);
743LIBBPF_API const struct bpf_line_info *
744bpf_prog_linfo__lfind(const struct bpf_prog_linfo *prog_linfo,
745 __u32 insn_off, __u32 nr_skip);
746
747
748
749
750
751
752
753
754
755LIBBPF_API bool bpf_probe_prog_type(enum bpf_prog_type prog_type,
756 __u32 ifindex);
757LIBBPF_API bool bpf_probe_map_type(enum bpf_map_type map_type, __u32 ifindex);
758LIBBPF_API bool bpf_probe_helper(enum bpf_func_id id,
759 enum bpf_prog_type prog_type, __u32 ifindex);
760LIBBPF_API bool bpf_probe_large_insn_limit(__u32 ifindex);
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791enum bpf_prog_info_array {
792 BPF_PROG_INFO_FIRST_ARRAY = 0,
793 BPF_PROG_INFO_JITED_INSNS = 0,
794 BPF_PROG_INFO_XLATED_INSNS,
795 BPF_PROG_INFO_MAP_IDS,
796 BPF_PROG_INFO_JITED_KSYMS,
797 BPF_PROG_INFO_JITED_FUNC_LENS,
798 BPF_PROG_INFO_FUNC_INFO,
799 BPF_PROG_INFO_LINE_INFO,
800 BPF_PROG_INFO_JITED_LINE_INFO,
801 BPF_PROG_INFO_PROG_TAGS,
802 BPF_PROG_INFO_LAST_ARRAY,
803};
804
805struct bpf_prog_info_linear {
806
807 __u32 info_len;
808
809 __u32 data_len;
810
811 __u64 arrays;
812 struct bpf_prog_info info;
813 __u8 data[];
814};
815
816LIBBPF_API struct bpf_prog_info_linear *
817bpf_program__get_prog_info_linear(int fd, __u64 arrays);
818
819LIBBPF_API void
820bpf_program__bpil_addr_to_offs(struct bpf_prog_info_linear *info_linear);
821
822LIBBPF_API void
823bpf_program__bpil_offs_to_addr(struct bpf_prog_info_linear *info_linear);
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839LIBBPF_API int libbpf_num_possible_cpus(void);
840
841struct bpf_map_skeleton {
842 const char *name;
843 struct bpf_map **map;
844 void **mmaped;
845};
846
847struct bpf_prog_skeleton {
848 const char *name;
849 struct bpf_program **prog;
850 struct bpf_link **link;
851};
852
853struct bpf_object_skeleton {
854 size_t sz;
855
856 const char *name;
857 void *data;
858 size_t data_sz;
859
860 struct bpf_object **obj;
861
862 int map_cnt;
863 int map_skel_sz;
864 struct bpf_map_skeleton *maps;
865
866 int prog_cnt;
867 int prog_skel_sz;
868 struct bpf_prog_skeleton *progs;
869};
870
871LIBBPF_API int
872bpf_object__open_skeleton(struct bpf_object_skeleton *s,
873 const struct bpf_object_open_opts *opts);
874LIBBPF_API int bpf_object__load_skeleton(struct bpf_object_skeleton *s);
875LIBBPF_API int bpf_object__attach_skeleton(struct bpf_object_skeleton *s);
876LIBBPF_API void bpf_object__detach_skeleton(struct bpf_object_skeleton *s);
877LIBBPF_API void bpf_object__destroy_skeleton(struct bpf_object_skeleton *s);
878
879struct gen_loader_opts {
880 size_t sz;
881 const char *data;
882 const char *insns;
883 __u32 data_sz;
884 __u32 insns_sz;
885};
886
887#define gen_loader_opts__last_field insns_sz
888LIBBPF_API int bpf_object__gen_loader(struct bpf_object *obj,
889 struct gen_loader_opts *opts);
890
891enum libbpf_tristate {
892 TRI_NO = 0,
893 TRI_YES = 1,
894 TRI_MODULE = 2,
895};
896
897struct bpf_linker_opts {
898
899 size_t sz;
900};
901#define bpf_linker_opts__last_field sz
902
903struct bpf_linker_file_opts {
904
905 size_t sz;
906};
907#define bpf_linker_file_opts__last_field sz
908
909struct bpf_linker;
910
911LIBBPF_API struct bpf_linker *bpf_linker__new(const char *filename, struct bpf_linker_opts *opts);
912LIBBPF_API int bpf_linker__add_file(struct bpf_linker *linker,
913 const char *filename,
914 const struct bpf_linker_file_opts *opts);
915LIBBPF_API int bpf_linker__finalize(struct bpf_linker *linker);
916LIBBPF_API void bpf_linker__free(struct bpf_linker *linker);
917
918#ifdef __cplusplus
919}
920#endif
921
922#endif
923