]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/bpf/bpf-helpers.h
Update copyright years.
[thirdparty/gcc.git] / gcc / config / bpf / bpf-helpers.h
CommitLineData
99dee823 1/* Copyright (C) 2019-2021 Free Software Foundation, Inc.
91dfef96
JM
2
3 This file is part of GCC.
4
5 GCC is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3, or (at your option)
8 any later version.
9
10 GCC is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 Under Section 7 of GPL version 3, you are granted additional
16 permissions described in the GCC Runtime Library Exception, version
17 3.1, as published by the Free Software Foundation.
18
19 You should have received a copy of the GNU General Public License and
20 a copy of the GCC Runtime Library Exception along with this program;
21 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 <http://www.gnu.org/licenses/>. */
23
24/* The purpose of this file is to provide a compatiblity layer with
25 the Linux kernel bpf_helpers.h header that is located in
26 linux/tools/testing/selftests/bpf/bpf_helpers.h. That file is
27 currently llvm-specific. */
28
29#ifndef __BPF_HELPERS_H
30#define __BPF_HELPERS_H
31
32#define SEC(NAME) __attribute__((section(NAME), used))
af30b83b 33#define KERNEL_HELPER(NUM) __attribute__((kernel_helper(NUM)))
91dfef96
JM
34
35/* Flags used in some kernel helpers. */
36
37#define BPF_ANY 0
38#define BPF_NOEXIST 1
39#define BPF_EXIST 2
40
41#define BPF_F_LOCK 4
42#define BPF_F_NO_COMMON_LRU (1U << 1)
43#define BPF_F_NUMA_NODE (1U << 2)
44
af30b83b
JM
45/* Prototypes of functions to call kernel helpers.
46 Please keep these protoypes sorted by helper number. */
91dfef96 47
af30b83b
JM
48void *bpf_map_lookup_elem (void *map, const void *key)
49 KERNEL_HELPER (1);
91dfef96 50
af30b83b
JM
51int bpf_map_update_elem (void *map, const void *key, const void *value,
52 unsigned long long flags)
53 KERNEL_HELPER (2);
91dfef96 54
af30b83b
JM
55int bpf_map_delete_elem (void *map, const void *key)
56 KERNEL_HELPER (3);
91dfef96 57
af30b83b
JM
58int bpf_probe_read (void *dst, int size, const void *unsafe_ptr)
59 KERNEL_HELPER (4);
91dfef96 60
af30b83b
JM
61unsigned long long bpf_ktime_get_ns (void)
62 KERNEL_HELPER (5);
91dfef96 63
af30b83b
JM
64int bpf_trace_printk (const char *fmt, int fmt_size, ...)
65 KERNEL_HELPER (6);
91dfef96 66
af30b83b
JM
67unsigned long long bpf_get_prandom_u32 (void)
68 KERNEL_HELPER (7);
91dfef96 69
af30b83b
JM
70unsigned long long bpf_get_smp_processor_id (void)
71 KERNEL_HELPER (8);
91dfef96 72
af30b83b
JM
73int bpf_skb_store_bytes (void *ctx, int off, void *from, int len,
74 unsigned int start_header)
75 KERNEL_HELPER (9);
91dfef96 76
af30b83b
JM
77int bpf_l3_csum_replace (void *ctx, int off, int from, int to, int flags)
78 KERNEL_HELPER (10);
91dfef96 79
af30b83b
JM
80int bpf_l4_csum_replace (void *ctx, int off, int from, int to, int flags)
81 KERNEL_HELPER (11);
91dfef96 82
af30b83b
JM
83int bpf_tail_call (void *ctx, void *map, unsigned int index)
84 KERNEL_HELPER (12);
91dfef96 85
af30b83b
JM
86int bpf_clone_redirect (void *ctx, int ifindex, int flags)
87 KERNEL_HELPER (13);
91dfef96 88
af30b83b
JM
89unsigned long long bpf_get_current_pid_tgid (void)
90 KERNEL_HELPER (14);
91dfef96 91
af30b83b
JM
92unsigned long long bpf_get_current_uid_gid (void)
93 KERNEL_HELPER (15);
91dfef96 94
af30b83b
JM
95int bpf_get_current_comm (void *buf, int buf_size)
96 KERNEL_HELPER (16);
91dfef96 97
af30b83b
JM
98unsigned int bpf_get_cgroup_classid (void *ctx)
99 KERNEL_HELPER (17);
91dfef96 100
af30b83b
JM
101int bpf_skb_vlan_push (void *ctx, short vlan_proto,
102 unsigned short vlan_tci)
103 KERNEL_HELPER (18);
91dfef96 104
af30b83b
JM
105int bpf_skb_vlan_pop (void *ctx)
106 KERNEL_HELPER (19);
91dfef96 107
af30b83b
JM
108int bpf_skb_get_tunnel_key (void *ctx, void *key, int size, int flags)
109 KERNEL_HELPER (20);
91dfef96 110
af30b83b
JM
111int bpf_skb_set_tunnel_key (void *ctx, void *key, int size, int flags)
112 KERNEL_HELPER (21);
91dfef96 113
af30b83b
JM
114unsigned long long bpf_perf_event_read (void *map, unsigned long long flags)
115 KERNEL_HELPER (22);
91dfef96 116
af30b83b
JM
117int bpf_redirect (int ifindex, int flags)
118 KERNEL_HELPER (23);
91dfef96 119
af30b83b
JM
120unsigned int bpf_get_route_realm (void *ctx)
121 KERNEL_HELPER (24);
91dfef96 122
af30b83b
JM
123int bpf_perf_event_output (void *ctx, void *map, unsigned long long flags,
124 void *data, int size)
125 KERNEL_HELPER (25);
91dfef96 126
af30b83b
JM
127int bpf_skb_load_bytes (void *ctx, int off, void *to, int len)
128 KERNEL_HELPER (26);
91dfef96 129
af30b83b
JM
130int bpf_get_stackid (void *ctx, void *map, int flags)
131 KERNEL_HELPER (27);
91dfef96 132
af30b83b
JM
133int bpf_csum_diff (void *from, int from_size, void *to, int to_size, int seed)
134 KERNEL_HELPER (28);
91dfef96 135
af30b83b
JM
136int bpf_skb_get_tunnel_opt (void *ctx, void *md, int size)
137 KERNEL_HELPER (29);
91dfef96 138
af30b83b
JM
139int bpf_skb_set_tunnel_opt (void *ctx, void *md, int size)
140 KERNEL_HELPER (30);
91dfef96 141
af30b83b
JM
142int bpf_skb_change_proto (void *ctx, short proto, unsigned long flags)
143 KERNEL_HELPER (31);
91dfef96 144
af30b83b
JM
145int bpf_skb_change_type (void *ctx, unsigned int type)
146 KERNEL_HELPER (32);
91dfef96 147
af30b83b
JM
148int bpf_skb_under_cgroup (void *ctx, void *map, int index)
149 KERNEL_HELPER (33);
91dfef96 150
af30b83b
JM
151unsigned int bpf_get_hash_recalc (void *ctx)
152 KERNEL_HELPER (34);
91dfef96 153
af30b83b
JM
154unsigned long long bpf_get_current_task (void)
155 KERNEL_HELPER (35);
91dfef96 156
af30b83b
JM
157int bpf_probe_write_user (void *dst, const void *src, int size)
158 KERNEL_HELPER (36);
91dfef96 159
af30b83b
JM
160int bpf_current_task_under_cgroup (void *map, int index)
161 KERNEL_HELPER (37);
91dfef96 162
af30b83b
JM
163int bpf_skb_change_tail (void *ctx, unsigned int len, unsigned long flags)
164 KERNEL_HELPER (38);
91dfef96 165
af30b83b
JM
166int bpf_skb_pull_data (void *, int len)
167 KERNEL_HELPER (39);
91dfef96 168
af30b83b
JM
169long long bpf_csum_update (void *ctx, unsigned int csum)
170 KERNEL_HELPER (40);
91dfef96 171
af30b83b
JM
172void bpf_set_hash_invalid (void *ctx)
173 KERNEL_HELPER (41);
91dfef96 174
af30b83b
JM
175int bpf_get_numa_node_id (void)
176 KERNEL_HELPER (42);
91dfef96 177
af30b83b
JM
178int bpf_skb_change_head (void *, int len, int flags)
179 KERNEL_HELPER (43);
91dfef96 180
af30b83b
JM
181int bpf_xdp_adjust_head (void *ctx, int offset)
182 KERNEL_HELPER (44);
91dfef96 183
af30b83b
JM
184int bpf_probe_read_str (void *ctx, unsigned int size, const void *unsafe_ptr)
185 KERNEL_HELPER (45);
91dfef96 186
af30b83b
JM
187int bpf_get_socket_cookie (void *ctx)
188 KERNEL_HELPER (46);
91dfef96 189
af30b83b
JM
190unsigned int bpf_get_socket_uid (void *ctx)
191 KERNEL_HELPER (47);
91dfef96 192
af30b83b
JM
193unsigned int bpf_set_hash (void *ctx, unsigned int hash)
194 KERNEL_HELPER (48);
91dfef96 195
af30b83b
JM
196int bpf_setsockopt (void *ctx, int level, int optname, void *optval, int optlen)
197 KERNEL_HELPER (49);
91dfef96 198
af30b83b
JM
199int bpf_skb_adjust_room (void *ctx, int len_diff, unsigned int mode,
200 unsigned long long flags)
201 KERNEL_HELPER (50);
91dfef96 202
af30b83b
JM
203int bpf_redirect_map (void *map, int key, int flags)
204 KERNEL_HELPER (51);
205
206int bpf_sk_redirect_map (void *ctx, void *map, int key, int flags)
207 KERNEL_HELPER (52);
208
209int bpf_sock_map_update (void *map, void *key, void *value,
210 unsigned long long flags)
211 KERNEL_HELPER (53);
212
213int bpf_xdp_adjust_meta (void *ctx, int offset)
214 KERNEL_HELPER (54);
215
216int bpf_perf_event_read_value (void *map, unsigned long long flags,
217 void *buf, unsigned int buf_size)
218 KERNEL_HELPER (55);
219
220int bpf_perf_prog_read_value (void *ctx, void *buf, unsigned int buf_size)
221 KERNEL_HELPER (56);
222
223int bpf_getsockopt (void *ctx, int level, int optname, void *optval,
224 int optlen)
225 KERNEL_HELPER (57);
226
227int bpf_override_return (void *ctx, unsigned long rc)
228 KERNEL_HELPER (58);
229
230int bpf_sock_ops_cb_flags_set (void *ctx, int flags)
231 KERNEL_HELPER (59);
232
233int bpf_msg_redirect_map (void *ctx, void *map, int key, int flags)
234 KERNEL_HELPER (60);
235
236int bpf_msg_apply_bytes (void *ctx, int len)
237 KERNEL_HELPER (61);
238
239int bpf_msg_cork_bytes (void *ctx, int len)
240 KERNEL_HELPER (62);
241
242int bpf_msg_pull_data (void *, int len)
243 KERNEL_HELPER (63);
244
245int bpf_bind (void *ctx, void *addr, int addr_len)
246 KERNEL_HELPER (64);
247
248int bpf_xdp_adjust_tail (struct xdp_md *xdp_md, int delta)
249 KERNEL_HELPER (65);
250
251int bpf_skb_get_xfrm_state (void *ctx, int index, void *state,
252 int size, int flags)
253 KERNEL_HELPER (66);
254
255int bpf_get_stack (void *ctx, void *buf, int size, int flags)
256 KERNEL_HELPER (67);
257
258int bpf_skb_load_bytes_relative (void *ctx, int off, void *to, int len,
259 unsigned int start_header)
260 KERNEL_HELPER (68);
261
262int bpf_fib_lookup (void *ctx, struct bpf_fib_lookup *params,
263 int plen, unsigned int flags)
264 KERNEL_HELPER (69);
265
266int bpf_sock_hash_update (void *map, void *key, void *value,
267 unsigned long long flags)
268 KERNEL_HELPER (70);
269
270int bpf_msg_redirect_hash (void *ctx, void *map, void *key, int flags)
271 KERNEL_HELPER (71);
272
273int bpf_sk_redirect_hash (void *ctx, void *map, void *key, int flags)
274 KERNEL_HELPER (72);
275
276int bpf_lwt_push_encap (void *ctx, unsigned int type, void *hdr,
277 unsigned int len)
278 KERNEL_HELPER (73);
279
280int bpf_lwt_seg6_store_bytes (void *ctx, unsigned int offset,
281 void *from, unsigned int len)
282 KERNEL_HELPER (74);
283
284int bpf_lwt_seg6_adjust_srh (void *ctx, unsigned int offset,
285 unsigned int len)
286 KERNEL_HELPER (75);
287
288int bpf_lwt_seg6_action (void *ctx, unsigned int action, void *param,
289 unsigned int param_len)
290 KERNEL_HELPER (76);
291
292int bpf_rc_repeat (void *ctx)
293 KERNEL_HELPER (77);
294
295int bpf_rc_keydown (void *ctx, unsigned int protocol,
296 unsigned long long scancode, unsigned int toggle)
297 KERNEL_HELPER (78);
298
299unsigned bpf_skb_cgroup_id (void *ctx)
300 KERNEL_HELPER (79);
301
302unsigned long long bpf_get_current_cgroup_id (void)
303 KERNEL_HELPER (80);
304
305void *bpf_get_local_storage (void *map, unsigned long long flags)
306 KERNEL_HELPER (81);
307
308int bpf_sk_select_reuseport (void *ctx, void *map, void *key, unsigned int flags)
309 KERNEL_HELPER (82);
310
311unsigned long long bpf_skb_ancestor_cgroup_id (void *ctx, int level)
312 KERNEL_HELPER (83);
313
314struct bpf_sock *bpf_sk_lookup_tcp (void *ctx, struct bpf_sock_tuple *tuple,
315 int size, unsigned long long netns_id,
316 unsigned long long flags)
317 KERNEL_HELPER (84);
318
319struct bpf_sock *bpf_sk_lookup_udp (void *ctx, struct bpf_sock_tuple *tuple,
320 int size, unsigned long long netns_id,
321 unsigned long long flags)
322 KERNEL_HELPER (85);
323
324int bpf_sk_release (struct bpf_sock *sk)
325 KERNEL_HELPER (86);
326
327int bpf_map_push_elem (void *map, const void *value, unsigned long long flags)
328 KERNEL_HELPER (87);
329
330int bpf_map_pop_elem (void *map, void *value)
331 KERNEL_HELPER (88);
332
333int bpf_map_peek_elem (void *map, void *value)
334 KERNEL_HELPER (89);
335
336int bpf_msg_push_data (void *ctx, int start, int cut, int flags)
337 KERNEL_HELPER (90);
338
339int bpf_msg_pop_data (void *ctx, int start, int cut, int flags)
340 KERNEL_HELPER (91);
341
342int bpf_rc_pointer_rel (void *ctx, int rel_x, int rel_y)
343 KERNEL_HELPER (92);
344
345void bpf_spin_lock (struct bpf_spin_lock *lock)
346 KERNEL_HELPER (93);
347
348void bpf_spin_unlock (struct bpf_spin_lock *lock)
349 KERNEL_HELPER (94);
350
351struct bpf_sock *bpf_sk_fullsock (struct bpf_sock *sk)
352 KERNEL_HELPER (95);
353
354struct bpf_sock *bpf_tcp_sock (struct bpf_sock *sk)
355 KERNEL_HELPER (96);
356
357int bpf_skb_ecn_set_ce (void *ctx)
358 KERNEL_HELPER (97);
359
360struct bpf_sock *bpf_get_listener_sock (struct bpf_sock *sk)
361 KERNEL_HELPER (98);
362
363struct bpf_sock *bpf_skc_lookup_tcp (void *ctx,
364 struct bpf_sock_tuple *tuple,
365 unsigned int tuple_size,
366 unsigned long netns,
367 unsigned long flags)
368 KERNEL_HELPER (99);
369
370int bpf_tcp_check_syncookie (struct bpf_sock *sk, void *iph,
371 unsigned int iph_len,
372 struct tcp_hdr *th,
373 unsigned int th_len)
374 KERNEL_HELPER (100);
375
376int bpf_sysctl_get_name (struct bpf_sysctl *ctx,
377 char *buf, unsigned long buf_len,
378 unsigned long flags)
379 KERNEL_HELPER (101);
380
381int bpf_sysctl_get_current_value (struct bpf_sysctl *ctx,
382 char *buf, unsigned long buf_len)
383 KERNEL_HELPER (102);
384
385int bpf_sysctl_get_new_value (struct bpf_sysctl *ctx, char *buf,
386 unsigned long buf_len)
387 KERNEL_HELPER (103);
388
389int bpf_sysctl_set_new_value (struct bpf_sysctl *ctx, const char *buf,
390 unsigned long buf_len)
391 KERNEL_HELPER (104);
392
393int bpf_strtol (const char *buf, unsigned long buf_len,
394 unsigned long flags, long *res)
395 KERNEL_HELPER (105);
396
397int bpf_strtoul (const char *buf, unsigned long buf_len,
398 unsigned long flags, unsigned long *res)
399 KERNEL_HELPER (106);
400
401void *bpf_sk_storage_get (void *map, struct bpf_sock *sk,
402 void *value, long flags)
403 KERNEL_HELPER (107);
404
405int bpf_sk_storage_delete (void *map, struct bpf_sock *sk)
406 KERNEL_HELPER (108);
91dfef96
JM
407
408/* Functions to emit BPF_LD_ABS and BPF_LD_IND instructions. We
409 provide the "standard" names as synonyms of the corresponding GCC
410 builtins. Note how the SKB argument is ignored. */
411
af30b83b
JM
412#define load_byte(SKB,OFF) __builtin_bpf_load_byte ((OFF))
413#define load_half(SKB,OFF) __builtin_bpf_load_half ((OFF))
414#define load_word(SKB,OFF) __builtin_bpf_load_word ((OFF))
91dfef96
JM
415
416struct bpf_map_def
417{
418 unsigned int type;
419 unsigned int key_size;
420 unsigned int value_size;
421 unsigned int max_entries;
422 unsigned int map_flags;
423 unsigned int inner_map_idx;
424 unsigned int numa_node;
425};
426
427#endif /* ! __BPF_HELPERS_H */