]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/bpf/bpf-helpers.h
1 /* Copyright (C) 2019-2020 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))
34 /* Flags used in some kernel helpers. */
41 #define BPF_F_NO_COMMON_LRU (1U << 1)
42 #define BPF_F_NUMA_NODE (1U << 2)
44 /* Functions to call kernel helpers. We provide the "standard" bpf_*
45 names as synonyms of the corresponding GCC builtins. In some
46 cases, where non-void pointers are passed to the helper, inline
47 functions are used to achieve proper type checking. */
49 #ifndef KERNEL_VERSION
50 # define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
53 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,0,0)
55 #define bpf_map_lookup_elem __builtin_bpf_helper_map_lookup_elem
56 #define bpf_map_update_elem __builtin_bpf_helper_map_update_elem
57 #define bpf_map_delete_elem __builtin_bpf_helper_map_delete_elem
59 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,1,0)
61 #define bpf_probe_read __builtin_bpf_helper_probe_read
62 #define bpf_ktime_get_ns __builtin_bpf_helper_ktime_get_ns
63 #define bpf_trace_printk __builtin_bpf_helper_trace_printk
64 #define bpf_get_prandom_u32 __builtin_bpf_helper_get_prandom_u32
65 #define bpf_get_smp_processor_id __builtin_bpf_helper_get_smp_processor_id
66 #define bpf_skb_store_bytes __builtin_bpf_helper_skb_store_bytes
67 #define bpf_l3_csum_replace __builtin_bpf_helper_l3_csum_replace
68 #define bpf_l4_csum_replace __builtin_bpf_helper_l4_csum_replace
70 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,2,0)
72 #define bpf_tail_call __builtin_bpf_helper_tail_call
73 #define bpf_clone_redirect __builtin_bpf_helper_clone_redirect
74 #define bpf_get_current_pid_tgid __builtin_bpf_helper_get_current_pid_tgid
75 #define bpf_get_current_uid_gid __builtin_bpf_helper_get_current_uid_gid
76 #define bpf_get_current_comm __builtin_bpf_helper_get_current_comm
78 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,3,0)
80 #define bpf_get_cgroup_classid __builtin_bpf_helper_get_cgroup_classid
81 #define bpf_skb_vlan_push __builtin_bpf_helper_skb_vlan_push
82 #define bpf_skb_vlan_pop __builtin_bpf_helper_skb_vlan_pop
83 #define bpf_skb_get_tunnel_key __builtin_bpf_helper_skb_get_tunnel_key
84 #define bpf_skb_set_tunnel_key __builtin_bpf_helper_skb_set_tunnel_key
85 #define bpf_perf_event_read __builtin_bpf_helper_perf_event_read
87 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,4,0)
89 #define bpf_redirect __builtin_bpf_helper_redirect
90 #define bpf_get_route_realm __builtin_bpf_helper_get_route_realm
91 #define bpf_perf_event_output __builtin_bpf_helper_perf_event_output
93 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,5,0)
95 #define bpf_skb_load_bytes __builtin_bpf_helper_skb_load_bytes
97 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,6,0)
99 #define bpf_get_stackid __builtin_bpf_helper_get_stackid
100 #define bpf_csum_diff __builtin_bpf_helper_csum_diff
101 #define bpf_skb_get_tunnel_opt __builtin_bpf_helper_skb_get_tunnel_opt
102 #define bpf_skb_set_tunnel_opt __builtin_bpf_helper_skb_set_tunnel_opt
104 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,8,0)
106 #define bpf_skb_change_proto __builtin_bpf_helper_skb_change_proto
107 #define bpf_skb_change_type __builtin_bpf_helper_skb_change_type
108 #define bpf_skb_under_cgroup __builtin_bpf_helper_skb_under_cgroup
109 #define bpf_get_hash_recalc __builtin_bpf_helper_get_hash_recalc
110 #define bpf_get_current_task __builtin_bpf_helper_get_current_task
111 #define bpf_probe_write_user __builtin_bpf_helper_probe_write_user
113 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,9,0)
115 #define bpf_current_task_under_cgroup __builtin_bpf_helper_current_task_under_cgroup
116 #define bpf_skb_change_tail __builtin_bpf_helper_skb_change_tail
117 #define bpf_skb_pull_data __builtin_bpf_helper_skb_pull_data
118 #define bpf_csum_update __builtin_bpf_helper_csum_update
119 #define bpf_set_hash_invalid __builtin_bpf_helper_set_hash_invalid
121 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,10,0)
123 #define bpf_get_numa_node_id __builtin_bpf_helper_get_numa_node_id
124 #define bpf_skb_change_head __builtin_bpf_helper_skb_change_head
125 #define bpf_xdp_adjust_head __builtin_bpf_helper_xdp_adjust_head
127 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,11,0)
129 #define bpf_probe_read_str __builtin_bpf_helper_probe_read_str
131 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,12,0)
133 #define bpf_get_socket_cookie __builtin_bpf_helper_get_socket_cookie
134 #define bpf_get_socket_uid __builtin_bpf_helper_get_socket_uid
136 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,13,0)
138 #define bpf_set_hash __builtin_bpf_helper_set_hash
139 #define bpf_setsockopt __builtin_bpf_helper_setsockopt
140 #define bpf_skb_adjust_room __builtin_bpf_helper_skb_adjust_room
142 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,14,0)
144 #define bpf_redirect_map __builtin_bpf_helper_redirect_map
145 #define bpf_sk_redirect_map __builtin_bpf_helper_sk_redirect_map
146 #define bpf_sock_map_update __builtin_bpf_helper_sock_map_update
148 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,15,0)
150 #define bpf_perf_event_read_value __builtin_bpf_helper_perf_event_read_value
151 #define bpf_perf_prog_read_value __builtin_bpf_helper_perf_prog_read_value
152 #define bpf_getsockopt __builtin_bpf_helper_getsockopt
153 #define bpf_xdp_adjust_meta __builtin_bpf_helper_xdp_adjust_meta
155 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,16,0)
157 #define bpf_override_return __builtin_bpf_helper_override_return
158 #define bpf_sock_ops_cb_flags_set __builtin_bpf_helper_sock_ops_cb_flags_set
160 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,17,0)
162 #define bpf_msg_redirect_map __builtin_bpf_helper_msg_redirect_map
163 #define bpf_msg_apply_bytes __builtin_bpf_helper_msg_apply_bytes
164 #define bpf_msg_cork_bytes __builtin_bpf_helper_msg_cork_bytes
165 #define bpf_pull_data __builtin_bpf_helper_pull_data
166 #define bpf_bind __builtin_bpf_helper_bpf_bind
168 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,18,0)
170 #define bpf_xdp_adjust_tail __builtin_bpf_helper_xdp_adjust_tail
171 #define bpf_skb_get_xfrm_state __builtin_bpf_helper_skb_get_xfrm_state
172 #define bpf_get_stack __builtin_bpf_helper_get_stack
173 #define bpf_skb_load_bytes_relative __builtin_bpf_helper_skb_load_bytes_relative
174 #define bpf_sock_hash_update __builtin_bpf_helper_sock_hash_update
175 #define bpf_msg_redirect_hash __builtin_bpf_helper_msg_redirect_hash
176 #define bpf_sk_redirect_hash __builtin_bpf_helper_sk_redirect_hash
177 #define bpf_lwt_push_encap __builtin_bpf_helper_lwt_push_encap
178 #define bpf_lwt_seg6_store_bytes __builtin_bpf_helper_lwt_seg6_store_bytes
179 #define bpf_lwt_seg6_adjust_srh __builtin_bpf_helper_lwt_seg6_adjust_srh
180 #define bpf_lwt_seg6_action __builtin_bpf_helper_lwt_seg6_action
181 #define bpf_rc_repeat __builtin_bpf_helper_rc_repeat
182 #define bpf_rc_keydown __builtin_bpf_helper_rc_keydown
183 #define bpf_skb_cgroup_id __builtin_bpf_helper_skb_cgroup_id
184 #define bpf_get_current_cgroup_id __builtin_bpf_helper_get_current_cgroup_id
187 bpf_fib_lookup (void *ctx
, struct bpf_fib_lookup
*param
, int plen
,
190 return __builtin_bpf_helper_fib_lookup (ctx
, (void *) param
, plen
, flags
);
194 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,19,0)
196 #define bpf_get_local_storage __builtin_bpf_helper_get_local_storage
197 #define bpf_sk_select_reuseport __builtin_bpf_helper_sk_select_reuseport
198 #define bpf_skb_ancestor_cgroup_id __builtin_bpf_helper_skb_ancestor_cgroup_id
200 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (4,20,0)
202 #define bpf_sk_release __builtin_bpf_helper_sk_release
203 #define bpf_map_push_elem __builtin_bpf_helper_map_push_elem
204 #define bpf_map_pop_elem __builtin_bpf_helper_map_pop_elem
205 #define bpf_map_peek_elem __builtin_bpf_helper_map_peek_elem
206 #define bpf_msg_push_data __builtin_bpf_helper_msg_push_data
208 static inline struct bpf_sock
*
209 bpf_sk_lookup_tcp (void *ctx
, struct bpf_sock_tuple
*tuple
,
210 int size
, unsigned long long netns_id
,
211 unsigned long long flags
)
214 (struct bpf_sock
*) __builtin_bpf_helper_sk_lookup_tcp (ctx
,
220 static inline struct bpf_sock
*
221 bpf_sk_lookup_udp (void *ctx
, struct bpf_sock_tuple
*tuple
,
222 int size
, unsigned long long netns_id
,
223 unsigned long long flags
)
226 (struct bpf_sock
*) __builtin_bpf_helper_sk_lookup_udp (ctx
,
232 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (5,0,0)
234 #define bpf_msg_pop_data __builtin_bpf_helper_pop_data
235 #define bpf_rc_pointer_rel __builtin_bpf_helper_rc_pointer_rel
237 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (5,1,0)
239 #define bpf_spin_lock __builtin_bpf_helper_spin_lock
240 #define bpf_spin_unlock __builtin_bpf_helper_spin_unlock
241 #define bpf_skb_ecn_set_ce __builtin_bpf_helper_skb_ecn_set_ce
243 static inline struct bpf_sock
*
244 bpf_sk_fullsock (struct bpf_sock
*sk
)
247 (struct bpf_sock
*) __builtin_bpf_helper_sk_fullsock ((void *) sk
);
250 static inline struct bpf_sock
*
251 bpf_tcp_sock (struct bpf_sock
*sk
)
254 (struct bpf_sock
*) __builtin_bpf_helper_tcp_sock ((void *) sk
);
257 static inline struct bpf_sock
*
258 bpf_get_listener_sock (struct bpf_sock
*sk
)
261 (struct bpf_sock
*) __builtin_bpf_helper_get_listener_sock ((void *) sk
);
264 #if __BPF_KERNEL_VERSION_CODE__ >= KERNEL_VERSION (5,2,0)
291 /* Functions to emit BPF_LD_ABS and BPF_LD_IND instructions. We
292 provide the "standard" names as synonyms of the corresponding GCC
293 builtins. Note how the SKB argument is ignored. */
295 static inline long long
296 load_byte (void *skb
__attribute__ ((unused
)),
297 unsigned long long off
)
299 return __builtin_bpf_load_byte (off
);
302 static inline long long
303 load_half (void *skb
__attribute__ ((unused
)),
304 unsigned long long off
)
306 return __builtin_bpf_load_half (off
);
309 static inline long long
310 load_word (void *skb
__attribute__ ((unused
)),
311 unsigned long long off
)
313 return __builtin_bpf_load_word (off
);
319 unsigned int key_size
;
320 unsigned int value_size
;
321 unsigned int max_entries
;
322 unsigned int map_flags
;
323 unsigned int inner_map_idx
;
324 unsigned int numa_node
;
327 #endif /* ! __BPF_HELPERS_H */