1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#ifndef __BPF_LIBBPF_H
22#define __BPF_LIBBPF_H
23
24#include <stdio.h>
25#include <stdbool.h>
26#include <linux/err.h>
27
28enum libbpf_errno {
29 __LIBBPF_ERRNO__START = 4000,
30
31
32 LIBBPF_ERRNO__LIBELF = __LIBBPF_ERRNO__START,
33 LIBBPF_ERRNO__FORMAT,
34 LIBBPF_ERRNO__KVERSION,
35 LIBBPF_ERRNO__ENDIAN,
36 LIBBPF_ERRNO__INTERNAL,
37 LIBBPF_ERRNO__RELOC,
38 LIBBPF_ERRNO__LOAD,
39 LIBBPF_ERRNO__VERIFY,
40 LIBBPF_ERRNO__PROG2BIG,
41 LIBBPF_ERRNO__KVER,
42 LIBBPF_ERRNO__PROGTYPE,
43 __LIBBPF_ERRNO__END,
44};
45
46int libbpf_strerror(int err, char *buf, size_t size);
47
48
49
50
51
52
53typedef int (*libbpf_print_fn_t)(const char *, ...)
54 __attribute__((format(printf, 1, 2)));
55
56void libbpf_set_print(libbpf_print_fn_t warn,
57 libbpf_print_fn_t info,
58 libbpf_print_fn_t debug);
59
60
61struct bpf_object;
62
63struct bpf_object *bpf_object__open(const char *path);
64struct bpf_object *bpf_object__open_buffer(void *obj_buf,
65 size_t obj_buf_sz,
66 const char *name);
67void bpf_object__close(struct bpf_object *object);
68
69
70int bpf_object__load(struct bpf_object *obj);
71int bpf_object__unload(struct bpf_object *obj);
72const char *bpf_object__name(struct bpf_object *obj);
73unsigned int bpf_object__kversion(struct bpf_object *obj);
74
75struct bpf_object *bpf_object__next(struct bpf_object *prev);
76#define bpf_object__for_each_safe(pos, tmp) \
77 for ((pos) = bpf_object__next(NULL), \
78 (tmp) = bpf_object__next(pos); \
79 (pos) != NULL; \
80 (pos) = (tmp), (tmp) = bpf_object__next(tmp))
81
82
83struct bpf_program;
84struct bpf_program *bpf_program__next(struct bpf_program *prog,
85 struct bpf_object *obj);
86
87#define bpf_object__for_each_program(pos, obj) \
88 for ((pos) = bpf_program__next(NULL, (obj)); \
89 (pos) != NULL; \
90 (pos) = bpf_program__next((pos), (obj)))
91
92typedef void (*bpf_program_clear_priv_t)(struct bpf_program *,
93 void *);
94
95int bpf_program__set_priv(struct bpf_program *prog, void *priv,
96 bpf_program_clear_priv_t clear_priv);
97
98void *bpf_program__priv(struct bpf_program *prog);
99
100const char *bpf_program__title(struct bpf_program *prog, bool needs_copy);
101
102int bpf_program__fd(struct bpf_program *prog);
103
104struct bpf_insn;
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135struct bpf_prog_prep_result {
136
137
138
139
140 struct bpf_insn *new_insn_ptr;
141 int new_insn_cnt;
142
143
144 int *pfd;
145};
146
147
148
149
150
151
152
153
154
155
156
157
158
159typedef int (*bpf_program_prep_t)(struct bpf_program *prog, int n,
160 struct bpf_insn *insns, int insns_cnt,
161 struct bpf_prog_prep_result *res);
162
163int bpf_program__set_prep(struct bpf_program *prog, int nr_instance,
164 bpf_program_prep_t prep);
165
166int bpf_program__nth_fd(struct bpf_program *prog, int n);
167
168
169
170
171int bpf_program__set_tracepoint(struct bpf_program *prog);
172int bpf_program__set_kprobe(struct bpf_program *prog);
173
174bool bpf_program__is_tracepoint(struct bpf_program *prog);
175bool bpf_program__is_kprobe(struct bpf_program *prog);
176
177
178
179
180
181
182
183struct bpf_map_def {
184 unsigned int type;
185 unsigned int key_size;
186 unsigned int value_size;
187 unsigned int max_entries;
188};
189
190
191
192
193
194struct bpf_map;
195struct bpf_map *
196bpf_object__find_map_by_name(struct bpf_object *obj, const char *name);
197
198struct bpf_map *
199bpf_map__next(struct bpf_map *map, struct bpf_object *obj);
200#define bpf_map__for_each(pos, obj) \
201 for ((pos) = bpf_map__next(NULL, (obj)); \
202 (pos) != NULL; \
203 (pos) = bpf_map__next((pos), (obj)))
204
205int bpf_map__fd(struct bpf_map *map);
206const struct bpf_map_def *bpf_map__def(struct bpf_map *map);
207const char *bpf_map__name(struct bpf_map *map);
208
209typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *);
210int bpf_map__set_priv(struct bpf_map *map, void *priv,
211 bpf_map_clear_priv_t clear_priv);
212void *bpf_map__priv(struct bpf_map *map);
213
214#endif
215