1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2019 Richard Palethorpe <[email protected]>
4*49cdfc7eSAndroid Build Coastguard Worker *
5*49cdfc7eSAndroid Build Coastguard Worker * Essential Extended Berkeley Packet Filter (eBPF) headers
6*49cdfc7eSAndroid Build Coastguard Worker *
7*49cdfc7eSAndroid Build Coastguard Worker * Mostly copied/adapted from linux/bpf.h and libbpf so that we can perform
8*49cdfc7eSAndroid Build Coastguard Worker * some eBPF testing without any external dependencies.
9*49cdfc7eSAndroid Build Coastguard Worker */
10*49cdfc7eSAndroid Build Coastguard Worker
11*49cdfc7eSAndroid Build Coastguard Worker #ifndef LAPI_BPF_H__
12*49cdfc7eSAndroid Build Coastguard Worker #define LAPI_BPF_H__
13*49cdfc7eSAndroid Build Coastguard Worker
14*49cdfc7eSAndroid Build Coastguard Worker #include <stdint.h>
15*49cdfc7eSAndroid Build Coastguard Worker
16*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/syscalls.h"
17*49cdfc7eSAndroid Build Coastguard Worker
18*49cdfc7eSAndroid Build Coastguard Worker /* Start copy from linux/bpf_(common).h */
19*49cdfc7eSAndroid Build Coastguard Worker #define BPF_CLASS(code) ((code) & 0x07)
20*49cdfc7eSAndroid Build Coastguard Worker #define BPF_LD 0x00
21*49cdfc7eSAndroid Build Coastguard Worker #define BPF_LDX 0x01
22*49cdfc7eSAndroid Build Coastguard Worker #define BPF_ST 0x02
23*49cdfc7eSAndroid Build Coastguard Worker #define BPF_STX 0x03
24*49cdfc7eSAndroid Build Coastguard Worker #define BPF_ALU 0x04
25*49cdfc7eSAndroid Build Coastguard Worker #define BPF_JMP 0x05
26*49cdfc7eSAndroid Build Coastguard Worker
27*49cdfc7eSAndroid Build Coastguard Worker #define BPF_JNE 0x50 /* jump != */
28*49cdfc7eSAndroid Build Coastguard Worker
29*49cdfc7eSAndroid Build Coastguard Worker #define BPF_SIZE(code) ((code) & 0x18)
30*49cdfc7eSAndroid Build Coastguard Worker #define BPF_B 0x10 /* 8-bit */
31*49cdfc7eSAndroid Build Coastguard Worker #define BPF_W 0x00 /* 32-bit */
32*49cdfc7eSAndroid Build Coastguard Worker #define BPF_DW 0x18 /* double word (64-bit) */
33*49cdfc7eSAndroid Build Coastguard Worker
34*49cdfc7eSAndroid Build Coastguard Worker #define BPF_MODE(code) ((code) & 0xe0)
35*49cdfc7eSAndroid Build Coastguard Worker #define BPF_IMM 0x00
36*49cdfc7eSAndroid Build Coastguard Worker #define BPF_MEM 0x60
37*49cdfc7eSAndroid Build Coastguard Worker
38*49cdfc7eSAndroid Build Coastguard Worker #define BPF_OP(code) ((code) & 0xf0)
39*49cdfc7eSAndroid Build Coastguard Worker #define BPF_ADD 0x00
40*49cdfc7eSAndroid Build Coastguard Worker #define BPF_SUB 0x10
41*49cdfc7eSAndroid Build Coastguard Worker #define BPF_MUL 0x20
42*49cdfc7eSAndroid Build Coastguard Worker #define BPF_DIV 0x30
43*49cdfc7eSAndroid Build Coastguard Worker #define BPF_LSH 0x60
44*49cdfc7eSAndroid Build Coastguard Worker #define BPF_RSH 0x70
45*49cdfc7eSAndroid Build Coastguard Worker #define BPF_MOD 0x90
46*49cdfc7eSAndroid Build Coastguard Worker
47*49cdfc7eSAndroid Build Coastguard Worker #define BPF_JEQ 0x10
48*49cdfc7eSAndroid Build Coastguard Worker
49*49cdfc7eSAndroid Build Coastguard Worker #define BPF_SRC(code) ((code) & 0x08)
50*49cdfc7eSAndroid Build Coastguard Worker #define BPF_K 0x00
51*49cdfc7eSAndroid Build Coastguard Worker #define BPF_X 0x08
52*49cdfc7eSAndroid Build Coastguard Worker
53*49cdfc7eSAndroid Build Coastguard Worker #define BPF_ALU64 0x07 /* alu mode in double word width */
54*49cdfc7eSAndroid Build Coastguard Worker #define BPF_MOV 0xb0 /* mov reg to reg */
55*49cdfc7eSAndroid Build Coastguard Worker #define BPF_CALL 0x80 /* function call */
56*49cdfc7eSAndroid Build Coastguard Worker #define BPF_EXIT 0x90 /* function return */
57*49cdfc7eSAndroid Build Coastguard Worker
58*49cdfc7eSAndroid Build Coastguard Worker /* Register numbers */
59*49cdfc7eSAndroid Build Coastguard Worker enum {
60*49cdfc7eSAndroid Build Coastguard Worker BPF_REG_0 = 0,
61*49cdfc7eSAndroid Build Coastguard Worker BPF_REG_1,
62*49cdfc7eSAndroid Build Coastguard Worker BPF_REG_2,
63*49cdfc7eSAndroid Build Coastguard Worker BPF_REG_3,
64*49cdfc7eSAndroid Build Coastguard Worker BPF_REG_4,
65*49cdfc7eSAndroid Build Coastguard Worker BPF_REG_5,
66*49cdfc7eSAndroid Build Coastguard Worker BPF_REG_6,
67*49cdfc7eSAndroid Build Coastguard Worker BPF_REG_7,
68*49cdfc7eSAndroid Build Coastguard Worker BPF_REG_8,
69*49cdfc7eSAndroid Build Coastguard Worker BPF_REG_9,
70*49cdfc7eSAndroid Build Coastguard Worker BPF_REG_10,
71*49cdfc7eSAndroid Build Coastguard Worker MAX_BPF_REG,
72*49cdfc7eSAndroid Build Coastguard Worker };
73*49cdfc7eSAndroid Build Coastguard Worker
74*49cdfc7eSAndroid Build Coastguard Worker struct bpf_insn {
75*49cdfc7eSAndroid Build Coastguard Worker uint8_t code; /* opcode */
76*49cdfc7eSAndroid Build Coastguard Worker uint8_t dst_reg:4; /* dest register */
77*49cdfc7eSAndroid Build Coastguard Worker uint8_t src_reg:4; /* source register */
78*49cdfc7eSAndroid Build Coastguard Worker int16_t off; /* signed offset */
79*49cdfc7eSAndroid Build Coastguard Worker int32_t imm; /* signed immediate constant */
80*49cdfc7eSAndroid Build Coastguard Worker };
81*49cdfc7eSAndroid Build Coastguard Worker
82*49cdfc7eSAndroid Build Coastguard Worker enum bpf_cmd {
83*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_CREATE,
84*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_LOOKUP_ELEM,
85*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_UPDATE_ELEM,
86*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_DELETE_ELEM,
87*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_GET_NEXT_KEY,
88*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_LOAD,
89*49cdfc7eSAndroid Build Coastguard Worker BPF_OBJ_PIN,
90*49cdfc7eSAndroid Build Coastguard Worker BPF_OBJ_GET,
91*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_ATTACH,
92*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_DETACH,
93*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TEST_RUN,
94*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_GET_NEXT_ID,
95*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_GET_NEXT_ID,
96*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_GET_FD_BY_ID,
97*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_GET_FD_BY_ID,
98*49cdfc7eSAndroid Build Coastguard Worker BPF_OBJ_GET_INFO_BY_FD,
99*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_QUERY,
100*49cdfc7eSAndroid Build Coastguard Worker BPF_RAW_TRACEPOINT_OPEN,
101*49cdfc7eSAndroid Build Coastguard Worker BPF_BTF_LOAD,
102*49cdfc7eSAndroid Build Coastguard Worker BPF_BTF_GET_FD_BY_ID,
103*49cdfc7eSAndroid Build Coastguard Worker BPF_TASK_FD_QUERY,
104*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_LOOKUP_AND_DELETE_ELEM,
105*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_FREEZE,
106*49cdfc7eSAndroid Build Coastguard Worker };
107*49cdfc7eSAndroid Build Coastguard Worker
108*49cdfc7eSAndroid Build Coastguard Worker enum bpf_map_type {
109*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_UNSPEC,
110*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_HASH,
111*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_ARRAY,
112*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_PROG_ARRAY,
113*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_PERF_EVENT_ARRAY,
114*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_PERCPU_HASH,
115*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_PERCPU_ARRAY,
116*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_STACK_TRACE,
117*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_CGROUP_ARRAY,
118*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_LRU_HASH,
119*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_LRU_PERCPU_HASH,
120*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_LPM_TRIE,
121*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_ARRAY_OF_MAPS,
122*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_HASH_OF_MAPS,
123*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_DEVMAP,
124*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_SOCKMAP,
125*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_CPUMAP,
126*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_XSKMAP,
127*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_SOCKHASH,
128*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_CGROUP_STORAGE,
129*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_REUSEPORT_SOCKARRAY,
130*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE,
131*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_QUEUE,
132*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_STACK,
133*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_SK_STORAGE,
134*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_DEVMAP_HASH,
135*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_STRUCT_OPS,
136*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_RINGBUF,
137*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_INODE_STORAGE,
138*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_TASK_STORAGE,
139*49cdfc7eSAndroid Build Coastguard Worker BPF_MAP_TYPE_BLOOM_FILTER,
140*49cdfc7eSAndroid Build Coastguard Worker };
141*49cdfc7eSAndroid Build Coastguard Worker
142*49cdfc7eSAndroid Build Coastguard Worker enum bpf_prog_type {
143*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_UNSPEC,
144*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_SOCKET_FILTER,
145*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_KPROBE,
146*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_SCHED_CLS,
147*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_SCHED_ACT,
148*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_TRACEPOINT,
149*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_XDP,
150*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_PERF_EVENT,
151*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_CGROUP_SKB,
152*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_CGROUP_SOCK,
153*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_LWT_IN,
154*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_LWT_OUT,
155*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_LWT_XMIT,
156*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_SOCK_OPS,
157*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_SK_SKB,
158*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_CGROUP_DEVICE,
159*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_SK_MSG,
160*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_RAW_TRACEPOINT,
161*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
162*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_LWT_SEG6LOCAL,
163*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_LIRC_MODE2,
164*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_SK_REUSEPORT,
165*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_FLOW_DISSECTOR,
166*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_CGROUP_SYSCTL,
167*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
168*49cdfc7eSAndroid Build Coastguard Worker BPF_PROG_TYPE_CGROUP_SOCKOPT,
169*49cdfc7eSAndroid Build Coastguard Worker };
170*49cdfc7eSAndroid Build Coastguard Worker
171*49cdfc7eSAndroid Build Coastguard Worker #define BPF_PSEUDO_MAP_FD 1
172*49cdfc7eSAndroid Build Coastguard Worker
173*49cdfc7eSAndroid Build Coastguard Worker #define BPF_OBJ_NAME_LEN 16U
174*49cdfc7eSAndroid Build Coastguard Worker
175*49cdfc7eSAndroid Build Coastguard Worker #define BPF_ANY 0 /* create new element or update existing */
176*49cdfc7eSAndroid Build Coastguard Worker #define BPF_NOEXIST 1 /* create new element if it didn't exist */
177*49cdfc7eSAndroid Build Coastguard Worker #define BPF_EXIST 2 /* update existing element */
178*49cdfc7eSAndroid Build Coastguard Worker #define BPF_F_LOCK 4 /* spin_lock-ed map_lookup/map_update */
179*49cdfc7eSAndroid Build Coastguard Worker
180*49cdfc7eSAndroid Build Coastguard Worker #define aligned_uint64_t uint64_t __attribute__((aligned(8)))
181*49cdfc7eSAndroid Build Coastguard Worker
182*49cdfc7eSAndroid Build Coastguard Worker union bpf_attr {
183*49cdfc7eSAndroid Build Coastguard Worker struct { /* anonymous struct used by BPF_MAP_CREATE command */
184*49cdfc7eSAndroid Build Coastguard Worker uint32_t map_type; /* one of enum bpf_map_type */
185*49cdfc7eSAndroid Build Coastguard Worker uint32_t key_size; /* size of key in bytes */
186*49cdfc7eSAndroid Build Coastguard Worker uint32_t value_size; /* size of value in bytes */
187*49cdfc7eSAndroid Build Coastguard Worker uint32_t max_entries; /* max number of entries in a map */
188*49cdfc7eSAndroid Build Coastguard Worker uint32_t map_flags; /* BPF_MAP_CREATE related
189*49cdfc7eSAndroid Build Coastguard Worker * flags defined above.
190*49cdfc7eSAndroid Build Coastguard Worker */
191*49cdfc7eSAndroid Build Coastguard Worker uint32_t inner_map_fd; /* fd pointing to the inner map */
192*49cdfc7eSAndroid Build Coastguard Worker uint32_t numa_node; /* numa node (effective only if
193*49cdfc7eSAndroid Build Coastguard Worker * BPF_F_NUMA_NODE is set).
194*49cdfc7eSAndroid Build Coastguard Worker */
195*49cdfc7eSAndroid Build Coastguard Worker char map_name[BPF_OBJ_NAME_LEN];
196*49cdfc7eSAndroid Build Coastguard Worker uint32_t map_ifindex; /* ifindex of netdev to create on */
197*49cdfc7eSAndroid Build Coastguard Worker uint32_t btf_fd; /* fd pointing to a BTF type data */
198*49cdfc7eSAndroid Build Coastguard Worker uint32_t btf_key_type_id; /* BTF type_id of the key */
199*49cdfc7eSAndroid Build Coastguard Worker uint32_t btf_value_type_id; /* BTF type_id of the value */
200*49cdfc7eSAndroid Build Coastguard Worker };
201*49cdfc7eSAndroid Build Coastguard Worker
202*49cdfc7eSAndroid Build Coastguard Worker struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
203*49cdfc7eSAndroid Build Coastguard Worker uint32_t map_fd;
204*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t key;
205*49cdfc7eSAndroid Build Coastguard Worker union {
206*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t value;
207*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t next_key;
208*49cdfc7eSAndroid Build Coastguard Worker };
209*49cdfc7eSAndroid Build Coastguard Worker uint64_t flags;
210*49cdfc7eSAndroid Build Coastguard Worker };
211*49cdfc7eSAndroid Build Coastguard Worker
212*49cdfc7eSAndroid Build Coastguard Worker struct { /* anonymous struct used by BPF_PROG_LOAD command */
213*49cdfc7eSAndroid Build Coastguard Worker uint32_t prog_type; /* one of enum bpf_prog_type */
214*49cdfc7eSAndroid Build Coastguard Worker uint32_t insn_cnt;
215*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t insns;
216*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t license;
217*49cdfc7eSAndroid Build Coastguard Worker uint32_t log_level; /* verbosity level of verifier */
218*49cdfc7eSAndroid Build Coastguard Worker uint32_t log_size; /* size of user buffer */
219*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t log_buf; /* user supplied buffer */
220*49cdfc7eSAndroid Build Coastguard Worker uint32_t kern_version; /* not used */
221*49cdfc7eSAndroid Build Coastguard Worker uint32_t prog_flags;
222*49cdfc7eSAndroid Build Coastguard Worker char prog_name[BPF_OBJ_NAME_LEN];
223*49cdfc7eSAndroid Build Coastguard Worker uint32_t prog_ifindex; /* ifindex of netdev to prep for */
224*49cdfc7eSAndroid Build Coastguard Worker /* For some prog types expected attach type must be known at
225*49cdfc7eSAndroid Build Coastguard Worker * load time to verify attach type specific parts of prog
226*49cdfc7eSAndroid Build Coastguard Worker * (context accesses, allowed helpers, etc).
227*49cdfc7eSAndroid Build Coastguard Worker */
228*49cdfc7eSAndroid Build Coastguard Worker uint32_t expected_attach_type;
229*49cdfc7eSAndroid Build Coastguard Worker uint32_t prog_btf_fd; /* fd pointing to BTF type data */
230*49cdfc7eSAndroid Build Coastguard Worker uint32_t func_info_rec_size; /* userspace bpf_func_info size */
231*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t func_info; /* func info */
232*49cdfc7eSAndroid Build Coastguard Worker uint32_t func_info_cnt; /* number of bpf_func_info records */
233*49cdfc7eSAndroid Build Coastguard Worker uint32_t line_info_rec_size; /* userspace bpf_line_info size */
234*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t line_info; /* line info */
235*49cdfc7eSAndroid Build Coastguard Worker uint32_t line_info_cnt; /* number of bpf_line_info records */
236*49cdfc7eSAndroid Build Coastguard Worker };
237*49cdfc7eSAndroid Build Coastguard Worker
238*49cdfc7eSAndroid Build Coastguard Worker struct { /* anonymous struct used by BPF_OBJ_* commands */
239*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t pathname;
240*49cdfc7eSAndroid Build Coastguard Worker uint32_t bpf_fd;
241*49cdfc7eSAndroid Build Coastguard Worker uint32_t file_flags;
242*49cdfc7eSAndroid Build Coastguard Worker };
243*49cdfc7eSAndroid Build Coastguard Worker
244*49cdfc7eSAndroid Build Coastguard Worker struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
245*49cdfc7eSAndroid Build Coastguard Worker uint32_t target_fd; /* container object to attach to */
246*49cdfc7eSAndroid Build Coastguard Worker uint32_t attach_bpf_fd; /* eBPF program to attach */
247*49cdfc7eSAndroid Build Coastguard Worker uint32_t attach_type;
248*49cdfc7eSAndroid Build Coastguard Worker uint32_t attach_flags;
249*49cdfc7eSAndroid Build Coastguard Worker };
250*49cdfc7eSAndroid Build Coastguard Worker
251*49cdfc7eSAndroid Build Coastguard Worker struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
252*49cdfc7eSAndroid Build Coastguard Worker uint32_t prog_fd;
253*49cdfc7eSAndroid Build Coastguard Worker uint32_t retval;
254*49cdfc7eSAndroid Build Coastguard Worker uint32_t data_size_in; /* input: len of data_in */
255*49cdfc7eSAndroid Build Coastguard Worker uint32_t data_size_out; /* input/output: len of data_out
256*49cdfc7eSAndroid Build Coastguard Worker * returns ENOSPC if data_out
257*49cdfc7eSAndroid Build Coastguard Worker * is too small.
258*49cdfc7eSAndroid Build Coastguard Worker */
259*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t data_in;
260*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t data_out;
261*49cdfc7eSAndroid Build Coastguard Worker uint32_t repeat;
262*49cdfc7eSAndroid Build Coastguard Worker uint32_t duration;
263*49cdfc7eSAndroid Build Coastguard Worker uint32_t ctx_size_in; /* input: len of ctx_in */
264*49cdfc7eSAndroid Build Coastguard Worker uint32_t ctx_size_out; /* input/output: len of ctx_out
265*49cdfc7eSAndroid Build Coastguard Worker * returns ENOSPC if ctx_out
266*49cdfc7eSAndroid Build Coastguard Worker * is too small.
267*49cdfc7eSAndroid Build Coastguard Worker */
268*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t ctx_in;
269*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t ctx_out;
270*49cdfc7eSAndroid Build Coastguard Worker } test;
271*49cdfc7eSAndroid Build Coastguard Worker
272*49cdfc7eSAndroid Build Coastguard Worker struct { /* anonymous struct used by BPF_*_GET_*_ID */
273*49cdfc7eSAndroid Build Coastguard Worker union {
274*49cdfc7eSAndroid Build Coastguard Worker uint32_t start_id;
275*49cdfc7eSAndroid Build Coastguard Worker uint32_t prog_id;
276*49cdfc7eSAndroid Build Coastguard Worker uint32_t map_id;
277*49cdfc7eSAndroid Build Coastguard Worker uint32_t btf_id;
278*49cdfc7eSAndroid Build Coastguard Worker };
279*49cdfc7eSAndroid Build Coastguard Worker uint32_t next_id;
280*49cdfc7eSAndroid Build Coastguard Worker uint32_t open_flags;
281*49cdfc7eSAndroid Build Coastguard Worker };
282*49cdfc7eSAndroid Build Coastguard Worker
283*49cdfc7eSAndroid Build Coastguard Worker struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
284*49cdfc7eSAndroid Build Coastguard Worker uint32_t bpf_fd;
285*49cdfc7eSAndroid Build Coastguard Worker uint32_t info_len;
286*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t info;
287*49cdfc7eSAndroid Build Coastguard Worker } info;
288*49cdfc7eSAndroid Build Coastguard Worker
289*49cdfc7eSAndroid Build Coastguard Worker struct { /* anonymous struct used by BPF_PROG_QUERY command */
290*49cdfc7eSAndroid Build Coastguard Worker uint32_t target_fd; /* container object to query */
291*49cdfc7eSAndroid Build Coastguard Worker uint32_t attach_type;
292*49cdfc7eSAndroid Build Coastguard Worker uint32_t query_flags;
293*49cdfc7eSAndroid Build Coastguard Worker uint32_t attach_flags;
294*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t prog_ids;
295*49cdfc7eSAndroid Build Coastguard Worker uint32_t prog_cnt;
296*49cdfc7eSAndroid Build Coastguard Worker } query;
297*49cdfc7eSAndroid Build Coastguard Worker
298*49cdfc7eSAndroid Build Coastguard Worker struct {
299*49cdfc7eSAndroid Build Coastguard Worker uint64_t name;
300*49cdfc7eSAndroid Build Coastguard Worker uint32_t prog_fd;
301*49cdfc7eSAndroid Build Coastguard Worker } raw_tracepoint;
302*49cdfc7eSAndroid Build Coastguard Worker
303*49cdfc7eSAndroid Build Coastguard Worker struct { /* anonymous struct for BPF_BTF_LOAD */
304*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t btf;
305*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t btf_log_buf;
306*49cdfc7eSAndroid Build Coastguard Worker uint32_t btf_size;
307*49cdfc7eSAndroid Build Coastguard Worker uint32_t btf_log_size;
308*49cdfc7eSAndroid Build Coastguard Worker uint32_t btf_log_level;
309*49cdfc7eSAndroid Build Coastguard Worker };
310*49cdfc7eSAndroid Build Coastguard Worker
311*49cdfc7eSAndroid Build Coastguard Worker struct {
312*49cdfc7eSAndroid Build Coastguard Worker uint32_t pid; /* input: pid */
313*49cdfc7eSAndroid Build Coastguard Worker uint32_t fd; /* input: fd */
314*49cdfc7eSAndroid Build Coastguard Worker uint32_t flags; /* input: flags */
315*49cdfc7eSAndroid Build Coastguard Worker uint32_t buf_len; /* input/output: buf len */
316*49cdfc7eSAndroid Build Coastguard Worker aligned_uint64_t buf; /* input/output:
317*49cdfc7eSAndroid Build Coastguard Worker * tp_name for tracepoint
318*49cdfc7eSAndroid Build Coastguard Worker * symbol for kprobe
319*49cdfc7eSAndroid Build Coastguard Worker * filename for uprobe
320*49cdfc7eSAndroid Build Coastguard Worker */
321*49cdfc7eSAndroid Build Coastguard Worker uint32_t prog_id; /* output: prod_id */
322*49cdfc7eSAndroid Build Coastguard Worker uint32_t fd_type; /* output: BPF_FD_TYPE_* */
323*49cdfc7eSAndroid Build Coastguard Worker uint64_t probe_offset; /* output: probe_offset */
324*49cdfc7eSAndroid Build Coastguard Worker uint64_t probe_addr; /* output: probe_addr */
325*49cdfc7eSAndroid Build Coastguard Worker } task_fd_query;
326*49cdfc7eSAndroid Build Coastguard Worker } __attribute__((aligned(8)));
327*49cdfc7eSAndroid Build Coastguard Worker
328*49cdfc7eSAndroid Build Coastguard Worker #define __BPF_FUNC_MAPPER(FN) \
329*49cdfc7eSAndroid Build Coastguard Worker FN(unspec), \
330*49cdfc7eSAndroid Build Coastguard Worker FN(map_lookup_elem), \
331*49cdfc7eSAndroid Build Coastguard Worker FN(map_update_elem), \
332*49cdfc7eSAndroid Build Coastguard Worker FN(map_delete_elem), \
333*49cdfc7eSAndroid Build Coastguard Worker FN(probe_read), \
334*49cdfc7eSAndroid Build Coastguard Worker FN(ktime_get_ns), \
335*49cdfc7eSAndroid Build Coastguard Worker FN(trace_printk), \
336*49cdfc7eSAndroid Build Coastguard Worker FN(get_prandom_u32), \
337*49cdfc7eSAndroid Build Coastguard Worker FN(get_smp_processor_id), \
338*49cdfc7eSAndroid Build Coastguard Worker FN(skb_store_bytes), \
339*49cdfc7eSAndroid Build Coastguard Worker FN(l3_csum_replace), \
340*49cdfc7eSAndroid Build Coastguard Worker FN(l4_csum_replace), \
341*49cdfc7eSAndroid Build Coastguard Worker FN(tail_call), \
342*49cdfc7eSAndroid Build Coastguard Worker FN(clone_redirect), \
343*49cdfc7eSAndroid Build Coastguard Worker FN(get_current_pid_tgid), \
344*49cdfc7eSAndroid Build Coastguard Worker FN(get_current_uid_gid), \
345*49cdfc7eSAndroid Build Coastguard Worker FN(get_current_comm), \
346*49cdfc7eSAndroid Build Coastguard Worker FN(get_cgroup_classid), \
347*49cdfc7eSAndroid Build Coastguard Worker FN(skb_vlan_push), \
348*49cdfc7eSAndroid Build Coastguard Worker FN(skb_vlan_pop), \
349*49cdfc7eSAndroid Build Coastguard Worker FN(skb_get_tunnel_key), \
350*49cdfc7eSAndroid Build Coastguard Worker FN(skb_set_tunnel_key), \
351*49cdfc7eSAndroid Build Coastguard Worker FN(perf_event_read), \
352*49cdfc7eSAndroid Build Coastguard Worker FN(redirect), \
353*49cdfc7eSAndroid Build Coastguard Worker FN(get_route_realm), \
354*49cdfc7eSAndroid Build Coastguard Worker FN(perf_event_output), \
355*49cdfc7eSAndroid Build Coastguard Worker FN(skb_load_bytes), \
356*49cdfc7eSAndroid Build Coastguard Worker FN(get_stackid), \
357*49cdfc7eSAndroid Build Coastguard Worker FN(csum_diff), \
358*49cdfc7eSAndroid Build Coastguard Worker FN(skb_get_tunnel_opt), \
359*49cdfc7eSAndroid Build Coastguard Worker FN(skb_set_tunnel_opt), \
360*49cdfc7eSAndroid Build Coastguard Worker FN(skb_change_proto), \
361*49cdfc7eSAndroid Build Coastguard Worker FN(skb_change_type), \
362*49cdfc7eSAndroid Build Coastguard Worker FN(skb_under_cgroup), \
363*49cdfc7eSAndroid Build Coastguard Worker FN(get_hash_recalc), \
364*49cdfc7eSAndroid Build Coastguard Worker FN(get_current_task), \
365*49cdfc7eSAndroid Build Coastguard Worker FN(probe_write_user), \
366*49cdfc7eSAndroid Build Coastguard Worker FN(current_task_under_cgroup), \
367*49cdfc7eSAndroid Build Coastguard Worker FN(skb_change_tail), \
368*49cdfc7eSAndroid Build Coastguard Worker FN(skb_pull_data), \
369*49cdfc7eSAndroid Build Coastguard Worker FN(csum_update), \
370*49cdfc7eSAndroid Build Coastguard Worker FN(set_hash_invalid), \
371*49cdfc7eSAndroid Build Coastguard Worker FN(get_numa_node_id), \
372*49cdfc7eSAndroid Build Coastguard Worker FN(skb_change_head), \
373*49cdfc7eSAndroid Build Coastguard Worker FN(xdp_adjust_head), \
374*49cdfc7eSAndroid Build Coastguard Worker FN(probe_read_str), \
375*49cdfc7eSAndroid Build Coastguard Worker FN(get_socket_cookie), \
376*49cdfc7eSAndroid Build Coastguard Worker FN(get_socket_uid), \
377*49cdfc7eSAndroid Build Coastguard Worker FN(set_hash), \
378*49cdfc7eSAndroid Build Coastguard Worker FN(setsockopt), \
379*49cdfc7eSAndroid Build Coastguard Worker FN(skb_adjust_room), \
380*49cdfc7eSAndroid Build Coastguard Worker FN(redirect_map), \
381*49cdfc7eSAndroid Build Coastguard Worker FN(sk_redirect_map), \
382*49cdfc7eSAndroid Build Coastguard Worker FN(sock_map_update), \
383*49cdfc7eSAndroid Build Coastguard Worker FN(xdp_adjust_meta), \
384*49cdfc7eSAndroid Build Coastguard Worker FN(perf_event_read_value), \
385*49cdfc7eSAndroid Build Coastguard Worker FN(perf_prog_read_value), \
386*49cdfc7eSAndroid Build Coastguard Worker FN(getsockopt), \
387*49cdfc7eSAndroid Build Coastguard Worker FN(override_return), \
388*49cdfc7eSAndroid Build Coastguard Worker FN(sock_ops_cb_flags_set), \
389*49cdfc7eSAndroid Build Coastguard Worker FN(msg_redirect_map), \
390*49cdfc7eSAndroid Build Coastguard Worker FN(msg_apply_bytes), \
391*49cdfc7eSAndroid Build Coastguard Worker FN(msg_cork_bytes), \
392*49cdfc7eSAndroid Build Coastguard Worker FN(msg_pull_data), \
393*49cdfc7eSAndroid Build Coastguard Worker FN(bind), \
394*49cdfc7eSAndroid Build Coastguard Worker FN(xdp_adjust_tail), \
395*49cdfc7eSAndroid Build Coastguard Worker FN(skb_get_xfrm_state), \
396*49cdfc7eSAndroid Build Coastguard Worker FN(get_stack), \
397*49cdfc7eSAndroid Build Coastguard Worker FN(skb_load_bytes_relative), \
398*49cdfc7eSAndroid Build Coastguard Worker FN(fib_lookup), \
399*49cdfc7eSAndroid Build Coastguard Worker FN(sock_hash_update), \
400*49cdfc7eSAndroid Build Coastguard Worker FN(msg_redirect_hash), \
401*49cdfc7eSAndroid Build Coastguard Worker FN(sk_redirect_hash), \
402*49cdfc7eSAndroid Build Coastguard Worker FN(lwt_push_encap), \
403*49cdfc7eSAndroid Build Coastguard Worker FN(lwt_seg6_store_bytes), \
404*49cdfc7eSAndroid Build Coastguard Worker FN(lwt_seg6_adjust_srh), \
405*49cdfc7eSAndroid Build Coastguard Worker FN(lwt_seg6_action), \
406*49cdfc7eSAndroid Build Coastguard Worker FN(rc_repeat), \
407*49cdfc7eSAndroid Build Coastguard Worker FN(rc_keydown), \
408*49cdfc7eSAndroid Build Coastguard Worker FN(skb_cgroup_id), \
409*49cdfc7eSAndroid Build Coastguard Worker FN(get_current_cgroup_id), \
410*49cdfc7eSAndroid Build Coastguard Worker FN(get_local_storage), \
411*49cdfc7eSAndroid Build Coastguard Worker FN(sk_select_reuseport), \
412*49cdfc7eSAndroid Build Coastguard Worker FN(skb_ancestor_cgroup_id), \
413*49cdfc7eSAndroid Build Coastguard Worker FN(sk_lookup_tcp), \
414*49cdfc7eSAndroid Build Coastguard Worker FN(sk_lookup_udp), \
415*49cdfc7eSAndroid Build Coastguard Worker FN(sk_release), \
416*49cdfc7eSAndroid Build Coastguard Worker FN(map_push_elem), \
417*49cdfc7eSAndroid Build Coastguard Worker FN(map_pop_elem), \
418*49cdfc7eSAndroid Build Coastguard Worker FN(map_peek_elem), \
419*49cdfc7eSAndroid Build Coastguard Worker FN(msg_push_data), \
420*49cdfc7eSAndroid Build Coastguard Worker FN(msg_pop_data), \
421*49cdfc7eSAndroid Build Coastguard Worker FN(rc_pointer_rel), \
422*49cdfc7eSAndroid Build Coastguard Worker FN(spin_lock), \
423*49cdfc7eSAndroid Build Coastguard Worker FN(spin_unlock), \
424*49cdfc7eSAndroid Build Coastguard Worker FN(sk_fullsock), \
425*49cdfc7eSAndroid Build Coastguard Worker FN(tcp_sock), \
426*49cdfc7eSAndroid Build Coastguard Worker FN(skb_ecn_set_ce), \
427*49cdfc7eSAndroid Build Coastguard Worker FN(get_listener_sock), \
428*49cdfc7eSAndroid Build Coastguard Worker FN(skc_lookup_tcp), \
429*49cdfc7eSAndroid Build Coastguard Worker FN(tcp_check_syncookie), \
430*49cdfc7eSAndroid Build Coastguard Worker FN(sysctl_get_name), \
431*49cdfc7eSAndroid Build Coastguard Worker FN(sysctl_get_current_value), \
432*49cdfc7eSAndroid Build Coastguard Worker FN(sysctl_get_new_value), \
433*49cdfc7eSAndroid Build Coastguard Worker FN(sysctl_set_new_value), \
434*49cdfc7eSAndroid Build Coastguard Worker FN(strtol), \
435*49cdfc7eSAndroid Build Coastguard Worker FN(strtoul), \
436*49cdfc7eSAndroid Build Coastguard Worker FN(sk_storage_get), \
437*49cdfc7eSAndroid Build Coastguard Worker FN(sk_storage_delete), \
438*49cdfc7eSAndroid Build Coastguard Worker FN(send_signal), \
439*49cdfc7eSAndroid Build Coastguard Worker FN(tcp_gen_syncookie), \
440*49cdfc7eSAndroid Build Coastguard Worker FN(skb_output), \
441*49cdfc7eSAndroid Build Coastguard Worker FN(probe_read_user), \
442*49cdfc7eSAndroid Build Coastguard Worker FN(probe_read_kernel), \
443*49cdfc7eSAndroid Build Coastguard Worker FN(probe_read_user_str), \
444*49cdfc7eSAndroid Build Coastguard Worker FN(probe_read_kernel_str), \
445*49cdfc7eSAndroid Build Coastguard Worker FN(tcp_send_ack), \
446*49cdfc7eSAndroid Build Coastguard Worker FN(send_signal_thread), \
447*49cdfc7eSAndroid Build Coastguard Worker FN(jiffies64), \
448*49cdfc7eSAndroid Build Coastguard Worker FN(read_branch_records), \
449*49cdfc7eSAndroid Build Coastguard Worker FN(get_ns_current_pid_tgid), \
450*49cdfc7eSAndroid Build Coastguard Worker FN(xdp_output), \
451*49cdfc7eSAndroid Build Coastguard Worker FN(get_netns_cookie), \
452*49cdfc7eSAndroid Build Coastguard Worker FN(get_current_ancestor_cgroup_id), \
453*49cdfc7eSAndroid Build Coastguard Worker FN(sk_assign), \
454*49cdfc7eSAndroid Build Coastguard Worker FN(ktime_get_boot_ns), \
455*49cdfc7eSAndroid Build Coastguard Worker FN(seq_printf), \
456*49cdfc7eSAndroid Build Coastguard Worker FN(seq_write), \
457*49cdfc7eSAndroid Build Coastguard Worker FN(sk_cgroup_id), \
458*49cdfc7eSAndroid Build Coastguard Worker FN(sk_ancestor_cgroup_id), \
459*49cdfc7eSAndroid Build Coastguard Worker FN(ringbuf_output), \
460*49cdfc7eSAndroid Build Coastguard Worker FN(ringbuf_reserve), \
461*49cdfc7eSAndroid Build Coastguard Worker FN(ringbuf_submit), \
462*49cdfc7eSAndroid Build Coastguard Worker FN(ringbuf_discard), \
463*49cdfc7eSAndroid Build Coastguard Worker FN(ringbuf_query), \
464*49cdfc7eSAndroid Build Coastguard Worker FN(csum_level),
465*49cdfc7eSAndroid Build Coastguard Worker
466*49cdfc7eSAndroid Build Coastguard Worker /* integer value in 'imm' field of BPF_CALL instruction selects which helper
467*49cdfc7eSAndroid Build Coastguard Worker * function eBPF program intends to call
468*49cdfc7eSAndroid Build Coastguard Worker */
469*49cdfc7eSAndroid Build Coastguard Worker #define __BPF_ENUM_FN(x) BPF_FUNC_ ## x
470*49cdfc7eSAndroid Build Coastguard Worker enum bpf_func_id {
471*49cdfc7eSAndroid Build Coastguard Worker __BPF_FUNC_MAPPER(__BPF_ENUM_FN)
472*49cdfc7eSAndroid Build Coastguard Worker __BPF_FUNC_MAX_ID,
473*49cdfc7eSAndroid Build Coastguard Worker };
474*49cdfc7eSAndroid Build Coastguard Worker #undef __BPF_ENUM_FN
475*49cdfc7eSAndroid Build Coastguard Worker
476*49cdfc7eSAndroid Build Coastguard Worker /* End copy from linux/bpf.h */
477*49cdfc7eSAndroid Build Coastguard Worker
478*49cdfc7eSAndroid Build Coastguard Worker /* Start copy from tools/include/filter.h */
479*49cdfc7eSAndroid Build Coastguard Worker
480*49cdfc7eSAndroid Build Coastguard Worker #define BPF_ALU64_REG(OP, DST, SRC) \
481*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
482*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_ALU64 | BPF_OP(OP) | BPF_X, \
483*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = DST, \
484*49cdfc7eSAndroid Build Coastguard Worker .src_reg = SRC, \
485*49cdfc7eSAndroid Build Coastguard Worker .off = 0, \
486*49cdfc7eSAndroid Build Coastguard Worker .imm = 0 })
487*49cdfc7eSAndroid Build Coastguard Worker
488*49cdfc7eSAndroid Build Coastguard Worker #define BPF_ALU32_REG(OP, DST, SRC) \
489*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
490*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_ALU | BPF_OP(OP) | BPF_X, \
491*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = DST, \
492*49cdfc7eSAndroid Build Coastguard Worker .src_reg = SRC, \
493*49cdfc7eSAndroid Build Coastguard Worker .off = 0, \
494*49cdfc7eSAndroid Build Coastguard Worker .imm = 0 })
495*49cdfc7eSAndroid Build Coastguard Worker
496*49cdfc7eSAndroid Build Coastguard Worker #define BPF_ALU64_IMM(OP, DST, IMM) \
497*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
498*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_ALU64 | BPF_OP(OP) | BPF_K, \
499*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = DST, \
500*49cdfc7eSAndroid Build Coastguard Worker .src_reg = 0, \
501*49cdfc7eSAndroid Build Coastguard Worker .off = 0, \
502*49cdfc7eSAndroid Build Coastguard Worker .imm = IMM })
503*49cdfc7eSAndroid Build Coastguard Worker
504*49cdfc7eSAndroid Build Coastguard Worker #define BPF_ALU32_IMM(OP, DST, IMM) \
505*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
506*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_ALU | BPF_OP(OP) | BPF_K, \
507*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = DST, \
508*49cdfc7eSAndroid Build Coastguard Worker .src_reg = 0, \
509*49cdfc7eSAndroid Build Coastguard Worker .off = 0, \
510*49cdfc7eSAndroid Build Coastguard Worker .imm = IMM })
511*49cdfc7eSAndroid Build Coastguard Worker
512*49cdfc7eSAndroid Build Coastguard Worker #define BPF_MOV64_REG(DST, SRC) \
513*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
514*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_ALU64 | BPF_MOV | BPF_X, \
515*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = DST, \
516*49cdfc7eSAndroid Build Coastguard Worker .src_reg = SRC, \
517*49cdfc7eSAndroid Build Coastguard Worker .off = 0, \
518*49cdfc7eSAndroid Build Coastguard Worker .imm = 0 })
519*49cdfc7eSAndroid Build Coastguard Worker
520*49cdfc7eSAndroid Build Coastguard Worker #define BPF_MOV32_REG(DST, SRC) \
521*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
522*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_ALU | BPF_MOV | BPF_X, \
523*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = DST, \
524*49cdfc7eSAndroid Build Coastguard Worker .src_reg = SRC, \
525*49cdfc7eSAndroid Build Coastguard Worker .off = 0, \
526*49cdfc7eSAndroid Build Coastguard Worker .imm = 0 })
527*49cdfc7eSAndroid Build Coastguard Worker
528*49cdfc7eSAndroid Build Coastguard Worker #define BPF_LD_IMM64(DST, IMM) \
529*49cdfc7eSAndroid Build Coastguard Worker BPF_LD_IMM64_RAW(DST, 0, IMM)
530*49cdfc7eSAndroid Build Coastguard Worker
531*49cdfc7eSAndroid Build Coastguard Worker #define BPF_LD_IMM64_RAW(DST, SRC, IMM) \
532*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
533*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_LD | BPF_DW | BPF_IMM, \
534*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = DST, \
535*49cdfc7eSAndroid Build Coastguard Worker .src_reg = SRC, \
536*49cdfc7eSAndroid Build Coastguard Worker .off = 0, \
537*49cdfc7eSAndroid Build Coastguard Worker .imm = (uint32_t) (IMM) }), \
538*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
539*49cdfc7eSAndroid Build Coastguard Worker .code = 0, /* zero is reserved opcode */ \
540*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = 0, \
541*49cdfc7eSAndroid Build Coastguard Worker .src_reg = 0, \
542*49cdfc7eSAndroid Build Coastguard Worker .off = 0, \
543*49cdfc7eSAndroid Build Coastguard Worker .imm = ((uint64_t) (IMM)) >> 32 })
544*49cdfc7eSAndroid Build Coastguard Worker
545*49cdfc7eSAndroid Build Coastguard Worker /* pseudo BPF_LD_IMM64 insn used to refer to process-local map_fd */
546*49cdfc7eSAndroid Build Coastguard Worker #define BPF_LD_MAP_FD(DST, MAP_FD) \
547*49cdfc7eSAndroid Build Coastguard Worker BPF_LD_IMM64_RAW(DST, BPF_PSEUDO_MAP_FD, MAP_FD)
548*49cdfc7eSAndroid Build Coastguard Worker
549*49cdfc7eSAndroid Build Coastguard Worker #define BPF_ST_MEM(SIZE, DST, OFF, IMM) \
550*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
551*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_ST | BPF_SIZE(SIZE) | BPF_MEM, \
552*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = DST, \
553*49cdfc7eSAndroid Build Coastguard Worker .src_reg = 0, \
554*49cdfc7eSAndroid Build Coastguard Worker .off = OFF, \
555*49cdfc7eSAndroid Build Coastguard Worker .imm = IMM })
556*49cdfc7eSAndroid Build Coastguard Worker
557*49cdfc7eSAndroid Build Coastguard Worker #define BPF_LDX_MEM(SIZE, DST, SRC, OFF) \
558*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
559*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_LDX | BPF_SIZE(SIZE) | BPF_MEM, \
560*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = DST, \
561*49cdfc7eSAndroid Build Coastguard Worker .src_reg = SRC, \
562*49cdfc7eSAndroid Build Coastguard Worker .off = OFF, \
563*49cdfc7eSAndroid Build Coastguard Worker .imm = 0 })
564*49cdfc7eSAndroid Build Coastguard Worker
565*49cdfc7eSAndroid Build Coastguard Worker #define BPF_STX_MEM(SIZE, DST, SRC, OFF) \
566*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
567*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_STX | BPF_SIZE(SIZE) | BPF_MEM, \
568*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = DST, \
569*49cdfc7eSAndroid Build Coastguard Worker .src_reg = SRC, \
570*49cdfc7eSAndroid Build Coastguard Worker .off = OFF, \
571*49cdfc7eSAndroid Build Coastguard Worker .imm = 0 })
572*49cdfc7eSAndroid Build Coastguard Worker
573*49cdfc7eSAndroid Build Coastguard Worker #define BPF_JMP_IMM(OP, DST, IMM, OFF) \
574*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
575*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_JMP | BPF_OP(OP) | BPF_K, \
576*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = DST, \
577*49cdfc7eSAndroid Build Coastguard Worker .src_reg = 0, \
578*49cdfc7eSAndroid Build Coastguard Worker .off = OFF, \
579*49cdfc7eSAndroid Build Coastguard Worker .imm = IMM })
580*49cdfc7eSAndroid Build Coastguard Worker
581*49cdfc7eSAndroid Build Coastguard Worker #define BPF_MOV64_IMM(DST, IMM) \
582*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
583*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_ALU64 | BPF_MOV | BPF_K, \
584*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = DST, \
585*49cdfc7eSAndroid Build Coastguard Worker .src_reg = 0, \
586*49cdfc7eSAndroid Build Coastguard Worker .off = 0, \
587*49cdfc7eSAndroid Build Coastguard Worker .imm = IMM })
588*49cdfc7eSAndroid Build Coastguard Worker
589*49cdfc7eSAndroid Build Coastguard Worker #define BPF_MOV32_IMM(DST, IMM) \
590*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
591*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_ALU | BPF_MOV | BPF_K, \
592*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = DST, \
593*49cdfc7eSAndroid Build Coastguard Worker .src_reg = 0, \
594*49cdfc7eSAndroid Build Coastguard Worker .off = 0, \
595*49cdfc7eSAndroid Build Coastguard Worker .imm = IMM })
596*49cdfc7eSAndroid Build Coastguard Worker
597*49cdfc7eSAndroid Build Coastguard Worker #define BPF_EMIT_CALL(FUNC) \
598*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
599*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_JMP | BPF_CALL, \
600*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = 0, \
601*49cdfc7eSAndroid Build Coastguard Worker .src_reg = 0, \
602*49cdfc7eSAndroid Build Coastguard Worker .off = 0, \
603*49cdfc7eSAndroid Build Coastguard Worker .imm = ((FUNC) - BPF_FUNC_unspec) })
604*49cdfc7eSAndroid Build Coastguard Worker
605*49cdfc7eSAndroid Build Coastguard Worker #define BPF_EXIT_INSN() \
606*49cdfc7eSAndroid Build Coastguard Worker ((struct bpf_insn) { \
607*49cdfc7eSAndroid Build Coastguard Worker .code = BPF_JMP | BPF_EXIT, \
608*49cdfc7eSAndroid Build Coastguard Worker .dst_reg = 0, \
609*49cdfc7eSAndroid Build Coastguard Worker .src_reg = 0, \
610*49cdfc7eSAndroid Build Coastguard Worker .off = 0, \
611*49cdfc7eSAndroid Build Coastguard Worker .imm = 0 })
612*49cdfc7eSAndroid Build Coastguard Worker
613*49cdfc7eSAndroid Build Coastguard Worker /* End copy from tools/include/filter.h */
614*49cdfc7eSAndroid Build Coastguard Worker
615*49cdfc7eSAndroid Build Coastguard Worker /* Start copy from tools/lib/bpf */
ptr_to_u64(const void * ptr)616*49cdfc7eSAndroid Build Coastguard Worker static inline uint64_t ptr_to_u64(const void *ptr)
617*49cdfc7eSAndroid Build Coastguard Worker {
618*49cdfc7eSAndroid Build Coastguard Worker return (uint64_t) (unsigned long) ptr;
619*49cdfc7eSAndroid Build Coastguard Worker }
620*49cdfc7eSAndroid Build Coastguard Worker
bpf(enum bpf_cmd cmd,union bpf_attr * attr,unsigned int size)621*49cdfc7eSAndroid Build Coastguard Worker static inline int bpf(enum bpf_cmd cmd, union bpf_attr *attr, unsigned int size)
622*49cdfc7eSAndroid Build Coastguard Worker {
623*49cdfc7eSAndroid Build Coastguard Worker return tst_syscall(__NR_bpf, cmd, attr, size);
624*49cdfc7eSAndroid Build Coastguard Worker }
625*49cdfc7eSAndroid Build Coastguard Worker /* End copy from tools/lib/bpf */
626*49cdfc7eSAndroid Build Coastguard Worker
627*49cdfc7eSAndroid Build Coastguard Worker #endif /* LAPI_BPF_H__ */
628