Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bpf_attr.h 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * Copyright (c) 2015-2018 Dmitry V. Levin <ldv@altlinux.org>
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: LGPL-2.1-or-later
  6. */
  7. #ifndef STRACE_BPF_ATTR_H
  8. # define STRACE_BPF_ATTR_H
  9. /*
  10. * The policy is that all fields of type uint64_t in this header file
  11. * must have ATTRIBUTE_ALIGNED(8).
  12. *
  13. * This should not cause any contradictions with <linux/bpf.h>
  14. * unless the latter is buggy.
  15. *
  16. * By word "buggy" I mean containing such changes as Linux kernel commit
  17. * v4.16-rc1~123^2~109^2~5^2~4.
  18. */
  19. # ifndef BPF_OBJ_NAME_LEN
  20. # define BPF_OBJ_NAME_LEN 16U
  21. # else
  22. # if BPF_OBJ_NAME_LEN != 16U
  23. # error "Unexpected value of BPF_OBJ_NAME_LEN"
  24. # endif
  25. # endif
  26. # ifndef BPF_TAG_SIZE
  27. # define BPF_TAG_SIZE 8
  28. # else
  29. # if BPF_TAG_SIZE != 8
  30. # error "Unexpected value of BPF_TAG_SIZE"
  31. # endif
  32. # endif
  33. struct BPF_MAP_CREATE_struct {
  34. uint32_t map_type;
  35. uint32_t key_size;
  36. uint32_t value_size;
  37. uint32_t max_entries;
  38. uint32_t map_flags;
  39. uint32_t inner_map_fd;
  40. uint32_t numa_node;
  41. char map_name[BPF_OBJ_NAME_LEN];
  42. uint32_t map_ifindex;
  43. };
  44. # define BPF_MAP_CREATE_struct_size \
  45. sizeof(struct BPF_MAP_CREATE_struct)
  46. # define expected_BPF_MAP_CREATE_struct_size 48
  47. struct BPF_MAP_LOOKUP_ELEM_struct {
  48. uint32_t map_fd;
  49. uint64_t ATTRIBUTE_ALIGNED(8) key;
  50. uint64_t ATTRIBUTE_ALIGNED(8) value;
  51. };
  52. # define BPF_MAP_LOOKUP_ELEM_struct_size \
  53. sizeof(struct BPF_MAP_LOOKUP_ELEM_struct)
  54. # define expected_BPF_MAP_LOOKUP_ELEM_struct_size 24
  55. struct BPF_MAP_UPDATE_ELEM_struct {
  56. uint32_t map_fd;
  57. uint64_t ATTRIBUTE_ALIGNED(8) key;
  58. uint64_t ATTRIBUTE_ALIGNED(8) value;
  59. uint64_t ATTRIBUTE_ALIGNED(8) flags;
  60. };
  61. # define BPF_MAP_UPDATE_ELEM_struct_size \
  62. sizeof(struct BPF_MAP_UPDATE_ELEM_struct)
  63. # define expected_BPF_MAP_UPDATE_ELEM_struct_size 32
  64. struct BPF_MAP_DELETE_ELEM_struct {
  65. uint32_t map_fd;
  66. uint64_t ATTRIBUTE_ALIGNED(8) key;
  67. };
  68. # define BPF_MAP_DELETE_ELEM_struct_size \
  69. sizeof(struct BPF_MAP_DELETE_ELEM_struct)
  70. # define expected_BPF_MAP_DELETE_ELEM_struct_size 16
  71. struct BPF_MAP_GET_NEXT_KEY_struct {
  72. uint32_t map_fd;
  73. uint64_t ATTRIBUTE_ALIGNED(8) key;
  74. uint64_t ATTRIBUTE_ALIGNED(8) next_key;
  75. };
  76. # define BPF_MAP_GET_NEXT_KEY_struct_size \
  77. sizeof(struct BPF_MAP_GET_NEXT_KEY_struct)
  78. # define expected_BPF_MAP_GET_NEXT_KEY_struct_size 24
  79. struct BPF_PROG_LOAD_struct {
  80. uint32_t prog_type;
  81. uint32_t insn_cnt;
  82. uint64_t ATTRIBUTE_ALIGNED(8) insns;
  83. uint64_t ATTRIBUTE_ALIGNED(8) license;
  84. uint32_t log_level;
  85. uint32_t log_size;
  86. uint64_t ATTRIBUTE_ALIGNED(8) log_buf;
  87. uint32_t kern_version;
  88. uint32_t prog_flags;
  89. char prog_name[BPF_OBJ_NAME_LEN];
  90. uint32_t prog_ifindex;
  91. uint32_t expected_attach_type;
  92. };
  93. # define BPF_PROG_LOAD_struct_size \
  94. offsetofend(struct BPF_PROG_LOAD_struct, expected_attach_type)
  95. # define expected_BPF_PROG_LOAD_struct_size 72
  96. struct BPF_OBJ_PIN_struct {
  97. uint64_t ATTRIBUTE_ALIGNED(8) pathname;
  98. uint32_t bpf_fd;
  99. uint32_t file_flags;
  100. };
  101. # define BPF_OBJ_PIN_struct_size \
  102. sizeof(struct BPF_OBJ_PIN_struct)
  103. # define expected_BPF_OBJ_PIN_struct_size 16
  104. # define BPF_OBJ_GET_struct BPF_OBJ_PIN_struct
  105. # define BPF_OBJ_GET_struct_size BPF_OBJ_PIN_struct_size
  106. struct BPF_PROG_ATTACH_struct {
  107. uint32_t target_fd;
  108. uint32_t attach_bpf_fd;
  109. uint32_t attach_type;
  110. uint32_t attach_flags;
  111. };
  112. # define BPF_PROG_ATTACH_struct_size \
  113. sizeof(struct BPF_PROG_ATTACH_struct)
  114. # define expected_BPF_PROG_ATTACH_struct_size 16
  115. struct BPF_PROG_DETACH_struct {
  116. uint32_t target_fd;
  117. uint32_t dummy;
  118. uint32_t attach_type;
  119. };
  120. # define BPF_PROG_DETACH_struct_size \
  121. sizeof(struct BPF_PROG_DETACH_struct)
  122. # define expected_BPF_PROG_DETACH_struct_size 12
  123. struct BPF_PROG_TEST_RUN_struct /* test */ {
  124. uint32_t prog_fd;
  125. uint32_t retval;
  126. uint32_t data_size_in;
  127. uint32_t data_size_out;
  128. uint64_t ATTRIBUTE_ALIGNED(8) data_in;
  129. uint64_t ATTRIBUTE_ALIGNED(8) data_out;
  130. uint32_t repeat;
  131. uint32_t duration;
  132. };
  133. # define BPF_PROG_TEST_RUN_struct_size \
  134. sizeof(struct BPF_PROG_TEST_RUN_struct)
  135. # define expected_BPF_PROG_TEST_RUN_struct_size 40
  136. struct BPF_PROG_GET_NEXT_ID_struct {
  137. uint32_t start_id;
  138. uint32_t next_id;
  139. uint32_t open_flags;
  140. };
  141. # define BPF_PROG_GET_NEXT_ID_struct_size \
  142. sizeof(struct BPF_PROG_GET_NEXT_ID_struct)
  143. # define expected_BPF_PROG_GET_NEXT_ID_struct_size 12
  144. # define BPF_MAP_GET_NEXT_ID_struct BPF_PROG_GET_NEXT_ID_struct
  145. # define BPF_MAP_GET_NEXT_ID_struct_size BPF_PROG_GET_NEXT_ID_struct_size
  146. struct BPF_PROG_GET_FD_BY_ID_struct {
  147. uint32_t prog_id;
  148. uint32_t next_id;
  149. uint32_t open_flags;
  150. };
  151. # define BPF_PROG_GET_FD_BY_ID_struct_size \
  152. sizeof(struct BPF_PROG_GET_FD_BY_ID_struct)
  153. # define expected_BPF_PROG_GET_FD_BY_ID_struct_size 12
  154. struct BPF_MAP_GET_FD_BY_ID_struct {
  155. uint32_t map_id;
  156. uint32_t next_id;
  157. uint32_t open_flags;
  158. };
  159. # define BPF_MAP_GET_FD_BY_ID_struct_size \
  160. sizeof(struct BPF_MAP_GET_FD_BY_ID_struct)
  161. # define expected_BPF_MAP_GET_FD_BY_ID_struct_size 12
  162. struct BPF_OBJ_GET_INFO_BY_FD_struct /* info */ {
  163. uint32_t bpf_fd;
  164. uint32_t info_len;
  165. uint64_t ATTRIBUTE_ALIGNED(8) info;
  166. };
  167. # define BPF_OBJ_GET_INFO_BY_FD_struct_size \
  168. sizeof(struct BPF_OBJ_GET_INFO_BY_FD_struct)
  169. # define expected_BPF_OBJ_GET_INFO_BY_FD_struct_size 16
  170. struct BPF_PROG_QUERY_struct /* query */ {
  171. uint32_t target_fd;
  172. uint32_t attach_type;
  173. uint32_t query_flags;
  174. uint32_t attach_flags;
  175. uint64_t ATTRIBUTE_ALIGNED(8) prog_ids;
  176. uint32_t prog_cnt;
  177. };
  178. # define BPF_PROG_QUERY_struct_size \
  179. offsetofend(struct BPF_PROG_QUERY_struct, prog_cnt)
  180. # define expected_BPF_PROG_QUERY_struct_size 28
  181. struct BPF_RAW_TRACEPOINT_OPEN_struct /* raw_tracepoint */ {
  182. uint64_t ATTRIBUTE_ALIGNED(8) name;
  183. uint32_t prog_fd;
  184. };
  185. # define BPF_RAW_TRACEPOINT_OPEN_struct_size \
  186. offsetofend(struct BPF_RAW_TRACEPOINT_OPEN_struct, prog_fd)
  187. # define expected_BPF_RAW_TRACEPOINT_OPEN_struct_size 12
  188. struct bpf_map_info_struct {
  189. uint32_t type;
  190. uint32_t id;
  191. uint32_t key_size;
  192. uint32_t value_size;
  193. uint32_t max_entries;
  194. uint32_t map_flags;
  195. char name[BPF_OBJ_NAME_LEN];
  196. uint32_t ifindex;
  197. /*
  198. * The kernel UAPI is broken by Linux commit
  199. * v4.16-rc1~123^2~109^2~5^2~4 .
  200. */
  201. uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
  202. uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
  203. };
  204. # define bpf_map_info_struct_size \
  205. sizeof(struct bpf_map_info_struct)
  206. # define expected_bpf_map_info_struct_size 64
  207. struct bpf_prog_info_struct {
  208. uint32_t type;
  209. uint32_t id;
  210. uint8_t tag[BPF_TAG_SIZE];
  211. uint32_t jited_prog_len;
  212. uint32_t xlated_prog_len;
  213. uint64_t ATTRIBUTE_ALIGNED(8) jited_prog_insns;
  214. uint64_t ATTRIBUTE_ALIGNED(8) xlated_prog_insns;
  215. uint64_t ATTRIBUTE_ALIGNED(8) load_time;
  216. uint32_t created_by_uid;
  217. uint32_t nr_map_ids;
  218. uint64_t ATTRIBUTE_ALIGNED(8) map_ids;
  219. char name[BPF_OBJ_NAME_LEN];
  220. uint32_t ifindex;
  221. /*
  222. * The kernel UAPI is broken by Linux commit
  223. * v4.16-rc1~123^2~227^2~5^2~2 .
  224. */
  225. uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
  226. uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
  227. };
  228. # define bpf_prog_info_struct_size \
  229. sizeof(struct bpf_prog_info_struct)
  230. # define expected_bpf_prog_info_struct_size 104
  231. #endif /* !STRACE_BPF_ATTR_H */