bpf_elf.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __BPF_ELF__
  3. #define __BPF_ELF__
  4. #include <asm/types.h>
  5. /* Note:
  6. *
  7. * Below ELF section names and bpf_elf_map structure definition
  8. * are not (!) kernel ABI. It's rather a "contract" between the
  9. * application and the BPF loader in tc. For compatibility, the
  10. * section names should stay as-is. Introduction of aliases, if
  11. * needed, are a possibility, though.
  12. */
  13. /* ELF section names, etc */
  14. #define ELF_SECTION_LICENSE "license"
  15. #define ELF_SECTION_MAPS "maps"
  16. #define ELF_SECTION_PROG "prog"
  17. #define ELF_SECTION_CLASSIFIER "classifier"
  18. #define ELF_SECTION_ACTION "action"
  19. #define ELF_MAX_MAPS 64
  20. #define ELF_MAX_LICENSE_LEN 128
  21. /* Object pinning settings */
  22. #define PIN_NONE 0
  23. #define PIN_OBJECT_NS 1
  24. #define PIN_GLOBAL_NS 2
  25. /* ELF map definition */
  26. struct bpf_elf_map {
  27. __u32 type;
  28. __u32 size_key;
  29. __u32 size_value;
  30. __u32 max_elem;
  31. __u32 flags;
  32. __u32 id;
  33. __u32 pinning;
  34. __u32 inner_id;
  35. __u32 inner_idx;
  36. };
  37. #define BPF_ANNOTATE_KV_PAIR(name, type_key, type_val) \
  38. struct ____btf_map_##name { \
  39. type_key key; \
  40. type_val value; \
  41. }; \
  42. struct ____btf_map_##name \
  43. __attribute__ ((section(".maps." #name), used)) \
  44. ____btf_map_##name = { }
  45. #endif /* __BPF_ELF__ */