bpf.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
  2. *
  3. * This program is free software; you can redistribute it and/or
  4. * modify it under the terms of version 2 of the GNU General Public
  5. * License as published by the Free Software Foundation.
  6. */
  7. #ifndef __LINUX_BPF_H__
  8. #define __LINUX_BPF_H__
  9. #include <linux/types.h>
  10. #include <linux/bpf_common.h>
  11. /* Extended instruction set based on top of classic BPF */
  12. /* instruction classes */
  13. #define BPF_ALU64 0x07 /* alu mode in double word width */
  14. /* ld/ldx fields */
  15. #define BPF_DW 0x18 /* double word */
  16. #define BPF_XADD 0xc0 /* exclusive add */
  17. /* alu/jmp fields */
  18. #define BPF_MOV 0xb0 /* mov reg to reg */
  19. #define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */
  20. /* change endianness of a register */
  21. #define BPF_END 0xd0 /* flags for endianness conversion: */
  22. #define BPF_TO_LE 0x00 /* convert to little-endian */
  23. #define BPF_TO_BE 0x08 /* convert to big-endian */
  24. #define BPF_FROM_LE BPF_TO_LE
  25. #define BPF_FROM_BE BPF_TO_BE
  26. #define BPF_JNE 0x50 /* jump != */
  27. #define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */
  28. #define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */
  29. #define BPF_CALL 0x80 /* function call */
  30. #define BPF_EXIT 0x90 /* function return */
  31. /* Register numbers */
  32. enum {
  33. BPF_REG_0 = 0,
  34. BPF_REG_1,
  35. BPF_REG_2,
  36. BPF_REG_3,
  37. BPF_REG_4,
  38. BPF_REG_5,
  39. BPF_REG_6,
  40. BPF_REG_7,
  41. BPF_REG_8,
  42. BPF_REG_9,
  43. BPF_REG_10,
  44. __MAX_BPF_REG,
  45. };
  46. /* BPF has 10 general purpose 64-bit registers and stack frame. */
  47. #define MAX_BPF_REG __MAX_BPF_REG
  48. struct bpf_insn {
  49. __u8 code; /* opcode */
  50. __u8 dst_reg:4; /* dest register */
  51. __u8 src_reg:4; /* source register */
  52. __s16 off; /* signed offset */
  53. __s32 imm; /* signed immediate constant */
  54. };
  55. /* BPF syscall commands, see bpf(2) man-page for details. */
  56. enum bpf_cmd {
  57. BPF_MAP_CREATE,
  58. BPF_MAP_LOOKUP_ELEM,
  59. BPF_MAP_UPDATE_ELEM,
  60. BPF_MAP_DELETE_ELEM,
  61. BPF_MAP_GET_NEXT_KEY,
  62. BPF_PROG_LOAD,
  63. BPF_OBJ_PIN,
  64. BPF_OBJ_GET,
  65. BPF_PROG_ATTACH,
  66. BPF_PROG_DETACH,
  67. };
  68. enum bpf_map_type {
  69. BPF_MAP_TYPE_UNSPEC,
  70. BPF_MAP_TYPE_HASH,
  71. BPF_MAP_TYPE_ARRAY,
  72. BPF_MAP_TYPE_PROG_ARRAY,
  73. BPF_MAP_TYPE_PERF_EVENT_ARRAY,
  74. BPF_MAP_TYPE_PERCPU_HASH,
  75. BPF_MAP_TYPE_PERCPU_ARRAY,
  76. BPF_MAP_TYPE_STACK_TRACE,
  77. BPF_MAP_TYPE_CGROUP_ARRAY,
  78. BPF_MAP_TYPE_LRU_HASH,
  79. BPF_MAP_TYPE_LRU_PERCPU_HASH,
  80. };
  81. enum bpf_prog_type {
  82. BPF_PROG_TYPE_UNSPEC,
  83. BPF_PROG_TYPE_SOCKET_FILTER,
  84. BPF_PROG_TYPE_KPROBE,
  85. BPF_PROG_TYPE_SCHED_CLS,
  86. BPF_PROG_TYPE_SCHED_ACT,
  87. BPF_PROG_TYPE_TRACEPOINT,
  88. BPF_PROG_TYPE_XDP,
  89. BPF_PROG_TYPE_PERF_EVENT,
  90. BPF_PROG_TYPE_CGROUP_SKB,
  91. BPF_PROG_TYPE_CGROUP_SOCK,
  92. BPF_PROG_TYPE_LWT_IN,
  93. BPF_PROG_TYPE_LWT_OUT,
  94. BPF_PROG_TYPE_LWT_XMIT,
  95. };
  96. enum bpf_attach_type {
  97. BPF_CGROUP_INET_INGRESS,
  98. BPF_CGROUP_INET_EGRESS,
  99. BPF_CGROUP_INET_SOCK_CREATE,
  100. __MAX_BPF_ATTACH_TYPE
  101. };
  102. #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
  103. /* If BPF_F_ALLOW_OVERRIDE flag is used in BPF_PROG_ATTACH command
  104. * to the given target_fd cgroup the descendent cgroup will be able to
  105. * override effective bpf program that was inherited from this cgroup
  106. */
  107. #define BPF_F_ALLOW_OVERRIDE (1U << 0)
  108. #define BPF_PSEUDO_MAP_FD 1
  109. /* flags for BPF_MAP_UPDATE_ELEM command */
  110. #define BPF_ANY 0 /* create new element or update existing */
  111. #define BPF_NOEXIST 1 /* create new element if it didn't exist */
  112. #define BPF_EXIST 2 /* update existing element */
  113. #define BPF_F_NO_PREALLOC (1U << 0)
  114. /* Instead of having one common LRU list in the
  115. * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list
  116. * which can scale and perform better.
  117. * Note, the LRU nodes (including free nodes) cannot be moved
  118. * across different LRU lists.
  119. */
  120. #define BPF_F_NO_COMMON_LRU (1U << 1)
  121. union bpf_attr {
  122. struct { /* anonymous struct used by BPF_MAP_CREATE command */
  123. __u32 map_type; /* one of enum bpf_map_type */
  124. __u32 key_size; /* size of key in bytes */
  125. __u32 value_size; /* size of value in bytes */
  126. __u32 max_entries; /* max number of entries in a map */
  127. __u32 map_flags; /* prealloc or not */
  128. };
  129. struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
  130. __u32 map_fd;
  131. __aligned_u64 key;
  132. union {
  133. __aligned_u64 value;
  134. __aligned_u64 next_key;
  135. };
  136. __u64 flags;
  137. };
  138. struct { /* anonymous struct used by BPF_PROG_LOAD command */
  139. __u32 prog_type; /* one of enum bpf_prog_type */
  140. __u32 insn_cnt;
  141. __aligned_u64 insns;
  142. __aligned_u64 license;
  143. __u32 log_level; /* verbosity level of verifier */
  144. __u32 log_size; /* size of user buffer */
  145. __aligned_u64 log_buf; /* user supplied buffer */
  146. __u32 kern_version; /* checked when prog_type=kprobe */
  147. };
  148. struct { /* anonymous struct used by BPF_OBJ_* commands */
  149. __aligned_u64 pathname;
  150. __u32 bpf_fd;
  151. };
  152. struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
  153. __u32 target_fd; /* container object to attach to */
  154. __u32 attach_bpf_fd; /* eBPF program to attach */
  155. __u32 attach_type;
  156. __u32 attach_flags;
  157. };
  158. } __attribute__((aligned(8)));
  159. /* BPF helper function descriptions:
  160. *
  161. * void *bpf_map_lookup_elem(&map, &key)
  162. * Return: Map value or NULL
  163. *
  164. * int bpf_map_update_elem(&map, &key, &value, flags)
  165. * Return: 0 on success or negative error
  166. *
  167. * int bpf_map_delete_elem(&map, &key)
  168. * Return: 0 on success or negative error
  169. *
  170. * int bpf_probe_read(void *dst, int size, void *src)
  171. * Return: 0 on success or negative error
  172. *
  173. * u64 bpf_ktime_get_ns(void)
  174. * Return: current ktime
  175. *
  176. * int bpf_trace_printk(const char *fmt, int fmt_size, ...)
  177. * Return: length of buffer written or negative error
  178. *
  179. * u32 bpf_prandom_u32(void)
  180. * Return: random value
  181. *
  182. * u32 bpf_raw_smp_processor_id(void)
  183. * Return: SMP processor ID
  184. *
  185. * int bpf_skb_store_bytes(skb, offset, from, len, flags)
  186. * store bytes into packet
  187. * @skb: pointer to skb
  188. * @offset: offset within packet from skb->mac_header
  189. * @from: pointer where to copy bytes from
  190. * @len: number of bytes to store into packet
  191. * @flags: bit 0 - if true, recompute skb->csum
  192. * other bits - reserved
  193. * Return: 0 on success or negative error
  194. *
  195. * int bpf_l3_csum_replace(skb, offset, from, to, flags)
  196. * recompute IP checksum
  197. * @skb: pointer to skb
  198. * @offset: offset within packet where IP checksum is located
  199. * @from: old value of header field
  200. * @to: new value of header field
  201. * @flags: bits 0-3 - size of header field
  202. * other bits - reserved
  203. * Return: 0 on success or negative error
  204. *
  205. * int bpf_l4_csum_replace(skb, offset, from, to, flags)
  206. * recompute TCP/UDP checksum
  207. * @skb: pointer to skb
  208. * @offset: offset within packet where TCP/UDP checksum is located
  209. * @from: old value of header field
  210. * @to: new value of header field
  211. * @flags: bits 0-3 - size of header field
  212. * bit 4 - is pseudo header
  213. * other bits - reserved
  214. * Return: 0 on success or negative error
  215. *
  216. * int bpf_tail_call(ctx, prog_array_map, index)
  217. * jump into another BPF program
  218. * @ctx: context pointer passed to next program
  219. * @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY
  220. * @index: index inside array that selects specific program to run
  221. * Return: 0 on success or negative error
  222. *
  223. * int bpf_clone_redirect(skb, ifindex, flags)
  224. * redirect to another netdev
  225. * @skb: pointer to skb
  226. * @ifindex: ifindex of the net device
  227. * @flags: bit 0 - if set, redirect to ingress instead of egress
  228. * other bits - reserved
  229. * Return: 0 on success or negative error
  230. *
  231. * u64 bpf_get_current_pid_tgid(void)
  232. * Return: current->tgid << 32 | current->pid
  233. *
  234. * u64 bpf_get_current_uid_gid(void)
  235. * Return: current_gid << 32 | current_uid
  236. *
  237. * int bpf_get_current_comm(char *buf, int size_of_buf)
  238. * stores current->comm into buf
  239. * Return: 0 on success or negative error
  240. *
  241. * u32 bpf_get_cgroup_classid(skb)
  242. * retrieve a proc's classid
  243. * @skb: pointer to skb
  244. * Return: classid if != 0
  245. *
  246. * int bpf_skb_vlan_push(skb, vlan_proto, vlan_tci)
  247. * Return: 0 on success or negative error
  248. *
  249. * int bpf_skb_vlan_pop(skb)
  250. * Return: 0 on success or negative error
  251. *
  252. * int bpf_skb_get_tunnel_key(skb, key, size, flags)
  253. * int bpf_skb_set_tunnel_key(skb, key, size, flags)
  254. * retrieve or populate tunnel metadata
  255. * @skb: pointer to skb
  256. * @key: pointer to 'struct bpf_tunnel_key'
  257. * @size: size of 'struct bpf_tunnel_key'
  258. * @flags: room for future extensions
  259. * Return: 0 on success or negative error
  260. *
  261. * u64 bpf_perf_event_read(&map, index)
  262. * Return: Number events read or error code
  263. *
  264. * int bpf_redirect(ifindex, flags)
  265. * redirect to another netdev
  266. * @ifindex: ifindex of the net device
  267. * @flags: bit 0 - if set, redirect to ingress instead of egress
  268. * other bits - reserved
  269. * Return: TC_ACT_REDIRECT
  270. *
  271. * u32 bpf_get_route_realm(skb)
  272. * retrieve a dst's tclassid
  273. * @skb: pointer to skb
  274. * Return: realm if != 0
  275. *
  276. * int bpf_perf_event_output(ctx, map, index, data, size)
  277. * output perf raw sample
  278. * @ctx: struct pt_regs*
  279. * @map: pointer to perf_event_array map
  280. * @index: index of event in the map
  281. * @data: data on stack to be output as raw data
  282. * @size: size of data
  283. * Return: 0 on success or negative error
  284. *
  285. * int bpf_get_stackid(ctx, map, flags)
  286. * walk user or kernel stack and return id
  287. * @ctx: struct pt_regs*
  288. * @map: pointer to stack_trace map
  289. * @flags: bits 0-7 - numer of stack frames to skip
  290. * bit 8 - collect user stack instead of kernel
  291. * bit 9 - compare stacks by hash only
  292. * bit 10 - if two different stacks hash into the same stackid
  293. * discard old
  294. * other bits - reserved
  295. * Return: >= 0 stackid on success or negative error
  296. *
  297. * s64 bpf_csum_diff(from, from_size, to, to_size, seed)
  298. * calculate csum diff
  299. * @from: raw from buffer
  300. * @from_size: length of from buffer
  301. * @to: raw to buffer
  302. * @to_size: length of to buffer
  303. * @seed: optional seed
  304. * Return: csum result or negative error code
  305. *
  306. * int bpf_skb_get_tunnel_opt(skb, opt, size)
  307. * retrieve tunnel options metadata
  308. * @skb: pointer to skb
  309. * @opt: pointer to raw tunnel option data
  310. * @size: size of @opt
  311. * Return: option size
  312. *
  313. * int bpf_skb_set_tunnel_opt(skb, opt, size)
  314. * populate tunnel options metadata
  315. * @skb: pointer to skb
  316. * @opt: pointer to raw tunnel option data
  317. * @size: size of @opt
  318. * Return: 0 on success or negative error
  319. *
  320. * int bpf_skb_change_proto(skb, proto, flags)
  321. * Change protocol of the skb. Currently supported is v4 -> v6,
  322. * v6 -> v4 transitions. The helper will also resize the skb. eBPF
  323. * program is expected to fill the new headers via skb_store_bytes
  324. * and lX_csum_replace.
  325. * @skb: pointer to skb
  326. * @proto: new skb->protocol type
  327. * @flags: reserved
  328. * Return: 0 on success or negative error
  329. *
  330. * int bpf_skb_change_type(skb, type)
  331. * Change packet type of skb.
  332. * @skb: pointer to skb
  333. * @type: new skb->pkt_type type
  334. * Return: 0 on success or negative error
  335. *
  336. * int bpf_skb_under_cgroup(skb, map, index)
  337. * Check cgroup2 membership of skb
  338. * @skb: pointer to skb
  339. * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
  340. * @index: index of the cgroup in the bpf_map
  341. * Return:
  342. * == 0 skb failed the cgroup2 descendant test
  343. * == 1 skb succeeded the cgroup2 descendant test
  344. * < 0 error
  345. *
  346. * u32 bpf_get_hash_recalc(skb)
  347. * Retrieve and possibly recalculate skb->hash.
  348. * @skb: pointer to skb
  349. * Return: hash
  350. *
  351. * u64 bpf_get_current_task(void)
  352. * Returns current task_struct
  353. * Return: current
  354. *
  355. * int bpf_probe_write_user(void *dst, void *src, int len)
  356. * safely attempt to write to a location
  357. * @dst: destination address in userspace
  358. * @src: source address on stack
  359. * @len: number of bytes to copy
  360. * Return: 0 on success or negative error
  361. *
  362. * int bpf_current_task_under_cgroup(map, index)
  363. * Check cgroup2 membership of current task
  364. * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
  365. * @index: index of the cgroup in the bpf_map
  366. * Return:
  367. * == 0 current failed the cgroup2 descendant test
  368. * == 1 current succeeded the cgroup2 descendant test
  369. * < 0 error
  370. *
  371. * int bpf_skb_change_tail(skb, len, flags)
  372. * The helper will resize the skb to the given new size, to be used f.e.
  373. * with control messages.
  374. * @skb: pointer to skb
  375. * @len: new skb length
  376. * @flags: reserved
  377. * Return: 0 on success or negative error
  378. *
  379. * int bpf_skb_pull_data(skb, len)
  380. * The helper will pull in non-linear data in case the skb is non-linear
  381. * and not all of len are part of the linear section. Only needed for
  382. * read/write with direct packet access.
  383. * @skb: pointer to skb
  384. * @len: len to make read/writeable
  385. * Return: 0 on success or negative error
  386. *
  387. * s64 bpf_csum_update(skb, csum)
  388. * Adds csum into skb->csum in case of CHECKSUM_COMPLETE.
  389. * @skb: pointer to skb
  390. * @csum: csum to add
  391. * Return: csum on success or negative error
  392. *
  393. * void bpf_set_hash_invalid(skb)
  394. * Invalidate current skb->hash.
  395. * @skb: pointer to skb
  396. *
  397. * int bpf_get_numa_node_id()
  398. * Return: Id of current NUMA node.
  399. *
  400. * int bpf_skb_change_head()
  401. * Grows headroom of skb and adjusts MAC header offset accordingly.
  402. * Will extends/reallocae as required automatically.
  403. * May change skb data pointer and will thus invalidate any check
  404. * performed for direct packet access.
  405. * @skb: pointer to skb
  406. * @len: length of header to be pushed in front
  407. * @flags: Flags (unused for now)
  408. * Return: 0 on success or negative error
  409. *
  410. * int bpf_xdp_adjust_head(xdp_md, delta)
  411. * Adjust the xdp_md.data by delta
  412. * @xdp_md: pointer to xdp_md
  413. * @delta: An positive/negative integer to be added to xdp_md.data
  414. * Return: 0 on success or negative on error
  415. */
  416. #define __BPF_FUNC_MAPPER(FN) \
  417. FN(unspec), \
  418. FN(map_lookup_elem), \
  419. FN(map_update_elem), \
  420. FN(map_delete_elem), \
  421. FN(probe_read), \
  422. FN(ktime_get_ns), \
  423. FN(trace_printk), \
  424. FN(get_prandom_u32), \
  425. FN(get_smp_processor_id), \
  426. FN(skb_store_bytes), \
  427. FN(l3_csum_replace), \
  428. FN(l4_csum_replace), \
  429. FN(tail_call), \
  430. FN(clone_redirect), \
  431. FN(get_current_pid_tgid), \
  432. FN(get_current_uid_gid), \
  433. FN(get_current_comm), \
  434. FN(get_cgroup_classid), \
  435. FN(skb_vlan_push), \
  436. FN(skb_vlan_pop), \
  437. FN(skb_get_tunnel_key), \
  438. FN(skb_set_tunnel_key), \
  439. FN(perf_event_read), \
  440. FN(redirect), \
  441. FN(get_route_realm), \
  442. FN(perf_event_output), \
  443. FN(skb_load_bytes), \
  444. FN(get_stackid), \
  445. FN(csum_diff), \
  446. FN(skb_get_tunnel_opt), \
  447. FN(skb_set_tunnel_opt), \
  448. FN(skb_change_proto), \
  449. FN(skb_change_type), \
  450. FN(skb_under_cgroup), \
  451. FN(get_hash_recalc), \
  452. FN(get_current_task), \
  453. FN(probe_write_user), \
  454. FN(current_task_under_cgroup), \
  455. FN(skb_change_tail), \
  456. FN(skb_pull_data), \
  457. FN(csum_update), \
  458. FN(set_hash_invalid), \
  459. FN(get_numa_node_id), \
  460. FN(skb_change_head), \
  461. FN(xdp_adjust_head),
  462. /* integer value in 'imm' field of BPF_CALL instruction selects which helper
  463. * function eBPF program intends to call
  464. */
  465. #define __BPF_ENUM_FN(x) BPF_FUNC_ ## x
  466. enum bpf_func_id {
  467. __BPF_FUNC_MAPPER(__BPF_ENUM_FN)
  468. __BPF_FUNC_MAX_ID,
  469. };
  470. #undef __BPF_ENUM_FN
  471. /* All flags used by eBPF helper functions, placed here. */
  472. /* BPF_FUNC_skb_store_bytes flags. */
  473. #define BPF_F_RECOMPUTE_CSUM (1ULL << 0)
  474. #define BPF_F_INVALIDATE_HASH (1ULL << 1)
  475. /* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
  476. * First 4 bits are for passing the header field size.
  477. */
  478. #define BPF_F_HDR_FIELD_MASK 0xfULL
  479. /* BPF_FUNC_l4_csum_replace flags. */
  480. #define BPF_F_PSEUDO_HDR (1ULL << 4)
  481. #define BPF_F_MARK_MANGLED_0 (1ULL << 5)
  482. /* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */
  483. #define BPF_F_INGRESS (1ULL << 0)
  484. /* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */
  485. #define BPF_F_TUNINFO_IPV6 (1ULL << 0)
  486. /* BPF_FUNC_get_stackid flags. */
  487. #define BPF_F_SKIP_FIELD_MASK 0xffULL
  488. #define BPF_F_USER_STACK (1ULL << 8)
  489. #define BPF_F_FAST_STACK_CMP (1ULL << 9)
  490. #define BPF_F_REUSE_STACKID (1ULL << 10)
  491. /* BPF_FUNC_skb_set_tunnel_key flags. */
  492. #define BPF_F_ZERO_CSUM_TX (1ULL << 1)
  493. #define BPF_F_DONT_FRAGMENT (1ULL << 2)
  494. /* BPF_FUNC_perf_event_output and BPF_FUNC_perf_event_read flags. */
  495. #define BPF_F_INDEX_MASK 0xffffffffULL
  496. #define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK
  497. /* BPF_FUNC_perf_event_output for sk_buff input context. */
  498. #define BPF_F_CTXLEN_MASK (0xfffffULL << 32)
  499. /* user accessible mirror of in-kernel sk_buff.
  500. * new fields can only be added to the end of this structure
  501. */
  502. struct __sk_buff {
  503. __u32 len;
  504. __u32 pkt_type;
  505. __u32 mark;
  506. __u32 queue_mapping;
  507. __u32 protocol;
  508. __u32 vlan_present;
  509. __u32 vlan_tci;
  510. __u32 vlan_proto;
  511. __u32 priority;
  512. __u32 ingress_ifindex;
  513. __u32 ifindex;
  514. __u32 tc_index;
  515. __u32 cb[5];
  516. __u32 hash;
  517. __u32 tc_classid;
  518. __u32 data;
  519. __u32 data_end;
  520. };
  521. struct bpf_tunnel_key {
  522. __u32 tunnel_id;
  523. union {
  524. __u32 remote_ipv4;
  525. __u32 remote_ipv6[4];
  526. };
  527. __u8 tunnel_tos;
  528. __u8 tunnel_ttl;
  529. __u16 tunnel_ext;
  530. __u32 tunnel_label;
  531. };
  532. /* Generic BPF return codes which all BPF program types may support.
  533. * The values are binary compatible with their TC_ACT_* counter-part to
  534. * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT
  535. * programs.
  536. *
  537. * XDP is handled seprately, see XDP_*.
  538. */
  539. enum bpf_ret_code {
  540. BPF_OK = 0,
  541. /* 1 reserved */
  542. BPF_DROP = 2,
  543. /* 3-6 reserved */
  544. BPF_REDIRECT = 7,
  545. /* >127 are reserved for prog type specific return codes */
  546. };
  547. struct bpf_sock {
  548. __u32 bound_dev_if;
  549. __u32 family;
  550. __u32 type;
  551. __u32 protocol;
  552. };
  553. #define XDP_PACKET_HEADROOM 256
  554. /* User return codes for XDP prog type.
  555. * A valid XDP program must return one of these defined values. All other
  556. * return codes are reserved for future use. Unknown return codes will result
  557. * in packet drop.
  558. */
  559. enum xdp_action {
  560. XDP_ABORTED = 0,
  561. XDP_DROP,
  562. XDP_PASS,
  563. XDP_TX,
  564. };
  565. /* user accessible metadata for XDP packet hook
  566. * new fields must be added to the end of this structure
  567. */
  568. struct xdp_md {
  569. __u32 data;
  570. __u32 data_end;
  571. };
  572. #endif /* __LINUX_BPF_H__ */