1 /* Copyright (C) 2019-2023 Free Software Foundation, Inc.
3 This file is part of GCC.
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)
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.
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.
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/>. */
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. */
29 #ifndef __BPF_HELPERS_H
30 #define __BPF_HELPERS_H
32 #define SEC(NAME) __attribute__((section(NAME), used))
33 #define KERNEL_HELPER(NUM) __attribute__((kernel_helper(NUM)))
35 /* Flags used in some kernel helpers. */
42 #define BPF_F_NO_COMMON_LRU (1U << 1)
43 #define BPF_F_NUMA_NODE (1U << 2)
45 /* Prototypes of functions to call kernel helpers.
46 Please keep these protoypes sorted by helper number. */
48 void *bpf_map_lookup_elem (void *map
, const void *key
)
51 int bpf_map_update_elem (void *map
, const void *key
, const void *value
,
52 unsigned long long flags
)
55 int bpf_map_delete_elem (void *map
, const void *key
)
58 int bpf_probe_read (void *dst
, int size
, const void *unsafe_ptr
)
61 unsigned long long bpf_ktime_get_ns (void)
64 int bpf_trace_printk (const char *fmt
, int fmt_size
, ...)
67 unsigned long long bpf_get_prandom_u32 (void)
70 unsigned long long bpf_get_smp_processor_id (void)
73 int bpf_skb_store_bytes (void *ctx
, int off
, void *from
, int len
,
74 unsigned int start_header
)
77 int bpf_l3_csum_replace (void *ctx
, int off
, int from
, int to
, int flags
)
80 int bpf_l4_csum_replace (void *ctx
, int off
, int from
, int to
, int flags
)
83 int bpf_tail_call (void *ctx
, void *map
, unsigned int index
)
86 int bpf_clone_redirect (void *ctx
, int ifindex
, int flags
)
89 unsigned long long bpf_get_current_pid_tgid (void)
92 unsigned long long bpf_get_current_uid_gid (void)
95 int bpf_get_current_comm (void *buf
, int buf_size
)
98 unsigned int bpf_get_cgroup_classid (void *ctx
)
101 int bpf_skb_vlan_push (void *ctx
, short vlan_proto
,
102 unsigned short vlan_tci
)
105 int bpf_skb_vlan_pop (void *ctx
)
108 int bpf_skb_get_tunnel_key (void *ctx
, void *key
, int size
, int flags
)
111 int bpf_skb_set_tunnel_key (void *ctx
, void *key
, int size
, int flags
)
114 unsigned long long bpf_perf_event_read (void *map
, unsigned long long flags
)
117 int bpf_redirect (int ifindex
, int flags
)
120 unsigned int bpf_get_route_realm (void *ctx
)
123 int bpf_perf_event_output (void *ctx
, void *map
, unsigned long long flags
,
124 void *data
, int size
)
127 int bpf_skb_load_bytes (void *ctx
, int off
, void *to
, int len
)
130 int bpf_get_stackid (void *ctx
, void *map
, int flags
)
133 int bpf_csum_diff (void *from
, int from_size
, void *to
, int to_size
, int seed
)
136 int bpf_skb_get_tunnel_opt (void *ctx
, void *md
, int size
)
139 int bpf_skb_set_tunnel_opt (void *ctx
, void *md
, int size
)
142 int bpf_skb_change_proto (void *ctx
, short proto
, unsigned long flags
)
145 int bpf_skb_change_type (void *ctx
, unsigned int type
)
148 int bpf_skb_under_cgroup (void *ctx
, void *map
, int index
)
151 unsigned int bpf_get_hash_recalc (void *ctx
)
154 unsigned long long bpf_get_current_task (void)
157 int bpf_probe_write_user (void *dst
, const void *src
, int size
)
160 int bpf_current_task_under_cgroup (void *map
, int index
)
163 int bpf_skb_change_tail (void *ctx
, unsigned int len
, unsigned long flags
)
166 int bpf_skb_pull_data (void *, int len
)
169 long long bpf_csum_update (void *ctx
, unsigned int csum
)
172 void bpf_set_hash_invalid (void *ctx
)
175 int bpf_get_numa_node_id (void)
178 int bpf_skb_change_head (void *, int len
, int flags
)
181 int bpf_xdp_adjust_head (void *ctx
, int offset
)
184 int bpf_probe_read_str (void *ctx
, unsigned int size
, const void *unsafe_ptr
)
187 int bpf_get_socket_cookie (void *ctx
)
190 unsigned int bpf_get_socket_uid (void *ctx
)
193 unsigned int bpf_set_hash (void *ctx
, unsigned int hash
)
196 int bpf_setsockopt (void *ctx
, int level
, int optname
, void *optval
, int optlen
)
199 int bpf_skb_adjust_room (void *ctx
, int len_diff
, unsigned int mode
,
200 unsigned long long flags
)
203 int bpf_redirect_map (void *map
, int key
, int flags
)
206 int bpf_sk_redirect_map (void *ctx
, void *map
, int key
, int flags
)
209 int bpf_sock_map_update (void *map
, void *key
, void *value
,
210 unsigned long long flags
)
213 int bpf_xdp_adjust_meta (void *ctx
, int offset
)
216 int bpf_perf_event_read_value (void *map
, unsigned long long flags
,
217 void *buf
, unsigned int buf_size
)
220 int bpf_perf_prog_read_value (void *ctx
, void *buf
, unsigned int buf_size
)
223 int bpf_getsockopt (void *ctx
, int level
, int optname
, void *optval
,
227 int bpf_override_return (void *ctx
, unsigned long rc
)
230 int bpf_sock_ops_cb_flags_set (void *ctx
, int flags
)
233 int bpf_msg_redirect_map (void *ctx
, void *map
, int key
, int flags
)
236 int bpf_msg_apply_bytes (void *ctx
, int len
)
239 int bpf_msg_cork_bytes (void *ctx
, int len
)
242 int bpf_msg_pull_data (void *, int len
)
245 int bpf_bind (void *ctx
, void *addr
, int addr_len
)
248 int bpf_xdp_adjust_tail (struct xdp_md
*xdp_md
, int delta
)
251 int bpf_skb_get_xfrm_state (void *ctx
, int index
, void *state
,
255 int bpf_get_stack (void *ctx
, void *buf
, int size
, int flags
)
258 int bpf_skb_load_bytes_relative (void *ctx
, int off
, void *to
, int len
,
259 unsigned int start_header
)
262 int bpf_fib_lookup (void *ctx
, struct bpf_fib_lookup
*params
,
263 int plen
, unsigned int flags
)
266 int bpf_sock_hash_update (void *map
, void *key
, void *value
,
267 unsigned long long flags
)
270 int bpf_msg_redirect_hash (void *ctx
, void *map
, void *key
, int flags
)
273 int bpf_sk_redirect_hash (void *ctx
, void *map
, void *key
, int flags
)
276 int bpf_lwt_push_encap (void *ctx
, unsigned int type
, void *hdr
,
280 int bpf_lwt_seg6_store_bytes (void *ctx
, unsigned int offset
,
281 void *from
, unsigned int len
)
284 int bpf_lwt_seg6_adjust_srh (void *ctx
, unsigned int offset
,
288 int bpf_lwt_seg6_action (void *ctx
, unsigned int action
, void *param
,
289 unsigned int param_len
)
292 int bpf_rc_repeat (void *ctx
)
295 int bpf_rc_keydown (void *ctx
, unsigned int protocol
,
296 unsigned long long scancode
, unsigned int toggle
)
299 unsigned bpf_skb_cgroup_id (void *ctx
)
302 unsigned long long bpf_get_current_cgroup_id (void)
305 void *bpf_get_local_storage (void *map
, unsigned long long flags
)
308 int bpf_sk_select_reuseport (void *ctx
, void *map
, void *key
, unsigned int flags
)
311 unsigned long long bpf_skb_ancestor_cgroup_id (void *ctx
, int level
)
314 struct 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
)
319 struct 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
)
324 int bpf_sk_release (struct bpf_sock
*sk
)
327 int bpf_map_push_elem (void *map
, const void *value
, unsigned long long flags
)
330 int bpf_map_pop_elem (void *map
, void *value
)
333 int bpf_map_peek_elem (void *map
, void *value
)
336 int bpf_msg_push_data (void *ctx
, int start
, int cut
, int flags
)
339 int bpf_msg_pop_data (void *ctx
, int start
, int cut
, int flags
)
342 int bpf_rc_pointer_rel (void *ctx
, int rel_x
, int rel_y
)
345 void bpf_spin_lock (struct bpf_spin_lock
*lock
)
348 void bpf_spin_unlock (struct bpf_spin_lock
*lock
)
351 struct bpf_sock
*bpf_sk_fullsock (struct bpf_sock
*sk
)
354 struct bpf_sock
*bpf_tcp_sock (struct bpf_sock
*sk
)
357 int bpf_skb_ecn_set_ce (void *ctx
)
360 struct bpf_sock
*bpf_get_listener_sock (struct bpf_sock
*sk
)
363 struct bpf_sock
*bpf_skc_lookup_tcp (void *ctx
,
364 struct bpf_sock_tuple
*tuple
,
365 unsigned int tuple_size
,
370 int bpf_tcp_check_syncookie (struct bpf_sock
*sk
, void *iph
,
371 unsigned int iph_len
,
376 int bpf_sysctl_get_name (struct bpf_sysctl
*ctx
,
377 char *buf
, unsigned long buf_len
,
381 int bpf_sysctl_get_current_value (struct bpf_sysctl
*ctx
,
382 char *buf
, unsigned long buf_len
)
385 int bpf_sysctl_get_new_value (struct bpf_sysctl
*ctx
, char *buf
,
386 unsigned long buf_len
)
389 int bpf_sysctl_set_new_value (struct bpf_sysctl
*ctx
, const char *buf
,
390 unsigned long buf_len
)
393 int bpf_strtol (const char *buf
, unsigned long buf_len
,
394 unsigned long flags
, long *res
)
397 int bpf_strtoul (const char *buf
, unsigned long buf_len
,
398 unsigned long flags
, unsigned long *res
)
401 void *bpf_sk_storage_get (void *map
, struct bpf_sock
*sk
,
402 void *value
, long flags
)
405 int bpf_sk_storage_delete (void *map
, struct bpf_sock
*sk
)
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. */
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))
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
;
427 #endif /* ! __BPF_HELPERS_H */