xref: /linux/include/uapi/linux/bpf.h (revision d74bad4e74ee373787a9ae24197c17b7cdc428d5)
1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2daedfb22SAlexei Starovoitov /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
3daedfb22SAlexei Starovoitov  *
4daedfb22SAlexei Starovoitov  * This program is free software; you can redistribute it and/or
5daedfb22SAlexei Starovoitov  * modify it under the terms of version 2 of the GNU General Public
6daedfb22SAlexei Starovoitov  * License as published by the Free Software Foundation.
7daedfb22SAlexei Starovoitov  */
8daedfb22SAlexei Starovoitov #ifndef _UAPI__LINUX_BPF_H__
9daedfb22SAlexei Starovoitov #define _UAPI__LINUX_BPF_H__
10daedfb22SAlexei Starovoitov 
11daedfb22SAlexei Starovoitov #include <linux/types.h>
12c15952dcSAlexei Starovoitov #include <linux/bpf_common.h>
13daedfb22SAlexei Starovoitov 
14daedfb22SAlexei Starovoitov /* Extended instruction set based on top of classic BPF */
15daedfb22SAlexei Starovoitov 
16daedfb22SAlexei Starovoitov /* instruction classes */
17daedfb22SAlexei Starovoitov #define BPF_ALU64	0x07	/* alu mode in double word width */
18daedfb22SAlexei Starovoitov 
19daedfb22SAlexei Starovoitov /* ld/ldx fields */
20cb5f7334SJesper Dangaard Brouer #define BPF_DW		0x18	/* double word (64-bit) */
21daedfb22SAlexei Starovoitov #define BPF_XADD	0xc0	/* exclusive add */
22daedfb22SAlexei Starovoitov 
23daedfb22SAlexei Starovoitov /* alu/jmp fields */
24daedfb22SAlexei Starovoitov #define BPF_MOV		0xb0	/* mov reg to reg */
25daedfb22SAlexei Starovoitov #define BPF_ARSH	0xc0	/* sign extending arithmetic shift right */
26daedfb22SAlexei Starovoitov 
27daedfb22SAlexei Starovoitov /* change endianness of a register */
28daedfb22SAlexei Starovoitov #define BPF_END		0xd0	/* flags for endianness conversion: */
29daedfb22SAlexei Starovoitov #define BPF_TO_LE	0x00	/* convert to little-endian */
30daedfb22SAlexei Starovoitov #define BPF_TO_BE	0x08	/* convert to big-endian */
31daedfb22SAlexei Starovoitov #define BPF_FROM_LE	BPF_TO_LE
32daedfb22SAlexei Starovoitov #define BPF_FROM_BE	BPF_TO_BE
33daedfb22SAlexei Starovoitov 
3492b31a9aSDaniel Borkmann /* jmp encodings */
35daedfb22SAlexei Starovoitov #define BPF_JNE		0x50	/* jump != */
3692b31a9aSDaniel Borkmann #define BPF_JLT		0xa0	/* LT is unsigned, '<' */
3792b31a9aSDaniel Borkmann #define BPF_JLE		0xb0	/* LE is unsigned, '<=' */
38daedfb22SAlexei Starovoitov #define BPF_JSGT	0x60	/* SGT is signed '>', GT in x86 */
39daedfb22SAlexei Starovoitov #define BPF_JSGE	0x70	/* SGE is signed '>=', GE in x86 */
4092b31a9aSDaniel Borkmann #define BPF_JSLT	0xc0	/* SLT is signed, '<' */
4192b31a9aSDaniel Borkmann #define BPF_JSLE	0xd0	/* SLE is signed, '<=' */
42daedfb22SAlexei Starovoitov #define BPF_CALL	0x80	/* function call */
43daedfb22SAlexei Starovoitov #define BPF_EXIT	0x90	/* function return */
44daedfb22SAlexei Starovoitov 
45daedfb22SAlexei Starovoitov /* Register numbers */
46daedfb22SAlexei Starovoitov enum {
47daedfb22SAlexei Starovoitov 	BPF_REG_0 = 0,
48daedfb22SAlexei Starovoitov 	BPF_REG_1,
49daedfb22SAlexei Starovoitov 	BPF_REG_2,
50daedfb22SAlexei Starovoitov 	BPF_REG_3,
51daedfb22SAlexei Starovoitov 	BPF_REG_4,
52daedfb22SAlexei Starovoitov 	BPF_REG_5,
53daedfb22SAlexei Starovoitov 	BPF_REG_6,
54daedfb22SAlexei Starovoitov 	BPF_REG_7,
55daedfb22SAlexei Starovoitov 	BPF_REG_8,
56daedfb22SAlexei Starovoitov 	BPF_REG_9,
57daedfb22SAlexei Starovoitov 	BPF_REG_10,
58daedfb22SAlexei Starovoitov 	__MAX_BPF_REG,
59daedfb22SAlexei Starovoitov };
60daedfb22SAlexei Starovoitov 
61daedfb22SAlexei Starovoitov /* BPF has 10 general purpose 64-bit registers and stack frame. */
62daedfb22SAlexei Starovoitov #define MAX_BPF_REG	__MAX_BPF_REG
63daedfb22SAlexei Starovoitov 
64daedfb22SAlexei Starovoitov struct bpf_insn {
65daedfb22SAlexei Starovoitov 	__u8	code;		/* opcode */
66daedfb22SAlexei Starovoitov 	__u8	dst_reg:4;	/* dest register */
67daedfb22SAlexei Starovoitov 	__u8	src_reg:4;	/* source register */
68daedfb22SAlexei Starovoitov 	__s16	off;		/* signed offset */
69daedfb22SAlexei Starovoitov 	__s32	imm;		/* signed immediate constant */
70daedfb22SAlexei Starovoitov };
71daedfb22SAlexei Starovoitov 
72b95a5c4dSDaniel Mack /* Key of an a BPF_MAP_TYPE_LPM_TRIE entry */
73b95a5c4dSDaniel Mack struct bpf_lpm_trie_key {
74b95a5c4dSDaniel Mack 	__u32	prefixlen;	/* up to 32 for AF_INET, 128 for AF_INET6 */
75b95a5c4dSDaniel Mack 	__u8	data[0];	/* Arbitrary size */
76b95a5c4dSDaniel Mack };
77b95a5c4dSDaniel Mack 
78b2197755SDaniel Borkmann /* BPF syscall commands, see bpf(2) man-page for details. */
7999c55f7dSAlexei Starovoitov enum bpf_cmd {
8099c55f7dSAlexei Starovoitov 	BPF_MAP_CREATE,
81db20fd2bSAlexei Starovoitov 	BPF_MAP_LOOKUP_ELEM,
82db20fd2bSAlexei Starovoitov 	BPF_MAP_UPDATE_ELEM,
83db20fd2bSAlexei Starovoitov 	BPF_MAP_DELETE_ELEM,
84db20fd2bSAlexei Starovoitov 	BPF_MAP_GET_NEXT_KEY,
8509756af4SAlexei Starovoitov 	BPF_PROG_LOAD,
86b2197755SDaniel Borkmann 	BPF_OBJ_PIN,
87b2197755SDaniel Borkmann 	BPF_OBJ_GET,
88f4324551SDaniel Mack 	BPF_PROG_ATTACH,
89f4324551SDaniel Mack 	BPF_PROG_DETACH,
901cf1cae9SAlexei Starovoitov 	BPF_PROG_TEST_RUN,
9134ad5580SMartin KaFai Lau 	BPF_PROG_GET_NEXT_ID,
9234ad5580SMartin KaFai Lau 	BPF_MAP_GET_NEXT_ID,
93b16d9aa4SMartin KaFai Lau 	BPF_PROG_GET_FD_BY_ID,
94bd5f5f4eSMartin KaFai Lau 	BPF_MAP_GET_FD_BY_ID,
951e270976SMartin KaFai Lau 	BPF_OBJ_GET_INFO_BY_FD,
96468e2f64SAlexei Starovoitov 	BPF_PROG_QUERY,
97c4f6699dSAlexei Starovoitov 	BPF_RAW_TRACEPOINT_OPEN,
9899c55f7dSAlexei Starovoitov };
9999c55f7dSAlexei Starovoitov 
10099c55f7dSAlexei Starovoitov enum bpf_map_type {
10199c55f7dSAlexei Starovoitov 	BPF_MAP_TYPE_UNSPEC,
1020f8e4bd8SAlexei Starovoitov 	BPF_MAP_TYPE_HASH,
10328fbcfa0SAlexei Starovoitov 	BPF_MAP_TYPE_ARRAY,
10404fd61abSAlexei Starovoitov 	BPF_MAP_TYPE_PROG_ARRAY,
105ea317b26SKaixu Xia 	BPF_MAP_TYPE_PERF_EVENT_ARRAY,
106824bd0ceSAlexei Starovoitov 	BPF_MAP_TYPE_PERCPU_HASH,
107a10423b8SAlexei Starovoitov 	BPF_MAP_TYPE_PERCPU_ARRAY,
108d5a3b1f6SAlexei Starovoitov 	BPF_MAP_TYPE_STACK_TRACE,
1094ed8ec52SMartin KaFai Lau 	BPF_MAP_TYPE_CGROUP_ARRAY,
11029ba732aSMartin KaFai Lau 	BPF_MAP_TYPE_LRU_HASH,
1118f844938SMartin KaFai Lau 	BPF_MAP_TYPE_LRU_PERCPU_HASH,
112b95a5c4dSDaniel Mack 	BPF_MAP_TYPE_LPM_TRIE,
11356f668dfSMartin KaFai Lau 	BPF_MAP_TYPE_ARRAY_OF_MAPS,
114bcc6b1b7SMartin KaFai Lau 	BPF_MAP_TYPE_HASH_OF_MAPS,
115546ac1ffSJohn Fastabend 	BPF_MAP_TYPE_DEVMAP,
116174a79ffSJohn Fastabend 	BPF_MAP_TYPE_SOCKMAP,
1176710e112SJesper Dangaard Brouer 	BPF_MAP_TYPE_CPUMAP,
11899c55f7dSAlexei Starovoitov };
11999c55f7dSAlexei Starovoitov 
12009756af4SAlexei Starovoitov enum bpf_prog_type {
12109756af4SAlexei Starovoitov 	BPF_PROG_TYPE_UNSPEC,
122ddd872bcSAlexei Starovoitov 	BPF_PROG_TYPE_SOCKET_FILTER,
1232541517cSAlexei Starovoitov 	BPF_PROG_TYPE_KPROBE,
12496be4325SDaniel Borkmann 	BPF_PROG_TYPE_SCHED_CLS,
12594caee8cSDaniel Borkmann 	BPF_PROG_TYPE_SCHED_ACT,
12698b5c2c6SAlexei Starovoitov 	BPF_PROG_TYPE_TRACEPOINT,
1276a773a15SBrenden Blanco 	BPF_PROG_TYPE_XDP,
1280515e599SAlexei Starovoitov 	BPF_PROG_TYPE_PERF_EVENT,
1290e33661dSDaniel Mack 	BPF_PROG_TYPE_CGROUP_SKB,
13061023658SDavid Ahern 	BPF_PROG_TYPE_CGROUP_SOCK,
1313a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_IN,
1323a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_OUT,
1333a0af8fdSThomas Graf 	BPF_PROG_TYPE_LWT_XMIT,
13440304b2aSLawrence Brakmo 	BPF_PROG_TYPE_SOCK_OPS,
135b005fd18SJohn Fastabend 	BPF_PROG_TYPE_SK_SKB,
136ebc614f6SRoman Gushchin 	BPF_PROG_TYPE_CGROUP_DEVICE,
1374f738adbSJohn Fastabend 	BPF_PROG_TYPE_SK_MSG,
138c4f6699dSAlexei Starovoitov 	BPF_PROG_TYPE_RAW_TRACEPOINT,
1394fbac77dSAndrey Ignatov 	BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
14009756af4SAlexei Starovoitov };
14109756af4SAlexei Starovoitov 
1420e33661dSDaniel Mack enum bpf_attach_type {
1430e33661dSDaniel Mack 	BPF_CGROUP_INET_INGRESS,
1440e33661dSDaniel Mack 	BPF_CGROUP_INET_EGRESS,
14561023658SDavid Ahern 	BPF_CGROUP_INET_SOCK_CREATE,
14640304b2aSLawrence Brakmo 	BPF_CGROUP_SOCK_OPS,
147464bc0fdSJohn Fastabend 	BPF_SK_SKB_STREAM_PARSER,
148464bc0fdSJohn Fastabend 	BPF_SK_SKB_STREAM_VERDICT,
149ebc614f6SRoman Gushchin 	BPF_CGROUP_DEVICE,
1504f738adbSJohn Fastabend 	BPF_SK_MSG_VERDICT,
1514fbac77dSAndrey Ignatov 	BPF_CGROUP_INET4_BIND,
1524fbac77dSAndrey Ignatov 	BPF_CGROUP_INET6_BIND,
153*d74bad4eSAndrey Ignatov 	BPF_CGROUP_INET4_CONNECT,
154*d74bad4eSAndrey Ignatov 	BPF_CGROUP_INET6_CONNECT,
1550e33661dSDaniel Mack 	__MAX_BPF_ATTACH_TYPE
1560e33661dSDaniel Mack };
1570e33661dSDaniel Mack 
1580e33661dSDaniel Mack #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
1590e33661dSDaniel Mack 
160324bda9eSAlexei Starovoitov /* cgroup-bpf attach flags used in BPF_PROG_ATTACH command
161324bda9eSAlexei Starovoitov  *
162324bda9eSAlexei Starovoitov  * NONE(default): No further bpf programs allowed in the subtree.
163324bda9eSAlexei Starovoitov  *
164324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_OVERRIDE: If a sub-cgroup installs some bpf program,
165324bda9eSAlexei Starovoitov  * the program in this cgroup yields to sub-cgroup program.
166324bda9eSAlexei Starovoitov  *
167324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_MULTI: If a sub-cgroup installs some bpf program,
168324bda9eSAlexei Starovoitov  * that cgroup program gets run in addition to the program in this cgroup.
169324bda9eSAlexei Starovoitov  *
170324bda9eSAlexei Starovoitov  * Only one program is allowed to be attached to a cgroup with
171324bda9eSAlexei Starovoitov  * NONE or BPF_F_ALLOW_OVERRIDE flag.
172324bda9eSAlexei Starovoitov  * Attaching another program on top of NONE or BPF_F_ALLOW_OVERRIDE will
173324bda9eSAlexei Starovoitov  * release old program and attach the new one. Attach flags has to match.
174324bda9eSAlexei Starovoitov  *
175324bda9eSAlexei Starovoitov  * Multiple programs are allowed to be attached to a cgroup with
176324bda9eSAlexei Starovoitov  * BPF_F_ALLOW_MULTI flag. They are executed in FIFO order
177324bda9eSAlexei Starovoitov  * (those that were attached first, run first)
178324bda9eSAlexei Starovoitov  * The programs of sub-cgroup are executed first, then programs of
179324bda9eSAlexei Starovoitov  * this cgroup and then programs of parent cgroup.
180324bda9eSAlexei Starovoitov  * When children program makes decision (like picking TCP CA or sock bind)
181324bda9eSAlexei Starovoitov  * parent program has a chance to override it.
182324bda9eSAlexei Starovoitov  *
183324bda9eSAlexei Starovoitov  * A cgroup with MULTI or OVERRIDE flag allows any attach flags in sub-cgroups.
184324bda9eSAlexei Starovoitov  * A cgroup with NONE doesn't allow any programs in sub-cgroups.
185324bda9eSAlexei Starovoitov  * Ex1:
186324bda9eSAlexei Starovoitov  * cgrp1 (MULTI progs A, B) ->
187324bda9eSAlexei Starovoitov  *    cgrp2 (OVERRIDE prog C) ->
188324bda9eSAlexei Starovoitov  *      cgrp3 (MULTI prog D) ->
189324bda9eSAlexei Starovoitov  *        cgrp4 (OVERRIDE prog E) ->
190324bda9eSAlexei Starovoitov  *          cgrp5 (NONE prog F)
191324bda9eSAlexei Starovoitov  * the event in cgrp5 triggers execution of F,D,A,B in that order.
192324bda9eSAlexei Starovoitov  * if prog F is detached, the execution is E,D,A,B
193324bda9eSAlexei Starovoitov  * if prog F and D are detached, the execution is E,A,B
194324bda9eSAlexei Starovoitov  * if prog F, E and D are detached, the execution is C,A,B
195324bda9eSAlexei Starovoitov  *
196324bda9eSAlexei Starovoitov  * All eligible programs are executed regardless of return code from
197324bda9eSAlexei Starovoitov  * earlier programs.
1987f677633SAlexei Starovoitov  */
1997f677633SAlexei Starovoitov #define BPF_F_ALLOW_OVERRIDE	(1U << 0)
200324bda9eSAlexei Starovoitov #define BPF_F_ALLOW_MULTI	(1U << 1)
2017f677633SAlexei Starovoitov 
202e07b98d9SDavid S. Miller /* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the
203e07b98d9SDavid S. Miller  * verifier will perform strict alignment checking as if the kernel
204e07b98d9SDavid S. Miller  * has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set,
205e07b98d9SDavid S. Miller  * and NET_IP_ALIGN defined to 2.
206e07b98d9SDavid S. Miller  */
207e07b98d9SDavid S. Miller #define BPF_F_STRICT_ALIGNMENT	(1U << 0)
208e07b98d9SDavid S. Miller 
209cc8b0b92SAlexei Starovoitov /* when bpf_ldimm64->src_reg == BPF_PSEUDO_MAP_FD, bpf_ldimm64->imm == fd */
210f1a66f85SDaniel Borkmann #define BPF_PSEUDO_MAP_FD	1
211f1a66f85SDaniel Borkmann 
212cc8b0b92SAlexei Starovoitov /* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative
213cc8b0b92SAlexei Starovoitov  * offset to another bpf function
214cc8b0b92SAlexei Starovoitov  */
215cc8b0b92SAlexei Starovoitov #define BPF_PSEUDO_CALL		1
216cc8b0b92SAlexei Starovoitov 
2173274f520SAlexei Starovoitov /* flags for BPF_MAP_UPDATE_ELEM command */
2183274f520SAlexei Starovoitov #define BPF_ANY		0 /* create new element or update existing */
2193274f520SAlexei Starovoitov #define BPF_NOEXIST	1 /* create new element if it didn't exist */
2203274f520SAlexei Starovoitov #define BPF_EXIST	2 /* update existing element */
2213274f520SAlexei Starovoitov 
22296eabe7aSMartin KaFai Lau /* flags for BPF_MAP_CREATE command */
2236c905981SAlexei Starovoitov #define BPF_F_NO_PREALLOC	(1U << 0)
22429ba732aSMartin KaFai Lau /* Instead of having one common LRU list in the
2258f844938SMartin KaFai Lau  * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list
22629ba732aSMartin KaFai Lau  * which can scale and perform better.
22729ba732aSMartin KaFai Lau  * Note, the LRU nodes (including free nodes) cannot be moved
22829ba732aSMartin KaFai Lau  * across different LRU lists.
22929ba732aSMartin KaFai Lau  */
23029ba732aSMartin KaFai Lau #define BPF_F_NO_COMMON_LRU	(1U << 1)
23196eabe7aSMartin KaFai Lau /* Specify numa node during map creation */
23296eabe7aSMartin KaFai Lau #define BPF_F_NUMA_NODE		(1U << 2)
2336c905981SAlexei Starovoitov 
234468e2f64SAlexei Starovoitov /* flags for BPF_PROG_QUERY */
235468e2f64SAlexei Starovoitov #define BPF_F_QUERY_EFFECTIVE	(1U << 0)
236468e2f64SAlexei Starovoitov 
237cb4d2b3fSMartin KaFai Lau #define BPF_OBJ_NAME_LEN 16U
238cb4d2b3fSMartin KaFai Lau 
2396e71b04aSChenbo Feng /* Flags for accessing BPF object */
2406e71b04aSChenbo Feng #define BPF_F_RDONLY		(1U << 3)
2416e71b04aSChenbo Feng #define BPF_F_WRONLY		(1U << 4)
2426e71b04aSChenbo Feng 
243615755a7SSong Liu /* Flag for stack_map, store build_id+offset instead of pointer */
244615755a7SSong Liu #define BPF_F_STACK_BUILD_ID	(1U << 5)
245615755a7SSong Liu 
246615755a7SSong Liu enum bpf_stack_build_id_status {
247615755a7SSong Liu 	/* user space need an empty entry to identify end of a trace */
248615755a7SSong Liu 	BPF_STACK_BUILD_ID_EMPTY = 0,
249615755a7SSong Liu 	/* with valid build_id and offset */
250615755a7SSong Liu 	BPF_STACK_BUILD_ID_VALID = 1,
251615755a7SSong Liu 	/* couldn't get build_id, fallback to ip */
252615755a7SSong Liu 	BPF_STACK_BUILD_ID_IP = 2,
253615755a7SSong Liu };
254615755a7SSong Liu 
255615755a7SSong Liu #define BPF_BUILD_ID_SIZE 20
256615755a7SSong Liu struct bpf_stack_build_id {
257615755a7SSong Liu 	__s32		status;
258615755a7SSong Liu 	unsigned char	build_id[BPF_BUILD_ID_SIZE];
259615755a7SSong Liu 	union {
260615755a7SSong Liu 		__u64	offset;
261615755a7SSong Liu 		__u64	ip;
262615755a7SSong Liu 	};
263615755a7SSong Liu };
264615755a7SSong Liu 
26599c55f7dSAlexei Starovoitov union bpf_attr {
26699c55f7dSAlexei Starovoitov 	struct { /* anonymous struct used by BPF_MAP_CREATE command */
26799c55f7dSAlexei Starovoitov 		__u32	map_type;	/* one of enum bpf_map_type */
26899c55f7dSAlexei Starovoitov 		__u32	key_size;	/* size of key in bytes */
26999c55f7dSAlexei Starovoitov 		__u32	value_size;	/* size of value in bytes */
27099c55f7dSAlexei Starovoitov 		__u32	max_entries;	/* max number of entries in a map */
27196eabe7aSMartin KaFai Lau 		__u32	map_flags;	/* BPF_MAP_CREATE related
27296eabe7aSMartin KaFai Lau 					 * flags defined above.
27396eabe7aSMartin KaFai Lau 					 */
27456f668dfSMartin KaFai Lau 		__u32	inner_map_fd;	/* fd pointing to the inner map */
27596eabe7aSMartin KaFai Lau 		__u32	numa_node;	/* numa node (effective only if
27696eabe7aSMartin KaFai Lau 					 * BPF_F_NUMA_NODE is set).
27796eabe7aSMartin KaFai Lau 					 */
278067cae47SMartin KaFai Lau 		char	map_name[BPF_OBJ_NAME_LEN];
279a3884572SJakub Kicinski 		__u32	map_ifindex;	/* ifindex of netdev to create on */
28099c55f7dSAlexei Starovoitov 	};
281db20fd2bSAlexei Starovoitov 
282db20fd2bSAlexei Starovoitov 	struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
283db20fd2bSAlexei Starovoitov 		__u32		map_fd;
284db20fd2bSAlexei Starovoitov 		__aligned_u64	key;
285db20fd2bSAlexei Starovoitov 		union {
286db20fd2bSAlexei Starovoitov 			__aligned_u64 value;
287db20fd2bSAlexei Starovoitov 			__aligned_u64 next_key;
288db20fd2bSAlexei Starovoitov 		};
2893274f520SAlexei Starovoitov 		__u64		flags;
290db20fd2bSAlexei Starovoitov 	};
29109756af4SAlexei Starovoitov 
29209756af4SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_LOAD command */
29309756af4SAlexei Starovoitov 		__u32		prog_type;	/* one of enum bpf_prog_type */
29409756af4SAlexei Starovoitov 		__u32		insn_cnt;
29509756af4SAlexei Starovoitov 		__aligned_u64	insns;
29609756af4SAlexei Starovoitov 		__aligned_u64	license;
297cbd35700SAlexei Starovoitov 		__u32		log_level;	/* verbosity level of verifier */
298cbd35700SAlexei Starovoitov 		__u32		log_size;	/* size of user buffer */
299cbd35700SAlexei Starovoitov 		__aligned_u64	log_buf;	/* user supplied buffer */
3002541517cSAlexei Starovoitov 		__u32		kern_version;	/* checked when prog_type=kprobe */
301e07b98d9SDavid S. Miller 		__u32		prog_flags;
302067cae47SMartin KaFai Lau 		char		prog_name[BPF_OBJ_NAME_LEN];
3031f6f4cb7SJakub Kicinski 		__u32		prog_ifindex;	/* ifindex of netdev to prep for */
3045e43f899SAndrey Ignatov 		/* For some prog types expected attach type must be known at
3055e43f899SAndrey Ignatov 		 * load time to verify attach type specific parts of prog
3065e43f899SAndrey Ignatov 		 * (context accesses, allowed helpers, etc).
3075e43f899SAndrey Ignatov 		 */
3085e43f899SAndrey Ignatov 		__u32		expected_attach_type;
30909756af4SAlexei Starovoitov 	};
310b2197755SDaniel Borkmann 
311b2197755SDaniel Borkmann 	struct { /* anonymous struct used by BPF_OBJ_* commands */
312b2197755SDaniel Borkmann 		__aligned_u64	pathname;
313b2197755SDaniel Borkmann 		__u32		bpf_fd;
3146e71b04aSChenbo Feng 		__u32		file_flags;
315b2197755SDaniel Borkmann 	};
316f4324551SDaniel Mack 
317f4324551SDaniel Mack 	struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
318f4324551SDaniel Mack 		__u32		target_fd;	/* container object to attach to */
319f4324551SDaniel Mack 		__u32		attach_bpf_fd;	/* eBPF program to attach */
320f4324551SDaniel Mack 		__u32		attach_type;
3217f677633SAlexei Starovoitov 		__u32		attach_flags;
322f4324551SDaniel Mack 	};
3231cf1cae9SAlexei Starovoitov 
3241cf1cae9SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
3251cf1cae9SAlexei Starovoitov 		__u32		prog_fd;
3261cf1cae9SAlexei Starovoitov 		__u32		retval;
3271cf1cae9SAlexei Starovoitov 		__u32		data_size_in;
3281cf1cae9SAlexei Starovoitov 		__u32		data_size_out;
3291cf1cae9SAlexei Starovoitov 		__aligned_u64	data_in;
3301cf1cae9SAlexei Starovoitov 		__aligned_u64	data_out;
3311cf1cae9SAlexei Starovoitov 		__u32		repeat;
3321cf1cae9SAlexei Starovoitov 		__u32		duration;
3331cf1cae9SAlexei Starovoitov 	} test;
33434ad5580SMartin KaFai Lau 
335b16d9aa4SMartin KaFai Lau 	struct { /* anonymous struct used by BPF_*_GET_*_ID */
336b16d9aa4SMartin KaFai Lau 		union {
33734ad5580SMartin KaFai Lau 			__u32		start_id;
338b16d9aa4SMartin KaFai Lau 			__u32		prog_id;
339bd5f5f4eSMartin KaFai Lau 			__u32		map_id;
340b16d9aa4SMartin KaFai Lau 		};
34134ad5580SMartin KaFai Lau 		__u32		next_id;
3426e71b04aSChenbo Feng 		__u32		open_flags;
34334ad5580SMartin KaFai Lau 	};
3441e270976SMartin KaFai Lau 
3451e270976SMartin KaFai Lau 	struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
3461e270976SMartin KaFai Lau 		__u32		bpf_fd;
3471e270976SMartin KaFai Lau 		__u32		info_len;
3481e270976SMartin KaFai Lau 		__aligned_u64	info;
3491e270976SMartin KaFai Lau 	} info;
350468e2f64SAlexei Starovoitov 
351468e2f64SAlexei Starovoitov 	struct { /* anonymous struct used by BPF_PROG_QUERY command */
352468e2f64SAlexei Starovoitov 		__u32		target_fd;	/* container object to query */
353468e2f64SAlexei Starovoitov 		__u32		attach_type;
354468e2f64SAlexei Starovoitov 		__u32		query_flags;
355468e2f64SAlexei Starovoitov 		__u32		attach_flags;
356468e2f64SAlexei Starovoitov 		__aligned_u64	prog_ids;
357468e2f64SAlexei Starovoitov 		__u32		prog_cnt;
358468e2f64SAlexei Starovoitov 	} query;
359c4f6699dSAlexei Starovoitov 
360c4f6699dSAlexei Starovoitov 	struct {
361c4f6699dSAlexei Starovoitov 		__u64 name;
362c4f6699dSAlexei Starovoitov 		__u32 prog_fd;
363c4f6699dSAlexei Starovoitov 	} raw_tracepoint;
36499c55f7dSAlexei Starovoitov } __attribute__((aligned(8)));
36599c55f7dSAlexei Starovoitov 
366ebb676daSThomas Graf /* BPF helper function descriptions:
367ebb676daSThomas Graf  *
368ebb676daSThomas Graf  * void *bpf_map_lookup_elem(&map, &key)
369ebb676daSThomas Graf  *     Return: Map value or NULL
370ebb676daSThomas Graf  *
371ebb676daSThomas Graf  * int bpf_map_update_elem(&map, &key, &value, flags)
372ebb676daSThomas Graf  *     Return: 0 on success or negative error
373ebb676daSThomas Graf  *
374ebb676daSThomas Graf  * int bpf_map_delete_elem(&map, &key)
375ebb676daSThomas Graf  *     Return: 0 on success or negative error
376ebb676daSThomas Graf  *
377ebb676daSThomas Graf  * int bpf_probe_read(void *dst, int size, void *src)
378ebb676daSThomas Graf  *     Return: 0 on success or negative error
379ebb676daSThomas Graf  *
380ebb676daSThomas Graf  * u64 bpf_ktime_get_ns(void)
381ebb676daSThomas Graf  *     Return: current ktime
382ebb676daSThomas Graf  *
383ebb676daSThomas Graf  * int bpf_trace_printk(const char *fmt, int fmt_size, ...)
384ebb676daSThomas Graf  *     Return: length of buffer written or negative error
385ebb676daSThomas Graf  *
386ebb676daSThomas Graf  * u32 bpf_prandom_u32(void)
387ebb676daSThomas Graf  *     Return: random value
388ebb676daSThomas Graf  *
389ebb676daSThomas Graf  * u32 bpf_raw_smp_processor_id(void)
390ebb676daSThomas Graf  *     Return: SMP processor ID
391ebb676daSThomas Graf  *
392ebb676daSThomas Graf  * int bpf_skb_store_bytes(skb, offset, from, len, flags)
393ebb676daSThomas Graf  *     store bytes into packet
39491bc4822SAlexei Starovoitov  *     @skb: pointer to skb
395a166151cSAlexei Starovoitov  *     @offset: offset within packet from skb->mac_header
39691bc4822SAlexei Starovoitov  *     @from: pointer where to copy bytes from
39791bc4822SAlexei Starovoitov  *     @len: number of bytes to store into packet
39891bc4822SAlexei Starovoitov  *     @flags: bit 0 - if true, recompute skb->csum
39991bc4822SAlexei Starovoitov  *             other bits - reserved
400ebb676daSThomas Graf  *     Return: 0 on success or negative error
401ebb676daSThomas Graf  *
402ebb676daSThomas Graf  * int bpf_l3_csum_replace(skb, offset, from, to, flags)
403ebb676daSThomas Graf  *     recompute IP checksum
40491bc4822SAlexei Starovoitov  *     @skb: pointer to skb
40591bc4822SAlexei Starovoitov  *     @offset: offset within packet where IP checksum is located
40691bc4822SAlexei Starovoitov  *     @from: old value of header field
40791bc4822SAlexei Starovoitov  *     @to: new value of header field
40891bc4822SAlexei Starovoitov  *     @flags: bits 0-3 - size of header field
40991bc4822SAlexei Starovoitov  *             other bits - reserved
410ebb676daSThomas Graf  *     Return: 0 on success or negative error
411ebb676daSThomas Graf  *
412ebb676daSThomas Graf  * int bpf_l4_csum_replace(skb, offset, from, to, flags)
413ebb676daSThomas Graf  *     recompute TCP/UDP checksum
41491bc4822SAlexei Starovoitov  *     @skb: pointer to skb
41591bc4822SAlexei Starovoitov  *     @offset: offset within packet where TCP/UDP checksum is located
41691bc4822SAlexei Starovoitov  *     @from: old value of header field
41791bc4822SAlexei Starovoitov  *     @to: new value of header field
41891bc4822SAlexei Starovoitov  *     @flags: bits 0-3 - size of header field
41991bc4822SAlexei Starovoitov  *             bit 4 - is pseudo header
42091bc4822SAlexei Starovoitov  *             other bits - reserved
421ebb676daSThomas Graf  *     Return: 0 on success or negative error
422ebb676daSThomas Graf  *
423ebb676daSThomas Graf  * int bpf_tail_call(ctx, prog_array_map, index)
424ebb676daSThomas Graf  *     jump into another BPF program
42504fd61abSAlexei Starovoitov  *     @ctx: context pointer passed to next program
42604fd61abSAlexei Starovoitov  *     @prog_array_map: pointer to map which type is BPF_MAP_TYPE_PROG_ARRAY
42790caccddSAlexei Starovoitov  *     @index: 32-bit index inside array that selects specific program to run
428ebb676daSThomas Graf  *     Return: 0 on success or negative error
429ebb676daSThomas Graf  *
430ebb676daSThomas Graf  * int bpf_clone_redirect(skb, ifindex, flags)
431ebb676daSThomas Graf  *     redirect to another netdev
4323896d655SAlexei Starovoitov  *     @skb: pointer to skb
4333896d655SAlexei Starovoitov  *     @ifindex: ifindex of the net device
4343896d655SAlexei Starovoitov  *     @flags: bit 0 - if set, redirect to ingress instead of egress
4353896d655SAlexei Starovoitov  *             other bits - reserved
436ebb676daSThomas Graf  *     Return: 0 on success or negative error
437ebb676daSThomas Graf  *
438ffeedafbSAlexei Starovoitov  * u64 bpf_get_current_pid_tgid(void)
439ffeedafbSAlexei Starovoitov  *     Return: current->tgid << 32 | current->pid
440ebb676daSThomas Graf  *
441ffeedafbSAlexei Starovoitov  * u64 bpf_get_current_uid_gid(void)
442ffeedafbSAlexei Starovoitov  *     Return: current_gid << 32 | current_uid
443ebb676daSThomas Graf  *
444ebb676daSThomas Graf  * int bpf_get_current_comm(char *buf, int size_of_buf)
445ffeedafbSAlexei Starovoitov  *     stores current->comm into buf
446ebb676daSThomas Graf  *     Return: 0 on success or negative error
447ebb676daSThomas Graf  *
448ebb676daSThomas Graf  * u32 bpf_get_cgroup_classid(skb)
449ebb676daSThomas Graf  *     retrieve a proc's classid
4508d20aabeSDaniel Borkmann  *     @skb: pointer to skb
4518d20aabeSDaniel Borkmann  *     Return: classid if != 0
452ebb676daSThomas Graf  *
453ebb676daSThomas Graf  * int bpf_skb_vlan_push(skb, vlan_proto, vlan_tci)
454ebb676daSThomas Graf  *     Return: 0 on success or negative error
455ebb676daSThomas Graf  *
456ebb676daSThomas Graf  * int bpf_skb_vlan_pop(skb)
457ebb676daSThomas Graf  *     Return: 0 on success or negative error
458ebb676daSThomas Graf  *
459ebb676daSThomas Graf  * int bpf_skb_get_tunnel_key(skb, key, size, flags)
460ebb676daSThomas Graf  * int bpf_skb_set_tunnel_key(skb, key, size, flags)
461d3aa45ceSAlexei Starovoitov  *     retrieve or populate tunnel metadata
462d3aa45ceSAlexei Starovoitov  *     @skb: pointer to skb
463d3aa45ceSAlexei Starovoitov  *     @key: pointer to 'struct bpf_tunnel_key'
464d3aa45ceSAlexei Starovoitov  *     @size: size of 'struct bpf_tunnel_key'
465d3aa45ceSAlexei Starovoitov  *     @flags: room for future extensions
466ebb676daSThomas Graf  *     Return: 0 on success or negative error
467ebb676daSThomas Graf  *
468b7d3ed5bSTeng Qin  * u64 bpf_perf_event_read(map, flags)
469b7d3ed5bSTeng Qin  *     read perf event counter value
470b7d3ed5bSTeng Qin  *     @map: pointer to perf_event_array map
471b7d3ed5bSTeng Qin  *     @flags: index of event in the map or bitmask flags
472b7d3ed5bSTeng Qin  *     Return: value of perf event counter read or error code
473ebb676daSThomas Graf  *
474ebb676daSThomas Graf  * int bpf_redirect(ifindex, flags)
475ebb676daSThomas Graf  *     redirect to another netdev
47627b29f63SAlexei Starovoitov  *     @ifindex: ifindex of the net device
47756ce097cSJohn Fastabend  *     @flags:
47856ce097cSJohn Fastabend  *	  cls_bpf:
47956ce097cSJohn Fastabend  *          bit 0 - if set, redirect to ingress instead of egress
48027b29f63SAlexei Starovoitov  *          other bits - reserved
48156ce097cSJohn Fastabend  *	  xdp_bpf:
48256ce097cSJohn Fastabend  *	    all bits - reserved
48356ce097cSJohn Fastabend  *     Return: cls_bpf: TC_ACT_REDIRECT on success or TC_ACT_SHOT on error
48456ce097cSJohn Fastabend  *	       xdp_bfp: XDP_REDIRECT on success or XDP_ABORT on error
48556ce097cSJohn Fastabend  * int bpf_redirect_map(map, key, flags)
48697f91a7cSJohn Fastabend  *     redirect to endpoint in map
48756ce097cSJohn Fastabend  *     @map: pointer to dev map
48897f91a7cSJohn Fastabend  *     @key: index in map to lookup
48997f91a7cSJohn Fastabend  *     @flags: --
49056ce097cSJohn Fastabend  *     Return: XDP_REDIRECT on success or XDP_ABORT on error
491ebb676daSThomas Graf  *
492ebb676daSThomas Graf  * u32 bpf_get_route_realm(skb)
493ebb676daSThomas Graf  *     retrieve a dst's tclassid
494c46646d0SDaniel Borkmann  *     @skb: pointer to skb
495c46646d0SDaniel Borkmann  *     Return: realm if != 0
496ebb676daSThomas Graf  *
497b7d3ed5bSTeng Qin  * int bpf_perf_event_output(ctx, map, flags, data, size)
498ebb676daSThomas Graf  *     output perf raw sample
499a43eec30SAlexei Starovoitov  *     @ctx: struct pt_regs*
500a43eec30SAlexei Starovoitov  *     @map: pointer to perf_event_array map
501b7d3ed5bSTeng Qin  *     @flags: index of event in the map or bitmask flags
502a43eec30SAlexei Starovoitov  *     @data: data on stack to be output as raw data
503a43eec30SAlexei Starovoitov  *     @size: size of data
504ebb676daSThomas Graf  *     Return: 0 on success or negative error
505ebb676daSThomas Graf  *
506ebb676daSThomas Graf  * int bpf_get_stackid(ctx, map, flags)
507ebb676daSThomas Graf  *     walk user or kernel stack and return id
508d5a3b1f6SAlexei Starovoitov  *     @ctx: struct pt_regs*
509d5a3b1f6SAlexei Starovoitov  *     @map: pointer to stack_trace map
510d5a3b1f6SAlexei Starovoitov  *     @flags: bits 0-7 - numer of stack frames to skip
511d5a3b1f6SAlexei Starovoitov  *             bit 8 - collect user stack instead of kernel
512d5a3b1f6SAlexei Starovoitov  *             bit 9 - compare stacks by hash only
513d5a3b1f6SAlexei Starovoitov  *             bit 10 - if two different stacks hash into the same stackid
514d5a3b1f6SAlexei Starovoitov  *                      discard old
515d5a3b1f6SAlexei Starovoitov  *             other bits - reserved
516d5a3b1f6SAlexei Starovoitov  *     Return: >= 0 stackid on success or negative error
517ebb676daSThomas Graf  *
518ebb676daSThomas Graf  * s64 bpf_csum_diff(from, from_size, to, to_size, seed)
519ebb676daSThomas Graf  *     calculate csum diff
5207d672345SDaniel Borkmann  *     @from: raw from buffer
5217d672345SDaniel Borkmann  *     @from_size: length of from buffer
5227d672345SDaniel Borkmann  *     @to: raw to buffer
5237d672345SDaniel Borkmann  *     @to_size: length of to buffer
5247d672345SDaniel Borkmann  *     @seed: optional seed
525ebb676daSThomas Graf  *     Return: csum result or negative error code
526ebb676daSThomas Graf  *
527ebb676daSThomas Graf  * int bpf_skb_get_tunnel_opt(skb, opt, size)
528ebb676daSThomas Graf  *     retrieve tunnel options metadata
52914ca0751SDaniel Borkmann  *     @skb: pointer to skb
53014ca0751SDaniel Borkmann  *     @opt: pointer to raw tunnel option data
53114ca0751SDaniel Borkmann  *     @size: size of @opt
532ebb676daSThomas Graf  *     Return: option size
533ebb676daSThomas Graf  *
534ebb676daSThomas Graf  * int bpf_skb_set_tunnel_opt(skb, opt, size)
535ebb676daSThomas Graf  *     populate tunnel options metadata
536ebb676daSThomas Graf  *     @skb: pointer to skb
537ebb676daSThomas Graf  *     @opt: pointer to raw tunnel option data
538ebb676daSThomas Graf  *     @size: size of @opt
539ebb676daSThomas Graf  *     Return: 0 on success or negative error
540ebb676daSThomas Graf  *
541ebb676daSThomas Graf  * int bpf_skb_change_proto(skb, proto, flags)
542ebb676daSThomas Graf  *     Change protocol of the skb. Currently supported is v4 -> v6,
543ebb676daSThomas Graf  *     v6 -> v4 transitions. The helper will also resize the skb. eBPF
544ebb676daSThomas Graf  *     program is expected to fill the new headers via skb_store_bytes
545ebb676daSThomas Graf  *     and lX_csum_replace.
5466578171aSDaniel Borkmann  *     @skb: pointer to skb
5476578171aSDaniel Borkmann  *     @proto: new skb->protocol type
5486578171aSDaniel Borkmann  *     @flags: reserved
5496578171aSDaniel Borkmann  *     Return: 0 on success or negative error
550ebb676daSThomas Graf  *
551ebb676daSThomas Graf  * int bpf_skb_change_type(skb, type)
552d2485c42SDaniel Borkmann  *     Change packet type of skb.
553d2485c42SDaniel Borkmann  *     @skb: pointer to skb
554d2485c42SDaniel Borkmann  *     @type: new skb->pkt_type type
555d2485c42SDaniel Borkmann  *     Return: 0 on success or negative error
556ebb676daSThomas Graf  *
557ebb676daSThomas Graf  * int bpf_skb_under_cgroup(skb, map, index)
558ebb676daSThomas Graf  *     Check cgroup2 membership of skb
5594a482f34SMartin KaFai Lau  *     @skb: pointer to skb
5604a482f34SMartin KaFai Lau  *     @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
5614a482f34SMartin KaFai Lau  *     @index: index of the cgroup in the bpf_map
5624a482f34SMartin KaFai Lau  *     Return:
5634a482f34SMartin KaFai Lau  *       == 0 skb failed the cgroup2 descendant test
5644a482f34SMartin KaFai Lau  *       == 1 skb succeeded the cgroup2 descendant test
5654a482f34SMartin KaFai Lau  *        < 0 error
566ebb676daSThomas Graf  *
567ebb676daSThomas Graf  * u32 bpf_get_hash_recalc(skb)
56813c5c240SDaniel Borkmann  *     Retrieve and possibly recalculate skb->hash.
56913c5c240SDaniel Borkmann  *     @skb: pointer to skb
57013c5c240SDaniel Borkmann  *     Return: hash
571ebb676daSThomas Graf  *
572606274c5SAlexei Starovoitov  * u64 bpf_get_current_task(void)
573606274c5SAlexei Starovoitov  *     Returns current task_struct
574606274c5SAlexei Starovoitov  *     Return: current
575ebb676daSThomas Graf  *
576ebb676daSThomas Graf  * int bpf_probe_write_user(void *dst, void *src, int len)
57796ae5227SSargun Dhillon  *     safely attempt to write to a location
57896ae5227SSargun Dhillon  *     @dst: destination address in userspace
57996ae5227SSargun Dhillon  *     @src: source address on stack
58096ae5227SSargun Dhillon  *     @len: number of bytes to copy
58196ae5227SSargun Dhillon  *     Return: 0 on success or negative error
582ebb676daSThomas Graf  *
583ebb676daSThomas Graf  * int bpf_current_task_under_cgroup(map, index)
584ebb676daSThomas Graf  *     Check cgroup2 membership of current task
58560d20f91SSargun Dhillon  *     @map: pointer to bpf_map in BPF_MAP_TYPE_CGROUP_ARRAY type
58660d20f91SSargun Dhillon  *     @index: index of the cgroup in the bpf_map
58760d20f91SSargun Dhillon  *     Return:
58860d20f91SSargun Dhillon  *       == 0 current failed the cgroup2 descendant test
58960d20f91SSargun Dhillon  *       == 1 current succeeded the cgroup2 descendant test
59060d20f91SSargun Dhillon  *        < 0 error
591ebb676daSThomas Graf  *
592ebb676daSThomas Graf  * int bpf_skb_change_tail(skb, len, flags)
593ebb676daSThomas Graf  *     The helper will resize the skb to the given new size, to be used f.e.
594ebb676daSThomas Graf  *     with control messages.
5955293efe6SDaniel Borkmann  *     @skb: pointer to skb
5965293efe6SDaniel Borkmann  *     @len: new skb length
5975293efe6SDaniel Borkmann  *     @flags: reserved
5985293efe6SDaniel Borkmann  *     Return: 0 on success or negative error
599ebb676daSThomas Graf  *
600ebb676daSThomas Graf  * int bpf_skb_pull_data(skb, len)
601ebb676daSThomas Graf  *     The helper will pull in non-linear data in case the skb is non-linear
602ebb676daSThomas Graf  *     and not all of len are part of the linear section. Only needed for
603ebb676daSThomas Graf  *     read/write with direct packet access.
60436bbef52SDaniel Borkmann  *     @skb: pointer to skb
60536bbef52SDaniel Borkmann  *     @len: len to make read/writeable
60636bbef52SDaniel Borkmann  *     Return: 0 on success or negative error
607ebb676daSThomas Graf  *
608ebb676daSThomas Graf  * s64 bpf_csum_update(skb, csum)
60936bbef52SDaniel Borkmann  *     Adds csum into skb->csum in case of CHECKSUM_COMPLETE.
61036bbef52SDaniel Borkmann  *     @skb: pointer to skb
61136bbef52SDaniel Borkmann  *     @csum: csum to add
61236bbef52SDaniel Borkmann  *     Return: csum on success or negative error
613ebb676daSThomas Graf  *
614ebb676daSThomas Graf  * void bpf_set_hash_invalid(skb)
615ebb676daSThomas Graf  *     Invalidate current skb->hash.
6167a4b28c6SDaniel Borkmann  *     @skb: pointer to skb
617ebb676daSThomas Graf  *
618ebb676daSThomas Graf  * int bpf_get_numa_node_id()
619ebb676daSThomas Graf  *     Return: Id of current NUMA node.
6203a0af8fdSThomas Graf  *
6213a0af8fdSThomas Graf  * int bpf_skb_change_head()
6223a0af8fdSThomas Graf  *     Grows headroom of skb and adjusts MAC header offset accordingly.
6233a0af8fdSThomas Graf  *     Will extends/reallocae as required automatically.
6243a0af8fdSThomas Graf  *     May change skb data pointer and will thus invalidate any check
6253a0af8fdSThomas Graf  *     performed for direct packet access.
6263a0af8fdSThomas Graf  *     @skb: pointer to skb
6273a0af8fdSThomas Graf  *     @len: length of header to be pushed in front
6283a0af8fdSThomas Graf  *     @flags: Flags (unused for now)
6293a0af8fdSThomas Graf  *     Return: 0 on success or negative error
63017bedab2SMartin KaFai Lau  *
63117bedab2SMartin KaFai Lau  * int bpf_xdp_adjust_head(xdp_md, delta)
63217bedab2SMartin KaFai Lau  *     Adjust the xdp_md.data by delta
63317bedab2SMartin KaFai Lau  *     @xdp_md: pointer to xdp_md
63417bedab2SMartin KaFai Lau  *     @delta: An positive/negative integer to be added to xdp_md.data
63517bedab2SMartin KaFai Lau  *     Return: 0 on success or negative on error
636a5e8c070SGianluca Borello  *
637a5e8c070SGianluca Borello  * int bpf_probe_read_str(void *dst, int size, const void *unsafe_ptr)
638a5e8c070SGianluca Borello  *     Copy a NUL terminated string from unsafe address. In case the string
639a5e8c070SGianluca Borello  *     length is smaller than size, the target is not padded with further NUL
640a5e8c070SGianluca Borello  *     bytes. In case the string length is larger than size, just count-1
641a5e8c070SGianluca Borello  *     bytes are copied and the last byte is set to NUL.
642a5e8c070SGianluca Borello  *     @dst: destination address
643a5e8c070SGianluca Borello  *     @size: maximum number of bytes to copy, including the trailing NUL
644a5e8c070SGianluca Borello  *     @unsafe_ptr: unsafe address
645a5e8c070SGianluca Borello  *     Return:
646a5e8c070SGianluca Borello  *       > 0 length of the string including the trailing NUL on success
647a5e8c070SGianluca Borello  *       < 0 error
64891b8270fSChenbo Feng  *
6493c60a531SAlexander Alemayhu  * u64 bpf_get_socket_cookie(skb)
65091b8270fSChenbo Feng  *     Get the cookie for the socket stored inside sk_buff.
65191b8270fSChenbo Feng  *     @skb: pointer to skb
65291b8270fSChenbo Feng  *     Return: 8 Bytes non-decreasing number on success or 0 if the socket
65391b8270fSChenbo Feng  *     field is missing inside sk_buff
6546acc5c29SChenbo Feng  *
6556acc5c29SChenbo Feng  * u32 bpf_get_socket_uid(skb)
6566acc5c29SChenbo Feng  *     Get the owner uid of the socket stored inside sk_buff.
6576acc5c29SChenbo Feng  *     @skb: pointer to skb
6585d4e3443SChenbo Feng  *     Return: uid of the socket owner on success or overflowuid if failed.
659ded092cdSDaniel Borkmann  *
660ded092cdSDaniel Borkmann  * u32 bpf_set_hash(skb, hash)
661ded092cdSDaniel Borkmann  *     Set full skb->hash.
662ded092cdSDaniel Borkmann  *     @skb: pointer to skb
663ded092cdSDaniel Borkmann  *     @hash: hash to set
6648c4b4c7eSLawrence Brakmo  *
6658c4b4c7eSLawrence Brakmo  * int bpf_setsockopt(bpf_socket, level, optname, optval, optlen)
6668c4b4c7eSLawrence Brakmo  *     Calls setsockopt. Not all opts are available, only those with
6678c4b4c7eSLawrence Brakmo  *     integer optvals plus TCP_CONGESTION.
668cd86d1fdSLawrence Brakmo  *     Supported levels: SOL_SOCKET and IPPROTO_TCP
6698c4b4c7eSLawrence Brakmo  *     @bpf_socket: pointer to bpf_socket
670cd86d1fdSLawrence Brakmo  *     @level: SOL_SOCKET or IPPROTO_TCP
6718c4b4c7eSLawrence Brakmo  *     @optname: option name
6728c4b4c7eSLawrence Brakmo  *     @optval: pointer to option value
673cd86d1fdSLawrence Brakmo  *     @optlen: length of optval in bytes
674cd86d1fdSLawrence Brakmo  *     Return: 0 or negative error
675cd86d1fdSLawrence Brakmo  *
676cd86d1fdSLawrence Brakmo  * int bpf_getsockopt(bpf_socket, level, optname, optval, optlen)
677cd86d1fdSLawrence Brakmo  *     Calls getsockopt. Not all opts are available.
678cd86d1fdSLawrence Brakmo  *     Supported levels: IPPROTO_TCP
679cd86d1fdSLawrence Brakmo  *     @bpf_socket: pointer to bpf_socket
680cd86d1fdSLawrence Brakmo  *     @level: IPPROTO_TCP
681cd86d1fdSLawrence Brakmo  *     @optname: option name
682cd86d1fdSLawrence Brakmo  *     @optval: pointer to option value
683cd86d1fdSLawrence Brakmo  *     @optlen: length of optval in bytes
6848c4b4c7eSLawrence Brakmo  *     Return: 0 or negative error
6852be7e212SDaniel Borkmann  *
686b13d8807SLawrence Brakmo  * int bpf_sock_ops_cb_flags_set(bpf_sock_ops, flags)
687b13d8807SLawrence Brakmo  *     Set callback flags for sock_ops
688b13d8807SLawrence Brakmo  *     @bpf_sock_ops: pointer to bpf_sock_ops_kern struct
689b13d8807SLawrence Brakmo  *     @flags: flags value
690b13d8807SLawrence Brakmo  *     Return: 0 for no error
691b13d8807SLawrence Brakmo  *             -EINVAL if there is no full tcp socket
692b13d8807SLawrence Brakmo  *             bits in flags that are not supported by current kernel
693b13d8807SLawrence Brakmo  *
6942be7e212SDaniel Borkmann  * int bpf_skb_adjust_room(skb, len_diff, mode, flags)
6952be7e212SDaniel Borkmann  *     Grow or shrink room in sk_buff.
6962be7e212SDaniel Borkmann  *     @skb: pointer to skb
6972be7e212SDaniel Borkmann  *     @len_diff: (signed) amount of room to grow/shrink
6982be7e212SDaniel Borkmann  *     @mode: operation mode (enum bpf_adj_room_mode)
6992be7e212SDaniel Borkmann  *     @flags: reserved for future use
7002be7e212SDaniel Borkmann  *     Return: 0 on success or negative error code
701174a79ffSJohn Fastabend  *
702174a79ffSJohn Fastabend  * int bpf_sk_redirect_map(map, key, flags)
703174a79ffSJohn Fastabend  *     Redirect skb to a sock in map using key as a lookup key for the
704174a79ffSJohn Fastabend  *     sock in map.
705174a79ffSJohn Fastabend  *     @map: pointer to sockmap
706174a79ffSJohn Fastabend  *     @key: key to lookup sock in map
707174a79ffSJohn Fastabend  *     @flags: reserved for future use
708bfa64075SJohn Fastabend  *     Return: SK_PASS
709174a79ffSJohn Fastabend  *
710464bc0fdSJohn Fastabend  * int bpf_sock_map_update(skops, map, key, flags)
711174a79ffSJohn Fastabend  *	@skops: pointer to bpf_sock_ops
712174a79ffSJohn Fastabend  *	@map: pointer to sockmap to update
713174a79ffSJohn Fastabend  *	@key: key to insert/update sock in map
714174a79ffSJohn Fastabend  *	@flags: same flags as map update elem
715de8f3a83SDaniel Borkmann  *
716de8f3a83SDaniel Borkmann  * int bpf_xdp_adjust_meta(xdp_md, delta)
717de8f3a83SDaniel Borkmann  *     Adjust the xdp_md.data_meta by delta
718de8f3a83SDaniel Borkmann  *     @xdp_md: pointer to xdp_md
719de8f3a83SDaniel Borkmann  *     @delta: An positive/negative integer to be added to xdp_md.data_meta
720de8f3a83SDaniel Borkmann  *     Return: 0 on success or negative on error
721908432caSYonghong Song  *
722908432caSYonghong Song  * int bpf_perf_event_read_value(map, flags, buf, buf_size)
723908432caSYonghong Song  *     read perf event counter value and perf event enabled/running time
724908432caSYonghong Song  *     @map: pointer to perf_event_array map
725908432caSYonghong Song  *     @flags: index of event in the map or bitmask flags
726908432caSYonghong Song  *     @buf: buf to fill
727908432caSYonghong Song  *     @buf_size: size of the buf
728908432caSYonghong Song  *     Return: 0 on success or negative error code
7294bebdc7aSYonghong Song  *
7304bebdc7aSYonghong Song  * int bpf_perf_prog_read_value(ctx, buf, buf_size)
7314bebdc7aSYonghong Song  *     read perf prog attached perf event counter and enabled/running time
7324bebdc7aSYonghong Song  *     @ctx: pointer to ctx
7334bebdc7aSYonghong Song  *     @buf: buf to fill
7344bebdc7aSYonghong Song  *     @buf_size: size of the buf
7354bebdc7aSYonghong Song  *     Return : 0 on success or negative error code
7369802d865SJosef Bacik  *
7379802d865SJosef Bacik  * int bpf_override_return(pt_regs, rc)
7389802d865SJosef Bacik  *	@pt_regs: pointer to struct pt_regs
7399802d865SJosef Bacik  *	@rc: the return value to set
7404f738adbSJohn Fastabend  *
7414f738adbSJohn Fastabend  * int bpf_msg_redirect_map(map, key, flags)
7424f738adbSJohn Fastabend  *     Redirect msg to a sock in map using key as a lookup key for the
7434f738adbSJohn Fastabend  *     sock in map.
7444f738adbSJohn Fastabend  *     @map: pointer to sockmap
7454f738adbSJohn Fastabend  *     @key: key to lookup sock in map
7464f738adbSJohn Fastabend  *     @flags: reserved for future use
7474f738adbSJohn Fastabend  *     Return: SK_PASS
7484f738adbSJohn Fastabend  *
749*d74bad4eSAndrey Ignatov  * int bpf_bind(ctx, addr, addr_len)
750*d74bad4eSAndrey Ignatov  *     Bind socket to address. Only binding to IP is supported, no port can be
751*d74bad4eSAndrey Ignatov  *     set in addr.
752*d74bad4eSAndrey Ignatov  *     @ctx: pointer to context of type bpf_sock_addr
753*d74bad4eSAndrey Ignatov  *     @addr: pointer to struct sockaddr to bind socket to
754*d74bad4eSAndrey Ignatov  *     @addr_len: length of sockaddr structure
755*d74bad4eSAndrey Ignatov  *     Return: 0 on success or negative error code
7567a4b28c6SDaniel Borkmann  */
757ebb676daSThomas Graf #define __BPF_FUNC_MAPPER(FN)		\
758ebb676daSThomas Graf 	FN(unspec),			\
759ebb676daSThomas Graf 	FN(map_lookup_elem),		\
760ebb676daSThomas Graf 	FN(map_update_elem),		\
761ebb676daSThomas Graf 	FN(map_delete_elem),		\
762ebb676daSThomas Graf 	FN(probe_read),			\
763ebb676daSThomas Graf 	FN(ktime_get_ns),		\
764ebb676daSThomas Graf 	FN(trace_printk),		\
765ebb676daSThomas Graf 	FN(get_prandom_u32),		\
766ebb676daSThomas Graf 	FN(get_smp_processor_id),	\
767ebb676daSThomas Graf 	FN(skb_store_bytes),		\
768ebb676daSThomas Graf 	FN(l3_csum_replace),		\
769ebb676daSThomas Graf 	FN(l4_csum_replace),		\
770ebb676daSThomas Graf 	FN(tail_call),			\
771ebb676daSThomas Graf 	FN(clone_redirect),		\
772ebb676daSThomas Graf 	FN(get_current_pid_tgid),	\
773ebb676daSThomas Graf 	FN(get_current_uid_gid),	\
774ebb676daSThomas Graf 	FN(get_current_comm),		\
775ebb676daSThomas Graf 	FN(get_cgroup_classid),		\
776ebb676daSThomas Graf 	FN(skb_vlan_push),		\
777ebb676daSThomas Graf 	FN(skb_vlan_pop),		\
778ebb676daSThomas Graf 	FN(skb_get_tunnel_key),		\
779ebb676daSThomas Graf 	FN(skb_set_tunnel_key),		\
780ebb676daSThomas Graf 	FN(perf_event_read),		\
781ebb676daSThomas Graf 	FN(redirect),			\
782ebb676daSThomas Graf 	FN(get_route_realm),		\
783ebb676daSThomas Graf 	FN(perf_event_output),		\
784ebb676daSThomas Graf 	FN(skb_load_bytes),		\
785ebb676daSThomas Graf 	FN(get_stackid),		\
786ebb676daSThomas Graf 	FN(csum_diff),			\
787ebb676daSThomas Graf 	FN(skb_get_tunnel_opt),		\
788ebb676daSThomas Graf 	FN(skb_set_tunnel_opt),		\
789ebb676daSThomas Graf 	FN(skb_change_proto),		\
790ebb676daSThomas Graf 	FN(skb_change_type),		\
791ebb676daSThomas Graf 	FN(skb_under_cgroup),		\
792ebb676daSThomas Graf 	FN(get_hash_recalc),		\
793ebb676daSThomas Graf 	FN(get_current_task),		\
794ebb676daSThomas Graf 	FN(probe_write_user),		\
795ebb676daSThomas Graf 	FN(current_task_under_cgroup),	\
796ebb676daSThomas Graf 	FN(skb_change_tail),		\
797ebb676daSThomas Graf 	FN(skb_pull_data),		\
798ebb676daSThomas Graf 	FN(csum_update),		\
799ebb676daSThomas Graf 	FN(set_hash_invalid),		\
8003a0af8fdSThomas Graf 	FN(get_numa_node_id),		\
80117bedab2SMartin KaFai Lau 	FN(skb_change_head),		\
802a5e8c070SGianluca Borello 	FN(xdp_adjust_head),		\
80391b8270fSChenbo Feng 	FN(probe_read_str),		\
8046acc5c29SChenbo Feng 	FN(get_socket_cookie),		\
805ded092cdSDaniel Borkmann 	FN(get_socket_uid),		\
8068c4b4c7eSLawrence Brakmo 	FN(set_hash),			\
8072be7e212SDaniel Borkmann 	FN(setsockopt),			\
80897f91a7cSJohn Fastabend 	FN(skb_adjust_room),		\
809174a79ffSJohn Fastabend 	FN(redirect_map),		\
810174a79ffSJohn Fastabend 	FN(sk_redirect_map),		\
811174a79ffSJohn Fastabend 	FN(sock_map_update),		\
812908432caSYonghong Song 	FN(xdp_adjust_meta),		\
8134bebdc7aSYonghong Song 	FN(perf_event_read_value),	\
814cd86d1fdSLawrence Brakmo 	FN(perf_prog_read_value),	\
8159802d865SJosef Bacik 	FN(getsockopt),			\
816b13d8807SLawrence Brakmo 	FN(override_return),		\
8174f738adbSJohn Fastabend 	FN(sock_ops_cb_flags_set),	\
8182a100317SJohn Fastabend 	FN(msg_redirect_map),		\
81991843d54SJohn Fastabend 	FN(msg_apply_bytes),		\
820015632bbSJohn Fastabend 	FN(msg_cork_bytes),		\
821*d74bad4eSAndrey Ignatov 	FN(msg_pull_data),		\
822*d74bad4eSAndrey Ignatov 	FN(bind),
8237a4b28c6SDaniel Borkmann 
824ebb676daSThomas Graf /* integer value in 'imm' field of BPF_CALL instruction selects which helper
825ebb676daSThomas Graf  * function eBPF program intends to call
8262d0e30c3SDaniel Borkmann  */
827ebb676daSThomas Graf #define __BPF_ENUM_FN(x) BPF_FUNC_ ## x
828ebb676daSThomas Graf enum bpf_func_id {
829ebb676daSThomas Graf 	__BPF_FUNC_MAPPER(__BPF_ENUM_FN)
83009756af4SAlexei Starovoitov 	__BPF_FUNC_MAX_ID,
83109756af4SAlexei Starovoitov };
832ebb676daSThomas Graf #undef __BPF_ENUM_FN
83309756af4SAlexei Starovoitov 
834781c53bcSDaniel Borkmann /* All flags used by eBPF helper functions, placed here. */
835781c53bcSDaniel Borkmann 
836781c53bcSDaniel Borkmann /* BPF_FUNC_skb_store_bytes flags. */
837781c53bcSDaniel Borkmann #define BPF_F_RECOMPUTE_CSUM		(1ULL << 0)
8388afd54c8SDaniel Borkmann #define BPF_F_INVALIDATE_HASH		(1ULL << 1)
839781c53bcSDaniel Borkmann 
840781c53bcSDaniel Borkmann /* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
841781c53bcSDaniel Borkmann  * First 4 bits are for passing the header field size.
842781c53bcSDaniel Borkmann  */
843781c53bcSDaniel Borkmann #define BPF_F_HDR_FIELD_MASK		0xfULL
844781c53bcSDaniel Borkmann 
845781c53bcSDaniel Borkmann /* BPF_FUNC_l4_csum_replace flags. */
846781c53bcSDaniel Borkmann #define BPF_F_PSEUDO_HDR		(1ULL << 4)
8472f72959aSDaniel Borkmann #define BPF_F_MARK_MANGLED_0		(1ULL << 5)
848d1b662adSDaniel Borkmann #define BPF_F_MARK_ENFORCE		(1ULL << 6)
849781c53bcSDaniel Borkmann 
850781c53bcSDaniel Borkmann /* BPF_FUNC_clone_redirect and BPF_FUNC_redirect flags. */
851781c53bcSDaniel Borkmann #define BPF_F_INGRESS			(1ULL << 0)
852781c53bcSDaniel Borkmann 
853c6c33454SDaniel Borkmann /* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */
854c6c33454SDaniel Borkmann #define BPF_F_TUNINFO_IPV6		(1ULL << 0)
855c6c33454SDaniel Borkmann 
856d5a3b1f6SAlexei Starovoitov /* BPF_FUNC_get_stackid flags. */
857d5a3b1f6SAlexei Starovoitov #define BPF_F_SKIP_FIELD_MASK		0xffULL
858d5a3b1f6SAlexei Starovoitov #define BPF_F_USER_STACK		(1ULL << 8)
859d5a3b1f6SAlexei Starovoitov #define BPF_F_FAST_STACK_CMP		(1ULL << 9)
860d5a3b1f6SAlexei Starovoitov #define BPF_F_REUSE_STACKID		(1ULL << 10)
861d5a3b1f6SAlexei Starovoitov 
8622da897e5SDaniel Borkmann /* BPF_FUNC_skb_set_tunnel_key flags. */
8632da897e5SDaniel Borkmann #define BPF_F_ZERO_CSUM_TX		(1ULL << 1)
86422080870SDaniel Borkmann #define BPF_F_DONT_FRAGMENT		(1ULL << 2)
86577a5196aSWilliam Tu #define BPF_F_SEQ_NUMBER		(1ULL << 3)
8662da897e5SDaniel Borkmann 
867908432caSYonghong Song /* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
868908432caSYonghong Song  * BPF_FUNC_perf_event_read_value flags.
869908432caSYonghong Song  */
8701e33759cSDaniel Borkmann #define BPF_F_INDEX_MASK		0xffffffffULL
8711e33759cSDaniel Borkmann #define BPF_F_CURRENT_CPU		BPF_F_INDEX_MASK
872555c8a86SDaniel Borkmann /* BPF_FUNC_perf_event_output for sk_buff input context. */
873555c8a86SDaniel Borkmann #define BPF_F_CTXLEN_MASK		(0xfffffULL << 32)
8741e33759cSDaniel Borkmann 
8752be7e212SDaniel Borkmann /* Mode for BPF_FUNC_skb_adjust_room helper. */
8762be7e212SDaniel Borkmann enum bpf_adj_room_mode {
8772be7e212SDaniel Borkmann 	BPF_ADJ_ROOM_NET,
8782be7e212SDaniel Borkmann };
8792be7e212SDaniel Borkmann 
8809bac3d6dSAlexei Starovoitov /* user accessible mirror of in-kernel sk_buff.
8819bac3d6dSAlexei Starovoitov  * new fields can only be added to the end of this structure
8829bac3d6dSAlexei Starovoitov  */
8839bac3d6dSAlexei Starovoitov struct __sk_buff {
8849bac3d6dSAlexei Starovoitov 	__u32 len;
8859bac3d6dSAlexei Starovoitov 	__u32 pkt_type;
8869bac3d6dSAlexei Starovoitov 	__u32 mark;
8879bac3d6dSAlexei Starovoitov 	__u32 queue_mapping;
888c2497395SAlexei Starovoitov 	__u32 protocol;
889c2497395SAlexei Starovoitov 	__u32 vlan_present;
890c2497395SAlexei Starovoitov 	__u32 vlan_tci;
89127cd5452SMichal Sekletar 	__u32 vlan_proto;
892bcad5718SDaniel Borkmann 	__u32 priority;
89337e82c2fSAlexei Starovoitov 	__u32 ingress_ifindex;
89437e82c2fSAlexei Starovoitov 	__u32 ifindex;
895d691f9e8SAlexei Starovoitov 	__u32 tc_index;
896d691f9e8SAlexei Starovoitov 	__u32 cb[5];
897ba7591d8SDaniel Borkmann 	__u32 hash;
898045efa82SDaniel Borkmann 	__u32 tc_classid;
899969bf05eSAlexei Starovoitov 	__u32 data;
900969bf05eSAlexei Starovoitov 	__u32 data_end;
901b1d9fc41SDaniel Borkmann 	__u32 napi_id;
9028a31db56SJohn Fastabend 
903de8f3a83SDaniel Borkmann 	/* Accessed by BPF_PROG_TYPE_sk_skb types from here to ... */
9048a31db56SJohn Fastabend 	__u32 family;
9058a31db56SJohn Fastabend 	__u32 remote_ip4;	/* Stored in network byte order */
9068a31db56SJohn Fastabend 	__u32 local_ip4;	/* Stored in network byte order */
9078a31db56SJohn Fastabend 	__u32 remote_ip6[4];	/* Stored in network byte order */
9088a31db56SJohn Fastabend 	__u32 local_ip6[4];	/* Stored in network byte order */
9098a31db56SJohn Fastabend 	__u32 remote_port;	/* Stored in network byte order */
9108a31db56SJohn Fastabend 	__u32 local_port;	/* stored in host byte order */
911de8f3a83SDaniel Borkmann 	/* ... here. */
912de8f3a83SDaniel Borkmann 
913de8f3a83SDaniel Borkmann 	__u32 data_meta;
9149bac3d6dSAlexei Starovoitov };
9159bac3d6dSAlexei Starovoitov 
916d3aa45ceSAlexei Starovoitov struct bpf_tunnel_key {
917d3aa45ceSAlexei Starovoitov 	__u32 tunnel_id;
918c6c33454SDaniel Borkmann 	union {
919d3aa45ceSAlexei Starovoitov 		__u32 remote_ipv4;
920c6c33454SDaniel Borkmann 		__u32 remote_ipv6[4];
921c6c33454SDaniel Borkmann 	};
922c6c33454SDaniel Borkmann 	__u8 tunnel_tos;
923c6c33454SDaniel Borkmann 	__u8 tunnel_ttl;
924c0e760c9SDaniel Borkmann 	__u16 tunnel_ext;
9254018ab18SDaniel Borkmann 	__u32 tunnel_label;
926d3aa45ceSAlexei Starovoitov };
927d3aa45ceSAlexei Starovoitov 
9283a0af8fdSThomas Graf /* Generic BPF return codes which all BPF program types may support.
9293a0af8fdSThomas Graf  * The values are binary compatible with their TC_ACT_* counter-part to
9303a0af8fdSThomas Graf  * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT
9313a0af8fdSThomas Graf  * programs.
9323a0af8fdSThomas Graf  *
9333a0af8fdSThomas Graf  * XDP is handled seprately, see XDP_*.
9343a0af8fdSThomas Graf  */
9353a0af8fdSThomas Graf enum bpf_ret_code {
9363a0af8fdSThomas Graf 	BPF_OK = 0,
9373a0af8fdSThomas Graf 	/* 1 reserved */
9383a0af8fdSThomas Graf 	BPF_DROP = 2,
9393a0af8fdSThomas Graf 	/* 3-6 reserved */
9403a0af8fdSThomas Graf 	BPF_REDIRECT = 7,
9413a0af8fdSThomas Graf 	/* >127 are reserved for prog type specific return codes */
9423a0af8fdSThomas Graf };
9433a0af8fdSThomas Graf 
94461023658SDavid Ahern struct bpf_sock {
94561023658SDavid Ahern 	__u32 bound_dev_if;
946aa4c1037SDavid Ahern 	__u32 family;
947aa4c1037SDavid Ahern 	__u32 type;
948aa4c1037SDavid Ahern 	__u32 protocol;
949482dca93SDavid Ahern 	__u32 mark;
950482dca93SDavid Ahern 	__u32 priority;
95161023658SDavid Ahern };
95261023658SDavid Ahern 
95317bedab2SMartin KaFai Lau #define XDP_PACKET_HEADROOM 256
95417bedab2SMartin KaFai Lau 
9556a773a15SBrenden Blanco /* User return codes for XDP prog type.
9566a773a15SBrenden Blanco  * A valid XDP program must return one of these defined values. All other
9579beb8bedSDaniel Borkmann  * return codes are reserved for future use. Unknown return codes will
9589beb8bedSDaniel Borkmann  * result in packet drops and a warning via bpf_warn_invalid_xdp_action().
9596a773a15SBrenden Blanco  */
9606a773a15SBrenden Blanco enum xdp_action {
9616a773a15SBrenden Blanco 	XDP_ABORTED = 0,
9626a773a15SBrenden Blanco 	XDP_DROP,
9636a773a15SBrenden Blanco 	XDP_PASS,
9646ce96ca3SBrenden Blanco 	XDP_TX,
965814abfabSJohn Fastabend 	XDP_REDIRECT,
9666a773a15SBrenden Blanco };
9676a773a15SBrenden Blanco 
9686a773a15SBrenden Blanco /* user accessible metadata for XDP packet hook
9696a773a15SBrenden Blanco  * new fields must be added to the end of this structure
9706a773a15SBrenden Blanco  */
9716a773a15SBrenden Blanco struct xdp_md {
9726a773a15SBrenden Blanco 	__u32 data;
9736a773a15SBrenden Blanco 	__u32 data_end;
974de8f3a83SDaniel Borkmann 	__u32 data_meta;
975daaf24c6SJesper Dangaard Brouer 	/* Below access go through struct xdp_rxq_info */
97602dd3291SJesper Dangaard Brouer 	__u32 ingress_ifindex; /* rxq->dev->ifindex */
97702dd3291SJesper Dangaard Brouer 	__u32 rx_queue_index;  /* rxq->queue_index  */
9786a773a15SBrenden Blanco };
9796a773a15SBrenden Blanco 
980174a79ffSJohn Fastabend enum sk_action {
981bfa64075SJohn Fastabend 	SK_DROP = 0,
982bfa64075SJohn Fastabend 	SK_PASS,
983174a79ffSJohn Fastabend };
984174a79ffSJohn Fastabend 
9854f738adbSJohn Fastabend /* user accessible metadata for SK_MSG packet hook, new fields must
9864f738adbSJohn Fastabend  * be added to the end of this structure
9874f738adbSJohn Fastabend  */
9884f738adbSJohn Fastabend struct sk_msg_md {
9894f738adbSJohn Fastabend 	void *data;
9904f738adbSJohn Fastabend 	void *data_end;
9914f738adbSJohn Fastabend };
9924f738adbSJohn Fastabend 
9931e270976SMartin KaFai Lau #define BPF_TAG_SIZE	8
9941e270976SMartin KaFai Lau 
9951e270976SMartin KaFai Lau struct bpf_prog_info {
9961e270976SMartin KaFai Lau 	__u32 type;
9971e270976SMartin KaFai Lau 	__u32 id;
9981e270976SMartin KaFai Lau 	__u8  tag[BPF_TAG_SIZE];
9991e270976SMartin KaFai Lau 	__u32 jited_prog_len;
10001e270976SMartin KaFai Lau 	__u32 xlated_prog_len;
10011e270976SMartin KaFai Lau 	__aligned_u64 jited_prog_insns;
10021e270976SMartin KaFai Lau 	__aligned_u64 xlated_prog_insns;
1003cb4d2b3fSMartin KaFai Lau 	__u64 load_time;	/* ns since boottime */
1004cb4d2b3fSMartin KaFai Lau 	__u32 created_by_uid;
1005cb4d2b3fSMartin KaFai Lau 	__u32 nr_map_ids;
1006cb4d2b3fSMartin KaFai Lau 	__aligned_u64 map_ids;
1007067cae47SMartin KaFai Lau 	char name[BPF_OBJ_NAME_LEN];
1008675fc275SJakub Kicinski 	__u32 ifindex;
1009675fc275SJakub Kicinski 	__u64 netns_dev;
1010675fc275SJakub Kicinski 	__u64 netns_ino;
10111e270976SMartin KaFai Lau } __attribute__((aligned(8)));
10121e270976SMartin KaFai Lau 
10131e270976SMartin KaFai Lau struct bpf_map_info {
10141e270976SMartin KaFai Lau 	__u32 type;
10151e270976SMartin KaFai Lau 	__u32 id;
10161e270976SMartin KaFai Lau 	__u32 key_size;
10171e270976SMartin KaFai Lau 	__u32 value_size;
10181e270976SMartin KaFai Lau 	__u32 max_entries;
10191e270976SMartin KaFai Lau 	__u32 map_flags;
1020067cae47SMartin KaFai Lau 	char  name[BPF_OBJ_NAME_LEN];
102152775b33SJakub Kicinski 	__u32 ifindex;
102252775b33SJakub Kicinski 	__u64 netns_dev;
102352775b33SJakub Kicinski 	__u64 netns_ino;
10241e270976SMartin KaFai Lau } __attribute__((aligned(8)));
10251e270976SMartin KaFai Lau 
10264fbac77dSAndrey Ignatov /* User bpf_sock_addr struct to access socket fields and sockaddr struct passed
10274fbac77dSAndrey Ignatov  * by user and intended to be used by socket (e.g. to bind to, depends on
10284fbac77dSAndrey Ignatov  * attach attach type).
10294fbac77dSAndrey Ignatov  */
10304fbac77dSAndrey Ignatov struct bpf_sock_addr {
10314fbac77dSAndrey Ignatov 	__u32 user_family;	/* Allows 4-byte read, but no write. */
10324fbac77dSAndrey Ignatov 	__u32 user_ip4;		/* Allows 1,2,4-byte read and 4-byte write.
10334fbac77dSAndrey Ignatov 				 * Stored in network byte order.
10344fbac77dSAndrey Ignatov 				 */
10354fbac77dSAndrey Ignatov 	__u32 user_ip6[4];	/* Allows 1,2,4-byte read an 4-byte write.
10364fbac77dSAndrey Ignatov 				 * Stored in network byte order.
10374fbac77dSAndrey Ignatov 				 */
10384fbac77dSAndrey Ignatov 	__u32 user_port;	/* Allows 4-byte read and write.
10394fbac77dSAndrey Ignatov 				 * Stored in network byte order
10404fbac77dSAndrey Ignatov 				 */
10414fbac77dSAndrey Ignatov 	__u32 family;		/* Allows 4-byte read, but no write */
10424fbac77dSAndrey Ignatov 	__u32 type;		/* Allows 4-byte read, but no write */
10434fbac77dSAndrey Ignatov 	__u32 protocol;		/* Allows 4-byte read, but no write */
10444fbac77dSAndrey Ignatov };
10454fbac77dSAndrey Ignatov 
104640304b2aSLawrence Brakmo /* User bpf_sock_ops struct to access socket values and specify request ops
104740304b2aSLawrence Brakmo  * and their replies.
104840304b2aSLawrence Brakmo  * Some of this fields are in network (bigendian) byte order and may need
104940304b2aSLawrence Brakmo  * to be converted before use (bpf_ntohl() defined in samples/bpf/bpf_endian.h).
105040304b2aSLawrence Brakmo  * New fields can only be added at the end of this structure
105140304b2aSLawrence Brakmo  */
105240304b2aSLawrence Brakmo struct bpf_sock_ops {
105340304b2aSLawrence Brakmo 	__u32 op;
105440304b2aSLawrence Brakmo 	union {
1055de525be2SLawrence Brakmo 		__u32 args[4];		/* Optionally passed to bpf program */
1056de525be2SLawrence Brakmo 		__u32 reply;		/* Returned by bpf program	    */
1057de525be2SLawrence Brakmo 		__u32 replylong[4];	/* Optionally returned by bpf prog  */
105840304b2aSLawrence Brakmo 	};
105940304b2aSLawrence Brakmo 	__u32 family;
106040304b2aSLawrence Brakmo 	__u32 remote_ip4;	/* Stored in network byte order */
106140304b2aSLawrence Brakmo 	__u32 local_ip4;	/* Stored in network byte order */
106240304b2aSLawrence Brakmo 	__u32 remote_ip6[4];	/* Stored in network byte order */
106340304b2aSLawrence Brakmo 	__u32 local_ip6[4];	/* Stored in network byte order */
106440304b2aSLawrence Brakmo 	__u32 remote_port;	/* Stored in network byte order */
106540304b2aSLawrence Brakmo 	__u32 local_port;	/* stored in host byte order */
1066f19397a5SLawrence Brakmo 	__u32 is_fullsock;	/* Some TCP fields are only valid if
1067f19397a5SLawrence Brakmo 				 * there is a full socket. If not, the
1068f19397a5SLawrence Brakmo 				 * fields read as zero.
1069f19397a5SLawrence Brakmo 				 */
1070f19397a5SLawrence Brakmo 	__u32 snd_cwnd;
1071f19397a5SLawrence Brakmo 	__u32 srtt_us;		/* Averaged RTT << 3 in usecs */
1072b13d8807SLawrence Brakmo 	__u32 bpf_sock_ops_cb_flags; /* flags defined in uapi/linux/tcp.h */
107344f0e430SLawrence Brakmo 	__u32 state;
107444f0e430SLawrence Brakmo 	__u32 rtt_min;
107544f0e430SLawrence Brakmo 	__u32 snd_ssthresh;
107644f0e430SLawrence Brakmo 	__u32 rcv_nxt;
107744f0e430SLawrence Brakmo 	__u32 snd_nxt;
107844f0e430SLawrence Brakmo 	__u32 snd_una;
107944f0e430SLawrence Brakmo 	__u32 mss_cache;
108044f0e430SLawrence Brakmo 	__u32 ecn_flags;
108144f0e430SLawrence Brakmo 	__u32 rate_delivered;
108244f0e430SLawrence Brakmo 	__u32 rate_interval_us;
108344f0e430SLawrence Brakmo 	__u32 packets_out;
108444f0e430SLawrence Brakmo 	__u32 retrans_out;
108544f0e430SLawrence Brakmo 	__u32 total_retrans;
108644f0e430SLawrence Brakmo 	__u32 segs_in;
108744f0e430SLawrence Brakmo 	__u32 data_segs_in;
108844f0e430SLawrence Brakmo 	__u32 segs_out;
108944f0e430SLawrence Brakmo 	__u32 data_segs_out;
109044f0e430SLawrence Brakmo 	__u32 lost_out;
109144f0e430SLawrence Brakmo 	__u32 sacked_out;
109244f0e430SLawrence Brakmo 	__u32 sk_txhash;
109344f0e430SLawrence Brakmo 	__u64 bytes_received;
109444f0e430SLawrence Brakmo 	__u64 bytes_acked;
109540304b2aSLawrence Brakmo };
109640304b2aSLawrence Brakmo 
1097b13d8807SLawrence Brakmo /* Definitions for bpf_sock_ops_cb_flags */
1098f89013f6SLawrence Brakmo #define BPF_SOCK_OPS_RTO_CB_FLAG	(1<<0)
1099a31ad29eSLawrence Brakmo #define BPF_SOCK_OPS_RETRANS_CB_FLAG	(1<<1)
1100d4487491SLawrence Brakmo #define BPF_SOCK_OPS_STATE_CB_FLAG	(1<<2)
1101d4487491SLawrence Brakmo #define BPF_SOCK_OPS_ALL_CB_FLAGS       0x7		/* Mask of all currently
1102b13d8807SLawrence Brakmo 							 * supported cb flags
1103b13d8807SLawrence Brakmo 							 */
1104b13d8807SLawrence Brakmo 
110540304b2aSLawrence Brakmo /* List of known BPF sock_ops operators.
110640304b2aSLawrence Brakmo  * New entries can only be added at the end
110740304b2aSLawrence Brakmo  */
110840304b2aSLawrence Brakmo enum {
110940304b2aSLawrence Brakmo 	BPF_SOCK_OPS_VOID,
11108550f328SLawrence Brakmo 	BPF_SOCK_OPS_TIMEOUT_INIT,	/* Should return SYN-RTO value to use or
11118550f328SLawrence Brakmo 					 * -1 if default value should be used
11128550f328SLawrence Brakmo 					 */
111313d3b1ebSLawrence Brakmo 	BPF_SOCK_OPS_RWND_INIT,		/* Should return initial advertized
111413d3b1ebSLawrence Brakmo 					 * window (in packets) or -1 if default
111513d3b1ebSLawrence Brakmo 					 * value should be used
111613d3b1ebSLawrence Brakmo 					 */
11179872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_TCP_CONNECT_CB,	/* Calls BPF program right before an
11189872a4bdSLawrence Brakmo 					 * active connection is initialized
11199872a4bdSLawrence Brakmo 					 */
11209872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB,	/* Calls BPF program when an
11219872a4bdSLawrence Brakmo 						 * active connection is
11229872a4bdSLawrence Brakmo 						 * established
11239872a4bdSLawrence Brakmo 						 */
11249872a4bdSLawrence Brakmo 	BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB,	/* Calls BPF program when a
11259872a4bdSLawrence Brakmo 						 * passive connection is
11269872a4bdSLawrence Brakmo 						 * established
11279872a4bdSLawrence Brakmo 						 */
112891b5b21cSLawrence Brakmo 	BPF_SOCK_OPS_NEEDS_ECN,		/* If connection's congestion control
112991b5b21cSLawrence Brakmo 					 * needs ECN
113091b5b21cSLawrence Brakmo 					 */
1131e6546ef6SLawrence Brakmo 	BPF_SOCK_OPS_BASE_RTT,		/* Get base RTT. The correct value is
1132e6546ef6SLawrence Brakmo 					 * based on the path and may be
1133e6546ef6SLawrence Brakmo 					 * dependent on the congestion control
1134e6546ef6SLawrence Brakmo 					 * algorithm. In general it indicates
1135e6546ef6SLawrence Brakmo 					 * a congestion threshold. RTTs above
1136e6546ef6SLawrence Brakmo 					 * this indicate congestion
1137e6546ef6SLawrence Brakmo 					 */
1138f89013f6SLawrence Brakmo 	BPF_SOCK_OPS_RTO_CB,		/* Called when an RTO has triggered.
1139f89013f6SLawrence Brakmo 					 * Arg1: value of icsk_retransmits
1140f89013f6SLawrence Brakmo 					 * Arg2: value of icsk_rto
1141f89013f6SLawrence Brakmo 					 * Arg3: whether RTO has expired
1142f89013f6SLawrence Brakmo 					 */
1143a31ad29eSLawrence Brakmo 	BPF_SOCK_OPS_RETRANS_CB,	/* Called when skb is retransmitted.
1144a31ad29eSLawrence Brakmo 					 * Arg1: sequence number of 1st byte
1145a31ad29eSLawrence Brakmo 					 * Arg2: # segments
1146a31ad29eSLawrence Brakmo 					 * Arg3: return value of
1147a31ad29eSLawrence Brakmo 					 *       tcp_transmit_skb (0 => success)
1148a31ad29eSLawrence Brakmo 					 */
1149d4487491SLawrence Brakmo 	BPF_SOCK_OPS_STATE_CB,		/* Called when TCP changes state.
1150d4487491SLawrence Brakmo 					 * Arg1: old_state
1151d4487491SLawrence Brakmo 					 * Arg2: new_state
1152d4487491SLawrence Brakmo 					 */
1153d4487491SLawrence Brakmo };
1154d4487491SLawrence Brakmo 
1155d4487491SLawrence Brakmo /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
1156d4487491SLawrence Brakmo  * changes between the TCP and BPF versions. Ideally this should never happen.
1157d4487491SLawrence Brakmo  * If it does, we need to add code to convert them before calling
1158d4487491SLawrence Brakmo  * the BPF sock_ops function.
1159d4487491SLawrence Brakmo  */
1160d4487491SLawrence Brakmo enum {
1161d4487491SLawrence Brakmo 	BPF_TCP_ESTABLISHED = 1,
1162d4487491SLawrence Brakmo 	BPF_TCP_SYN_SENT,
1163d4487491SLawrence Brakmo 	BPF_TCP_SYN_RECV,
1164d4487491SLawrence Brakmo 	BPF_TCP_FIN_WAIT1,
1165d4487491SLawrence Brakmo 	BPF_TCP_FIN_WAIT2,
1166d4487491SLawrence Brakmo 	BPF_TCP_TIME_WAIT,
1167d4487491SLawrence Brakmo 	BPF_TCP_CLOSE,
1168d4487491SLawrence Brakmo 	BPF_TCP_CLOSE_WAIT,
1169d4487491SLawrence Brakmo 	BPF_TCP_LAST_ACK,
1170d4487491SLawrence Brakmo 	BPF_TCP_LISTEN,
1171d4487491SLawrence Brakmo 	BPF_TCP_CLOSING,	/* Now a valid state */
1172d4487491SLawrence Brakmo 	BPF_TCP_NEW_SYN_RECV,
1173d4487491SLawrence Brakmo 
1174d4487491SLawrence Brakmo 	BPF_TCP_MAX_STATES	/* Leave at the end! */
117540304b2aSLawrence Brakmo };
117640304b2aSLawrence Brakmo 
1177fc747810SLawrence Brakmo #define TCP_BPF_IW		1001	/* Set TCP initial congestion window */
117813bf9641SLawrence Brakmo #define TCP_BPF_SNDCWND_CLAMP	1002	/* Set sndcwnd_clamp */
1179fc747810SLawrence Brakmo 
1180908432caSYonghong Song struct bpf_perf_event_value {
1181908432caSYonghong Song 	__u64 counter;
1182908432caSYonghong Song 	__u64 enabled;
1183908432caSYonghong Song 	__u64 running;
1184908432caSYonghong Song };
1185908432caSYonghong Song 
1186ebc614f6SRoman Gushchin #define BPF_DEVCG_ACC_MKNOD	(1ULL << 0)
1187ebc614f6SRoman Gushchin #define BPF_DEVCG_ACC_READ	(1ULL << 1)
1188ebc614f6SRoman Gushchin #define BPF_DEVCG_ACC_WRITE	(1ULL << 2)
1189ebc614f6SRoman Gushchin 
1190ebc614f6SRoman Gushchin #define BPF_DEVCG_DEV_BLOCK	(1ULL << 0)
1191ebc614f6SRoman Gushchin #define BPF_DEVCG_DEV_CHAR	(1ULL << 1)
1192ebc614f6SRoman Gushchin 
1193ebc614f6SRoman Gushchin struct bpf_cgroup_dev_ctx {
119406ef0ccbSYonghong Song 	/* access_type encoded as (BPF_DEVCG_ACC_* << 16) | BPF_DEVCG_DEV_* */
119506ef0ccbSYonghong Song 	__u32 access_type;
1196ebc614f6SRoman Gushchin 	__u32 major;
1197ebc614f6SRoman Gushchin 	__u32 minor;
1198ebc614f6SRoman Gushchin };
1199ebc614f6SRoman Gushchin 
1200c4f6699dSAlexei Starovoitov struct bpf_raw_tracepoint_args {
1201c4f6699dSAlexei Starovoitov 	__u64 args[0];
1202c4f6699dSAlexei Starovoitov };
1203c4f6699dSAlexei Starovoitov 
1204daedfb22SAlexei Starovoitov #endif /* _UAPI__LINUX_BPF_H__ */
1205