Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Alexei Starovoitov | 249b812 | 2014-12-01 15:06:37 -0800 | [diff] [blame] | 2 | #ifndef __BPF_LOAD_H |
| 3 | #define __BPF_LOAD_H |
| 4 | |
Jakub Kicinski | 2bf3e2e | 2018-05-14 22:35:02 -0700 | [diff] [blame] | 5 | #include <bpf/bpf.h> |
Joe Stringer | d40fc18 | 2016-12-14 14:43:38 -0800 | [diff] [blame] | 6 | |
Alexei Starovoitov | 249b812 | 2014-12-01 15:06:37 -0800 | [diff] [blame] | 7 | #define MAX_MAPS 32 |
| 8 | #define MAX_PROGS 32 |
| 9 | |
Jakub Kicinski | 74662ea | 2018-05-10 10:24:38 -0700 | [diff] [blame] | 10 | struct bpf_load_map_def { |
Martin KaFai Lau | 9fd63d0 | 2017-04-14 10:30:28 -0700 | [diff] [blame] | 11 | unsigned int type; |
| 12 | unsigned int key_size; |
| 13 | unsigned int value_size; |
| 14 | unsigned int max_entries; |
| 15 | unsigned int map_flags; |
| 16 | unsigned int inner_map_idx; |
Martin KaFai Lau | ad17d0e | 2017-08-18 11:28:01 -0700 | [diff] [blame] | 17 | unsigned int numa_node; |
Martin KaFai Lau | 9fd63d0 | 2017-04-14 10:30:28 -0700 | [diff] [blame] | 18 | }; |
| 19 | |
Jesper Dangaard Brouer | 6979bcc | 2017-05-02 14:32:01 +0200 | [diff] [blame] | 20 | struct bpf_map_data { |
| 21 | int fd; |
| 22 | char *name; |
| 23 | size_t elf_offset; |
Jakub Kicinski | 74662ea | 2018-05-10 10:24:38 -0700 | [diff] [blame] | 24 | struct bpf_load_map_def def; |
Jesper Dangaard Brouer | 6979bcc | 2017-05-02 14:32:01 +0200 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | typedef void (*fixup_map_cb)(struct bpf_map_data *map, int idx); |
Martin KaFai Lau | 9fd63d0 | 2017-04-14 10:30:28 -0700 | [diff] [blame] | 28 | |
Alexei Starovoitov | 249b812 | 2014-12-01 15:06:37 -0800 | [diff] [blame] | 29 | extern int prog_fd[MAX_PROGS]; |
Alexei Starovoitov | b896c4f | 2015-03-25 12:49:23 -0700 | [diff] [blame] | 30 | extern int event_fd[MAX_PROGS]; |
Joe Stringer | d40fc18 | 2016-12-14 14:43:38 -0800 | [diff] [blame] | 31 | extern char bpf_log_buf[BPF_LOG_BUF_SIZE]; |
David Ahern | 4f2e7ae | 2016-12-01 08:48:07 -0800 | [diff] [blame] | 32 | extern int prog_cnt; |
Alexei Starovoitov | 249b812 | 2014-12-01 15:06:37 -0800 | [diff] [blame] | 33 | |
Jesper Dangaard Brouer | 9178b4c | 2017-05-02 14:32:06 +0200 | [diff] [blame] | 34 | /* There is a one-to-one mapping between map_fd[] and map_data[]. |
| 35 | * The map_data[] just contains more rich info on the given map. |
| 36 | */ |
| 37 | extern int map_fd[MAX_MAPS]; |
| 38 | extern struct bpf_map_data map_data[MAX_MAPS]; |
| 39 | extern int map_data_count; |
| 40 | |
Alexei Starovoitov | 249b812 | 2014-12-01 15:06:37 -0800 | [diff] [blame] | 41 | /* parses elf file compiled by llvm .c->.o |
| 42 | * . parses 'maps' section and creates maps via BPF syscall |
| 43 | * . parses 'license' section and passes it to syscall |
| 44 | * . parses elf relocations for BPF maps and adjusts BPF_LD_IMM64 insns by |
| 45 | * storing map_fd into insn->imm and marking such insns as BPF_PSEUDO_MAP_FD |
| 46 | * . loads eBPF programs via BPF syscall |
| 47 | * |
| 48 | * One ELF file can contain multiple BPF programs which will be loaded |
| 49 | * and their FDs stored stored in prog_fd array |
| 50 | * |
| 51 | * returns zero on success |
| 52 | */ |
| 53 | int load_bpf_file(char *path); |
Martin KaFai Lau | 9fd63d0 | 2017-04-14 10:30:28 -0700 | [diff] [blame] | 54 | int load_bpf_file_fixup_map(const char *path, fixup_map_cb fixup_map); |
Alexei Starovoitov | 249b812 | 2014-12-01 15:06:37 -0800 | [diff] [blame] | 55 | |
Alexei Starovoitov | b896c4f | 2015-03-25 12:49:23 -0700 | [diff] [blame] | 56 | void read_trace_pipe(void); |
Eric Leblond | b259c2f | 2018-01-30 21:55:04 +0100 | [diff] [blame] | 57 | int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags); |
Alexei Starovoitov | 249b812 | 2014-12-01 15:06:37 -0800 | [diff] [blame] | 58 | #endif |