Blame view

samples/bpf/bpf_load.h 1.64 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
249b812d8   Alexei Starovoitov   samples: bpf: elf...
2
3
  #ifndef __BPF_LOAD_H
  #define __BPF_LOAD_H
d40fc181e   Joe Stringer   samples/bpf: Make...
4
  #include "libbpf.h"
249b812d8   Alexei Starovoitov   samples: bpf: elf...
5
6
  #define MAX_MAPS 32
  #define MAX_PROGS 32
9fd63d05f   Martin KaFai Lau   bpf: Allow bpf sa...
7
8
9
10
11
12
13
  struct bpf_map_def {
  	unsigned int type;
  	unsigned int key_size;
  	unsigned int value_size;
  	unsigned int max_entries;
  	unsigned int map_flags;
  	unsigned int inner_map_idx;
ad17d0e6c   Martin KaFai Lau   bpf: Allow numa s...
14
  	unsigned int numa_node;
9fd63d05f   Martin KaFai Lau   bpf: Allow bpf sa...
15
  };
6979bcc73   Jesper Dangaard Brouer   samples/bpf: load...
16
17
18
19
20
21
22
23
  struct bpf_map_data {
  	int fd;
  	char *name;
  	size_t elf_offset;
  	struct bpf_map_def def;
  };
  
  typedef void (*fixup_map_cb)(struct bpf_map_data *map, int idx);
9fd63d05f   Martin KaFai Lau   bpf: Allow bpf sa...
24

249b812d8   Alexei Starovoitov   samples: bpf: elf...
25
  extern int prog_fd[MAX_PROGS];
b896c4f95   Alexei Starovoitov   samples/bpf: Add ...
26
  extern int event_fd[MAX_PROGS];
d40fc181e   Joe Stringer   samples/bpf: Make...
27
  extern char bpf_log_buf[BPF_LOG_BUF_SIZE];
4f2e7ae56   David Ahern   samples/bpf: Upda...
28
  extern int prog_cnt;
249b812d8   Alexei Starovoitov   samples: bpf: elf...
29

9178b4c17   Jesper Dangaard Brouer   samples/bpf: expo...
30
31
32
33
34
35
  /* There is a one-to-one mapping between map_fd[] and map_data[].
   * The map_data[] just contains more rich info on the given map.
   */
  extern int map_fd[MAX_MAPS];
  extern struct bpf_map_data map_data[MAX_MAPS];
  extern int map_data_count;
249b812d8   Alexei Starovoitov   samples: bpf: elf...
36
37
38
39
40
41
42
43
44
45
46
47
48
  /* parses elf file compiled by llvm .c->.o
   * . parses 'maps' section and creates maps via BPF syscall
   * . parses 'license' section and passes it to syscall
   * . parses elf relocations for BPF maps and adjusts BPF_LD_IMM64 insns by
   *   storing map_fd into insn->imm and marking such insns as BPF_PSEUDO_MAP_FD
   * . loads eBPF programs via BPF syscall
   *
   * One ELF file can contain multiple BPF programs which will be loaded
   * and their FDs stored stored in prog_fd array
   *
   * returns zero on success
   */
  int load_bpf_file(char *path);
9fd63d05f   Martin KaFai Lau   bpf: Allow bpf sa...
49
  int load_bpf_file_fixup_map(const char *path, fixup_map_cb fixup_map);
249b812d8   Alexei Starovoitov   samples: bpf: elf...
50

b896c4f95   Alexei Starovoitov   samples/bpf: Add ...
51
  void read_trace_pipe(void);
3622e7e49   Alexei Starovoitov   samples/bpf: move...
52
53
54
55
  struct ksym {
  	long addr;
  	char *name;
  };
b896c4f95   Alexei Starovoitov   samples/bpf: Add ...
56

3622e7e49   Alexei Starovoitov   samples/bpf: move...
57
58
  int load_kallsyms(void);
  struct ksym *ksym_search(long key);
6387d0111   Jesper Dangaard Brouer   samples/bpf: fix ...
59
  int set_link_xdp_fd(int ifindex, int fd, __u32 flags);
249b812d8   Alexei Starovoitov   samples: bpf: elf...
60
  #endif