common.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // This is a compact version of `vmlinux.h` to be used in the examples using C code.
  2. #pragma once
  3. typedef unsigned char __u8;
  4. typedef short int __s16;
  5. typedef short unsigned int __u16;
  6. typedef int __s32;
  7. typedef unsigned int __u32;
  8. typedef long long int __s64;
  9. typedef long long unsigned int __u64;
  10. typedef __u8 u8;
  11. typedef __s16 s16;
  12. typedef __u16 u16;
  13. typedef __s32 s32;
  14. typedef __u32 u32;
  15. typedef __s64 s64;
  16. typedef __u64 u64;
  17. typedef __u16 __le16;
  18. typedef __u16 __be16;
  19. typedef __u32 __be32;
  20. typedef __u64 __be64;
  21. typedef __u32 __wsum;
  22. #include "bpf_helpers.h"
  23. enum bpf_map_type {
  24. BPF_MAP_TYPE_UNSPEC = 0,
  25. BPF_MAP_TYPE_HASH = 1,
  26. BPF_MAP_TYPE_ARRAY = 2,
  27. BPF_MAP_TYPE_PROG_ARRAY = 3,
  28. BPF_MAP_TYPE_PERF_EVENT_ARRAY = 4,
  29. BPF_MAP_TYPE_PERCPU_HASH = 5,
  30. BPF_MAP_TYPE_PERCPU_ARRAY = 6,
  31. BPF_MAP_TYPE_STACK_TRACE = 7,
  32. BPF_MAP_TYPE_CGROUP_ARRAY = 8,
  33. BPF_MAP_TYPE_LRU_HASH = 9,
  34. BPF_MAP_TYPE_LRU_PERCPU_HASH = 10,
  35. BPF_MAP_TYPE_LPM_TRIE = 11,
  36. BPF_MAP_TYPE_ARRAY_OF_MAPS = 12,
  37. BPF_MAP_TYPE_HASH_OF_MAPS = 13,
  38. BPF_MAP_TYPE_DEVMAP = 14,
  39. BPF_MAP_TYPE_SOCKMAP = 15,
  40. BPF_MAP_TYPE_CPUMAP = 16,
  41. BPF_MAP_TYPE_XSKMAP = 17,
  42. BPF_MAP_TYPE_SOCKHASH = 18,
  43. BPF_MAP_TYPE_CGROUP_STORAGE = 19,
  44. BPF_MAP_TYPE_REUSEPORT_SOCKARRAY = 20,
  45. BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE = 21,
  46. BPF_MAP_TYPE_QUEUE = 22,
  47. BPF_MAP_TYPE_STACK = 23,
  48. BPF_MAP_TYPE_SK_STORAGE = 24,
  49. BPF_MAP_TYPE_DEVMAP_HASH = 25,
  50. BPF_MAP_TYPE_STRUCT_OPS = 26,
  51. BPF_MAP_TYPE_RINGBUF = 27,
  52. BPF_MAP_TYPE_INODE_STORAGE = 28,
  53. };
  54. enum xdp_action {
  55. XDP_ABORTED = 0,
  56. XDP_DROP = 1,
  57. XDP_PASS = 2,
  58. XDP_TX = 3,
  59. XDP_REDIRECT = 4,
  60. };
  61. struct xdp_md {
  62. __u32 data;
  63. __u32 data_end;
  64. __u32 data_meta;
  65. __u32 ingress_ifindex;
  66. __u32 rx_queue_index;
  67. __u32 egress_ifindex;
  68. };
  69. typedef __u16 __sum16;
  70. #define ETH_P_IP 0x0800
  71. struct ethhdr {
  72. unsigned char h_dest[6];
  73. unsigned char h_source[6];
  74. __be16 h_proto;
  75. };
  76. struct iphdr {
  77. __u8 ihl: 4;
  78. __u8 version: 4;
  79. __u8 tos;
  80. __be16 tot_len;
  81. __be16 id;
  82. __be16 frag_off;
  83. __u8 ttl;
  84. __u8 protocol;
  85. __sum16 check;
  86. __be32 saddr;
  87. __be32 daddr;
  88. };
  89. enum {
  90. BPF_ANY = 0,
  91. BPF_NOEXIST = 1,
  92. BPF_EXIST = 2,
  93. BPF_F_LOCK = 4,
  94. };
  95. /* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
  96. * BPF_FUNC_perf_event_read_value flags.
  97. */
  98. #define BPF_F_INDEX_MASK 0xffffffffULL
  99. #define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK
  100. #if defined(__TARGET_ARCH_x86)
  101. struct pt_regs {
  102. /*
  103. * C ABI says these regs are callee-preserved. They aren't saved on kernel entry
  104. * unless syscall needs a complete, fully filled "struct pt_regs".
  105. */
  106. unsigned long r15;
  107. unsigned long r14;
  108. unsigned long r13;
  109. unsigned long r12;
  110. unsigned long rbp;
  111. unsigned long rbx;
  112. /* These regs are callee-clobbered. Always saved on kernel entry. */
  113. unsigned long r11;
  114. unsigned long r10;
  115. unsigned long r9;
  116. unsigned long r8;
  117. unsigned long rax;
  118. unsigned long rcx;
  119. unsigned long rdx;
  120. unsigned long rsi;
  121. unsigned long rdi;
  122. /*
  123. * On syscall entry, this is syscall#. On CPU exception, this is error code.
  124. * On hw interrupt, it's IRQ number:
  125. */
  126. unsigned long orig_rax;
  127. /* Return frame for iretq */
  128. unsigned long rip;
  129. unsigned long cs;
  130. unsigned long eflags;
  131. unsigned long rsp;
  132. unsigned long ss;
  133. /* top of stack page */
  134. };
  135. #endif /* __TARGET_ARCH_x86 */