Eric Leblond | 6061a3d | 2018-01-30 21:55:03 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: LGPL-2.1 */ |
| 2 | |
Wang Nan | 1b76c13 | 2015-07-01 02:13:51 +0000 | [diff] [blame] | 3 | /* |
| 4 | * Common eBPF ELF object loading operations. |
| 5 | * |
| 6 | * Copyright (C) 2013-2015 Alexei Starovoitov <ast@kernel.org> |
| 7 | * Copyright (C) 2015 Wang Nan <wangnan0@huawei.com> |
| 8 | * Copyright (C) 2015 Huawei Inc. |
Wang Nan | 203d1ca | 2016-07-04 11:02:42 +0000 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Lesser General Public |
| 12 | * License as published by the Free Software Foundation; |
| 13 | * version 2.1 of the License (not later!) |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU Lesser General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Lesser General Public |
| 21 | * License along with this program; if not, see <http://www.gnu.org/licenses> |
Wang Nan | 1b76c13 | 2015-07-01 02:13:51 +0000 | [diff] [blame] | 22 | */ |
| 23 | #ifndef __BPF_LIBBPF_H |
| 24 | #define __BPF_LIBBPF_H |
| 25 | |
Wang Nan | 1a5e3fb | 2015-07-01 02:13:53 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
Joe Stringer | e28ff1a | 2017-01-22 17:11:25 -0800 | [diff] [blame] | 27 | #include <stdint.h> |
Wang Nan | aa9b1ac | 2015-07-01 02:14:08 +0000 | [diff] [blame] | 28 | #include <stdbool.h> |
Wang Nan | 5a6acad | 2016-11-26 07:03:27 +0000 | [diff] [blame] | 29 | #include <sys/types.h> // for size_t |
Alexei Starovoitov | dd26b7f | 2017-03-30 21:45:40 -0700 | [diff] [blame] | 30 | #include <linux/bpf.h> |
Wang Nan | 6371ca3b | 2015-11-06 13:49:37 +0000 | [diff] [blame] | 31 | |
| 32 | enum libbpf_errno { |
| 33 | __LIBBPF_ERRNO__START = 4000, |
| 34 | |
| 35 | /* Something wrong in libelf */ |
| 36 | LIBBPF_ERRNO__LIBELF = __LIBBPF_ERRNO__START, |
| 37 | LIBBPF_ERRNO__FORMAT, /* BPF object format invalid */ |
| 38 | LIBBPF_ERRNO__KVERSION, /* Incorrect or no 'version' section */ |
Colin Ian King | de8a63b | 2016-06-28 13:23:37 +0100 | [diff] [blame] | 39 | LIBBPF_ERRNO__ENDIAN, /* Endian mismatch */ |
Wang Nan | 6371ca3b | 2015-11-06 13:49:37 +0000 | [diff] [blame] | 40 | LIBBPF_ERRNO__INTERNAL, /* Internal error in libbpf */ |
| 41 | LIBBPF_ERRNO__RELOC, /* Relocation failed */ |
| 42 | LIBBPF_ERRNO__LOAD, /* Load program failure for unknown reason */ |
| 43 | LIBBPF_ERRNO__VERIFY, /* Kernel verifier blocks program loading */ |
| 44 | LIBBPF_ERRNO__PROG2BIG, /* Program too big */ |
| 45 | LIBBPF_ERRNO__KVER, /* Incorrect kernel version */ |
Wang Nan | 705fa21 | 2016-07-13 10:44:02 +0000 | [diff] [blame] | 46 | LIBBPF_ERRNO__PROGTYPE, /* Kernel doesn't support this program type */ |
Eric Leblond | 949abbe | 2018-01-30 21:55:01 +0100 | [diff] [blame] | 47 | LIBBPF_ERRNO__WRNGPID, /* Wrong pid in netlink message */ |
| 48 | LIBBPF_ERRNO__INVSEQ, /* Invalid netlink sequence */ |
Wang Nan | 6371ca3b | 2015-11-06 13:49:37 +0000 | [diff] [blame] | 49 | __LIBBPF_ERRNO__END, |
| 50 | }; |
| 51 | |
| 52 | int libbpf_strerror(int err, char *buf, size_t size); |
Wang Nan | 1a5e3fb | 2015-07-01 02:13:53 +0000 | [diff] [blame] | 53 | |
Wang Nan | b3f59d6 | 2015-07-01 02:13:52 +0000 | [diff] [blame] | 54 | /* |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 55 | * __printf is defined in include/linux/compiler-gcc.h. However, |
| 56 | * it would be better if libbpf.h didn't depend on Linux header files. |
Wang Nan | b3f59d6 | 2015-07-01 02:13:52 +0000 | [diff] [blame] | 57 | * So instead of __printf, here we use gcc attribute directly. |
| 58 | */ |
| 59 | typedef int (*libbpf_print_fn_t)(const char *, ...) |
| 60 | __attribute__((format(printf, 1, 2))); |
| 61 | |
| 62 | void libbpf_set_print(libbpf_print_fn_t warn, |
| 63 | libbpf_print_fn_t info, |
| 64 | libbpf_print_fn_t debug); |
| 65 | |
Wang Nan | 1a5e3fb | 2015-07-01 02:13:53 +0000 | [diff] [blame] | 66 | /* Hide internal to user */ |
| 67 | struct bpf_object; |
| 68 | |
Jakub Kicinski | 07f2d4e | 2018-07-10 14:43:02 -0700 | [diff] [blame] | 69 | struct bpf_object_open_attr { |
| 70 | const char *file; |
| 71 | enum bpf_prog_type prog_type; |
| 72 | }; |
| 73 | |
Wang Nan | 1a5e3fb | 2015-07-01 02:13:53 +0000 | [diff] [blame] | 74 | struct bpf_object *bpf_object__open(const char *path); |
Jakub Kicinski | 07f2d4e | 2018-07-10 14:43:02 -0700 | [diff] [blame] | 75 | struct bpf_object *bpf_object__open_xattr(struct bpf_object_open_attr *attr); |
Wang Nan | 6c95639 | 2015-07-01 02:13:54 +0000 | [diff] [blame] | 76 | struct bpf_object *bpf_object__open_buffer(void *obj_buf, |
Wang Nan | acf860a | 2015-08-27 02:30:55 +0000 | [diff] [blame] | 77 | size_t obj_buf_sz, |
| 78 | const char *name); |
Joe Stringer | d5148d8 | 2017-01-26 13:19:58 -0800 | [diff] [blame] | 79 | int bpf_object__pin(struct bpf_object *object, const char *path); |
Wang Nan | 1a5e3fb | 2015-07-01 02:13:53 +0000 | [diff] [blame] | 80 | void bpf_object__close(struct bpf_object *object); |
| 81 | |
Wang Nan | 52d3352 | 2015-07-01 02:14:04 +0000 | [diff] [blame] | 82 | /* Load/unload object into/from kernel */ |
| 83 | int bpf_object__load(struct bpf_object *obj); |
| 84 | int bpf_object__unload(struct bpf_object *obj); |
Arnaldo Carvalho de Melo | a7fe045 | 2016-06-03 12:22:51 -0300 | [diff] [blame] | 85 | const char *bpf_object__name(struct bpf_object *obj); |
| 86 | unsigned int bpf_object__kversion(struct bpf_object *obj); |
Martin KaFai Lau | 8a138ae | 2018-04-18 15:56:05 -0700 | [diff] [blame] | 87 | int bpf_object__btf_fd(const struct bpf_object *obj); |
Wang Nan | 52d3352 | 2015-07-01 02:14:04 +0000 | [diff] [blame] | 88 | |
Wang Nan | 9a208ef | 2015-07-01 02:14:10 +0000 | [diff] [blame] | 89 | struct bpf_object *bpf_object__next(struct bpf_object *prev); |
| 90 | #define bpf_object__for_each_safe(pos, tmp) \ |
| 91 | for ((pos) = bpf_object__next(NULL), \ |
| 92 | (tmp) = bpf_object__next(pos); \ |
| 93 | (pos) != NULL; \ |
| 94 | (pos) = (tmp), (tmp) = bpf_object__next(tmp)) |
| 95 | |
Wang Nan | 10931d2 | 2016-11-26 07:03:26 +0000 | [diff] [blame] | 96 | typedef void (*bpf_object_clear_priv_t)(struct bpf_object *, void *); |
| 97 | int bpf_object__set_priv(struct bpf_object *obj, void *priv, |
| 98 | bpf_object_clear_priv_t clear_priv); |
| 99 | void *bpf_object__priv(struct bpf_object *prog); |
| 100 | |
Jakub Kicinski | b60df2a | 2018-07-10 14:42:59 -0700 | [diff] [blame] | 101 | int libbpf_prog_type_by_name(const char *name, enum bpf_prog_type *prog_type, |
| 102 | enum bpf_attach_type *expected_attach_type); |
| 103 | |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 104 | /* Accessors of bpf_program */ |
Wang Nan | aa9b1ac | 2015-07-01 02:14:08 +0000 | [diff] [blame] | 105 | struct bpf_program; |
| 106 | struct bpf_program *bpf_program__next(struct bpf_program *prog, |
| 107 | struct bpf_object *obj); |
| 108 | |
| 109 | #define bpf_object__for_each_program(pos, obj) \ |
| 110 | for ((pos) = bpf_program__next(NULL, (obj)); \ |
| 111 | (pos) != NULL; \ |
| 112 | (pos) = bpf_program__next((pos), (obj))) |
| 113 | |
| 114 | typedef void (*bpf_program_clear_priv_t)(struct bpf_program *, |
| 115 | void *); |
| 116 | |
Arnaldo Carvalho de Melo | edb13ed | 2016-06-03 12:38:21 -0300 | [diff] [blame] | 117 | int bpf_program__set_priv(struct bpf_program *prog, void *priv, |
| 118 | bpf_program_clear_priv_t clear_priv); |
Wang Nan | aa9b1ac | 2015-07-01 02:14:08 +0000 | [diff] [blame] | 119 | |
Arnaldo Carvalho de Melo | be834ff | 2016-06-03 12:36:39 -0300 | [diff] [blame] | 120 | void *bpf_program__priv(struct bpf_program *prog); |
Jakub Kicinski | 9aba361 | 2018-06-28 14:41:37 -0700 | [diff] [blame] | 121 | void bpf_program__set_ifindex(struct bpf_program *prog, __u32 ifindex); |
Wang Nan | aa9b1ac | 2015-07-01 02:14:08 +0000 | [diff] [blame] | 122 | |
Namhyung Kim | 715f8db | 2015-11-03 20:21:05 +0900 | [diff] [blame] | 123 | const char *bpf_program__title(struct bpf_program *prog, bool needs_copy); |
Wang Nan | aa9b1ac | 2015-07-01 02:14:08 +0000 | [diff] [blame] | 124 | |
| 125 | int bpf_program__fd(struct bpf_program *prog); |
Joe Stringer | f367540 | 2017-01-26 13:19:56 -0800 | [diff] [blame] | 126 | int bpf_program__pin_instance(struct bpf_program *prog, const char *path, |
| 127 | int instance); |
| 128 | int bpf_program__pin(struct bpf_program *prog, const char *path); |
Wang Nan | aa9b1ac | 2015-07-01 02:14:08 +0000 | [diff] [blame] | 129 | |
Wang Nan | b580563 | 2015-11-16 12:10:09 +0000 | [diff] [blame] | 130 | struct bpf_insn; |
| 131 | |
| 132 | /* |
| 133 | * Libbpf allows callers to adjust BPF programs before being loaded |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 134 | * into kernel. One program in an object file can be transformed into |
| 135 | * multiple variants to be attached to different hooks. |
Wang Nan | b580563 | 2015-11-16 12:10:09 +0000 | [diff] [blame] | 136 | * |
| 137 | * bpf_program_prep_t, bpf_program__set_prep and bpf_program__nth_fd |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 138 | * form an API for this purpose. |
Wang Nan | b580563 | 2015-11-16 12:10:09 +0000 | [diff] [blame] | 139 | * |
| 140 | * - bpf_program_prep_t: |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 141 | * Defines a 'preprocessor', which is a caller defined function |
Wang Nan | b580563 | 2015-11-16 12:10:09 +0000 | [diff] [blame] | 142 | * passed to libbpf through bpf_program__set_prep(), and will be |
| 143 | * called before program is loaded. The processor should adjust |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 144 | * the program one time for each instance according to the instance id |
Wang Nan | b580563 | 2015-11-16 12:10:09 +0000 | [diff] [blame] | 145 | * passed to it. |
| 146 | * |
| 147 | * - bpf_program__set_prep: |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 148 | * Attaches a preprocessor to a BPF program. The number of instances |
| 149 | * that should be created is also passed through this function. |
Wang Nan | b580563 | 2015-11-16 12:10:09 +0000 | [diff] [blame] | 150 | * |
| 151 | * - bpf_program__nth_fd: |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 152 | * After the program is loaded, get resulting FD of a given instance |
| 153 | * of the BPF program. |
Wang Nan | b580563 | 2015-11-16 12:10:09 +0000 | [diff] [blame] | 154 | * |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 155 | * If bpf_program__set_prep() is not used, the program would be loaded |
Wang Nan | b580563 | 2015-11-16 12:10:09 +0000 | [diff] [blame] | 156 | * without adjustment during bpf_object__load(). The program has only |
| 157 | * one instance. In this case bpf_program__fd(prog) is equal to |
| 158 | * bpf_program__nth_fd(prog, 0). |
| 159 | */ |
| 160 | |
| 161 | struct bpf_prog_prep_result { |
| 162 | /* |
| 163 | * If not NULL, load new instruction array. |
| 164 | * If set to NULL, don't load this instance. |
| 165 | */ |
| 166 | struct bpf_insn *new_insn_ptr; |
| 167 | int new_insn_cnt; |
| 168 | |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 169 | /* If not NULL, result FD is written to it. */ |
Wang Nan | b580563 | 2015-11-16 12:10:09 +0000 | [diff] [blame] | 170 | int *pfd; |
| 171 | }; |
| 172 | |
| 173 | /* |
| 174 | * Parameters of bpf_program_prep_t: |
| 175 | * - prog: The bpf_program being loaded. |
| 176 | * - n: Index of instance being generated. |
| 177 | * - insns: BPF instructions array. |
| 178 | * - insns_cnt:Number of instructions in insns. |
| 179 | * - res: Output parameter, result of transformation. |
| 180 | * |
| 181 | * Return value: |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 182 | * - Zero: pre-processing success. |
| 183 | * - Non-zero: pre-processing error, stop loading. |
Wang Nan | b580563 | 2015-11-16 12:10:09 +0000 | [diff] [blame] | 184 | */ |
| 185 | typedef int (*bpf_program_prep_t)(struct bpf_program *prog, int n, |
| 186 | struct bpf_insn *insns, int insns_cnt, |
| 187 | struct bpf_prog_prep_result *res); |
| 188 | |
| 189 | int bpf_program__set_prep(struct bpf_program *prog, int nr_instance, |
| 190 | bpf_program_prep_t prep); |
| 191 | |
| 192 | int bpf_program__nth_fd(struct bpf_program *prog, int n); |
| 193 | |
Wang Nan | 3409091 | 2015-07-01 02:14:02 +0000 | [diff] [blame] | 194 | /* |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 195 | * Adjust type of BPF program. Default is kprobe. |
Wang Nan | 5f44e4c8 | 2016-07-13 10:44:01 +0000 | [diff] [blame] | 196 | */ |
Joe Stringer | 7803ba7 | 2017-01-22 17:11:24 -0800 | [diff] [blame] | 197 | int bpf_program__set_socket_filter(struct bpf_program *prog); |
Wang Nan | 5f44e4c8 | 2016-07-13 10:44:01 +0000 | [diff] [blame] | 198 | int bpf_program__set_tracepoint(struct bpf_program *prog); |
Andrey Ignatov | e14c93f | 2018-04-17 10:28:46 -0700 | [diff] [blame] | 199 | int bpf_program__set_raw_tracepoint(struct bpf_program *prog); |
Wang Nan | 5f44e4c8 | 2016-07-13 10:44:01 +0000 | [diff] [blame] | 200 | int bpf_program__set_kprobe(struct bpf_program *prog); |
Joe Stringer | 7803ba7 | 2017-01-22 17:11:24 -0800 | [diff] [blame] | 201 | int bpf_program__set_sched_cls(struct bpf_program *prog); |
| 202 | int bpf_program__set_sched_act(struct bpf_program *prog); |
| 203 | int bpf_program__set_xdp(struct bpf_program *prog); |
| 204 | int bpf_program__set_perf_event(struct bpf_program *prog); |
Alexei Starovoitov | dd26b7f | 2017-03-30 21:45:40 -0700 | [diff] [blame] | 205 | void bpf_program__set_type(struct bpf_program *prog, enum bpf_prog_type type); |
John Fastabend | 16962b2 | 2018-04-23 14:30:38 -0700 | [diff] [blame] | 206 | void bpf_program__set_expected_attach_type(struct bpf_program *prog, |
| 207 | enum bpf_attach_type type); |
Wang Nan | 5f44e4c8 | 2016-07-13 10:44:01 +0000 | [diff] [blame] | 208 | |
Joe Stringer | 7803ba7 | 2017-01-22 17:11:24 -0800 | [diff] [blame] | 209 | bool bpf_program__is_socket_filter(struct bpf_program *prog); |
Wang Nan | 5f44e4c8 | 2016-07-13 10:44:01 +0000 | [diff] [blame] | 210 | bool bpf_program__is_tracepoint(struct bpf_program *prog); |
Andrey Ignatov | e14c93f | 2018-04-17 10:28:46 -0700 | [diff] [blame] | 211 | bool bpf_program__is_raw_tracepoint(struct bpf_program *prog); |
Wang Nan | 5f44e4c8 | 2016-07-13 10:44:01 +0000 | [diff] [blame] | 212 | bool bpf_program__is_kprobe(struct bpf_program *prog); |
Joe Stringer | 7803ba7 | 2017-01-22 17:11:24 -0800 | [diff] [blame] | 213 | bool bpf_program__is_sched_cls(struct bpf_program *prog); |
| 214 | bool bpf_program__is_sched_act(struct bpf_program *prog); |
| 215 | bool bpf_program__is_xdp(struct bpf_program *prog); |
| 216 | bool bpf_program__is_perf_event(struct bpf_program *prog); |
Wang Nan | 5f44e4c8 | 2016-07-13 10:44:01 +0000 | [diff] [blame] | 217 | |
| 218 | /* |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 219 | * No need for __attribute__((packed)), all members of 'bpf_map_def' |
| 220 | * are all aligned. In addition, using __attribute__((packed)) |
| 221 | * would trigger a -Wpacked warning message, and lead to an error |
| 222 | * if -Werror is set. |
Wang Nan | 3409091 | 2015-07-01 02:14:02 +0000 | [diff] [blame] | 223 | */ |
| 224 | struct bpf_map_def { |
| 225 | unsigned int type; |
| 226 | unsigned int key_size; |
| 227 | unsigned int value_size; |
| 228 | unsigned int max_entries; |
Craig Gallek | fe9b5f7 | 2017-10-05 10:41:58 -0400 | [diff] [blame] | 229 | unsigned int map_flags; |
Wang Nan | 3409091 | 2015-07-01 02:14:02 +0000 | [diff] [blame] | 230 | }; |
| 231 | |
Wang Nan | 9d759a9 | 2015-11-27 08:47:35 +0000 | [diff] [blame] | 232 | /* |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 233 | * The 'struct bpf_map' in include/linux/bpf.h is internal to the kernel, |
| 234 | * so no need to worry about a name clash. |
Wang Nan | 9d759a9 | 2015-11-27 08:47:35 +0000 | [diff] [blame] | 235 | */ |
| 236 | struct bpf_map; |
Wang Nan | 561bbcc | 2015-11-27 08:47:36 +0000 | [diff] [blame] | 237 | struct bpf_map * |
Arnaldo Carvalho de Melo | a7fe045 | 2016-06-03 12:22:51 -0300 | [diff] [blame] | 238 | bpf_object__find_map_by_name(struct bpf_object *obj, const char *name); |
Wang Nan | 9d759a9 | 2015-11-27 08:47:35 +0000 | [diff] [blame] | 239 | |
Wang Nan | 5a6acad | 2016-11-26 07:03:27 +0000 | [diff] [blame] | 240 | /* |
| 241 | * Get bpf_map through the offset of corresponding struct bpf_map_def |
Jakub Kicinski | 2eb57bb | 2018-05-10 10:24:41 -0700 | [diff] [blame] | 242 | * in the BPF object file. |
Wang Nan | 5a6acad | 2016-11-26 07:03:27 +0000 | [diff] [blame] | 243 | */ |
| 244 | struct bpf_map * |
| 245 | bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset); |
| 246 | |
Wang Nan | 9d759a9 | 2015-11-27 08:47:35 +0000 | [diff] [blame] | 247 | struct bpf_map * |
| 248 | bpf_map__next(struct bpf_map *map, struct bpf_object *obj); |
| 249 | #define bpf_map__for_each(pos, obj) \ |
| 250 | for ((pos) = bpf_map__next(NULL, (obj)); \ |
| 251 | (pos) != NULL; \ |
| 252 | (pos) = bpf_map__next((pos), (obj))) |
| 253 | |
Arnaldo Carvalho de Melo | 6e009e6 | 2016-06-03 12:15:52 -0300 | [diff] [blame] | 254 | int bpf_map__fd(struct bpf_map *map); |
Arnaldo Carvalho de Melo | 53897a7 | 2016-06-02 14:21:06 -0300 | [diff] [blame] | 255 | const struct bpf_map_def *bpf_map__def(struct bpf_map *map); |
Arnaldo Carvalho de Melo | 009ad5d | 2016-06-02 11:02:05 -0300 | [diff] [blame] | 256 | const char *bpf_map__name(struct bpf_map *map); |
Martin KaFai Lau | 61746db | 2018-05-22 15:04:24 -0700 | [diff] [blame] | 257 | uint32_t bpf_map__btf_key_type_id(const struct bpf_map *map); |
| 258 | uint32_t bpf_map__btf_value_type_id(const struct bpf_map *map); |
Wang Nan | 9d759a9 | 2015-11-27 08:47:35 +0000 | [diff] [blame] | 259 | |
| 260 | typedef void (*bpf_map_clear_priv_t)(struct bpf_map *, void *); |
Arnaldo Carvalho de Melo | edb13ed | 2016-06-03 12:38:21 -0300 | [diff] [blame] | 261 | int bpf_map__set_priv(struct bpf_map *map, void *priv, |
| 262 | bpf_map_clear_priv_t clear_priv); |
Arnaldo Carvalho de Melo | b4cbfa5 | 2016-06-02 10:51:59 -0300 | [diff] [blame] | 263 | void *bpf_map__priv(struct bpf_map *map); |
Jakub Kicinski | 26736eb | 2018-07-10 14:43:06 -0700 | [diff] [blame] | 264 | int bpf_map__reuse_fd(struct bpf_map *map, int fd); |
Jakub Kicinski | f83fb22 | 2018-07-10 14:43:01 -0700 | [diff] [blame] | 265 | bool bpf_map__is_offload_neutral(struct bpf_map *map); |
Jakub Kicinski | 9aba361 | 2018-06-28 14:41:37 -0700 | [diff] [blame] | 266 | void bpf_map__set_ifindex(struct bpf_map *map, __u32 ifindex); |
Joe Stringer | b6989f3 | 2017-01-26 13:19:57 -0800 | [diff] [blame] | 267 | int bpf_map__pin(struct bpf_map *map, const char *path); |
Wang Nan | 9d759a9 | 2015-11-27 08:47:35 +0000 | [diff] [blame] | 268 | |
Joe Stringer | e28ff1a | 2017-01-22 17:11:25 -0800 | [diff] [blame] | 269 | long libbpf_get_error(const void *ptr); |
| 270 | |
Andrey Ignatov | d7be143 | 2018-03-30 15:08:01 -0700 | [diff] [blame] | 271 | struct bpf_prog_load_attr { |
| 272 | const char *file; |
| 273 | enum bpf_prog_type prog_type; |
| 274 | enum bpf_attach_type expected_attach_type; |
David Beckett | f0307a7 | 2018-05-16 14:02:49 -0700 | [diff] [blame] | 275 | int ifindex; |
Andrey Ignatov | d7be143 | 2018-03-30 15:08:01 -0700 | [diff] [blame] | 276 | }; |
| 277 | |
| 278 | int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr, |
| 279 | struct bpf_object **pobj, int *prog_fd); |
John Fastabend | 6f6d33f | 2017-08-15 22:34:22 -0700 | [diff] [blame] | 280 | int bpf_prog_load(const char *file, enum bpf_prog_type type, |
| 281 | struct bpf_object **pobj, int *prog_fd); |
Eric Leblond | 949abbe | 2018-01-30 21:55:01 +0100 | [diff] [blame] | 282 | |
| 283 | int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags); |
Jakub Kicinski | d0cabbb | 2018-05-10 10:24:40 -0700 | [diff] [blame] | 284 | |
| 285 | enum bpf_perf_event_ret { |
| 286 | LIBBPF_PERF_EVENT_DONE = 0, |
| 287 | LIBBPF_PERF_EVENT_ERROR = -1, |
| 288 | LIBBPF_PERF_EVENT_CONT = -2, |
| 289 | }; |
| 290 | |
| 291 | typedef enum bpf_perf_event_ret (*bpf_perf_event_print_t)(void *event, |
| 292 | void *priv); |
| 293 | int bpf_perf_event_read_simple(void *mem, unsigned long size, |
| 294 | unsigned long page_size, |
| 295 | void **buf, size_t *buf_len, |
| 296 | bpf_perf_event_print_t fn, void *priv); |
Wang Nan | 1b76c13 | 2015-07-01 02:13:51 +0000 | [diff] [blame] | 297 | #endif |