@@ -17,6 +17,13 @@ static int (*bpf_map_update_elem)(void *map, void *key, void *value,
1717 (void * ) BPF_FUNC_map_update_elem ;
1818static int (* bpf_map_delete_elem )(void * map , void * key ) =
1919 (void * ) BPF_FUNC_map_delete_elem ;
20+ static int (* bpf_map_push_elem )(void * map , void * value ,
21+ unsigned long long flags ) =
22+ (void * ) BPF_FUNC_map_push_elem ;
23+ static int (* bpf_map_pop_elem )(void * map , void * value ) =
24+ (void * ) BPF_FUNC_map_pop_elem ;
25+ static int (* bpf_map_peek_elem )(void * map , void * value ) =
26+ (void * ) BPF_FUNC_map_peek_elem ;
2027static int (* bpf_probe_read )(void * dst , int size , void * unsafe_ptr ) =
2128 (void * ) BPF_FUNC_probe_read ;
2229static unsigned long long (* bpf_ktime_get_ns )(void ) =
@@ -64,6 +71,120 @@ static unsigned long long (*bpf_get_prandom_u32)(void) =
6471 (void * ) BPF_FUNC_get_prandom_u32 ;
6572static int (* bpf_xdp_adjust_head )(void * ctx , int offset ) =
6673 (void * ) BPF_FUNC_xdp_adjust_head ;
74+ static int (* bpf_xdp_adjust_meta )(void * ctx , int offset ) =
75+ (void * ) BPF_FUNC_xdp_adjust_meta ;
76+ static int (* bpf_get_socket_cookie )(void * ctx ) =
77+ (void * ) BPF_FUNC_get_socket_cookie ;
78+ static int (* bpf_setsockopt )(void * ctx , int level , int optname , void * optval ,
79+ int optlen ) =
80+ (void * ) BPF_FUNC_setsockopt ;
81+ static int (* bpf_getsockopt )(void * ctx , int level , int optname , void * optval ,
82+ int optlen ) =
83+ (void * ) BPF_FUNC_getsockopt ;
84+ static int (* bpf_sock_ops_cb_flags_set )(void * ctx , int flags ) =
85+ (void * ) BPF_FUNC_sock_ops_cb_flags_set ;
86+ static int (* bpf_sk_redirect_map )(void * ctx , void * map , int key , int flags ) =
87+ (void * ) BPF_FUNC_sk_redirect_map ;
88+ static int (* bpf_sk_redirect_hash )(void * ctx , void * map , void * key , int flags ) =
89+ (void * ) BPF_FUNC_sk_redirect_hash ;
90+ static int (* bpf_sock_map_update )(void * map , void * key , void * value ,
91+ unsigned long long flags ) =
92+ (void * ) BPF_FUNC_sock_map_update ;
93+ static int (* bpf_sock_hash_update )(void * map , void * key , void * value ,
94+ unsigned long long flags ) =
95+ (void * ) BPF_FUNC_sock_hash_update ;
96+ static int (* bpf_perf_event_read_value )(void * map , unsigned long long flags ,
97+ void * buf , unsigned int buf_size ) =
98+ (void * ) BPF_FUNC_perf_event_read_value ;
99+ static int (* bpf_perf_prog_read_value )(void * ctx , void * buf ,
100+ unsigned int buf_size ) =
101+ (void * ) BPF_FUNC_perf_prog_read_value ;
102+ static int (* bpf_override_return )(void * ctx , unsigned long rc ) =
103+ (void * ) BPF_FUNC_override_return ;
104+ static int (* bpf_msg_redirect_map )(void * ctx , void * map , int key , int flags ) =
105+ (void * ) BPF_FUNC_msg_redirect_map ;
106+ static int (* bpf_msg_redirect_hash )(void * ctx ,
107+ void * map , void * key , int flags ) =
108+ (void * ) BPF_FUNC_msg_redirect_hash ;
109+ static int (* bpf_msg_apply_bytes )(void * ctx , int len ) =
110+ (void * ) BPF_FUNC_msg_apply_bytes ;
111+ static int (* bpf_msg_cork_bytes )(void * ctx , int len ) =
112+ (void * ) BPF_FUNC_msg_cork_bytes ;
113+ static int (* bpf_msg_pull_data )(void * ctx , int start , int end , int flags ) =
114+ (void * ) BPF_FUNC_msg_pull_data ;
115+ static int (* bpf_msg_push_data )(void * ctx , int start , int end , int flags ) =
116+ (void * ) BPF_FUNC_msg_push_data ;
117+ static int (* bpf_msg_pop_data )(void * ctx , int start , int cut , int flags ) =
118+ (void * ) BPF_FUNC_msg_pop_data ;
119+ static int (* bpf_bind )(void * ctx , void * addr , int addr_len ) =
120+ (void * ) BPF_FUNC_bind ;
121+ static int (* bpf_xdp_adjust_tail )(void * ctx , int offset ) =
122+ (void * ) BPF_FUNC_xdp_adjust_tail ;
123+ static int (* bpf_skb_get_xfrm_state )(void * ctx , int index , void * state ,
124+ int size , int flags ) =
125+ (void * ) BPF_FUNC_skb_get_xfrm_state ;
126+ static int (* bpf_sk_select_reuseport )(void * ctx , void * map , void * key , __u32 flags ) =
127+ (void * ) BPF_FUNC_sk_select_reuseport ;
128+ static int (* bpf_get_stack )(void * ctx , void * buf , int size , int flags ) =
129+ (void * ) BPF_FUNC_get_stack ;
130+ static int (* bpf_fib_lookup )(void * ctx , struct bpf_fib_lookup * params ,
131+ int plen , __u32 flags ) =
132+ (void * ) BPF_FUNC_fib_lookup ;
133+ static int (* bpf_lwt_push_encap )(void * ctx , unsigned int type , void * hdr ,
134+ unsigned int len ) =
135+ (void * ) BPF_FUNC_lwt_push_encap ;
136+ static int (* bpf_lwt_seg6_store_bytes )(void * ctx , unsigned int offset ,
137+ void * from , unsigned int len ) =
138+ (void * ) BPF_FUNC_lwt_seg6_store_bytes ;
139+ static int (* bpf_lwt_seg6_action )(void * ctx , unsigned int action , void * param ,
140+ unsigned int param_len ) =
141+ (void * ) BPF_FUNC_lwt_seg6_action ;
142+ static int (* bpf_lwt_seg6_adjust_srh )(void * ctx , unsigned int offset ,
143+ unsigned int len ) =
144+ (void * ) BPF_FUNC_lwt_seg6_adjust_srh ;
145+ static int (* bpf_rc_repeat )(void * ctx ) =
146+ (void * ) BPF_FUNC_rc_repeat ;
147+ static int (* bpf_rc_keydown )(void * ctx , unsigned int protocol ,
148+ unsigned long long scancode , unsigned int toggle ) =
149+ (void * ) BPF_FUNC_rc_keydown ;
150+ static unsigned long long (* bpf_get_current_cgroup_id )(void ) =
151+ (void * ) BPF_FUNC_get_current_cgroup_id ;
152+ static void * (* bpf_get_local_storage )(void * map , unsigned long long flags ) =
153+ (void * ) BPF_FUNC_get_local_storage ;
154+ static unsigned long long (* bpf_skb_cgroup_id )(void * ctx ) =
155+ (void * ) BPF_FUNC_skb_cgroup_id ;
156+ static unsigned long long (* bpf_skb_ancestor_cgroup_id )(void * ctx , int level ) =
157+ (void * ) BPF_FUNC_skb_ancestor_cgroup_id ;
158+ static struct bpf_sock * (* bpf_sk_lookup_tcp )(void * ctx ,
159+ struct bpf_sock_tuple * tuple ,
160+ int size , unsigned long long netns_id ,
161+ unsigned long long flags ) =
162+ (void * ) BPF_FUNC_sk_lookup_tcp ;
163+ static struct bpf_sock * (* bpf_sk_lookup_udp )(void * ctx ,
164+ struct bpf_sock_tuple * tuple ,
165+ int size , unsigned long long netns_id ,
166+ unsigned long long flags ) =
167+ (void * ) BPF_FUNC_sk_lookup_udp ;
168+ static int (* bpf_sk_release )(struct bpf_sock * sk ) =
169+ (void * ) BPF_FUNC_sk_release ;
170+ static int (* bpf_skb_vlan_push )(void * ctx , __be16 vlan_proto , __u16 vlan_tci ) =
171+ (void * ) BPF_FUNC_skb_vlan_push ;
172+ static int (* bpf_skb_vlan_pop )(void * ctx ) =
173+ (void * ) BPF_FUNC_skb_vlan_pop ;
174+ static int (* bpf_rc_pointer_rel )(void * ctx , int rel_x , int rel_y ) =
175+ (void * ) BPF_FUNC_rc_pointer_rel ;
176+ static void (* bpf_spin_lock )(struct bpf_spin_lock * lock ) =
177+ (void * ) BPF_FUNC_spin_lock ;
178+ static void (* bpf_spin_unlock )(struct bpf_spin_lock * lock ) =
179+ (void * ) BPF_FUNC_spin_unlock ;
180+ static struct bpf_sock * (* bpf_sk_fullsock )(struct bpf_sock * sk ) =
181+ (void * ) BPF_FUNC_sk_fullsock ;
182+ static struct bpf_tcp_sock * (* bpf_tcp_sock )(struct bpf_sock * sk ) =
183+ (void * ) BPF_FUNC_tcp_sock ;
184+ static struct bpf_sock * (* bpf_get_listener_sock )(struct bpf_sock * sk ) =
185+ (void * ) BPF_FUNC_get_listener_sock ;
186+ static int (* bpf_skb_ecn_set_ce )(void * ctx ) =
187+ (void * ) BPF_FUNC_skb_ecn_set_ce ;
67188
68189/* llvm builtin functions that eBPF C program may use to
69190 * emit BPF_LD_ABS and BPF_LD_IND instructions
@@ -86,22 +207,108 @@ struct bpf_map_def {
86207 unsigned int max_entries ;
87208 unsigned int map_flags ;
88209 unsigned int inner_map_idx ;
210+ unsigned int numa_node ;
89211};
90212
213+ #define BPF_ANNOTATE_KV_PAIR (name , type_key , type_val ) \
214+ struct ____btf_map_##name { \
215+ type_key key; \
216+ type_val value; \
217+ }; \
218+ struct ____btf_map_##name \
219+ __attribute__ ((section(".maps." #name), used)) \
220+ ____btf_map_##name = { }
221+
91222static int (* bpf_skb_load_bytes )(void * ctx , int off , void * to , int len ) =
92223 (void * ) BPF_FUNC_skb_load_bytes ;
224+ static int (* bpf_skb_load_bytes_relative )(void * ctx , int off , void * to , int len , __u32 start_header ) =
225+ (void * ) BPF_FUNC_skb_load_bytes_relative ;
93226static int (* bpf_skb_store_bytes )(void * ctx , int off , void * from , int len , int flags ) =
94227 (void * ) BPF_FUNC_skb_store_bytes ;
95228static int (* bpf_l3_csum_replace )(void * ctx , int off , int from , int to , int flags ) =
96229 (void * ) BPF_FUNC_l3_csum_replace ;
97230static int (* bpf_l4_csum_replace )(void * ctx , int off , int from , int to , int flags ) =
98231 (void * ) BPF_FUNC_l4_csum_replace ;
232+ static int (* bpf_csum_diff )(void * from , int from_size , void * to , int to_size , int seed ) =
233+ (void * ) BPF_FUNC_csum_diff ;
99234static int (* bpf_skb_under_cgroup )(void * ctx , void * map , int index ) =
100235 (void * ) BPF_FUNC_skb_under_cgroup ;
101236static int (* bpf_skb_change_head )(void * , int len , int flags ) =
102237 (void * ) BPF_FUNC_skb_change_head ;
238+ static int (* bpf_skb_pull_data )(void * , int len ) =
239+ (void * ) BPF_FUNC_skb_pull_data ;
240+ static unsigned int (* bpf_get_cgroup_classid )(void * ctx ) =
241+ (void * ) BPF_FUNC_get_cgroup_classid ;
242+ static unsigned int (* bpf_get_route_realm )(void * ctx ) =
243+ (void * ) BPF_FUNC_get_route_realm ;
244+ static int (* bpf_skb_change_proto )(void * ctx , __be16 proto , __u64 flags ) =
245+ (void * ) BPF_FUNC_skb_change_proto ;
246+ static int (* bpf_skb_change_type )(void * ctx , __u32 type ) =
247+ (void * ) BPF_FUNC_skb_change_type ;
248+ static unsigned int (* bpf_get_hash_recalc )(void * ctx ) =
249+ (void * ) BPF_FUNC_get_hash_recalc ;
250+ static unsigned long long (* bpf_get_current_task )(void * ctx ) =
251+ (void * ) BPF_FUNC_get_current_task ;
252+ static int (* bpf_skb_change_tail )(void * ctx , __u32 len , __u64 flags ) =
253+ (void * ) BPF_FUNC_skb_change_tail ;
254+ static long long (* bpf_csum_update )(void * ctx , __u32 csum ) =
255+ (void * ) BPF_FUNC_csum_update ;
256+ static void (* bpf_set_hash_invalid )(void * ctx ) =
257+ (void * ) BPF_FUNC_set_hash_invalid ;
258+ static int (* bpf_get_numa_node_id )(void ) =
259+ (void * ) BPF_FUNC_get_numa_node_id ;
260+ static int (* bpf_probe_read_str )(void * ctx , __u32 size ,
261+ const void * unsafe_ptr ) =
262+ (void * ) BPF_FUNC_probe_read_str ;
263+ static unsigned int (* bpf_get_socket_uid )(void * ctx ) =
264+ (void * ) BPF_FUNC_get_socket_uid ;
265+ static unsigned int (* bpf_set_hash )(void * ctx , __u32 hash ) =
266+ (void * ) BPF_FUNC_set_hash ;
267+ static int (* bpf_skb_adjust_room )(void * ctx , __s32 len_diff , __u32 mode ,
268+ unsigned long long flags ) =
269+ (void * ) BPF_FUNC_skb_adjust_room ;
270+
271+ /* Scan the ARCH passed in from ARCH env variable (see Makefile) */
272+ #if defined(__TARGET_ARCH_x86 )
273+ #define bpf_target_x86
274+ #define bpf_target_defined
275+ #elif defined(__TARGET_ARCH_s930x )
276+ #define bpf_target_s930x
277+ #define bpf_target_defined
278+ #elif defined(__TARGET_ARCH_arm64 )
279+ #define bpf_target_arm64
280+ #define bpf_target_defined
281+ #elif defined(__TARGET_ARCH_mips )
282+ #define bpf_target_mips
283+ #define bpf_target_defined
284+ #elif defined(__TARGET_ARCH_powerpc )
285+ #define bpf_target_powerpc
286+ #define bpf_target_defined
287+ #elif defined(__TARGET_ARCH_sparc )
288+ #define bpf_target_sparc
289+ #define bpf_target_defined
290+ #else
291+ #undef bpf_target_defined
292+ #endif
103293
294+ /* Fall back to what the compiler says */
295+ #ifndef bpf_target_defined
104296#if defined(__x86_64__ )
297+ #define bpf_target_x86
298+ #elif defined(__s390x__ )
299+ #define bpf_target_s930x
300+ #elif defined(__aarch64__ )
301+ #define bpf_target_arm64
302+ #elif defined(__mips__ )
303+ #define bpf_target_mips
304+ #elif defined(__powerpc__ )
305+ #define bpf_target_powerpc
306+ #elif defined(__sparc__ )
307+ #define bpf_target_sparc
308+ #endif
309+ #endif
310+
311+ #if defined(bpf_target_x86 )
105312
106313#define PT_REGS_PARM1 (x ) ((x)->di)
107314#define PT_REGS_PARM2 (x ) ((x)->si)
@@ -114,7 +321,7 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
114321#define PT_REGS_SP (x ) ((x)->sp)
115322#define PT_REGS_IP (x ) ((x)->ip)
116323
117- #elif defined(__s390x__ )
324+ #elif defined(bpf_target_s390x )
118325
119326#define PT_REGS_PARM1 (x ) ((x)->gprs[2])
120327#define PT_REGS_PARM2 (x ) ((x)->gprs[3])
@@ -127,7 +334,7 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
127334#define PT_REGS_SP (x ) ((x)->gprs[15])
128335#define PT_REGS_IP (x ) ((x)->psw.addr)
129336
130- #elif defined(__aarch64__ )
337+ #elif defined(bpf_target_arm64 )
131338
132339#define PT_REGS_PARM1 (x ) ((x)->regs[0])
133340#define PT_REGS_PARM2 (x ) ((x)->regs[1])
@@ -140,7 +347,20 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
140347#define PT_REGS_SP (x ) ((x)->sp)
141348#define PT_REGS_IP (x ) ((x)->pc)
142349
143- #elif defined(__powerpc__ )
350+ #elif defined(bpf_target_mips )
351+
352+ #define PT_REGS_PARM1 (x ) ((x)->regs[4])
353+ #define PT_REGS_PARM2 (x ) ((x)->regs[5])
354+ #define PT_REGS_PARM3 (x ) ((x)->regs[6])
355+ #define PT_REGS_PARM4 (x ) ((x)->regs[7])
356+ #define PT_REGS_PARM5 (x ) ((x)->regs[8])
357+ #define PT_REGS_RET (x ) ((x)->regs[31])
358+ #define PT_REGS_FP (x ) ((x)->regs[30]) /* Works only with CONFIG_FRAME_POINTER */
359+ #define PT_REGS_RC (x ) ((x)->regs[1])
360+ #define PT_REGS_SP (x ) ((x)->regs[29])
361+ #define PT_REGS_IP (x ) ((x)->cp0_epc)
362+
363+ #elif defined(bpf_target_powerpc )
144364
145365#define PT_REGS_PARM1 (x ) ((x)->gpr[3])
146366#define PT_REGS_PARM2 (x ) ((x)->gpr[4])
@@ -151,7 +371,7 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
151371#define PT_REGS_SP (x ) ((x)->sp)
152372#define PT_REGS_IP (x ) ((x)->nip)
153373
154- #elif defined(__sparc__ )
374+ #elif defined(bpf_target_sparc )
155375
156376#define PT_REGS_PARM1 (x ) ((x)->u_regs[UREG_I0])
157377#define PT_REGS_PARM2 (x ) ((x)->u_regs[UREG_I1])
@@ -161,6 +381,8 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
161381#define PT_REGS_RET (x ) ((x)->u_regs[UREG_I7])
162382#define PT_REGS_RC (x ) ((x)->u_regs[UREG_I0])
163383#define PT_REGS_SP (x ) ((x)->u_regs[UREG_FP])
384+
385+ /* Should this also be a bpf_target check for the sparc case? */
164386#if defined(__arch64__ )
165387#define PT_REGS_IP (x ) ((x)->tpc)
166388#else
@@ -169,10 +391,10 @@ static int (*bpf_skb_change_head)(void *, int len, int flags) =
169391
170392#endif
171393
172- #ifdef __powerpc__
394+ #ifdef bpf_target_powerpc
173395#define BPF_KPROBE_READ_RET_IP (ip , ctx ) ({ (ip) = (ctx)->link; })
174396#define BPF_KRETPROBE_READ_RET_IP BPF_KPROBE_READ_RET_IP
175- #elif defined( __sparc__ )
397+ #elif bpf_target_sparc
176398#define BPF_KPROBE_READ_RET_IP (ip , ctx ) ({ (ip) = PT_REGS_RET(ctx); })
177399#define BPF_KRETPROBE_READ_RET_IP BPF_KPROBE_READ_RET_IP
178400#else
0 commit comments