diff options
author | Andrey Ignatov <rdna@fb.com> | 2018-10-16 01:50:34 -0400 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2018-10-16 18:16:47 -0400 |
commit | ab9e084821221b2eda57a512535fe35b49e672d8 (patch) | |
tree | 024031e7d7cfd5b695d11c5e3617275b5e068e51 /tools/lib/bpf | |
parent | 421f4292f46e871cdcf8bdc3e6fdfcefe2e81a9d (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/Makefile | 1 | ||||
-rw-r--r-- | tools/lib/bpf/bpf.h | 118 | ||||
-rw-r--r-- | tools/lib/bpf/btf.h | 22 | ||||
-rw-r--r-- | tools/lib/bpf/libbpf.h | 186 |
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) | |||
125 | override CFLAGS += -Werror -Wall | 125 | override CFLAGS += -Werror -Wall |
126 | override CFLAGS += -fPIC | 126 | override CFLAGS += -fPIC |
127 | override CFLAGS += $(INCLUDES) | 127 | override CFLAGS += $(INCLUDES) |
128 | override CFLAGS += -fvisibility=hidden | ||
128 | 129 | ||
129 | ifeq ($(VERBOSE),1) | 130 | ifeq ($(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 | |||
30 | struct bpf_create_map_attr { | 34 | struct 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 | ||
45 | int bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr); | 49 | LIBBPF_API int |
46 | int bpf_create_map_node(enum bpf_map_type map_type, const char *name, | 50 | bpf_create_map_xattr(const struct bpf_create_map_attr *create_attr); |
47 | int key_size, int value_size, int max_entries, | 51 | LIBBPF_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, |
49 | int 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, | 54 | LIBBPF_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, |
52 | int 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); | 57 | LIBBPF_API int bpf_create_map(enum bpf_map_type map_type, int key_size, |
54 | int 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, | 59 | LIBBPF_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, |
57 | int 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); | 63 | LIBBPF_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 | ||
61 | struct bpf_load_program_attr { | 68 | struct 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) |
77 | int bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr, | 84 | LIBBPF_API int |
78 | char *log_buf, size_t log_buf_sz); | 85 | bpf_load_program_xattr(const struct bpf_load_program_attr *load_attr, |
79 | int 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, | 87 | LIBBPF_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, |
83 | int 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, | 91 | LIBBPF_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 | ||
88 | int bpf_map_update_elem(int fd, const void *key, const void *value, | 98 | LIBBPF_API int bpf_map_update_elem(int fd, const void *key, const void *value, |
89 | __u64 flags); | 99 | __u64 flags); |
90 | 100 | ||
91 | int bpf_map_lookup_elem(int fd, const void *key, void *value); | 101 | LIBBPF_API int bpf_map_lookup_elem(int fd, const void *key, void *value); |
92 | int bpf_map_delete_elem(int fd, const void *key); | 102 | LIBBPF_API int bpf_map_delete_elem(int fd, const void *key); |
93 | int bpf_map_get_next_key(int fd, const void *key, void *next_key); | 103 | LIBBPF_API int bpf_map_get_next_key(int fd, const void *key, void *next_key); |
94 | int bpf_obj_pin(int fd, const char *pathname); | 104 | LIBBPF_API int bpf_obj_pin(int fd, const char *pathname); |
95 | int bpf_obj_get(const char *pathname); | 105 | LIBBPF_API int bpf_obj_get(const char *pathname); |
96 | int bpf_prog_attach(int prog_fd, int attachable_fd, enum bpf_attach_type type, | 106 | LIBBPF_API int bpf_prog_attach(int prog_fd, int attachable_fd, |
97 | unsigned int flags); | 107 | enum bpf_attach_type type, unsigned int flags); |
98 | int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type); | 108 | LIBBPF_API int bpf_prog_detach(int attachable_fd, enum bpf_attach_type type); |
99 | int bpf_prog_detach2(int prog_fd, int attachable_fd, enum bpf_attach_type type); | 109 | LIBBPF_API int bpf_prog_detach2(int prog_fd, int attachable_fd, |
100 | int 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, | 111 | LIBBPF_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, |
103 | int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id); | 113 | __u32 *retval, __u32 *duration); |
104 | int bpf_map_get_next_id(__u32 start_id, __u32 *next_id); | 114 | LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id); |
105 | int bpf_prog_get_fd_by_id(__u32 id); | 115 | LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id); |
106 | int bpf_map_get_fd_by_id(__u32 id); | 116 | LIBBPF_API int bpf_prog_get_fd_by_id(__u32 id); |
107 | int bpf_btf_get_fd_by_id(__u32 id); | 117 | LIBBPF_API int bpf_map_get_fd_by_id(__u32 id); |
108 | int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len); | 118 | LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id); |
109 | int bpf_prog_query(int target_fd, enum bpf_attach_type type, __u32 query_flags, | 119 | LIBBPF_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); | 120 | LIBBPF_API int bpf_prog_query(int target_fd, enum bpf_attach_type type, |
111 | int bpf_raw_tracepoint_open(const char *name, int prog_fd); | 121 | __u32 query_flags, __u32 *attach_flags, |
112 | int 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); | 123 | LIBBPF_API int bpf_raw_tracepoint_open(const char *name, int prog_fd); |
114 | int bpf_task_fd_query(int pid, int fd, __u32 flags, char *buf, __u32 *buf_len, | 124 | LIBBPF_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); | 126 | LIBBPF_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 | ||
11 | struct btf; | 15 | struct btf; |
@@ -14,13 +18,15 @@ struct btf_type; | |||
14 | typedef int (*btf_print_fn_t)(const char *, ...) | 18 | typedef int (*btf_print_fn_t)(const char *, ...) |
15 | __attribute__((format(printf, 1, 2))); | 19 | __attribute__((format(printf, 1, 2))); |
16 | 20 | ||
17 | void btf__free(struct btf *btf); | 21 | LIBBPF_API void btf__free(struct btf *btf); |
18 | struct btf *btf__new(__u8 *data, __u32 size, btf_print_fn_t err_log); | 22 | LIBBPF_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); | 23 | LIBBPF_API __s32 btf__find_by_name(const struct btf *btf, |
20 | const 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); | 25 | LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf, |
22 | int btf__resolve_type(const struct btf *btf, __u32 type_id); | 26 | __u32 id); |
23 | int btf__fd(const struct btf *btf); | 27 | LIBBPF_API __s64 btf__resolve_size(const struct btf *btf, __u32 type_id); |
24 | const char *btf__name_by_offset(const struct btf *btf, __u32 offset); | 28 | LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id); |
29 | LIBBPF_API int btf__fd(const struct btf *btf); | ||
30 | LIBBPF_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 | |||
19 | enum libbpf_errno { | 23 | enum 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 | ||
40 | int libbpf_strerror(int err, char *buf, size_t size); | 44 | LIBBPF_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); | |||
47 | typedef int (*libbpf_print_fn_t)(const char *, ...) | 51 | typedef int (*libbpf_print_fn_t)(const char *, ...) |
48 | __attribute__((format(printf, 1, 2))); | 52 | __attribute__((format(printf, 1, 2))); |
49 | 53 | ||
50 | void libbpf_set_print(libbpf_print_fn_t warn, | 54 | LIBBPF_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 */ |
55 | struct bpf_object; | 59 | struct 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 | ||
62 | struct bpf_object *bpf_object__open(const char *path); | 66 | LIBBPF_API struct bpf_object *bpf_object__open(const char *path); |
63 | struct bpf_object *bpf_object__open_xattr(struct bpf_object_open_attr *attr); | 67 | LIBBPF_API struct bpf_object * |
68 | bpf_object__open_xattr(struct bpf_object_open_attr *attr); | ||
64 | struct bpf_object *__bpf_object__open_xattr(struct bpf_object_open_attr *attr, | 69 | struct bpf_object *__bpf_object__open_xattr(struct bpf_object_open_attr *attr, |
65 | int flags); | 70 | int flags); |
66 | struct bpf_object *bpf_object__open_buffer(void *obj_buf, | 71 | LIBBPF_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); |
69 | int bpf_object__pin(struct bpf_object *object, const char *path); | 74 | LIBBPF_API int bpf_object__pin(struct bpf_object *object, const char *path); |
70 | void bpf_object__close(struct bpf_object *object); | 75 | LIBBPF_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 */ |
73 | int bpf_object__load(struct bpf_object *obj); | 78 | LIBBPF_API int bpf_object__load(struct bpf_object *obj); |
74 | int bpf_object__unload(struct bpf_object *obj); | 79 | LIBBPF_API int bpf_object__unload(struct bpf_object *obj); |
75 | const char *bpf_object__name(struct bpf_object *obj); | 80 | LIBBPF_API const char *bpf_object__name(struct bpf_object *obj); |
76 | unsigned int bpf_object__kversion(struct bpf_object *obj); | 81 | LIBBPF_API unsigned int bpf_object__kversion(struct bpf_object *obj); |
77 | int bpf_object__btf_fd(const struct bpf_object *obj); | 82 | LIBBPF_API int bpf_object__btf_fd(const struct bpf_object *obj); |
78 | 83 | ||
79 | struct bpf_program * | 84 | LIBBPF_API struct bpf_program * |
80 | bpf_object__find_program_by_title(struct bpf_object *obj, const char *title); | 85 | bpf_object__find_program_by_title(struct bpf_object *obj, const char *title); |
81 | 86 | ||
82 | struct bpf_object *bpf_object__next(struct bpf_object *prev); | 87 | LIBBPF_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 | ||
89 | typedef void (*bpf_object_clear_priv_t)(struct bpf_object *, void *); | 94 | typedef void (*bpf_object_clear_priv_t)(struct bpf_object *, void *); |
90 | int bpf_object__set_priv(struct bpf_object *obj, void *priv, | 95 | LIBBPF_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); |
92 | void *bpf_object__priv(struct bpf_object *prog); | 97 | LIBBPF_API void *bpf_object__priv(struct bpf_object *prog); |
93 | 98 | ||
94 | int libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type, | 99 | LIBBPF_API int |
95 | enum bpf_attach_type *expected_attach_type); | 100 | libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type, |
96 | int libbpf_attach_type_by_name(const char *name, | 101 | enum bpf_attach_type *expected_attach_type); |
97 | enum bpf_attach_type *attach_type); | 102 | LIBBPF_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 */ |
100 | struct bpf_program; | 106 | struct bpf_program; |
101 | struct bpf_program *bpf_program__next(struct bpf_program *prog, | 107 | LIBBPF_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, | |||
109 | typedef void (*bpf_program_clear_priv_t)(struct bpf_program *, | 115 | typedef void (*bpf_program_clear_priv_t)(struct bpf_program *, |
110 | void *); | 116 | void *); |
111 | 117 | ||
112 | int bpf_program__set_priv(struct bpf_program *prog, void *priv, | 118 | LIBBPF_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 | ||
115 | void *bpf_program__priv(struct bpf_program *prog); | 121 | LIBBPF_API void *bpf_program__priv(struct bpf_program *prog); |
116 | void bpf_program__set_ifindex(struct bpf_program *prog, __u32 ifindex); | 122 | LIBBPF_API void bpf_program__set_ifindex(struct bpf_program *prog, |
123 | __u32 ifindex); | ||
117 | 124 | ||
118 | const char *bpf_program__title(struct bpf_program *prog, bool needs_copy); | 125 | LIBBPF_API const char *bpf_program__title(struct bpf_program *prog, |
126 | bool needs_copy); | ||
119 | 127 | ||
120 | int bpf_program__load(struct bpf_program *prog, char *license, | 128 | LIBBPF_API int bpf_program__load(struct bpf_program *prog, char *license, |
121 | __u32 kern_version); | 129 | __u32 kern_version); |
122 | int bpf_program__fd(struct bpf_program *prog); | 130 | LIBBPF_API int bpf_program__fd(struct bpf_program *prog); |
123 | int bpf_program__pin_instance(struct bpf_program *prog, const char *path, | 131 | LIBBPF_API int bpf_program__pin_instance(struct bpf_program *prog, |
124 | int instance); | 132 | const char *path, |
125 | int bpf_program__pin(struct bpf_program *prog, const char *path); | 133 | int instance); |
126 | void bpf_program__unload(struct bpf_program *prog); | 134 | LIBBPF_API int bpf_program__pin(struct bpf_program *prog, const char *path); |
135 | LIBBPF_API void bpf_program__unload(struct bpf_program *prog); | ||
127 | 136 | ||
128 | struct bpf_insn; | 137 | struct 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 | ||
187 | int bpf_program__set_prep(struct bpf_program *prog, int nr_instance, | 196 | LIBBPF_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 | ||
190 | int bpf_program__nth_fd(struct bpf_program *prog, int n); | 199 | LIBBPF_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 | */ |
195 | int bpf_program__set_socket_filter(struct bpf_program *prog); | 204 | LIBBPF_API int bpf_program__set_socket_filter(struct bpf_program *prog); |
196 | int bpf_program__set_tracepoint(struct bpf_program *prog); | 205 | LIBBPF_API int bpf_program__set_tracepoint(struct bpf_program *prog); |
197 | int bpf_program__set_raw_tracepoint(struct bpf_program *prog); | 206 | LIBBPF_API int bpf_program__set_raw_tracepoint(struct bpf_program *prog); |
198 | int bpf_program__set_kprobe(struct bpf_program *prog); | 207 | LIBBPF_API int bpf_program__set_kprobe(struct bpf_program *prog); |
199 | int bpf_program__set_sched_cls(struct bpf_program *prog); | 208 | LIBBPF_API int bpf_program__set_sched_cls(struct bpf_program *prog); |
200 | int bpf_program__set_sched_act(struct bpf_program *prog); | 209 | LIBBPF_API int bpf_program__set_sched_act(struct bpf_program *prog); |
201 | int bpf_program__set_xdp(struct bpf_program *prog); | 210 | LIBBPF_API int bpf_program__set_xdp(struct bpf_program *prog); |
202 | int bpf_program__set_perf_event(struct bpf_program *prog); | 211 | LIBBPF_API int bpf_program__set_perf_event(struct bpf_program *prog); |
203 | void bpf_program__set_type(struct bpf_program *prog, enum bpf_prog_type type); | 212 | LIBBPF_API void bpf_program__set_type(struct bpf_program *prog, |
204 | void bpf_program__set_expected_attach_type(struct bpf_program *prog, | 213 | enum bpf_prog_type type); |
205 | enum bpf_attach_type type); | 214 | LIBBPF_API void |
206 | 215 | bpf_program__set_expected_attach_type(struct bpf_program *prog, | |
207 | bool bpf_program__is_socket_filter(struct bpf_program *prog); | 216 | enum bpf_attach_type type); |
208 | bool bpf_program__is_tracepoint(struct bpf_program *prog); | 217 | |
209 | bool bpf_program__is_raw_tracepoint(struct bpf_program *prog); | 218 | LIBBPF_API bool bpf_program__is_socket_filter(struct bpf_program *prog); |
210 | bool bpf_program__is_kprobe(struct bpf_program *prog); | 219 | LIBBPF_API bool bpf_program__is_tracepoint(struct bpf_program *prog); |
211 | bool bpf_program__is_sched_cls(struct bpf_program *prog); | 220 | LIBBPF_API bool bpf_program__is_raw_tracepoint(struct bpf_program *prog); |
212 | bool bpf_program__is_sched_act(struct bpf_program *prog); | 221 | LIBBPF_API bool bpf_program__is_kprobe(struct bpf_program *prog); |
213 | bool bpf_program__is_xdp(struct bpf_program *prog); | 222 | LIBBPF_API bool bpf_program__is_sched_cls(struct bpf_program *prog); |
214 | bool bpf_program__is_perf_event(struct bpf_program *prog); | 223 | LIBBPF_API bool bpf_program__is_sched_act(struct bpf_program *prog); |
224 | LIBBPF_API bool bpf_program__is_xdp(struct bpf_program *prog); | ||
225 | LIBBPF_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 | */ |
234 | struct bpf_map; | 245 | struct bpf_map; |
235 | struct bpf_map * | 246 | LIBBPF_API struct bpf_map * |
236 | bpf_object__find_map_by_name(struct bpf_object *obj, const char *name); | 247 | bpf_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 | */ |
242 | struct bpf_map * | 253 | LIBBPF_API struct bpf_map * |
243 | bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset); | 254 | bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset); |
244 | 255 | ||
245 | struct bpf_map * | 256 | LIBBPF_API struct bpf_map * |
246 | bpf_map__next(struct bpf_map *map, struct bpf_object *obj); | 257 | bpf_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 | ||
252 | int bpf_map__fd(struct bpf_map *map); | 263 | LIBBPF_API int bpf_map__fd(struct bpf_map *map); |
253 | const struct bpf_map_def *bpf_map__def(struct bpf_map *map); | 264 | LIBBPF_API const struct bpf_map_def *bpf_map__def(struct bpf_map *map); |
254 | const char *bpf_map__name(struct bpf_map *map); | 265 | LIBBPF_API const char *bpf_map__name(struct bpf_map *map); |
255 | __u32 bpf_map__btf_key_type_id(const struct bpf_map *map); | 266 | LIBBPF_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); | 267 | LIBBPF_API __u32 bpf_map__btf_value_type_id(const struct bpf_map *map); |
257 | 268 | ||
258 | typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *); | 269 | typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *); |
259 | int bpf_map__set_priv(struct bpf_map *map, void *priv, | 270 | LIBBPF_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); |
261 | void *bpf_map__priv(struct bpf_map *map); | 272 | LIBBPF_API void *bpf_map__priv(struct bpf_map *map); |
262 | int bpf_map__reuse_fd(struct bpf_map *map, int fd); | 273 | LIBBPF_API int bpf_map__reuse_fd(struct bpf_map *map, int fd); |
263 | bool bpf_map__is_offload_neutral(struct bpf_map *map); | 274 | LIBBPF_API bool bpf_map__is_offload_neutral(struct bpf_map *map); |
264 | void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex); | 275 | LIBBPF_API void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex); |
265 | int bpf_map__pin(struct bpf_map *map, const char *path); | 276 | LIBBPF_API int bpf_map__pin(struct bpf_map *map, const char *path); |
266 | 277 | ||
267 | long libbpf_get_error(const void *ptr); | 278 | LIBBPF_API long libbpf_get_error(const void *ptr); |
268 | 279 | ||
269 | struct bpf_prog_load_attr { | 280 | struct 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 | ||
276 | int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr, | 287 | LIBBPF_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); |
278 | int bpf_prog_load(const char *file, enum bpf_prog_type type, | 289 | LIBBPF_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 | ||
281 | int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags); | 292 | LIBBPF_API int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags); |
282 | 293 | ||
283 | enum bpf_perf_event_ret { | 294 | enum 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 | ||
289 | typedef enum bpf_perf_event_ret (*bpf_perf_event_print_t)(void *event, | 300 | typedef enum bpf_perf_event_ret (*bpf_perf_event_print_t)(void *event, |
290 | void *priv); | 301 | void *priv); |
291 | int bpf_perf_event_read_simple(void *mem, unsigned long size, | 302 | LIBBPF_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 | ||
296 | struct nlattr; | 308 | struct nlattr; |
297 | typedef int (*libbpf_dump_nlmsg_t)(void *cookie, void *msg, struct nlattr **tb); | 309 | typedef int (*libbpf_dump_nlmsg_t)(void *cookie, void *msg, struct nlattr **tb); |