blob: 814894a129745a2c699665adf6b9c07513b9b0aa [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Alexei Starovoitov249b8122014-12-01 15:06:37 -08002#ifndef __BPF_LOAD_H
3#define __BPF_LOAD_H
4
Jakub Kicinski2bf3e2e2018-05-14 22:35:02 -07005#include <bpf/bpf.h>
Joe Stringerd40fc182016-12-14 14:43:38 -08006
Alexei Starovoitov249b8122014-12-01 15:06:37 -08007#define MAX_MAPS 32
8#define MAX_PROGS 32
9
Jakub Kicinski74662ea2018-05-10 10:24:38 -070010struct bpf_load_map_def {
Martin KaFai Lau9fd63d02017-04-14 10:30:28 -070011 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 Lauad17d0e2017-08-18 11:28:01 -070017 unsigned int numa_node;
Martin KaFai Lau9fd63d02017-04-14 10:30:28 -070018};
19
Jesper Dangaard Brouer6979bcc2017-05-02 14:32:01 +020020struct bpf_map_data {
21 int fd;
22 char *name;
23 size_t elf_offset;
Jakub Kicinski74662ea2018-05-10 10:24:38 -070024 struct bpf_load_map_def def;
Jesper Dangaard Brouer6979bcc2017-05-02 14:32:01 +020025};
26
27typedef void (*fixup_map_cb)(struct bpf_map_data *map, int idx);
Martin KaFai Lau9fd63d02017-04-14 10:30:28 -070028
Alexei Starovoitov249b8122014-12-01 15:06:37 -080029extern int prog_fd[MAX_PROGS];
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070030extern int event_fd[MAX_PROGS];
Joe Stringerd40fc182016-12-14 14:43:38 -080031extern char bpf_log_buf[BPF_LOG_BUF_SIZE];
David Ahern4f2e7ae2016-12-01 08:48:07 -080032extern int prog_cnt;
Alexei Starovoitov249b8122014-12-01 15:06:37 -080033
Jesper Dangaard Brouer9178b4c2017-05-02 14:32:06 +020034/* 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 */
37extern int map_fd[MAX_MAPS];
38extern struct bpf_map_data map_data[MAX_MAPS];
39extern int map_data_count;
40
Alexei Starovoitov249b8122014-12-01 15:06:37 -080041/* 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 */
53int load_bpf_file(char *path);
Martin KaFai Lau9fd63d02017-04-14 10:30:28 -070054int load_bpf_file_fixup_map(const char *path, fixup_map_cb fixup_map);
Alexei Starovoitov249b8122014-12-01 15:06:37 -080055
Alexei Starovoitovb896c4f2015-03-25 12:49:23 -070056void read_trace_pipe(void);
Eric Leblondb259c2f2018-01-30 21:55:04 +010057int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags);
Alexei Starovoitov249b8122014-12-01 15:06:37 -080058#endif