bpf.h 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of version 2 of the GNU General Public
  6. * License as published by the Free Software Foundation.
  7. */
  8. #ifndef _UAPI__LINUX_BPF_H__
  9. #define _UAPI__LINUX_BPF_H__
  10. #include <linux/types.h>
  11. #include <linux/bpf_common.h>
  12. /* Extended instruction set based on top of classic BPF */
  13. /* instruction classes */
  14. #define BPF_ALU64 0x07 /* alu mode in double word width */
  15. /* ld/ldx fields */
  16. #define BPF_DW 0x18 /* double word (64-bit) */
  17. #define BPF_XADD 0xc0 /* exclusive add */
  18. /* alu/jmp fields */
  19. #define BPF_MOV 0xb0 /* mov reg to reg */
  20. #define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */
  21. /* change endianness of a register */
  22. #define BPF_END 0xd0 /* flags for endianness conversion: */
  23. #define BPF_TO_LE 0x00 /* convert to little-endian */
  24. #define BPF_TO_BE 0x08 /* convert to big-endian */
  25. #define BPF_FROM_LE BPF_TO_LE
  26. #define BPF_FROM_BE BPF_TO_BE
  27. /* jmp encodings */
  28. #define BPF_JNE 0x50 /* jump != */
  29. #define BPF_JLT 0xa0 /* LT is unsigned, '<' */
  30. #define BPF_JLE 0xb0 /* LE is unsigned, '<=' */
  31. #define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */
  32. #define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */
  33. #define BPF_JSLT 0xc0 /* SLT is signed, '<' */
  34. #define BPF_JSLE 0xd0 /* SLE is signed, '<=' */
  35. #define BPF_CALL 0x80 /* function call */
  36. #define BPF_EXIT 0x90 /* function return */
  37. /* Register numbers */
  38. enum {
  39. BPF_REG_0 = 0,
  40. BPF_REG_1,
  41. BPF_REG_2,
  42. BPF_REG_3,
  43. BPF_REG_4,
  44. BPF_REG_5,
  45. BPF_REG_6,
  46. BPF_REG_7,
  47. BPF_REG_8,
  48. BPF_REG_9,
  49. BPF_REG_10,
  50. __MAX_BPF_REG,
  51. };
  52. /* BPF has 10 general purpose 64-bit registers and stack frame. */
  53. #define MAX_BPF_REG __MAX_BPF_REG
  54. struct bpf_insn {
  55. __u8 code; /* opcode */
  56. __u8 dst_reg:4; /* dest register */
  57. __u8 src_reg:4; /* source register */
  58. __s16 off; /* signed offset */
  59. __s32 imm; /* signed immediate constant */
  60. };
  61. /* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */
  62. struct bpf_lpm_trie_key {
  63. __u32 prefixlen; /* up to 32 for AF_INET, 128 for AF_INET6 */
  64. __u8 data[0]; /* Arbitrary size */
  65. };
  66. /* BPF syscall commands, see bpf(2) man-page for details. */
  67. enum bpf_cmd {
  68. BPF_MAP_CREATE,
  69. BPF_MAP_LOOKUP_ELEM,
  70. BPF_MAP_UPDATE_ELEM,
  71. BPF_MAP_DELETE_ELEM,
  72. BPF_MAP_GET_NEXT_KEY,
  73. BPF_PROG_LOAD,
  74. BPF_OBJ_PIN,
  75. BPF_OBJ_GET,
  76. BPF_PROG_ATTACH,
  77. BPF_PROG_DETACH,
  78. BPF_PROG_TEST_RUN,
  79. BPF_PROG_GET_NEXT_ID,
  80. BPF_MAP_GET_NEXT_ID,
  81. BPF_PROG_GET_FD_BY_ID,
  82. BPF_MAP_GET_FD_BY_ID,
  83. BPF_OBJ_GET_INFO_BY_FD,
  84. BPF_PROG_QUERY,
  85. BPF_RAW_TRACEPOINT_OPEN,
  86. };
  87. enum bpf_map_type {
  88. BPF_MAP_TYPE_UNSPEC,
  89. BPF_MAP_TYPE_HASH,
  90. BPF_MAP_TYPE_ARRAY,
  91. BPF_MAP_TYPE_PROG_ARRAY,
  92. BPF_MAP_TYPE_PERF_EVENT_ARRAY,
  93. BPF_MAP_TYPE_PERCPU_HASH,
  94. BPF_MAP_TYPE_PERCPU_ARRAY,
  95. BPF_MAP_TYPE_STACK_TRACE,
  96. BPF_MAP_TYPE_CGROUP_ARRAY,
  97. BPF_MAP_TYPE_LRU_HASH,
  98. BPF_MAP_TYPE_LRU_PERCPU_HASH,
  99. BPF_MAP_TYPE_LPM_TRIE,
  100. BPF_MAP_TYPE_ARRAY_OF_MAPS,
  101. BPF_MAP_TYPE_HASH_OF_MAPS,
  102. BPF_MAP_TYPE_DEVMAP,
  103. BPF_MAP_TYPE_SOCKMAP,
  104. BPF_MAP_TYPE_CPUMAP,
  105. };
  106. enum bpf_prog_type {
  107. BPF_PROG_TYPE_UNSPEC,
  108. BPF_PROG_TYPE_SOCKET_FILTER,
  109. BPF_PROG_TYPE_KPROBE,
  110. BPF_PROG_TYPE_SCHED_CLS,
  111. BPF_PROG_TYPE_SCHED_ACT,
  112. BPF_PROG_TYPE_TRACEPOINT,
  113. BPF_PROG_TYPE_XDP,
  114. BPF_PROG_TYPE_PERF_EVENT,
  115. BPF_PROG_TYPE_CGROUP_SKB,
  116. BPF_PROG_TYPE_CGROUP_SOCK,
  117. BPF_PROG_TYPE_LWT_IN,
  118. BPF_PROG_TYPE_LWT_OUT,
  119. BPF_PROG_TYPE_LWT_XMIT,
  120. BPF_PROG_TYPE_SOCK_OPS,
  121. BPF_PROG_TYPE_SK_SKB,
  122. BPF_PROG_TYPE_CGROUP_DEVICE,
  123. BPF_PROG_TYPE_SK_MSG,
  124. BPF_PROG_TYPE_RAW_TRACEPOINT,
  125. BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
  126. };
  127. enum bpf_attach_type {
  128. BPF_CGROUP_INET_INGRESS,
  129. BPF_CGROUP_INET_EGRESS,
  130. BPF_CGROUP_INET_SOCK_CREATE,
  131. BPF_CGROUP_SOCK_OPS,
  132. BPF_SK_SKB_STREAM_PARSER,
  133. BPF_SK_SKB_STREAM_VERDICT,
  134. BPF_CGROUP_DEVICE,
  135. BPF_SK_MSG_VERDICT,
  136. BPF_CGROUP_INET4_BIND,
  137. BPF_CGROUP_INET6_BIND,
  138. BPF_CGROUP_INET4_CONNECT,
  139. BPF_CGROUP_INET6_CONNECT,
  140. BPF_CGROUP_INET4_POST_BIND,
  141. BPF_CGROUP_INET6_POST_BIND,
  142. __MAX_BPF_ATTACH_TYPE
  143. };
  144. #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
  145. /* cgroup-bpf attach flags used in BPF_PROG_ATTACH command
  146. *
  147. * NONE(default): No further bpf programs allowed in the subtree.
  148. *
  149. * BPF_F_ALLOW_OVERRIDE: If a sub-cgroup installs some bpf program,
  150. * the program in this cgroup yields to sub-cgroup program.
  151. *
  152. * BPF_F_ALLOW_MULTI: If a sub-cgroup installs some bpf program,
  153. * that cgroup program gets run in addition to the program in this cgroup.
  154. *
  155. * Only one program is allowed to be attached to a cgroup with
  156. * NONE or BPF_F_ALLOW_OVERRIDE flag.
  157. * Attaching another program on top of NONE or BPF_F_ALLOW_OVERRIDE will
  158. * release old program and attach the new one. Attach flags has to match.
  159. *
  160. * Multiple programs are allowed to be attached to a cgroup with
  161. * BPF_F_ALLOW_MULTI flag. They are executed in FIFO order
  162. * (those that were attached first, run first)
  163. * The programs of sub-cgroup are executed first, then programs of
  164. * this cgroup and then programs of parent cgroup.
  165. * When children program makes decision (like picking TCP CA or sock bind)
  166. * parent program has a chance to override it.
  167. *
  168. * A cgroup with MULTI or OVERRIDE flag allows any attach flags in sub-cgroups.
  169. * A cgroup with NONE doesn't allow any programs in sub-cgroups.
  170. * Ex1:
  171. * cgrp1 (MULTI progs A, B) ->
  172. * cgrp2 (OVERRIDE prog C) ->
  173. * cgrp3 (MULTI prog D) ->
  174. * cgrp4 (OVERRIDE prog E) ->
  175. * cgrp5 (NONE prog F)
  176. * the event in cgrp5 triggers execution of F,D,A,B in that order.
  177. * if prog F is detached, the execution is E,D,A,B
  178. * if prog F and D are detached, the execution is E,A,B
  179. * if prog F, E and D are detached, the execution is C,A,B
  180. *
  181. * All eligible programs are executed regardless of return code from
  182. * earlier programs.
  183. */
  184. #define BPF_F_ALLOW_OVERRIDE (1U << 0)
  185. #define BPF_F_ALLOW_MULTI (1U << 1)
  186. /* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the
  187. * verifier will perform strict alignment checking as if the kernel
  188. * has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set,
  189. * and NET_IP_ALIGN defined to 2.
  190. */
  191. #define BPF_F_STRICT_ALIGNMENT (1U << 0)
  192. /* when bpf_ldimm64->src_reg == BPF_PSEUDO_MAP_FD, bpf_ldimm64->imm == fd */
  193. #define BPF_PSEUDO_MAP_FD 1
  194. /* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative
  195. * offset to another bpf function
  196. */
  197. #define BPF_PSEUDO_CALL 1
  198. /* flags for BPF_MAP_UPDATE_ELEM command */
  199. #define BPF_ANY 0 /* create new element or update existing */
  200. #define BPF_NOEXIST 1 /* create new element if it didn't exist */
  201. #define BPF_EXIST 2 /* update existing element */
  202. /* flags for BPF_MAP_CREATE command */
  203. #define BPF_F_NO_PREALLOC (1U << 0)
  204. /* Instead of having one common LRU list in the
  205. * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list
  206. * which can scale and perform better.
  207. * Note, the LRU nodes (including free nodes) cannot be moved
  208. * across different LRU lists.
  209. */
  210. #define BPF_F_NO_COMMON_LRU (1U << 1)
  211. /* Specify numa node during map creation */
  212. #define BPF_F_NUMA_NODE (1U << 2)
  213. /* flags for BPF_PROG_QUERY */
  214. #define BPF_F_QUERY_EFFECTIVE (1U << 0)
  215. #define BPF_OBJ_NAME_LEN 16U
  216. /* Flags for accessing BPF object */
  217. #define BPF_F_RDONLY (1U << 3)
  218. #define BPF_F_WRONLY (1U << 4)
  219. /* Flag for stack_map, store build_id+offset instead of pointer */
  220. #define BPF_F_STACK_BUILD_ID (1U << 5)
  221. enum bpf_stack_build_id_status {
  222. /* user space need an empty entry to identify end of a trace */
  223. BPF_STACK_BUILD_ID_EMPTY = 0,
  224. /* with valid build_id and offset */
  225. BPF_STACK_BUILD_ID_VALID = 1,
  226. /* couldn't get build_id, fallback to ip */
  227. BPF_STACK_BUILD_ID_IP = 2,
  228. };
  229. #define BPF_BUILD_ID_SIZE 20
  230. struct bpf_stack_build_id {
  231. __s32 status;
  232. unsigned char build_id[BPF_BUILD_ID_SIZE];
  233. union {
  234. __u64 offset;
  235. __u64 ip;
  236. };
  237. };
  238. union bpf_attr {
  239. struct { /* anonymous struct used by BPF_MAP_CREATE command */
  240. __u32 map_type; /* one of enum bpf_map_type */
  241. __u32 key_size; /* size of key in bytes */
  242. __u32 value_size; /* size of value in bytes */
  243. __u32 max_entries; /* max number of entries in a map */
  244. __u32 map_flags; /* BPF_MAP_CREATE related
  245. * flags defined above.
  246. */
  247. __u32 inner_map_fd; /* fd pointing to the inner map */
  248. __u32 numa_node; /* numa node (effective only if
  249. * BPF_F_NUMA_NODE is set).
  250. */
  251. char map_name[BPF_OBJ_NAME_LEN];
  252. __u32 map_ifindex; /* ifindex of netdev to create on */
  253. };
  254. struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
  255. __u32 map_fd;
  256. __aligned_u64 key;
  257. union {
  258. __aligned_u64 value;
  259. __aligned_u64 next_key;
  260. };
  261. __u64 flags;
  262. };
  263. struct { /* anonymous struct used by BPF_PROG_LOAD command */
  264. __u32 prog_type; /* one of enum bpf_prog_type */
  265. __u32 insn_cnt;
  266. __aligned_u64 insns;
  267. __aligned_u64 license;
  268. __u32 log_level; /* verbosity level of verifier */
  269. __u32 log_size; /* size of user buffer */
  270. __aligned_u64 log_buf; /* user supplied buffer */
  271. __u32 kern_version; /* checked when prog_type=kprobe */
  272. __u32 prog_flags;
  273. char prog_name[BPF_OBJ_NAME_LEN];
  274. __u32 prog_ifindex; /* ifindex of netdev to prep for */
  275. /* For some prog types expected attach type must be known at
  276. * load time to verify attach type specific parts of prog
  277. * (context accesses, allowed helpers, etc).
  278. */
  279. __u32 expected_attach_type;
  280. };
  281. struct { /* anonymous struct used by BPF_OBJ_* commands */
  282. __aligned_u64 pathname;
  283. __u32 bpf_fd;
  284. __u32 file_flags;
  285. };
  286. struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
  287. __u32 target_fd; /* container object to attach to */
  288. __u32 attach_bpf_fd; /* eBPF program to attach */
  289. __u32 attach_type;
  290. __u32 attach_flags;
  291. };
  292. struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
  293. __u32 prog_fd;
  294. __u32 retval;
  295. __u32 data_size_in;
  296. __u32 data_size_out;
  297. __aligned_u64 data_in;
  298. __aligned_u64 data_out;
  299. __u32 repeat;
  300. __u32 duration;
  301. } test;
  302. struct { /* anonymous struct used by BPF_*_GET_*_ID */
  303. union {
  304. __u32 start_id;
  305. __u32 prog_id;
  306. __u32 map_id;
  307. };
  308. __u32 next_id;
  309. __u32 open_flags;
  310. };
  311. struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
  312. __u32 bpf_fd;
  313. __u32 info_len;
  314. __aligned_u64 info;
  315. } info;
  316. struct { /* anonymous struct used by BPF_PROG_QUERY command */
  317. __u32 target_fd; /* container object to query */
  318. __u32 attach_type;
  319. __u32 query_flags;
  320. __u32 attach_flags;
  321. __aligned_u64 prog_ids;
  322. __u32 prog_cnt;
  323. } query;
  324. struct {
  325. __u64 name;
  326. __u32 prog_fd;
  327. } raw_tracepoint;
  328. } __attribute__((aligned(8)));
  329. /* BPF helper function descriptions:
  330. *
  331. * void *bpf_map_lookup_elem(&map, &key)
  332. * Return: Map value or NULL
  333. *
  334. * int bpf_map_update_elem(&map, &key, &value, flags)
  335. * Return: 0 on success or negative error
  336. *
  337. * int bpf_map_delete_elem(&map, &key)
  338. * Return: 0 on success or negative error
  339. *
  340. * int bpf_probe_read(void *dst, int size, void *src)
  341. * Return: 0 on success or negative error
  342. *
  343. * u64 bpf_ktime_get_ns(void)
  344. * Return: current ktime
  345. *
  346. * int bpf_trace_printk(const char *fmt, int fmt_size, ...)
  347. * Return: length of buffer written or negative error
  348. *
  349. * u32 bpf_prandom_u32(void)
  350. * Return: random value
  351. *
  352. * u32 bpf_raw_smp_processor_id(void)
  353. * Return: SMP processor ID
  354. *
  355. * int bpf_skb_store_bytes(skb, offset, from, len, flags)
  356. * store bytes into packet
  357. * @skb: pointer to skb
  358. * @offset: offset within packet from skb->mac_header
  359. * @from: pointer where to copy bytes from
  360. * @len: number of bytes to store into packet
  361. * @flags: bit 0 - if true, recompute skb->csum
  362. * other bits - reserved
  363. * Return: 0 on success or negative error
  364. *
  365. * int bpf_l3_csum_replace(skb, offset, from, to, flags)
  366. * recompute IP checksum
  367. * @skb: pointer to skb
  368. * @offset: offset within packet where IP checksum is located
  369. * @from: old value of header field
  370. * @to: new value of header field
  371. * @flags: bits 0-3 - size of header field
  372. * other bits - reserved
  373. * Return: 0 on success or negative error
  374. *
  375. * int bpf_l4_csum_replace(skb, offset, from, to, flags)
  376. * recompute TCP/UDP checksum
  377. * @skb: pointer to skb
  378. * @offset: offset within packet where TCP/UDP checksum is located
  379. * @from: old value of header field
  380. * @to: new value of header field
  381. * @flags: bits 0-3 - size of header field
  382. * bit 4 - is pseudo header
  383. * other bits - reserved
  384. * Return: 0 on success or negative error
  385. *
  386. * int bpf_tail_call(ctx, prog_array_map, index)
  387. * jump into another BPF program
  388. * @ctx: context pointer passed to next program
  389. * @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY
  390. * @index: 32-bit index inside array that selects specific program to run
  391. * Return: 0 on success or negative error
  392. *
  393. * int bpf_clone_redirect(skb, ifindex, flags)
  394. * redirect to another netdev
  395. * @skb: pointer to skb
  396. * @ifindex: ifindex of the net device
  397. * @flags: bit 0 - if set, redirect to ingress instead of egress
  398. * other bits - reserved
  399. * Return: 0 on success or negative error
  400. *
  401. * u64 bpf_get_current_pid_tgid(void)
  402. * Return: current->tgid << 32 | current->pid
  403. *
  404. * u64 bpf_get_current_uid_gid(void)
  405. * Return: current_gid << 32 | current_uid
  406. *
  407. * int bpf_get_current_comm(char *buf, int size_of_buf)
  408. * stores current->comm into buf
  409. * Return: 0 on success or negative error
  410. *
  411. * u32 bpf_get_cgroup_classid(skb)
  412. * retrieve a proc's classid
  413. * @skb: pointer to skb
  414. * Return: classid if != 0
  415. *
  416. * int bpf_skb_vlan_push(skb, vlan_proto, vlan_tci)
  417. * Return: 0 on success or negative error
  418. *
  419. * int bpf_skb_vlan_pop(skb)
  420. * Return: 0 on success or negative error
  421. *
  422. * int bpf_skb_get_tunnel_key(skb, key, size, flags)
  423. * int bpf_skb_set_tunnel_key(skb, key, size, flags)
  424. * retrieve or populate tunnel metadata
  425. * @skb: pointer to skb
  426. * @key: pointer to 'struct bpf_tunnel_key'
  427. * @size: size of 'struct bpf_tunnel_key'
  428. * @flags: room for future extensions
  429. * Return: 0 on success or negative error
  430. *
  431. * u64 bpf_perf_event_read(map, flags)
  432. * read perf event counter value
  433. * @map: pointer to perf_event_array map
  434. * @flags: index of event in the map or bitmask flags
  435. * Return: value of perf event counter read or error code
  436. *
  437. * int bpf_redirect(ifindex, flags)
  438. * redirect to another netdev
  439. * @ifindex: ifindex of the net device
  440. * @flags:
  441. * cls_bpf:
  442. * bit 0 - if set, redirect to ingress instead of egress
  443. * other bits - reserved
  444. * xdp_bpf:
  445. * all bits - reserved
  446. * Return: cls_bpf: TC_ACT_REDIRECT on success or TC_ACT_SHOT on error
  447. * xdp_bfp: XDP_REDIRECT on success or XDP_ABORT on error
  448. * int bpf_redirect_map(map, key, flags)
  449. * redirect to endpoint in map
  450. * @map: pointer to dev map
  451. * @key: index in map to lookup
  452. * @flags: --
  453. * Return: XDP_REDIRECT on success or XDP_ABORT on error
  454. *
  455. * u32 bpf_get_route_realm(skb)
  456. * retrieve a dst's tclassid
  457. * @skb: pointer to skb
  458. * Return: realm if != 0
  459. *
  460. * int bpf_perf_event_output(ctx, map, flags, data, size)
  461. * output perf raw sample
  462. * @ctx: struct pt_regs*
  463. * @map: pointer to perf_event_array map
  464. * @flags: index of event in the map or bitmask flags
  465. * @data: data on stack to be output as raw data
  466. * @size: size of data
  467. * Return: 0 on success or negative error
  468. *
  469. * int bpf_get_stackid(ctx, map, flags)
  470. * walk user or kernel stack and return id
  471. * @ctx: struct pt_regs*
  472. * @map: pointer to stack_trace map
  473. * @flags: bits 0-7 - numer of stack frames to skip
  474. * bit 8 - collect user stack instead of kernel
  475. * bit 9 - compare stacks by hash only
  476. * bit 10 - if two different stacks hash into the same stackid
  477. * discard old
  478. * other bits - reserved
  479. * Return: >= 0 stackid on success or negative error
  480. *
  481. * s64 bpf_csum_diff(from, from_size, to, to_size, seed)
  482. * calculate csum diff
  483. * @from: raw from buffer
  484. * @from_size: length of from buffer
  485. * @to: raw to buffer
  486. * @to_size: length of to buffer
  487. * @seed: optional seed
  488. * Return: csum result or negative error code
  489. *
  490. * int bpf_skb_get_tunnel_opt(skb, opt, size)
  491. * retrieve tunnel options metadata
  492. * @skb: pointer to skb
  493. * @opt: pointer to raw tunnel option data
  494. * @size: size of @opt
  495. * Return: option size
  496. *
  497. * int bpf_skb_set_tunnel_opt(skb, opt, size)
  498. * populate tunnel options metadata
  499. * @skb: pointer to skb
  500. * @opt: pointer to raw tunnel option data
  501. * @size: size of @opt
  502. * Return: 0 on success or negative error
  503. *
  504. * int bpf_skb_change_proto(skb, proto, flags)
  505. * Change protocol of the skb. Currently supported is v4 -> v6,
  506. * v6 -> v4 transitions. The helper will also resize the skb. eBPF
  507. * program is expected to fill the new headers via skb_store_bytes
  508. * and lX_csum_replace.
  509. * @skb: pointer to skb
  510. * @proto: new skb->protocol type
  511. * @flags: reserved
  512. * Return: 0 on success or negative error
  513. *
  514. * int bpf_skb_change_type(skb, type)
  515. * Change packet type of skb.
  516. * @skb: pointer to skb
  517. * @type: new skb->pkt_type type
  518. * Return: 0 on success or negative error
  519. *
  520. * int bpf_skb_under_cgroup(skb, map, index)
  521. * Check cgroup2 membership of skb
  522. * @skb: pointer to skb
  523. * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
  524. * @index: index of the cgroup in the bpf_map
  525. * Return:
  526. * == 0 skb failed the cgroup2 descendant test
  527. * == 1 skb succeeded the cgroup2 descendant test
  528. * < 0 error
  529. *
  530. * u32 bpf_get_hash_recalc(skb)
  531. * Retrieve and possibly recalculate skb->hash.
  532. * @skb: pointer to skb
  533. * Return: hash
  534. *
  535. * u64 bpf_get_current_task(void)
  536. * Returns current task_struct
  537. * Return: current
  538. *
  539. * int bpf_probe_write_user(void *dst, void *src, int len)
  540. * safely attempt to write to a location
  541. * @dst: destination address in userspace
  542. * @src: source address on stack
  543. * @len: number of bytes to copy
  544. * Return: 0 on success or negative error
  545. *
  546. * int bpf_current_task_under_cgroup(map, index)
  547. * Check cgroup2 membership of current task
  548. * @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
  549. * @index: index of the cgroup in the bpf_map
  550. * Return:
  551. * == 0 current failed the cgroup2 descendant test
  552. * == 1 current succeeded the cgroup2 descendant test
  553. * < 0 error
  554. *
  555. * int bpf_skb_change_tail(skb, len, flags)
  556. * The helper will resize the skb to the given new size, to be used f.e.
  557. * with control messages.
  558. * @skb: pointer to skb
  559. * @len: new skb length
  560. * @flags: reserved
  561. * Return: 0 on success or negative error
  562. *
  563. * int bpf_skb_pull_data(skb, len)
  564. * The helper will pull in non-linear data in case the skb is non-linear
  565. * and not all of len are part of the linear section. Only needed for
  566. * read/write with direct packet access.
  567. * @skb: pointer to skb
  568. * @len: len to make read/writeable
  569. * Return: 0 on success or negative error
  570. *
  571. * s64 bpf_csum_update(skb, csum)
  572. * Adds csum into skb->csum in case of CHECKSUM_COMPLETE.
  573. * @skb: pointer to skb
  574. * @csum: csum to add
  575. * Return: csum on success or negative error
  576. *
  577. * void bpf_set_hash_invalid(skb)
  578. * Invalidate current skb->hash.
  579. * @skb: pointer to skb
  580. *
  581. * int bpf_get_numa_node_id()
  582. * Return: Id of current NUMA node.
  583. *
  584. * int bpf_skb_change_head()
  585. * Grows headroom of skb and adjusts MAC header offset accordingly.
  586. * Will extends/reallocae as required automatically.
  587. * May change skb data pointer and will thus invalidate any check
  588. * performed for direct packet access.
  589. * @skb: pointer to skb
  590. * @len: length of header to be pushed in front
  591. * @flags: Flags (unused for now)
  592. * Return: 0 on success or negative error
  593. *
  594. * int bpf_xdp_adjust_head(xdp_md, delta)
  595. * Adjust the xdp_md.data by delta
  596. * @xdp_md: pointer to xdp_md
  597. * @delta: An positive/negative integer to be added to xdp_md.data
  598. * Return: 0 on success or negative on error
  599. *
  600. * int bpf_probe_read_str(void *dst, int size, const void *unsafe_ptr)
  601. * Copy a NUL terminated string from unsafe address. In case the string
  602. * length is smaller than size, the target is not padded with further NUL
  603. * bytes. In case the string length is larger than size, just count-1
  604. * bytes are copied and the last byte is set to NUL.
  605. * @dst: destination address
  606. * @size: maximum number of bytes to copy, including the trailing NUL
  607. * @unsafe_ptr: unsafe address
  608. * Return:
  609. * > 0 length of the string including the trailing NUL on success
  610. * < 0 error
  611. *
  612. * u64 bpf_get_socket_cookie(skb)
  613. * Get the cookie for the socket stored inside sk_buff.
  614. * @skb: pointer to skb
  615. * Return: 8 Bytes non-decreasing number on success or 0 if the socket
  616. * field is missing inside sk_buff
  617. *
  618. * u32 bpf_get_socket_uid(skb)
  619. * Get the owner uid of the socket stored inside sk_buff.
  620. * @skb: pointer to skb
  621. * Return: uid of the socket owner on success or overflowuid if failed.
  622. *
  623. * u32 bpf_set_hash(skb, hash)
  624. * Set full skb->hash.
  625. * @skb: pointer to skb
  626. * @hash: hash to set
  627. *
  628. * int bpf_setsockopt(bpf_socket, level, optname, optval, optlen)
  629. * Calls setsockopt. Not all opts are available, only those with
  630. * integer optvals plus TCP_CONGESTION.
  631. * Supported levels: SOL_SOCKET and IPPROTO_TCP
  632. * @bpf_socket: pointer to bpf_socket
  633. * @level: SOL_SOCKET or IPPROTO_TCP
  634. * @optname: option name
  635. * @optval: pointer to option value
  636. * @optlen: length of optval in bytes
  637. * Return: 0 or negative error
  638. *
  639. * int bpf_getsockopt(bpf_socket, level, optname, optval, optlen)
  640. * Calls getsockopt. Not all opts are available.
  641. * Supported levels: IPPROTO_TCP
  642. * @bpf_socket: pointer to bpf_socket
  643. * @level: IPPROTO_TCP
  644. * @optname: option name
  645. * @optval: pointer to option value
  646. * @optlen: length of optval in bytes
  647. * Return: 0 or negative error
  648. *
  649. * int bpf_sock_ops_cb_flags_set(bpf_sock_ops, flags)
  650. * Set callback flags for sock_ops
  651. * @bpf_sock_ops: pointer to bpf_sock_ops_kern struct
  652. * @flags: flags value
  653. * Return: 0 for no error
  654. * -EINVAL if there is no full tcp socket
  655. * bits in flags that are not supported by current kernel
  656. *
  657. * int bpf_skb_adjust_room(skb, len_diff, mode, flags)
  658. * Grow or shrink room in sk_buff.
  659. * @skb: pointer to skb
  660. * @len_diff: (signed) amount of room to grow/shrink
  661. * @mode: operation mode (enum bpf_adj_room_mode)
  662. * @flags: reserved for future use
  663. * Return: 0 on success or negative error code
  664. *
  665. * int bpf_sk_redirect_map(map, key, flags)
  666. * Redirect skb to a sock in map using key as a lookup key for the
  667. * sock in map.
  668. * @map: pointer to sockmap
  669. * @key: key to lookup sock in map
  670. * @flags: reserved for future use
  671. * Return: SK_PASS
  672. *
  673. * int bpf_sock_map_update(skops, map, key, flags)
  674. * @skops: pointer to bpf_sock_ops
  675. * @map: pointer to sockmap to update
  676. * @key: key to insert/update sock in map
  677. * @flags: same flags as map update elem
  678. *
  679. * int bpf_xdp_adjust_meta(xdp_md, delta)
  680. * Adjust the xdp_md.data_meta by delta
  681. * @xdp_md: pointer to xdp_md
  682. * @delta: An positive/negative integer to be added to xdp_md.data_meta
  683. * Return: 0 on success or negative on error
  684. *
  685. * int bpf_perf_event_read_value(map, flags, buf, buf_size)
  686. * read perf event counter value and perf event enabled/running time
  687. * @map: pointer to perf_event_array map
  688. * @flags: index of event in the map or bitmask flags
  689. * @buf: buf to fill
  690. * @buf_size: size of the buf
  691. * Return: 0 on success or negative error code
  692. *
  693. * int bpf_perf_prog_read_value(ctx, buf, buf_size)
  694. * read perf prog attached perf event counter and enabled/running time
  695. * @ctx: pointer to ctx
  696. * @buf: buf to fill
  697. * @buf_size: size of the buf
  698. * Return : 0 on success or negative error code
  699. *
  700. * int bpf_override_return(pt_regs, rc)
  701. * @pt_regs: pointer to struct pt_regs
  702. * @rc: the return value to set
  703. *
  704. * int bpf_msg_redirect_map(map, key, flags)
  705. * Redirect msg to a sock in map using key as a lookup key for the
  706. * sock in map.
  707. * @map: pointer to sockmap
  708. * @key: key to lookup sock in map
  709. * @flags: reserved for future use
  710. * Return: SK_PASS
  711. *
  712. * int bpf_bind(ctx, addr, addr_len)
  713. * Bind socket to address. Only binding to IP is supported, no port can be
  714. * set in addr.
  715. * @ctx: pointer to context of type bpf_sock_addr
  716. * @addr: pointer to struct sockaddr to bind socket to
  717. * @addr_len: length of sockaddr structure
  718. * Return: 0 on success or negative error code
  719. */
  720. #define __BPF_FUNC_MAPPER(FN) \
  721. FN(unspec), \
  722. FN(map_lookup_elem), \
  723. FN(map_update_elem), \
  724. FN(map_delete_elem), \
  725. FN(probe_read), \
  726. FN(ktime_get_ns), \
  727. FN(trace_printk), \
  728. FN(get_prandom_u32), \
  729. FN(get_smp_processor_id), \
  730. FN(skb_store_bytes), \
  731. FN(l3_csum_replace), \
  732. FN(l4_csum_replace), \
  733. FN(tail_call), \
  734. FN(clone_redirect), \
  735. FN(get_current_pid_tgid), \
  736. FN(get_current_uid_gid), \
  737. FN(get_current_comm), \
  738. FN(get_cgroup_classid), \
  739. FN(skb_vlan_push), \
  740. FN(skb_vlan_pop), \
  741. FN(skb_get_tunnel_key), \
  742. FN(skb_set_tunnel_key), \
  743. FN(perf_event_read), \
  744. FN(redirect), \
  745. FN(get_route_realm), \
  746. FN(perf_event_output), \
  747. FN(skb_load_bytes), \
  748. FN(get_stackid), \
  749. FN(csum_diff), \
  750. FN(skb_get_tunnel_opt), \
  751. FN(skb_set_tunnel_opt), \
  752. FN(skb_change_proto), \
  753. FN(skb_change_type), \
  754. FN(skb_under_cgroup), \
  755. FN(get_hash_recalc), \
  756. FN(get_current_task), \
  757. FN(probe_write_user), \
  758. FN(current_task_under_cgroup), \
  759. FN(skb_change_tail), \
  760. FN(skb_pull_data), \
  761. FN(csum_update), \
  762. FN(set_hash_invalid), \
  763. FN(get_numa_node_id), \
  764. FN(skb_change_head), \
  765. FN(xdp_adjust_head), \
  766. FN(probe_read_str), \
  767. FN(get_socket_cookie), \
  768. FN(get_socket_uid), \
  769. FN(set_hash), \
  770. FN(setsockopt), \
  771. FN(skb_adjust_room), \
  772. FN(redirect_map), \
  773. FN(sk_redirect_map), \
  774. FN(sock_map_update), \
  775. FN(xdp_adjust_meta), \
  776. FN(perf_event_read_value), \
  777. FN(perf_prog_read_value), \
  778. FN(getsockopt), \
  779. FN(override_return), \
  780. FN(sock_ops_cb_flags_set), \
  781. FN(msg_redirect_map), \
  782. FN(msg_apply_bytes), \
  783. FN(msg_cork_bytes), \
  784. FN(msg_pull_data), \
  785. FN(bind),
  786. /* integer value in 'imm' field of BPF_CALL instruction selects which helper
  787. * function eBPF program intends to call
  788. */
  789. #define __BPF_ENUM_FN(x) BPF_FUNC_ ## x
  790. enum bpf_func_id {
  791. __BPF_FUNC_MAPPER(__BPF_ENUM_FN)
  792. __BPF_FUNC_MAX_ID,
  793. };
  794. #undef __BPF_ENUM_FN
  795. /* All flags used by eBPF helper functions, placed here. */
  796. /* BPF_FUNC_skb_store_bytes flags. */
  797. #define BPF_F_RECOMPUTE_CSUM (1ULL << 0)
  798. #define BPF_F_INVALIDATE_HASH (1ULL << 1)
  799. /* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
  800. * First 4 bits are for passing the header field size.
  801. */
  802. #define BPF_F_HDR_FIELD_MASK 0xfULL
  803. /* BPF_FUNC_l4_csum_replace flags. */
  804. #define BPF_F_PSEUDO_HDR (1ULL << 4)
  805. #define BPF_F_MARK_MANGLED_0 (1ULL << 5)
  806. #define BPF_F_MARK_ENFORCE (1ULL << 6)
  807. /* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */
  808. #define BPF_F_INGRESS (1ULL << 0)
  809. /* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */
  810. #define BPF_F_TUNINFO_IPV6 (1ULL << 0)
  811. /* BPF_FUNC_get_stackid flags. */
  812. #define BPF_F_SKIP_FIELD_MASK 0xffULL
  813. #define BPF_F_USER_STACK (1ULL << 8)
  814. #define BPF_F_FAST_STACK_CMP (1ULL << 9)
  815. #define BPF_F_REUSE_STACKID (1ULL << 10)
  816. /* BPF_FUNC_skb_set_tunnel_key flags. */
  817. #define BPF_F_ZERO_CSUM_TX (1ULL << 1)
  818. #define BPF_F_DONT_FRAGMENT (1ULL << 2)
  819. #define BPF_F_SEQ_NUMBER (1ULL << 3)
  820. /* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
  821. * BPF_FUNC_perf_event_read_value flags.
  822. */
  823. #define BPF_F_INDEX_MASK 0xffffffffULL
  824. #define BPF_F_CURRENT_CPU BPF_F_INDEX_MASK
  825. /* BPF_FUNC_perf_event_output for sk_buff input context. */
  826. #define BPF_F_CTXLEN_MASK (0xfffffULL << 32)
  827. /* Mode for BPF_FUNC_skb_adjust_room helper. */
  828. enum bpf_adj_room_mode {
  829. BPF_ADJ_ROOM_NET,
  830. };
  831. /* user accessible mirror of in-kernel sk_buff.
  832. * new fields can only be added to the end of this structure
  833. */
  834. struct __sk_buff {
  835. __u32 len;
  836. __u32 pkt_type;
  837. __u32 mark;
  838. __u32 queue_mapping;
  839. __u32 protocol;
  840. __u32 vlan_present;
  841. __u32 vlan_tci;
  842. __u32 vlan_proto;
  843. __u32 priority;
  844. __u32 ingress_ifindex;
  845. __u32 ifindex;
  846. __u32 tc_index;
  847. __u32 cb[5];
  848. __u32 hash;
  849. __u32 tc_classid;
  850. __u32 data;
  851. __u32 data_end;
  852. __u32 napi_id;
  853. /* Accessed by BPF_PROG_TYPE_sk_skb types from here to ... */
  854. __u32 family;
  855. __u32 remote_ip4; /* Stored in network byte order */
  856. __u32 local_ip4; /* Stored in network byte order */
  857. __u32 remote_ip6[4]; /* Stored in network byte order */
  858. __u32 local_ip6[4]; /* Stored in network byte order */
  859. __u32 remote_port; /* Stored in network byte order */
  860. __u32 local_port; /* stored in host byte order */
  861. /* ... here. */
  862. __u32 data_meta;
  863. };
  864. struct bpf_tunnel_key {
  865. __u32 tunnel_id;
  866. union {
  867. __u32 remote_ipv4;
  868. __u32 remote_ipv6[4];
  869. };
  870. __u8 tunnel_tos;
  871. __u8 tunnel_ttl;
  872. __u16 tunnel_ext;
  873. __u32 tunnel_label;
  874. };
  875. /* Generic BPF return codes which all BPF program types may support.
  876. * The values are binary compatible with their TC_ACT_* counter-part to
  877. * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT
  878. * programs.
  879. *
  880. * XDP is handled seprately, see XDP_*.
  881. */
  882. enum bpf_ret_code {
  883. BPF_OK = 0,
  884. /* 1 reserved */
  885. BPF_DROP = 2,
  886. /* 3-6 reserved */
  887. BPF_REDIRECT = 7,
  888. /* >127 are reserved for prog type specific return codes */
  889. };
  890. struct bpf_sock {
  891. __u32 bound_dev_if;
  892. __u32 family;
  893. __u32 type;
  894. __u32 protocol;
  895. __u32 mark;
  896. __u32 priority;
  897. __u32 src_ip4; /* Allows 1,2,4-byte read.
  898. * Stored in network byte order.
  899. */
  900. __u32 src_ip6[4]; /* Allows 1,2,4-byte read.
  901. * Stored in network byte order.
  902. */
  903. __u32 src_port; /* Allows 4-byte read.
  904. * Stored in host byte order
  905. */
  906. };
  907. #define XDP_PACKET_HEADROOM 256
  908. /* User return codes for XDP prog type.
  909. * A valid XDP program must return one of these defined values. All other
  910. * return codes are reserved for future use. Unknown return codes will
  911. * result in packet drops and a warning via bpf_warn_invalid_xdp_action().
  912. */
  913. enum xdp_action {
  914. XDP_ABORTED = 0,
  915. XDP_DROP,
  916. XDP_PASS,
  917. XDP_TX,
  918. XDP_REDIRECT,
  919. };
  920. /* user accessible metadata for XDP packet hook
  921. * new fields must be added to the end of this structure
  922. */
  923. struct xdp_md {
  924. __u32 data;
  925. __u32 data_end;
  926. __u32 data_meta;
  927. /* Below access go through struct xdp_rxq_info */
  928. __u32 ingress_ifindex; /* rxq->dev->ifindex */
  929. __u32 rx_queue_index; /* rxq->queue_index */
  930. };
  931. enum sk_action {
  932. SK_DROP = 0,
  933. SK_PASS,
  934. };
  935. /* user accessible metadata for SK_MSG packet hook, new fields must
  936. * be added to the end of this structure
  937. */
  938. struct sk_msg_md {
  939. void *data;
  940. void *data_end;
  941. };
  942. #define BPF_TAG_SIZE 8
  943. struct bpf_prog_info {
  944. __u32 type;
  945. __u32 id;
  946. __u8 tag[BPF_TAG_SIZE];
  947. __u32 jited_prog_len;
  948. __u32 xlated_prog_len;
  949. __aligned_u64 jited_prog_insns;
  950. __aligned_u64 xlated_prog_insns;
  951. __u64 load_time; /* ns since boottime */
  952. __u32 created_by_uid;
  953. __u32 nr_map_ids;
  954. __aligned_u64 map_ids;
  955. char name[BPF_OBJ_NAME_LEN];
  956. __u32 ifindex;
  957. __u32 :32;
  958. __u64 netns_dev;
  959. __u64 netns_ino;
  960. } __attribute__((aligned(8)));
  961. struct bpf_map_info {
  962. __u32 type;
  963. __u32 id;
  964. __u32 key_size;
  965. __u32 value_size;
  966. __u32 max_entries;
  967. __u32 map_flags;
  968. char name[BPF_OBJ_NAME_LEN];
  969. __u32 ifindex;
  970. __u32 :32;
  971. __u64 netns_dev;
  972. __u64 netns_ino;
  973. } __attribute__((aligned(8)));
  974. /* User bpf_sock_addr struct to access socket fields and sockaddr struct passed
  975. * by user and intended to be used by socket (e.g. to bind to, depends on
  976. * attach attach type).
  977. */
  978. struct bpf_sock_addr {
  979. __u32 user_family; /* Allows 4-byte read, but no write. */
  980. __u32 user_ip4; /* Allows 1,2,4-byte read and 4-byte write.
  981. * Stored in network byte order.
  982. */
  983. __u32 user_ip6[4]; /* Allows 1,2,4-byte read an 4-byte write.
  984. * Stored in network byte order.
  985. */
  986. __u32 user_port; /* Allows 4-byte read and write.
  987. * Stored in network byte order
  988. */
  989. __u32 family; /* Allows 4-byte read, but no write */
  990. __u32 type; /* Allows 4-byte read, but no write */
  991. __u32 protocol; /* Allows 4-byte read, but no write */
  992. };
  993. /* User bpf_sock_ops struct to access socket values and specify request ops
  994. * and their replies.
  995. * Some of this fields are in network (bigendian) byte order and may need
  996. * to be converted before use (bpf_ntohl() defined in samples/bpf/bpf_endian.h).
  997. * New fields can only be added at the end of this structure
  998. */
  999. struct bpf_sock_ops {
  1000. __u32 op;
  1001. union {
  1002. __u32 args[4]; /* Optionally passed to bpf program */
  1003. __u32 reply; /* Returned by bpf program */
  1004. __u32 replylong[4]; /* Optionally returned by bpf prog */
  1005. };
  1006. __u32 family;
  1007. __u32 remote_ip4; /* Stored in network byte order */
  1008. __u32 local_ip4; /* Stored in network byte order */
  1009. __u32 remote_ip6[4]; /* Stored in network byte order */
  1010. __u32 local_ip6[4]; /* Stored in network byte order */
  1011. __u32 remote_port; /* Stored in network byte order */
  1012. __u32 local_port; /* stored in host byte order */
  1013. __u32 is_fullsock; /* Some TCP fields are only valid if
  1014. * there is a full socket. If not, the
  1015. * fields read as zero.
  1016. */
  1017. __u32 snd_cwnd;
  1018. __u32 srtt_us; /* Averaged RTT << 3 in usecs */
  1019. __u32 bpf_sock_ops_cb_flags; /* flags defined in uapi/linux/tcp.h */
  1020. __u32 state;
  1021. __u32 rtt_min;
  1022. __u32 snd_ssthresh;
  1023. __u32 rcv_nxt;
  1024. __u32 snd_nxt;
  1025. __u32 snd_una;
  1026. __u32 mss_cache;
  1027. __u32 ecn_flags;
  1028. __u32 rate_delivered;
  1029. __u32 rate_interval_us;
  1030. __u32 packets_out;
  1031. __u32 retrans_out;
  1032. __u32 total_retrans;
  1033. __u32 segs_in;
  1034. __u32 data_segs_in;
  1035. __u32 segs_out;
  1036. __u32 data_segs_out;
  1037. __u32 lost_out;
  1038. __u32 sacked_out;
  1039. __u32 sk_txhash;
  1040. __u64 bytes_received;
  1041. __u64 bytes_acked;
  1042. };
  1043. /* Definitions for bpf_sock_ops_cb_flags */
  1044. #define BPF_SOCK_OPS_RTO_CB_FLAG (1<<0)
  1045. #define BPF_SOCK_OPS_RETRANS_CB_FLAG (1<<1)
  1046. #define BPF_SOCK_OPS_STATE_CB_FLAG (1<<2)
  1047. #define BPF_SOCK_OPS_ALL_CB_FLAGS 0x7 /* Mask of all currently
  1048. * supported cb flags
  1049. */
  1050. /* List of known BPF sock_ops operators.
  1051. * New entries can only be added at the end
  1052. */
  1053. enum {
  1054. BPF_SOCK_OPS_VOID,
  1055. BPF_SOCK_OPS_TIMEOUT_INIT, /* Should return SYN-RTO value to use or
  1056. * -1 if default value should be used
  1057. */
  1058. BPF_SOCK_OPS_RWND_INIT, /* Should return initial advertized
  1059. * window (in packets) or -1 if default
  1060. * value should be used
  1061. */
  1062. BPF_SOCK_OPS_TCP_CONNECT_CB, /* Calls BPF program right before an
  1063. * active connection is initialized
  1064. */
  1065. BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB, /* Calls BPF program when an
  1066. * active connection is
  1067. * established
  1068. */
  1069. BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB, /* Calls BPF program when a
  1070. * passive connection is
  1071. * established
  1072. */
  1073. BPF_SOCK_OPS_NEEDS_ECN, /* If connection's congestion control
  1074. * needs ECN
  1075. */
  1076. BPF_SOCK_OPS_BASE_RTT, /* Get base RTT. The correct value is
  1077. * based on the path and may be
  1078. * dependent on the congestion control
  1079. * algorithm. In general it indicates
  1080. * a congestion threshold. RTTs above
  1081. * this indicate congestion
  1082. */
  1083. BPF_SOCK_OPS_RTO_CB, /* Called when an RTO has triggered.
  1084. * Arg1: value of icsk_retransmits
  1085. * Arg2: value of icsk_rto
  1086. * Arg3: whether RTO has expired
  1087. */
  1088. BPF_SOCK_OPS_RETRANS_CB, /* Called when skb is retransmitted.
  1089. * Arg1: sequence number of 1st byte
  1090. * Arg2: # segments
  1091. * Arg3: return value of
  1092. * tcp_transmit_skb (0 => success)
  1093. */
  1094. BPF_SOCK_OPS_STATE_CB, /* Called when TCP changes state.
  1095. * Arg1: old_state
  1096. * Arg2: new_state
  1097. */
  1098. };
  1099. /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
  1100. * changes between the TCP and BPF versions. Ideally this should never happen.
  1101. * If it does, we need to add code to convert them before calling
  1102. * the BPF sock_ops function.
  1103. */
  1104. enum {
  1105. BPF_TCP_ESTABLISHED = 1,
  1106. BPF_TCP_SYN_SENT,
  1107. BPF_TCP_SYN_RECV,
  1108. BPF_TCP_FIN_WAIT1,
  1109. BPF_TCP_FIN_WAIT2,
  1110. BPF_TCP_TIME_WAIT,
  1111. BPF_TCP_CLOSE,
  1112. BPF_TCP_CLOSE_WAIT,
  1113. BPF_TCP_LAST_ACK,
  1114. BPF_TCP_LISTEN,
  1115. BPF_TCP_CLOSING, /* Now a valid state */
  1116. BPF_TCP_NEW_SYN_RECV,
  1117. BPF_TCP_MAX_STATES /* Leave at the end! */
  1118. };
  1119. #define TCP_BPF_IW 1001 /* Set TCP initial congestion window */
  1120. #define TCP_BPF_SNDCWND_CLAMP 1002 /* Set sndcwnd_clamp */
  1121. struct bpf_perf_event_value {
  1122. __u64 counter;
  1123. __u64 enabled;
  1124. __u64 running;
  1125. };
  1126. #define BPF_DEVCG_ACC_MKNOD (1ULL << 0)
  1127. #define BPF_DEVCG_ACC_READ (1ULL << 1)
  1128. #define BPF_DEVCG_ACC_WRITE (1ULL << 2)
  1129. #define BPF_DEVCG_DEV_BLOCK (1ULL << 0)
  1130. #define BPF_DEVCG_DEV_CHAR (1ULL << 1)
  1131. struct bpf_cgroup_dev_ctx {
  1132. /* access_type encoded as (BPF_DEVCG_ACC_* << 16) | BPF_DEVCG_DEV_* */
  1133. __u32 access_type;
  1134. __u32 major;
  1135. __u32 minor;
  1136. };
  1137. struct bpf_raw_tracepoint_args {
  1138. __u64 args[0];
  1139. };
  1140. #endif /* _UAPI__LINUX_BPF_H__ */