1  /* SPDX-License-Identifier: GPL-2.0 */
2  #ifndef __BPF_LOAD_H
3  #define __BPF_LOAD_H
4  
5  #include <bpf/bpf.h>
6  
7  #define MAX_MAPS 32
8  #define MAX_PROGS 32
9  
10  struct bpf_load_map_def {
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;
17  	unsigned int numa_node;
18  };
19  
20  struct bpf_map_data {
21  	int fd;
22  	char *name;
23  	size_t elf_offset;
24  	struct bpf_load_map_def def;
25  };
26  
27  typedef void (*fixup_map_cb)(struct bpf_map_data *map, int idx);
28  
29  extern int prog_fd[MAX_PROGS];
30  extern int event_fd[MAX_PROGS];
31  extern char bpf_log_buf[BPF_LOG_BUF_SIZE];
32  extern int prog_cnt;
33  
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  
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);
54  int load_bpf_file_fixup_map(const char *path, fixup_map_cb fixup_map);
55  
56  void read_trace_pipe(void);
57  int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags);
58  #endif
59