aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf
diff options
context:
space:
mode:
authorAndrey Ignatov <rdna@fb.com>2018-10-16 01:50:34 -0400
committerAlexei Starovoitov <ast@kernel.org>2018-10-16 18:16:47 -0400
commitab9e084821221b2eda57a512535fe35b49e672d8 (patch)
tree024031e7d7cfd5b695d11c5e3617275b5e068e51 /tools/lib/bpf
parent421f4292f46e871cdcf8bdc3e6fdfcefe2e81a9d (diff)
libbpf: Per-symbol visibility for DSO
Make global symbols in libbpf DSO hidden by default with -fvisibility=hidden and export symbols that are part of ABI explicitly with __attribute__((visibility("default"))). This is common practice that should prevent from accidentally exporting a symbol, that is not supposed to be a part of ABI what, in turn, improves both libbpf developer- and user-experiences. See [1] for more details. Export control becomes more important since more and more projects use libbpf. The patch doesn't export a bunch of netlink related functions since as agreed in [2] they'll be reworked. That doesn't break bpftool since bpftool links libbpf statically. [1] https://www.akkadia.org/drepper/dsohowto.pdf (2.2 Export Control) [2] https://www.mail-archive.com/netdev@vger.kernel.org/msg251434.html Signed-off-by: Andrey Ignatov <rdna@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/lib/bpf')
-rw-r--r--tools/lib/bpf/Makefile1
-rw-r--r--tools/lib/bpf/bpf.h118
-rw-r--r--tools/lib/bpf/btf.h22
-rw-r--r--tools/lib/bpf/libbpf.h186
4 files changed, 179 insertions, 148 deletions
diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index 79d84413ddf2..425b480bda75 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -125,6 +125,7 @@ override CFLAGS += $(EXTRA_WARNINGS)
125override CFLAGS += -Werror -Wall 125override CFLAGS += -Werror -Wall
126override CFLAGS += -fPIC 126override CFLAGS += -fPIC
127override CFLAGS += $(INCLUDES) 127override CFLAGS += $(INCLUDES)
128override CFLAGS += -fvisibility=hidden
128 129
129ifeq ($(VERBOSE),1) 130ifeq ($(VERBOSE),1)
130 Q = 131 Q =
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index 69a4d40c4227..258c3c178333 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -27,6 +27,10 @@
27#include <stdbool.h> 27#include <stdbool.h>
28#include <stddef.h> 28#include <stddef.h>
29 29
30#ifndef LIBBPF_API
31#define LIBBPF_API __attribute__((visibility("default")))
32#endif
33
30struct bpf_create_map_attr { 34struct bpf_create_map_attr {
31 const char *name; 35 const char *name;
32 enum bpf_map_type map_type; 36 enum bpf_map_type map_type;
@@ -42,21 +46,24 @@ struct bpf_create_map_attr {
42 __u32 inner_map_fd; 46 __u32 inner_map_fd;
43}; 47};
44 48
45int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr); 49LIBBPF_API int
46int bpf_create_map_node(enum bpf_map_type map_type, const char *name, 50bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr);
47 int key_size, int value_size, int max_entries, 51LIBBPF_API int bpf_create_map_node(enum bpf_map_type map_type, const char *name,
48 __u32 map_flags, int node); 52 int key_size, int value_size,
49int bpf_create_map_name(enum bpf_map_type map_type, const char *name, 53 int max_entries, __u32 map_flags, int node);
50 int key_size, int value_size, int max_entries, 54LIBBPF_API int bpf_create_map_name(enum bpf_map_type map_type, const char *name,
51 __u32 map_flags); 55 int key_size, int value_size,
52int bpf_create_map(enum bpf_map_type map_type, int key_size, int value_size, 56 int max_entries, __u32 map_flags);
53 int max_entries, __u32 map_flags); 57LIBBPF_API int bpf_create_map(enum bpf_map_type map_type, int key_size,
54int bpf_create_map_in_map_node(enum bpf_map_type map_type, const char *name, 58 int value_size, int max_entries, __u32 map_flags);
55 int key_size, int inner_map_fd, int max_entries, 59LIBBPF_API int bpf_create_map_in_map_node(enum bpf_map_type map_type,
56 __u32 map_flags, int node); 60 const char *name, int key_size,
57int bpf_create_map_in_map(enum bpf_map_type map_type, const char *name, 61 int inner_map_fd, int max_entries,
58 int key_size, int inner_map_fd, int max_entries, 62 __u32 map_flags, int node);
59 __u32 map_flags); 63LIBBPF_API int bpf_create_map_in_map(enum bpf_map_type map_type,
64 const char *name, int key_size,
65 int inner_map_fd, int max_entries,
66 __u32 map_flags);
60 67
61struct bpf_load_program_attr { 68struct bpf_load_program_attr {
62 enum bpf_prog_type prog_type; 69 enum bpf_prog_type prog_type;
@@ -74,44 +81,49 @@ struct bpf_load_program_attr {
74 81
75/* Recommend log buffer size */ 82/* Recommend log buffer size */
76#define BPF_LOG_BUF_SIZE (256 * 1024) 83#define BPF_LOG_BUF_SIZE (256 * 1024)
77int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr, 84LIBBPF_API int
78 char *log_buf, size_t log_buf_sz); 85bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr,
79int bpf_load_program(enum bpf_prog_type type, const struct bpf_insn *insns, 86 char *log_buf, size_t log_buf_sz);
80 size_t insns_cnt, const char *license, 87LIBBPF_API int bpf_load_program(enum bpf_prog_type type,
81 __u32 kern_version, char *log_buf, 88 const struct bpf_insn *insns, size_t insns_cnt,
82 size_t log_buf_sz); 89 const char *license, __u32 kern_version,
83int bpf_verify_program(enum bpf_prog_type type, const struct bpf_insn *insns, 90 char *log_buf, size_t log_buf_sz);
84 size_t insns_cnt, int strict_alignment, 91LIBBPF_API int bpf_verify_program(enum bpf_prog_type type,
85 const char *license, __u32 kern_version, 92 const struct bpf_insn *insns,
86 char *log_buf, size_t log_buf_sz, int log_level); 93 size_t insns_cnt, int strict_alignment,
94 const char *license, __u32 kern_version,
95 char *log_buf, size_t log_buf_sz,
96 int log_level);
87 97
88int bpf_map_update_elem(int fd, const void *key, const void *value, 98LIBBPF_API int bpf_map_update_elem(int fd, const void *key, const void *value,
89 __u64 flags); 99 __u64 flags);
90 100
91int bpf_map_lookup_elem(int fd, const void *key, void *value); 101LIBBPF_API int bpf_map_lookup_elem(int fd, const void *key, void *value);
92int bpf_map_delete_elem(int fd, const void *key); 102LIBBPF_API int bpf_map_delete_elem(int fd, const void *key);
93int bpf_map_get_next_key(int fd, const void *key, void *next_key); 103LIBBPF_API int bpf_map_get_next_key(int fd, const void *key, void *next_key);
94int bpf_obj_pin(int fd, const char *pathname); 104LIBBPF_API int bpf_obj_pin(int fd, const char *pathname);
95int bpf_obj_get(const char *pathname); 105LIBBPF_API int bpf_obj_get(const char *pathname);
96int bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type, 106LIBBPF_API int bpf_prog_attach(int prog_fd, int attachable_fd,
97 unsigned int flags); 107 enum bpf_attach_type type, unsigned int flags);
98int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type); 108LIBBPF_API int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type);
99int bpf_prog_detach2(int prog_fd, int attachable_fd, enum bpf_attach_type type); 109LIBBPF_API int bpf_prog_detach2(int prog_fd, int attachable_fd,
100int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size, 110 enum bpf_attach_type type);
101 void *data_out, __u32 *size_out, __u32 *retval, 111LIBBPF_API int bpf_prog_test_run(int prog_fd, int repeat, void *data,
102 __u32 *duration); 112 __u32 size, void *data_out, __u32 *size_out,
103int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id); 113 __u32 *retval, __u32 *duration);
104int bpf_map_get_next_id(__u32 start_id, __u32 *next_id); 114LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id);
105int bpf_prog_get_fd_by_id(__u32 id); 115LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id);
106int bpf_map_get_fd_by_id(__u32 id); 116LIBBPF_API int bpf_prog_get_fd_by_id(__u32 id);
107int bpf_btf_get_fd_by_id(__u32 id); 117LIBBPF_API int bpf_map_get_fd_by_id(__u32 id);
108int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len); 118LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id);
109int bpf_prog_query(int target_fd, enum bpf_attach_type type, __u32 query_flags, 119LIBBPF_API int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len);
110 __u32 *attach_flags, __u32 *prog_ids, __u32 *prog_cnt); 120LIBBPF_API int bpf_prog_query(int target_fd, enum bpf_attach_type type,
111int bpf_raw_tracepoint_open(const char *name, int prog_fd); 121 __u32 query_flags, __u32 *attach_flags,
112int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf, __u32 log_buf_size, 122 __u32 *prog_ids, __u32 *prog_cnt);
113 bool do_log); 123LIBBPF_API int bpf_raw_tracepoint_open(const char *name, int prog_fd);
114int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, __u32 *buf_len, 124LIBBPF_API int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf,
115 __u32 *prog_id, __u32 *fd_type, __u64 *probe_offset, 125 __u32 log_buf_size, bool do_log);
116 __u64 *probe_addr); 126LIBBPF_API int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf,
127 __u32 *buf_len, __u32 *prog_id, __u32 *fd_type,
128 __u64 *probe_offset, __u64 *probe_addr);
117#endif /* __LIBBPF_BPF_H */ 129#endif /* __LIBBPF_BPF_H */
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index 6db5462bb2ef..b77e7080f7e7 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -6,6 +6,10 @@
6 6
7#include <linux/types.h> 7#include <linux/types.h>
8 8
9#ifndef LIBBPF_API
10#define LIBBPF_API __attribute__((visibility("default")))
11#endif
12
9#define BTF_ELF_SEC ".BTF" 13#define BTF_ELF_SEC ".BTF"
10 14
11struct btf; 15struct btf;
@@ -14,13 +18,15 @@ struct btf_type;
14typedef int (*btf_print_fn_t)(const char *, ...) 18typedef int (*btf_print_fn_t)(const char *, ...)
15 __attribute__((format(printf, 1, 2))); 19 __attribute__((format(printf, 1, 2)));
16 20
17void btf__free(struct btf *btf); 21LIBBPF_API void btf__free(struct btf *btf);
18struct btf *btf__new(__u8 *data, __u32 size, btf_print_fn_t err_log); 22LIBBPF_API struct btf *btf__new(__u8 *data, __u32 size, btf_print_fn_t err_log);
19__s32 btf__find_by_name(const struct btf *btf, const char *type_name); 23LIBBPF_API __s32 btf__find_by_name(const struct btf *btf,
20const struct btf_type *btf__type_by_id(const struct btf *btf, __u32 id); 24 const char *type_name);
21__s64 btf__resolve_size(const struct btf *btf, __u32 type_id); 25LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf,
22int btf__resolve_type(const struct btf *btf, __u32 type_id); 26 __u32 id);
23int btf__fd(const struct btf *btf); 27LIBBPF_API __s64 btf__resolve_size(const struct btf *btf, __u32 type_id);
24const char *btf__name_by_offset(const struct btf *btf, __u32 offset); 28LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id);
29LIBBPF_API int btf__fd(const struct btf *btf);
30LIBBPF_API const char *btf__name_by_offset(const struct btf *btf, __u32 offset);
25 31
26#endif /* __LIBBPF_BTF_H */ 32#endif /* __LIBBPF_BTF_H */
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h
index 7e9c801a9fdd..1354cc9f8cba 100644
--- a/tools/lib/bpf/libbpf.h
+++ b/tools/lib/bpf/libbpf.h
@@ -16,6 +16,10 @@
16#include <sys/types.h> // for size_t 16#include <sys/types.h> // for size_t
17#include <linux/bpf.h> 17#include <linux/bpf.h>
18 18
19#ifndef LIBBPF_API
20#define LIBBPF_API __attribute__((visibility("default")))
21#endif
22
19enum libbpf_errno { 23enum libbpf_errno {
20 __LIBBPF_ERRNO__START = 4000, 24 __LIBBPF_ERRNO__START = 4000,
21 25
@@ -37,7 +41,7 @@ enum libbpf_errno {
37 __LIBBPF_ERRNO__END, 41 __LIBBPF_ERRNO__END,
38}; 42};
39 43
40int libbpf_strerror(int err, char *buf, size_t size); 44LIBBPF_API int libbpf_strerror(int err, char *buf, size_t size);
41 45
42/* 46/*
43 * __printf is defined in include/linux/compiler-gcc.h. However, 47 * __printf is defined in include/linux/compiler-gcc.h. However,
@@ -47,9 +51,9 @@ int libbpf_strerror(int err, char *buf, size_t size);
47typedef int (*libbpf_print_fn_t)(const char *, ...) 51typedef int (*libbpf_print_fn_t)(const char *, ...)
48 __attribute__((format(printf, 1, 2))); 52 __attribute__((format(printf, 1, 2)));
49 53
50void libbpf_set_print(libbpf_print_fn_t warn, 54LIBBPF_API void libbpf_set_print(libbpf_print_fn_t warn,
51 libbpf_print_fn_t info, 55 libbpf_print_fn_t info,
52 libbpf_print_fn_t debug); 56 libbpf_print_fn_t debug);
53 57
54/* Hide internal to user */ 58/* Hide internal to user */
55struct bpf_object; 59struct bpf_object;
@@ -59,27 +63,28 @@ struct bpf_object_open_attr {
59 enum bpf_prog_type prog_type; 63 enum bpf_prog_type prog_type;
60}; 64};
61 65
62struct bpf_object *bpf_object__open(const char *path); 66LIBBPF_API struct bpf_object *bpf_object__open(const char *path);
63struct bpf_object *bpf_object__open_xattr(struct bpf_object_open_attr *attr); 67LIBBPF_API struct bpf_object *
68bpf_object__open_xattr(struct bpf_object_open_attr *attr);
64struct bpf_object *__bpf_object__open_xattr(struct bpf_object_open_attr *attr, 69struct bpf_object *__bpf_object__open_xattr(struct bpf_object_open_attr *attr,
65 int flags); 70 int flags);
66struct bpf_object *bpf_object__open_buffer(void *obj_buf, 71LIBBPF_API struct bpf_object *bpf_object__open_buffer(void *obj_buf,
67 size_t obj_buf_sz, 72 size_t obj_buf_sz,
68 const char *name); 73 const char *name);
69int bpf_object__pin(struct bpf_object *object, const char *path); 74LIBBPF_API int bpf_object__pin(struct bpf_object *object, const char *path);
70void bpf_object__close(struct bpf_object *object); 75LIBBPF_API void bpf_object__close(struct bpf_object *object);
71 76
72/* Load/unload object into/from kernel */ 77/* Load/unload object into/from kernel */
73int bpf_object__load(struct bpf_object *obj); 78LIBBPF_API int bpf_object__load(struct bpf_object *obj);
74int bpf_object__unload(struct bpf_object *obj); 79LIBBPF_API int bpf_object__unload(struct bpf_object *obj);
75const char *bpf_object__name(struct bpf_object *obj); 80LIBBPF_API const char *bpf_object__name(struct bpf_object *obj);
76unsigned int bpf_object__kversion(struct bpf_object *obj); 81LIBBPF_API unsigned int bpf_object__kversion(struct bpf_object *obj);
77int bpf_object__btf_fd(const struct bpf_object *obj); 82LIBBPF_API int bpf_object__btf_fd(const struct bpf_object *obj);
78 83
79struct bpf_program * 84LIBBPF_API struct bpf_program *
80bpf_object__find_program_by_title(struct bpf_object *obj, const char *title); 85bpf_object__find_program_by_title(struct bpf_object *obj, const char *title);
81 86
82struct bpf_object *bpf_object__next(struct bpf_object *prev); 87LIBBPF_API struct bpf_object *bpf_object__next(struct bpf_object *prev);
83#define bpf_object__for_each_safe(pos, tmp) \ 88#define bpf_object__for_each_safe(pos, tmp) \
84 for ((pos) = bpf_object__next(NULL), \ 89 for ((pos) = bpf_object__next(NULL), \
85 (tmp) = bpf_object__next(pos); \ 90 (tmp) = bpf_object__next(pos); \
@@ -87,19 +92,20 @@ struct bpf_object *bpf_object__next(struct bpf_object *prev);
87 (pos) = (tmp), (tmp) = bpf_object__next(tmp)) 92 (pos) = (tmp), (tmp) = bpf_object__next(tmp))
88 93
89typedef void (*bpf_object_clear_priv_t)(struct bpf_object *, void *); 94typedef void (*bpf_object_clear_priv_t)(struct bpf_object *, void *);
90int bpf_object__set_priv(struct bpf_object *obj, void *priv, 95LIBBPF_API int bpf_object__set_priv(struct bpf_object *obj, void *priv,
91 bpf_object_clear_priv_t clear_priv); 96 bpf_object_clear_priv_t clear_priv);
92void *bpf_object__priv(struct bpf_object *prog); 97LIBBPF_API void *bpf_object__priv(struct bpf_object *prog);
93 98
94int libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type, 99LIBBPF_API int
95 enum bpf_attach_type *expected_attach_type); 100libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type,
96int libbpf_attach_type_by_name(const char *name, 101 enum bpf_attach_type *expected_attach_type);
97 enum bpf_attach_type *attach_type); 102LIBBPF_API int libbpf_attach_type_by_name(const char *name,
103 enum bpf_attach_type *attach_type);
98 104
99/* Accessors of bpf_program */ 105/* Accessors of bpf_program */
100struct bpf_program; 106struct bpf_program;
101struct bpf_program *bpf_program__next(struct bpf_program *prog, 107LIBBPF_API struct bpf_program *bpf_program__next(struct bpf_program *prog,
102 struct bpf_object *obj); 108 struct bpf_object *obj);
103 109
104#define bpf_object__for_each_program(pos, obj) \ 110#define bpf_object__for_each_program(pos, obj) \
105 for ((pos) = bpf_program__next(NULL, (obj)); \ 111 for ((pos) = bpf_program__next(NULL, (obj)); \
@@ -109,21 +115,24 @@ struct bpf_program *bpf_program__next(struct bpf_program *prog,
109typedef void (*bpf_program_clear_priv_t)(struct bpf_program *, 115typedef void (*bpf_program_clear_priv_t)(struct bpf_program *,
110 void *); 116 void *);
111 117
112int bpf_program__set_priv(struct bpf_program *prog, void *priv, 118LIBBPF_API int bpf_program__set_priv(struct bpf_program *prog, void *priv,
113 bpf_program_clear_priv_t clear_priv); 119 bpf_program_clear_priv_t clear_priv);
114 120
115void *bpf_program__priv(struct bpf_program *prog); 121LIBBPF_API void *bpf_program__priv(struct bpf_program *prog);
116void bpf_program__set_ifindex(struct bpf_program *prog, __u32 ifindex); 122LIBBPF_API void bpf_program__set_ifindex(struct bpf_program *prog,
123 __u32 ifindex);
117 124
118const char *bpf_program__title(struct bpf_program *prog, bool needs_copy); 125LIBBPF_API const char *bpf_program__title(struct bpf_program *prog,
126 bool needs_copy);
119 127
120int bpf_program__load(struct bpf_program *prog, char *license, 128LIBBPF_API int bpf_program__load(struct bpf_program *prog, char *license,
121 __u32 kern_version); 129 __u32 kern_version);
122int bpf_program__fd(struct bpf_program *prog); 130LIBBPF_API int bpf_program__fd(struct bpf_program *prog);
123int bpf_program__pin_instance(struct bpf_program *prog, const char *path, 131LIBBPF_API int bpf_program__pin_instance(struct bpf_program *prog,
124 int instance); 132 const char *path,
125int bpf_program__pin(struct bpf_program *prog, const char *path); 133 int instance);
126void bpf_program__unload(struct bpf_program *prog); 134LIBBPF_API int bpf_program__pin(struct bpf_program *prog, const char *path);
135LIBBPF_API void bpf_program__unload(struct bpf_program *prog);
127 136
128struct bpf_insn; 137struct bpf_insn;
129 138
@@ -184,34 +193,36 @@ typedef int (*bpf_program_prep_t)(struct bpf_program *prog, int n,
184 struct bpf_insn *insns, int insns_cnt, 193 struct bpf_insn *insns, int insns_cnt,
185 struct bpf_prog_prep_result *res); 194 struct bpf_prog_prep_result *res);
186 195
187int bpf_program__set_prep(struct bpf_program *prog, int nr_instance, 196LIBBPF_API int bpf_program__set_prep(struct bpf_program *prog, int nr_instance,
188 bpf_program_prep_t prep); 197 bpf_program_prep_t prep);
189 198
190int bpf_program__nth_fd(struct bpf_program *prog, int n); 199LIBBPF_API int bpf_program__nth_fd(struct bpf_program *prog, int n);
191 200
192/* 201/*
193 * Adjust type of BPF program. Default is kprobe. 202 * Adjust type of BPF program. Default is kprobe.
194 */ 203 */
195int bpf_program__set_socket_filter(struct bpf_program *prog); 204LIBBPF_API int bpf_program__set_socket_filter(struct bpf_program *prog);
196int bpf_program__set_tracepoint(struct bpf_program *prog); 205LIBBPF_API int bpf_program__set_tracepoint(struct bpf_program *prog);
197int bpf_program__set_raw_tracepoint(struct bpf_program *prog); 206LIBBPF_API int bpf_program__set_raw_tracepoint(struct bpf_program *prog);
198int bpf_program__set_kprobe(struct bpf_program *prog); 207LIBBPF_API int bpf_program__set_kprobe(struct bpf_program *prog);
199int bpf_program__set_sched_cls(struct bpf_program *prog); 208LIBBPF_API int bpf_program__set_sched_cls(struct bpf_program *prog);
200int bpf_program__set_sched_act(struct bpf_program *prog); 209LIBBPF_API int bpf_program__set_sched_act(struct bpf_program *prog);
201int bpf_program__set_xdp(struct bpf_program *prog); 210LIBBPF_API int bpf_program__set_xdp(struct bpf_program *prog);
202int bpf_program__set_perf_event(struct bpf_program *prog); 211LIBBPF_API int bpf_program__set_perf_event(struct bpf_program *prog);
203void bpf_program__set_type(struct bpf_program *prog, enum bpf_prog_type type); 212LIBBPF_API void bpf_program__set_type(struct bpf_program *prog,
204void bpf_program__set_expected_attach_type(struct bpf_program *prog, 213 enum bpf_prog_type type);
205 enum bpf_attach_type type); 214LIBBPF_API void
206 215bpf_program__set_expected_attach_type(struct bpf_program *prog,
207bool bpf_program__is_socket_filter(struct bpf_program *prog); 216 enum bpf_attach_type type);
208bool bpf_program__is_tracepoint(struct bpf_program *prog); 217
209bool bpf_program__is_raw_tracepoint(struct bpf_program *prog); 218LIBBPF_API bool bpf_program__is_socket_filter(struct bpf_program *prog);
210bool bpf_program__is_kprobe(struct bpf_program *prog); 219LIBBPF_API bool bpf_program__is_tracepoint(struct bpf_program *prog);
211bool bpf_program__is_sched_cls(struct bpf_program *prog); 220LIBBPF_API bool bpf_program__is_raw_tracepoint(struct bpf_program *prog);
212bool bpf_program__is_sched_act(struct bpf_program *prog); 221LIBBPF_API bool bpf_program__is_kprobe(struct bpf_program *prog);
213bool bpf_program__is_xdp(struct bpf_program *prog); 222LIBBPF_API bool bpf_program__is_sched_cls(struct bpf_program *prog);
214bool bpf_program__is_perf_event(struct bpf_program *prog); 223LIBBPF_API bool bpf_program__is_sched_act(struct bpf_program *prog);
224LIBBPF_API bool bpf_program__is_xdp(struct bpf_program *prog);
225LIBBPF_API bool bpf_program__is_perf_event(struct bpf_program *prog);
215 226
216/* 227/*
217 * No need for __attribute__((packed)), all members of 'bpf_map_def' 228 * No need for __attribute__((packed)), all members of 'bpf_map_def'
@@ -232,39 +243,39 @@ struct bpf_map_def {
232 * so no need to worry about a name clash. 243 * so no need to worry about a name clash.
233 */ 244 */
234struct bpf_map; 245struct bpf_map;
235struct bpf_map * 246LIBBPF_API struct bpf_map *
236bpf_object__find_map_by_name(struct bpf_object *obj, const char *name); 247bpf_object__find_map_by_name(struct bpf_object *obj, const char *name);
237 248
238/* 249/*
239 * Get bpf_map through the offset of corresponding struct bpf_map_def 250 * Get bpf_map through the offset of corresponding struct bpf_map_def
240 * in the BPF object file. 251 * in the BPF object file.
241 */ 252 */
242struct bpf_map * 253LIBBPF_API struct bpf_map *
243bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset); 254bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset);
244 255
245struct bpf_map * 256LIBBPF_API struct bpf_map *
246bpf_map__next(struct bpf_map *map, struct bpf_object *obj); 257bpf_map__next(struct bpf_map *map, struct bpf_object *obj);
247#define bpf_map__for_each(pos, obj) \ 258#define bpf_map__for_each(pos, obj) \
248 for ((pos) = bpf_map__next(NULL, (obj)); \ 259 for ((pos) = bpf_map__next(NULL, (obj)); \
249 (pos) != NULL; \ 260 (pos) != NULL; \
250 (pos) = bpf_map__next((pos), (obj))) 261 (pos) = bpf_map__next((pos), (obj)))
251 262
252int bpf_map__fd(struct bpf_map *map); 263LIBBPF_API int bpf_map__fd(struct bpf_map *map);
253const struct bpf_map_def *bpf_map__def(struct bpf_map *map); 264LIBBPF_API const struct bpf_map_def *bpf_map__def(struct bpf_map *map);
254const char *bpf_map__name(struct bpf_map *map); 265LIBBPF_API const char *bpf_map__name(struct bpf_map *map);
255__u32 bpf_map__btf_key_type_id(const struct bpf_map *map); 266LIBBPF_API __u32 bpf_map__btf_key_type_id(const struct bpf_map *map);
256__u32 bpf_map__btf_value_type_id(const struct bpf_map *map); 267LIBBPF_API __u32 bpf_map__btf_value_type_id(const struct bpf_map *map);
257 268
258typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *); 269typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *);
259int bpf_map__set_priv(struct bpf_map *map, void *priv, 270LIBBPF_API int bpf_map__set_priv(struct bpf_map *map, void *priv,
260 bpf_map_clear_priv_t clear_priv); 271 bpf_map_clear_priv_t clear_priv);
261void *bpf_map__priv(struct bpf_map *map); 272LIBBPF_API void *bpf_map__priv(struct bpf_map *map);
262int bpf_map__reuse_fd(struct bpf_map *map, int fd); 273LIBBPF_API int bpf_map__reuse_fd(struct bpf_map *map, int fd);
263bool bpf_map__is_offload_neutral(struct bpf_map *map); 274LIBBPF_API bool bpf_map__is_offload_neutral(struct bpf_map *map);
264void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex); 275LIBBPF_API void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex);
265int bpf_map__pin(struct bpf_map *map, const char *path); 276LIBBPF_API int bpf_map__pin(struct bpf_map *map, const char *path);
266 277
267long libbpf_get_error(const void *ptr); 278LIBBPF_API long libbpf_get_error(const void *ptr);
268 279
269struct bpf_prog_load_attr { 280struct bpf_prog_load_attr {
270 const char *file; 281 const char *file;
@@ -273,12 +284,12 @@ struct bpf_prog_load_attr {
273 int ifindex; 284 int ifindex;
274}; 285};
275 286
276int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr, 287LIBBPF_API int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr,
277 struct bpf_object **pobj, int *prog_fd); 288 struct bpf_object **pobj, int *prog_fd);
278int bpf_prog_load(const char *file, enum bpf_prog_type type, 289LIBBPF_API int bpf_prog_load(const char *file, enum bpf_prog_type type,
279 struct bpf_object **pobj, int *prog_fd); 290 struct bpf_object **pobj, int *prog_fd);
280 291
281int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags); 292LIBBPF_API int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags);
282 293
283enum bpf_perf_event_ret { 294enum bpf_perf_event_ret {
284 LIBBPF_PERF_EVENT_DONE = 0, 295 LIBBPF_PERF_EVENT_DONE = 0,
@@ -288,10 +299,11 @@ enum bpf_perf_event_ret {
288 299
289typedef enum bpf_perf_event_ret (*bpf_perf_event_print_t)(void *event, 300typedef enum bpf_perf_event_ret (*bpf_perf_event_print_t)(void *event,
290 void *priv); 301 void *priv);
291int bpf_perf_event_read_simple(void *mem, unsigned long size, 302LIBBPF_API int bpf_perf_event_read_simple(void *mem, unsigned long size,
292 unsigned long page_size, 303 unsigned long page_size,
293 void **buf, size_t *buf_len, 304 void **buf, size_t *buf_len,
294 bpf_perf_event_print_t fn, void *priv); 305 bpf_perf_event_print_t fn,
306 void *priv);
295 307
296struct nlattr; 308struct nlattr;
297typedef int (*libbpf_dump_nlmsg_t)(void *cookie, void *msg, struct nlattr **tb); 309typedef int (*libbpf_dump_nlmsg_t)(void *cookie, void *msg, struct nlattr **tb);