bpf_load.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef __BPF_LOAD_H
  2. #define __BPF_LOAD_H
  3. #include "libbpf.h"
  4. #define MAX_MAPS 32
  5. #define MAX_PROGS 32
  6. struct bpf_map_def {
  7. unsigned int type;
  8. unsigned int key_size;
  9. unsigned int value_size;
  10. unsigned int max_entries;
  11. unsigned int map_flags;
  12. unsigned int inner_map_idx;
  13. };
  14. struct bpf_map_data {
  15. int fd;
  16. char *name;
  17. size_t elf_offset;
  18. struct bpf_map_def def;
  19. };
  20. typedef void (*fixup_map_cb)(struct bpf_map_data *map, int idx);
  21. extern int prog_fd[MAX_PROGS];
  22. extern int event_fd[MAX_PROGS];
  23. extern char bpf_log_buf[BPF_LOG_BUF_SIZE];
  24. extern int prog_cnt;
  25. /* There is a one-to-one mapping between map_fd[] and map_data[].
  26. * The map_data[] just contains more rich info on the given map.
  27. */
  28. extern int map_fd[MAX_MAPS];
  29. extern struct bpf_map_data map_data[MAX_MAPS];
  30. extern int map_data_count;
  31. /* parses elf file compiled by llvm .c->.o
  32. * . parses 'maps' section and creates maps via BPF syscall
  33. * . parses 'license' section and passes it to syscall
  34. * . parses elf relocations for BPF maps and adjusts BPF_LD_IMM64 insns by
  35. * storing map_fd into insn->imm and marking such insns as BPF_PSEUDO_MAP_FD
  36. * . loads eBPF programs via BPF syscall
  37. *
  38. * One ELF file can contain multiple BPF programs which will be loaded
  39. * and their FDs stored stored in prog_fd array
  40. *
  41. * returns zero on success
  42. */
  43. int load_bpf_file(char *path);
  44. int load_bpf_file_fixup_map(const char *path, fixup_map_cb fixup_map);
  45. void read_trace_pipe(void);
  46. struct ksym {
  47. long addr;
  48. char *name;
  49. };
  50. int load_kallsyms(void);
  51. struct ksym *ksym_search(long key);
  52. int set_link_xdp_fd(int ifindex, int fd, __u32 flags);
  53. #endif